data_loaders.py
Provides several Dataloader objects which open different kinds of data files - typically acquired at different sources (i.e. beamlines at various synchrotrons) - and bring them into the same shape and form.
- class data_loaders.Dataset[source]
The generic class inheriting after
BaseModeland defining structure of the dataset inpiva. Data files read by corresponding Dataloader classes are returned in this format.Creates a generic dataset object inheriting from
BaseModelthat will be filled with all required data and metadata, depending on what is accessible from files generated by different instruments, and left asNoneotherwise. Asterix indicates attributes that are mandatory for functioning of the DataViewers.Object contains:
attribute
type
description
data *
np.ndarray- Acquired data set, always 3D
matrix (
len(data.shape) = 3). Oriented as: dim(0)-scanned axis, dim(1)- analyzer axis, dim(2)-energy axis. When scan type is a single cut (resulting data are 2D), first dimension is equal (data[0, :, :] = np.array([0]))
xscale *
np.ndarray- Axis along the scanned direction,
units depend on the scan type. When scan type is a single cut (2D), it is set to
np.array([1])
yscale *
np.ndarray- Axis along the analyzer slit,
most likely in [deg]
zscale *
np.ndarray- Axis along the energy direction,
most likely in [eV]
ekin
np.ndarrayNone
- Energy axis in kinetic energy
scale (if default scale is in
binding energy)
kxscale
np.ndarrayNone
- Momentum axis (saved after
conversion) along the scanned
direction
kyscale
np.ndarrayNone
- Momentum axis (saved after
conversion) along the analyzer
direction
x
float|None
x position of the manipulator
y
float|None
y position of the manipulator
z
float|None
z position of the manipulator
theta
float|None
- theta angle of the manipulator;
often referred as polar
phi
float|None
- phi angle of the manipulator;
often referred as azimuth
tilt
float|None
tilt angle of the manipulator
temp
float|None
Temperature during the experiment
pressure
float|None
Pressure during the experiment
hv
float|None
- Photon energy used during the
experiment
wf
float|None
Work function of the analyzer
Ef
float|None
Correction for the Fermi level
polarization
str|None
Photon polarization
PE
int|None
Pass energy of the analyzer
exit_slit
float|None
- Exit (vertical) slit of the
beamline; responsible for energy
resolution
FE
float|None
Front end of the beamline
scan_type
str|None
- Type of the measurement (e.g.
cut, tilt scan, hv scan)
scan_dim
list|None
- If scan other than cut, scanned
dimensions as list: [start,
stop, step]
acq_mode
str|None
Data acquisition mode
lens_mode
str|None
Lens mode of the analyzer
ana_slit
str|None
Slit opening of the analyzer
defl_angle
float|None
Applied deflection angle
n_sweeps
int|None
Number of sweeps
DT
int|None
Dwell time
data_provenance
- Dataset logbook; contains
information about original file and keeps track of functions called on the data
- model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- add_org_file_entry(fname, dl)[source]
Add information about the original data file to data provenance logbook.
- Parameters:
fname (str) – file name
dl (str) – specific Dataloader (inheriting from
Dataloader) that was used to open the file
- Return type:
None
- class data_loaders.Dataloader[source]
Parent class (interface) from which other DataLoaders inherit some methods. Even while using same software, files can differ from beamline to beamline in terms of format, amount of saved metadata and the way they are stored. To take differences into account DataLoaders for specific beamlines are implemented separately.
- load_ses_zip(filename, bl_md=None, metadata=False)[source]
Load data from SES (Scienta) *.zip files.
- Parameters:
filename (str) – absolute path to the file
bl_md (list | None) – beamline specific metadata passed as a list of tuples in format (name
str, labelstr, typetype), where name stands for how data entry is saved in the file, label - how the information should be called in theBaseModeland type - type of the variable (float,str, etc.)metadata (bool) – if
True, read only metadata and size of the dataset to display them inDataBrowserwindow. Helps to browse through the files faster, without actually loading entire file.
- Return type:
None
- load_ses_ibw(filename, bl_md=None, metadata=False)[source]
Load data from SES (Scianta) IGOR binary wave (*.ibw) files.
- Parameters:
filename (str) – absolute path to the file
bl_md (list | None) – beamline specific metadata. Not used here, but required to mach format of other Dataloaders. See
load_ses_zip()for more info.metadata (bool) – if
True, read only metadata and size of the dataset. Seeload_ses_zip()for more info.
- Return type:
None
- load_ses_pxt(filename, bl_md=None, metadata=False)[source]
Load data from SES (Scianta) IGOR packed experiment (*.pxt) files.
- Parameters:
filename (str) – absolute path to the file
bl_md (list | None) – beamline specific metadata. Not used here, but required to mach format of other Dataloaders. See
load_ses_zip()for more info.metadata (bool) – if
True, read only metadata and size of the dataset. Seeload_ses_zip()for more info.
- Return type:
None
- static read_ses_metadata(ns, meta, bl_md=None, zip=False)[source]
Load metadata from SES file/notes/comments for the analyzer settings and some beamline specific, if provided.
- Parameters:
meta (list) – list of strings, usually lines read from loaded data, where the metadata can be found.
bl_md (list | None) – beamline specific metadata. See
load_ses_zip()for more info.zip (bool) – lines in
metamight require slightly different decoding. IfTrue, apply the one used in zip files.
- Return type:
None
- static load_raster_scan(wave, bl_md=None, metadata=False)[source]
Load data from xy manipulator raster scan. Each energy-momentum map is saved as a separate
Datasetobject.- Parameters:
wave (Any) – loaded ibw wave.
bl_md (list | None) – beamline specific metadata. Not used here, but required to mach format of other Dataloaders. See
load_ses_zip()for more info.metadata (bool) – if
True, read only metadata and size of the dataset. Seeload_ses_zip()for more info.
- Returns:
array with loaded
Datasetobjects- Return type:
- class data_loaders.DataloaderPickle[source]
Dataloader for opening files saved with
piva. Files are in binary format saved usingpicklemodule, and contain rawDatasetobject.
- class data_loaders.DataloaderSIS[source]
Dataloader for opening files from SIS beamline at SLS (Swiss Light Source, Switzerland).
- class data_loaders.DataloaderADRESS[source]
Dataloader for opening files from Address beamline at SLS (Swiss Light Source, Switzerland).
- read_metadata(keys, metadata_list)[source]
Read metadata from HDF file in a similar fashion as in
Dataloader.read_ses_metadata()(see for more details).- Parameters:
keys (list) – keys to metadata passed as a list of tuples in format (name
str, labelstr, typetype), where name stands for how data entry is saved in the file, label - how the information should be called in theBaseModeland type - type of the variable (float,str, etc.)metadata_list (list) – list of strings, usually lines read from loaded data, where the metadata can be found.
- Return type:
None
- class data_loaders.DataloaderBloch[source]
Dataloader for opening files from Bloch beamline at MAX-IV (Sweden).
- class data_loaders.DataloaderI05[source]
Dataloader for opening files from I05 beamline at Diamond Light Source (UK).
- class data_loaders.DataloaderMERLIN[source]
Dataloader for opening files from Merlin beamline at ALS (Advanced Light Source, Berkeley, CA).
- class data_loaders.DataloaderHERS[source]
Dataloader for opening files from Merlin beamline at ALS (Advanced Light Source, Berkeley, CA).
- class data_loaders.DataloaderURANOS[source]
Dataloader for opening files from Uranos beamline at Solaris (Poland).
- class data_loaders.DataloaderCASSIOPEE[source]
Dataloader for opening files from CASSIOPEE beamline at SOLEIL (France).
- load_from_file(filename, metadata=False)[source]
Recognize correct format and load data from the file.
- load_from_dir(dirname)[source]
Read data from directory containing slices of data saved in separate files. Note: At CASSIOPEE beamline multidimensional scans are saved as a collection of *.txt files, that need to be combined into full map.
- Parameters:
dirname (str) – absolute path to the file
- Return type:
None
- load_from_txt(filename)[source]
Load data from *.txt file.
- Parameters:
filename (str) – absolute path to the file
- Return type:
None
- get_outer_loop(dirname, filenames)[source]
Try to determine the scantype and the corresponding z-axis scale from the additional metadata textfiles. These follow the assumptions made in
load_from_dir(). Additionally, the MONOCHROMATOR section must come before the UNDULATOR section as in both sections we have a key hv but only the former makes sense.
- static get_metadata(filename)[source]
Extract some of the metadata stored in a CASSIOPEE output text file. Also try to detect the line number below which the data starts (for
np.loadtxt( , skiprows=).)
- static read_metadata(keys, metadata_file)[source]
Read some metadata from one of the header files.
- Parameters:
keys (list) – keys to metadata passed as a list of tuples in format (name
str, labelstr, typetype), where name stands for how data entry is saved in the file, label - how the information should be called in theNamespaceand type - type of the variable (float,str, etc.)metadata_file (IOBase) – opened file containing metadata
- Returns:
object with collected metadata
- Return type:
- data_loaders.start_step_n(start, step, n)[source]
Return an array that starts at value
startand goesnsteps ofstep. Helpful for generating axes, as many systems provide exactly starting value, step and dimensionality of the data.
- data_loaders.load_data(filename, metadata=False, suppress_warnings=False)[source]
Try to load file by iterating through all Dataloaders and applying the respective Dataloader’s
load_datamethod.- Parameters:
- Returns:
loaded dataset with available metadata. NOTE: method returns
Datasetloaded with the first Dataloader that didn’t raise any errors. Might be, that other Dataloader can perform better, especially with regard to loaded metadata.- Return type: