imagestructurefunction¶
Image structure function data class.
The ImageStructureFunction object is used to store and retrieve information
about the image structure function computed in DDM.
The ImageStructureFunction.data contains the image structure function
values in \((\Delta t, k_y, k_x)\) order. For instance, the image
structure function at the 10th delay computed can be accessed via
dqt.data[9]
Note
Remember that Python uses zero-based indexing.
The ImageStructureFunction can then be saved into a binary file by using
ImageStructureFunction.save() (it will have a .sf.ddm extension)
and later retrieved from the memory using
SFReader.load(), which you can call directly from fastddm as
# load image structure function
dqt = fastddm.load("path/to/my_dqt_file.sf.ddm")
In order to avoid reading and loading the entire file, we also provide
a fast reader through the SFReader, which can be used to
access directly from the disk the relevant data, for example:
from fastddm.imagestructurefunction import SFReader
# open file
r = SFReader("path/to/my_dqt_file.sf.ddm")
# access quantities in full plane representation
# access kx array
kx = r.get_kx()
# access 10th computed delay
frame = r.get_frame(index=9)
# access the same quantities in half plane representation
kx_half = r.get_kx(full=False)
frame_half = r.get_frame(index=9, full=False)
- class fastddm.imagestructurefunction.ImageStructureFunction(_data: ndarray, _kx: ndarray, _ky: ndarray, _width: int, _height: int, _tau: ndarray, _pixel_size: float = 1.0, _delta_t: float = 1.0)¶
Image structure function container class.
- Parameters:
_data (numpy.ndarray) – The packed data (2D image structure function, power spectrum, and variance).
_kx (numpy.ndarray) – The array of wavevector values over x.
_ky (numpy.ndarray) – The array of wavevector values over y.
_width (int) – The width of the full (symmetric) 2D image structure function.
_height (int) – The height of the full (symmetric) 2D image structure function.
_tau (numpy.ndarray) – The array of time delays.
_pixel_size (float, optional) – The effective pixel size. Default is 1.
_delta_t (float, optional) – The time delay between two consecutive frames. Default is 1.
- __len__()¶
Length of the image structure function data. It coincides with the number of lags.
- Returns:
The length of data.
- Return type:
- full_kx() ndarray¶
Get the full array of wavevector values over x.
- Returns:
The full
kxarray.- Return type:
- full_ky() ndarray¶
Get the full array of wavevector values over y.
- Returns:
The full
kyarray.- Return type:
- full_power_spec() ndarray¶
Get the full (symmetric) average 2D power spectrum of the input images.
- Returns:
The full 2D power spectrum.
- Return type:
- full_slice(idx: int) ndarray¶
Get the full (symmetric) 2D image structure function at index
idx.- Parameters:
idx (int) – The slice index.
- Returns:
The full 2D image structure function slice.
- Return type:
- Raises:
IndexError – If
idxis out of bounds.
- full_var() ndarray¶
Get the full (symmetric) 2D variance (over time) of the Fourier transformed images.
- Returns:
The full 2D variance.
- Return type:
- save(fname: str = 'analysis_blob') None¶
Save
ImageStructureFunctionto binary file.- Parameters:
fname (str, optional) – The full file name, by default “analysis_blob”.
- save_as_tiff(seq: Sequence[int], fnames: Sequence[str]) None¶
Save
ImageStructureFunctionframes as images.- Parameters:
- Raises:
RuntimeError – If number of elements in
fnamesandseqare different.
- set_frame_rate(frame_rate: float) None¶
Set the acquisition frame rate.
This will propagate also on the values of
tau.- Parameters:
frame_rate (float) – The acquisition frame rate.
- property data: ndarray¶
The 2D image structure function (in \((\Delta t, k_y, k_x)\) order).
- Returns:
The 2D image structure function.
- Return type:
- property delta_t: float¶
The time delay between to consecutive frames.
- Returns:
Time delay.
- Return type:
- property height: int¶
The height of the full (symmetric) 2D image structure function.
- Returns:
The full height.
- Return type:
- property kx: ndarray¶
The array of wave vector values over x.
- Returns:
The array of
kx.- Return type:
- property ky: ndarray¶
The array of wave vector values over y.
- Returns:
The array of
ky.- Return type:
- property power_spec: ndarray¶
The average 2D power spectrum of the input images.
- Returns:
The average 2D power spectrum of the input images.
- Return type:
- class fastddm.imagestructurefunction.SFParser(fh: BinaryIO)¶
Image structure function file parser class.
Inherits from
Parser.
- class fastddm.imagestructurefunction.SFReader(file: str)¶
FastDDM image structure function reader class.
Inherits from
Reader.- get_frame(index: int, full: bool | None = True) ndarray¶
Read
dataslice array from file.- Parameters:
- Returns:
The
dataslice array.- Return type:
- Raises:
IndexError – If
indexis out of range.
- get_kx(full: bool | None = True) ndarray¶
Read
kxarray from file.- Parameters:
full (Optional[bool]) – If True, return the full (symmetric)
kxarray. Default is True.- Returns:
The
kxarray.- Return type:
- get_ky(full: bool | None = True) ndarray¶
Read
kyarray from file.- Parameters:
full (Optional[bool]) – If True, return the full (symmetric)
kyarray. Default is True. This flag has in fact no effect on the output sincekyis already full.- Returns:
The
kyarray.- Return type:
- get_power_spec(full: bool | None = True) ndarray¶
Read power spectrum array from file.
- Parameters:
full (Optional[bool]) – If True, return the full (symmetric) power spectrum. Default is True.
- Returns:
The power spectrum array.
- Return type:
- get_var(full: bool | None = True) ndarray¶
Read variance array from file.
- Parameters:
full (Optional[bool]) – If True, return the full (symmetric) variance. Default is True.
- Returns:
The variance array.
- Return type:
- load() ImageStructureFunction¶
Load image structure function from file.
- Returns:
ImageStructureFunctionobject.- Return type:
- Raises:
IOError – If file version not supported.
- class fastddm.imagestructurefunction.SFWriter(file: str)¶
Image structure function writer class.
Inherits from
Writer. It adds the unique methodwrite_obj. Defines the functions to writeImageStructureFunctionobject to binary file.The structure of the binary file is the following:
Header:
bytes 0-1: endianness, string, utf-8 encoding [
"LL"= ‘little’,"BB"= ‘big’]bytes 2-3: file identifier, 16-bit integer, unsigned short [
73for image structure function]bytes 4-5: file version, pair of 8-bit integers as (major_version, minor_version), unsigned char
byte 6: dtype, string, utf-8 encoding [
"d"= float64,"f"= float32]bytes 7-14: data length, 64-bit integer, unsigned long long
bytes 15-22: data height, 64-bit integer, unsigned long long
bytes 23-30: data width, 64-bit integer, unsigned long long
bytes 31-38: extra slices, 64-bit integer, unsigned long long
bytes 39-46: full width, 64-bit integer, unsigned long long
bytes 47-54: full height, 64-bit integer, unsigned long long
The data is stored in ‘C’ order and
dtypeformat as follows:from byte
data_offset:_datafrom byte
extra_offset: extra datafrom byte
kx_offset:kxarrayfrom byte
ky_offset:kyarrayfrom byte
tau_offset:tauarrayfrom byte
pixel_size_offset:pixel_sizevaluefrom byte
delta_t_offset:delta_tvalue
From the end of the file, the byte offsets are stored as unsigned long long 64-bit integers in this order:
data_offsetkx_offsetky_offsettau_offsetpixel_size_offsetdelta_t_offsetextra_offset
- write_obj(obj: ImageStructureFunction) None¶
Write
ImageStructureFunctionobject to binary file.- Parameters:
obj (ImageStructureFunction) –
ImageStructureFunctionobject.