dacapo.gp
Submodules
Classes
A Gunpowder node for generating the target from the ground truth |
|
Class for applying gamma noise augmentation. |
|
Elasticly deform a batch. Requests larger batches upstream to avoid data |
|
Reject batches based on the masked-in vs. masked-out ratio. |
|
A class to copy a mask into a new key with the option to drop channels via max collapse. |
|
A provider for serving graph data in gunpowder pipelines. |
|
A BatchFilter that multiplies two input arrays and produces an output array. |
Package Contents
- class dacapo.gp.DaCapoTargetFilter(predictor: dacapo.experiments.tasks.predictors.Predictor, gt_key: gunpowder.ArrayKey, target_key: gunpowder.ArrayKey | None = None, weights_key: gunpowder.ArrayKey | None = None, mask_key: gunpowder.ArrayKey | None = None)
A Gunpowder node for generating the target from the ground truth
- gt
The dataset to use for generating the target.
- Type:
Array
- target_key
The key with which to provide the target.
- Type:
gp.ArrayKey
- weights_key
The key with which to provide the weights.
- Type:
gp.ArrayKey
- mask_key
The key with which to provide the mask.
- Type:
gp.ArrayKey
- setup()
Set up the provider.
- prepare(request)
Prepare the request.
- process(batch, request)
Process the batch.
Note
This class is a subclass of gunpowder.BatchFilter and is used to generate the target from the ground truth.
- predictor
- gt_key
- target_key
- weights_key
- mask_key
- moving_counts = None
- setup()
Set up the provider. This function sets the provider to provide the target with the given key.
- Raises:
RuntimeError – If the key is already provided.
Examples
>>> target_filter.setup()
- prepare(request)
Prepare the request.
- Parameters:
request (gp.BatchRequest) – The request to prepare.
- Returns:
The dependencies.
- Return type:
deps (gp.BatchRequest)
- Raises:
NotImplementedError – If the target_key is not provided.
Examples
>>> request = gp.BatchRequest() >>> request[gp.ArrayKey("GT")] = gp.ArraySpec(roi=gp.Roi((0, 0, 0), (1, 1, 1))) >>> target_filter.prepare(request)
- process(batch, request)
Process the batch.
- Parameters:
batch (gp.Batch) – The batch to process.
request (gp.BatchRequest) – The request to process.
- Returns:
The output batch.
- Return type:
output (gp.Batch)
Examples
>>> request = gp.BatchRequest() >>> request[gp.ArrayKey("GT")] = gp.ArraySpec(roi=gp.Roi((0, 0, 0), (1, 1, 1))) >>> target_filter.process(batch, request)
- class dacapo.gp.GammaAugment(arrays, gamma_min, gamma_max)
Class for applying gamma noise augmentation.
- arrays
An iterable collection of np arrays to augment
- gamma_min
A float representing the lower limit of gamma perturbation
- gamma_max
A float representing the upper limit of gamma perturbation
- setup()
Method to configure the internal state of the class
- process()
Method to apply gamma noise to the desired arrays
- __augment()
Private method to perform the actual augmentation
- arrays
- gamma_min
- gamma_max
- setup()
Configuring the internal state by iterating over arrays.
- Raises:
AssertionError – If the array data type is not float32 or float64
Examples
>>> setup() setup()
- process(batch, request)
Method to apply gamma noise to the desired arrays.
- Parameters:
batch – The input batch to be processed.
request – An object which holds the requested output location.
- Returns:
The batch with the gamma noise applied.
- Raises:
AssertionError – If the array data type is not float32 or float64
Examples
>>> process(batch, request) process(batch, request)
- class dacapo.gp.ElasticAugment(control_point_spacing, control_point_displacement_sigma, rotation_interval, subsample=1, augmentation_probability=1.0, seed=None, uniform_3d_rotation=False)
Elasticly deform a batch. Requests larger batches upstream to avoid data loss due to rotation and jitter. :param control_point_spacing: Distance between control points for the elastic deformation, in voxels per dimension. :type control_point_spacing: tuple of int :param control_point_displacement_sigma: Standard deviation of control point displacement distribution, in world coordinates. :type control_point_displacement_sigma: tuple of float :param rotation_interval: Interval to randomly sample rotation angles from (0, 2PI). :type rotation_interval: tuple of two float :param subsample: Instead of creating an elastic transformation on the full resolution, create one sub-sampled by the given factor, and linearly interpolate to obtain the full resolution transformation. This can significantly speed up this node, at the expense of having visible piecewise linear deformations for large factors. Usually, a factor of 4 can safely be used without noticeable changes. However, the default is 1 (i.e., no sub-sampling). :type subsample: int :param seed: Set random state for reproducible results (tests only, do not use in production code!!) :type seed: int :param augmentation_probability: Probability to apply the augmentation. :type augmentation_probability: float :param uniform_3d_rotation: Use a uniform 3D rotation instead of a rotation around a random axis. :type uniform_3d_rotation: bool
- Provides:
The arrays in the batch, deformed.
- Requests:
The arrays in the batch, enlarged such that the deformed ROI fits into the enlarged input ROI.
- Method:
setup: Set up the ElasticAugment node. prepare: Prepare the ElasticAugment node. process: Process the ElasticAugment node.
Notes
This node is a port of the ElasticAugment node from the original `gunpowder <
- control_point_spacing
- control_point_displacement_sigma
- rotation_start
- rotation_max_amount
- subsample
- augmentation_probability
- uniform_3d_rotation
- do_augment = False
- transformations
- target_rois
- setup()
Set up the object by calculating the voxel size and spatial dimensions.
This method calculates the voxel size by finding the minimum value for each axis from the voxel sizes of all array specs. It then sets the voxel_size attribute of the object. The spatial dimensions are also set based on the dimensions of the voxel size.
- Raises:
AssertionError – If the voxel size is not a Coordinate object.
Examples
>>> setup()
- prepare(request)
Prepares the request for augmentation.
- Parameters:
request – The request object containing the data to be augmented.
- Raises:
AssertionError – If the key in the request is not an ArrayKey or GraphKey.
Examples
>>> prepare(request)
Notes
This method prepares the request for augmentation by performing the following steps: 1. Logs the preparation details, including the transformation voxel size. 2. Calculates the master ROI based on the total ROI. 3. Generates a uniform random sample and determines whether to perform augmentation based on the augmentation probability. 4. If augmentation is not required, logs the decision and returns. 5. Snaps the master ROI to the grid based on the voxel size and calculates the master transformation. 6. Clears the existing transformations and target ROIs. 7. Iterates over each key in the request and prepares it for augmentation. 8. Updates the upstream request with the modified ROI.
- process(batch, request)
Process the ElasticAugment node.
- Parameters:
batch – The batch object containing the data to be processed.
request – The request object specifying the data to be processed.
- Raises:
AssertionError – If the key in the request is not an ArrayKey or GraphKey.
Examples
>>> process(batch, request)
Notes
This method applies the transformation to the data in the batch and restores the original ROIs.
- class dacapo.gp.RejectIfEmpty(gt=None, p=0.5, background=0)
Reject batches based on the masked-in vs. masked-out ratio. .. attribute:: gt
The gt array to use
- type:
ArrayKey
, optional
- p
The probability that we reject until gt is nonempty
- Type:
float
, optional
- Method:
setup: Set up the provider. provide: Provide a batch.
- gt
- p
- background = 0
- setup()
Set up the provider.
- Raises:
AssertionError – If only 1 upstream provider is supported.
Examples
>>> setup() setup()
- provide(request)
Provides a batch of data, rejecting empty ground truth (gt) if requested.
- Parameters:
request – The request object containing the necessary information.
- Returns:
The batch of data.
- Raises:
AssertionError – If the requested gt is not present in the request.
Examples
>>> provide(request) provide(request)
- class dacapo.gp.CopyMask(array_key: gunpowder.ArrayKey, copy_key: gunpowder.ArrayKey, drop_channels: bool = False)
A class to copy a mask into a new key with the option to drop channels via max collapse.
- array_key
Original key of the array from where the mask will be copied.
- Type:
gp.ArrayKey
- copy_key
New key where the copied mask will reside.
- Type:
gp.ArrayKey
- drop_channels
If True, channels will be dropped via a max collapse.
- Type:
bool
- setup()
Sets up the filter by enabling autoskip and providing the copied key.
- prepare()
Prepares the filter by copying the request of copy_key into a dependency.
- process()
Processes the batch by copying the mask from the array_key to the copy_key.
Note
This class is a subclass of gunpowder.BatchFilter and is used to copy a mask into a new key with the option to drop channels via max collapse.
- array_key
- copy_key
- drop_channels
- setup()
Sets up the filter by enabling autoskip and providing the copied key.
- Raises:
RuntimeError – If the key is already provided.
Examples
>>> copy_mask.setup()
- prepare(request)
Prepares the filter by copying the request of copy_key into a dependency.
- Parameters:
request – The request to prepare.
- Returns:
The prepared dependencies.
- Return type:
deps
- Raises:
NotImplementedError – If the copy_key is not provided.
Examples
>>> request = gp.BatchRequest() >>> request[self.copy_key] = gp.ArraySpec(roi=gp.Roi((0, 0, 0), (1, 1, 1))) >>> copy_mask.prepare(request)
- process(batch, request)
Processes the batch by copying the mask from the array_key to the copy_key.
If “drop_channels” attribute is True, it performs max collapse.
- Parameters:
batch – The batch to process.
request – The request for processing.
- Returns:
The processed outputs.
- Return type:
outputs
- Raises:
KeyError – If the requested key is not in the request.
Examples
>>> request = gp.BatchRequest() >>> request[gp.ArrayKey("ARRAY")] = gp.ArraySpec(roi=gp.Roi((0, 0, 0), (1, 1, 1))) >>> copy_mask.process(batch, request)
- class dacapo.gp.GraphSource(key: gunpowder.GraphKey, graph: gunpowder.Graph)
A provider for serving graph data in gunpowder pipelines.
The Graph Source loads a single graph to serve to the pipeline based on ROI requests it receives.
- key
The key of the graph to be served.
- Type:
gp.GraphKey
- graph
The graph to be served.
- Type:
gp.Graph
- setup()
Set up the provider.
- provide(request)
Provides the graph for the requested ROI.
Note
This class is a subclass of gunpowder.BatchProvider and is used to serve graph data to gunpowder pipelines.
- key
- graph
- setup()
Set up the provider. This function sets the provider to provide the graph with the given key.
- Raises:
RuntimeError – If the key is already provided.
Examples
>>> graph_source.setup()
- provide(request)
Provides the graph for the requested ROI.
This method will be passively called by gunpowder to get a batch. Depending on the request we provide a subgraph of our data, or nothing at all.
- Parameters:
request (gp.BatchRequest) – BatchRequest with the same ROI for
graph. (each requested array and)
- Returns:
The graph contained in a Batch.
- Return type:
outputs (gp.Batch)
- Raises:
KeyError – If the requested key is not in the request.
Examples
>>> request = gp.BatchRequest() >>> request[gp.GraphKey("GRAPH")] = gp.GraphSpec(roi=gp.Roi((0, 0, 0), (1, 1, 1))) >>> graph_source.provide(request)
- class dacapo.gp.Product(x1_key: gunpowder.ArrayKey, x2_key: gunpowder.ArrayKey, y_key: gunpowder.ArrayKey)
A BatchFilter that multiplies two input arrays and produces an output array.
- x1_key
The key of the first input array.
- Type:
ArrayKey
- x2_key
The key of the second input array.
- Type:
ArrayKey
- y_key
The key of the output array.
- Type:
ArrayKey
- Provides:
y_key (gp.ArrayKey): The key of the output array.
- Method:
__init__: Initialize the Product BatchFilter. setup: Set up the Product BatchFilter. prepare: Prepare the Product BatchFilter. process: Process the Product BatchFilter.
- x1_key
- x2_key
- y_key
- setup()
Set up the Product BatchFilter.
Enables autoskip and specifies the output array.
- Raises:
AssertionError – If the input arrays are not provided.
Examples
>>> setup() setup()
- prepare(request)
Prepare the Product BatchFilter.
- Parameters:
request (gp.BatchRequest) – The batch request.
- Returns:
The dependencies.
- Return type:
gp.BatchRequest
- Raises:
AssertionError – If the input arrays are not provided.
Examples
>>> prepare(request) prepare(request)
- process(batch, request)
Process the Product BatchFilter.
- Parameters:
batch (gp.Batch) – The input batch.
request (gp.BatchRequest) – The batch request.
- Returns:
The output batch.
- Return type:
gp.Batch
- Raises:
AssertionError – If the input arrays are not provided.
Examples
>>> process(batch, request) process(batch, request)