The managers sub-package#

The pydidas.managers sub-package includes manager classes which handle certain aspects of pydidas.

class pydidas.managers.CompositeImageManager(*args, **kwargs)#

A manager to arrrange images in a composite.

The CompositeImage class holds a numpy array to combine individual images to a composite and to provide basic insertion and manipulation routines.

apply_thresholds(**kwargs: dict)#

Apply thresholds to the composite image.

This method applies thresholds to the composite image. By default, it will apply the thresholds defined in the ParameterCollection but these can be overwritten with the low and high arguments. Note that these values will be used to update the ParameterCollection. This method will only apply the thresholds to the image but will not return the iamge itself.

Parameters:
  • low (Union[float, None], optional) – The lower threshold. If not specified, the stored lower threshold from the ParameterCollection will be used. A value of np.nan or None will be ignored.

  • high (Union[float, None], optional) – The upper threshold. If not specified, the stored upper threshold from the ParameterCollection will be used. A value of np.nan or None will be ignored.

create_new_image()#

Create a new image array with the stored Parameters.

The new image array is accessible through the .image property.

export(output_fname: Path | str, **kwargs: dict)#

Export the image to a file.

Parameters:
  • output_fname (Union[Path, str]) – The full file system path and filename for the output image file.

  • **kwargs (dict) – Optional keyword arguments to be passed to the exporters.

property image: ndarray#

Get the composite image.

Returns:

The composite image.

Return type:

np.ndarray

insert_image(image: ndarray, index: int)#

Put the image in the composite image.

This method will find the correct place for the image in the composite and copy the image data there.

Parameters:
  • image (np.ndarray) – The image data.

  • index (int) – The image index. This is needed to find the correct place for the image in the composite.

save(output_fname: str)#

Save the image in binary npy format.

Parameters:

output_fname (str) – The full filename and path to the output image file.

property shape: tuple[int, int]#

Get the shape of the composite image.

Returns:

The shape of the composite image.

Return type:

tuple[int, int]

class pydidas.managers.FilelistManager(*args: tuple, **kwargs: dict)#

The FilelistManager creates and manages a file list from which to select items for processing.

Any required Parameters can be supplied as arguments or with refkey=<ParameterInstance> as kwargs. Any Parameter not given will default to new instances with the default values.

Note

The FilelistManager uses the following generic Parameters:

live_processingbool, optional

Keyword to toggle live processing which means file existance and size checks will be disabled in the setup process and the file processing will wait for files to be created (indefinitely). The default is False.

first_filepathlib.Path

The name of the first file for a file series or of the hdf5 file in case of hdf5 file input.

last_filepathlib.Path, optional

Used only for file series: The name of the last file to be added to the composite image.

file_steppingint, optional

The step width (in files). A value n > 1 will only process every n-th image for the composite. The default is 1.

Parameters:
  • *args (tuple) – Any of the Parameters in use can be given as instances.

  • **kwargs (dict) – Parameters can also be supplied as kwargs, referencey by their refkey.

property filesize: float#

Get the file size of the processed files.

Returns:

The file size in bytes.

Return type:

float

get_config() dict#

Get the full _config dictionary.

Returns:

_config – The config dictionary with information about the file list, sizes and number of files.

Return type:

dict

get_filename(index: int) Path#

Get the filename of the image file numbered with index.

Parameters:

index (int) – The index of the image file.

Raises:

UserConfigError – If the file list is not correctly initiated or if the index is out of the range of the file list.

Returns:

The filename (and path) of the image file indexed with index.

Return type:

Path

property n_files: int#

Get the number of files.

Returns:

n_files – The number of files in the filelist.

Return type:

int

reset()#

Reset the filelist to the initial configuration.

update(first_file: None | str | Path = None, last_file: None | str | Path = None, live_processing: None | bool = None, file_stepping: None | int = None)#

Create a filelist with updated parameters.

Parameters:
  • first_file (Union[None, str, Path], optional) – The path to the first file. If None, the stored Parameter for ‘first_file’ will be used. The default is None.

  • last_file (Union[None, str, Path], optional) – The path to the last file. If None, the stored Parameter for ‘last_file’ will be used. The default is None.

  • live_processing (Union[None. bool], optional) – Flag for live processing (i.e. disable file system checks.) If None, the stored Parameter ‘live_processing’ will be used. The default is None.

  • file_stepping (Union[None, int], optional) – The file stepping number. If None, the stored Parameter ‘file_stepping’ will be used. The default is None.

class pydidas.managers.ImageMetadataManager(*args: tuple, **kwargs: dict)#

Class to handle image metadata.

The ImageMetadataManager is responsible for keeping track of the metadata (shape, datatype, imager per file) of image files. All the metadata is available for the user through class properties.

Note

The ImageMetadataManager uses the following generic Parameters:

filenamePath

The name of the first file for a file series or of the hdf5 file in case of hdf5 file input.

hdf5_keyHdf5key, optional

Used only for hdf5 files: The dataset key.

hdf5_slicing_axisint, optional

The slicing axis for hdf5 files, i.e. the axis used for iterating over the images. The default is 0.

hdf5_first_image_numint, optional

The first image in the hdf5-dataset to be used. The default is 0.

hdf5_last_image_numint, optional

The last image in the hdf5-dataset to be used. The value -1 will default to the last image. The default is -1.

hdf5_steppingint, optional

The step width (in images) of hdf5 datasets. A value n > 1 will only add every n-th image to the composite. The default is 1.

binningint, optional

The re-binning factor for the images in the composite. The binning will be applied to the cropped images. The default is 1.

Parameters:
  • *args (tuple) – Any of the Parameters in use can be given as instances.

  • **kwargs (dict) – Parameters can also be supplied as kwargs, referencey by their refkey.

property datatype: type#

Get the datatype of the raw image.

Returns:

The datatype class.

Return type:

type

property filename: Path#

Get the currently stored reference filename.

Returns:

The filename.

Return type:

Path

property final_shape: tuple[float, float]#

Get the final shape of the processed image (cropped & binned).

Returns:

The final shape of the image.

Return type:

tuple[float, float]

property hdf5_dset_shape: tuple[int, ...]#

Get the shape of the hdf5 dataset.

Returns:

The shape (number of datapoints) of the dataset.

Return type:

tuple[int, …]

property images_per_file: int#

Get the number of images per file.

Returns:

The number of images per file.

Return type:

int

property numbers: range | int#

Get the frame numbers pointing to the selected images.

Returns:

The selected frame numbers.

Return type:

Union[range, int]

property raw_size_x: int#

Get the x-size of the raw image.

Returns:

The number of pixels in x-direction.

Return type:

int

property raw_size_y: int#

Get the y-size of the raw image.

Returns:

The number of pixels in y-direction.

Return type:

int

property roi: None | tuple[slice, slice]#

Get the ROI object required to achieve the final image shape.

Returns:

Either None, if no ROI has been defined or a tuple with the slice objects for y and x dimensions.

Return type:

Union[None, tuple[slice, slice]]

store_image_data(img_shape: tuple[int, int], img_dtype: type, n_image: int)#

Store the data about the image shape and datatype.

Parameters:
  • img_shape (tuple[int, int]) – The shape of the image.

  • img_dtype (type) – The python datatype of the image.

  • n_image (int) – The number of images per file.

update(filename: str | Path | None = None)#

Perform a full update.

If a new filename is specified, it will be set as first action. Otherwise, the metadata will be extracted from the current file.

Parameters:

filename (Union[str, Path, None], optional) – The filename to be updated. If None, the current filename will be used. The default is None.

update_final_image()#

Calculate the dimensions of the final image.

update_input_data()#

Update the image metadata from new input.