mantidimaging.core.io.saver module

mantidimaging.core.io.saver.generate_names(name_prefix: str, indices: List[int] | Indices | None, num_images: int, custom_idx: int | None = None, zfill_len: int = 6, name_postfix: str = '', out_format: str = 'tif') List[str][source]
mantidimaging.core.io.saver.make_dirs_if_needed(dirname: str | None = None, overwrite_all: bool = False)[source]

Makes sure that the directory needed (for example to save a file) exists, otherwise creates it.

Parameters:

: (dirname) – (output) directory to check

mantidimaging.core.io.saver.rescale_single_image(image: ndarray, min_input: float, max_input: float, max_output: float) ndarray[source]
mantidimaging.core.io.saver.save(images: Images, output_dir: str, name_prefix: str = 'image', swap_axes: bool = False, out_format: str = 'tif', overwrite_all: bool = False, custom_idx: int | None = None, zfill_len: int = 6, name_postfix: str = '', indices: List[int] | Indices | None = None, pixel_depth: str | None = None, progress: Progress | None = None) str | List[str][source]

Save image volume (3d) into a series of slices along the Z axis. The Z axis in the script is the ndarray.shape[0].

Parameters:
  • images – Data as images/slices stores in numpy array

  • output_dir – Output directory for the files

  • name_prefix – Prefix for the names of the images, appended before the image number

  • swap_axes – Swap the 0 and 1 axis of the images (convert from radiograms to sinograms on saving)

  • out_format – File format of the saved out images

  • overwrite_all – Overwrite existing images with conflicting names

  • custom_idx – Single index to be used for the file name, instead of incremental numbers

  • zfill_len – This option is ignored if custom_idx is specified! Prepend zeros to the output file names to have a constant file name length. Example: - saving out an image with zfill_len = 6: saved_image000001,…saved_image000201 and so on - saving out an image with zfill_len = 3: saved_image001,…saved_image201 and so on

  • name_postfix – Postfix for the name after the index

  • indices – Only works if custom_idx is not specified. Specify the start and end range of the indices which will be used for the file names.

  • progress – Passed to ensure progress during saving is tracked properly

  • pixel_depth – Defines the target pixel depth of the save operation so np.float32 or np.int16 will ensure the values are scaled correctly to these values.

Returns:

The filename/filenames of the saved data.

mantidimaging.core.io.saver.write_fits(data: ndarray, filename: str, overwrite: bool = False, description: str | None = '')[source]
mantidimaging.core.io.saver.write_img(data: ndarray, filename: str, overwrite: bool = False, description: str | None = '')[source]
mantidimaging.core.io.saver.write_nxs(data: ndarray, filename: str, projection_angles: ndarray | None = None, overwrite: bool = False)[source]