Skip to content

nabu.io.cast_volume

source module nabu.io.cast_volume

Functions

  • cast_volume cast given volume to output_volume of 'output_data_type' type

  • get_default_output_volume For a given input volume and output type return output volume as an instance of VolumeBase

  • clamp_and_rescale_data rescale data to 'new_min', 'new_max'

  • find_histogram Look for histogram of the provided url. If found one return the DataUrl of the nabu histogram

  • remove_volume Remove files belonging to a volume, claim disk space.

source cast_volume(input_volume: VolumeBase, output_volume: VolumeBase, output_data_type: numpy.dtype, data_min=None, data_max=None, scan=None, rescale_min_percentile=RESCALE_MIN_PERCENTILE, rescale_max_percentile=RESCALE_MAX_PERCENTILE, save=True, store=False, remove_input_volume: bool = False)VolumeBase

cast given volume to output_volume of 'output_data_type' type

:param VolumeBase input_volume: :param VolumeBase output_volume: :param numpy.dtype output_data_type: output data type :param number data_min: data min value to clamp to new_min. Any lower value will also be clamp to new_min. :param number data_max: data max value to clamp to new_max. Any hight value will also be clamp to new_max. :param TomoScanBase scan: source scan that produced input_volume. Can be used to find histogram for example. :param rescale_min_percentile: if data_min is None will set data_min to 'rescale_min_percentile' :param rescale_max_percentile: if data_max is None will set data_min to 'rescale_max_percentile' :param bool save: if True dump the slice on disk (one by one) :param bool store: if True once the volume is cast then set output_volume.data :return: output_volume with data and metadata set

.. warning:: the created will volume will not be saved in this processing. If you want to save the cast volume you must do it yourself.

.. note:: if you want to tune compression ratios (for jp2k) then please update the cratios attributes of the output volume

Raises

  • TypeError

source get_default_output_volume(input_volume: VolumeBase, output_type: str, output_dir: str = _DEFAULT_OUTPUT_DIR)VolumeBase

For a given input volume and output type return output volume as an instance of VolumeBase

:param VolumeBase intput_volume: volume for which we want to get the resulting output volume for a cast :param str output_type: output_type of the volume (edf, tiff, hdf5...) :param str output_dir: output dir to save the cast volume

Raises

  • TypeError

  • ValueError

  • NotImplementedError

source clamp_and_rescale_data(data: numpy.ndarray, new_min, new_max, data_min=None, data_max=None, rescale_min_percentile=RESCALE_MIN_PERCENTILE, rescale_max_percentile=RESCALE_MAX_PERCENTILE, default_value_for_nan=None, do_float64=True)

rescale data to 'new_min', 'new_max'

Parameters

  • data : numpy.ndarray Data to be rescaled (image or volume)

  • new_min : scalar Rescaled data new min (clamp min value)

  • new_max : scalar Rescaled data new min (clamp max value)

  • data_min : scalar, optional Data minimum value. If not provided, will re-compute the min() over data.

  • data_max : scalar, optional Data maximum value. If not provided, will re-compute the min() over data.

  • rescale_min_percentile : scalar, optional if data_min is None will set data_min to 'rescale_min_percentile'

  • rescale_max_percentile if data_max is None will set data_min to 'rescale_max_percentile'

  • default_value_for_nan : scalar, optional Value that will replace NaNs, if any. Default is None (keep NaNs, will likely raise an error)

  • do_float64 Whether to do internal computations in float64. Recommended when casting from float32 to int32 for example.

source find_histogram(volume: VolumeBase, scan=None)

Look for histogram of the provided url. If found one return the DataUrl of the nabu histogram

Raises

  • TypeError

  • NotImplementedError

source remove_volume(volume, check=True)

Remove files belonging to a volume, claim disk space.

Parameters

  • volume : tomoscan.esrf.volume Volume object

  • check : bool, optional Whether to check if the files that would be removed do not have extra other files ; interrupt the operation if so.

Raises

  • TypeError

  • NotImplementedError