sample_model
BackgroundModel
Bases: ModelBase
BackgroundModel represents a model of the background in an experiment at various Q.
Source code in src/easydynamics/sample_model/background_model.py
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 | |
__init__(display_name='MyBackgroundModel', unique_name=None, unit='meV', components=None, Q=None)
Initialize the BackgroundModel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
display_name
|
str | None
|
Display name of the model. |
'MyBackgroundModel'
|
unique_name
|
str | None
|
Unique name of the model. If None, a unique name will be generated. |
None
|
unit
|
str | sc.Unit
|
Unit of the model. |
'meV'
|
components
|
ModelComponent | ComponentCollection | None
|
Template components of the model. If None, no components are added. These components are copied into ComponentCollections for each Q value. |
None
|
Q
|
Q_type | None
|
Q values for the model. If None, Q is not set. |
None
|
Source code in src/easydynamics/sample_model/background_model.py
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 | |
ComponentCollection
Bases: EasyDynamicsList, EasyDynamicsModelBase
Collection of model components.
Examples:
Create a ComponentCollection with two components:
>>> import easydynamics.sample_model as sm
>>> component1 = sm.Gaussian(name='Gaussian1', area=1.0, width=1.0)
>>> component2 = sm.Lorentzian(name='Lorentzian1', area=2.0, width=0.5)
>>> collection = sm.ComponentCollection(components=[component1, component2])
Append a component to the collection:
>>> component3 = sm.Gaussian(name='Gaussian2', area=0.5, width=0.8)
>>> collection.append(component3)
Evaluate the collection at a given energy axis:
>>> import numpy as np
>>> x = np.linspace(-5, 5, 100)
>>> values = collection.evaluate(x)
Remove a component by name:
>>> collection.remove('Gaussian1')
List component names:
>>> collection.list_component_names()
['Lorentzian1', 'Gaussian2']
Source code in src/easydynamics/sample_model/component_collection.py
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 | |
is_empty
property
writable
Check if the ComponentCollection has no components.
Returns:
| Type | Description |
|---|---|
bool
|
True if the collection has no components, False otherwise. |
__init__(components=None, unit='meV', name='ComponentCollection', display_name=None, unique_name=None)
Initialize a new ComponentCollection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
components
|
ModelComponent | list[ModelComponent] | None
|
Initial model components to add to the ComponentCollection. |
None
|
unit
|
str | sc.Unit
|
Unit of the collection. |
'meV'
|
name
|
str
|
Name of the collection. |
'ComponentCollection'
|
display_name
|
str | None
|
Display name of the collection. |
None
|
unique_name
|
str | None
|
Unique name of the collection. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If unit is not a string or sc.Unit, or if components is not a list of ModelComponent. |
Source code in src/easydynamics/sample_model/component_collection.py
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 | |
convert_unit(unit)
Convert the unit of the ComponentCollection and all its components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The target unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If unit is not a string or sc.Unit. |
Exception
|
If any component cannot be converted to the specified unit. |
Source code in src/easydynamics/sample_model/component_collection.py
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 | |
append_component(component)
Append a model component or the components from another ComponentCollection to this ComponentCollection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
component
|
ModelComponent | ComponentCollection
|
The component to append. If a ComponentCollection is provided, all of its components will be appended. |
required |
Source code in src/easydynamics/sample_model/component_collection.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | |
list_component_names()
List the names of all components in the model.
Returns:
| Type | Description |
|---|---|
list[str]
|
List of names of the components in the collection. |
Source code in src/easydynamics/sample_model/component_collection.py
200 201 202 203 204 205 206 207 208 209 210 | |
normalize_area()
Normalize the areas of all components so they sum to 1.
This is useful for convolutions.
Raises:
| Type | Description |
|---|---|
ValueError
|
If there are no components in the model or if the total area is zero or not finite, which would prevent normalization. |
Source code in src/easydynamics/sample_model/component_collection.py
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 | |
get_all_variables()
Get all parameters from the model component.
Returns:
| Type | Description |
|---|---|
list[DescriptorBase]
|
List of parameters in the component. |
Source code in src/easydynamics/sample_model/component_collection.py
255 256 257 258 259 260 261 262 263 264 265 | |
evaluate(x)
Evaluate the sum of all components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
Energy axis. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
Evaluated model values. |
Source code in src/easydynamics/sample_model/component_collection.py
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | |
evaluate_component(x, name)
Evaluate a single component by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
Energy axis. |
required |
name
|
str
|
Component name. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If there are no components in the model. |
TypeError
|
If name is not a string. |
KeyError
|
If no component with the given name exists in the collection. |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
Evaluated values for the specified component. |
Source code in src/easydynamics/sample_model/component_collection.py
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 | |
fix_all_parameters()
Fix all free parameters in the model.
Source code in src/easydynamics/sample_model/component_collection.py
329 330 331 332 | |
free_all_parameters()
Free all fixed parameters in the model.
Source code in src/easydynamics/sample_model/component_collection.py
334 335 336 337 | |
__contains__(item)
Check if a component with the given name or instance exists in the ComponentCollection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
str | ModelComponent
|
The component name or instance to check for. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the component exists, False otherwise. |
Source code in src/easydynamics/sample_model/component_collection.py
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 | |
__repr__()
Return a string representation of the ComponentCollection.
Returns:
| Type | Description |
|---|---|
str
|
String representation of the ComponentCollection. |
Source code in src/easydynamics/sample_model/component_collection.py
366 367 368 369 370 371 372 373 374 375 376 377 | |
__copy__()
Create a deep copy of the ComponentCollection.
Returns:
| Type | Description |
|---|---|
ComponentCollection
|
A deep copy of the ComponentCollection. |
Source code in src/easydynamics/sample_model/component_collection.py
417 418 419 420 421 422 423 424 425 426 427 | |
DampedHarmonicOscillator
Bases: CreateParametersMixin, ModelComponent
Model of a Damped Harmonic Oscillator (DHO).
The intensity is given by $$ I(x) = \frac{2 A x_0^2 \gamma}{\pi \left( (x^2 - x_0^2)^2 + (2 \gamma x)^2 \right)}, $$ where \(A\) is the area, \(x_0\) is the center, and \(\gamma\) is the width.
Source code in src/easydynamics/sample_model/components/damped_harmonic_oscillator.py
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 | |
area
property
writable
Get the area parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The area parameter. |
center
property
writable
Get the center parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The center parameter. |
width
property
writable
Get the width parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The width parameter. |
__init__(area=1.0, center=1.0, width=1.0, unit='meV', name='DampedHarmonicOscillator', display_name=None, unique_name=None)
Initialize the Damped Harmonic Oscillator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
area
|
Numeric | Parameter
|
Area under the curve. |
1.0
|
center
|
Numeric | Parameter
|
Resonance frequency, approximately the peak position. |
1.0
|
width
|
Numeric | Parameter
|
Damping constant, approximately the half width at half max (HWHM) of the peaks. By default, 1.0. |
1.0
|
unit
|
str | sc.Unit
|
Unit of the parameters. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'DampedHarmonicOscillator'
|
display_name
|
str | None
|
Display name of the component. |
None
|
unique_name
|
str | None
|
Unique name of the component. If None, a unique_name is automatically generated. By default, None. |
None
|
Source code in src/easydynamics/sample_model/components/damped_harmonic_oscillator.py
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 | |
evaluate(x)
Evaluate the Damped Harmonic Oscillator at the given x values.
If x is a scipp Variable, the unit of the DHO will be converted to match x. The intensity is given by $$ I(x) = \frac{2 A x_0^2 \gamma}{\pi \left( (x^2 - x_0^2)^2 + (2 \gamma x)^2 \right)}, $$ where \(A\) is the area, \(x_0\) is the center, and \(\gamma\) is the width.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the DHO. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The intensity of the DHO at the given x values. |
Source code in src/easydynamics/sample_model/components/damped_harmonic_oscillator.py
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 | |
__repr__()
Return a string representation of the Damped Harmonic Oscillator.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Damped Harmonic Oscillator. |
Source code in src/easydynamics/sample_model/components/damped_harmonic_oscillator.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | |
DeltaFunction
Bases: CreateParametersMixin, ModelComponent
Delta function.
Evaluates to zero everywhere, except in convolutions, where it acts as an identity. This is handled by the Convolution method. If the center is not provided, it will be centered at 0 and fixed, which is typically what you want in QENS.
Source code in src/easydynamics/sample_model/components/delta_function.py
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 | |
area
property
writable
Get the area parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The area parameter. |
center
property
writable
Get the center parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The center parameter. |
__init__(center=None, area=1.0, unit='meV', name='DeltaFunction', display_name=None, unique_name=None)
Initialize the Delta function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
center
|
Numeric | Parameter | None
|
Center of the delta function. If None, it will be centered at 0 and fixed. |
None
|
area
|
Numeric | Parameter
|
Total area under the curve. |
1.0
|
unit
|
str | sc.Unit
|
Unit of the parameters. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'DeltaFunction'
|
display_name
|
str | None
|
Display name of the component. |
None
|
unique_name
|
str | None
|
Unique name of the component. If None, a unique_name is automatically generated. By default, None. |
None
|
Source code in src/easydynamics/sample_model/components/delta_function.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 | |
evaluate(x)
Evaluate the Delta function at the given x values.
The Delta function evaluates to zero everywhere, except at the center. Its numerical integral is equal to the area. It acts as an identity in convolutions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the Delta function. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The evaluated Delta function at the given x values. |
Source code in src/easydynamics/sample_model/components/delta_function.py
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 | |
__repr__()
Return a string representation of the Delta function.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Delta function. |
Source code in src/easydynamics/sample_model/components/delta_function.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
Exponential
Bases: CreateParametersMixin, ModelComponent
Model of an exponential function.
The intensity is given by
where \(A\) is the amplitude, \(x_0\) is the center, and \(B\) describes the rate of decay or growth.
Source code in src/easydynamics/sample_model/components/exponential.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 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 | |
amplitude
property
writable
Get the amplitude parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The amplitude parameter. |
center
property
writable
Get the center parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The center parameter. |
rate
property
writable
Get the rate parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The rate parameter. |
__init__(amplitude=1.0, center=None, rate=1.0, unit='meV', name='Exponential', display_name=None, unique_name=None)
Initialize the Exponential component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
amplitude
|
Numeric | Parameter
|
Amplitude of the Exponential. |
1.0
|
center
|
Numeric | Parameter | None
|
Center of the Exponential. If None, the center is fixed at 0. |
None
|
rate
|
Numeric | Parameter
|
Decay or growth constant of the Exponential. |
1.0
|
unit
|
str | sc.Unit
|
Unit of the parameters. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'Exponential'
|
display_name
|
str | None
|
Display name of the component. |
None
|
unique_name
|
str | None
|
Unique name of the component. If None, a unique_name is automatically generated. By default, None. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If amplitude, center, or rate are not numbers or Parameters. |
ValueError
|
If amplitude, center or rate are not finite numbers. |
Source code in src/easydynamics/sample_model/components/exponential.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 | |
evaluate(x)
Evaluate the Exponential at the given x values.
If x is a scipp Variable, the unit of the Exponential will be converted to match x. The intensity is given by $$ I(x) = A \exp\left( r (x - x_0) \right) $$
where \(A\) is the amplitude, \(x_0\) is the center, and \(r\) is the rate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the Exponential. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The intensity of the Exponential at the given x values. |
Source code in src/easydynamics/sample_model/components/exponential.py
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 | |
convert_unit(unit)
Convert the unit of the Parameters in the component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The new unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If unit is not a string or sc.Unit. |
Exception
|
If conversion fails for any parameter. |
Source code in src/easydynamics/sample_model/components/exponential.py
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 | |
__repr__()
Return a string representation of the Exponential.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Exponential. |
Source code in src/easydynamics/sample_model/components/exponential.py
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | |
ExpressionComponent
Bases: ModelComponent
Model component defined by a symbolic expression.
Source code in src/easydynamics/sample_model/components/expression_component.py
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 | |
expression
property
writable
Return the original expression string.
Returns:
| Type | Description |
|---|---|
str
|
The original expression string provided at initialization. |
__init__(expression, parameters=None, unit='meV', name='Expression', display_name=None, unique_name=None)
Initialize the ExpressionComponent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expression
|
str
|
The symbolic expression as a string. Must contain 'x' as the independent variable. |
required |
parameters
|
dict[str, Numeric] | None
|
Dictionary of parameter names and their initial values. |
None
|
unit
|
str | sc.Unit
|
Unit of the output. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'Expression'
|
display_name
|
str | None
|
Display name for the component. |
None
|
unique_name
|
str | None
|
Unique name for the component. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the expression is invalid or does not contain 'x'. |
TypeError
|
If any parameter value is not numeric. |
Examples:
>>> expr = ExpressionComponent(
... 'A * exp(-(x - x0)**2 / (2*sigma**2))',
... parameters={'A': 10, 'x0': 0, 'sigma': 1},
... unit='meV',
... display_name='Gaussian Peak',
... )
>>> expr.A = 5
>>> y = expr.evaluate(x)
Source code in src/easydynamics/sample_model/components/expression_component.py
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 | |
evaluate(x)
Evaluate the expression for given x values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
Input values for the independent variable. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
Evaluated results. |
Source code in src/easydynamics/sample_model/components/expression_component.py
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 | |
get_all_variables()
Return all parameters.
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
List of all parameters in the expression. |
Source code in src/easydynamics/sample_model/components/expression_component.py
267 268 269 270 271 272 273 274 275 276 | |
convert_unit(_new_unit)
Convert the unit of the expression.
Unit conversion is not implemented for ExpressionComponent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
_new_unit
|
str | sc.Unit
|
The new unit to convert to (ignored). |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always raised to indicate unit conversion is not supported. |
Source code in src/easydynamics/sample_model/components/expression_component.py
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | |
__getattr__(name)
Allow access to parameters as attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the parameter to access. |
required |
Raises:
| Type | Description |
|---|---|
AttributeError
|
If the parameter does not exist. |
Returns:
| Type | Description |
|---|---|
Parameter
|
The parameter with the given name. |
Source code in src/easydynamics/sample_model/components/expression_component.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 | |
__setattr__(name, value)
Allow setting parameter values as attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the parameter to set. |
required |
value
|
Numeric
|
New value for the parameter. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the value is not numeric. |
Source code in src/easydynamics/sample_model/components/expression_component.py
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 | |
__dir__()
Include parameter names in dir() output for better IDE support.
Returns:
| Type | Description |
|---|---|
list[str]
|
List of attribute names, including parameters. |
Source code in src/easydynamics/sample_model/components/expression_component.py
351 352 353 354 355 356 357 358 359 360 | |
__repr__()
Return a string representation of the ExpressionComponent.
Returns:
| Type | Description |
|---|---|
str
|
String representation of the ExpressionComponent. |
Source code in src/easydynamics/sample_model/components/expression_component.py
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | |
Gaussian
Bases: CreateParametersMixin, ModelComponent
Model of a Gaussian function.
The intensity is given by
$$ I(x) = \frac{A}{\sigma \sqrt{2\pi}} \exp\left( -\frac{1}{2} \left(\frac{x - x_0}{\sigma}\right)^2 \right) $$
where \(A\) is the area, \(x_0\) is the center, and \(\sigma\) is the width.
If the center is not provided, it will be centered at 0 and fixed, which is typically what you want in QENS.
Source code in src/easydynamics/sample_model/components/gaussian.py
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 | |
area
property
writable
Get the area parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The area parameter. |
center
property
writable
Get the center parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The center parameter. |
width
property
writable
Get the width parameter (standard deviation).
Returns:
| Type | Description |
|---|---|
Parameter
|
The width parameter. |
__init__(area=1.0, center=None, width=1.0, unit='meV', name='Gaussian', display_name=None, unique_name=None)
Initialize the Gaussian component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
area
|
Numeric | Parameter
|
Area of the Gaussian. |
1.0
|
center
|
Numeric | Parameter | None
|
Center of the Gaussian. If None. |
None
|
width
|
Numeric | Parameter
|
Standard deviation. |
1.0
|
unit
|
str | sc.Unit
|
Unit of the parameters. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'Gaussian'
|
display_name
|
str | None
|
Name of the component. |
None
|
unique_name
|
str | None
|
Unique name of the component. if None, a unique_name is automatically generated. By default, None. |
None
|
Source code in src/easydynamics/sample_model/components/gaussian.py
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 | |
evaluate(x)
Evaluate the Gaussian at the given x values.
If x is a scipp Variable, the unit of the Gaussian will be converted to match x. The intensity is given by $$ I(x) = \frac{A}{\sigma \sqrt{2\pi}} \exp\left( -\frac{1}{2} \left(\frac{x - x_0}{\sigma}\right)^2 \right) $$
where \(A\) is the area, \(x_0\) is the center, and \(\sigma\) is the width.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the Gaussian. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The intensity of the Gaussian at the given x values. |
Source code in src/easydynamics/sample_model/components/gaussian.py
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 | |
__repr__()
Return a string representation of the Gaussian.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Gaussian. |
Source code in src/easydynamics/sample_model/components/gaussian.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
Lorentzian
Bases: CreateParametersMixin, ModelComponent
Model of a Lorentzian function.
The intensity is given by $$ I(x) = \frac{A}{\pi} \frac{\Gamma}{(x - x_0)^2 + \Gamma^2}, $$ where \(A\) is the area, \(x_0\) is the center, and \(\Gamma\) is the half width at half maximum (HWHM).
If the center is not provided, it will be centered at 0 and fixed, which is typically what you want in QENS.
Source code in src/easydynamics/sample_model/components/lorentzian.py
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 | |
area
property
writable
Get the area parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The area parameter. |
center
property
writable
Get the center parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The center parameter. |
width
property
writable
Get the width parameter (HWHM).
Returns:
| Type | Description |
|---|---|
Parameter
|
The width parameter. |
__init__(area=1.0, center=None, width=1.0, unit='meV', name='Lorentzian', display_name=None, unique_name=None)
Initialize the Lorentzian component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
area
|
Numeric | Parameter
|
Area of the Lorentzian. |
1.0
|
center
|
Numeric | Parameter | None
|
Center of the Lorentzian. If None, defaults to 0 and is fixed. |
None
|
width
|
Numeric | Parameter
|
Half width at half maximum (HWHM). |
1.0
|
unit
|
str | sc.Unit
|
Unit of the parameters. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'Lorentzian'
|
display_name
|
str | None
|
Display name for the component. |
None
|
unique_name
|
str | None
|
Unique name of the component. If None, a unique_name is automatically generated. By default, None. |
None
|
Source code in src/easydynamics/sample_model/components/lorentzian.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 | |
evaluate(x)
Evaluate the Lorentzian at the given x values.
If x is a scipp Variable, the unit of the Lorentzian will be converted to match x. The intensity is given by
where \(A\) is the area, \(x_0\) is the center, and \(\Gamma\) is the half width at half maximum (HWHM).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the Lorentzian. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The intensity of the Lorentzian at the given x values. |
Source code in src/easydynamics/sample_model/components/lorentzian.py
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 | |
__repr__()
Return a string representation of the Lorentzian.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Lorentzian. |
Source code in src/easydynamics/sample_model/components/lorentzian.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
Polynomial
Bases: ModelComponent
Polynomial function component.
The intensity is given by $$ I(x) = c_0 + c_1 x + c_2 x^2 + ... + c_N x^N, $$ where \(C_i\) are the coefficients.
Source code in src/easydynamics/sample_model/components/polynomial.py
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 | |
coefficients
property
writable
Get the coefficients of the polynomial as a list of Parameters.
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
The coefficients of the polynomial. |
degree
property
writable
Get the degree of the polynomial.
Returns:
| Type | Description |
|---|---|
int
|
The degree of the polynomial. |
__init__(coefficients=(0.0,), unit='meV', name='Polynomial', display_name=None, unique_name=None)
Initialize the Polynomial component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coefficients
|
Sequence[Numeric | Parameter]
|
Coefficients c0, c1, ..., cN. |
(0.0,)
|
unit
|
str | sc.Unit
|
Unit of the Polynomial component. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'Polynomial'
|
display_name
|
str | None
|
Display name of the Polynomial component. |
None
|
unique_name
|
str | None
|
Unique name of the component. If None, a unique_name is automatically generated. By default, None. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If coefficients is not a sequence of numbers or Parameters or if any item in coefficients is not a number or Parameter. |
ValueError
|
If coefficients is an empty sequence. |
Source code in src/easydynamics/sample_model/components/polynomial.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 | |
coefficient_values()
Get the coefficients of the polynomial as a list.
Returns:
| Type | Description |
|---|---|
list[float]
|
The coefficient values of the polynomial. |
Source code in src/easydynamics/sample_model/components/polynomial.py
146 147 148 149 150 151 152 153 154 155 | |
evaluate(x)
Evaluate the Polynomial at the given x values.
The intensity is given by $$ I(x) = c_0 + c_1 x + c_2 x^2 + ... + c_N x^N, $$ where \(C_i\) are the coefficients.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the Polynomial. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The evaluated Polynomial at the given x values. |
Source code in src/easydynamics/sample_model/components/polynomial.py
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 | |
get_all_variables()
Get all variables from the model component.
Returns:
| Type | Description |
|---|---|
list[DescriptorBase]
|
List of variables in the component. |
Source code in src/easydynamics/sample_model/components/polynomial.py
222 223 224 225 226 227 228 229 230 231 | |
convert_unit(unit)
Convert the unit of the polynomial.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The target unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
UnitError
|
If the provided unit is not a string or sc.Unit. |
Source code in src/easydynamics/sample_model/components/polynomial.py
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 | |
__repr__()
Return a string representation of the Polynomial.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Polynomial. |
Source code in src/easydynamics/sample_model/components/polynomial.py
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | |
Voigt
Bases: CreateParametersMixin, ModelComponent
Voigt profile, a convolution of Gaussian and Lorentzian.
If the center is not provided, it will be centered at 0 and fixed, which is typically what you want in QENS.
Use scipy.special.voigt_profile to evaluate the Voigt profile.
Source code in src/easydynamics/sample_model/components/voigt.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 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 | |
area
property
writable
Get the area parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The area parameter. |
center
property
writable
Get the center parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The center parameter. |
gaussian_width
property
writable
Get the Gaussian width parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The Gaussian width parameter. |
lorentzian_width
property
writable
Get the Lorentzian width parameter (HWHM).
Returns:
| Type | Description |
|---|---|
Parameter
|
The Lorentzian width parameter. |
__init__(area=1.0, center=None, gaussian_width=1.0, lorentzian_width=1.0, unit='meV', name='Voigt', display_name=None, unique_name=None)
Initialize a Voigt component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
area
|
Numeric | Parameter
|
Total area under the curve. |
1.0
|
center
|
Numeric | Parameter | None
|
Center of the Voigt profile. |
None
|
gaussian_width
|
Numeric | Parameter
|
Standard deviation of the Gaussian part. |
1.0
|
lorentzian_width
|
Numeric | Parameter
|
Half width at half max (HWHM) of the Lorentzian part. |
1.0
|
unit
|
str | sc.Unit
|
Unit of the parameters. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'Voigt'
|
display_name
|
str | None
|
Display name of the component. |
None
|
unique_name
|
str | None
|
Unique name of the component. If None, a unique_name is automatically generated. By default, None. |
None
|
Source code in src/easydynamics/sample_model/components/voigt.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 | |
evaluate(x)
Evaluate the Voigt at the given x values.
If x is a scipp Variable, the unit of the Voigt will be converted to match x. The Voigt evaluates to the convolution of a Gaussian with sigma gaussian_width and a Lorentzian with half width at half max lorentzian_width, centered at center, with area equal to area.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the Voigt. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The intensity of the Voigt at the given x values. |
Source code in src/easydynamics/sample_model/components/voigt.py
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 | |
__repr__()
Return a string representation of the Voigt.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Voigt. |
Source code in src/easydynamics/sample_model/components/voigt.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
BrownianTranslationalDiffusion
Bases: DiffusionModelBase
Model of Brownian translational diffusion, consisting of a Lorentzian function for each Q-value, where the width is given by \(D Q^2\), where \(D\) is the diffusion coefficient. The area of the Lorentzians is given by the scale parameter multiplied by the QISF, which is 1 for this model. The EISF is 0 for this model, so there is no delta function component. Q is assumed to have units of 1/angstrom. Creates ComponentCollections with Lorentzian components for given Q-values.
Examples:
>>> Q=np.linspace(0.5,2,7) >>>energy=np.linspace(-2, 2, 501)
>>> scale = 1.0
>>> diffusion_coefficient = 2.4e-9 # m^2/s
>>> diffusion_model=BrownianTranslationalDiffusion(name="DiffusionModel",
>>> scale=scale, diffusion_coefficient= diffusion_coefficient,)
>>> component_collections = diffusion_model.create_component_collections(Q)
See also the tutorials.
Source code in src/easydynamics/sample_model/diffusion_model/brownian_translational_diffusion.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 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 | |
diffusion_coefficient
property
writable
Get the diffusion coefficient parameter D.
Returns:
| Type | Description |
|---|---|
Parameter
|
Diffusion coefficient D in m^2/s. |
__init__(scale=1.0, diffusion_coefficient=1.0, unit='meV', name='BrownianTranslationalDiffusion', display_name='BrownianTranslationalDiffusion', unique_name=None)
Initialize a new BrownianTranslationalDiffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scale
|
Numeric
|
Scale factor for the diffusion model. Must be a non-negative number. |
1.0
|
diffusion_coefficient
|
Numeric
|
Diffusion coefficient D in m^2/s. |
1.0
|
unit
|
str | sc.Unit
|
Unit of the diffusion model. Must be convertible to meV. |
'meV'
|
name
|
str
|
Name of the diffusion model. |
'BrownianTranslationalDiffusion'
|
display_name
|
str | None
|
Display name of the diffusion model. |
'BrownianTranslationalDiffusion'
|
unique_name
|
str | None
|
Unique name of the diffusion model. If None, a unique name will be generated. By default, None. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If scale or diffusion_coefficient is not a number. |
Source code in src/easydynamics/sample_model/diffusion_model/brownian_translational_diffusion.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 | |
calculate_width(Q)
Calculate the half-width at half-maximum (HWHM) for the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type
|
Scattering vector in 1/angstrom. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
HWHM values in the unit of the model (e.g., meV). |
Source code in src/easydynamics/sample_model/diffusion_model/brownian_translational_diffusion.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
calculate_EISF(Q)
Calculate the Elastic Incoherent Structure Factor (EISF) for the Brownian translational diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type
|
Scattering vector in 1/angstrom. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
EISF values (dimensionless). |
Source code in src/easydynamics/sample_model/diffusion_model/brownian_translational_diffusion.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
calculate_QISF(Q)
Calculate the Quasi-Elastic Incoherent Structure Factor (QISF).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type
|
Scattering vector in 1/angstrom. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
QISF values (dimensionless). |
Source code in src/easydynamics/sample_model/diffusion_model/brownian_translational_diffusion.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | |
create_component_collections(Q, component_name='Brownian diffusion', component_display_name=None)
Create ComponentCollection components for the Brownian translational diffusion model at given Q values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type
|
Scattering vector values. |
required |
component_name
|
str
|
Name of the Brownian diffusion component. |
'Brownian diffusion'
|
component_display_name
|
str | None
|
Display name of the Brownian diffusion component. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If component_display_name is not a string. If component_name is not a string. |
Returns:
| Type | Description |
|---|---|
list[ComponentCollection]
|
List of ComponentCollections with Lorentzian components for each Q value. Each Lorentzian has a width given by \(D*Q^2\) and an area given by the scale parameter multiplied by the QISF (which is 1 for this model). |
Source code in src/easydynamics/sample_model/diffusion_model/brownian_translational_diffusion.py
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 | |
__repr__()
String representation of the BrownianTranslationalDiffusion model.
Returns:
| Type | Description |
|---|---|
str
|
String representation of the BrownianTranslationalDiffusion model. |
Source code in src/easydynamics/sample_model/diffusion_model/brownian_translational_diffusion.py
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | |
InstrumentModel
Bases: NewBase
InstrumentModel represents a model of the instrument in an experiment at various Q.
It can contain a model of the resolution function for convolutions, of the background and an offset in the energy axis.
Source code in src/easydynamics/sample_model/instrument_model.py
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 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 | |
resolution_model
property
writable
Get the resolution model of the instrument.
Returns:
| Type | Description |
|---|---|
ResolutionModel
|
The resolution model of the instrument. |
background_model
property
writable
Get the background model of the instrument.
Returns:
| Type | Description |
|---|---|
BackgroundModel
|
The background model of the instrument. |
Q
property
writable
Get the Q values of the InstrumentModel.
Returns:
| Type | Description |
|---|---|
np.ndarray | None
|
The Q values of the InstrumentModel, or None if not set. |
unit
property
writable
Get the unit of the InstrumentModel.
Returns:
| Type | Description |
|---|---|
str | sc.Unit
|
The unit of the InstrumentModel. |
energy_offset
property
writable
Get the energy offset template parameter of the instrument model.
Returns:
| Type | Description |
|---|---|
Parameter
|
The energy offset template parameter of the instrument model. |
__init__(display_name='MyInstrumentModel', unique_name=None, Q=None, resolution_model=None, background_model=None, energy_offset=None, unit='meV')
Initialize an InstrumentModel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
display_name
|
str
|
The display name of the InstrumentModel. |
'MyInstrumentModel'
|
unique_name
|
str | None
|
The unique name of the InstrumentModel. |
None
|
Q
|
Q_type | None
|
The Q values where the instrument is modelled. |
None
|
resolution_model
|
ResolutionModel | None
|
The resolution model of the instrument. If None, an empty resolution model is created and no resolution convolution is carried out. |
None
|
background_model
|
BackgroundModel | None
|
The background model of the instrument. If None, an empty background model is created, and the background evaluates to 0. |
None
|
energy_offset
|
Numeric | None
|
Template energy offset of the instrument. Will be copied to each Q value. If None, the energy offset will be 0. |
None
|
unit
|
str | sc.Unit
|
The unit of the energy axis. |
'meV'
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If resolution_model is not a ResolutionModel or None, or if background_model is not a BackgroundModel or None, or if energy_offset is not a number or None. |
Source code in src/easydynamics/sample_model/instrument_model.py
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 | |
clear_Q(confirm=False)
Clear the Q values of the InstrumentModel and any associated ResolutionModel and BackgroundModel, removing all component collections and their associated Parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
confirm
|
bool
|
Confirmation to clear Q values. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If confirm is not True. |
Source code in src/easydynamics/sample_model/instrument_model.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | |
convert_unit(unit_str)
Convert the unit of the InstrumentModel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit_str
|
str | sc.Unit
|
The unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If unit_str is not a valid unit string or scipp Unit. |
Source code in src/easydynamics/sample_model/instrument_model.py
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 | |
get_all_variables(Q_index=None)
Get all variables in the InstrumentModel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the Q value to get variables for. If None, get variables for all Q values. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If Q_index is not an int or None. |
IndexError
|
If Q_index is out of bounds for the Q values in the InstrumentModel. |
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all variables in the InstrumentModel. If Q_index is specified, only variables from the ComponentCollection at the given Q index are included. Otherwise, all variables in the InstrumentModel are included. |
Source code in src/easydynamics/sample_model/instrument_model.py
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 | |
fix_resolution_parameters()
Fix all parameters in the resolution model.
Source code in src/easydynamics/sample_model/instrument_model.py
394 395 396 | |
free_resolution_parameters()
Free all parameters in the resolution model.
Source code in src/easydynamics/sample_model/instrument_model.py
398 399 400 | |
normalize_resolution()
Normalize the resolution model to have area 1.
Source code in src/easydynamics/sample_model/instrument_model.py
402 403 404 | |
get_energy_offset(Q_index=None)
Get the energy offset Parameter at a specific Q index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the Q value to get the energy offset for. If None, get the energy offset for all Q values. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If no Q values are set in the InstrumentModel. |
IndexError
|
If Q_index is out of bounds. |
TypeError
|
If Q_index is not an int or None. |
Returns:
| Type | Description |
|---|---|
Parameter | list[Parameter]
|
The energy offset Parameter at the specified Q index, or a list of Parameters if Q_index is None. |
Source code in src/easydynamics/sample_model/instrument_model.py
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 443 444 445 446 | |
fix_energy_offset(Q_index=None)
Fix energy offset parameters.
If Q_index is specified, only fix the energy offset for that Q value. If Q_index is None, fix energy offsets for all Q values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the Q value to fix the energy offset for. If None, fix energy offsets for all Q values. |
None
|
Source code in src/easydynamics/sample_model/instrument_model.py
448 449 450 451 452 453 454 455 456 457 458 459 460 461 | |
free_energy_offset(Q_index=None)
Free energy offset parameters.
If Q_index is specified, only free the energy offset for that Q value. If Q_index is None, free energy offsets for all Q values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the Q value to free the energy offset for. If None, free energy offsets for all Q values. |
None
|
Source code in src/easydynamics/sample_model/instrument_model.py
463 464 465 466 467 468 469 470 471 472 473 474 475 476 | |
__repr__()
Return a string representation of the InstrumentModel.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the InstrumentModel. |
Source code in src/easydynamics/sample_model/instrument_model.py
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 | |
ResolutionModel
Bases: ModelBase
ResolutionModel represents a model of the instrment resolution in an experiment at various Q.
Source code in src/easydynamics/sample_model/resolution_model.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 | |
__init__(display_name='MyResolutionModel', unique_name=None, unit='meV', components=None, Q=None)
Initialize a ResolutionModel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
display_name
|
str
|
Display name of the model. |
'MyResolutionModel'
|
unique_name
|
str | None
|
Unique name of the model. If None, a unique name will be generated. |
None
|
unit
|
str | sc.Unit
|
Unit of the model. |
'meV'
|
components
|
ModelComponent | ComponentCollection | None
|
Template components of the model. If None, no components are added. These components are copied into ComponentCollections for each Q value. |
None
|
Q
|
Q_type | None
|
Q values for the model. If None, Q is not set. |
None
|
Source code in src/easydynamics/sample_model/resolution_model.py
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 | |
append_component(component)
Append a component to the ResolutionModel.
Does not allow DeltaFunction or Polynomial components, as these are not physical resolution components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
component
|
ModelComponent | ComponentCollection
|
Component(s) to append. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the component is a DeltaFunction or Polynomial. |
Source code in src/easydynamics/sample_model/resolution_model.py
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 | |
SampleModel
Bases: ModelBase
SampleModel represents a model of a sample with components and diffusion models, parameterized by Q and optionally temperature. Generates ComponentCollections for each Q value, combining components from the base model and diffusion models.
Applies detailed balancing based on temperature if provided.
Source code in src/easydynamics/sample_model/sample_model.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 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 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 | |
diffusion_models
property
writable
Get the diffusion models of the SampleModel.
Returns:
| Type | Description |
|---|---|
list[DiffusionModelBase]
|
The diffusion models of the SampleModel. |
temperature
property
writable
Get the temperature of the SampleModel.
Returns:
| Type | Description |
|---|---|
Parameter | None
|
The temperature Parameter of the SampleModel, or None if not set. |
temperature_unit
property
writable
Get the temperature unit of the SampleModel.
Returns:
| Type | Description |
|---|---|
str | sc.Unit
|
The unit of the temperature Parameter. |
normalize_detailed_balance
property
writable
Get whether to divide the detailed balance factor by temperature.
Returns:
| Type | Description |
|---|---|
bool
|
True if the detailed balance factor is divided by temperature, False otherwise. |
use_detailed_balance
property
writable
Get whether to apply detailed balance to the model.
Returns:
| Type | Description |
|---|---|
bool
|
True if detailed balance is applied, False otherwise. |
detailed_balance_settings
property
writable
Get the DetailedBalanceSettings of the SampleModel.
Returns:
| Type | Description |
|---|---|
DetailedBalanceSettings
|
The DetailedBalanceSettings of the SampleModel. |
__init__(display_name='MySampleModel', unique_name=None, unit='meV', components=None, Q=None, diffusion_models=None, temperature=None, temperature_unit='K', detailed_balance_settings=None)
Initialize the SampleModel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
display_name
|
str
|
Display name of the model. |
'MySampleModel'
|
unique_name
|
str | None
|
Unique name of the model. If None, a unique name will be generated. |
None
|
unit
|
str | sc.Unit
|
Unit of the model. If None,. |
'meV'
|
components
|
ModelComponent | ComponentCollection | None
|
Template components of the model. If None, no components are added. These components are copied into ComponentCollections for each Q value. |
None
|
Q
|
Q_type | None
|
Q values for the model. If None, Q is not set. |
None
|
diffusion_models
|
DiffusionModelBase | list[DiffusionModelBase] | None
|
Diffusion models to include in the SampleModel. If None, no diffusion models are added. |
None
|
temperature
|
float | None
|
Temperature for detailed balancing. If None, no detailed balancing is applied. By default, None. |
None
|
temperature_unit
|
str | sc.Unit
|
Unit of the temperature. |
'K'
|
detailed_balance_settings
|
DetailedBalanceSettings | None
|
Settings for detailed balancing. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If diffusion_models is not a DiffusionModelBase, a list of DiffusionModelBase, or None, or if temperature is not a number or None, or if detailed_balance_settings is not a DetailedBalanceSettings instance. |
ValueError
|
If temperature is negative. |
Source code in src/easydynamics/sample_model/sample_model.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 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 | |
append_diffusion_model(diffusion_model)
Append a DiffusionModel to the SampleModel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
diffusion_model
|
DiffusionModelBase
|
The DiffusionModel to append. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the diffusion_model is not a DiffusionModelBase. |
Source code in src/easydynamics/sample_model/sample_model.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
remove_diffusion_model(name)
Remove a DiffusionModel from the SampleModel by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the DiffusionModel to remove. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no DiffusionModel with the given name is found. |
Source code in src/easydynamics/sample_model/sample_model.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
clear_diffusion_models()
Clear all DiffusionModels from the SampleModel.
Source code in src/easydynamics/sample_model/sample_model.py
173 174 175 176 | |
convert_temperature_unit(unit)
Convert the unit of the temperature Parameter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The unit to convert the temperature Parameter to. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If temperature is not set or conversion fails. |
Exception
|
If the provided unit is invalid or cannot be converted. |
Source code in src/easydynamics/sample_model/sample_model.py
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 | |
evaluate(x)
Evaluate the sample model at all Q for the given x values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values to evaluate the model at. Can be a number, list, numpy array, scipp Variable, or scipp DataArray. |
required |
Returns:
| Type | Description |
|---|---|
list[np.ndarray]
|
List of evaluated model values for each Q. |
Source code in src/easydynamics/sample_model/sample_model.py
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 | |
get_all_variables(Q_index=None)
Get all Parameters and Descriptors from all ComponentCollections in the SampleModel.
Also includes temperature if set and all variables from diffusion models. Ignores the Parameters and Descriptors in self._components as these are just templates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
If specified, only get variables from the ComponentCollection at the given Q index. If None, get variables from all ComponentCollections. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
List of all Parameters and Descriptors, including temperature if set and all variables from diffusion models. |
Source code in src/easydynamics/sample_model/sample_model.py
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 | |
__repr__()
Return a string representation of the SampleModel.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the SampleModel. |
Source code in src/easydynamics/sample_model/sample_model.py
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 | |
background_model
BackgroundModel
Bases: ModelBase
BackgroundModel represents a model of the background in an experiment at various Q.
Source code in src/easydynamics/sample_model/background_model.py
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 | |
__init__(display_name='MyBackgroundModel', unique_name=None, unit='meV', components=None, Q=None)
Initialize the BackgroundModel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
display_name
|
str | None
|
Display name of the model. |
'MyBackgroundModel'
|
unique_name
|
str | None
|
Unique name of the model. If None, a unique name will be generated. |
None
|
unit
|
str | sc.Unit
|
Unit of the model. |
'meV'
|
components
|
ModelComponent | ComponentCollection | None
|
Template components of the model. If None, no components are added. These components are copied into ComponentCollections for each Q value. |
None
|
Q
|
Q_type | None
|
Q values for the model. If None, Q is not set. |
None
|
Source code in src/easydynamics/sample_model/background_model.py
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 | |
component_collection
ComponentCollection
Bases: EasyDynamicsList, EasyDynamicsModelBase
Collection of model components.
Examples:
Create a ComponentCollection with two components:
>>> import easydynamics.sample_model as sm
>>> component1 = sm.Gaussian(name='Gaussian1', area=1.0, width=1.0)
>>> component2 = sm.Lorentzian(name='Lorentzian1', area=2.0, width=0.5)
>>> collection = sm.ComponentCollection(components=[component1, component2])
Append a component to the collection:
>>> component3 = sm.Gaussian(name='Gaussian2', area=0.5, width=0.8)
>>> collection.append(component3)
Evaluate the collection at a given energy axis:
>>> import numpy as np
>>> x = np.linspace(-5, 5, 100)
>>> values = collection.evaluate(x)
Remove a component by name:
>>> collection.remove('Gaussian1')
List component names:
>>> collection.list_component_names()
['Lorentzian1', 'Gaussian2']
Source code in src/easydynamics/sample_model/component_collection.py
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 | |
is_empty
property
writable
Check if the ComponentCollection has no components.
Returns:
| Type | Description |
|---|---|
bool
|
True if the collection has no components, False otherwise. |
__init__(components=None, unit='meV', name='ComponentCollection', display_name=None, unique_name=None)
Initialize a new ComponentCollection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
components
|
ModelComponent | list[ModelComponent] | None
|
Initial model components to add to the ComponentCollection. |
None
|
unit
|
str | sc.Unit
|
Unit of the collection. |
'meV'
|
name
|
str
|
Name of the collection. |
'ComponentCollection'
|
display_name
|
str | None
|
Display name of the collection. |
None
|
unique_name
|
str | None
|
Unique name of the collection. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If unit is not a string or sc.Unit, or if components is not a list of ModelComponent. |
Source code in src/easydynamics/sample_model/component_collection.py
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 | |
convert_unit(unit)
Convert the unit of the ComponentCollection and all its components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The target unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If unit is not a string or sc.Unit. |
Exception
|
If any component cannot be converted to the specified unit. |
Source code in src/easydynamics/sample_model/component_collection.py
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 | |
append_component(component)
Append a model component or the components from another ComponentCollection to this ComponentCollection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
component
|
ModelComponent | ComponentCollection
|
The component to append. If a ComponentCollection is provided, all of its components will be appended. |
required |
Source code in src/easydynamics/sample_model/component_collection.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | |
list_component_names()
List the names of all components in the model.
Returns:
| Type | Description |
|---|---|
list[str]
|
List of names of the components in the collection. |
Source code in src/easydynamics/sample_model/component_collection.py
200 201 202 203 204 205 206 207 208 209 210 | |
normalize_area()
Normalize the areas of all components so they sum to 1.
This is useful for convolutions.
Raises:
| Type | Description |
|---|---|
ValueError
|
If there are no components in the model or if the total area is zero or not finite, which would prevent normalization. |
Source code in src/easydynamics/sample_model/component_collection.py
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 | |
get_all_variables()
Get all parameters from the model component.
Returns:
| Type | Description |
|---|---|
list[DescriptorBase]
|
List of parameters in the component. |
Source code in src/easydynamics/sample_model/component_collection.py
255 256 257 258 259 260 261 262 263 264 265 | |
evaluate(x)
Evaluate the sum of all components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
Energy axis. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
Evaluated model values. |
Source code in src/easydynamics/sample_model/component_collection.py
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | |
evaluate_component(x, name)
Evaluate a single component by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
Energy axis. |
required |
name
|
str
|
Component name. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If there are no components in the model. |
TypeError
|
If name is not a string. |
KeyError
|
If no component with the given name exists in the collection. |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
Evaluated values for the specified component. |
Source code in src/easydynamics/sample_model/component_collection.py
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 | |
fix_all_parameters()
Fix all free parameters in the model.
Source code in src/easydynamics/sample_model/component_collection.py
329 330 331 332 | |
free_all_parameters()
Free all fixed parameters in the model.
Source code in src/easydynamics/sample_model/component_collection.py
334 335 336 337 | |
__contains__(item)
Check if a component with the given name or instance exists in the ComponentCollection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
str | ModelComponent
|
The component name or instance to check for. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the component exists, False otherwise. |
Source code in src/easydynamics/sample_model/component_collection.py
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 | |
__repr__()
Return a string representation of the ComponentCollection.
Returns:
| Type | Description |
|---|---|
str
|
String representation of the ComponentCollection. |
Source code in src/easydynamics/sample_model/component_collection.py
366 367 368 369 370 371 372 373 374 375 376 377 | |
__copy__()
Create a deep copy of the ComponentCollection.
Returns:
| Type | Description |
|---|---|
ComponentCollection
|
A deep copy of the ComponentCollection. |
Source code in src/easydynamics/sample_model/component_collection.py
417 418 419 420 421 422 423 424 425 426 427 | |
components
DampedHarmonicOscillator
Bases: CreateParametersMixin, ModelComponent
Model of a Damped Harmonic Oscillator (DHO).
The intensity is given by $$ I(x) = \frac{2 A x_0^2 \gamma}{\pi \left( (x^2 - x_0^2)^2 + (2 \gamma x)^2 \right)}, $$ where \(A\) is the area, \(x_0\) is the center, and \(\gamma\) is the width.
Source code in src/easydynamics/sample_model/components/damped_harmonic_oscillator.py
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 | |
area
property
writable
Get the area parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The area parameter. |
center
property
writable
Get the center parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The center parameter. |
width
property
writable
Get the width parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The width parameter. |
__init__(area=1.0, center=1.0, width=1.0, unit='meV', name='DampedHarmonicOscillator', display_name=None, unique_name=None)
Initialize the Damped Harmonic Oscillator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
area
|
Numeric | Parameter
|
Area under the curve. |
1.0
|
center
|
Numeric | Parameter
|
Resonance frequency, approximately the peak position. |
1.0
|
width
|
Numeric | Parameter
|
Damping constant, approximately the half width at half max (HWHM) of the peaks. By default, 1.0. |
1.0
|
unit
|
str | sc.Unit
|
Unit of the parameters. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'DampedHarmonicOscillator'
|
display_name
|
str | None
|
Display name of the component. |
None
|
unique_name
|
str | None
|
Unique name of the component. If None, a unique_name is automatically generated. By default, None. |
None
|
Source code in src/easydynamics/sample_model/components/damped_harmonic_oscillator.py
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 | |
evaluate(x)
Evaluate the Damped Harmonic Oscillator at the given x values.
If x is a scipp Variable, the unit of the DHO will be converted to match x. The intensity is given by $$ I(x) = \frac{2 A x_0^2 \gamma}{\pi \left( (x^2 - x_0^2)^2 + (2 \gamma x)^2 \right)}, $$ where \(A\) is the area, \(x_0\) is the center, and \(\gamma\) is the width.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the DHO. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The intensity of the DHO at the given x values. |
Source code in src/easydynamics/sample_model/components/damped_harmonic_oscillator.py
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 | |
__repr__()
Return a string representation of the Damped Harmonic Oscillator.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Damped Harmonic Oscillator. |
Source code in src/easydynamics/sample_model/components/damped_harmonic_oscillator.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | |
DeltaFunction
Bases: CreateParametersMixin, ModelComponent
Delta function.
Evaluates to zero everywhere, except in convolutions, where it acts as an identity. This is handled by the Convolution method. If the center is not provided, it will be centered at 0 and fixed, which is typically what you want in QENS.
Source code in src/easydynamics/sample_model/components/delta_function.py
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 | |
area
property
writable
Get the area parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The area parameter. |
center
property
writable
Get the center parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The center parameter. |
__init__(center=None, area=1.0, unit='meV', name='DeltaFunction', display_name=None, unique_name=None)
Initialize the Delta function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
center
|
Numeric | Parameter | None
|
Center of the delta function. If None, it will be centered at 0 and fixed. |
None
|
area
|
Numeric | Parameter
|
Total area under the curve. |
1.0
|
unit
|
str | sc.Unit
|
Unit of the parameters. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'DeltaFunction'
|
display_name
|
str | None
|
Display name of the component. |
None
|
unique_name
|
str | None
|
Unique name of the component. If None, a unique_name is automatically generated. By default, None. |
None
|
Source code in src/easydynamics/sample_model/components/delta_function.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 | |
evaluate(x)
Evaluate the Delta function at the given x values.
The Delta function evaluates to zero everywhere, except at the center. Its numerical integral is equal to the area. It acts as an identity in convolutions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the Delta function. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The evaluated Delta function at the given x values. |
Source code in src/easydynamics/sample_model/components/delta_function.py
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 | |
__repr__()
Return a string representation of the Delta function.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Delta function. |
Source code in src/easydynamics/sample_model/components/delta_function.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
Exponential
Bases: CreateParametersMixin, ModelComponent
Model of an exponential function.
The intensity is given by
where \(A\) is the amplitude, \(x_0\) is the center, and \(B\) describes the rate of decay or growth.
Source code in src/easydynamics/sample_model/components/exponential.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 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 | |
amplitude
property
writable
Get the amplitude parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The amplitude parameter. |
center
property
writable
Get the center parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The center parameter. |
rate
property
writable
Get the rate parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The rate parameter. |
__init__(amplitude=1.0, center=None, rate=1.0, unit='meV', name='Exponential', display_name=None, unique_name=None)
Initialize the Exponential component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
amplitude
|
Numeric | Parameter
|
Amplitude of the Exponential. |
1.0
|
center
|
Numeric | Parameter | None
|
Center of the Exponential. If None, the center is fixed at 0. |
None
|
rate
|
Numeric | Parameter
|
Decay or growth constant of the Exponential. |
1.0
|
unit
|
str | sc.Unit
|
Unit of the parameters. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'Exponential'
|
display_name
|
str | None
|
Display name of the component. |
None
|
unique_name
|
str | None
|
Unique name of the component. If None, a unique_name is automatically generated. By default, None. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If amplitude, center, or rate are not numbers or Parameters. |
ValueError
|
If amplitude, center or rate are not finite numbers. |
Source code in src/easydynamics/sample_model/components/exponential.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 | |
evaluate(x)
Evaluate the Exponential at the given x values.
If x is a scipp Variable, the unit of the Exponential will be converted to match x. The intensity is given by $$ I(x) = A \exp\left( r (x - x_0) \right) $$
where \(A\) is the amplitude, \(x_0\) is the center, and \(r\) is the rate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the Exponential. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The intensity of the Exponential at the given x values. |
Source code in src/easydynamics/sample_model/components/exponential.py
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 | |
convert_unit(unit)
Convert the unit of the Parameters in the component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The new unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If unit is not a string or sc.Unit. |
Exception
|
If conversion fails for any parameter. |
Source code in src/easydynamics/sample_model/components/exponential.py
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 | |
__repr__()
Return a string representation of the Exponential.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Exponential. |
Source code in src/easydynamics/sample_model/components/exponential.py
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | |
ExpressionComponent
Bases: ModelComponent
Model component defined by a symbolic expression.
Source code in src/easydynamics/sample_model/components/expression_component.py
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 | |
expression
property
writable
Return the original expression string.
Returns:
| Type | Description |
|---|---|
str
|
The original expression string provided at initialization. |
__init__(expression, parameters=None, unit='meV', name='Expression', display_name=None, unique_name=None)
Initialize the ExpressionComponent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expression
|
str
|
The symbolic expression as a string. Must contain 'x' as the independent variable. |
required |
parameters
|
dict[str, Numeric] | None
|
Dictionary of parameter names and their initial values. |
None
|
unit
|
str | sc.Unit
|
Unit of the output. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'Expression'
|
display_name
|
str | None
|
Display name for the component. |
None
|
unique_name
|
str | None
|
Unique name for the component. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the expression is invalid or does not contain 'x'. |
TypeError
|
If any parameter value is not numeric. |
Examples:
>>> expr = ExpressionComponent(
... 'A * exp(-(x - x0)**2 / (2*sigma**2))',
... parameters={'A': 10, 'x0': 0, 'sigma': 1},
... unit='meV',
... display_name='Gaussian Peak',
... )
>>> expr.A = 5
>>> y = expr.evaluate(x)
Source code in src/easydynamics/sample_model/components/expression_component.py
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 | |
evaluate(x)
Evaluate the expression for given x values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
Input values for the independent variable. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
Evaluated results. |
Source code in src/easydynamics/sample_model/components/expression_component.py
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 | |
get_all_variables()
Return all parameters.
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
List of all parameters in the expression. |
Source code in src/easydynamics/sample_model/components/expression_component.py
267 268 269 270 271 272 273 274 275 276 | |
convert_unit(_new_unit)
Convert the unit of the expression.
Unit conversion is not implemented for ExpressionComponent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
_new_unit
|
str | sc.Unit
|
The new unit to convert to (ignored). |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always raised to indicate unit conversion is not supported. |
Source code in src/easydynamics/sample_model/components/expression_component.py
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | |
__getattr__(name)
Allow access to parameters as attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the parameter to access. |
required |
Raises:
| Type | Description |
|---|---|
AttributeError
|
If the parameter does not exist. |
Returns:
| Type | Description |
|---|---|
Parameter
|
The parameter with the given name. |
Source code in src/easydynamics/sample_model/components/expression_component.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 | |
__setattr__(name, value)
Allow setting parameter values as attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the parameter to set. |
required |
value
|
Numeric
|
New value for the parameter. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the value is not numeric. |
Source code in src/easydynamics/sample_model/components/expression_component.py
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 | |
__dir__()
Include parameter names in dir() output for better IDE support.
Returns:
| Type | Description |
|---|---|
list[str]
|
List of attribute names, including parameters. |
Source code in src/easydynamics/sample_model/components/expression_component.py
351 352 353 354 355 356 357 358 359 360 | |
__repr__()
Return a string representation of the ExpressionComponent.
Returns:
| Type | Description |
|---|---|
str
|
String representation of the ExpressionComponent. |
Source code in src/easydynamics/sample_model/components/expression_component.py
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | |
Gaussian
Bases: CreateParametersMixin, ModelComponent
Model of a Gaussian function.
The intensity is given by
$$ I(x) = \frac{A}{\sigma \sqrt{2\pi}} \exp\left( -\frac{1}{2} \left(\frac{x - x_0}{\sigma}\right)^2 \right) $$
where \(A\) is the area, \(x_0\) is the center, and \(\sigma\) is the width.
If the center is not provided, it will be centered at 0 and fixed, which is typically what you want in QENS.
Source code in src/easydynamics/sample_model/components/gaussian.py
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 | |
area
property
writable
Get the area parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The area parameter. |
center
property
writable
Get the center parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The center parameter. |
width
property
writable
Get the width parameter (standard deviation).
Returns:
| Type | Description |
|---|---|
Parameter
|
The width parameter. |
__init__(area=1.0, center=None, width=1.0, unit='meV', name='Gaussian', display_name=None, unique_name=None)
Initialize the Gaussian component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
area
|
Numeric | Parameter
|
Area of the Gaussian. |
1.0
|
center
|
Numeric | Parameter | None
|
Center of the Gaussian. If None. |
None
|
width
|
Numeric | Parameter
|
Standard deviation. |
1.0
|
unit
|
str | sc.Unit
|
Unit of the parameters. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'Gaussian'
|
display_name
|
str | None
|
Name of the component. |
None
|
unique_name
|
str | None
|
Unique name of the component. if None, a unique_name is automatically generated. By default, None. |
None
|
Source code in src/easydynamics/sample_model/components/gaussian.py
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 | |
evaluate(x)
Evaluate the Gaussian at the given x values.
If x is a scipp Variable, the unit of the Gaussian will be converted to match x. The intensity is given by $$ I(x) = \frac{A}{\sigma \sqrt{2\pi}} \exp\left( -\frac{1}{2} \left(\frac{x - x_0}{\sigma}\right)^2 \right) $$
where \(A\) is the area, \(x_0\) is the center, and \(\sigma\) is the width.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the Gaussian. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The intensity of the Gaussian at the given x values. |
Source code in src/easydynamics/sample_model/components/gaussian.py
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 | |
__repr__()
Return a string representation of the Gaussian.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Gaussian. |
Source code in src/easydynamics/sample_model/components/gaussian.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
Lorentzian
Bases: CreateParametersMixin, ModelComponent
Model of a Lorentzian function.
The intensity is given by $$ I(x) = \frac{A}{\pi} \frac{\Gamma}{(x - x_0)^2 + \Gamma^2}, $$ where \(A\) is the area, \(x_0\) is the center, and \(\Gamma\) is the half width at half maximum (HWHM).
If the center is not provided, it will be centered at 0 and fixed, which is typically what you want in QENS.
Source code in src/easydynamics/sample_model/components/lorentzian.py
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 | |
area
property
writable
Get the area parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The area parameter. |
center
property
writable
Get the center parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The center parameter. |
width
property
writable
Get the width parameter (HWHM).
Returns:
| Type | Description |
|---|---|
Parameter
|
The width parameter. |
__init__(area=1.0, center=None, width=1.0, unit='meV', name='Lorentzian', display_name=None, unique_name=None)
Initialize the Lorentzian component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
area
|
Numeric | Parameter
|
Area of the Lorentzian. |
1.0
|
center
|
Numeric | Parameter | None
|
Center of the Lorentzian. If None, defaults to 0 and is fixed. |
None
|
width
|
Numeric | Parameter
|
Half width at half maximum (HWHM). |
1.0
|
unit
|
str | sc.Unit
|
Unit of the parameters. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'Lorentzian'
|
display_name
|
str | None
|
Display name for the component. |
None
|
unique_name
|
str | None
|
Unique name of the component. If None, a unique_name is automatically generated. By default, None. |
None
|
Source code in src/easydynamics/sample_model/components/lorentzian.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 | |
evaluate(x)
Evaluate the Lorentzian at the given x values.
If x is a scipp Variable, the unit of the Lorentzian will be converted to match x. The intensity is given by
where \(A\) is the area, \(x_0\) is the center, and \(\Gamma\) is the half width at half maximum (HWHM).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the Lorentzian. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The intensity of the Lorentzian at the given x values. |
Source code in src/easydynamics/sample_model/components/lorentzian.py
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 | |
__repr__()
Return a string representation of the Lorentzian.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Lorentzian. |
Source code in src/easydynamics/sample_model/components/lorentzian.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
Polynomial
Bases: ModelComponent
Polynomial function component.
The intensity is given by $$ I(x) = c_0 + c_1 x + c_2 x^2 + ... + c_N x^N, $$ where \(C_i\) are the coefficients.
Source code in src/easydynamics/sample_model/components/polynomial.py
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 | |
coefficients
property
writable
Get the coefficients of the polynomial as a list of Parameters.
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
The coefficients of the polynomial. |
degree
property
writable
Get the degree of the polynomial.
Returns:
| Type | Description |
|---|---|
int
|
The degree of the polynomial. |
__init__(coefficients=(0.0,), unit='meV', name='Polynomial', display_name=None, unique_name=None)
Initialize the Polynomial component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coefficients
|
Sequence[Numeric | Parameter]
|
Coefficients c0, c1, ..., cN. |
(0.0,)
|
unit
|
str | sc.Unit
|
Unit of the Polynomial component. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'Polynomial'
|
display_name
|
str | None
|
Display name of the Polynomial component. |
None
|
unique_name
|
str | None
|
Unique name of the component. If None, a unique_name is automatically generated. By default, None. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If coefficients is not a sequence of numbers or Parameters or if any item in coefficients is not a number or Parameter. |
ValueError
|
If coefficients is an empty sequence. |
Source code in src/easydynamics/sample_model/components/polynomial.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 | |
coefficient_values()
Get the coefficients of the polynomial as a list.
Returns:
| Type | Description |
|---|---|
list[float]
|
The coefficient values of the polynomial. |
Source code in src/easydynamics/sample_model/components/polynomial.py
146 147 148 149 150 151 152 153 154 155 | |
evaluate(x)
Evaluate the Polynomial at the given x values.
The intensity is given by $$ I(x) = c_0 + c_1 x + c_2 x^2 + ... + c_N x^N, $$ where \(C_i\) are the coefficients.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the Polynomial. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The evaluated Polynomial at the given x values. |
Source code in src/easydynamics/sample_model/components/polynomial.py
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 | |
get_all_variables()
Get all variables from the model component.
Returns:
| Type | Description |
|---|---|
list[DescriptorBase]
|
List of variables in the component. |
Source code in src/easydynamics/sample_model/components/polynomial.py
222 223 224 225 226 227 228 229 230 231 | |
convert_unit(unit)
Convert the unit of the polynomial.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The target unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
UnitError
|
If the provided unit is not a string or sc.Unit. |
Source code in src/easydynamics/sample_model/components/polynomial.py
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 | |
__repr__()
Return a string representation of the Polynomial.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Polynomial. |
Source code in src/easydynamics/sample_model/components/polynomial.py
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | |
Voigt
Bases: CreateParametersMixin, ModelComponent
Voigt profile, a convolution of Gaussian and Lorentzian.
If the center is not provided, it will be centered at 0 and fixed, which is typically what you want in QENS.
Use scipy.special.voigt_profile to evaluate the Voigt profile.
Source code in src/easydynamics/sample_model/components/voigt.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 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 | |
area
property
writable
Get the area parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The area parameter. |
center
property
writable
Get the center parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The center parameter. |
gaussian_width
property
writable
Get the Gaussian width parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The Gaussian width parameter. |
lorentzian_width
property
writable
Get the Lorentzian width parameter (HWHM).
Returns:
| Type | Description |
|---|---|
Parameter
|
The Lorentzian width parameter. |
__init__(area=1.0, center=None, gaussian_width=1.0, lorentzian_width=1.0, unit='meV', name='Voigt', display_name=None, unique_name=None)
Initialize a Voigt component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
area
|
Numeric | Parameter
|
Total area under the curve. |
1.0
|
center
|
Numeric | Parameter | None
|
Center of the Voigt profile. |
None
|
gaussian_width
|
Numeric | Parameter
|
Standard deviation of the Gaussian part. |
1.0
|
lorentzian_width
|
Numeric | Parameter
|
Half width at half max (HWHM) of the Lorentzian part. |
1.0
|
unit
|
str | sc.Unit
|
Unit of the parameters. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'Voigt'
|
display_name
|
str | None
|
Display name of the component. |
None
|
unique_name
|
str | None
|
Unique name of the component. If None, a unique_name is automatically generated. By default, None. |
None
|
Source code in src/easydynamics/sample_model/components/voigt.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 | |
evaluate(x)
Evaluate the Voigt at the given x values.
If x is a scipp Variable, the unit of the Voigt will be converted to match x. The Voigt evaluates to the convolution of a Gaussian with sigma gaussian_width and a Lorentzian with half width at half max lorentzian_width, centered at center, with area equal to area.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the Voigt. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The intensity of the Voigt at the given x values. |
Source code in src/easydynamics/sample_model/components/voigt.py
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 | |
__repr__()
Return a string representation of the Voigt.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Voigt. |
Source code in src/easydynamics/sample_model/components/voigt.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
damped_harmonic_oscillator
DampedHarmonicOscillator
Bases: CreateParametersMixin, ModelComponent
Model of a Damped Harmonic Oscillator (DHO).
The intensity is given by $$ I(x) = \frac{2 A x_0^2 \gamma}{\pi \left( (x^2 - x_0^2)^2 + (2 \gamma x)^2 \right)}, $$ where \(A\) is the area, \(x_0\) is the center, and \(\gamma\) is the width.
Source code in src/easydynamics/sample_model/components/damped_harmonic_oscillator.py
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 | |
area
property
writable
Get the area parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The area parameter. |
center
property
writable
Get the center parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The center parameter. |
width
property
writable
Get the width parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The width parameter. |
__init__(area=1.0, center=1.0, width=1.0, unit='meV', name='DampedHarmonicOscillator', display_name=None, unique_name=None)
Initialize the Damped Harmonic Oscillator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
area
|
Numeric | Parameter
|
Area under the curve. |
1.0
|
center
|
Numeric | Parameter
|
Resonance frequency, approximately the peak position. |
1.0
|
width
|
Numeric | Parameter
|
Damping constant, approximately the half width at half max (HWHM) of the peaks. By default, 1.0. |
1.0
|
unit
|
str | sc.Unit
|
Unit of the parameters. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'DampedHarmonicOscillator'
|
display_name
|
str | None
|
Display name of the component. |
None
|
unique_name
|
str | None
|
Unique name of the component. If None, a unique_name is automatically generated. By default, None. |
None
|
Source code in src/easydynamics/sample_model/components/damped_harmonic_oscillator.py
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 | |
evaluate(x)
Evaluate the Damped Harmonic Oscillator at the given x values.
If x is a scipp Variable, the unit of the DHO will be converted to match x. The intensity is given by $$ I(x) = \frac{2 A x_0^2 \gamma}{\pi \left( (x^2 - x_0^2)^2 + (2 \gamma x)^2 \right)}, $$ where \(A\) is the area, \(x_0\) is the center, and \(\gamma\) is the width.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the DHO. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The intensity of the DHO at the given x values. |
Source code in src/easydynamics/sample_model/components/damped_harmonic_oscillator.py
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 | |
__repr__()
Return a string representation of the Damped Harmonic Oscillator.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Damped Harmonic Oscillator. |
Source code in src/easydynamics/sample_model/components/damped_harmonic_oscillator.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | |
delta_function
DeltaFunction
Bases: CreateParametersMixin, ModelComponent
Delta function.
Evaluates to zero everywhere, except in convolutions, where it acts as an identity. This is handled by the Convolution method. If the center is not provided, it will be centered at 0 and fixed, which is typically what you want in QENS.
Source code in src/easydynamics/sample_model/components/delta_function.py
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 | |
area
property
writable
Get the area parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The area parameter. |
center
property
writable
Get the center parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The center parameter. |
__init__(center=None, area=1.0, unit='meV', name='DeltaFunction', display_name=None, unique_name=None)
Initialize the Delta function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
center
|
Numeric | Parameter | None
|
Center of the delta function. If None, it will be centered at 0 and fixed. |
None
|
area
|
Numeric | Parameter
|
Total area under the curve. |
1.0
|
unit
|
str | sc.Unit
|
Unit of the parameters. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'DeltaFunction'
|
display_name
|
str | None
|
Display name of the component. |
None
|
unique_name
|
str | None
|
Unique name of the component. If None, a unique_name is automatically generated. By default, None. |
None
|
Source code in src/easydynamics/sample_model/components/delta_function.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 | |
evaluate(x)
Evaluate the Delta function at the given x values.
The Delta function evaluates to zero everywhere, except at the center. Its numerical integral is equal to the area. It acts as an identity in convolutions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the Delta function. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The evaluated Delta function at the given x values. |
Source code in src/easydynamics/sample_model/components/delta_function.py
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 | |
__repr__()
Return a string representation of the Delta function.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Delta function. |
Source code in src/easydynamics/sample_model/components/delta_function.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
exponential
Exponential
Bases: CreateParametersMixin, ModelComponent
Model of an exponential function.
The intensity is given by
where \(A\) is the amplitude, \(x_0\) is the center, and \(B\) describes the rate of decay or growth.
Source code in src/easydynamics/sample_model/components/exponential.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 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 | |
amplitude
property
writable
Get the amplitude parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The amplitude parameter. |
center
property
writable
Get the center parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The center parameter. |
rate
property
writable
Get the rate parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The rate parameter. |
__init__(amplitude=1.0, center=None, rate=1.0, unit='meV', name='Exponential', display_name=None, unique_name=None)
Initialize the Exponential component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
amplitude
|
Numeric | Parameter
|
Amplitude of the Exponential. |
1.0
|
center
|
Numeric | Parameter | None
|
Center of the Exponential. If None, the center is fixed at 0. |
None
|
rate
|
Numeric | Parameter
|
Decay or growth constant of the Exponential. |
1.0
|
unit
|
str | sc.Unit
|
Unit of the parameters. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'Exponential'
|
display_name
|
str | None
|
Display name of the component. |
None
|
unique_name
|
str | None
|
Unique name of the component. If None, a unique_name is automatically generated. By default, None. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If amplitude, center, or rate are not numbers or Parameters. |
ValueError
|
If amplitude, center or rate are not finite numbers. |
Source code in src/easydynamics/sample_model/components/exponential.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 | |
evaluate(x)
Evaluate the Exponential at the given x values.
If x is a scipp Variable, the unit of the Exponential will be converted to match x. The intensity is given by $$ I(x) = A \exp\left( r (x - x_0) \right) $$
where \(A\) is the amplitude, \(x_0\) is the center, and \(r\) is the rate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the Exponential. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The intensity of the Exponential at the given x values. |
Source code in src/easydynamics/sample_model/components/exponential.py
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 | |
convert_unit(unit)
Convert the unit of the Parameters in the component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The new unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If unit is not a string or sc.Unit. |
Exception
|
If conversion fails for any parameter. |
Source code in src/easydynamics/sample_model/components/exponential.py
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 | |
__repr__()
Return a string representation of the Exponential.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Exponential. |
Source code in src/easydynamics/sample_model/components/exponential.py
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | |
expression_component
ExpressionComponent
Bases: ModelComponent
Model component defined by a symbolic expression.
Source code in src/easydynamics/sample_model/components/expression_component.py
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 | |
expression
property
writable
Return the original expression string.
Returns:
| Type | Description |
|---|---|
str
|
The original expression string provided at initialization. |
__init__(expression, parameters=None, unit='meV', name='Expression', display_name=None, unique_name=None)
Initialize the ExpressionComponent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expression
|
str
|
The symbolic expression as a string. Must contain 'x' as the independent variable. |
required |
parameters
|
dict[str, Numeric] | None
|
Dictionary of parameter names and their initial values. |
None
|
unit
|
str | sc.Unit
|
Unit of the output. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'Expression'
|
display_name
|
str | None
|
Display name for the component. |
None
|
unique_name
|
str | None
|
Unique name for the component. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the expression is invalid or does not contain 'x'. |
TypeError
|
If any parameter value is not numeric. |
Examples:
>>> expr = ExpressionComponent(
... 'A * exp(-(x - x0)**2 / (2*sigma**2))',
... parameters={'A': 10, 'x0': 0, 'sigma': 1},
... unit='meV',
... display_name='Gaussian Peak',
... )
>>> expr.A = 5
>>> y = expr.evaluate(x)
Source code in src/easydynamics/sample_model/components/expression_component.py
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 | |
evaluate(x)
Evaluate the expression for given x values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
Input values for the independent variable. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
Evaluated results. |
Source code in src/easydynamics/sample_model/components/expression_component.py
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 | |
get_all_variables()
Return all parameters.
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
List of all parameters in the expression. |
Source code in src/easydynamics/sample_model/components/expression_component.py
267 268 269 270 271 272 273 274 275 276 | |
convert_unit(_new_unit)
Convert the unit of the expression.
Unit conversion is not implemented for ExpressionComponent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
_new_unit
|
str | sc.Unit
|
The new unit to convert to (ignored). |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always raised to indicate unit conversion is not supported. |
Source code in src/easydynamics/sample_model/components/expression_component.py
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | |
__getattr__(name)
Allow access to parameters as attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the parameter to access. |
required |
Raises:
| Type | Description |
|---|---|
AttributeError
|
If the parameter does not exist. |
Returns:
| Type | Description |
|---|---|
Parameter
|
The parameter with the given name. |
Source code in src/easydynamics/sample_model/components/expression_component.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 | |
__setattr__(name, value)
Allow setting parameter values as attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the parameter to set. |
required |
value
|
Numeric
|
New value for the parameter. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the value is not numeric. |
Source code in src/easydynamics/sample_model/components/expression_component.py
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 | |
__dir__()
Include parameter names in dir() output for better IDE support.
Returns:
| Type | Description |
|---|---|
list[str]
|
List of attribute names, including parameters. |
Source code in src/easydynamics/sample_model/components/expression_component.py
351 352 353 354 355 356 357 358 359 360 | |
__repr__()
Return a string representation of the ExpressionComponent.
Returns:
| Type | Description |
|---|---|
str
|
String representation of the ExpressionComponent. |
Source code in src/easydynamics/sample_model/components/expression_component.py
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | |
gaussian
Gaussian
Bases: CreateParametersMixin, ModelComponent
Model of a Gaussian function.
The intensity is given by
$$ I(x) = \frac{A}{\sigma \sqrt{2\pi}} \exp\left( -\frac{1}{2} \left(\frac{x - x_0}{\sigma}\right)^2 \right) $$
where \(A\) is the area, \(x_0\) is the center, and \(\sigma\) is the width.
If the center is not provided, it will be centered at 0 and fixed, which is typically what you want in QENS.
Source code in src/easydynamics/sample_model/components/gaussian.py
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 | |
area
property
writable
Get the area parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The area parameter. |
center
property
writable
Get the center parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The center parameter. |
width
property
writable
Get the width parameter (standard deviation).
Returns:
| Type | Description |
|---|---|
Parameter
|
The width parameter. |
__init__(area=1.0, center=None, width=1.0, unit='meV', name='Gaussian', display_name=None, unique_name=None)
Initialize the Gaussian component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
area
|
Numeric | Parameter
|
Area of the Gaussian. |
1.0
|
center
|
Numeric | Parameter | None
|
Center of the Gaussian. If None. |
None
|
width
|
Numeric | Parameter
|
Standard deviation. |
1.0
|
unit
|
str | sc.Unit
|
Unit of the parameters. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'Gaussian'
|
display_name
|
str | None
|
Name of the component. |
None
|
unique_name
|
str | None
|
Unique name of the component. if None, a unique_name is automatically generated. By default, None. |
None
|
Source code in src/easydynamics/sample_model/components/gaussian.py
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 | |
evaluate(x)
Evaluate the Gaussian at the given x values.
If x is a scipp Variable, the unit of the Gaussian will be converted to match x. The intensity is given by $$ I(x) = \frac{A}{\sigma \sqrt{2\pi}} \exp\left( -\frac{1}{2} \left(\frac{x - x_0}{\sigma}\right)^2 \right) $$
where \(A\) is the area, \(x_0\) is the center, and \(\sigma\) is the width.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the Gaussian. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The intensity of the Gaussian at the given x values. |
Source code in src/easydynamics/sample_model/components/gaussian.py
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 | |
__repr__()
Return a string representation of the Gaussian.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Gaussian. |
Source code in src/easydynamics/sample_model/components/gaussian.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
lorentzian
Lorentzian
Bases: CreateParametersMixin, ModelComponent
Model of a Lorentzian function.
The intensity is given by $$ I(x) = \frac{A}{\pi} \frac{\Gamma}{(x - x_0)^2 + \Gamma^2}, $$ where \(A\) is the area, \(x_0\) is the center, and \(\Gamma\) is the half width at half maximum (HWHM).
If the center is not provided, it will be centered at 0 and fixed, which is typically what you want in QENS.
Source code in src/easydynamics/sample_model/components/lorentzian.py
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 | |
area
property
writable
Get the area parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The area parameter. |
center
property
writable
Get the center parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The center parameter. |
width
property
writable
Get the width parameter (HWHM).
Returns:
| Type | Description |
|---|---|
Parameter
|
The width parameter. |
__init__(area=1.0, center=None, width=1.0, unit='meV', name='Lorentzian', display_name=None, unique_name=None)
Initialize the Lorentzian component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
area
|
Numeric | Parameter
|
Area of the Lorentzian. |
1.0
|
center
|
Numeric | Parameter | None
|
Center of the Lorentzian. If None, defaults to 0 and is fixed. |
None
|
width
|
Numeric | Parameter
|
Half width at half maximum (HWHM). |
1.0
|
unit
|
str | sc.Unit
|
Unit of the parameters. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'Lorentzian'
|
display_name
|
str | None
|
Display name for the component. |
None
|
unique_name
|
str | None
|
Unique name of the component. If None, a unique_name is automatically generated. By default, None. |
None
|
Source code in src/easydynamics/sample_model/components/lorentzian.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 | |
evaluate(x)
Evaluate the Lorentzian at the given x values.
If x is a scipp Variable, the unit of the Lorentzian will be converted to match x. The intensity is given by
where \(A\) is the area, \(x_0\) is the center, and \(\Gamma\) is the half width at half maximum (HWHM).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the Lorentzian. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The intensity of the Lorentzian at the given x values. |
Source code in src/easydynamics/sample_model/components/lorentzian.py
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 | |
__repr__()
Return a string representation of the Lorentzian.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Lorentzian. |
Source code in src/easydynamics/sample_model/components/lorentzian.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
mixins
CreateParametersMixin
Provides parameter creation and validation methods for model components.
This mixin provides methods to create and validate common physics parameters (area, center, width) with appropriate bounds and type checking.
Source code in src/easydynamics/sample_model/components/mixins.py
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 | |
model_component
ModelComponent
Bases: EasyDynamicsModelBase
Abstract base class for all model components.
Source code in src/easydynamics/sample_model/components/model_component.py
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 | |
unit
property
writable
Get the unit.
Returns:
| Type | Description |
|---|---|
str
|
The unit of the model component. |
__init__(unit='meV', name='ModelComponent', display_name=None, unique_name=None)
Initialize the ModelComponent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The unit of the model component. |
'meV'
|
name
|
str
|
The name of the model component for indexing. |
'ModelComponent'
|
display_name
|
str | None
|
A human-readable name for the component. |
None
|
unique_name
|
str | None
|
A unique identifier for the component. |
None
|
Source code in src/easydynamics/sample_model/components/model_component.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 | |
fix_all_parameters()
Fix all parameters in the model component.
Source code in src/easydynamics/sample_model/components/model_component.py
83 84 85 86 87 88 | |
free_all_parameters()
Free all parameters in the model component.
Source code in src/easydynamics/sample_model/components/model_component.py
90 91 92 93 | |
convert_unit(unit)
Convert the unit of the Parameters in the component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The new unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the provided unit is not a str or sc.Unit. |
Exception
|
If the provided unit is invalid or incompatible with the component's parameters. |
Source code in src/easydynamics/sample_model/components/model_component.py
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 | |
evaluate(x)
abstractmethod
Abstract method to evaluate the model component at input x.
Must be implemented by subclasses.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the component. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
Evaluated function values. |
Source code in src/easydynamics/sample_model/components/model_component.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |
__repr__()
Return a string representation of the ModelComponent.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the ModelComponent. |
Source code in src/easydynamics/sample_model/components/model_component.py
225 226 227 228 229 230 231 232 233 234 235 | |
polynomial
Polynomial
Bases: ModelComponent
Polynomial function component.
The intensity is given by $$ I(x) = c_0 + c_1 x + c_2 x^2 + ... + c_N x^N, $$ where \(C_i\) are the coefficients.
Source code in src/easydynamics/sample_model/components/polynomial.py
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 | |
coefficients
property
writable
Get the coefficients of the polynomial as a list of Parameters.
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
The coefficients of the polynomial. |
degree
property
writable
Get the degree of the polynomial.
Returns:
| Type | Description |
|---|---|
int
|
The degree of the polynomial. |
__init__(coefficients=(0.0,), unit='meV', name='Polynomial', display_name=None, unique_name=None)
Initialize the Polynomial component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coefficients
|
Sequence[Numeric | Parameter]
|
Coefficients c0, c1, ..., cN. |
(0.0,)
|
unit
|
str | sc.Unit
|
Unit of the Polynomial component. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'Polynomial'
|
display_name
|
str | None
|
Display name of the Polynomial component. |
None
|
unique_name
|
str | None
|
Unique name of the component. If None, a unique_name is automatically generated. By default, None. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If coefficients is not a sequence of numbers or Parameters or if any item in coefficients is not a number or Parameter. |
ValueError
|
If coefficients is an empty sequence. |
Source code in src/easydynamics/sample_model/components/polynomial.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 | |
coefficient_values()
Get the coefficients of the polynomial as a list.
Returns:
| Type | Description |
|---|---|
list[float]
|
The coefficient values of the polynomial. |
Source code in src/easydynamics/sample_model/components/polynomial.py
146 147 148 149 150 151 152 153 154 155 | |
evaluate(x)
Evaluate the Polynomial at the given x values.
The intensity is given by $$ I(x) = c_0 + c_1 x + c_2 x^2 + ... + c_N x^N, $$ where \(C_i\) are the coefficients.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the Polynomial. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The evaluated Polynomial at the given x values. |
Source code in src/easydynamics/sample_model/components/polynomial.py
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 | |
get_all_variables()
Get all variables from the model component.
Returns:
| Type | Description |
|---|---|
list[DescriptorBase]
|
List of variables in the component. |
Source code in src/easydynamics/sample_model/components/polynomial.py
222 223 224 225 226 227 228 229 230 231 | |
convert_unit(unit)
Convert the unit of the polynomial.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The target unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
UnitError
|
If the provided unit is not a string or sc.Unit. |
Source code in src/easydynamics/sample_model/components/polynomial.py
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 | |
__repr__()
Return a string representation of the Polynomial.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Polynomial. |
Source code in src/easydynamics/sample_model/components/polynomial.py
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | |
voigt
Voigt
Bases: CreateParametersMixin, ModelComponent
Voigt profile, a convolution of Gaussian and Lorentzian.
If the center is not provided, it will be centered at 0 and fixed, which is typically what you want in QENS.
Use scipy.special.voigt_profile to evaluate the Voigt profile.
Source code in src/easydynamics/sample_model/components/voigt.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 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 | |
area
property
writable
Get the area parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The area parameter. |
center
property
writable
Get the center parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The center parameter. |
gaussian_width
property
writable
Get the Gaussian width parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The Gaussian width parameter. |
lorentzian_width
property
writable
Get the Lorentzian width parameter (HWHM).
Returns:
| Type | Description |
|---|---|
Parameter
|
The Lorentzian width parameter. |
__init__(area=1.0, center=None, gaussian_width=1.0, lorentzian_width=1.0, unit='meV', name='Voigt', display_name=None, unique_name=None)
Initialize a Voigt component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
area
|
Numeric | Parameter
|
Total area under the curve. |
1.0
|
center
|
Numeric | Parameter | None
|
Center of the Voigt profile. |
None
|
gaussian_width
|
Numeric | Parameter
|
Standard deviation of the Gaussian part. |
1.0
|
lorentzian_width
|
Numeric | Parameter
|
Half width at half max (HWHM) of the Lorentzian part. |
1.0
|
unit
|
str | sc.Unit
|
Unit of the parameters. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'Voigt'
|
display_name
|
str | None
|
Display name of the component. |
None
|
unique_name
|
str | None
|
Unique name of the component. If None, a unique_name is automatically generated. By default, None. |
None
|
Source code in src/easydynamics/sample_model/components/voigt.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 | |
evaluate(x)
Evaluate the Voigt at the given x values.
If x is a scipp Variable, the unit of the Voigt will be converted to match x. The Voigt evaluates to the convolution of a Gaussian with sigma gaussian_width and a Lorentzian with half width at half max lorentzian_width, centered at center, with area equal to area.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the Voigt. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The intensity of the Voigt at the given x values. |
Source code in src/easydynamics/sample_model/components/voigt.py
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 | |
__repr__()
Return a string representation of the Voigt.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Voigt. |
Source code in src/easydynamics/sample_model/components/voigt.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
diffusion_model
BrownianTranslationalDiffusion
Bases: DiffusionModelBase
Model of Brownian translational diffusion, consisting of a Lorentzian function for each Q-value, where the width is given by \(D Q^2\), where \(D\) is the diffusion coefficient. The area of the Lorentzians is given by the scale parameter multiplied by the QISF, which is 1 for this model. The EISF is 0 for this model, so there is no delta function component. Q is assumed to have units of 1/angstrom. Creates ComponentCollections with Lorentzian components for given Q-values.
Examples:
>>> Q=np.linspace(0.5,2,7) >>>energy=np.linspace(-2, 2, 501)
>>> scale = 1.0
>>> diffusion_coefficient = 2.4e-9 # m^2/s
>>> diffusion_model=BrownianTranslationalDiffusion(name="DiffusionModel",
>>> scale=scale, diffusion_coefficient= diffusion_coefficient,)
>>> component_collections = diffusion_model.create_component_collections(Q)
See also the tutorials.
Source code in src/easydynamics/sample_model/diffusion_model/brownian_translational_diffusion.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 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 | |
diffusion_coefficient
property
writable
Get the diffusion coefficient parameter D.
Returns:
| Type | Description |
|---|---|
Parameter
|
Diffusion coefficient D in m^2/s. |
__init__(scale=1.0, diffusion_coefficient=1.0, unit='meV', name='BrownianTranslationalDiffusion', display_name='BrownianTranslationalDiffusion', unique_name=None)
Initialize a new BrownianTranslationalDiffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scale
|
Numeric
|
Scale factor for the diffusion model. Must be a non-negative number. |
1.0
|
diffusion_coefficient
|
Numeric
|
Diffusion coefficient D in m^2/s. |
1.0
|
unit
|
str | sc.Unit
|
Unit of the diffusion model. Must be convertible to meV. |
'meV'
|
name
|
str
|
Name of the diffusion model. |
'BrownianTranslationalDiffusion'
|
display_name
|
str | None
|
Display name of the diffusion model. |
'BrownianTranslationalDiffusion'
|
unique_name
|
str | None
|
Unique name of the diffusion model. If None, a unique name will be generated. By default, None. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If scale or diffusion_coefficient is not a number. |
Source code in src/easydynamics/sample_model/diffusion_model/brownian_translational_diffusion.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 | |
calculate_width(Q)
Calculate the half-width at half-maximum (HWHM) for the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type
|
Scattering vector in 1/angstrom. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
HWHM values in the unit of the model (e.g., meV). |
Source code in src/easydynamics/sample_model/diffusion_model/brownian_translational_diffusion.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
calculate_EISF(Q)
Calculate the Elastic Incoherent Structure Factor (EISF) for the Brownian translational diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type
|
Scattering vector in 1/angstrom. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
EISF values (dimensionless). |
Source code in src/easydynamics/sample_model/diffusion_model/brownian_translational_diffusion.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
calculate_QISF(Q)
Calculate the Quasi-Elastic Incoherent Structure Factor (QISF).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type
|
Scattering vector in 1/angstrom. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
QISF values (dimensionless). |
Source code in src/easydynamics/sample_model/diffusion_model/brownian_translational_diffusion.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | |
create_component_collections(Q, component_name='Brownian diffusion', component_display_name=None)
Create ComponentCollection components for the Brownian translational diffusion model at given Q values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type
|
Scattering vector values. |
required |
component_name
|
str
|
Name of the Brownian diffusion component. |
'Brownian diffusion'
|
component_display_name
|
str | None
|
Display name of the Brownian diffusion component. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If component_display_name is not a string. If component_name is not a string. |
Returns:
| Type | Description |
|---|---|
list[ComponentCollection]
|
List of ComponentCollections with Lorentzian components for each Q value. Each Lorentzian has a width given by \(D*Q^2\) and an area given by the scale parameter multiplied by the QISF (which is 1 for this model). |
Source code in src/easydynamics/sample_model/diffusion_model/brownian_translational_diffusion.py
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 | |
__repr__()
String representation of the BrownianTranslationalDiffusion model.
Returns:
| Type | Description |
|---|---|
str
|
String representation of the BrownianTranslationalDiffusion model. |
Source code in src/easydynamics/sample_model/diffusion_model/brownian_translational_diffusion.py
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | |
JumpTranslationalDiffusion
Bases: DiffusionModelBase
Model of Jump translational diffusion.
The model consists of a Lorentzian function for each Q-value, where the width is given by
where \(D\) is the diffusion coefficient and \(t\) is the relaxation time. Q is assumed to have units of 1/angstrom. Creates ComponentCollections with Lorentzian components for given Q-values.
Examples:
>>> Q = np.linspace(0.5, 2, 7)
>>> energy = np.linspace(-2, 2, 501)
>>> scale = 1.0
>>> diffusion_coefficient = 2.4e-9 # m^2/s
>>> relaxation_time = 1.0 # ps
>>> diffusion_model = JumpTranslationalDiffusion(
... scale=scale,
... diffusion_coefficient=diffusion_coefficient,
... relaxation_time=relaxation_time,
... )
>>> component_collections = diffusion_model.create_component_collections(Q)
See also the tutorials..
Source code in src/easydynamics/sample_model/diffusion_model/jump_translational_diffusion.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 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 443 444 | |
diffusion_coefficient
property
writable
Get the diffusion coefficient parameter D.
Returns:
| Type | Description |
|---|---|
Parameter
|
Diffusion coefficient D. |
relaxation_time
property
writable
Get the relaxation time parameter t.
Returns:
| Type | Description |
|---|---|
Parameter
|
Relaxation time t in ps. |
__init__(scale=1.0, diffusion_coefficient=1.0, relaxation_time=1.0, unit='meV', name='JumpTranslationalDiffusion', display_name='JumpTranslationalDiffusion', unique_name=None)
Initialize a new JumpTranslationalDiffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scale
|
Numeric
|
Scale factor for the diffusion model. Must be a non-negative number. |
1.0
|
diffusion_coefficient
|
Numeric
|
Diffusion coefficient D in m^2/s. |
1.0
|
relaxation_time
|
Numeric
|
Relaxation time t in ps. |
1.0
|
unit
|
str | sc.Unit
|
Unit of the diffusion model. Must be convertible to meV. |
'meV'
|
name
|
str
|
Name of the diffusion model. |
'JumpTranslationalDiffusion'
|
display_name
|
str | None
|
Display name of the diffusion model. |
'JumpTranslationalDiffusion'
|
unique_name
|
str | None
|
Unique name of the diffusion model. If None, a unique name will be generated. By default, None. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If scale, diffusion_coefficient, or relaxation_time are not numbers. |
Source code in src/easydynamics/sample_model/diffusion_model/jump_translational_diffusion.py
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 | |
calculate_width(Q)
Calculate the half-width at half-maximum (HWHM) for the diffusion model. \(\Gamma(Q) = Q^2/(1+D t Q^2)\), where \(D\) is the diffusion coefficient and \(t\) is the relaxation time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type
|
Scattering vector in 1/angstrom. Can be a single value or an array of values. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
HWHM values in the unit of the model (e.g., meV). |
Source code in src/easydynamics/sample_model/diffusion_model/jump_translational_diffusion.py
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 | |
calculate_EISF(Q)
Calculate the Elastic Incoherent Structure Factor (EISF).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type
|
Scattering vector in 1/angstrom. Can be a single value or an array of values. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
EISF values (dimensionless). |
Source code in src/easydynamics/sample_model/diffusion_model/jump_translational_diffusion.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | |
calculate_QISF(Q)
Calculate the Quasi-Elastic Incoherent Structure Factor (QISF).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type
|
Scattering vector in 1/angstrom. Can be a single value or an array of values. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
QISF values (dimensionless). |
Source code in src/easydynamics/sample_model/diffusion_model/jump_translational_diffusion.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | |
create_component_collections(Q, component_name='Jump translational diffusion', component_display_name='Jump translational diffusion')
Create ComponentCollection components for the diffusion model at given Q values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type
|
Scattering vector in 1/angstrom. Can be a single value or an array of values. |
required |
component_name
|
str
|
Name of the Jump Diffusion Lorentzian component. |
'Jump translational diffusion'
|
component_display_name
|
str
|
Name of the Jump Diffusion Lorentzian component. |
'Jump translational diffusion'
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If component_display_name is not a string. If component_name is not a string. |
Returns:
| Type | Description |
|---|---|
list[ComponentCollection]
|
List of ComponentCollections with Jump Diffusion Lorentzian components. |
Source code in src/easydynamics/sample_model/diffusion_model/jump_translational_diffusion.py
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 | |
__repr__()
String representation of the JumpTranslationalDiffusion model.
Returns:
| Type | Description |
|---|---|
str
|
String representation of the JumpTranslationalDiffusion model. |
Source code in src/easydynamics/sample_model/diffusion_model/jump_translational_diffusion.py
431 432 433 434 435 436 437 438 439 440 441 442 443 444 | |
brownian_translational_diffusion
BrownianTranslationalDiffusion
Bases: DiffusionModelBase
Model of Brownian translational diffusion, consisting of a Lorentzian function for each Q-value, where the width is given by \(D Q^2\), where \(D\) is the diffusion coefficient. The area of the Lorentzians is given by the scale parameter multiplied by the QISF, which is 1 for this model. The EISF is 0 for this model, so there is no delta function component. Q is assumed to have units of 1/angstrom. Creates ComponentCollections with Lorentzian components for given Q-values.
Examples:
>>> Q=np.linspace(0.5,2,7) >>>energy=np.linspace(-2, 2, 501)
>>> scale = 1.0
>>> diffusion_coefficient = 2.4e-9 # m^2/s
>>> diffusion_model=BrownianTranslationalDiffusion(name="DiffusionModel",
>>> scale=scale, diffusion_coefficient= diffusion_coefficient,)
>>> component_collections = diffusion_model.create_component_collections(Q)
See also the tutorials.
Source code in src/easydynamics/sample_model/diffusion_model/brownian_translational_diffusion.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 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 | |
diffusion_coefficient
property
writable
Get the diffusion coefficient parameter D.
Returns:
| Type | Description |
|---|---|
Parameter
|
Diffusion coefficient D in m^2/s. |
__init__(scale=1.0, diffusion_coefficient=1.0, unit='meV', name='BrownianTranslationalDiffusion', display_name='BrownianTranslationalDiffusion', unique_name=None)
Initialize a new BrownianTranslationalDiffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scale
|
Numeric
|
Scale factor for the diffusion model. Must be a non-negative number. |
1.0
|
diffusion_coefficient
|
Numeric
|
Diffusion coefficient D in m^2/s. |
1.0
|
unit
|
str | sc.Unit
|
Unit of the diffusion model. Must be convertible to meV. |
'meV'
|
name
|
str
|
Name of the diffusion model. |
'BrownianTranslationalDiffusion'
|
display_name
|
str | None
|
Display name of the diffusion model. |
'BrownianTranslationalDiffusion'
|
unique_name
|
str | None
|
Unique name of the diffusion model. If None, a unique name will be generated. By default, None. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If scale or diffusion_coefficient is not a number. |
Source code in src/easydynamics/sample_model/diffusion_model/brownian_translational_diffusion.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 | |
calculate_width(Q)
Calculate the half-width at half-maximum (HWHM) for the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type
|
Scattering vector in 1/angstrom. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
HWHM values in the unit of the model (e.g., meV). |
Source code in src/easydynamics/sample_model/diffusion_model/brownian_translational_diffusion.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
calculate_EISF(Q)
Calculate the Elastic Incoherent Structure Factor (EISF) for the Brownian translational diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type
|
Scattering vector in 1/angstrom. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
EISF values (dimensionless). |
Source code in src/easydynamics/sample_model/diffusion_model/brownian_translational_diffusion.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
calculate_QISF(Q)
Calculate the Quasi-Elastic Incoherent Structure Factor (QISF).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type
|
Scattering vector in 1/angstrom. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
QISF values (dimensionless). |
Source code in src/easydynamics/sample_model/diffusion_model/brownian_translational_diffusion.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | |
create_component_collections(Q, component_name='Brownian diffusion', component_display_name=None)
Create ComponentCollection components for the Brownian translational diffusion model at given Q values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type
|
Scattering vector values. |
required |
component_name
|
str
|
Name of the Brownian diffusion component. |
'Brownian diffusion'
|
component_display_name
|
str | None
|
Display name of the Brownian diffusion component. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If component_display_name is not a string. If component_name is not a string. |
Returns:
| Type | Description |
|---|---|
list[ComponentCollection]
|
List of ComponentCollections with Lorentzian components for each Q value. Each Lorentzian has a width given by \(D*Q^2\) and an area given by the scale parameter multiplied by the QISF (which is 1 for this model). |
Source code in src/easydynamics/sample_model/diffusion_model/brownian_translational_diffusion.py
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 | |
__repr__()
String representation of the BrownianTranslationalDiffusion model.
Returns:
| Type | Description |
|---|---|
str
|
String representation of the BrownianTranslationalDiffusion model. |
Source code in src/easydynamics/sample_model/diffusion_model/brownian_translational_diffusion.py
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | |
diffusion_model_base
DiffusionModelBase
Bases: EasyDynamicsModelBase
Base class for constructing diffusion models.
Source code in src/easydynamics/sample_model/diffusion_model/diffusion_model_base.py
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 | |
scale
property
writable
Get the scale parameter of the diffusion model.
Returns:
| Type | Description |
|---|---|
Parameter
|
Scale parameter of the diffusion model. |
__init__(scale=1.0, unit='meV', name='DiffusionModel', display_name='MyDiffusionModel', unique_name=None)
Initialize a new DiffusionModel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scale
|
Numeric
|
Scale factor for the diffusion model. Must be a non-negative number. |
1.0
|
unit
|
str | sc.Unit
|
Unit of the diffusion model. Must be convertible to meV. |
'meV'
|
name
|
str
|
Name of the diffusion model. |
'DiffusionModel'
|
display_name
|
str | None
|
Display name of the diffusion model. |
'MyDiffusionModel'
|
unique_name
|
str | None
|
Unique name of the diffusion model. If None, a unique name will be generated. By default, None. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If scale is not a number. |
UnitError
|
If unit is not a string or scipp Unit, or if it cannot be converted to meV. |
Source code in src/easydynamics/sample_model/diffusion_model/diffusion_model_base.py
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 | |
__repr__()
String representation of the Diffusion model.
Returns:
| Type | Description |
|---|---|
str
|
String representation of the DiffusionModel. |
Source code in src/easydynamics/sample_model/diffusion_model/diffusion_model_base.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 | |
jump_translational_diffusion
JumpTranslationalDiffusion
Bases: DiffusionModelBase
Model of Jump translational diffusion.
The model consists of a Lorentzian function for each Q-value, where the width is given by
where \(D\) is the diffusion coefficient and \(t\) is the relaxation time. Q is assumed to have units of 1/angstrom. Creates ComponentCollections with Lorentzian components for given Q-values.
Examples:
>>> Q = np.linspace(0.5, 2, 7)
>>> energy = np.linspace(-2, 2, 501)
>>> scale = 1.0
>>> diffusion_coefficient = 2.4e-9 # m^2/s
>>> relaxation_time = 1.0 # ps
>>> diffusion_model = JumpTranslationalDiffusion(
... scale=scale,
... diffusion_coefficient=diffusion_coefficient,
... relaxation_time=relaxation_time,
... )
>>> component_collections = diffusion_model.create_component_collections(Q)
See also the tutorials..
Source code in src/easydynamics/sample_model/diffusion_model/jump_translational_diffusion.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 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 443 444 | |
diffusion_coefficient
property
writable
Get the diffusion coefficient parameter D.
Returns:
| Type | Description |
|---|---|
Parameter
|
Diffusion coefficient D. |
relaxation_time
property
writable
Get the relaxation time parameter t.
Returns:
| Type | Description |
|---|---|
Parameter
|
Relaxation time t in ps. |
__init__(scale=1.0, diffusion_coefficient=1.0, relaxation_time=1.0, unit='meV', name='JumpTranslationalDiffusion', display_name='JumpTranslationalDiffusion', unique_name=None)
Initialize a new JumpTranslationalDiffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scale
|
Numeric
|
Scale factor for the diffusion model. Must be a non-negative number. |
1.0
|
diffusion_coefficient
|
Numeric
|
Diffusion coefficient D in m^2/s. |
1.0
|
relaxation_time
|
Numeric
|
Relaxation time t in ps. |
1.0
|
unit
|
str | sc.Unit
|
Unit of the diffusion model. Must be convertible to meV. |
'meV'
|
name
|
str
|
Name of the diffusion model. |
'JumpTranslationalDiffusion'
|
display_name
|
str | None
|
Display name of the diffusion model. |
'JumpTranslationalDiffusion'
|
unique_name
|
str | None
|
Unique name of the diffusion model. If None, a unique name will be generated. By default, None. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If scale, diffusion_coefficient, or relaxation_time are not numbers. |
Source code in src/easydynamics/sample_model/diffusion_model/jump_translational_diffusion.py
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 | |
calculate_width(Q)
Calculate the half-width at half-maximum (HWHM) for the diffusion model. \(\Gamma(Q) = Q^2/(1+D t Q^2)\), where \(D\) is the diffusion coefficient and \(t\) is the relaxation time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type
|
Scattering vector in 1/angstrom. Can be a single value or an array of values. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
HWHM values in the unit of the model (e.g., meV). |
Source code in src/easydynamics/sample_model/diffusion_model/jump_translational_diffusion.py
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 | |
calculate_EISF(Q)
Calculate the Elastic Incoherent Structure Factor (EISF).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type
|
Scattering vector in 1/angstrom. Can be a single value or an array of values. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
EISF values (dimensionless). |
Source code in src/easydynamics/sample_model/diffusion_model/jump_translational_diffusion.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | |
calculate_QISF(Q)
Calculate the Quasi-Elastic Incoherent Structure Factor (QISF).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type
|
Scattering vector in 1/angstrom. Can be a single value or an array of values. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
QISF values (dimensionless). |
Source code in src/easydynamics/sample_model/diffusion_model/jump_translational_diffusion.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | |
create_component_collections(Q, component_name='Jump translational diffusion', component_display_name='Jump translational diffusion')
Create ComponentCollection components for the diffusion model at given Q values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type
|
Scattering vector in 1/angstrom. Can be a single value or an array of values. |
required |
component_name
|
str
|
Name of the Jump Diffusion Lorentzian component. |
'Jump translational diffusion'
|
component_display_name
|
str
|
Name of the Jump Diffusion Lorentzian component. |
'Jump translational diffusion'
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If component_display_name is not a string. If component_name is not a string. |
Returns:
| Type | Description |
|---|---|
list[ComponentCollection]
|
List of ComponentCollections with Jump Diffusion Lorentzian components. |
Source code in src/easydynamics/sample_model/diffusion_model/jump_translational_diffusion.py
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 | |
__repr__()
String representation of the JumpTranslationalDiffusion model.
Returns:
| Type | Description |
|---|---|
str
|
String representation of the JumpTranslationalDiffusion model. |
Source code in src/easydynamics/sample_model/diffusion_model/jump_translational_diffusion.py
431 432 433 434 435 436 437 438 439 440 441 442 443 444 | |
instrument_model
InstrumentModel
Bases: NewBase
InstrumentModel represents a model of the instrument in an experiment at various Q.
It can contain a model of the resolution function for convolutions, of the background and an offset in the energy axis.
Source code in src/easydynamics/sample_model/instrument_model.py
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 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 | |
resolution_model
property
writable
Get the resolution model of the instrument.
Returns:
| Type | Description |
|---|---|
ResolutionModel
|
The resolution model of the instrument. |
background_model
property
writable
Get the background model of the instrument.
Returns:
| Type | Description |
|---|---|
BackgroundModel
|
The background model of the instrument. |
Q
property
writable
Get the Q values of the InstrumentModel.
Returns:
| Type | Description |
|---|---|
np.ndarray | None
|
The Q values of the InstrumentModel, or None if not set. |
unit
property
writable
Get the unit of the InstrumentModel.
Returns:
| Type | Description |
|---|---|
str | sc.Unit
|
The unit of the InstrumentModel. |
energy_offset
property
writable
Get the energy offset template parameter of the instrument model.
Returns:
| Type | Description |
|---|---|
Parameter
|
The energy offset template parameter of the instrument model. |
__init__(display_name='MyInstrumentModel', unique_name=None, Q=None, resolution_model=None, background_model=None, energy_offset=None, unit='meV')
Initialize an InstrumentModel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
display_name
|
str
|
The display name of the InstrumentModel. |
'MyInstrumentModel'
|
unique_name
|
str | None
|
The unique name of the InstrumentModel. |
None
|
Q
|
Q_type | None
|
The Q values where the instrument is modelled. |
None
|
resolution_model
|
ResolutionModel | None
|
The resolution model of the instrument. If None, an empty resolution model is created and no resolution convolution is carried out. |
None
|
background_model
|
BackgroundModel | None
|
The background model of the instrument. If None, an empty background model is created, and the background evaluates to 0. |
None
|
energy_offset
|
Numeric | None
|
Template energy offset of the instrument. Will be copied to each Q value. If None, the energy offset will be 0. |
None
|
unit
|
str | sc.Unit
|
The unit of the energy axis. |
'meV'
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If resolution_model is not a ResolutionModel or None, or if background_model is not a BackgroundModel or None, or if energy_offset is not a number or None. |
Source code in src/easydynamics/sample_model/instrument_model.py
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 | |
clear_Q(confirm=False)
Clear the Q values of the InstrumentModel and any associated ResolutionModel and BackgroundModel, removing all component collections and their associated Parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
confirm
|
bool
|
Confirmation to clear Q values. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If confirm is not True. |
Source code in src/easydynamics/sample_model/instrument_model.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | |
convert_unit(unit_str)
Convert the unit of the InstrumentModel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit_str
|
str | sc.Unit
|
The unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If unit_str is not a valid unit string or scipp Unit. |
Source code in src/easydynamics/sample_model/instrument_model.py
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 | |
get_all_variables(Q_index=None)
Get all variables in the InstrumentModel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the Q value to get variables for. If None, get variables for all Q values. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If Q_index is not an int or None. |
IndexError
|
If Q_index is out of bounds for the Q values in the InstrumentModel. |
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all variables in the InstrumentModel. If Q_index is specified, only variables from the ComponentCollection at the given Q index are included. Otherwise, all variables in the InstrumentModel are included. |
Source code in src/easydynamics/sample_model/instrument_model.py
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 | |
fix_resolution_parameters()
Fix all parameters in the resolution model.
Source code in src/easydynamics/sample_model/instrument_model.py
394 395 396 | |
free_resolution_parameters()
Free all parameters in the resolution model.
Source code in src/easydynamics/sample_model/instrument_model.py
398 399 400 | |
normalize_resolution()
Normalize the resolution model to have area 1.
Source code in src/easydynamics/sample_model/instrument_model.py
402 403 404 | |
get_energy_offset(Q_index=None)
Get the energy offset Parameter at a specific Q index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the Q value to get the energy offset for. If None, get the energy offset for all Q values. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If no Q values are set in the InstrumentModel. |
IndexError
|
If Q_index is out of bounds. |
TypeError
|
If Q_index is not an int or None. |
Returns:
| Type | Description |
|---|---|
Parameter | list[Parameter]
|
The energy offset Parameter at the specified Q index, or a list of Parameters if Q_index is None. |
Source code in src/easydynamics/sample_model/instrument_model.py
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 443 444 445 446 | |
fix_energy_offset(Q_index=None)
Fix energy offset parameters.
If Q_index is specified, only fix the energy offset for that Q value. If Q_index is None, fix energy offsets for all Q values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the Q value to fix the energy offset for. If None, fix energy offsets for all Q values. |
None
|
Source code in src/easydynamics/sample_model/instrument_model.py
448 449 450 451 452 453 454 455 456 457 458 459 460 461 | |
free_energy_offset(Q_index=None)
Free energy offset parameters.
If Q_index is specified, only free the energy offset for that Q value. If Q_index is None, free energy offsets for all Q values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the Q value to free the energy offset for. If None, free energy offsets for all Q values. |
None
|
Source code in src/easydynamics/sample_model/instrument_model.py
463 464 465 466 467 468 469 470 471 472 473 474 475 476 | |
__repr__()
Return a string representation of the InstrumentModel.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the InstrumentModel. |
Source code in src/easydynamics/sample_model/instrument_model.py
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 | |
model_base
ModelBase
Bases: EasyDynamicsModelBase
Base class for Sample Models.
Contains common functionality for models with components and Q dependence.
Source code in src/easydynamics/sample_model/model_base.py
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 443 444 445 | |
unit
property
writable
Get the unit of the SampleModel.
Returns:
| Type | Description |
|---|---|
str | sc.Unit | None
|
The unit of the SampleModel. |
components
property
writable
Get the components of the SampleModel.
Returns:
| Type | Description |
|---|---|
list[ModelComponent]
|
The components of the SampleModel. |
Q
property
writable
Get the Q values of the SampleModel.
Returns:
| Type | Description |
|---|---|
np.ndarray | None
|
The Q values of the SampleModel, or None if not set. |
__init__(display_name='MyModelBase', unique_name=None, unit='meV', components=None, Q=None)
Initialize the ModelBase.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
display_name
|
str
|
Display name of the model. |
'MyModelBase'
|
unique_name
|
str | None
|
Unique name of the model. If None, a unique name will be generated. |
None
|
unit
|
str | sc.Unit | None
|
Unit of the model. |
'meV'
|
components
|
ModelComponent | ComponentCollection | None
|
Template components of the model. If None, no components are added. These components are copied into ComponentCollections for each Q value. |
None
|
Q
|
Q_type | None
|
Q values for the model. If None, Q is not set. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If components is not a ModelComponent or ComponentCollection. |
Source code in src/easydynamics/sample_model/model_base.py
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 | |
evaluate(x)
Evaluate the sample model at all Q for the given x values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
Energy axis values to evaluate the model at. If a scipp Variable or DataArray is provided, the unit of the model will be converted to match the unit of x for evaluation, and the result will be returned in the same unit as x. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If there are no components in the model to evaluate. |
Returns:
| Type | Description |
|---|---|
list[np.ndarray]
|
A list of numpy arrays containing the evaluated model values for each Q. The length of the list will match the number of Q values in the model. |
Source code in src/easydynamics/sample_model/model_base.py
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 | |
append_component(component)
Append a ModelComponent or ComponentCollection to the SampleModel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
component
|
ModelComponent | ComponentCollection
|
The ModelComponent or ComponentCollection to append. |
required |
Source code in src/easydynamics/sample_model/model_base.py
111 112 113 114 115 116 117 118 119 120 121 | |
remove_component(name)
Remove a ModelComponent from the SampleModel by its name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the ModelComponent to remove. |
required |
Source code in src/easydynamics/sample_model/model_base.py
123 124 125 126 127 128 129 130 131 132 133 | |
clear_components()
Clear all ModelComponents from the SampleModel.
Source code in src/easydynamics/sample_model/model_base.py
135 136 137 138 | |
clear_Q(confirm=False)
Clear the Q values of the SampleModel, removing all component collections and their associated Parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
confirm
|
bool
|
Confirmation to clear Q values. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If confirm is not True. |
Source code in src/easydynamics/sample_model/model_base.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | |
convert_unit(unit)
Convert the unit of the ComponentCollection and all its components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The new unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the provided unit is not a string or sc.Unit. |
Exception
|
If the provided unit is not compatible with the current unit. |
Source code in src/easydynamics/sample_model/model_base.py
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 | |
fix_all_parameters()
Fix all Parameters in all ComponentCollections.
Source code in src/easydynamics/sample_model/model_base.py
318 319 320 321 | |
free_all_parameters()
Free all Parameters in all ComponentCollections.
Source code in src/easydynamics/sample_model/model_base.py
323 324 325 326 | |
get_all_variables(Q_index=None)
Get all Parameters and Descriptors from all ComponentCollections in the ModelBase. Parameters Ignores the Parameters and Descriptors in self._components as these are just templates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
If None, get variables for all ComponentCollections. If int, get variables for the ComponentCollection at this index. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If Q_index is not an int or None. |
IndexError
|
If Q_index is out of bounds for the number of ComponentCollections. |
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all Parameters and Descriptors from the ComponentCollections in the ModelBase. |
Source code in src/easydynamics/sample_model/model_base.py
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 | |
get_component_collection(Q_index)
Get the ComponentCollection at the given Q index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int
|
The index of the desired ComponentCollection. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If Q_index is not an int. |
IndexError
|
If Q_index is out of bounds for the number of ComponentCollections. |
Returns:
| Type | Description |
|---|---|
ComponentCollection
|
The ComponentCollection at the. |
Source code in src/easydynamics/sample_model/model_base.py
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 | |
normalize_area()
Normalize the area of the model across all Q values.
Source code in src/easydynamics/sample_model/model_base.py
401 402 403 404 | |
__repr__()
Return a string representation of the ModelBase.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the ModelBase. |
Source code in src/easydynamics/sample_model/model_base.py
433 434 435 436 437 438 439 440 441 442 443 444 445 | |
resolution_model
ResolutionModel
Bases: ModelBase
ResolutionModel represents a model of the instrment resolution in an experiment at various Q.
Source code in src/easydynamics/sample_model/resolution_model.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 | |
__init__(display_name='MyResolutionModel', unique_name=None, unit='meV', components=None, Q=None)
Initialize a ResolutionModel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
display_name
|
str
|
Display name of the model. |
'MyResolutionModel'
|
unique_name
|
str | None
|
Unique name of the model. If None, a unique name will be generated. |
None
|
unit
|
str | sc.Unit
|
Unit of the model. |
'meV'
|
components
|
ModelComponent | ComponentCollection | None
|
Template components of the model. If None, no components are added. These components are copied into ComponentCollections for each Q value. |
None
|
Q
|
Q_type | None
|
Q values for the model. If None, Q is not set. |
None
|
Source code in src/easydynamics/sample_model/resolution_model.py
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 | |
append_component(component)
Append a component to the ResolutionModel.
Does not allow DeltaFunction or Polynomial components, as these are not physical resolution components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
component
|
ModelComponent | ComponentCollection
|
Component(s) to append. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the component is a DeltaFunction or Polynomial. |
Source code in src/easydynamics/sample_model/resolution_model.py
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 | |
sample_model
SampleModel
Bases: ModelBase
SampleModel represents a model of a sample with components and diffusion models, parameterized by Q and optionally temperature. Generates ComponentCollections for each Q value, combining components from the base model and diffusion models.
Applies detailed balancing based on temperature if provided.
Source code in src/easydynamics/sample_model/sample_model.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 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 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 | |
diffusion_models
property
writable
Get the diffusion models of the SampleModel.
Returns:
| Type | Description |
|---|---|
list[DiffusionModelBase]
|
The diffusion models of the SampleModel. |
temperature
property
writable
Get the temperature of the SampleModel.
Returns:
| Type | Description |
|---|---|
Parameter | None
|
The temperature Parameter of the SampleModel, or None if not set. |
temperature_unit
property
writable
Get the temperature unit of the SampleModel.
Returns:
| Type | Description |
|---|---|
str | sc.Unit
|
The unit of the temperature Parameter. |
normalize_detailed_balance
property
writable
Get whether to divide the detailed balance factor by temperature.
Returns:
| Type | Description |
|---|---|
bool
|
True if the detailed balance factor is divided by temperature, False otherwise. |
use_detailed_balance
property
writable
Get whether to apply detailed balance to the model.
Returns:
| Type | Description |
|---|---|
bool
|
True if detailed balance is applied, False otherwise. |
detailed_balance_settings
property
writable
Get the DetailedBalanceSettings of the SampleModel.
Returns:
| Type | Description |
|---|---|
DetailedBalanceSettings
|
The DetailedBalanceSettings of the SampleModel. |
__init__(display_name='MySampleModel', unique_name=None, unit='meV', components=None, Q=None, diffusion_models=None, temperature=None, temperature_unit='K', detailed_balance_settings=None)
Initialize the SampleModel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
display_name
|
str
|
Display name of the model. |
'MySampleModel'
|
unique_name
|
str | None
|
Unique name of the model. If None, a unique name will be generated. |
None
|
unit
|
str | sc.Unit
|
Unit of the model. If None,. |
'meV'
|
components
|
ModelComponent | ComponentCollection | None
|
Template components of the model. If None, no components are added. These components are copied into ComponentCollections for each Q value. |
None
|
Q
|
Q_type | None
|
Q values for the model. If None, Q is not set. |
None
|
diffusion_models
|
DiffusionModelBase | list[DiffusionModelBase] | None
|
Diffusion models to include in the SampleModel. If None, no diffusion models are added. |
None
|
temperature
|
float | None
|
Temperature for detailed balancing. If None, no detailed balancing is applied. By default, None. |
None
|
temperature_unit
|
str | sc.Unit
|
Unit of the temperature. |
'K'
|
detailed_balance_settings
|
DetailedBalanceSettings | None
|
Settings for detailed balancing. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If diffusion_models is not a DiffusionModelBase, a list of DiffusionModelBase, or None, or if temperature is not a number or None, or if detailed_balance_settings is not a DetailedBalanceSettings instance. |
ValueError
|
If temperature is negative. |
Source code in src/easydynamics/sample_model/sample_model.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 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 | |
append_diffusion_model(diffusion_model)
Append a DiffusionModel to the SampleModel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
diffusion_model
|
DiffusionModelBase
|
The DiffusionModel to append. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the diffusion_model is not a DiffusionModelBase. |
Source code in src/easydynamics/sample_model/sample_model.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
remove_diffusion_model(name)
Remove a DiffusionModel from the SampleModel by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the DiffusionModel to remove. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no DiffusionModel with the given name is found. |
Source code in src/easydynamics/sample_model/sample_model.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
clear_diffusion_models()
Clear all DiffusionModels from the SampleModel.
Source code in src/easydynamics/sample_model/sample_model.py
173 174 175 176 | |
convert_temperature_unit(unit)
Convert the unit of the temperature Parameter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The unit to convert the temperature Parameter to. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If temperature is not set or conversion fails. |
Exception
|
If the provided unit is invalid or cannot be converted. |
Source code in src/easydynamics/sample_model/sample_model.py
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 | |
evaluate(x)
Evaluate the sample model at all Q for the given x values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values to evaluate the model at. Can be a number, list, numpy array, scipp Variable, or scipp DataArray. |
required |
Returns:
| Type | Description |
|---|---|
list[np.ndarray]
|
List of evaluated model values for each Q. |
Source code in src/easydynamics/sample_model/sample_model.py
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 | |
get_all_variables(Q_index=None)
Get all Parameters and Descriptors from all ComponentCollections in the SampleModel.
Also includes temperature if set and all variables from diffusion models. Ignores the Parameters and Descriptors in self._components as these are just templates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
If specified, only get variables from the ComponentCollection at the given Q index. If None, get variables from all ComponentCollections. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
List of all Parameters and Descriptors, including temperature if set and all variables from diffusion models. |
Source code in src/easydynamics/sample_model/sample_model.py
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 | |
__repr__()
Return a string representation of the SampleModel.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the SampleModel. |
Source code in src/easydynamics/sample_model/sample_model.py
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 | |