dacapo.experiments.datasplits.datasets.arrays.numpy_array
Classes
This is just a wrapper for a numpy array to make it fit the DaCapo Array interface. |
Module Contents
- class dacapo.experiments.datasplits.datasets.arrays.numpy_array.NumpyArray(array_config)
This is just a wrapper for a numpy array to make it fit the DaCapo Array interface.
- data
The numpy array.
- dtype
The data type of the numpy array.
- roi
The region of interest of the numpy array.
- voxel_size
The voxel size of the numpy array.
- axes
The axes of the numpy array.
- from_gp_array()
Create a NumpyArray from a Gunpowder Array.
- from_np_array()
Create a NumpyArray from a numpy array.
Note
This class is a subclass of Array.
- property attrs
- Returns the attributes of the array.
- Returns:
The attributes of the array.
- Return type:
dict
- Raises:
ValueError – If the array does not have attributes.
Examples
>>> array = NumpyArray.from_np_array(np.zeros((2, 3, 4)), Roi((0, 0, 0), (2, 3, 4)), Coordinate((1, 1, 1)), ["z", "y", "x"]) >>> array.attrs {}
Note
This method is a property. It returns the attributes of the array.
- classmethod from_gp_array(array: gunpowder.Array)
Create a NumpyArray from a Gunpowder Array.
- Parameters:
array (gp.Array) – The Gunpowder Array.
- Returns:
The NumpyArray.
- Return type:
- Raises:
ValueError – If the array does not have a data type.
Examples
>>> array = gp.Array(data=np.zeros((2, 3, 4)), spec=gp.ArraySpec(roi=Roi((0, 0, 0), (2, 3, 4)), voxel_size=Coordinate((1, 1, 1)))) >>> array = NumpyArray.from_gp_array(array) >>> array.data array([[[0., 0., 0., 0.], [0., 0., 0., 0.], [0., 0., 0., 0.]], [[0., 0., 0., 0.], [0., 0., 0., 0.], [0., 0., 0., 0.]]])
Note
This method creates a NumpyArray from a Gunpowder Array.
- classmethod from_np_array(array: numpy.ndarray, roi, voxel_size, axes)
Create a NumpyArray from a numpy array.
- Parameters:
array (np.ndarray) – The numpy array.
roi (Roi) – The region of interest of the array.
voxel_size (Coordinate) – The voxel size of the array.
axes (List[str]) – The axes of the array.
- Returns:
The NumpyArray.
- Return type:
- Raises:
ValueError – If the array does not have a data type.
Examples
>>> array = NumpyArray.from_np_array(np.zeros((2, 3, 4)), Roi((0, 0, 0), (2, 3, 4)), Coordinate((1, 1, 1)), ["z", "y", "x"]) >>> array.data array([[[0., 0., 0., 0.], [0., 0., 0., 0.], [0., 0., 0., 0.]], [[0., 0., 0., 0.], [0., 0., 0., 0.], [0., 0., 0., 0.]]])
Note
This method creates a NumpyArray from a numpy array.
- property axes
- Returns the axes of the array.
- Returns:
The axes of the array.
- Return type:
List[str]
- Raises:
ValueError – If the array does not have axes.
Examples
>>> array = NumpyArray.from_np_array(np.zeros((2, 3, 4)), Roi((0, 0, 0), (2, 3, 4)), Coordinate((1, 1, 1)), ["z", "y", "x"]) >>> array.axes ['z', 'y', 'x']
Note
This method is a property. It returns the axes of the array.
- property dims
- Returns the number of dimensions of the array.
- Returns:
The number of dimensions of the array.
- Return type:
int
- Raises:
ValueError – If the array does not have a dimension.
Examples
>>> array = NumpyArray.from_np_array(np.zeros((2, 3, 4)), Roi((0, 0, 0), (2, 3, 4)), Coordinate((1, 1, 1)), ["z", "y", "x"]) >>> array.dims 3
Note
This method is a property. It returns the number of dimensions of the array.
- property voxel_size
- Returns the voxel size of the array.
- Returns:
The voxel size of the array.
- Return type:
Coordinate
Examples
>>> array = NumpyArray.from_np_array(np.zeros((2, 3, 4)), Roi((0, 0, 0), (2, 3, 4)), Coordinate((1, 1, 1)), ["z", "y", "x"]) >>> array.voxel_size Coordinate((1, 1, 1))
Note
This method is a property. It returns the voxel size of the array.
- property roi
- Returns the region of interest of the array.
- Returns:
The region of interest of the array.
- Return type:
Roi
Examples
>>> array = NumpyArray.from_np_array(np.zeros((2, 3, 4)), Roi((0, 0, 0), (2, 3, 4)), Coordinate((1, 1, 1)), ["z", "y", "x"]) >>> array.roi Roi((0, 0, 0), (2, 3, 4))
Note
This method is a property. It returns the region of interest of the array.
- property writable: bool
Returns whether the array is writable.
- Returns:
Whether the array is writable.
- Return type:
bool
- Raises:
ValueError – If the array is not writable.
Examples
>>> array = NumpyArray.from_np_array(np.zeros((2, 3, 4)), Roi((0, 0, 0), (2, 3, 4)), Coordinate((1, 1, 1)), ["z", "y", "x"]) >>> array.writable True
Note
This method is a property. It returns whether the array is writable.
- property data
- Returns the numpy array.
- Returns:
The numpy array.
- Return type:
np.ndarray
Examples
>>> array = NumpyArray.from_np_array(np.zeros((2, 3, 4)), Roi((0, 0, 0), (2, 3, 4)), Coordinate((1, 1, 1)), ["z", "y", "x"]) >>> array.data array([[[0., 0., 0., 0.], [0., 0., 0., 0.], [0., 0., 0., 0.]], [[0., 0., 0., 0.], [0., 0., 0., 0.], [0., 0., 0., 0.]]])
Note
This method is a property. It returns the numpy array.
- property dtype
- Returns the data type of the array.
- Returns:
The data type of the array.
- Return type:
np.dtype
- Raises:
ValueError – If the array does not have a data type.
Examples
>>> array = NumpyArray.from_np_array(np.zeros((2, 3, 4)), Roi((0, 0, 0), (2, 3, 4)), Coordinate((1, 1, 1)), ["z", "y", "x"]) >>> array.dtype dtype('float64')
Note
This method is a property. It returns the data type of the array.
- property num_channels
- Returns the number of channels in the array.
- Returns:
The number of channels in the array.
- Return type:
int
- Raises:
ValueError – If the array does not have a channel dimension.
Examples
>>> array = NumpyArray.from_np_array(np.zeros((1, 2, 3, 4)), Roi((0, 0, 0), (1, 2, 3)), Coordinate((1, 1, 1)), ["b", "c", "z", "y", "x"]) >>> array.num_channels 1 >>> array = NumpyArray.from_np_array(np.zeros((2, 3, 4)), Roi((0, 0, 0), (2, 3, 4)), Coordinate((1, 1, 1)), ["z", "y", "x"]) >>> array.num_channels Traceback (most recent call last): ... ValueError: Array does not have a channel dimension.
Note
This method is a property. It returns the number of channels in the array.