model
DEFAULTS = {'scale': {'description': 'Scaling of the reflectomety profile', 'url': 'https://github.com/reflectivity/edu_outreach/blob/master/refl_maths/paper.tex', 'value': 1.0, 'min': 0, 'max': np.inf, 'fixed': True}, 'background': {'description': 'Linear background to include in reflectometry data', 'url': 'https://github.com/reflectivity/edu_outreach/blob/master/refl_maths/paper.tex', 'value': 1e-08, 'min': 0.0, 'max': np.inf, 'fixed': True}, 'resolution': {'value': 5.0}}
module-attribute
COLORS = ['#0173B2', '#DE8F05', '#029E73', '#D55E00', '#CC78BC', '#CA9161', '#FBAFE4', '#949494', '#ECE133', '#56B4E9']
module-attribute
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
11 12 13 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 | |
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.
Sample
Bases: BaseCollection
A sample is a collection of assemblies that represent the structure for which experimental measurements exist.
Source code in src/easyreflectometry/sample/collections/sample.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 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 | |
superphase
property
The superphase of the sample.
subphase
property
The subphase of the sample.
__init__(*assemblies, name='EasySample', interface=None, unique_name=None, populate_if_none=True, **kwargs)
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
|
{}
|
|
populate_if_none
|
bool
|
By default, True. |
True
|
unique_name
|
Optional[str]
|
By default, None. |
None
|
*assemblies
|
Optional[List[BaseAssembly]]
|
|
()
|
args
|
The assemblies in the sample. |
required | |
name
|
str
|
Name of the sample. By default, 'EasySample'. |
'EasySample'
|
interface
|
Calculator interface. By default, None. |
None
|
Source code in src/easyreflectometry/sample/collections/sample.py
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 | |
add_assembly(assembly=None)
Add an assembly to the sample.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
assembly
|
Optional[BaseAssembly]
|
Assembly to add. By default, None. |
None
|
Source code in src/easyreflectometry/sample/collections/sample.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
duplicate_assembly(index)
Add an assembly to the sample.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
|
required |
assembly
|
Assembly to add. |
required |
Source code in src/easyreflectometry/sample/collections/sample.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
move_up(index)
Move the assembly at the given index up in the sample.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
Index of the assembly to move up. |
required |
Source code in src/easyreflectometry/sample/collections/sample.py
118 119 120 121 122 123 124 125 126 | |
move_down(index)
Move the assembly at the given index down in the sample.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
Index of the assembly to move down. |
required |
Source code in src/easyreflectometry/sample/collections/sample.py
128 129 130 131 132 133 134 135 136 | |
remove_assembly(index)
Remove the assembly at the given index from the sample.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
Index of the assembly to remove. |
required |
Source code in src/easyreflectometry/sample/collections/sample.py
138 139 140 141 142 143 144 145 146 | |
BaseCore
Bases: ModelBase
Local base class for sample-tree objects (Material, Layer, assemblies).
Built on top of easyscience.base_classes.ModelBase (the replacement for
the deprecated ObjBase). On top of ModelBase this class adds:
- a
nameproperty - an
interfaceproperty whose setter propagates the calculator interface to child objects and (re)generates bindings - a yaml-formatted
__repr__driven by an abstract_dict_repr - an
_get_linkable_attributescompatibility shim used by the calculator'sInterfaceFactoryTemplate.generate_bindings - an
as_dictalias forto_dict
Subclass __init__ convention:
1. Build child Parameters / sub-objects.
2. Call super().__init__(name=..., unique_name=...).
3. Assign children to backing fields (self._sld = sld etc.) or pass
them as **kwargs to this base class (transitional path; each
kwarg is stored as a plain instance attribute).
4. Last: self.interface = interface (triggers generate_bindings).
Source code in src/easyreflectometry/sample/base_core.py
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 | |
interface
property
writable
The calculator interface attached to this object (may be None).
name
property
writable
Common (display-friendly) name.
generate_bindings()
Propagate the interface to child objects, then bind via the calculator.
We propagate to any child whose class advertises an interface property
with a setter. That includes both the new BaseCore-based children and
legacy BasedBase-derived collections (which extend SerializerComponent,
not NewBase).
Source code in src/easyreflectometry/sample/base_core.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
get_parameters()
Compatibility shim for legacy callers; prefer :meth:get_all_parameters.
Source code in src/easyreflectometry/sample/base_core.py
162 163 164 | |
get_all_variables()
Discover Parameters/Descriptors across both class-level and instance-level attrs.
ModelBase.get_all_variables walks dir(self), which NewBase restricts
to class attributes only. During the transition some subclasses still
store child Parameters as plain instance attributes (see the kwargs path
in :meth:__init__); those are invisible to dir(). We therefore also
scan self.__dict__ for DescriptorBase instances and for child
ModelBase objects whose own get_all_variables we recurse into.
Source code in src/easyreflectometry/sample/base_core.py
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 | |
to_dict(skip=None)
Serialize, skipping the calculator interface and unique_name by default.
The calculator (CalculatorFactory) is not serializable and is not part
of the model's persistent state — round-trip code that needs it back
reattaches it after from_dict. The legacy ObjBase-based pipeline
achieved the same by never including interface in its _kwargs
encoding; we replicate that here.
unique_name is also stripped by default, matching the legacy
BasedBase.as_dict contract. The installed SerializerBase does not
propagate per-object _default_unique_name to nested children — if
we leave it in, child Parameters end up with explicit unique_names in
the dict (e.g. Parameter_0) that subsequently collide on reload when
the global counter restarts from 0.
Pass a copy of skip to super since NewBase.to_dict mutates the
list (appends unique_name / display_name if those are default).
Source code in src/easyreflectometry/sample/base_core.py
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 | |
as_dict(skip=None)
Compatibility alias for :meth:to_dict.
Source code in src/easyreflectometry/sample/base_core.py
228 229 230 | |
__repr__()
Yaml-formatted multi-line string built from :attr:_dict_repr.
Source code in src/easyreflectometry/sample/base_core.py
238 239 240 | |
PercentageFwhm
Bases: ResolutionFunction
Source code in src/easyreflectometry/model/resolution_functions.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
__init__(constant=None)
Init function.
Source code in src/easyreflectometry/model/resolution_functions.py
60 61 62 63 64 | |
smearing(q)
Return per-point sigma values from the constant FWHM percentage.
constant is a FWHM percentage of q; it is converted to an
absolute sigma so the smearing() contract is sigma for all types.
Source code in src/easyreflectometry/model/resolution_functions.py
66 67 68 69 70 71 72 73 74 | |
as_dict(skip=None)
As dict.
Source code in src/easyreflectometry/model/resolution_functions.py
76 77 78 79 80 | |
ResolutionFunction
Source code in src/easyreflectometry/model/resolution_functions.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
smearing(q)
abstractmethod
Return the resolution as sigma (standard deviation) at each q.
Source code in src/easyreflectometry/model/resolution_functions.py
35 36 37 38 | |
from_dict(data)
classmethod
Smearing function.
Source code in src/easyreflectometry/model/resolution_functions.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
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 | |
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 | |
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
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | |
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
172 173 174 175 176 177 178 179 180 181 182 183 | |
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
185 186 187 188 189 190 191 192 193 194 195 196 197 | |
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
225 226 227 228 229 230 231 232 233 | |
to_dict(skip=None)
Serialize the model, encoding the resolution function and interface name.
Source code in src/easyreflectometry/model/model.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 | |
as_dict(skip=None)
Compatibility alias for :meth:to_dict.
Source code in src/easyreflectometry/model/model.py
273 274 275 | |
as_orso()
Convert the model to a dictionary suitable for ORSO.
Source code in src/easyreflectometry/model/model.py
277 278 279 | |
from_dict(passed_dict)
classmethod
Create a Model from a dictionary.
Source code in src/easyreflectometry/model/model.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | |
apply_default_limits(parameter, kind)
Apply default min/max to a parameter if current bounds are infinite.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parameter
|
Parameter
|
The parameter to adjust. |
required |
kind
|
str
|
One of 'thickness', 'roughness', 'sld', 'isld', 'scale'. |
required |
Source code in src/easyreflectometry/limits.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | |
get_as_parameter(name, value, default_dict, unique_name_prefix=None)
This function creates a parameter for the variable name.
A parameter has a value and metadata.
If the value already is a parameter, it is returned. If the value is a number, a parameter is created with this value and metadata from the dictionary. If the value is None, a parameter is created with the default value and metadata from the dictionary.
param value: The value to use for the parameter. If None, the default value in the dictionary is used.
param name: The name of the parameter
param default_dict: Dictionary with entry for `name` containing the default value and metadata for the parameter
Source code in src/easyreflectometry/utils.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 | |