nexus_scan¶
NeXus Scan Classes
NexusScan - NeXus Scan class, lazy loader of scan files NexusDataHolder - Loads scan data and meta data into attributes
NexusDataHolder
¶
Bases: DataHolder, NexusScan
Nexus data holder class - Automatically reads scannable and metadata from file - acts like the old .dat DataHolder class - has additional functions to read data from NeXus file
Example: scan = NexusDataHolder('12345.nxs') scan.eta -> returns array scan.metadata.metadata -> returns value scan('signal') -> evaluate expression
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str | None
|
path to Nexus file |
required |
hdf_map
|
NexusMap | None
|
NexusMap object or None to generate |
None
|
flatten_scannables
|
bool
|
if True, flattens all scannable arrays to 1D |
True
|
Source code in mmg_toolbox/nexus/nexus_scan.py
NexusScan
¶
Bases: NexusLoader
Light-weight NeXus file reader
Example: scan = NexusScan('scan.nxs') scan('scan_command') -> returns value
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nxs_filename
|
str
|
path to nexus file |
required |
hdf_map
|
NexusMap | None
|
NexusMap object or None |
None
|
config
|
dict | None
|
configuration dict |
None
|
Source code in mmg_toolbox/nexus/nexus_scan.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 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 | |
arrays(*args, units='', default=np.array([np.nan]))
¶
Return Numpy arrays
Source code in mmg_toolbox/nexus/nexus_scan.py
datasets(*args)
¶
Return HDF5 datasets from NeXus file (leaves file in open state)
get_plot_axis(axis_name, reduce_shape=True, flatten=False)
¶
Return plot axis data and label for given axis name
E.G. data, label = scan.get_plot_axis('axes', flatten=True)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
axis_name
|
str
|
axis name as given in self.map |
required |
reduce_shape
|
bool
|
reduces shape (summing additional axes) of >2D arrays to self.map.scannables_shape |
True
|
flatten
|
bool
|
flattens output if True |
False
|
Returns:
| Type | Description |
|---|---|
tuple[ndarray, str]
|
(data, label) tuple |
Source code in mmg_toolbox/nexus/nexus_scan.py
get_plot_data(x_axis=None, *y_axis, z_axis=None)
¶
Return dict of plottable data
E.G.
data = scan.get_plot_data('axes', 'signal')
plt.plot(data['x'], data['y'])
plt.xlabel(data['xlabel'])
plt.ylabel(data['ylabel'])
plt.title(data['title'])
plt.legend(data['legend'])
:param x_axis: axis name as given in self.map
:param y_axis: axis name as given in self.map
:param z_axis: axis name as given in self.map
:returns: {
'xlabel': str label of first axes
'ylabel': str label of first signal
'xdata': flattened array of first axes
'ydata': flattened array of first signal
'axes_names': list of axes names,
'signal_names': list of signal + auxiliary signal names,
'axes_data': list of ND arrays of data for axes,
'signal_data': list of ND array of data for signal + auxiliary signals,
'axes_labels': list of axes labels as 'name [units]',
'signal_labels': list of signal labels,
'data': dict of all scannables axes,
'title': str title as 'filename
NXtitle' if dataset is a 2D grid scan, additional rows: 'grid_xlabel': str label of grid x-axis 'grid_ylabel': str label of grid y-axis 'grid_label': str label of height or colour 'grid_xdata': 2D array of x-coordinates 'grid_ydata': 2D array of y-coordinates 'grid_data': 2D array of height or colour }
Source code in mmg_toolbox/nexus/nexus_scan.py
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 | |
hdf_find(*field_or_class, find_all=False)
¶
Find datasets and groups within hdf file
HdfDataset = scan.hdf_find('NXentry', ['NXdata', 'measurement'], 'signal')
Warning: HDF file stays in open state while Dataset or Group objects exist.
Parameters:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field_or_class
|
str | list[str]
|
names to search for, in hierarchical order. Lists treated as OR |
()
|
find_all
|
bool
|
whether to return all datasets or only the first match |
False
|
Returns:
| Type | Description |
|---|---|
Dataset | Group | list[Dataset | Group]
|
matching Dataset or Group, or list of matching Datasets or Groups |
Source code in mmg_toolbox/nexus/nexus_scan.py
hdf_tree_string(group='/', all_links=True, attributes=True)
¶
Generate string of the hdf file structure, similar to h5ls. Uses h5py.visititems
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
all_links
|
bool
|
bool, if True, also show links |
True
|
group
|
str
|
only display tree structure of this group (default root) |
'/'
|
attributes
|
bool
|
if True, display the attributes of groups and datasets |
True
|
Returns:
| Type | Description |
|---|---|
str
|
str |
Source code in mmg_toolbox/nexus/nexus_scan.py
image(index=None)
¶
Return image or selection from default detector
Source code in mmg_toolbox/nexus/nexus_scan.py
instrument_model()
¶
load_hdf()
¶
metadata_str(expression=None)
¶
Generate metadata string from beamline config
strings(*args, units=False)
¶
table(delimiter=', ', string_spec='', format_spec='f', default_decimals=8)
¶
Return data table
Source code in mmg_toolbox/nexus/nexus_scan.py
times(*args)
¶
Return datetime object
Source code in mmg_toolbox/nexus/nexus_scan.py
values(*args, value_func=np.mean, units='', default=np.array(np.nan))
¶
Return float values
Source code in mmg_toolbox/nexus/nexus_scan.py
volume()
¶
xas_spectra(sample_name=None, element_edge=None, mode='all', dls_loader=False)
¶
Load XAS Spectra from the scan file
Parameters
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample_name
|
str | None
|
sample name, e.g. 'sample1' or None to load from NeXus file |
None
|
element_edge
|
str | None
|
element edge, e.g. 'FeL3' or None to determine from energy range |
None
|
mode
|
str | list[str]
|
detector values to load, 'all', 'default' or e.g. 'tey', 'tfy' as specified in file |
'all'
|
dls_loader
|
bool
|
bool, if True uses explicit loading of metadata from DLS MMG beamlines |
False
|
Returns:
| Type | Description |
|---|---|
SpectraContainer
|
SpectraContainer |