nexus.py¶
Nexus Related functions and nexus class
NexusMap
¶
Bases: HdfMap
HdfMap for Nexus (.nxs) files
Extends the HdfMap class with additional behaviours for NeXus files. http://www.nexusformat.org/
E.G. nxmap = NexusMap() with h5py.File('file.nxs', 'r') as nxs: nxmap.populate(nxs, default_entry_only=True) # populates only from the default entry
Special behaviour¶
nxmap['axes'] -> return path of default axes dataset nxmap['signal'] -> return path of default signal dataset nxmap['image_data'] -> return path of first area detector data object [axes_paths], [signal_paths] = nxmap.nexus_default_paths() [axes_names], [signal_names] = nxmap.nexus_default_names() # returns default names in nxmap.scannables
Source code in src/hdfmap/nexus.py
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 |
|
all_nxclasses()
¶
Return list of unique NX_class attributes used in NXgroups
Source code in src/hdfmap/nexus.py
generate_image_data_from_nxdetector()
¶
find the NXdetector group and assign the image data Must be called after the scannables have been defined as the scan shape is required
Source code in src/hdfmap/nexus.py
generate_scannables_from_nxdata(hdf_file, use_auxiliary=True)
¶
Generate scannables from default NXdata, using axuiliary_names if available
Source code in src/hdfmap/nexus.py
generate_scannables_from_scan_fields_or_nxdata(hdf_file)
¶
Generate scannables from scan_field names or default NXdata
Source code in src/hdfmap/nexus.py
get_plot_data(hdf_file)
¶
Return plotting data from scannables
:returns: {
'xlabel': str label of first axes
'ylabel': str label of first signal
'xdata': flattened array of first axes
'ydata': flattend array of first signal
'axes_names': list of axes names,
'signal_names': list of signal + auxilliary signal names,
'axes_data': list of ND arrays of data for axes,
'signal_data': list of ND array of data for signal + auxilliary 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 src/hdfmap/nexus.py
info_nexus(scannables=True, image_data=True, metadata=False)
¶
Return str info on nexus format
Source code in src/hdfmap/nexus.py
nexus_default_names()
¶
Return name of default axes and signal paths, as defined in scannables
Source code in src/hdfmap/nexus.py
nexus_default_paths()
¶
Return default axes and signal paths
Source code in src/hdfmap/nexus.py
populate(hdf_file, groups=None, default_entry_only=False)
¶
Populate only datasets from default or first entry, with scannables from given groups. Automatically load defaults (axes, signal) and generate scannables from default group
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hdf_file
|
File
|
HDF File object |
required |
groups
|
list of group names or NXClass names to search for datasets, within default entry |
None
|
|
default_entry_only
|
if True, only the first or default entry will be loaded |
False
|
Source code in src/hdfmap/nexus.py
check_nexus_class(hdf_group, nxclass)
¶
Check if hdf_group is a certain NX_class
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hdf_group
|
Group
|
hdf or nexus group object |
required |
nxclass
|
str
|
str name in NX_class attribute |
required |
Returns:
Type | Description |
---|---|
bool
|
True/False |
Source code in src/hdfmap/nexus.py
default_nxdata(entry_group)
¶
Return the default NXdata path within an NXentry group
See: https://manual.nexusformat.org/datarules.html#version-3
Source code in src/hdfmap/nexus.py
default_nxentry(hdf_file)
¶
Return the default NXentry path, or the first NXentry if there is no default, errors if no NXentry
See: https://manual.nexusformat.org/datarules.html#version-3
Source code in src/hdfmap/nexus.py
find_nexus_data_strict(hdf_file)
¶
Nexus compliant method of finding default plotting axes in hdf files - find "default" entry group in top File group - find "default" data group in entry - find "axes" attr in default data - find "signal" attr in default data - generate paths of signal and axes if not nexus compliant, raises KeyError This method is very fast but only works on nexus compliant files
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hdf_file
|
File
|
open HDF file object, i.e. h5py.File(...) |
required |
Returns:
Type | Description |
---|---|
tuple[list[Dataset], Dataset]
|
dataset object for plot axis |
Source code in src/hdfmap/nexus.py
find_nexus_defaults(hdf_file, nx_data_path=None)
¶
Nexus compliant method of finding default plotting axes in hdf files - find "default" entry group in top File group - find "default" data group in entry (or 'measurement', or first 'NXdata') - find "axes" attr in default data - find "signal" attr in default data - generate paths of signal and axes
See: https://manual.nexusformat.org/datarules.html#version-3
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hdf_file
|
File
|
open HDF file object, i.e. h5py.File(...) |
required |
nx_data_path
|
str | None
|
hdf path of NXdata group, or None to find the default |
None
|
Returns:
Type | Description |
---|---|
tuple[list[str], list[str]]
|
list of str hdf paths for signal dataset |
Source code in src/hdfmap/nexus.py
names_from_scan_fields(hdf_file, scan_fields_path)
¶
Extract a list of dataset names from the diamond_scan/scan_fields dataset
scan_fields stores scannables as class_name.dataset_name, return only the dataset_name
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hdf_file
|
File
|
|
required |
scan_fields_path
|
str
|
|
required |
Returns:
Type | Description |
---|---|
list[str]
|
['names',] |