Code reference
module-level
- qpformat.load_data(path, fmt=None, bg_data=None, bg_fmt=None, meta_data=None, holo_kw=None, as_type='float32')[source]
Load experimental data
- Parameters
path (str or pathlib.Path) – Path to experimental data file or folder
fmt (str) – The file format to use (see file_formats.formats). If set to None, the file format is guessed.
bg_data (str or pathlib.Path) – Path to background data file or qpimage.QPImage
bg_fmt (str) – The file format to use (see file_formats.formats) for the background. If set to None, the file format is be guessed.
meta_data (dict) – Meta data (see qpimage.meta.DATA_KEYS)
holo_kw (dict) – Keyword arguments for hologram data; See
qpimage.holo.get_field()
for valid keyword arguments.as_type (str) – Defines the data type that the input data is casted to. The default is “float32” which saves memory. If high numerical accuracy is required (does not apply for a simple 2D phase analysis), set this to double precision (“float64”).
- Returns
dataobj – Object that gives lazy access to the experimental data.
- Return type
file format base classes
SeriesData
- class qpformat.file_formats.SeriesData(path, meta_data=None, holo_kw=None, as_type='float32')[source]
Series data file format base class
- Parameters
path (str or pathlib.Path) – Path to the experimental data file.
meta_data (dict) – Dictionary containing meta data. see
qpimage.META_KEYS
.as_type (str) – Defines the data type that the input data is casted to. The default is “float32” which saves memory. If high numerical accuracy is required (does not apply for a simple 2D phase analysis), set this to double precision (“float64”).
- path
pathlib.Path to data file or io.IOBase
- meta_data
Enforced metadata via keyword arguments
- holo_kw
Hologram retrieval; keyword arguments for
qpimage.holo.get_field()
.
- background_identifier
Unique string that identifies the background data that was set using set_bg.
- property identifier
Return a unique identifier for the given data set
- property shape
Return dataset shape (lenght, image0, image1).
This should be overridden by the subclass, because by default the first qpimage is used for that.
- get_identifier(idx)[source]
Return an identifier for the data at index idx
Changed in version 0.4.2: indexing starts at 1 instead of 0
- get_name(idx)[source]
Return name of data at index idx
Changed in version 0.4.2: indexing starts at 1 instead of 0
- abstract get_qpimage_raw(idx)[source]
Return QPImage without background correction
Note that this method must always return a QPImage instance with the “identifier” metadata key set!
- saveh5(h5file, qpi_slice=None, series_slice=None, time_interval=None, count=None, max_count=None)[source]
Save the data set as an HDF5 file (qpimage.QPSeries format)
- Parameters
h5file (str, pathlib.Path, or h5py.Group) – Where to store the series data
qpi_slice (tuple of (slice, slice)) – If not None, only store a slice of each QPImage in h5file. A value of None is equivalent to
(slice(0, -1), slice(0, -1))
.series_slice (slice) – If None, save the entire series, otherwise only save the images specified by this slice.
time_interval (tuple of (float, float)) – If not None, only stores QPImages that were recorded within the given time interval.
count (multiprocessing.Value) – Can be used to monitor the progress of the algorithm. Initially, the value of max_count.value is incremented by the total number of steps. At each step, the value of count.value is incremented.
max_count (multiprocessing.Value) – Can be used to monitor the progress of the algorithm. Initially, the value of max_count.value is incremented by the total number of steps. At each step, the value of count.value is incremented.
Notes
The series “identifier” meta data is only set when all of qpi_slice, series_slice, and time_interval are None.
- set_bg(dataset)[source]
Set background data
- Parameters
dataset (DataSet, qpimage.QPImage, or int) – If the
len(dataset)
matcheslen(self)
, then background correction is performed element-wise. Otherwise,len(dataset)
must be one and is used for all data ofself
.
See also
get_qpimage
obtain the background corrected QPImage
SingleData
- class qpformat.file_formats.SingleData(path, meta_data=None, holo_kw=None, as_type='float32')[source]
Single data file format base class
- Parameters
path (str or pathlib.Path) – Path to the experimental data file.
meta_data (dict) – Dictionary containing meta data. see
qpimage.META_KEYS
.as_type (str) – Defines the data type that the input data is casted to. The default is “float32” which saves memory. If high numerical accuracy is required (does not apply for a simple 2D phase analysis), set this to double precision (“float64”).
- get_identifier(idx=0)[source]
Return an identifier for the data at index idx
Changed in version 0.4.2: indexing starts at 1 instead of 0
- get_name(idx=0)[source]
Return name of data at index idx
Changed in version 0.4.2: indexing starts at 1 instead of 0
- property identifier
Return a unique identifier for the given data set
- saveh5(h5file, qpi_slice=None, series_slice=None, time_interval=None, count=None, max_count=None)
Save the data set as an HDF5 file (qpimage.QPSeries format)
- Parameters
h5file (str, pathlib.Path, or h5py.Group) – Where to store the series data
qpi_slice (tuple of (slice, slice)) – If not None, only store a slice of each QPImage in h5file. A value of None is equivalent to
(slice(0, -1), slice(0, -1))
.series_slice (slice) – If None, save the entire series, otherwise only save the images specified by this slice.
time_interval (tuple of (float, float)) – If not None, only stores QPImages that were recorded within the given time interval.
count (multiprocessing.Value) – Can be used to monitor the progress of the algorithm. Initially, the value of max_count.value is incremented by the total number of steps. At each step, the value of count.value is incremented.
max_count (multiprocessing.Value) – Can be used to monitor the progress of the algorithm. Initially, the value of max_count.value is incremented by the total number of steps. At each step, the value of count.value is incremented.
Notes
The series “identifier” meta data is only set when all of qpi_slice, series_slice, and time_interval are None.
- set_bg(dataset)
Set background data
- Parameters
dataset (DataSet, qpimage.QPImage, or int) – If the
len(dataset)
matcheslen(self)
, then background correction is performed element-wise. Otherwise,len(dataset)
must be one and is used for all data ofself
.
See also
get_qpimage
obtain the background corrected QPImage
- property shape
Return dataset shape (lenght, image0, image1).
This should be overridden by the subclass, because by default the first qpimage is used for that.
- abstract static verify(path)
Verify that path has this file format
Returns True if the file format matches. The implementation of this method should be fast and memory efficient, because e.g. the “GroupFolder” file format depends on it.
- path
pathlib.Path to data file or io.IOBase
- meta_data
Enforced metadata via keyword arguments
- holo_kw
Hologram retrieval; keyword arguments for
qpimage.holo.get_field()
.
- background_identifier
Unique string that identifies the background data that was set using set_bg.
file format readers
All file formats inherit from qpformat.file_formats.SeriesData
(and/or qpformat.file_formats.SingleData
).
SeriesFolder
SeriesHDF5SinogramMeep
- class qpformat.file_formats.SeriesHDF5SinogramMeep(path, meta_data=None, *args, **kwargs)[source]
sinograms extracted from Meep/FDTD simulations
I introduced this format in 2022 as part of my efforts to make the finite-difference time domain simulations from the ODTbrain manuscript [MSG15] publicly available.
The HDF5 file contains a “background” and a “sinogram” group. The subgroups of “sinogram” are enumerated starting with “0”. Each of them contain the complex “field” at a plane behind the scattering phantom as an HDF5 Dataset. The location of the plane (and all other relevant metadata) is stored in the attributes of this Dataset. In the same group, there are also the C++ “simulation_code” and the log “simulation_output” which can be used to reproduce the simulation.
Initialize with default wavelength of 500nm
- is_series = True
- storage_type = 'field'
SeriesHdf5HyperSpy
- class qpformat.file_formats.SeriesHdf5HyperSpy(path, meta_data=None, holo_kw=None, as_type='float32')[source]
HyperSpy hologram series (HDF5 format)
HyperSpy has its own implementation to read this file format.
- is_series = True
- storage_type = 'raw-oah'
SeriesHdf5Qpimage
SeriesHdf5QpimageSubjoined
SeriesZipTifHolo
- class qpformat.file_formats.SeriesZipTifHolo(*args, **kwargs)[source]
Off-axis hologram series (zipped TIFF files)
The data are stored as multiple TIFF files (
qpformat.file_formats.SingleTifHolo
) in a zip file.- is_series = True
- storage_type = 'raw-oah'
- property files
List of hologram data file names in the input zip file
SeriesZipTifPhasics
- class qpformat.file_formats.SeriesZipTifPhasics(*args, **kwargs)[source]
Phasics series data (zipped “SID PHA*.tif” files)
The data are stored as multiple TIFF files (
qpformat.file_formats.SingleTifPhasics
) in a zip file.- is_series = True
- storage_type = 'phase,intensity'
- property files
List of Phasics tif file names in the input zip file
SingleHdf5Qpimage
SingleNpyNumpy
- class qpformat.file_formats.SingleNpyNumpy(path, meta_data=None, holo_kw=None, as_type='float32')[source]
Numpy complex field or phase data (numpy binary format)
The experimental data given in path consist of a single 2D ndarray (no pickled objects). The ndarray is either complex-valued (scattered field) or real-valued (phase).
- is_series = False
- storage_type
Depending on input data type, the storage type is either “field” (complex) or “phase” (real).
SingleTifHolo
SingleTifPhasics
- class qpformat.file_formats.SingleTifPhasics(path, meta_data={}, *args, **kwargs)[source]
Phasics image (“SID PHA*.tif”)
Notes
Only the processed phase data files are supported, i.e. TIFF file names starting with “SID PHA” exported by the commercial Phasics software.
If the “wavelength” key in meta_data is not set (units: [m]), then the wavelength is extracted from the xml data stored in tag “61238” of the tif file.
- is_series = False
- storage_type = 'phase,intensity'
exceptions
- exception qpformat.file_formats.MultipleFormatsNotSupportedError[source]
Used when a folder contains series file formats
(see GitHub issue #1)