Create a Dataset object in Python#
A lot of low-level functions in Darfix takes a Dataset object as input. When testing/debugging these, it can be useful to create such an object in Python to run the functions.
To do this, we use the load_process_data function:
- darfix.core.data_selection.load_process_data(detector_url, root_dir=None, dark_detector_url=None, title='', metadata_url=None, progress_callback=None)[source]#
Loads data from detector_url.
- Parameters:
detector_url (
Union[str,DataUrl]) – detector_url to be loaded.metadata_url – path to the scan metadata for HDF5 containing positioner information in order to load metadata for non-edf files
root_dir (
Optional[str])dark_detector_url (
Union[str,DataUrl,None])title (
str)progress_callback (
Optional[Callable[[],int]])
Here is an example on how to use it to load a HDF5 dataset (here the Silicon_111_reflection_0003 dataset)
from darfix.core.data_selection import load_process_data
filepath = '/data/scisoft/darfix/datasets/darfix/bliss_hdf5/Silicon_111_reflection_0003/Silicon_111_reflection_0003.h5'
scan_index = 1
detector_name = 'pco_ff'
dataset, bg_dataset = load_process_data(
detector_url=f"silx://{filepath}?/{scan_index}.1/measurement/{detector_name}",
metadata_url=f"silx://{filepath}?{scan_index}.1/instrument/positioners",
)
Then, we use the find_dimensions method to register the appropriate dimensions in the Dataset. This is mandatory to run most operations on a Dataset
dataset.find_dimensions(tolerance=1e-5)
dataset.reshape_data()
The tolerance need to be changed depending on the dataset used. We use here the value appropriate for Silicon_111_reflection_0003, the default value being 1e-9.
The Dataset is now ready for computations. For example, we can compute the moments (Center of Mass, Skewness, Kurtosis, …) by using apply_moments:
dataset.apply_moments()
moments = dataset.moments_dims