Create a ImageDataset
object in Python#
A lot of low-level functions in Darfix takes a ImageDataset
or 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)[source]#
Loads data from detector_url. If detector_url is:
a str: consider it as a file pattern (for EDF files).
a DataUrl: consider it readable by silx get_data function
- 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
)
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'
img_dataset, indices, bg_indices, 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 ImageDataset
. This is mandatory to run most operations on a Dataset
img_dataset.find_dimensions(tolerance=1e-5)
img_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 ImageDataset
is now ready for computations. For example, we can compute the moments (Center of Mass, Skewness, Kurtosis, …) by using apply_moments
:
img_dataset.apply_moments()
moments = img_dataset.moments_dims
Tip
For some operations (e.g. noise removal), you will need a Dataset
object. You can generate it from the ImageDataset
object:
from darfix.dtypes import Dataset
from darfix.core.noiseremoval import apply_background_subtraction
dataset = Dataset(img_dataset)
new_img_dataset = apply_background_subtraction(dataset)