tomoscan.esrf.volume.jp2kvolume.JP2KVolume¶
- class tomoscan.esrf.volume.jp2kvolume.JP2KVolume(folder: Optional[str] = None, volume_basename: Optional[str] = None, data: Optional[ndarray] = None, source_scan: Optional[TomoScanBase] = None, metadata: Optional[dict] = None, data_url: Optional[DataUrl] = None, metadata_url: Optional[DataUrl] = None, overwrite: bool = False, start_index=0, data_extension='jp2', metadata_extension='txt', cratios: Optional[list] = None, psnr: Optional[list] = None, n_threads: Optional[int] = None, clip_values: Optional[tuple] = None, rescale_data: bool = True)¶
Bases:
VolumeSingleFrameBaseSave volume data to single frame jp2k files and metadata to .txt file
- Parameters:
cratios (Optional[list]) – list of ints. compression ratio for each jpeg2000 layer
psnr (Optional[list]) – list of int. The PSNR (Peak Signal-to-Noise ratio) for each jpeg2000 layer. This defines a quality metric for lossy compression. The number “0” stands for lossless compression.
n_threads (Optional[int]) – number of thread to use for writing. If None will try to get as much as possible
clip_values (Optional[tuple]) – optional tuple of two float (min, max) to clamp volume value
rescale_data (bool) – rescale data before dumping each frame. Expected to be True when dump a new volume and False when save volume cast for example (and when histogram is know…)
- Warning:
each file saved under {volume_basename}_{index_zfill6}.jp2k is considered to be a slice of the volume.
- __init__(folder: Optional[str] = None, volume_basename: Optional[str] = None, data: Optional[ndarray] = None, source_scan: Optional[TomoScanBase] = None, metadata: Optional[dict] = None, data_url: Optional[DataUrl] = None, metadata_url: Optional[DataUrl] = None, overwrite: bool = False, start_index=0, data_extension='jp2', metadata_extension='txt', cratios: Optional[list] = None, psnr: Optional[list] = None, n_threads: Optional[int] = None, clip_values: Optional[tuple] = None, rescale_data: bool = True) None¶
Methods
__init__([folder, volume_basename, data, ...])browse_data_files([url])- param url:
data url. If not provided will take self.data_url
browse_data_urls([url])generator on data urls used.
browse_metadata_files([url])- param url:
metadata url. If not provided will take self.metadata_url
browse_slices([url])generator of 2D numpy array representing a slice
check_can_provide_identifier()remove object stored in data and medatada
data_file_name_generator(n_frames, data_url)browse output files for n_frames
data_file_saver_generator(n_frames, ...)Provide a helper class to dump data frame by frame.
compute data and metadata urls from 'parent url' :return: data_url: Optional[DataUrl], metadata_url: Optional[DataUrl]
example as string to explain how users can defined identifiers from a string
format_data_path_for_data(data_path, index, ...)Return file path to save the frame at index of the current volume
from_identifier(identifier)Return the Dataset from a identifier
get_bounding_box([axis])Return the bounding box covered by the Tomo object axis is expected to be in (0, 1, 2) or (x==0, y==1, z==2)
get_data_path_pattern_for_data(data_path, ...)Return file path pattern (and not full path) to load data.
dataset unique identifier.
compute min max of the volume.
get_min_max_values([url])compute min max over 'data' if exists else browsing the volume slice by slice
get_slice([index, axis, xy, xz, yz, url])get_volume_basename([url])get_volume_shape([url])load()load_chunk(chunk[, url])Load a sub-volume.
load_data([url, store])load_frame(file_name, scheme)Function dedicated for volune saving each frame on a single file
load_metadata([url, store])save([url])save_data([url])save data to the provided url or existing one if none is provided
save_frame(frame, file_name, scheme)Function dedicated for volune saving each frame on a single file
save_metadata([url])save metadata to the provided url or existing one if none is provided
select(volume[, xy, xz, yz, axis, index])setup_multithread_encoding([n_threads, ...])Setup OpenJpeg multi-threaded encoding.
Attributes
DEFAULT_DATA_EXTENSIONDEFAULT_DATA_PATH_PATTERNDEFAULT_DATA_SCHEMEDEFAULT_METADATA_EXTENSIONDEFAULT_METADATA_PATH_PATTERNDEFAULT_METADATA_SCHEMEEXTENSION- return:
optional min and max value to clip - as float.
cratiosdatadata_extensiondata_urlextensionmetadatametadata_extensionmetadata_urloverwritepixel_sizeposition are provided as a tuple using the same reference for axis as the volume data.
psnrrescale_datasource_scanstart_indexurlvoxel size as (axis 0 dim - aka z, axis 1 dim - aka y, axis 2 dim aka z)
- browse_data_files(url=None)¶
- Parameters:
url – data url. If not provided will take self.data_url
return a generator go through all the existings files associated to the data volume
- browse_data_urls(url=None)¶
generator on data urls used.
- Parameters:
url – data url to be used. If not provided will take self.data_url
- browse_metadata_files(url=None)¶
- Parameters:
url – metadata url. If not provided will take self.metadata_url
return a generator go through all the existings files associated to the data volume
- browse_slices(url=None)¶
generator of 2D numpy array representing a slice
- Parameters:
url – data url to be used. If not provided will browse self.data if exists else self.data_url
- Warning:
this will get the slice from the data on disk and never use data property. so before browsing slices you might want to check if data is already loaded
- clear_cache()¶
remove object stored in data and medatada
- property clip_values: Optional[tuple]¶
- Returns:
optional min and max value to clip - as float.
- Return type:
Optional[tuple]
- data_file_name_generator(n_frames, data_url)¶
browse output files for n_frames
- data_file_saver_generator(n_frames, data_url: DataUrl, overwrite: bool)¶
Provide a helper class to dump data frame by frame. For know the only possible interaction is Helper[:] = frame
- Parameters:
n_frames (int) – number of frame the final volume will contain
data_url (DataUrl) – url to dump data
overwrite (bool) – overwrite existing file ?
- deduce_data_and_metadata_urls(url: Optional[DataUrl]) tuple¶
compute data and metadata urls from ‘parent url’ :return: data_url: Optional[DataUrl], metadata_url: Optional[DataUrl]
- static example_defined_from_str_identifier() str¶
example as string to explain how users can defined identifiers from a string
- format_data_path_for_data(data_path: str, index: int, volume_basename: str) str¶
Return file path to save the frame at index of the current volume
- static from_identifier(identifier)¶
Return the Dataset from a identifier
- get_bounding_box(axis: Optional[Union[str, int]] = None)¶
Return the bounding box covered by the Tomo object axis is expected to be in (0, 1, 2) or (x==0, y==1, z==2)
- get_data_path_pattern_for_data(data_path: str, volume_basename: str) str¶
Return file path pattern (and not full path) to load data. For example in edf it can return ‘myacquisition_*.edf’ in order to be handled by
- get_identifier() JP2KVolumeIdentifier¶
dataset unique identifier. Can be for example a hdf5 and en entry from which the dataset can be rebuild
- get_min_max() tuple¶
compute min max of the volume. Can take some time but avoid to load the full volume in memory
- get_min_max_values(url=None) tuple¶
compute min max over ‘data’ if exists else browsing the volume slice by slice
- Parameters:
url – data url to be used. If not provided will take self.data_url
- load_chunk(chunk, url=None)¶
Load a sub-volume.
- Parameters:
chunk – tuple of slice objects indicating which chunk of the volume has to be loaded.
url – data url to be used. If not provided will take self.data_url
- load_frame(file_name, scheme)¶
Function dedicated for volune saving each frame on a single file
- Parameters:
file_name (str) – path to store the data
scheme (str) – scheme to save the data
- property position: Optional[tuple]¶
position are provided as a tuple using the same reference for axis as the volume data. position is returned as (axis_0_pos, axis_1_pos, axis_2_pos). Can also be see as (z_position, y_position, x_position)
- save_data(url: Optional[DataUrl] = None) None¶
save data to the provided url or existing one if none is provided
- save_frame(frame, file_name, scheme)¶
Function dedicated for volune saving each frame on a single file
- Parameters:
frame (numpy.ndarray) – frame to be save
file_name (str) – path to store the data
scheme (str) – scheme to save the data
- save_metadata(url: Optional[DataUrl] = None) None¶
save metadata to the provided url or existing one if none is provided
- static setup_multithread_encoding(n_threads=None, what_if_not_available='ignore')¶
Setup OpenJpeg multi-threaded encoding.
- n_threads: int, optional
Number of threads. If not provided, all available threads are used.
- na: str, optional
- What to do if requirements are not fulfilled. Possible values are:
“ignore”: do nothing, proceed
“print”: show an information message
“raise”: raise an error
- property voxel_size: Optional[tuple]¶
voxel size as (axis 0 dim - aka z, axis 1 dim - aka y, axis 2 dim aka z)