navigate.model.data_sources.data_source.DataSource
- class navigate.model.data_sources.data_source.DataSource(file_name: str = '', mode: str = 'w')
Bases:
object
- __init__(file_name: str = '', mode: str = 'w') → None
Base class for data sources, which can be of arbitrary file type.
This implements read and write methods for accessing each data source. We expect to open the file for read or write during initialization.
file_name stores the name of the file to read/write from data stores a pointer to the actual data in the data source and metadata stores a pointer to the metadata.
Concept and some of the code borrowed from python-microscopy (https://github.com/python-microscopy/python-microscopy/).
- Parameters:
file_name (str) – Name of the file to read/write from.
mode (str) – Mode to open the file in. Can be ‘r’ or ‘w’.
Methods
__init__
([file_name, mode])Base class for data sources, which can be of arbitrary file type.
close
()Clean up any leftover file pointers, etc.
Get the shape of the data source from the metadata.
read
()Read data from file.
set_metadata
(metadata_config)Sets the metadata
Sets the metadata from according to the microscope configuration.
setup
()Additional steps for establishing the initial file setup.
write
(data, **kw)Writes 2D image to the data source.
Attributes
Return array representation of data stored in data source.
Getter for the mode of the data source.
Getter for the size of this data source in bytes.
Getter for the shape as XYCZT.
Getter for the voxel size
Logger for this class.
Name of the file to read/write from.
Pointer to the metadata.
Number of bits per pixel.
Pixel size in x dimension (microns).
Pixel size in x dimension (microns).
Pixel size in x dimension (microns).
The time interval between frames (seconds).
Step size between channels (always 1)
Size of the data source in x dimension.
Size of the data source in y dimension.
Size of the data source in z dimension.
Size of the data source in t dimension.
Size of the data source in c dimension.
Number of positions in the data source.
- close() → None
Clean up any leftover file pointers, etc.
- get_shape_from_metadata()
Get the shape of the data source from the metadata.
- read() → None
Read data from file.
- Raises:
NotImplementedError – If not implemented in a derived class.
- set_metadata(metadata_config: dict) → None
Sets the metadata
- Parameters:
metadata_config (dict) – shape configuration: “c”, “z”, “t”, “p”, “is_dynamic”, “per_stack”
- set_metadata_from_configuration_experiment(configuration: Dict[str, Any], microscope_name: Optional[str] = None) → None
Sets the metadata from according to the microscope configuration.
- Parameters:
configuration (Dict[str, Any]) – Configuration experiment.
microscope_name (str) – The microscope name
- setup()
Additional steps for establishing the initial file setup.
- write(data: Union[_SupportsArray[dtype], _NestedSequence[_SupportsArray[dtype]], bool, int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]], **kw) → None
Writes 2D image to the data source.
- Parameters:
data (npt.ArrayLike) – Data to write to file.
**kw (dict) – Additional keyword arguments.
- Raises:
NotImplementedError – If not implemented in a derived class.
- bits
Number of bits per pixel.
- Type:
int
- property data: Union[_SupportsArray[dtype], _NestedSequence[_SupportsArray[dtype]], bool, int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]
Return array representation of data stored in data source.
- Returns:
Array representation of data stored in data source.
- Return type:
npt.ArrayLike
- Raises:
NotImplementedError – If not implemented in a derived class.
- dc
Step size between channels (always 1)
- Type:
float
- dt
The time interval between frames (seconds).
- Type:
float
- dx
Pixel size in x dimension (microns). float: Pixel size in y dimension (microns). float: Pixel size in z dimension (microns).
- Type:
float
- dy
Pixel size in x dimension (microns). float: Pixel size in y dimension (microns). float: Pixel size in z dimension (microns).
- Type:
float
- dz
Pixel size in x dimension (microns). float: Pixel size in y dimension (microns). float: Pixel size in z dimension (microns).
- Type:
float
- file_name
Name of the file to read/write from.
- Type:
str
- logger
Logger for this class.
- Type:
logging.Logger
- metadata
Pointer to the metadata.
- Type:
npt.ArrayLike
- property mode: str
Getter for the mode of the data source.
- Returns:
Mode of the data source.
- Return type:
str
- property nbytes: int
Getter for the size of this data source in bytes.
Does not account for pyramidal data sources. That process is handled by the bdv_data_source class, which is a child of this class.
- Returns:
total_bytes – Size of this data source in bytes.
- Return type:
int
- positions
Number of positions in the data source.
- Type:
int
- property shape: tuple
Getter for the shape as XYCZT.
- Returns:
Shape of the data source in XYCZT format.
- Return type:
tuple
- shape_c
Size of the data source in c dimension.
- Type:
int
- shape_t
Size of the data source in t dimension.
- Type:
int
- shape_x
Size of the data source in x dimension.
- Type:
int
- shape_y
Size of the data source in y dimension.
- Type:
int
- shape_z
Size of the data source in z dimension.
- Type:
int
- property voxel_size: tuple
Getter for the voxel size
- Returns:
Voxel size in x, y, z dimensions.
- Return type:
tuple