spectra_container¶
SpectraContainer object
=== DATA MODEL === spectra = Spectra(energy, signal, mode, process) metadata = XasMetadata(scan_no=1234, default_mode='tey', sample_name='Fe') scan = SpectraContainer('name', {'mode': spectra}, metadata=metadata) scan2 = scan + 2 # add 2 to signal of each contained mode scan.remove_background() # apply operation to each contained mode, store previous version in scan.parents
SpectraContainer
¶
Container for Spectra objects and metadata
Attributes
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
name of this Scan (usually the scan number) |
required |
spectra
|
dict[str, Spectra | SpectraSubtraction]
|
dict of Spectra objects for different detectors |
required |
parents
|
SpectraContainer
|
list of SpectraContainer objects for parent processes |
()
|
metadata
|
XasMetadata
|
XasMetadata object containing regularised scan metadata Selected Behaviours (see Docs for full list) print(spectra1) : displays contained spectra, metadata and previous analysis steps spectra1 + spectra2 : Averages contained spectra on a regular energy grid spectra1 - spectra2 : Subtracts spectra on an interpolated energy grid spectra1.trim(ev_from_start=1) : trim contained spectra by 1 eV spectra1.divide_by_preedge() : divide contained spectra by preedge signal spectra1.remove_background(type) : Subtract background using various methods spectra1.analysis_steps_str() : returns a formatted string of previous analysis steps spectra1.create_background_figure() : create a matplotlib figure of all contained spectra spectra1.create_background_figure() : create a matplotlib figure including background subtraction spectra1.write_nexus('filename.nxs') : write a processed NeXus file |
None
|
Source code in mmg_toolbox/xas/spectra_container.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 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 | |
analysis_steps()
¶
Return ordered dictionary of processing steps from parent objects
analysis_steps_str()
¶
Return string of analysis steps
Source code in mmg_toolbox/xas/spectra_container.py
auto_edge_background(peak_width_ev=5.0, edges=None)
¶
Remove generic xray absorption background from spectra
Source code in mmg_toolbox/xas/spectra_container.py
copy(name=None)
¶
Create copy of spectra container using new name
create_background_figure(**kwargs)
¶
Create matplotlib figure showing each spectra and background subtraction in separate axes
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kwargs
|
kwargs to pass to plt.figure |
{}
|
Returns:
| Type | Description |
|---|---|
Figure
|
matplotlib Figure |
Source code in mmg_toolbox/xas/spectra_container.py
create_figure(**kwargs)
¶
Create matplotlib figure showing each spectra in a separate axes
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kwargs
|
kwargs to pass to plt.figure |
{}
|
Returns:
| Type | Description |
|---|---|
Figure
|
matplotlib Figure |
Source code in mmg_toolbox/xas/spectra_container.py
divide_by_background(name='flat', *args, **kwargs)
¶
Divide by background using various methods
spectra = spectra.divide_by_background('flat', ev_from_start=5)
Background options | Option | parameters | | --- | ---------- | | 'flat' | ev_from_start | | 'norm' | ev_from_start | | 'linear' | ev_from_start | | 'curve' | ev_from_start | | 'exp' | ev_from_start, ev_from_end | | 'step' | ev_from_start | | 'double_edge_step' | l3_energy, l2_energy, peak_width_ev | | 'poly_edges' | *step_energies, peak_width_ev | | 'exp_edges' | *step_energies, peak_width_ev |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
the name of the background to remove e.g. 'flat', 'linear', 'curve', 'exp', 'step', 'double_edge_step', 'poly_edges' |
'flat'
|
|
args
|
additional positional arguments |
()
|
|
kwargs
|
additional keyword arguments |
{}
|
Returns:
| Type | Description |
|---|---|
SpectraContainer
|
processed SpectraContainer object |
Source code in mmg_toolbox/xas/spectra_container.py
divide_by_jump(ev_from_start=5, ev_from_end=None)
¶
Normalise the spectra to the jump between edges
divide_by_peak()
¶
divide_by_postedge(ev_from_end=5)
¶
divide_by_preedge(ev_from_start=5)
¶
divide_by_signal_at_energy(energy1, energy2=None)
¶
find_edges(search_edges=spa.SEARCH_EDGES)
¶
Return list of edges within the energy range
get_all_arrays()
¶
Return energy, signal arrays of all modes
Source code in mmg_toolbox/xas/spectra_container.py
get_arrays(mode=None)
¶
Return energy, signal arrays of chosen mode
Source code in mmg_toolbox/xas/spectra_container.py
get_edges()
¶
remove_background(name='flat', *args, **kwargs)
¶
Remove background using various methods
spectra = spectra.remove_background('flat', ev_from_start=5)
Background options | Option | parameters | | --- | ---------- | | 'flat' | ev_from_start | | 'norm' | ev_from_start | | 'linear' | ev_from_start | | 'curve' | ev_from_start | | 'exp' | ev_from_start, ev_from_end | | 'step' | ev_from_start | | 'double_edge_step' | l3_energy, l2_energy, peak_width_ev | | 'poly_edges' | *step_energies, peak_width_ev | | 'exp_edges' | *step_energies, peak_width_ev |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
the name of the background to remove e.g. 'flat', 'linear', 'curve', 'exp', 'step', 'double_edge_step', 'poly_edges' |
'flat'
|
|
args
|
additional positional arguments |
()
|
|
kwargs
|
additional keyword arguments |
{}
|
Returns:
| Type | Description |
|---|---|
SpectraContainer
|
processed SpectraContainer object |
Source code in mmg_toolbox/xas/spectra_container.py
trim(ev_from_start=1.0, ev_from_end=None)
¶
write_csv(csv_filename, mode=None)
¶
Write spectra to csv file
spectra.write_csv('xas_spectra.csv') # spectra contains modes TEY and TFY
energy, tey, tfy = np.loadtxt('xas_spectra.csv', delimiter=',').T
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
csv_filename
|
str
|
filename to write |
required |
mode
|
str | None
|
mode to write, or None to write all mode spectra to single file |
None
|
Source code in mmg_toolbox/xas/spectra_container.py
write_nexus(nexus_filename)
¶
SpectraContainerSubtraction
¶
Bases: SpectraContainer
Special subclass for subtraction of SpectraContainers - XMCD and XMLD
Source code in mmg_toolbox/xas/spectra_container.py
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 | |
calculate_signal_ratio()
¶
Return the maximum signal as a ratio of the average parent spectra
Source code in mmg_toolbox/xas/spectra_container.py
calculate_sum_rules(n_holes=None, mode=None)
¶
Calculate sum rules of XMCD spectra from integration
orb, spin = spectra.calculate_sum_rules(n_holes)
Parameters
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_holes
|
float | None
|
number of holes in absorbing ion |
None
|
mode
|
str | None
|
select which detection mode to use (None for default) |
None
|
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
orb, spin sum rule values for the detector mode |
Source code in mmg_toolbox/xas/spectra_container.py
create_sum_rules_figure(**kwargs)
¶
Create matplotlib figure of subtraction plots showing different integration regions
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kwargs
|
kwargs to pass to plt.figure |
{}
|
Returns:
| Type | Description |
|---|---|
Figure
|
matplotlib Figure |
Source code in mmg_toolbox/xas/spectra_container.py
sum_rules_report(n_holes=None, mode=None)
¶
Calculate sum rules of XMCD spectra and return report
print(spectra.sum_rules_report(n_holes))
Parameters
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_holes
|
float | None
|
number of holes in absorbing ion |
None
|
mode
|
str | None
|
select which detection mode to use (None for default) |
None
|
Returns:
| Type | Description |
|---|---|
str
|
str |
Source code in mmg_toolbox/xas/spectra_container.py
average_polarised_scans(*scans)
¶
Find unique polarisations and average each scan at that polarisation Spectra are only separated by polarisation, all spectra with the same polarisation are averaged together.
pol1, pol2 = average_polarised_scans(*scans)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scans
|
SpectraContainer
|
list of SpectraContainer objects |
()
|
Returns:
| Type | Description |
|---|---|
tuple[SpectraContainer, SpectraContainer | None]
|
pol1, (pol2|None) SpectraContainer objects for opposite polarisations |