dacapo.experiments.datasplits.datasets.arrays

Submodules

Classes

Array

An Array is a multi-dimensional array of data that can be read from and written to. It is

ArrayConfig

Base class for array configurations. Each subclass of an

DummyArray

This is just a dummy array for testing. It has a shape of (100, 50, 50) and is filled with zeros.

DummyArrayConfig

This is just a dummy array config used for testing. None of the

ZarrArray

This is a zarr array.

ZarrArrayConfig

This config class provides the necessary configuration for a zarr array.

BinarizeArray

This is wrapper around a ZarrArray containing uint annotations.

BinarizeArrayConfig

This config class provides the necessary configuration for turning an Annotated dataset into a

ResampledArray

This is a zarr array that is a resampled version of another array.

ResampledArrayConfig

A configuration for a ResampledArray. This array will up or down sample an array into the desired voxel size.

IntensitiesArray

This is wrapper another array that will normalize intensities to

IntensitiesArrayConfig

This config class provides the necessary configuration for turning an Annotated dataset into a

MissingAnnotationsMask

This is wrapper around a ZarrArray containing uint annotations.

MissingAnnotationsMaskConfig

This config class provides the necessary configuration for turning an Annotated dataset into a

OnesArray

This is a wrapper around another source_array that simply provides ones

OnesArrayConfig

This array read data from the source array and then return a np.ones_like() version.

ConcatArray

This is a wrapper around other source_arrays that concatenates

ConcatArrayConfig

This array read data from the source array and then return a np.ones_like() version of the data.

LogicalOrArray

Array that computes the logical OR of the instances in a list of source arrays.

LogicalOrArrayConfig

This config class takes a source array and performs a logical or over the channels.

CropArray

Used to crop a larger array to a smaller array. This is useful when you

CropArrayConfig

This config class provides the necessary configuration for cropping an

MergeInstancesArray

This array merges multiple source arrays into a single array by summing them. This is useful for merging

MergeInstancesArrayConfig

Configuration for an array that merges instances from multiple arrays

DVIDArray

This is a DVID array. It is a wrapper around a DVID array that provides

DVIDArrayConfig

This config class provides the necessary configuration for a DVID array. It takes a source string and returns the DVIDArray object.

SumArray

This class provides a sum array. This array is a virtual array that is created by summing

SumArrayConfig

This config class provides the necessary configuration for a sum

NumpyArray

This is just a wrapper for a numpy array to make it fit the DaCapo Array interface.

ConstantArray

This is a wrapper around another source_array that simply provides constant value

ConstantArrayConfig

This array read data from the source array and then return a np.ones_like() version.

Package Contents

class dacapo.experiments.datasplits.datasets.arrays.Array

An Array is a multi-dimensional array of data that can be read from and written to. It is defined by a region of interest (ROI) in world units, a voxel size, and a number of spatial dimensions. The data is stored in a numpy array, and can be accessed using numpy-like slicing syntax.

The Array class is an abstract base class that defines the interface for all Array implementations. It provides a number of properties that must be implemented by subclasses, such as the ROI, voxel size, and data type of the array. It also provides a method for fetching data from the array, which is implemented by slicing the numpy array.

The Array class also provides a method for checking if the array can be visualized in Neuroglancer, and a method for generating a Neuroglancer layer for the array. These methods are implemented by subclasses that support visualization in Neuroglancer.

attrs

A dictionary of metadata attributes stored on this array.

Type:

Dict[str, Any]

axes

The axes of this dataset as a string of characters, as they are indexed. Permitted characters are:

  • zyx for spatial dimensions

  • c for channels

  • s for samples

Type:

List[str]

dims

The number of spatial dimensions.

Type:

int

voxel_size

The size of a voxel in physical units.

Type:

Coordinate

roi

The total ROI of this array, in world units.

Type:

Roi

dtype

The dtype of this array, in numpy dtypes

Type:

Any

num_channels

The number of channels provided by this dataset. Should return None if the channel dimension doesn’t exist.

Type:

Optional[int]

data

A numpy-like readable and writable view into this array.

Type:

np.ndarray

writable

Can we write to this Array?

Type:

bool

__getitem__(self, roi

Roi) -> np.ndarray: Get a numpy like readable and writable view into this array.

_can_neuroglance(self) bool

Check if this array can be visualized in Neuroglancer.

_neuroglancer_layer(self)

Generate a Neuroglancer layer for this array.

_slices(self, roi

Roi) -> Iterable[slice]: Generate a list of slices for the given ROI.

Note

This class is used to define the interface for all Array implementations. It provides a number of properties that must be implemented by subclasses, such as the ROI, voxel size, and data type of the array. It also provides a method for fetching data from the array, which is implemented by slicing the numpy array. The Array class also provides a method for checking if the array can be visualized in Neuroglancer, and a method for generating a Neuroglancer layer for the array. These methods are implemented by subclasses that support visualization in Neuroglancer.

property attrs: Dict[str, Any]
Abstractmethod:

Return a dictionary of metadata attributes stored on this array.

Returns:

A dictionary of metadata attributes stored on this array.

Return type:

Dict[str, Any]

Raises:

NotImplementedError – This method must be implemented by the subclass.

Examples

>>> array = Array()
>>> array.attrs
{}

Note

This method must be implemented by the subclass.

property axes: List[str]
Abstractmethod:

Returns the axes of this dataset as a string of charactes, as they are indexed. Permitted characters are:

  • zyx for spatial dimensions

  • c for channels

  • s for samples

Returns:

The axes of this dataset as a string of characters, as they are indexed.

Return type:

List[str]

Raises:

NotImplementedError – This method must be implemented by the subclass.

Examples

>>> array = Array()
>>> array.axes
['z', 'y', 'x']

Note

This method must be implemented by the subclass.

property dims: int
Abstractmethod:

Returns the number of spatial dimensions.

Returns:

The number of spatial dimensions.

Return type:

int

Raises:

NotImplementedError – This method must be implemented by the subclass.

Examples

>>> array = Array()
>>> array.dims
3

Note

This method must be implemented by the subclass.

property voxel_size: funlib.geometry.Coordinate
Abstractmethod:

The size of a voxel in physical units.

Returns:

The size of a voxel in physical units.

Return type:

Coordinate

Raises:

NotImplementedError – This method must be implemented by the subclass.

Examples

>>> array = Array()
>>> array.voxel_size
Coordinate((1, 1, 1))

Note

This method must be implemented by the subclass.

property roi: funlib.geometry.Roi
Abstractmethod:

The total ROI of this array, in world units.

Returns:

The total ROI of this array, in world units.

Return type:

Roi

Raises:

NotImplementedError – This method must be implemented by the subclass.

Examples

>>> array = Array()
>>> array.roi
Roi(offset=Coordinate((0, 0, 0)), shape=Coordinate((100, 100, 100)))

Note

This method must be implemented by the subclass.

property dtype: Any
Abstractmethod:

The dtype of this array, in numpy dtypes

Returns:

The dtype of this array, in numpy dtypes.

Return type:

Any

Raises:

NotImplementedError – This method must be implemented by the subclass.

Examples

>>> array = Array()
>>> array.dtype
np.dtype('uint8')

Note

This method must be implemented by the subclass.

property num_channels: int | None
Abstractmethod:

The number of channels provided by this dataset. Should return None if the channel dimension doesn’t exist.

Returns:

The number of channels provided by this dataset.

Return type:

Optional[int]

Raises:

NotImplementedError – This method must be implemented by the subclass.

Examples

>>> array = Array()
>>> array.num_channels
1

Note

This method must be implemented by the subclass.

property data: numpy.ndarray
Abstractmethod:

Get a numpy like readable and writable view into this array.

Returns:

A numpy like readable and writable view into this array.

Return type:

np.ndarray

Raises:

NotImplementedError – This method must be implemented by the subclass.

Examples

>>> array = Array()
>>> array.data
np.ndarray

Note

This method must be implemented by the subclass.

property writable: bool
Abstractmethod:

Can we write to this Array?

Returns:

Can we write to this Array?

Return type:

bool

Raises:

NotImplementedError – This method must be implemented by the subclass.

Examples

>>> array = Array()
>>> array.writable
False

Note

This method must be implemented by the subclass.

class dacapo.experiments.datasplits.datasets.arrays.ArrayConfig

Base class for array configurations. Each subclass of an Array should have a corresponding config class derived from ArrayConfig. This class should be used to store the configuration of the array.

name

A unique name for this array. This will be saved so you and others can find and reuse this array. Keep it short and avoid special characters.

Type:

str

verify(self) Tuple[bool, str]

This method is used to check whether this is a valid Array.

Note

This class is used to create a base class for array configurations. Each subclass of an Array should have a corresponding config class derived from ArrayConfig. This class should be used to store the configuration of the array.

name: str
verify() Tuple[bool, str]

Check whether this is a valid Array

Returns:

A tuple with the first element being a boolean indicating whether the array is valid and the second element being a string with a message explaining why the array is invalid

Return type:

Tuple[bool, str]

Raises:

NotImplementedError – This method is not implemented in this class

Examples

>>> array_config = ArrayConfig(name="array_config")
>>> array_config.verify()
(True, "No validation for this Array")

Note

This method is used to check whether this is a valid Array.

class dacapo.experiments.datasplits.datasets.arrays.DummyArray(array_config)

This is just a dummy array for testing. It has a shape of (100, 50, 50) and is filled with zeros.

array_config

The config object for the array

Type:

ArrayConfig

__getitem__()

Returns the intensities normalized to the range (0, 1)

Notes

The array_config must be an ArrayConfig object. The min and max values are used to normalize the intensities. All intensities are converted to float32.

property attrs
Returns the attributes of the source array
Returns:

The attributes of the source array

Return type:

dict

Raises:

ValueError – If the attributes is not a dictionary

Examples

>>> intensities_array.attrs
{'resolution': (1.0, 1.0, 1.0), 'unit': 'micrometer'}
property axes
Returns the axes of the source array
Returns:

The axes of the source array

Return type:

str

Raises:

ValueError – If the axes is not a string

Examples

>>> intensities_array.axes
'zyx'

Notes

The axes are the same as the source array

property dims
Returns the number of dimensions of the source array
Returns:

The number of dimensions of the source array

Return type:

int

Raises:

ValueError – If the dims is not an integer

Examples

>>> intensities_array.dims
3

Notes

The dims are the same as the source array

property voxel_size
Returns the voxel size of the source array
Returns:

The voxel size of the source array

Return type:

Coordinate

Raises:

ValueError – If the voxel size is not a Coordinate object

Examples

>>> intensities_array.voxel_size
Coordinate(x=1.0, y=1.0, z=1.0)

Notes

The voxel size is the same as the source array

property roi
Returns the region of interest of the source array
Returns:

The region of interest of the source array

Return type:

Roi

Raises:

ValueError – If the roi is not a Roi object

Examples

>>> intensities_array.roi
Roi(offset=(0, 0, 0), shape=(100, 100, 100))

Notes

The roi is the same as the source array

property writable: bool

Returns whether the array is writable

Returns:

Whether the array is writable

Return type:

bool

Examples

>>> intensities_array.writable
True

Notes

The array is always writable

property data
Returns the data of the source array
Returns:

The data of the source array

Return type:

np.ndarray

Raises:

ValueError – If the data is not a numpy array

Examples

>>> intensities_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.],
        [0., 0., 0., ..., 0., 0., 0.],
        [0., 0., 0., ..., 0., 0., 0.]],

Notes

The data is the same as the source array

property dtype
Returns the data type of the array
Returns:

The data type of the array

Return type:

type

Raises:

ValueError – If the data type is not a type

Examples

>>> intensities_array.dtype
numpy.float32

Notes

The data type is the same as the source array

property num_channels
Returns the number of channels in the source array
Returns:

The number of channels in the source array

Return type:

int

Raises:

ValueError – If the number of channels is not an integer

Examples

>>> intensities_array.num_channels
1

Notes

The number of channels is the same as the source array

class dacapo.experiments.datasplits.datasets.arrays.DummyArrayConfig

This is just a dummy array config used for testing. None of the attributes have any particular meaning. It is used to test the ArrayConfig class.

to_array()

Returns the DummyArray object

verify()

Returns whether the DummyArrayConfig is valid

Notes

The source_array_config must be an ArrayConfig object.

array_type
verify() Tuple[bool, str]

Check whether this is a valid Array

Returns:

Whether the Array is valid and a message

Return type:

Tuple[bool, str]

Raises:

ValueError – If the source is not a tuple of strings

Examples

>>> dummy_array_config = DummyArrayConfig(...)
>>> dummy_array_config.verify()
(False, "This is a DummyArrayConfig and is never valid")

Notes

The source must be a tuple of strings.

class dacapo.experiments.datasplits.datasets.arrays.ZarrArray(array_config)

This is a zarr array.

name

The name of the array.

Type:

str

file_name

The file name of the array.

Type:

Path

dataset

The dataset name.

Type:

str

_axes

The axes of the array.

Type:

Optional[List[str]]

snap_to_grid

The snap to grid.

Type:

Optional[Coordinate]

__init__(array_config)

Initializes the array type ‘raw’ and name for the DummyDataset instance.

__str__()

Returns the string representation of the ZarrArray.

__repr__()

Returns the string representation of the ZarrArray.

attrs()

Returns the attributes of the array.

axes()

Returns the axes of the array.

dims()

Returns the dimensions of the array.

_daisy_array()

Returns the daisy array.

voxel_size()

Returns the voxel size of the array.

roi()

Returns the region of interest of the array.

writable()

Returns the boolean value of the array.

dtype()

Returns the data type of the array.

num_channels()

Returns the number of channels of the array.

spatial_axes()

Returns the spatial axes of the array.

data()

Returns the data of the array.

__getitem__(roi)

Returns the data of the array for the given region of interest.

__setitem__(roi, value)

Sets the data of the array for the given region of interest.

create_from_array_identifier(array_identifier, axes, roi, num_channels, voxel_size, dtype, write_size=None, name=None, overwrite=False)

Creates a new ZarrArray given an array identifier.

open_from_array_identifier(array_identifier, name='')

Opens a new ZarrArray given an array identifier.

_can_neuroglance()

Returns the boolean value of the array.

_neuroglancer_source()

Returns the neuroglancer source of the array.

_neuroglancer_layer()

Returns the neuroglancer layer of the array.

_transform_matrix()

Returns the transform matrix of the array.

_output_dimensions()

Returns the output dimensions of the array.

_source_name()

Returns the source name of the array.

add_metadata(metadata)

Adds metadata to the array.

Notes

This class is used to create a zarr array.

name
file_name
dataset
snap_to_grid
property mode
property attrs
Returns the attributes of the array.
Parameters:

attrs (Any) – The attributes of the array.

Returns:

The attributes of the array.

Return type:

Any

Raises:

NotImplementedError

Examples

>>> attrs()

Notes

This method is used to return the attributes of the array.

property axes
Returns the axes of the array.
Parameters:

axes (List[str]) – The axes of the array.

Returns:

The axes of the array.

Return type:

List[str]

Raises:

NotImplementedError

Examples

>>> axes()

Notes

This method is used to return the axes of the array.

property dims: int

Returns the dimensions of the array.

Parameters:

dims (int) – The dimensions of the array.

Returns:

The dimensions of the array.

Return type:

int

Raises:

NotImplementedError

Examples

>>> dims()

Notes

This method is used to return the dimensions of the array.

voxel_size() funlib.geometry.Coordinate

Returns the voxel size of the array.

Parameters:

voxel_size (Coordinate) – The voxel size.

Returns:

The voxel size of the array.

Return type:

Coordinate

Raises:

NotImplementedError

Examples

>>> voxel_size()

Notes

This method is used to return the voxel size of the array.

roi() funlib.geometry.Roi

Returns the region of interest of the array.

Parameters:

roi (Roi) – The region of interest.

Returns:

The region of interest of the array.

Return type:

Roi

Raises:

NotImplementedError

Examples

>>> roi()

Notes

This method is used to return the region of interest of the array.

property writable: bool

Returns the boolean value of the array.

Parameters:

writable (bool) – The boolean value of the array.

Returns:

The boolean value of the array.

Return type:

bool

Raises:

NotImplementedError

Examples

>>> writable()

Notes

This method is used to return the boolean value of the array.

property dtype: Any

Returns the data type of the array.

Parameters:

dtype (Any) – The data type of the array.

Returns:

The data type of the array.

Return type:

Any

Raises:

NotImplementedError

Examples

>>> dtype()

Notes

This method is used to return the data type of the array.

property num_channels: int | None

Returns the number of channels of the array.

Parameters:

num_channels (Optional[int]) – The number of channels of the array.

Returns:

The number of channels of the array.

Return type:

Optional[int]

Raises:

NotImplementedError

Examples

>>> num_channels()

Notes

This method is used to return the number of channels of the array.

property spatial_axes: List[str]

Returns the spatial axes of the array.

Parameters:

spatial_axes (List[str]) – The spatial axes of the array.

Returns:

The spatial axes of the array.

Return type:

List[str]

Raises:

NotImplementedError

Examples

>>> spatial_axes()

Notes

This method is used to return the spatial axes of the array.

property data: Any

Returns the data of the array.

Parameters:

data (Any) – The data of the array.

Returns:

The data of the array.

Return type:

Any

Raises:

NotImplementedError

Examples

>>> data()

Notes

This method is used to return the data of the array.

classmethod create_from_array_identifier(array_identifier, axes, roi, num_channels, voxel_size, dtype, mode='a', write_size=None, name=None, overwrite=False)

Create a new ZarrArray given an array identifier. It is assumed that this array_identifier points to a dataset that does not yet exist.

Parameters:
  • array_identifier (ArrayIdentifier) – The array identifier.

  • axes (List[str]) – The axes of the array.

  • roi (Roi) – The region of interest.

  • num_channels (int) – The number of channels.

  • voxel_size (Coordinate) – The voxel size.

  • dtype (Any) – The data type.

  • write_size (Optional[Coordinate]) – The write size.

  • name (Optional[str]) – The name of the array.

  • overwrite (bool) – The boolean value to overwrite the array.

Returns:

The ZarrArray.

Return type:

ZarrArray

Raises:

NotImplementedError

Examples

>>> create_from_array_identifier(array_identifier, axes, roi, num_channels, voxel_size, dtype, write_size=None, name=None, overwrite=False)

Notes

This method is used to create a new ZarrArray given an array identifier.

classmethod open_from_array_identifier(array_identifier, name='')

Opens a new ZarrArray given an array identifier.

Parameters:
  • array_identifier (ArrayIdentifier) – The array identifier.

  • name (str) – The name of the array.

Returns:

The ZarrArray.

Return type:

ZarrArray

Raises:

NotImplementedError

Examples

>>> open_from_array_identifier(array_identifier, name="")

Notes

This method is used to open a new ZarrArray given an array identifier.

add_metadata(metadata: Dict[str, Any]) None

Adds metadata to the array.

Parameters:

metadata (Dict[str, Any]) – The metadata to add to the array.

Raises:

NotImplementedError

Examples

>>> add_metadata(metadata)

Notes

This method is used to add metadata to the array.

class dacapo.experiments.datasplits.datasets.arrays.ZarrArrayConfig

This config class provides the necessary configuration for a zarr array.

A zarr array is a container for large, multi-dimensional arrays. It is similar to HDF5, but is designed to work with large arrays that do not fit into memory. Zarr arrays can be stored on disk or in the cloud and can be accessed concurrently by multiple processes. Zarr arrays can be compressed and support chunked, N-dimensional arrays.

file_name

Path The file name of the zarr container.

dataset

str The name of your dataset. May include ‘/’ characters for nested heirarchies

snap_to_grid

Optional[Coordinate] If you need to make sure your ROI’s align with a specific voxel_size

_axes

Optional[List[str]] The axes of your data!

verify() Tuple[bool, str]

Check whether this is a valid Array

Note

This class is a subclass of ArrayConfig.

array_type
file_name: upath.UPath
dataset: str
snap_to_grid: funlib.geometry.Coordinate | None
mode: str | None
verify() Tuple[bool, str]

Check whether this is a valid Array

Returns:

A tuple of a boolean and a string. The boolean indicates whether the Array is valid or not. The string provides a reason why the Array is not valid.

Return type:

Tuple[bool, str]

Raises:

NotImplementedError – This method is not implemented for this Array

Examples

>>> zarr_array_config = ZarrArrayConfig(
...     file_name=Path("data.zarr"),
...     dataset="data",
...     snap_to_grid=Coordinate(1, 1, 1),
...     _axes=["x", "y", "z"]
... )
>>> zarr_array_config.verify()
(True, 'No validation for this Array')

Note

This method is not implemented for this Array

class dacapo.experiments.datasplits.datasets.arrays.BinarizeArray(array_config)

This is wrapper around a ZarrArray containing uint annotations. Because we often want to predict classes that are a combination of a set of labels we wrap a ZarrArray with the BinarizeArray and provide something like groupings=[(“mito”, [3,4,5])] where 4 corresponds to mito_mem (mitochondria membrane), 5 is mito_ribo (mitochondria ribosomes), and 3 is everything else that is part of a mitochondria. The BinarizeArray will simply combine labels 3,4,5 into a single binary channel for the class of “mito”.

We use a single channel per class because some classes may overlap. For example if you had groupings=[(“mito”, [3,4,5]), (“membrane”, [4, 8, 1])] where 4 is mito_mem, 8 is er_mem (ER membrane), and 1 is pm (plasma membrane). Now you can have a binary classification for membrane or not which in some cases overlaps with the channel for mitochondria which includes the mito membrane.

name

The name of the array.

Type:

str

source_array

The source array to binarize.

Type:

Array

background

The label to treat as background.

Type:

int

groupings

A list of tuples where the first element is the name of the class and the second element is a list of labels that should be combined into a single binary channel.

Type:

List[Tuple[str, List[int]]]

__init__(self, array_config)

This method initializes the BinarizeArray object.

__attrs_post_init__(self)

This method is called after the instance has been initialized by the constructor. It is used to set the default_config to an instance of ArrayConfig if it is None.

__getitem__(self, roi

Roi) -> np.ndarray: This method returns the binary channels for the given region of interest.

_can_neuroglance(self)

This method returns True if the source array can be visualized in neuroglance.

_neuroglancer_source(self)

This method returns the source array for neuroglancer.

_neuroglancer_layer(self)

This method returns the neuroglancer layer for the source array.

_source_name(self)

This method returns the name of the source array.

Note

This class is used to create a BinarizeArray object which is a wrapper around a ZarrArray containing uint annotations.

name
background
property attrs
This method returns the attributes of the source array.
Returns:

The attributes of the source array.

Return type:

Dict

Raises:

ValueError – If the source array is not writable.

Examples

>>> binarize_array.attrs

Note

This method is used to return the attributes of the source array.

property axes
This method returns the axes of the source array.
Returns:

The axes of the source array.

Return type:

List[str]

Raises:

ValueError – If the source array is not writable.

Examples

>>> binarize_array.axes

Note

This method is used to return the axes of the source array.

property dims: int

This method returns the dimensions of the source array.

Returns:

The dimensions of the source array.

Return type:

int

Raises:

ValueError – If the source array is not writable.

Examples

>>> binarize_array.dims

Note

This method is used to return the dimensions of the source array.

property voxel_size: funlib.geometry.Coordinate

This method returns the voxel size of the source array.

Returns:

The voxel size of the source array.

Return type:

Coordinate

Raises:

ValueError – If the source array is not writable.

Examples

>>> binarize_array.voxel_size

Note

This method is used to return the voxel size of the source array.

property roi: funlib.geometry.Roi

This method returns the region of interest of the source array.

Returns:

The region of interest of the source array.

Return type:

Roi

Raises:

ValueError – If the source array is not writable.

Examples

>>> binarize_array.roi

Note

This method is used to return the region of interest of the source array.

property writable: bool

This method returns True if the source array is writable.

Returns:

True if the source array is writable.

Return type:

bool

Raises:

ValueError – If the source array is not writable.

Examples

>>> binarize_array.writable

Note

This method is used to return True if the source array is writable.

property dtype
This method returns the data type of the source array.
Returns:

The data type of the source array.

Return type:

np.dtype

Raises:

ValueError – If the source array is not writable.

Examples

>>> binarize_array.dtype

Note

This method is used to return the data type of the source array.

property num_channels: int

This method returns the number of channels in the source array.

Returns:

The number of channels in the source array.

Return type:

int

Raises:

ValueError – If the source array is not writable.

Examples

>>> binarize_array.num_channels

Note

This method is used to return the number of channels in the source array.

property data
This method returns the data of the source array.
Returns:

The data of the source array.

Return type:

np.ndarray

Raises:

ValueError – If the source array is not writable.

Examples

>>> binarize_array.data

Note

This method is used to return the data of the source array.

property channels
This method returns the channel names of the source array.
Returns:

The channel names of the source array.

Return type:

Iterator[str]

Raises:

ValueError – If the source array is not writable.

Examples

>>> binarize_array.channels

Note

This method is used to return the channel names of the source array.

class dacapo.experiments.datasplits.datasets.arrays.BinarizeArrayConfig

This config class provides the necessary configuration for turning an Annotated dataset into a multi class binary classification problem. Each class will be binarized into a separate channel.

source_array_config

The Array from which to pull annotated data. Is expected to contain a volume with uint64 voxels and no channel dimension

Type:

ArrayConfig

groupings

List of id groups with a symantic name. Each id group is a List of ids. Group i found in groupings[i] will be binarized and placed in channel i. An empty group will binarize all non background labels.

Type:

List[Tuple[str, List[int]]]

background

The id considered background. Will never be binarized to 1, defaults to 0.

Type:

int

Note

This class is used to create a BinarizeArray object which is used to turn an Annotated dataset into a multi class binary classification problem. Each class will be binarized into a separate channel.

array_type
source_array_config: dacapo.experiments.datasplits.datasets.arrays.array_config.ArrayConfig
groupings: List[Tuple[str, List[int]]]
background: int
class dacapo.experiments.datasplits.datasets.arrays.ResampledArray(array_config)

This is a zarr array that is a resampled version of another array.

Resampling is done by rescaling the source array with the given upsample and downsample factors. The voxel size of the resampled array is the voxel size of the source array divided by the downsample factor and multiplied by the upsample factor.

name

str The name of the array

source_array

Array The source array

upsample

Coordinate The upsample factor for each dimension

downsample

Coordinate The downsample factor for each dimension

interp_order

int The order of the interpolation used for resampling

attrs()

Dict Returns the attributes of the source array

axes()

str Returns the axes of the source array

dims()

int Returns the number of dimensions of the source array

voxel_size()

Coordinate Returns the voxel size of the resampled array

roi()

Roi Returns the region of interest of the resampled array

writable()

bool Returns whether the resampled array is writable

dtype()

np.dtype Returns the data type of the resampled array

num_channels()

int Returns the number of channels of the resampled array

data()

np.ndarray Returns the data of the resampled array

scale()

Tuple[float] Returns the scale of the resampled array

__getitem__(roi

Roi) -> np.ndarray Returns the data of the resampled array within the given region of interest

_can_neuroglance() bool

Returns whether the source array can be visualized with neuroglance

_neuroglancer_layer() Dict

Returns the neuroglancer layer of the source array

_neuroglancer_source() Dict

Returns the neuroglancer source of the source array

_source_name() str

Returns the name of the source array

Note

This class is a subclass of Array.

name
upsample
downsample
interp_order
property attrs
Returns the attributes of the source array.
Returns:

The attributes of the source array

Return type:

Dict

Raises:

ValueError – If the resampled array is not writable

Examples

>>> resampled_array.attrs

Note

This method returns the attributes of the source array.

property axes
Returns the axes of the source array.
Returns:

The axes of the source array

Return type:

str

Raises:

ValueError – If the resampled array is not writable

Examples

>>> resampled_array.axes

Note

This method returns the axes of the source array.

property dims: int

Returns the number of dimensions of the source array.

Returns:

The number of dimensions of the source array

Return type:

int

Raises:

ValueError – If the resampled array is not writable

Examples

>>> resampled_array.dims

Note

This method returns the number of dimensions of the source array.

property voxel_size: funlib.geometry.Coordinate

Returns the voxel size of the resampled array.

Returns:

The voxel size of the resampled array

Return type:

Coordinate

Raises:

ValueError – If the resampled array is not writable

Examples

>>> resampled_array.voxel_size

Note

This method returns the voxel size of the resampled array.

property roi: funlib.geometry.Roi

Returns the region of interest of the resampled array.

Returns:

The region of interest of the resampled array

Return type:

Roi

Raises:

ValueError – If the resampled array is not writable

Examples

>>> resampled_array.roi

Note

This method returns the region of interest of the resampled array.

property writable: bool

Returns whether the resampled array is writable.

Returns:

True if the resampled array is writable, False otherwise

Return type:

bool

Raises:

ValueError – If the resampled array is not writable

Examples

>>> resampled_array.writable

Note

This method returns whether the resampled array is writable.

property dtype
Returns the data type of the resampled array.
Returns:

The data type of the resampled array

Return type:

np.dtype

Raises:

ValueError – If the resampled array is not writable

Examples

>>> resampled_array.dtype

Note

This method returns the data type of the resampled array.

property num_channels: int

Returns the number of channels of the resampled array.

Returns:

The number of channels of the resampled array

Return type:

int

Raises:

ValueError – If the resampled array is not writable

Examples

>>> resampled_array.num_channels

Note

This method returns the number of channels of the resampled array.

property data
Returns the data of the resampled array.
Returns:

The data of the resampled array

Return type:

np.ndarray

Raises:

ValueError – If the resampled array is not writable

Examples

>>> resampled_array.data

Note

This method returns the data of the resampled array.

property scale
Returns the scale of the resampled array.
Returns:

The scale of the resampled array

Return type:

Tuple[float]

Raises:

ValueError – If the resampled array is not writable

Examples

>>> resampled_array.scale

Note

This method returns the scale of the resampled array.

class dacapo.experiments.datasplits.datasets.arrays.ResampledArrayConfig

A configuration for a ResampledArray. This array will up or down sample an array into the desired voxel size.

source_array_config

The Array that you want to upsample or downsample.

Type:

ArrayConfig

upsample

The amount by which to upsample!

Type:

Coordinate

downsample

The amount by which to downsample!

Type:

Coordinate

interp_order

The order of the interpolation!

Type:

bool

create_array()

Creates a ResampledArray from the configuration.

Note

This class is meant to be used with the ArrayDataset class.

array_type
source_array_config: dacapo.experiments.datasplits.datasets.arrays.array_config.ArrayConfig
upsample: funlib.geometry.Coordinate
downsample: funlib.geometry.Coordinate
interp_order: bool
class dacapo.experiments.datasplits.datasets.arrays.IntensitiesArray(array_config)

This is wrapper another array that will normalize intensities to the range (0, 1) and convert to float32. Use this if you have your intensities stored as uint8 or similar and want your model to have floats as input.

array_config

The config object for the array

Type:

ArrayConfig

min

The minimum intensity value in the array

Type:

float

max

The maximum intensity value in the array

Type:

float

__getitem__()

Returns the intensities normalized to the range (0, 1)

Notes

The array_config must be an ArrayConfig object. The min and max values are used to normalize the intensities. All intensities are converted to float32.

name
property attrs
Returns the attributes of the source array
Returns:

The attributes of the source array

Return type:

dict

Raises:

ValueError – If the attributes is not a dictionary

Examples

>>> intensities_array.attrs
{'resolution': (1.0, 1.0, 1.0), 'unit': 'micrometer'}

Notes

The attributes are the same as the source array

property axes
Returns the axes of the source array
Returns:

The axes of the source array

Return type:

str

Raises:

ValueError – If the axes is not a string

Examples

>>> intensities_array.axes
'zyx'

Notes

The axes are the same as the source array

property dims: int

Returns the dimensions of the source array

Returns:

The dimensions of the source array

Return type:

int

Raises:

ValueError – If the dimensions is not an integer

Examples

>>> intensities_array.dims
3

Notes

The dimensions are the same as the source array

property voxel_size: funlib.geometry.Coordinate

Returns the voxel size of the source array

Returns:

The voxel size of the source array

Return type:

Coordinate

Raises:

ValueError – If the voxel size is not a Coordinate object

Examples

>>> intensities_array.voxel_size
Coordinate(x=1.0, y=1.0, z=1.0)

Notes

The voxel size is the same as the source array

property roi: funlib.geometry.Roi

Returns the region of interest of the source array

Returns:

The region of interest of the source array

Return type:

Roi

Raises:

ValueError – If the region of interest is not a Roi object

Examples

>>> intensities_array.roi
Roi(offset=(0, 0, 0), shape=(10, 20, 30))

Notes

The region of interest is the same as the source 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

>>> intensities_array.writable
False

Notes

The array is not writable because it is a virtual array created by modifying another array on demand.

property dtype
Returns the data type of the array
Returns:

The data type of the array

Return type:

type

Raises:

ValueError – If the data type is not a type

Examples

>>> intensities_array.dtype
numpy.float32

Notes

The data type is always float32

property num_channels: int

Returns the number of channels in the source array

Returns:

The number of channels in the source array

Return type:

int

Raises:

ValueError – If the number of channels is not an integer

Examples

>>> intensities_array.num_channels
3

Notes

The number of channels is the same as the source array

property data
Returns the data of the source array
Returns:

The data of the source array

Return type:

np.ndarray

Raises:

ValueError – If the data is not a numpy array

Examples

>>> intensities_array.data
array([[[0.1, 0.2, 0.3], [0.4, 0.5, 0.6]], [[0.7, 0.8, 0.9], [1.0, 1.1, 1.2]]])

Notes

The data is the same as the source array

class dacapo.experiments.datasplits.datasets.arrays.IntensitiesArrayConfig

This config class provides the necessary configuration for turning an Annotated dataset into a multi class binary classification problem. It takes a source array and normalizes the intensities between 0 and 1. The source array is expected to contain a volume with uint64 voxels and no channel dimension.

source_array_config

The Array from which to pull annotated data

Type:

ArrayConfig

min

The minimum intensity in your data

Type:

float

max

The maximum intensity in your data

Type:

float

to_array()

Returns the IntensitiesArray object

Notes

The source_array_config must be an ArrayConfig object.

array_type
source_array_config: dacapo.experiments.datasplits.datasets.arrays.array_config.ArrayConfig
min: float
max: float
class dacapo.experiments.datasplits.datasets.arrays.MissingAnnotationsMask(array_config)

This is wrapper around a ZarrArray containing uint annotations. Complementary to the BinarizeArray class where we convert labels into individual channels for training, we may find crops where a specific label is present, but not annotated. In that case you might want to avoid training specific channels for specific training volumes. See package fibsem_tools for appropriate metadata format for indicating presence of labels in your ground truth. “https://github.com/janelia-cosem/fibsem-tools

array_config

A BinarizeArrayConfig object

__getitem__(roi

Roi) -> np.ndarray: Returns a binary mask of the annotations that are present but not annotated.

Note

This class is not meant to be used directly. It is used by the BinarizeArray class to mask out annotations that are present but not annotated.

name
property axes
Returns the axes of the source array
Returns:

Axes of the source array

Return type:

list

Raises:

ValueError – If the source array does not have a name

Examples

>>> source_array = ZarrArray(ZarrArrayConfig(...))
>>> source_array.axes
['x', 'y', 'z']

Notes

This is a helper function for the BinarizeArray class

property dims: int

Returns the number of dimensions of the source array

Returns:

Number of dimensions of the source array

Return type:

int

Raises:

ValueError – If the source array does not have a name

Examples

>>> source_array = ZarrArray(ZarrArrayConfig(...))
>>> source_array.dims
3

Notes

This is a helper function for the BinarizeArray class

property voxel_size: funlib.geometry.Coordinate

Returns the voxel size of the source array

Returns:

Voxel size of the source array

Return type:

Coordinate

Raises:

ValueError – If the source array does not have a name

Examples

>>> source_array = ZarrArray(ZarrArrayConfig(...))
>>> source_array.voxel_size
Coordinate(x=4, y=4, z=40)

Notes

This is a helper function for the BinarizeArray class

property roi: funlib.geometry.Roi

Returns the region of interest of the source array

Returns:

Region of interest of the source array

Return type:

Roi

Raises:

ValueError – If the source array does not have a name

Examples

>>> source_array = ZarrArray(ZarrArrayConfig(...))
>>> source_array.roi
Roi(offset=(0, 0, 0), shape=(100, 100, 100))

Notes

This is a helper function for the BinarizeArray class

property writable: bool

Returns whether the source array is writable

Returns:

Whether the source array is writable

Return type:

bool

Raises:

ValueError – If the source array does not have a name

Examples

>>> source_array = ZarrArray(ZarrArrayConfig(...))
>>> source_array.writable
False

Notes

This is a helper function for the BinarizeArray class

property dtype
Returns the data type of the source array
Returns:

Data type of the source array

Return type:

np.dtype

Raises:

ValueError – If the source array does not have a name

Examples

>>> source_array = ZarrArray(ZarrArrayConfig(...))
>>> source_array.dtype
np.uint8

Notes

This is a helper function for the BinarizeArray class

property num_channels: int

Returns the number of channels

Returns:

Number of channels

Return type:

int

Raises:

ValueError – If the source array does not have a name

Examples

>>> source_array = ZarrArray(ZarrArrayConfig(...))
>>> source_array.num_channels
2

Notes

This is a helper function for the BinarizeArray class

property data
Returns the data of the source array
Returns:

Data of the source array

Return type:

np.ndarray

Raises:

ValueError – If the source array does not have a name

Examples

>>> source_array = ZarrArray(ZarrArrayConfig(...))
>>> source_array.data
np.ndarray(...)

Notes

This is a helper function for the BinarizeArray class

property attrs
Returns the attributes of the source array
Returns:

Attributes of the source array

Return type:

dict

Raises:

ValueError – If the source array does not have a name

Examples

>>> source_array = ZarrArray(ZarrArrayConfig(...))
>>> source_array.attrs
{'name': 'source_array', 'resolution': [4, 4, 40]}

Notes

This is a helper function for the BinarizeArray class

property channels
Returns the names of the channels
Returns:

Names of the channels

Return type:

Generator[str]

Raises:

ValueError – If the source array does not have a name

Examples

>>> source_array = ZarrArray(ZarrArrayConfig(...))
>>> source_array.channels
Generator['channel1', 'channel2', ...]

Notes

This is a helper function for the BinarizeArray class

class dacapo.experiments.datasplits.datasets.arrays.MissingAnnotationsMaskConfig

This config class provides the necessary configuration for turning an Annotated dataset into a multi class binary classification problem

source_array_config

ArrayConfig The Array from which to pull annotated data. Is expected to contain a volume with uint64 voxels and no channel dimension

groupings

List[Tuple[str, List[int]]] List of id groups with a symantic name. Each id group is a List of ids. Group i found in groupings[i] will be binarized and placed in channel i.

Note

The output array will have a channel dimension equal to the number of groups. Each channel will be a binary mask of the ids in the groupings list.

array_type
source_array_config: dacapo.experiments.datasplits.datasets.arrays.array_config.ArrayConfig
groupings: List[Tuple[str, List[int]]]
class dacapo.experiments.datasplits.datasets.arrays.OnesArray(array_config)

This is a wrapper around another source_array that simply provides ones with the same metadata as the source_array.

This is useful for creating a mask array that is the same size as the original array, but with all values set to 1.

source_array

The source array that this array is based on.

like()

Create a new OnesArray with the same metadata as another array.

attrs()

Get the attributes of the array.

axes()

Get the axes of the array.

dims()

Get the dimensions of the array.

voxel_size()

Get the voxel size of the array.

roi()

Get the region of interest of the array.

writable()

Check if the array is writable.

data()

Get the data of the array.

dtype()

Get the data type of the array.

num_channels()

Get the number of channels of the array.

__getitem__()

Get a subarray of the array.

Note

This class is not meant to be instantiated directly. Instead, use the like method to create a new OnesArray with the same metadata as another array.

classmethod like(array: dacapo.experiments.datasplits.datasets.arrays.array.Array)

Create a new OnesArray with the same metadata as another array.

Parameters:

array – The source array.

Returns:

The new OnesArray with the same metadata as the source array.

Raises:

RuntimeError – If the source array is not specified.

Examples

>>> from dacapo.experiments.datasplits.datasets.arrays import OnesArray
>>> from dacapo.experiments.datasplits.datasets.arrays import NumpyArray
>>> import numpy as np
>>> source_array = NumpyArray(np.zeros((10, 10, 10)))
>>> ones_array = OnesArray.like(source_array)
>>> ones_array.source_array
NumpyArray(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., 0., 0., 0., 0., 0., 0.],
                        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
                        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
                        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
                        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
                        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
                        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
                        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]]]), voxel_size=(1.0, 1.0, 1.0), roi=Roi((0, 0, 0), (10, 10, 10)), num_channels=1)

Notes

This class is not meant to be instantiated directly. Instead, use the like method to create a new OnesArray with the same metadata as another array.

property attrs
Get the attributes of the array.
Returns:

An empty dictionary.

Examples

>>> from dacapo.experiments.datasplits.datasets.arrays import OnesArray
>>> from dacapo.experiments.datasplits.datasets.arrays import NumpyArray
>>> import numpy as np
>>> source_array = NumpyArray(np.zeros((10, 10, 10)))
>>> ones_array = OnesArray(source_array)
>>> ones_array.attrs
{}

Notes

This method is used to get the attributes of the array. The attributes are stored as key-value pairs in a dictionary. This method returns an empty dictionary because the OnesArray does not have any attributes.

property source_array: dacapo.experiments.datasplits.datasets.arrays.array.Array

Get the source array that this array is based on.

Returns:

The source array.

Raises:

RuntimeError – If the source array is not specified.

Examples

>>> from dacapo.experiments.datasplits.datasets.arrays import OnesArray
>>> from dacapo.experiments.datasplits.datasets.arrays import NumpyArray
>>> import numpy as np
>>> source_array = NumpyArray(np.zeros((10, 10, 10)))
>>> ones_array = OnesArray(source_array)
>>> ones_array.source_array
NumpyArray(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., 0., 0., 0., 0., 0., 0.],
                        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
                        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
                        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
                        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
                        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
                        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
                        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]]]), voxel_size=(1.0, 1.0, 1.0), roi=Roi((0, 0, 0), (10, 10, 10)), num_channels=1)

Notes

This method is used to get the source array that this array is based on. The source array is the array that the OnesArray is created from. This method returns the source array that was specified when the OnesArray was created.

property axes
Get the axes of the array.
Returns:

The axes of the array.

Raises:

RuntimeError – If the axes are not specified.

Examples

>>> from dacapo.experiments.datasplits.datasets.arrays import OnesArray
>>> from dacapo.experiments.datasplits.datasets.arrays import NumpyArray
>>> import numpy as np
>>> source_array = NumpyArray(np.zeros((10, 10, 10)))
>>> ones_array = OnesArray(source_array)
>>> ones_array.axes
'zyx'

Notes

This method is used to get the axes of the array. The axes are the order of the dimensions of the array. This method returns the axes of the array that was specified when the OnesArray was created.

property dims
Get the dimensions of the array.
Returns:

The dimensions of the array.

Raises:

RuntimeError – If the dimensions are not specified.

Examples

>>> from dacapo.experiments.datasplits.datasets.arrays import OnesArray
>>> from dacapo.experiments.datasplits.datasets.arrays import NumpyArray
>>> import numpy as np
>>> source_array = NumpyArray(np.zeros((10, 10, 10)))
>>> ones_array = OnesArray(source_array)
>>> ones_array.dims
(10, 10, 10)

Notes

This method is used to get the dimensions of the array. The dimensions are the size of the array along each axis. This method returns the dimensions of the array that was specified when the OnesArray was created.

property voxel_size
Get the voxel size of the array.
Returns:

The voxel size of the array.

Raises:

RuntimeError – If the voxel size is not specified.

Examples

>>> from dacapo.experiments.datasplits.datasets.arrays import OnesArray
>>> from dacapo.experiments.datasplits.datasets.arrays import NumpyArray
>>> import numpy as np
>>> source_array = NumpyArray(np.zeros((10, 10, 10)))
>>> ones_array = OnesArray(source_array)
>>> ones_array.voxel_size
(1.0, 1.0, 1.0)

Notes

This method is used to get the voxel size of the array. The voxel size is the size of each voxel in the array. This method returns the voxel size of the array that was specified when the OnesArray was created.

property roi
Get the region of interest of the array.
Returns:

The region of interest of the array.

Raises:

RuntimeError – If the region of interest is not specified.

Examples

>>> from dacapo.experiments.datasplits.datasets.arrays import OnesArray
>>> from dacapo.experiments.datasplits.datasets.arrays import NumpyArray
>>> from funlib.geometry import Roi
>>> import numpy as np
>>> source_array = NumpyArray(np.zeros((10, 10, 10)))
>>> ones_array = OnesArray(source_array)
>>> ones_array.roi
Roi((0, 0, 0), (10, 10, 10))

Notes

This method is used to get the region of interest of the array. The region of interest is the region of the array that contains the data. This method returns the region of interest of the array that was specified when the OnesArray was created.

property writable: bool

Check if the array is writable.

Returns:

False.

Raises:

RuntimeError – If the writability of the array is not specified.

Examples

>>> from dacapo.experiments.datasplits.datasets.arrays import OnesArray
>>> from dacapo.experiments.datasplits.datasets.arrays import NumpyArray
>>> import numpy as np
>>> source_array = NumpyArray(np.zeros((10, 10, 10)))
>>> ones_array = OnesArray(source_array)
>>> ones_array.writable
False

Notes

This method is used to check if the array is writable. An array is writable if it can be modified in place. This method returns False because the OnesArray is read-only and cannot be modified.

property data
Get the data of the array.
Returns:

The data of the array.

Raises:

RuntimeError – If the data is not specified.

Examples

>>> from dacapo.experiments.datasplits.datasets.arrays import OnesArray
>>> from dacapo.experiments.datasplits.datasets.arrays import NumpyArray
>>> import numpy as np
>>> source_array = NumpyArray(np.zeros((10, 10, 10)))
>>> ones_array = OnesArray(source_array)
>>> ones_array.data
array([[[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]])

Notes

This method is used to get the data of the array. The data is the values that are stored in the array. This method returns a subarray of the array with all values set to 1.

property dtype
Get the data type of the array.
Returns:

The data type of the array.

Raises:

RuntimeError – If the data type is not specified.

Examples

>>> from dacapo.experiments.datasplits.datasets.arrays import OnesArray
>>> from dacapo.experiments.datasplits.datasets.arrays import NumpyArray
>>> import numpy as np
>>> source_array = NumpyArray(np.zeros((10, 10, 10)))
>>> ones_array = OnesArray(source_array)
>>> ones_array.dtype
<class 'numpy.bool_'>

Notes

This method is used to get the data type of the array. The data type is the type of the values that are stored in the array. This method returns the data type of the array that was specified when the OnesArray was created.

property num_channels
Get the number of channels of the array.
Returns:

The number of channels of the array.

Raises:

RuntimeError – If the number of channels is not specified.

Examples

>>> from dacapo.experiments.datasplits.datasets.arrays import OnesArray
>>> from dacapo.experiments.datasplits.datasets.arrays import NumpyArray
>>> import numpy as np
>>> source_array = NumpyArray(np.zeros((10, 10, 10)))
>>> ones_array = OnesArray(source_array)
>>> ones_array.num_channels
1

Notes

This method is used to get the number of channels of the array. The number of channels is the number of values that are stored at each voxel in the array. This method returns the number of channels of the array that was specified when the OnesArray was created.

class dacapo.experiments.datasplits.datasets.arrays.OnesArrayConfig

This array read data from the source array and then return a np.ones_like() version.

This is useful for creating a mask array from a source array. For example, if you have a 2D array of data and you want to create a mask array that is the same shape as the data array, you can use this class to create the mask array.

source_array_config

The source array that you want to copy and fill with ones.

create_array()

Create the array.

Note

This class is a subclass of ArrayConfig.

array_type
source_array_config: dacapo.experiments.datasplits.datasets.arrays.array_config.ArrayConfig
class dacapo.experiments.datasplits.datasets.arrays.ConcatArray(array_config)

This is a wrapper around other source_arrays that concatenates them along the channel dimension. The source_arrays are expected to have the same shape and ROI, but can have different data types.

name

The name of the array.

channels

The list of channel names.

source_arrays

A dictionary mapping channel names to source arrays.

default_array

An optional default array to use for channels that are not present in source_arrays.

from_toml(cls, toml_path

str) -> ConcatArrayConfig: Load the ConcatArrayConfig from a TOML file

to_toml(self, toml_path

str) -> None: Save the ConcatArrayConfig to a TOML file

create_array(self) ConcatArray

Create the ConcatArray from the config

Note

This class is a subclass of Array and inherits all its attributes and methods. The only difference is that the array_type is ConcatArray.

name
channels
property source_arrays: Dict[str, dacapo.experiments.datasplits.datasets.arrays.array.Array]

Return the source arrays of the ConcatArray.

Returns:

The source arrays of the ConcatArray.

Return type:

Dict[str, Array]

Raises:

AssertionError – If the source arrays are empty.

Examples

>>> config = ConcatArrayConfig(
...     name="my_concat_array",
...     channels=["A", "B"],
...     source_array_configs={
...         "A": ArrayConfig(...),
...         "B": ArrayConfig(...),
...     },
...     default_config=ArrayConfig(...),
... )
>>> array = ConcatArray(config)
>>> array.source_arrays
{'A': Array(...), 'B': Array(...)}

Note

The source_arrays are expected to have the same shape and ROI.

default_array
property attrs
Return the attributes of the ConcatArray as a dictionary.
Returns:

The attributes of the ConcatArray.

Return type:

Dict[str, Any]

Raises:

AssertionError – If the source arrays have different attributes.

Examples

>>> config = ConcatArrayConfig(
...     name="my_concat_array",
...     channels=["A", "B"],
...     source_array_configs={
...         "A": ArrayConfig(...),
...         "B": ArrayConfig(...),
...     },
...     default_config=ArrayConfig(...),
... )
>>> array = ConcatArray(config)
>>> array.attrs
{'axes': 'cxyz', 'roi': Roi(...), 'voxel_size': (1, 1, 1)}

Note

The source_arrays are expected to have the same attributes.

property source_array: dacapo.experiments.datasplits.datasets.arrays.array.Array

Return the source array of the ConcatArray.

Returns:

The source array of the ConcatArray.

Return type:

Array

Raises:

AssertionError – If the source array is None.

Examples

>>> config = ConcatArrayConfig(
...     name="my_concat_array",
...     channels=["A", "B"],
...     source_array_configs={
...         "A": ArrayConfig(...),
...         "B": ArrayConfig(...),
...     },
...     default_config=ArrayConfig(...),
... )
>>> array = ConcatArray(config)
>>> array.source_array
Array(...)

Note

The source_array is expected to have the same shape and ROI.

property axes
Return the axes of the ConcatArray.
Returns:

The axes of the ConcatArray.

Return type:

str

Raises:

AssertionError – If the source arrays have different axes.

Examples

>>> config = ConcatArrayConfig(
...     name="my_concat_array",
...     channels=["A", "B"],
...     source_array_configs={
...         "A": ArrayConfig(...),
...         "B": ArrayConfig(...),
...     },
...     default_config=ArrayConfig(...),
... )
>>> array = ConcatArray(config)
>>> array.axes
'cxyz'

Note

The source_arrays are expected to have the same axes.

property dims
Return the dimensions of the ConcatArray.
Returns:

The dimensions of the ConcatArray.

Return type:

Tuple[int]

Raises:

AssertionError – If the source arrays have different dimensions.

Examples

>>> config = ConcatArrayConfig(
...     name="my_concat_array",
...     channels=["A", "B"],
...     source_array_configs={
...         "A": ArrayConfig(...),
...         "B": ArrayConfig(...),
...     },
...     default_config=ArrayConfig(...),
... )
>>> array = ConcatArray(config)
>>> array.dims
(2, 100, 100, 100)

Note

The source_arrays are expected to have the same dimensions.

property voxel_size
Return the voxel size of the ConcatArray.
Returns:

The voxel size of the ConcatArray.

Return type:

Tuple[float]

Raises:

AssertionError – If the source arrays have different voxel sizes.

Examples

>>> config = ConcatArrayConfig(
...     name="my_concat_array",
...     channels=["A", "B"],
...     source_array_configs={
...         "A": ArrayConfig(...),
...         "B": ArrayConfig(...),
...     },
...     default_config=ArrayConfig(...),
... )
>>> array = ConcatArray(config)
>>> array.voxel_size
(1, 1, 1)

Note

The source_arrays are expected to have the same voxel size.

property roi
Return the ROI of the ConcatArray.
Returns:

The ROI of the ConcatArray.

Return type:

Roi

Raises:

AssertionError – If the source arrays have different ROIs.

Examples

>>> config = ConcatArrayConfig(
...     name="my_concat_array",
...     channels=["A", "B"],
...     source_array_configs={
...         "A": ArrayConfig(...),
...         "B": ArrayConfig(...),
...     },
...     default_config=ArrayConfig(...),
... )
>>> array = ConcatArray(config)
>>> array.roi
Roi(...)

Note

The source_arrays are expected to have the same ROI.

property writable: bool

Return whether the ConcatArray is writable.

Returns:

Whether the ConcatArray is writable.

Return type:

bool

Raises:

AssertionError – If the ConcatArray is writable.

Examples

>>> config = ConcatArrayConfig(
...     name="my_concat_array",
...     channels=["A", "B"],
...     source_array_configs={
...         "A": ArrayConfig(...),
...         "B": ArrayConfig(...),
...     },
...     default_config=ArrayConfig(...),
... )
>>> array = ConcatArray(config)
>>> array.writable
False

Note

The ConcatArray is not writable.

property data
Return the data of the ConcatArray.
Returns:

The data of the ConcatArray.

Return type:

np.ndarray

Raises:

RuntimeError – If the ConcatArray is not writable.

Examples

>>> config = ConcatArrayConfig(
...     name="my_concat_array",
...     channels=["A", "B"],
...     source_array_configs={
...         "A": ArrayConfig(...),
...         "B": ArrayConfig(...),
...     },
...     default_config=ArrayConfig(...),
... )
>>> array = ConcatArray(config)
>>> array.data
np.ndarray(...)

Note

The ConcatArray is not writable.

property dtype
Return the data type of the ConcatArray.
Returns:

The data type of the ConcatArray.

Return type:

np.dtype

Raises:

AssertionError – If the source arrays have different data types.

Examples

>>> config = ConcatArrayConfig(
...     name="my_concat_array",
...     channels=["A", "B"],
...     source_array_configs={
...         "A": ArrayConfig(...),
...         "B": ArrayConfig(...),
...     },
...     default_config=ArrayConfig(...),
... )
>>> array = ConcatArray(config)
>>> array.dtype
np.float32

Note

The source_arrays are expected to have the same data type.

property num_channels
Return the number of channels of the ConcatArray.
Returns:

The number of channels of the ConcatArray.

Return type:

int

Raises:

AssertionError – If the source arrays have different numbers of channels.

Examples

>>> config = ConcatArrayConfig(
...     name="my_concat_array",
...     channels=["A", "B"],
...     source_array_configs={
...         "A": ArrayConfig(...),
...         "B": ArrayConfig(...),
...     },
...     default_config=ArrayConfig(...),
... )
>>> array = ConcatArray(config)
>>> array.num_channels
2

Note

The source_arrays are expected to have the same number of channels.

class dacapo.experiments.datasplits.datasets.arrays.ConcatArrayConfig

This array read data from the source array and then return a np.ones_like() version of the data.

channels

An ordering for the source_arrays.

Type:

List[str]

source_array_configs

A mapping from channels to array_configs. If a channel has no ArrayConfig it will be filled with zeros

Type:

Dict[str, ArrayConfig]

default_config

An optional array providing the default array per channel. If not provided, missing channels will simply be filled with 0s

Type:

Optional[ArrayConfig]

__attrs_post_init__(self)

This method is called after the instance has been initialized by the constructor. It is used to set the default_config to an instance of ArrayConfig if it is None.

get_array(self, source_arrays

Dict[str, np.ndarray]) -> np.ndarray: This method reads data from the source array and then return a np.ones_like() version of the data.

Note

This class is used to create a ConcatArray object which is used to read data from the source array and then return a np.ones_like() version of the data. The source array is a dictionary with the key being the channel and the value being the array.

array_type
channels: List[str]
source_array_configs: Dict[str, dacapo.experiments.datasplits.datasets.arrays.array_config.ArrayConfig]
default_config: dacapo.experiments.datasplits.datasets.arrays.array_config.ArrayConfig | None
class dacapo.experiments.datasplits.datasets.arrays.LogicalOrArray(array_config)

Array that computes the logical OR of the instances in a list of source arrays.

name

str The name of the array

source_array

Array The source array from which to take the logical OR

axes()

() -> List[str] Get the axes of the array

dims()

() -> int Get the number of dimensions of the array

voxel_size()

() -> Coordinate Get the voxel size of the array

roi()

() -> Roi Get the region of interest of the array

writable()

() -> bool Get whether the array is writable

dtype()

() -> type Get the data type of the array

num_channels()

() -> int Get the number of channels in the array

data()

() -> np.ndarray Get the data of the array

attrs()

() -> dict Get the attributes of the array

__getitem__()

(roi: Roi) -> np.ndarray Get the data of the array in the region of interest

_can_neuroglance()

() -> bool Get whether the array can be visualized in neuroglance

_neuroglancer_source()

() -> dict Get the neuroglancer source of the array

_neuroglancer_layer()

() -> Tuple[neuroglancer.Layer, dict] Get the neuroglancer layer of the array

_source_name()

() -> str Get the name of the source array

Notes

The LogicalOrArray class is used to create a LogicalOrArray. The LogicalOrArray class is a subclass of the Array class.

name
property axes
Get the axes of the array
Returns:

The axes of the array

Return type:

List[str]

Raises:

ValueError – If the array is not writable

Examples

>>> array_config = MergeInstancesArrayConfig(
...     name="logical_or",
...     source_array_configs=[
...         ArrayConfig(
...             name="mask1",
...             array_type=MaskArray,
...             source_array_config=MaskArrayConfig(
...                 name="mask1",
...                 mask_id=1,
...             ),
...         ),
...         ArrayConfig(
...             name="mask2",
...             array_type=MaskArray,
...             source_array_config=MaskArrayConfig(
...                 name="mask2",
...                 mask_id=2,
...             ),
...         ),
...     ],
... )
>>> array = array_config.create_array()
>>> array.axes
['x', 'y', 'z']

Notes

The axes method is used to get the axes of the array. The axes are the dimensions of the array.

property dims: int

Get the number of dimensions of the array

Returns:

The number of dimensions of the array

Return type:

int

Raises:

ValueError – If the array is not writable

Examples

>>> array_config = MergeInstancesArrayConfig(
...     name="logical_or",
...     source_array_configs=[
...         ArrayConfig(
...             name="mask1",
...             array_type=MaskArray,
...             source_array_config=MaskArrayConfig(
...                 name="mask1",
...                 mask_id=1,
...             ),
...         ),
...         ArrayConfig(
...             name="mask2",
...             array_type=MaskArray,
...             source_array_config=MaskArrayConfig(
...                 name="mask2",
...                 mask_id=2,
...             ),
...         ),
...     ],
... )
>>> array = array_config.create_array()
>>> array.dims
3

Notes

The dims method is used to get the number of dimensions of the array. The number of dimensions is the number of axes of the array.

property voxel_size: funlib.geometry.Coordinate

Get the voxel size of the array

Returns:

The voxel size of the array

Return type:

Coordinate

Raises:

ValueError – If the array is not writable

Examples

>>> array_config = MergeInstancesArrayConfig(
...     name="logical_or",
...     source_array_configs=[
...         ArrayConfig(
...             name="mask1",
...             array_type=MaskArray,
...             source_array_config=MaskArrayConfig(
...                 name="mask1",
...                 mask_id=1,
...             ),
...         ),
...         ArrayConfig(
...             name="mask2",
...             array_type=MaskArray,
...             source_array_config=MaskArrayConfig(
...                 name="mask2",
...                 mask_id=2,
...             ),
...         ),
...     ],
... )
>>> array = array_config.create_array()
>>> array.voxel_size
Coordinate(x=1.0, y=1.0, z=1.0)

Notes

The voxel_size method is used to get the voxel size of the array. The voxel size is the size of a voxel in the array.

property roi: funlib.geometry.Roi

Get the region of interest of the array

Returns:

The region of interest of the array

Return type:

Roi

Raises:

ValueError – If the array is not writable

Examples

>>> array_config = MergeInstancesArrayConfig(
...     name="logical_or",
...     source_array_configs=[
...         ArrayConfig(
...             name="mask1",
...             array_type=MaskArray,
...             source_array_config=MaskArrayConfig(
...                 name="mask1",
...                 mask_id=1,
...             ),
...         ),
...         ArrayConfig(
...             name="mask2",
...             array_type=MaskArray,
...             source_array_config=MaskArrayConfig(
...                 name="mask2",
...                 mask_id=2,
...             ),
...         ),
...     ],
... )
>>> array = array_config.create_array()
>>> array.roi
Roi(offset=(0, 0, 0), shape=(10, 10, 10))

Notes

The roi method is used to get the region of interest of the array. The region of interest is the shape and offset of the array.

property writable: bool

Get whether the array is writable

Returns:

Whether the array is writable

Return type:

bool

Raises:

ValueError – If the array is not writable

Examples

>>> array_config = MergeInstancesArrayConfig(
...     name="logical_or",
...     source_array_configs=[
...         ArrayConfig(
...             name="mask1",
...             array_type=MaskArray,
...             source_array_config=MaskArrayConfig(
...                 name="mask1",
...                 mask_id=1,
...             ),
...         ),
...         ArrayConfig(
...             name="mask2",
...             array_type=MaskArray,
...             source_array_config=MaskArrayConfig(
...                 name="mask2",
...                 mask_id=2,
...             ),
...         ),
...     ],
... )
>>> array = array_config.create_array()
>>> array.writable
False

Notes

The writable method is used to get whether the array is writable. An array is writable if it can be modified.

property dtype
Get the data type of the array
Returns:

The data type of the array

Return type:

type

Raises:

ValueError – If the array is not writable

Examples

>>> array_config = MergeInstancesArrayConfig(
...     name="logical_or",
...     source_array_configs=[
...         ArrayConfig(
...             name="mask1",
...             array_type=MaskArray,
...             source_array_config=MaskArrayConfig(
...                 name="mask1",
...                 mask_id=1,
...             ),
...         ),
...         ArrayConfig(
...             name="mask2",
...             array_type=MaskArray,
...             source_array_config=MaskArrayConfig(
...                 name="mask2",
...                 mask_id=2,
...             ),
...         ),
...     ],
... )
>>> array = array_config.create_array()
>>> array.dtype
<class 'numpy.uint8'>

Notes

The dtype method is used to get the data type of the array. The data type is the type of the data in the array.

property num_channels
Get the number of channels in the array
Returns:

The number of channels in the array

Return type:

int

Raises:

ValueError – If the array is not writable

Examples

>>> array_config = MergeInstancesArrayConfig(
...     name="logical_or",
...     source_array_configs=[
...         ArrayConfig(
...             name="mask1",
...             array_type=MaskArray,
...             source_array_config=MaskArrayConfig(
...                 name="mask1",
...                 mask_id=1,
...             ),
...         ),
...         ArrayConfig(
...             name="mask2",
...             array_type=MaskArray,
...             source_array_config=MaskArrayConfig(
...                 name="mask2",
...                 mask_id=2,
...             ),
...         ),
...     ],
... )
>>> array = array_config.create_array()
>>> array.num_channels
1

Notes

The num_channels method is used to get the number of channels in the array. The number of channels is the number of channels in the array.

property data
Get the data of the array
Returns:

The data of the array

Return type:

np.ndarray

Raises:

ValueError – If the array is not writable

Examples

>>> array_config = MergeInstancesArrayConfig(
...     name="logical_or",
...     source_array_configs=[
...         ArrayConfig(
...             name="mask1",
...             array_type=MaskArray,
...             source_array_config=MaskArrayConfig(
...                 name="mask1",
...                 mask_id=1,
...             ),
...         ),
...         ArrayConfig(
...             name="mask2",
...             array_type=MaskArray,
...             source_array_config=MaskArrayConfig(
...                 name="mask2",
...                 mask_id=2,
...             ),
...         ),
...     ],
... )
>>> array = array_config.create_array()
>>> array.data
array([[[1, 1, 1, ..., 1, 1, 1],
        [1, 1, 1, ..., 1, 1, 1],
        [1, 1, 1, ..., 1, 1, 1],
        ...,
        [1, 1, 1, ..., 1, 1, 1],
        [1, 1, 1, ..., 1, 1, 1],
        [1, 1, 1, ..., 1, 1, 1]]], dtype=uint8)

Notes

The data method is used to get the data of the array. The data is the content of the array.

property attrs
Get the attributes of the array
Returns:

The attributes of the array

Return type:

dict

Raises:

ValueError – If the array is not writable

Examples

>>> array_config = MergeInstancesArrayConfig(
...     name="logical_or",
...     source_array_configs=[
...         ArrayConfig(
...             name="mask1",
...             array_type=MaskArray,
...             source_array_config=MaskArrayConfig(
...                 name="mask1",
...                 mask_id=1,
...             ),
...         ),
...         ArrayConfig(
...             name="mask2",
...             array_type=MaskArray,
...             source_array_config=MaskArrayConfig(
...                 name="mask2",
...                 mask_id=2,
...             ),
...         ),
...     ],
... )
>>> array = array_config.create_array()
>>> array.attrs
{'name': 'logical_or'}

Notes

The attrs method is used to get the attributes of the array. The attributes are the metadata of the array.

class dacapo.experiments.datasplits.datasets.arrays.LogicalOrArrayConfig

This config class takes a source array and performs a logical or over the channels. Good for union multiple masks.

source_array_config

The Array of masks from which to take the union

Type:

ArrayConfig

to_array()

Returns the LogicalOrArray object

Notes

The source_array_config must be an ArrayConfig object.

array_type
source_array_config: dacapo.experiments.datasplits.datasets.arrays.array_config.ArrayConfig
class dacapo.experiments.datasplits.datasets.arrays.CropArray(array_config)

Used to crop a larger array to a smaller array. This is useful when you want to work with a subset of a larger array, but don’t want to copy the data. The crop is done on demand, so the data is not copied until you actually access it.

name

The name of the array.

source_array

The array to crop.

crop_roi

The region of interest to crop to.

attrs()

Returns the attributes of the source array.

axes()

Returns the axes of the source array.

dims()

Returns the number of dimensions of the source array.

voxel_size()

Returns the voxel size of the source array.

roi()

Returns the region of interest of the source array.

writable()

Returns whether the array is writable.

dtype()

Returns the data type of the source array.

num_channels()

Returns the number of channels of the source array.

data()

Returns the data of the source array.

channels()

Returns the channels of the source array.

__getitem__(roi)

Returns the data of the source array within the region of interest.

_can_neuroglance()

Returns whether the source array can be viewed in Neuroglancer.

_neuroglancer_source()

Returns the source of the source array for Neuroglancer.

_neuroglancer_layer()

Returns the layer of the source array for Neuroglancer.

_source_name()

Returns the name of the source array.

Note

This class is a subclass of Array.

name
crop_roi
property attrs
Returns the attributes of the source array.
Returns:

The attributes of the source array.

Raises:

ValueError – If the region of interest to crop to is not within the

Examples

>>> from dacapo.experiments.datasplits.datasets.arrays import ArrayConfig
>>> from dacapo.experiments.datasplits.datasets.arrays import CropArray
>>> from funlib.geometry import Roi
>>> import numpy as np
>>> array_config = ArrayConfig(
...     name='array',
...     source_array_config=source_array_config,
...     roi=Roi((0, 0, 0), (10, 10, 10))
... )
>>> crop_array = CropArray(array_config)
>>> crop_array.attrs
{}

Note

The attributes are empty because the source array is not modified.

property axes
Returns the axes of the source array.
Returns:

The axes of the source array.

Raises:

ValueError – If the region of interest to crop to is not within the

Examples

>>> from dacapo.experiments.datasplits.datasets.arrays import ArrayConfig
>>> from dacapo.experiments.datasplits.datasets.arrays import CropArray
>>> from funlib.geometry import Roi
>>> import numpy as np
>>> array_config = ArrayConfig(
...     name='array',
...     source_array_config=source_array_config,
...     roi=Roi((0, 0, 0), (10, 10, 10))
... )
>>> crop_array = CropArray(array_config)
>>> crop_array.axes
'zyx'

Note

The axes are ‘zyx’ because the source array is not modified.

property dims: int

Returns the number of dimensions of the source array.

Returns:

The number of dimensions of the source array.

Raises:

ValueError – If the region of interest to crop to is not within the region of interest of the source array.

Examples

>>> from dacapo.experiments.datasplits.datasets.arrays import ArrayConfig
>>> from dacapo.experiments.datasplits.datasets.arrays import CropArray
>>> from funlib.geometry import Roi
>>> import numpy as np
>>> array_config = ArrayConfig(
...     name='array',
...     source_array_config=source_array_config,
...     roi=Roi((0, 0, 0), (10, 10, 10))
... )
>>> crop_array = CropArray(array_config)
>>> crop_array.dims
3

Note

The number of dimensions is 3 because the source array is not modified.

property voxel_size: funlib.geometry.Coordinate

Returns the voxel size of the source array.

Returns:

The voxel size of the source array.

Raises:

ValueError – If the region of interest to crop to is not within the region of interest of the source array.

Examples

>>> from dacapo.experiments.datasplits.datasets.arrays import ArrayConfig
>>> from dacapo.experiments.datasplits.datasets.arrays import CropArray
>>> from funlib.geometry import Roi
>>> import numpy as np
>>> array_config = ArrayConfig(
...     name='array',
...     source_array_config=source_array_config,
...     roi=Roi((0, 0, 0), (10, 10, 10))
... )
>>> crop_array = CropArray(array_config)
>>> crop_array.voxel_size
Coordinate(x=1.0, y=1.0, z=1.0)

Note

The voxel size is (1.0, 1.0, 1.0) because the source array is not modified.

property roi: funlib.geometry.Roi

Returns the region of interest of the source array.

Returns:

The region of interest of the source array.

Raises:

ValueError – If the region of interest to crop to is not within the region of interest of the source array.

Examples

>>> from dacapo.experiments.datasplits.datasets.arrays import ArrayConfig
>>> from dacapo.experiments.datasplits.datasets.arrays import CropArray
>>> from funlib.geometry import Roi
>>> import numpy as np
>>> array_config = ArrayConfig(
...     name='array',
...     source_array_config=source_array_config,
...     roi=Roi((0, 0, 0), (10, 10, 10))
... )
>>> crop_array = CropArray(array_config)
>>> crop_array.roi
Roi(offset=(0, 0, 0), shape=(10, 10, 10))

Note

The region of interest is (0, 0, 0) with shape (10, 10, 10) because the source array is not modified.

property writable: bool

Returns whether the array is writable.

Returns:

False

Raises:

ValueError – If the region of interest to crop to is not within the region of interest of the source array.

Examples

>>> from dacapo.experiments.datasplits.datasets.arrays import ArrayConfig
>>> from dacapo.experiments.datasplits.datasets.arrays import CropArray
>>> from funlib.geometry import Roi
>>> import numpy as np
>>> array_config = ArrayConfig(
...     name='array',
...     source_array_config=source_array_config,
...     roi=Roi((0, 0, 0), (10, 10, 10))
... )
>>> crop_array = CropArray(array_config)
>>> crop_array.writable
False

Note

The array is not writable because it is a virtual array created by modifying another array on demand.

property dtype
Returns the data type of the source array.
Returns:

The data type of the source array.

Raises:

ValueError – If the region of interest to crop to is not within the region of interest of the source array.

Examples

>>> from dacapo.experiments.datasplits.datasets.arrays import ArrayConfig
>>> from dacapo.experiments.datasplits.datasets.arrays import CropArray
>>> from funlib.geometry import Roi
>>> import numpy as np
>>> array_config = ArrayConfig(
...     name='array',
...     source_array_config=source_array_config,
...     roi=Roi((0, 0, 0), (10, 10, 10))
... )
>>> crop_array = CropArray(array_config)
>>> crop_array.dtype
numpy.dtype('uint8')

Note

The data type is uint8 because the source array is not modified.

property num_channels: int

Returns the number of channels of the source array.

Returns:

The number of channels of the source array.

Raises:

ValueError – If the region of interest to crop to is not within the region of interest of the source array.

Examples

>>> from dacapo.experiments.datasplits.datasets.arrays import ArrayConfig
>>> from dacapo.experiments.datasplits.datasets.arrays import CropArray
>>> from funlib.geometry import Roi
>>> import numpy as np
>>> array_config = ArrayConfig(
...     name='array',
...     source_array_config=source_array_config,
...     roi=Roi((0, 0, 0), (10, 10, 10))
... )
>>> crop_array = CropArray(array_config)
>>> crop_array.num_channels
1

Note

The number of channels is 1 because the source array is not modified.

property data
Returns the data of the source array.
Returns:

The data of the source array.

Raises:

ValueError – If the region of interest to crop to is not within the region of interest of the source array.

Examples

>>> from dacapo.experiments.datasplits.datasets.arrays import ArrayConfig
>>> from dacapo.experiments.datasplits.datasets.arrays import CropArray
>>> from funlib.geometry import Roi
>>> import numpy as np
>>> array_config = ArrayConfig(
...     name='array',
...     source_array_config=source_array_config,
...     roi=Roi((0, 0, 0), (10, 10, 10))
... )
>>> crop_array = CropArray(array_config)
>>> crop_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, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],
       [[0, 0, 0, 0, 0, 0, 0, 0, 0
property channels
Returns the channels of the source array.
Returns:

The channels of the source array.

Raises:

ValueError – If the region of interest to crop to is not within the region of interest of the source array.

Examples

>>> from dacapo.experiments.datasplits.datasets.arrays import ArrayConfig
>>> from dacapo.experiments.datasplits.datasets.arrays import CropArray
>>> from funlib.geometry import Roi
>>> import numpy as np
>>> array_config = ArrayConfig(
...     name='array',
...     source_array_config=source_array_config,
...     roi=Roi((0, 0, 0), (10, 10, 10))
... )
>>> crop_array = CropArray(array_config)
>>> crop_array.channels
1

Note

The channels is 1 because the source array is not modified.

class dacapo.experiments.datasplits.datasets.arrays.CropArrayConfig

This config class provides the necessary configuration for cropping an Array to a smaller ROI. Especially useful for validation volumes that may be too large for quick evaluation. The ROI is specified in the config. The cropped Array will have the same dtype as the source Array.

source_array_config

The Array to crop

Type:

ArrayConfig

roi

The ROI for cropping

Type:

Roi

from_toml(cls, toml_path

str) -> CropArrayConfig: Load the CropArrayConfig from a TOML file

to_toml(self, toml_path

str) -> None: Save the CropArrayConfig to a TOML file

create_array(self) CropArray

Create the CropArray from the config

Note

This class is a subclass of ArrayConfig and inherits all its attributes and methods. The only difference is that the array_type is CropArray.

array_type
source_array_config: dacapo.experiments.datasplits.datasets.arrays.array_config.ArrayConfig
roi: funlib.geometry.Roi
class dacapo.experiments.datasplits.datasets.arrays.MergeInstancesArray(array_config)

This array merges multiple source arrays into a single array by summing them. This is useful for merging instance segmentation arrays into a single array. NeuoGlancer will display each instance as a different color.

name

str The name of the array

source_array_configs

List[ArrayConfig] A list of source arrays to merge

__getitem__(roi

Roi) -> np.ndarray Returns a numpy array with the requested region of interest

_can_neuroglance() bool

Returns True if the array can be visualized in neuroglancer

_neuroglancer_source() str

Returns the source name for the array in neuroglancer

_neuroglancer_layer() Tuple[neuroglancer.SegmentationLayer, Dict[str, Any]]

Returns a neuroglancer layer and its configuration

_source_name() str

Returns the source name for the array

Note

This array is not writable Source arrays must have the same shape.

name
property axes
Returns the axes of the array
Returns:

The axes of the array

Return type:

List[str]

Raises:

ValueError – If the source arrays have different shapes

Example

```python from dacapo.experiments.datasplits.datasets.arrays import MergeInstancesArray from dacapo.experiments.datasplits.datasets.arrays import MergeInstancesArrayConfig from dacapo.experiments.datasplits.datasets.arrays import ArrayConfig from dacapo.experiments.datasplits.datasets.arrays import ArrayType from funlib.geometry import Coordinate, Roi array_config = MergeInstancesArrayConfig(

name=”array”, source_array_configs=[

ArrayConfig(

name=”array1”, array_type=ArrayType.INSTANCE_SEGMENTATION, path=”path/to/array1.h5”,

), ArrayConfig(

name=”array2”, array_type=ArrayType.INSTANCE_SEGMENTATION, path=”path/to/array2.h5”,

),

],

) array = MergeInstancesArray(array_config) axes = array.axes ```

Note

This example shows how to get the axes of the array

property dims: int

Returns the number of dimensions of the array

Returns:

The number of dimensions of the array

Return type:

int

Raises:

ValueError – If the source arrays have different shapes

Example

```python from dacapo.experiments.datasplits.datasets.arrays import MergeInstancesArray from dacapo.experiments.datasplits.datasets.arrays import MergeInstancesArrayConfig from dacapo.experiments.datasplits.datasets.arrays import ArrayConfig from dacapo.experiments.datasplits.datasets.arrays import ArrayType from funlib.geometry import Coordinate, Roi array_config = MergeInstancesArrayConfig(

name=”array”, source_array_configs=[

ArrayConfig(

name=”array1”, array_type=ArrayType.INSTANCE_SEGMENTATION, path=”path/to/array1.h5”,

), ArrayConfig(

name=”array2”, array_type=ArrayType.INSTANCE_SEGMENTATION, path=”path/to/array2.h5”,

),

],

) array = MergeInstancesArray(array_config) dims = array.dims ```

Note

This example shows how to get the number of dimensions of the array

property voxel_size: funlib.geometry.Coordinate

Returns the voxel size of the array

Returns:

The voxel size of the array

Return type:

Coordinate

Raises:

ValueError – If the source arrays have different shapes

Example

```python from dacapo.experiments.datasplits.datasets.arrays import MergeInstancesArray from dacapo.experiments.datasplits.datasets.arrays import MergeInstancesArrayConfig from dacapo.experiments.datasplits.datasets.arrays import ArrayConfig from dacapo.experiments.datasplits.datasets.arrays import ArrayType from funlib.geometry import Coordinate, Roi array_config = MergeInstancesArrayConfig(

name=”array”, source_array_configs=[

ArrayConfig(

name=”array1”, array_type=ArrayType.INSTANCE_SEGMENTATION, path=”path/to/array1.h5”,

), ArrayConfig(

name=”array2”, array_type=ArrayType.INSTANCE_SEGMENTATION, path=”path/to/array2.h5”,

),

],

) array = MergeInstancesArray(array_config) voxel_size = array.voxel_size ```

Note

This example shows how to get the voxel size of the array

property roi: funlib.geometry.Roi

Returns the region of interest of the array

Returns:

The region of interest of the array

Return type:

Roi

Raises:

ValueError – If the source arrays have different shapes

Example

```python from dacapo.experiments.datasplits.datasets.arrays import MergeInstancesArray from dacapo.experiments.datasplits.datasets.arrays import MergeInstancesArrayConfig from dacapo.experiments.datasplits.datasets.arrays import ArrayConfig from dacapo.experiments.datasplits.datasets.arrays import ArrayType from funlib.geometry import Coordinate, Roi array_config = MergeInstancesArrayConfig(

name=”array”, source_array_configs=[

ArrayConfig(

name=”array1”, array_type=ArrayType.INSTANCE_SEGMENTATION, path=”path/to/array1.h5”,

), ArrayConfig(

name=”array2”, array_type=ArrayType.INSTANCE_SEGMENTATION, path=”path/to/array2.h5”,

),

],

) array = MergeInstancesArray(array_config) roi = array.roi ```

Note

This example shows how to get the region of interest of the array

property writable: bool

Returns True if the array is writable, False otherwise

Returns:

True if the array is writable, False otherwise

Return type:

bool

Raises:

ValueError – If the source arrays have different shapes

Example

```python from dacapo.experiments.datasplits.datasets.arrays import MergeInstancesArray from dacapo.experiments.datasplits.datasets.arrays import MergeInstancesArrayConfig from dacapo.experiments.datasplits.datasets.arrays import ArrayConfig from dacapo.experiments.datasplits.datasets.arrays import ArrayType from funlib.geometry import Coordinate, Roi array_config = MergeInstancesArrayConfig(

name=”array”, source_array_configs=[

ArrayConfig(

name=”array1”, array_type=ArrayType.INSTANCE_SEGMENTATION, path=”path/to/array1.h5”,

), ArrayConfig(

name=”array2”, array_type=ArrayType.INSTANCE_SEGMENTATION, path=”path/to/array2.h5”,

),

],

) array = MergeInstancesArray(array_config) writable = array.writable ```

Note

This example shows how to check if the array is writable

property dtype
Returns the data type of the array
Returns:

The data type of the array

Return type:

np.dtype

Raises:

ValueError – If the source arrays have different shapes

Example

```python from dacapo.experiments.datasplits.datasets.arrays import MergeInstancesArray from dacapo.experiments.datasplits.datasets.arrays import MergeInstancesArrayConfig from dacapo.experiments.datasplits.datasets.arrays import ArrayConfig from dacapo.experiments.datasplits.datasets.arrays import ArrayType from funlib.geometry import Coordinate, Roi array_config = MergeInstancesArrayConfig(

name=”array”, source_array_configs=[

ArrayConfig(

name=”array1”, array_type=ArrayType.INSTANCE_SEGMENTATION, path=”path/to/array1.h5”,

), ArrayConfig(

name=”array2”, array_type=ArrayType.INSTANCE_SEGMENTATION, path=”path/to/array2.h5”,

),

],

) array = MergeInstancesArray(array_config) dtype = array.dtype ```

Note

This example shows how to get the data type of the array

property num_channels
Returns the number of channels of the array
Returns:

The number of channels of the array

Return type:

int

Raises:

ValueError – If the source arrays have different shapes

Example

```python from dacapo.experiments.datasplits.datasets.arrays import MergeInstancesArray from dacapo.experiments.datasplits.datasets.arrays import MergeInstancesArrayConfig from dacapo.experiments.datasplits.datasets.arrays import ArrayConfig from dacapo.experiments.datasplits.datasets.arrays import ArrayType from funlib.geometry import Coordinate, Roi array_config = MergeInstancesArrayConfig(

name=”array”, source_array_configs=[

ArrayConfig(

name=”array1”, array_type=ArrayType.INSTANCE_SEGMENTATION, path=”path/to/array1.h5”,

), ArrayConfig(

name=”array2”, array_type=ArrayType.INSTANCE_SEGMENTATION, path=”path/to/array2.h5”,

),

],

) array = MergeInstancesArray(array_config) num_channels = array.num_channels ```

Note

This example shows how to get the number of channels of the array

property data
Returns the data of the array
Returns:

The data of the array

Return type:

np.ndarray

Raises:

ValueError – If the source arrays have different shapes

Example

```python from dacapo.experiments.datasplits.datasets.arrays import MergeInstancesArray from dacapo.experiments.datasplits.datasets.arrays import MergeInstancesArrayConfig from dacapo.experiments.datasplits.datasets.arrays import ArrayConfig from dacapo.experiments.datasplits.datasets.arrays import ArrayType from funlib.geometry import Coordinate, Roi array_config = MergeInstancesArrayConfig(

name=”array”, source_array_configs=[

ArrayConfig(

name=”array1”, array_type=ArrayType.INSTANCE_SEGMENTATION, path=”path/to/array1.h5”,

), ArrayConfig(

name=”array2”, array_type=ArrayType.INSTANCE_SEGMENTATION, path=”path/to/array2.h5”,

),

],

) array = MergeInstancesArray(array_config) data = array.data ```

Note

This example shows how to get the data of the array

property attrs
Returns the attributes of the array
Returns:

The attributes of the array

Return type:

Dict[str, Any]

Raises:

ValueError – If the source arrays have different shapes

Example

```python from dacapo.experiments.datasplits.datasets.arrays import MergeInstancesArray from dacapo.experiments.datasplits.datasets.arrays import MergeInstancesArrayConfig from dacapo.experiments.datasplits.datasets.arrays import ArrayConfig from dacapo.experiments.datasplits.datasets.arrays import ArrayType from funlib.geometry import Coordinate, Roi array_config = MergeInstancesArrayConfig(

name=”array”, source_array_configs=[

ArrayConfig(

name=”array1”, array_type=ArrayType.INSTANCE_SEGMENTATION, path=”path/to/array1.h5”,

), ArrayConfig(

name=”array2”, array_type=ArrayType.INSTANCE_SEGMENTATION, path=”path/to/array2.h5”,

),

],

) array = MergeInstancesArray(array_config) attributes = array.attrs ```

Note

This example shows how to get the attributes of the array

class dacapo.experiments.datasplits.datasets.arrays.MergeInstancesArrayConfig

Configuration for an array that merges instances from multiple arrays into a single array. The instances are merged by taking the union of the instances in the source arrays.

source_array_configs

List[ArrayConfig] The Array of masks from which to take the union

create_array()

() -> MergeInstancesArray Create a MergeInstancesArray instance from the configuration

Notes

The MergeInstancesArrayConfig class is used to create a MergeInstancesArray

array_type
source_array_configs: List[dacapo.experiments.datasplits.datasets.arrays.array_config.ArrayConfig]
class dacapo.experiments.datasplits.datasets.arrays.DVIDArray(array_config)

This is a DVID array. It is a wrapper around a DVID array that provides the necessary methods to interact with the array. It is used to fetch data from a DVID server. The source is a tuple of three strings: the server, the UUID, and the data name.

DVID: data management system for terabyte-sized 3D images

name

The name of the array

Type:

str

source

The source of the array

Type:

tuple[str, str, str]

__getitem__()

Returns the data from the array for a given region of interest

Notes

The source is a tuple of three strings: the server, the UUID, and the data name.

name: str
source: tuple[str, str, str]
attrs()

Returns the attributes of the DVID array

Returns:

The attributes of the DVID array

Return type:

dict

Raises:

ValueError – If the attributes is not a dictionary

Examples

>>> dvid_array.attrs
{'Extended': {'VoxelSize': (1.0, 1.0, 1.0), 'Values': [{'DataType': 'uint64'}]}, 'Extents': {'MinPoint': (0, 0, 0), 'MaxPoint': (100, 100, 100)}}

Notes

The attributes are the same as the source array

property axes
Returns the axes of the DVID array
Returns:

The axes of the DVID array

Return type:

str

Raises:

ValueError – If the axes is not a string

Examples

>>> dvid_array.axes
'zyx'

Notes

The axes are the same as the source array

property dims: int

Returns the dimensions of the DVID array

Returns:

The dimensions of the DVID array

Return type:

int

Raises:

ValueError – If the dimensions is not an integer

Examples

>>> dvid_array.dims
3

Notes

The dimensions are the same as the source array

voxel_size() funlib.geometry.Coordinate

Returns the voxel size of the DVID array

Returns:

The voxel size of the DVID array

Return type:

Coordinate

Raises:

ValueError – If the voxel size is not a Coordinate object

Examples

>>> dvid_array.voxel_size
Coordinate(x=1.0, y=1.0, z=1.0)

Notes

The voxel size is the same as the source array

roi() funlib.geometry.Roi

Returns the region of interest of the DVID array

Returns:

The region of interest of the DVID array

Return type:

Roi

Raises:

ValueError – If the region of interest is not a Roi object

Examples

>>> dvid_array.roi
Roi(...)

Notes

The region of interest is the same as the source array

property writable: bool

Returns whether the DVID array is writable

Returns:

Whether the DVID array is writable

Return type:

bool

Raises:

ValueError – If the writable is not a boolean

Examples

>>> dvid_array.writable
False

Notes

The writable is the same as the source array

property dtype: Any

Returns the data type of the DVID array

Returns:

The data type of the DVID array

Return type:

type

Raises:

ValueError – If the data type is not a type

Examples

>>> dvid_array.dtype
numpy.uint64

Notes

The data type is the same as the source array

property num_channels: int | None

Returns the number of channels of the DVID array

Returns:

The number of channels of the DVID array

Return type:

int

Raises:

ValueError – If the number of channels is not an integer

Examples

>>> dvid_array.num_channels
1

Notes

The number of channels is the same as the source array

property spatial_axes: List[str]

Returns the spatial axes of the DVID array

Returns:

The spatial axes of the DVID array

Return type:

List[str]

Raises:

ValueError – If the spatial axes is not a list

Examples

>>> dvid_array.spatial_axes
['z', 'y', 'x']

Notes

The spatial axes are the same as the source array

property data: Any
Abstractmethod:

Returns the number of channels of the DVID array

Returns:

The number of channels of the DVID array

Return type:

int

Raises:

ValueError – If the number of channels is not an integer

Examples

>>> dvid_array.num_channels
1

Notes

The number of channels is the same as the source array

abstract add_metadata(metadata: Dict[str, Any]) None

Adds metadata to the DVID array

Parameters:

metadata (dict) – The metadata to add to the DVID array

Returns:

None

Raises:

ValueError – If the metadata is not a dictionary

Examples

>>> dvid_array.add_metadata({'description': 'This is a DVID array'})

Notes

The metadata is added to the source array

class dacapo.experiments.datasplits.datasets.arrays.DVIDArrayConfig

This config class provides the necessary configuration for a DVID array. It takes a source string and returns the DVIDArray object.

source

The source strings

Type:

Tuple[str, str, str]

to_array()

Returns the DVIDArray object

Notes

The source must be a tuple of strings.

array_type
source: Tuple[str, str, str]
verify() Tuple[bool, str]

Check whether this is a valid Array

Returns:

Whether the Array is valid and a message

Return type:

Tuple[bool, str]

Raises:

ValueError – If the source is not a tuple of strings

Examples

>>> dvid_array_config = DVIDArrayConfig(...)
>>> dvid_array_config.verify()
(True, "No validation for this Array")

Notes

The source must be a tuple of strings.

class dacapo.experiments.datasplits.datasets.arrays.SumArray(array_config)

This class provides a sum array. This array is a virtual array that is created by summing multiple source arrays. The source arrays must have the same shape and ROI.

name

str The name of the array.

_source_arrays

List[Array] The source arrays to sum.

_source_array

Array The first source array.

__getitem__(roi

Roi) -> np.ndarray Get the data for the given region of interest.

_can_neuroglance() bool

Check if neuroglance can be used.

_neuroglancer_source() Dict

Return the source for neuroglance.

_neuroglancer_layer() Tuple[neuroglancer.SegmentationLayer, Dict]

Return the neuroglancer layer.

_source_name() str

Return the source name.

Note

This class is a subclass of Array.

name
property axes
The axes of the array.
Returns:

The axes of the array.

Return type:

List[str]

Raises:

ValueError – Cannot get a writable view of this array because it is a virtual array created by modifying another array on demand.

Examples

>>> sum_array.axes
['x', 'y', 'z']

Note

This class is a subclass of Array.

property dims: int

The number of dimensions of the array.

Returns:

The number of dimensions of the array.

Return type:

int

Raises:

ValueError – Cannot get a writable view of this array because it is a virtual array created by modifying another array on demand.

Examples

>>> sum_array.dims
3

Note

This class is a subclass of Array.

property voxel_size: funlib.geometry.Coordinate

The size of each voxel in each dimension.

Returns:

The size of each voxel in each dimension.

Return type:

Coordinate

Raises:

ValueError – Cannot get a writable view of this array because it is a virtual array created by modifying another array on demand.

Examples

>>> sum_array.voxel_size
Coordinate([1, 1, 1])

Note

This class is a subclass of Array.

property roi: funlib.geometry.Roi

The region of interest of the array.

Parameters:

roi – Roi The region of interest.

Returns:

The region of interest.

Return type:

Roi

Raises:

ValueError – Cannot get a writable view of this array because it is a virtual array created by modifying another array on demand.

Examples

>>> sum_array.roi
Roi(Coordinate([0, 0, 0]), Coordinate([100, 100, 100]))

Note

This class is a subclass of Array.

property writable: bool

Check if the array is writable.

Parameters:

writable – bool Check if the array is writable.

Returns:

True if the array is writable, otherwise False.

Return type:

bool

Raises:

ValueError – Cannot get a writable view of this array because it is a virtual array created by modifying another array on demand.

Examples

>>> sum_array.writable
False

Note

This class is a subclass of Array.

property dtype
The data type of the array.
Parameters:

dtype – np.uint8 The data type of the array.

Returns:

The data type of the array.

Return type:

np.uint8

Raises:

ValueError – Cannot get a writable view of this array because it is a virtual array created by modifying another array on demand.

Examples

>>> sum_array.dtype
np.uint8

Note

This class is a subclass of Array.

property num_channels
The number of channels in the array.
Parameters:

num_channels – Optional[int] The number of channels in the array.

Returns:

The number of channels in the array.

Return type:

Optional[int]

Raises:

ValueError – Cannot get a writable view of this array because it is a virtual array created by modifying another array on demand.

Examples

>>> sum_array.num_channels
None

Note

This class is a subclass of Array.

property data
Get the data of the array.
Parameters:

data – np.ndarray The data of the array.

Returns:

The data of the array.

Return type:

np.ndarray

Raises:

ValueError – Cannot get a writable view of this array because it is a virtual array created by modifying another array on demand.

Examples

>>> sum_array.data
np.array([[[0, 0], [0, 0]], [[0, 0], [0, 0]]])

Note

This class is a subclass of Array.

property attrs
Return the attributes of the array.
Parameters:

attrs – Dict The attributes of the array.

Returns:

The attributes of the array.

Return type:

Dict

Raises:

ValueError – Cannot get a writable view of this array because it is a virtual array created by modifying another array on demand.

Examples

>>> sum_array.attrs
{}

Note

This class is a subclass of Array.

class dacapo.experiments.datasplits.datasets.arrays.SumArrayConfig

This config class provides the necessary configuration for a sum array.

source_array_configs

List[ArrayConfig] The Array of masks from which to take the union

Note

This class is a subclass of ArrayConfig.

array_type
source_array_configs: List[dacapo.experiments.datasplits.datasets.arrays.array_config.ArrayConfig]
class dacapo.experiments.datasplits.datasets.arrays.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:

NumpyArray

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:

NumpyArray

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.

class dacapo.experiments.datasplits.datasets.arrays.ConstantArray(array_config)

This is a wrapper around another source_array that simply provides constant value with the same metadata as the source_array.

This is useful for creating a mask array that is the same size as the original array, but with all values set to 1.

source_array

The source array that this array is based on.

like()

Create a new ConstantArray with the same metadata as another array.

attrs()

Get the attributes of the array.

axes()

Get the axes of the array.

dims()

Get the dimensions of the array.

voxel_size()

Get the voxel size of the array.

roi()

Get the region of interest of the array.

writable()

Check if the array is writable.

data()

Get the data of the array.

dtype()

Get the data type of the array.

num_channels()

Get the number of channels of the array.

__getitem__()

Get a subarray of the array.

Note

This class is not meant to be instantiated directly. Instead, use the like method to create a new ConstantArray with the same metadata as another array.

classmethod like(array: dacapo.experiments.datasplits.datasets.arrays.array.Array)

Create a new ConstantArray with the same metadata as another array.

Parameters:

array – The source array.

Returns:

The new ConstantArray with the same metadata as the source array.

Raises:

RuntimeError – If the source array is not specified.

Examples

>>> from dacapo.experiments.datasplits.datasets.arrays import ConstantArray
>>> from dacapo.experiments.datasplits.datasets.arrays import NumpyArray
>>> import numpy as np
>>> source_array = NumpyArray(np.zeros((10, 10, 10)))
>>> ones_array = ConstantArray.like(source_array)
>>> ones_array.source_array
NumpyArray(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., 0., 0., 0., 0., 0., 0.],
                        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
                        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
                        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
                        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
                        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
                        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
                        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]]]), voxel_size=(1.0, 1.0, 1.0), roi=Roi((0, 0, 0), (10, 10, 10)), num_channels=1)

Notes

This class is not meant to be instantiated directly. Instead, use the like method to create a new ConstantArray with the same metadata as another array.

property attrs
Get the attributes of the array.
Returns:

An empty dictionary.

Examples

>>> from dacapo.experiments.datasplits.datasets.arrays import ConstantArray
>>> from dacapo.experiments.datasplits.datasets.arrays import NumpyArray
>>> import numpy as np
>>> source_array = NumpyArray(np.zeros((10, 10, 10)))
>>> ones_array = ConstantArray(source_array)
>>> ones_array.attrs
{}

Notes

This method is used to get the attributes of the array. The attributes are stored as key-value pairs in a dictionary. This method returns an empty dictionary because the ConstantArray does not have any attributes.

property source_array: dacapo.experiments.datasplits.datasets.arrays.array.Array

Get the source array that this array is based on.

Returns:

The source array.

Raises:

RuntimeError – If the source array is not specified.

Examples

>>> from dacapo.experiments.datasplits.datasets.arrays import ConstantArray
>>> from dacapo.experiments.datasplits.datasets.arrays import NumpyArray
>>> import numpy as np
>>> source_array = NumpyArray(np.zeros((10, 10, 10)))
>>> ones_array = ConstantArray(source_array)
>>> ones_array.source_array
NumpyArray(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., 0., 0., 0., 0., 0., 0.],
                        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
                        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
                        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
                        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
                        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
                        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
                        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]]]), voxel_size=(1.0, 1.0, 1.0), roi=Roi((0, 0, 0), (10, 10, 10)), num_channels=1)

Notes

This method is used to get the source array that this array is based on. The source array is the array that the ConstantArray is created from. This method returns the source array that was specified when the ConstantArray was created.

property axes
Get the axes of the array.
Returns:

The axes of the array.

Raises:

RuntimeError – If the axes are not specified.

Examples

>>> from dacapo.experiments.datasplits.datasets.arrays import ConstantArray
>>> from dacapo.experiments.datasplits.datasets.arrays import NumpyArray
>>> import numpy as np
>>> source_array = NumpyArray(np.zeros((10, 10, 10)))
>>> ones_array = ConstantArray(source_array)
>>> ones_array.axes
'zyx'

Notes

This method is used to get the axes of the array. The axes are the order of the dimensions of the array. This method returns the axes of the array that was specified when the ConstantArray was created.

property dims
Get the dimensions of the array.
Returns:

The dimensions of the array.

Raises:

RuntimeError – If the dimensions are not specified.

Examples

>>> from dacapo.experiments.datasplits.datasets.arrays import ConstantArray
>>> from dacapo.experiments.datasplits.datasets.arrays import NumpyArray
>>> import numpy as np
>>> source_array = NumpyArray(np.zeros((10, 10, 10)))
>>> ones_array = ConstantArray(source_array)
>>> ones_array.dims
(10, 10, 10)

Notes

This method is used to get the dimensions of the array. The dimensions are the size of the array along each axis. This method returns the dimensions of the array that was specified when the ConstantArray was created.

property voxel_size
Get the voxel size of the array.
Returns:

The voxel size of the array.

Raises:

RuntimeError – If the voxel size is not specified.

Examples

>>> from dacapo.experiments.datasplits.datasets.arrays import ConstantArray
>>> from dacapo.experiments.datasplits.datasets.arrays import NumpyArray
>>> import numpy as np
>>> source_array = NumpyArray(np.zeros((10, 10, 10)))
>>> ones_array = ConstantArray(source_array)
>>> ones_array.voxel_size
(1.0, 1.0, 1.0)

Notes

This method is used to get the voxel size of the array. The voxel size is the size of each voxel in the array. This method returns the voxel size of the array that was specified when the ConstantArray was created.

property roi
Get the region of interest of the array.
Returns:

The region of interest of the array.

Raises:

RuntimeError – If the region of interest is not specified.

Examples

>>> from dacapo.experiments.datasplits.datasets.arrays import ConstantArray
>>> from dacapo.experiments.datasplits.datasets.arrays import NumpyArray
>>> from funlib.geometry import Roi
>>> import numpy as np
>>> source_array = NumpyArray(np.zeros((10, 10, 10)))
>>> ones_array = ConstantArray(source_array)
>>> ones_array.roi
Roi((0, 0, 0), (10, 10, 10))

Notes

This method is used to get the region of interest of the array. The region of interest is the region of the array that contains the data. This method returns the region of interest of the array that was specified when the ConstantArray was created.

property writable: bool

Check if the array is writable.

Returns:

False.

Raises:

RuntimeError – If the writability of the array is not specified.

Examples

>>> from dacapo.experiments.datasplits.datasets.arrays import ConstantArray
>>> from dacapo.experiments.datasplits.datasets.arrays import NumpyArray
>>> import numpy as np
>>> source_array = NumpyArray(np.zeros((10, 10, 10)))
>>> ones_array = ConstantArray(source_array)
>>> ones_array.writable
False

Notes

This method is used to check if the array is writable. An array is writable if it can be modified in place. This method returns False because the ConstantArray is read-only and cannot be modified.

property data
Get the data of the array.
Returns:

The data of the array.

Raises:

RuntimeError – If the data is not specified.

Examples

>>> from dacapo.experiments.datasplits.datasets.arrays import ConstantArray
>>> from dacapo.experiments.datasplits.datasets.arrays import NumpyArray
>>> import numpy as np
>>> source_array = NumpyArray(np.zeros((10, 10, 10)))
>>> ones_array = ConstantArray(source_array)
>>> ones_array.data
array([[[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]])

Notes

This method is used to get the data of the array. The data is the values that are stored in the array. This method returns a subarray of the array with all values set to 1.

property dtype
Get the data type of the array.
Returns:

The data type of the array.

Raises:

RuntimeError – If the data type is not specified.

Examples

>>> from dacapo.experiments.datasplits.datasets.arrays import ConstantArray
>>> from dacapo.experiments.datasplits.datasets.arrays import NumpyArray
>>> import numpy as np
>>> source_array = NumpyArray(np.zeros((10, 10, 10)))
>>> ones_array = ConstantArray(source_array)
>>> ones_array.dtype
<class 'numpy.bool_'>

Notes

This method is used to get the data type of the array. The data type is the type of the values that are stored in the array. This method returns the data type of the array that was specified when the ConstantArray was created.

property num_channels
Get the number of channels of the array.
Returns:

The number of channels of the array.

Raises:

RuntimeError – If the number of channels is not specified.

Examples

>>> from dacapo.experiments.datasplits.datasets.arrays import ConstantArray
>>> from dacapo.experiments.datasplits.datasets.arrays import NumpyArray
>>> import numpy as np
>>> source_array = NumpyArray(np.zeros((10, 10, 10)))
>>> ones_array = ConstantArray(source_array)
>>> ones_array.num_channels
1

Notes

This method is used to get the number of channels of the array. The number of channels is the number of values that are stored at each voxel in the array. This method returns the number of channels of the array that was specified when the ConstantArray was created.

class dacapo.experiments.datasplits.datasets.arrays.ConstantArrayConfig

This array read data from the source array and then return a np.ones_like() version.

This is useful for creating a mask array from a source array. For example, if you have a 2D array of data and you want to create a mask array that is the same shape as the data array, you can use this class to create the mask array.

source_array_config

The source array that you want to copy and fill with ones.

create_array()

Create the array.

Note

This class is a subclass of ArrayConfig.

array_type
source_array_config: dacapo.experiments.datasplits.datasets.arrays.array_config.ArrayConfig
constant: int