Calculators
The calculator translates an EasyReflectometry model into a backend engine (refl1d or refnx) and computes reflectivity.
Polarized reflectivity
With the refl1d calculator and include_magnetism enabled, all four
spin channels are available:
polarized_reflectivity_profiles(x_array, model_id)returns the reflectivity of all four channels as a dictionary keyed'pp','pm','mp','mm'(in that order).polarization_channelselects which channelreflectity_profile— and hence fitting — uses (default'pp').magnetic_sld_profile(model_id)returns the nuclear and magnetic scattering length density profiles as a tuplez,sld(z),rhoM(z)(magnetic SLD) andthetaM(z)(magnetic angle).
Note that polarization_channel is state of the currently active
calculator instance, not of a model or dataset: it affects every
subsequent calculation using that calculator, and switching calculators
via the factory constructs a fresh instance, which resets the channel
(along with include_magnetism). Calculators without magnetism support
(refnx) raise NotImplementedError when magnetism is enabled.
polarization
POLARIZATION_CHANNEL_TO_INDEX = {PolarizationChannel.PP: 3, PolarizationChannel.PM: 2, PolarizationChannel.MP: 1, PolarizationChannel.MM: 0}
module-attribute
PolarizationChannel
Bases: str, Enum
Spin cross-section channels for polarized neutron reflectometry.
The accepted spellings are exactly the enum values ('pp', 'pm', 'mp', 'mm'); uppercase strings are rejected.
Source code in src/easyreflectometry/calculators/polarization.py
7 8 9 10 11 12 13 14 15 16 17 | |
calculator_base
Model
Bases: BaseCore
Model is the class that represents the experiment.
It is used to store the information about the experiment and to perform the calculations.
Source code in src/easyreflectometry/model/model.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 | |
total_thickness
property
Read-only parameter: the summed thickness of the film layers.
The superphase (first layer of the sample) and the subphase (last layer) are semi-infinite and excluded. The parameter is dependent: it tracks the layer thicknesses, never enters a fit and cannot be set; it can be referenced from constraint expressions and inequality constraints like any other parameter.
has_magnetism
property
Whether any layer in the sample carries magnetic properties.
is_default
property
writable
Whether this model was created as a default placeholder.
resolution_function
property
writable
Return the resolution function.
__init__(sample=None, scale=None, background=None, resolution_function=None, name='Model', color=COLORS[0], unique_name=None, interface=None)
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unique_name
|
Optional[str]
|
By default, None. |
None
|
color
|
str
|
By default, COLORS[0]. |
COLORS[0]
|
sample
|
Union[Sample, None]
|
The sample being modelled. By default, None. |
None
|
scale
|
Union[Parameter, Number, None]
|
Scaling factor of profile. By default, None. |
None
|
background
|
Union[Parameter, Number, None]
|
Linear background magnitude. By default, None. |
None
|
name
|
str
|
Name of the model. By default, 'Model'. |
'Model'
|
resolution_function
|
Union[ResolutionFunction, None]
|
Resolution function. By default, None. |
None
|
interface
|
Calculator interface. By default, None. |
None
|
Source code in src/easyreflectometry/model/model.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
interface(new_interface)
Set the interface; runs generate_bindings and then refreshes the
calculator's resolution function.
Source code in src/easyreflectometry/model/model.py
294 295 296 297 298 299 300 301 302 | |
refresh_derived()
Re-derive the model's computed parameters from the current layer structure.
Cheap (a few string operations) and idempotent: the dependency is
only rebuilt when the set of contributing layers changed. Called on
every access to :attr:total_thickness, so layers added or removed
through any path (Model.add_assemblies, assembly.layers.append,
...) are picked up without explicit notification.
Source code in src/easyreflectometry/model/model.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | |
add_assemblies(*assemblies)
Add assemblies to the model sample.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*assemblies
|
list[BaseAssembly]
|
Assemblies to add to model sample. |
()
|
Source code in src/easyreflectometry/model/model.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | |
duplicate_assembly(index)
Duplicate a given item or layer in a sample.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
|
required |
idx
|
Index of the item or layer to duplicate. |
required |
Source code in src/easyreflectometry/model/model.py
236 237 238 239 240 241 242 243 244 245 246 247 | |
remove_assembly(index)
Remove an assembly from the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
|
required |
idx
|
Index of the item to remove. |
required |
Source code in src/easyreflectometry/model/model.py
249 250 251 252 253 254 255 256 257 258 259 260 261 | |
to_dict(skip=None)
Serialize the model, encoding the resolution function and interface name.
Source code in src/easyreflectometry/model/model.py
327 328 329 330 331 332 333 334 335 336 337 338 339 340 | |
as_dict(skip=None)
Compatibility alias for :meth:to_dict.
Source code in src/easyreflectometry/model/model.py
342 343 344 | |
as_orso()
The sample as an ORSO simple-model (sample.model) dictionary.
Slab representation: lengths in angstrom, SLDs in 1/angstrom^2,
repeating multilayers via the inline N ( ... ) stack syntax.
Returns:
| Type | Description |
|---|---|
dict
|
The ORSO model-language dictionary (the content of an .ort file's
|
Source code in src/easyreflectometry/model/model.py
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 | |
from_dict(passed_dict)
classmethod
Create a Model from a dictionary.
Source code in src/easyreflectometry/model/model.py
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 | |
BaseAssembly
Bases: BaseCore
Assembly of layers.
The front layer (front_layer) is the layer the neutron beam starts in, it has an index of 0. The back layer (back_layer) is the final layer from which the unreflected neutron beam is transmitted, its index number depends on the number of finite layers in the system, but it might be accessed at index -1.
Source code in src/easyreflectometry/sample/assemblies/base_assembly.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | |
type
property
Get type of the assembly.
Needed by the GUI.
front_layer
property
writable
Get the front layer in the assembly.
back_layer
property
writable
Get the back layer in the assembly.
conformal_thickness
property
writable
Whether every layer shares the front layer's thickness.
conformal_roughness
property
writable
Whether every layer shares the front layer's roughness.
Layer
Bases: BaseCore
Source code in src/easyreflectometry/sample/elements/layers/layer.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
__init__(material=None, thickness=None, roughness=None, name='EasyLayer', unique_name=None, interface=None, magnetism=None)
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unique_name
|
Optional[str]
|
By default, None. |
None
|
material
|
Union[Material, None]
|
The material for the layer. By default, None. |
None
|
thickness
|
Union[Parameter, float, None]
|
Layer thickness in Angstrom. By default, None. |
None
|
roughness
|
Union[Parameter, float, None]
|
Upper roughness on the layer in Angstrom. By default, None. |
None
|
magnetism
|
Union[LayerMagnetism, None]
|
Magnetic properties of the layer; None for a non-magnetic layer. By default, None. |
None
|
name
|
str
|
Name of the layer. By default, 'EasyLayer'. |
'EasyLayer'
|
interface
|
Interface object. By default, None. |
None
|
Source code in src/easyreflectometry/sample/elements/layers/layer.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
interface(new_interface)
Set the interface; runs generate_bindings and, for a magnetic layer,
enables magnetism on the calculator (raising if it does not support it).
Source code in src/easyreflectometry/sample/elements/layers/layer.py
106 107 108 109 110 111 112 113 | |
assign_material(material)
Assign a material to the layer interface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
material
|
Material
|
The material to assign to the layer. |
required |
Source code in src/easyreflectometry/sample/elements/layers/layer.py
175 176 177 178 179 180 181 182 183 184 185 | |
Material
Bases: BaseCore
Source code in src/easyreflectometry/sample/elements/materials/material.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
__init__(sld=None, isld=None, name='EasyMaterial', unique_name=None, interface=None)
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unique_name
|
Optional[str]
|
By default, None. |
None
|
sld
|
Union[Parameter, float, None]
|
Real scattering length density. By default, None. |
None
|
isld
|
Union[Parameter, float, None]
|
Imaginary scattering length density. By default, None. |
None
|
name
|
str
|
Name of the material. By default, 'EasyMaterial'. |
'EasyMaterial'
|
interface
|
Calculator interface. By default, None. |
None
|
Source code in src/easyreflectometry/sample/elements/materials/material.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
MaterialMixture
Bases: BaseCore
Source code in src/easyreflectometry/sample/elements/materials/material_mixture.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | |
fraction
property
writable
The Parameter that controls the mixing fraction of material_b in material_a.
__init__(material_a=None, material_b=None, fraction=None, name=None, unique_name=None, interface=None)
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unique_name
|
Optional[str]
|
By default, None. |
None
|
material_a
|
Union[Material, None]
|
The first material. By default, None. |
None
|
material_b
|
Union[Material, None]
|
The second material. By default, None. |
None
|
fraction
|
Union[Parameter, float, None]
|
The fraction of material_b in material_a. By default, None. |
None
|
name
|
Union[str, None]
|
Name of the material. By default, None. |
None
|
interface
|
Calculator interface. By default, None. |
None
|
Source code in src/easyreflectometry/sample/elements/materials/material_mixture.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
from_dict(obj_dict)
classmethod
Re-attach mixed-sld dependencies after :class:ModelBase swaps in
the saved _fraction Parameter.
:class:ModelBase.from_dict runs __init__ (which builds the
_sld / _isld constraints against the temporary _fraction
created from the float kwargs) and then re-points self._fraction
at the persisted Parameter. The constraint graph still references the
temporary object, so subsequent mm.fraction = X mutations don't
propagate to _sld / _isld. Re-running _materials_constraints
here points the graph at the live objects.
Source code in src/easyreflectometry/sample/elements/materials/material_mixture.py
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | |
Multilayer
Bases: BaseAssembly
A multi layer is build from a single or a list of Layer or LayerCollection.
The multi layer will arrange the layers as slabs, allowing the reflectometry to be determined from them. The front layer is where the neutron beam starts in, it has an index of 0.
More information about the usage of this assembly is available in the
multilayer documentation_
.. _multilayer documentation: ../sample/assemblies_library.html#multilayer
Source code in src/easyreflectometry/sample/assemblies/multilayer.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
__init__(layers=None, name='EasyMultilayer', unique_name=None, interface=None, type='Multi-layer', populate_if_none=True, conformal_thickness=False, conformal_roughness=False)
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
populate_if_none
|
Optional[bool]
|
By default, True. |
True
|
unique_name
|
Optional[str]
|
By default, None. |
None
|
layers
|
Union[Layer, list[Layer], LayerCollection, None]
|
The layers that make up the multi-layer. By default, None. |
None
|
name
|
str
|
Name for multi layer. By default, 'EasyMultilayer'. |
'EasyMultilayer'
|
interface
|
Calculator interface. By default, None. |
None
|
|
type
|
str
|
Type of the constructed instance. By default, 'Multi-layer'. |
'Multi-layer'
|
conformal_thickness
|
bool
|
Tie every layer's thickness to the front layer's. Serialization
reads the current graph state through the matching property, so
the ties are rebuilt on |
False
|
conformal_roughness
|
bool
|
Tie every layer's roughness to the front layer's, likewise persistent. By default, False. |
False
|
Source code in src/easyreflectometry/sample/assemblies/multilayer.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
add_layer(*layers)
Add a layer to the multi layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*layers
|
tuple[Layer]
|
Layers to add to the multi layer. |
()
|
Source code in src/easyreflectometry/sample/assemblies/multilayer.py
86 87 88 89 90 91 92 93 94 95 96 97 98 | |
duplicate_layer(idx)
Duplicate a given layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
idx
|
int
|
Index of layer to duplicate. |
required |
Source code in src/easyreflectometry/sample/assemblies/multilayer.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
remove_layer(idx)
Remove a layer from the item.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
idx
|
int
|
Index of layer to remove. |
required |
Source code in src/easyreflectometry/sample/assemblies/multilayer.py
117 118 119 120 121 122 123 124 125 126 127 | |
from_dict(data)
classmethod
Create a Multilayer from a dictionary.
Source code in src/easyreflectometry/sample/assemblies/multilayer.py
135 136 137 138 139 | |
WrapperBase
Source code in src/easyreflectometry/calculators/wrapper_base.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 | |
magnetism
property
writable
Magnetism function.
polarization_channel
property
writable
The spin channel returned by calculate when magnetism is enabled.
__init__()
Constructor.
Source code in src/easyreflectometry/calculators/wrapper_base.py
18 19 20 21 22 23 24 25 26 27 28 | |
reset_storage()
Reset the storage area to blank.
Source code in src/easyreflectometry/calculators/wrapper_base.py
30 31 32 33 34 35 36 37 | |
create_material(name)
abstractmethod
Create a material using SLD.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the material. |
required |
Source code in src/easyreflectometry/calculators/wrapper_base.py
39 40 41 42 43 44 45 46 47 48 | |
create_layer(name)
abstractmethod
Create a layer using Slab.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the layer. |
required |
Source code in src/easyreflectometry/calculators/wrapper_base.py
50 51 52 53 54 55 56 57 58 59 | |
create_item(name)
abstractmethod
Create an item using Stack.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the item. |
required |
Source code in src/easyreflectometry/calculators/wrapper_base.py
61 62 63 64 65 66 67 68 69 70 | |
create_model(name)
abstractmethod
Create a model for analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name for the model. |
required |
Source code in src/easyreflectometry/calculators/wrapper_base.py
72 73 74 75 76 77 78 79 80 81 | |
update_model(name, **kwargs)
abstractmethod
Update the non-structural parameters of the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name for the model. |
required |
**kwargs
|
|
{}
|
Source code in src/easyreflectometry/calculators/wrapper_base.py
83 84 85 86 87 88 89 90 91 92 93 | |
get_model_value(name, key)
abstractmethod
A function to get a given model value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name for the model. |
required |
key
|
str
|
The given value keys. |
required |
Source code in src/easyreflectometry/calculators/wrapper_base.py
95 96 97 98 99 100 101 102 103 104 105 106 | |
assign_material_to_layer(material_name, layer_name)
abstractmethod
Assign a material to a layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
material_name
|
str
|
The material name. |
required |
layer_name
|
str
|
The layer name. |
required |
Source code in src/easyreflectometry/calculators/wrapper_base.py
108 109 110 111 112 113 114 115 116 117 118 119 | |
add_layer_to_item(layer_name, item_name)
abstractmethod
Create a layer from the material of the same name, in a given item.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer_name
|
str
|
The layer name. |
required |
item_name
|
str
|
The item name. |
required |
Source code in src/easyreflectometry/calculators/wrapper_base.py
121 122 123 124 125 126 127 128 129 130 131 132 | |
add_item(item_name, model_name)
abstractmethod
Add an item to the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_name
|
str
|
Items to add to model. |
required |
model_name
|
str
|
Name for the model. |
required |
Source code in src/easyreflectometry/calculators/wrapper_base.py
134 135 136 137 138 139 140 141 142 143 144 145 | |
remove_layer_from_item(layer_name, item_name)
abstractmethod
Remove a layer in a given item.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer_name
|
str
|
The layer name. |
required |
item_name
|
str
|
The item name. |
required |
Source code in src/easyreflectometry/calculators/wrapper_base.py
147 148 149 150 151 152 153 154 155 156 157 158 | |
remove_item(item_name, model_name)
abstractmethod
Remove a given item.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_name
|
str
|
The item name. |
required |
model_name
|
str
|
Name of the model. |
required |
Source code in src/easyreflectometry/calculators/wrapper_base.py
160 161 162 163 164 165 166 167 168 169 170 171 | |
calculate(q_array, model_name)
abstractmethod
For a given q array calculate the corresponding reflectivity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q_array
|
np.ndarray
|
Array of data points to be calculated. |
required |
model_name
|
str
|
The model name. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
Reflectivity calculated at q. |
Source code in src/easyreflectometry/calculators/wrapper_base.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
sld_profile(model_name)
abstractmethod
Return the scattering length density profile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str
|
Name for the model. |
required |
Returns:
| Type | Description |
|---|---|
tuple[np.ndarray, np.ndarray]
|
Z and sld(z). |
Source code in src/easyreflectometry/calculators/wrapper_base.py
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |
update_material(name, **kwargs)
Update a material.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the material. |
required |
**kwargs
|
Key-value pairs of attributes to update. |
{}
|
Source code in src/easyreflectometry/calculators/wrapper_base.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 | |
get_material_value(name, key)
A function to get a given material value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The material name. |
required |
key
|
str
|
The given value keys. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The desired value. |
Source code in src/easyreflectometry/calculators/wrapper_base.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | |
update_layer(name, **kwargs)
Update a layer in a given item.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The layer name. |
required |
**kwargs
|
|
{}
|
Source code in src/easyreflectometry/calculators/wrapper_base.py
241 242 243 244 245 246 247 248 249 250 251 252 253 | |
get_layer_value(name, key)
A function to get a given layer value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The layer name. |
required |
key
|
str
|
The given value keys. |
required |
Source code in src/easyreflectometry/calculators/wrapper_base.py
255 256 257 258 259 260 261 262 263 264 265 266 267 | |
update_item(name, **kwargs)
Update a layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
|
{}
|
|
name
|
str
|
The item name. |
required |
Source code in src/easyreflectometry/calculators/wrapper_base.py
269 270 271 272 273 274 275 276 277 278 279 280 281 | |
get_item_value(name, key)
A function to get a given item value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The item name. |
required |
key
|
str
|
The given value keys. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The desired value. |
Source code in src/easyreflectometry/calculators/wrapper_base.py
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | |
set_resolution_function(resolution_function)
Set the resolution function for the calculator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resolution_function
|
ResolutionFunction
|
The resolution function. |
required |
Source code in src/easyreflectometry/calculators/wrapper_base.py
302 303 304 305 306 307 308 309 310 | |
remove_layer_magnetism(name)
Remove the magnetic state of one layer; disable magnetism when none is left.
No-op by default; overridden by backends that support magnetism.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The layer name. |
required |
Source code in src/easyreflectometry/calculators/wrapper_base.py
351 352 353 354 355 356 357 358 359 360 | |
calculate_channel(q_array, model_name, channel)
For a given q array calculate the reflectivity of one explicit spin channel.
Unlike the polarization_channel property (global calculator state used by
calculate), the channel is passed explicitly, so several channels can be
evaluated against the same model, e.g. one per dataset in a simultaneous
multi-channel fit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q_array
|
np.ndarray
|
Array of data points to be calculated. |
required |
model_name
|
str
|
The model name. |
required |
channel
|
PolarizationChannel | str
|
One of 'pp', 'pm', 'mp', 'mm' (or the corresponding enum member). |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
Reflectivity of the requested channel at q. |
Source code in src/easyreflectometry/calculators/wrapper_base.py
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 | |
calculate_polarized(q_array, model_name)
For a given q array calculate the reflectivity of all four spin channels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q_array
|
np.ndarray
|
Array of data points to be calculated. |
required |
model_name
|
str
|
The model name. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, np.ndarray]
|
Reflectivity per spin channel, keyed 'pp', 'pm', 'mp', 'mm' (in that order). |
Source code in src/easyreflectometry/calculators/wrapper_base.py
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 | |
magnetic_sld_profile(model_name)
Return the nuclear and magnetic scattering length density profiles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str
|
The model name. |
required |
Returns:
| Type | Description |
|---|---|
z, sld(z), magnetic sld rhoM(z) and magnetic angle thetaM(z).
|
|
Source code in src/easyreflectometry/calculators/wrapper_base.py
430 431 432 433 434 435 436 437 438 439 440 441 442 | |
CalculatorBase
Bases: SerializerComponent
This class is a template and defines all properties that a calculator should have.
Source code in src/easyreflectometry/calculators/calculator_base.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | |
supports_magnetism
property
Whether this calculator backend can model magnetic samples.
include_magnetism
property
writable
Include magnetism.
polarization_channel
property
writable
The spin channel ('pp', 'pm', 'mp' or 'mm') used by reflectity_profile when magnetism is enabled.
Note: this state belongs to the currently-active calculator instance; switching calculators via the factory constructs a fresh instance and resets it.
__init_subclass__(is_abstract=False, **kwargs)
Initialise all subclasses so that they can be created in the factory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cls
|
|
required | |
is_abstract
|
bool
|
Is this a subclass which shouldn't be dded. By default, False. |
False
|
**kwargs
|
Key word arguments. |
{}
|
Source code in src/easyreflectometry/calculators/calculator_base.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
__init__()
Init function.
Source code in src/easyreflectometry/calculators/calculator_base.py
48 49 50 51 | |
reset_storage()
Reset the storage area of the calculator.
Source code in src/easyreflectometry/calculators/calculator_base.py
53 54 55 | |
create(model)
Creation function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Material | Layer | Multilayer | Model
|
Object to be created. |
required |
Source code in src/easyreflectometry/calculators/calculator_base.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
assign_material_to_layer(material_id, layer_id)
Assign a material to a layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
material_id
|
str
|
The material name. |
required |
layer_id
|
str
|
The layer name. |
required |
Source code in src/easyreflectometry/calculators/calculator_base.py
132 133 134 135 136 137 138 139 140 141 142 | |
add_layer_to_item(layer_id, item_id)
Add a layer to the item stack.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_id
|
str
|
The item id. |
required |
layer_id
|
str
|
The layer id. |
required |
Source code in src/easyreflectometry/calculators/calculator_base.py
144 145 146 147 148 149 150 151 152 153 154 | |
remove_layer_from_item(layer_id, item_id)
Remove a layer from an item stack.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_id
|
str
|
The item id. |
required |
layer_id
|
str
|
The layer id. |
required |
Source code in src/easyreflectometry/calculators/calculator_base.py
156 157 158 159 160 161 162 163 164 165 166 | |
add_item_to_model(item_id, model_id)
Add a layer to the item stack.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_id
|
str
|
The item id. |
required |
model_id
|
str
|
The model id. |
required |
Source code in src/easyreflectometry/calculators/calculator_base.py
168 169 170 171 172 173 174 175 176 177 178 | |
remove_item_from_model(item_id, model_id)
Remove an item from the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_id
|
str
|
The item id. |
required |
model_id
|
str
|
The model id. |
required |
Source code in src/easyreflectometry/calculators/calculator_base.py
180 181 182 183 184 185 186 187 188 189 190 | |
reflectity_profile(x_array, model_id)
Determines the reflectivity profile for the given range and model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x_array
|
np.ndarray
|
Points to be calculated at. |
required |
model_id
|
str
|
The model id. |
required |
Source code in src/easyreflectometry/calculators/calculator_base.py
192 193 194 195 196 197 198 199 200 201 202 | |
reflectivity_profile_channel(x_array, model_id, channel)
Determine the reflectivity profile of one explicit spin channel.
Unlike polarization_channel (global calculator state), the channel is an
argument, so several channels can be evaluated against the same model —
one per dataset in a simultaneous multi-channel fit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x_array
|
np.ndarray
|
Points to be calculated at. |
required |
model_id
|
str
|
The model id. |
required |
channel
|
PolarizationChannel | str
|
One of 'pp', 'pm', 'mp', 'mm' (or the corresponding enum member). |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
Reflectivity of the requested channel at q. |
Source code in src/easyreflectometry/calculators/calculator_base.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | |
polarized_reflectivity_profiles(x_array, model_id)
Determines the reflectivity profiles of all four spin channels for the given range and model.
Requires include_magnetism to be enabled and a calculator that supports it (refl1d).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x_array
|
np.ndarray
|
Points to be calculated at. |
required |
model_id
|
str
|
The model id. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, np.ndarray]
|
Reflectivity per spin channel, keyed 'pp', 'pm', 'mp', 'mm' (in that order). |
Source code in src/easyreflectometry/calculators/calculator_base.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | |
sld_profile(model_id)
Return the scattering length density profile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
The model id. |
required |
Returns:
| Type | Description |
|---|---|
tuple[np.ndarray, np.ndarray]
|
z and sld(z). |
Source code in src/easyreflectometry/calculators/calculator_base.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 | |
magnetic_sld_profile(model_id)
Return the nuclear and magnetic scattering length density profiles.
Requires include_magnetism to be enabled and a calculator that supports it (refl1d).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
The model id. |
required |
Returns:
| Type | Description |
|---|---|
tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]
|
z, sld(z), magnetic sld rhoM(z) and magnetic angle thetaM(z). |
Source code in src/easyreflectometry/calculators/calculator_base.py
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | |
set_resolution_function(resolution_function)
Set resolution function.
Source code in src/easyreflectometry/calculators/calculator_base.py
278 279 280 | |
remove_layer_magnetism(layer_id)
Remove the magnetic state of one layer; disables include_magnetism
when no magnetic layer is left.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer_id
|
str
|
The layer id. |
required |
Source code in src/easyreflectometry/calculators/calculator_base.py
287 288 289 290 291 292 293 294 295 296 | |