Skip to content

Commit

Permalink
Format Python code with psf/black push (#161)
Browse files Browse the repository at this point in the history
There appear to be some python formatting errors in
5d604cf. This pull request
uses the [psf/black](https://github.com/psf/black) formatter to fix
these issues.
  • Loading branch information
mzouink authored Mar 13, 2024
2 parents 18d8a51 + 161dfed commit 8f672ec
Show file tree
Hide file tree
Showing 42 changed files with 191 additions and 152 deletions.
9 changes: 5 additions & 4 deletions dacapo/compute_context/local_torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@

from typing import Optional


@attr.s
class LocalTorch(ComputeContext):
"""
The LocalTorch class is a subclass of the ComputeContext class.
The LocalTorch class is a subclass of the ComputeContext class.
It is used to specify the context in which computations are to be done.
LocalTorch is used to specify that computations are to be done on the local machine using PyTorch.
Attributes:
_device (Optional[str]): This stores the type of device on which torch computations are to be done. It can
_device (Optional[str]): This stores the type of device on which torch computations are to be done. It can
take "cuda" for GPU or "cpu" for CPU. None value results in automatic detection of device type.
"""

Expand All @@ -27,7 +28,7 @@ class LocalTorch(ComputeContext):
@property
def device(self):
"""
A property method that returns the torch device object. It automatically detects and uses "cuda" (GPU) if
A property method that returns the torch device object. It automatically detects and uses "cuda" (GPU) if
available, else it falls back on using "cpu".
"""
if self._device is None:
Expand Down
9 changes: 5 additions & 4 deletions dacapo/experiments/architectures/architecture.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

class Architecture(torch.nn.Module, ABC):
"""
An abstract base class for defining the architecture of a neural network model.
An abstract base class for defining the architecture of a neural network model.
It is inherited from PyTorch's Module and built-in class `ABC` (Abstract Base Classes).
Other classes can inherit this class to define their own specific variations of architecture.
It requires to implement several property methods, and also includes additional methods related to the architecture design.
"""

@property
@abstractmethod
def input_shape(self) -> Coordinate:
Expand Down Expand Up @@ -60,9 +61,9 @@ def num_out_channels(self) -> int:
def dims(self) -> int:
"""
Returns the number of dimensions of the input shape.
Returns:
int: The number of dimensions.
int: The number of dimensions.
"""
return self.input_shape.dims

Expand All @@ -76,4 +77,4 @@ def scale(self, input_voxel_size: Coordinate) -> Coordinate:
Returns:
Coordinate: The scaled voxel size.
"""
return input_voxel_size
return input_voxel_size
3 changes: 2 additions & 1 deletion dacapo/experiments/architectures/architecture_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ArchitectureConfig:
validates the given architecture.
"""

name: str = attr.ib(
metadata={
"help_text": "A unique name for this architecture. This will be saved so "
Expand All @@ -37,4 +38,4 @@ def verify(self) -> Tuple[bool, str]:
str
A description of the architecture.
"""
return True, "No validation for this Architecture"
return True, "No validation for this Architecture"
18 changes: 9 additions & 9 deletions dacapo/experiments/architectures/dummy_architecture.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

class DummyArchitecture(Architecture):
"""
A class used to represent a dummy architecture layer for a 3D CNN.
A class used to represent a dummy architecture layer for a 3D CNN.
Attributes:
channels_in: An integer representing the number of input channels.
channels_out: An integer representing the number of output channels.
conv: A 3D convolution object.
input_shape: A coordinate object representing the shape of the input.
Methods:
forward(x): Performs the forward pass of the network.
"""
Expand All @@ -33,7 +33,7 @@ def __init__(self, architecture_config):
def input_shape(self):
"""
Returns the input shape for this architecture.
Returns:
Coordinate: Input shape of the architecture.
"""
Expand All @@ -43,7 +43,7 @@ def input_shape(self):
def num_in_channels(self):
"""
Returns the number of input channels for this architecture.
Returns:
int: Number of input channels.
"""
Expand All @@ -53,7 +53,7 @@ def num_in_channels(self):
def num_out_channels(self):
"""
Returns the number of output channels for this architecture.
Returns:
int: Number of output channels.
"""
Expand All @@ -62,11 +62,11 @@ def num_out_channels(self):
def forward(self, x):
"""
Perform the forward pass of the network.
Args:
x: Input tensor.
Returns:
Tensor: Output tensor after the forward pass.
"""
return self.conv(x)
return self.conv(x)
8 changes: 4 additions & 4 deletions dacapo/experiments/architectures/dummy_architecture_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
@attr.s
class DummyArchitectureConfig(ArchitectureConfig):
"""A dummy architecture configuration class used for testing purposes.
It extends the base class "ArchitectureConfig". This class contains dummy attributes and always
returns that the configuration is invalid when verified.
Attributes:
architecture_type (:obj:`DummyArchitecture`): A class attribute assigning
architecture_type (:obj:`DummyArchitecture`): A class attribute assigning
the DummyArchitecture class to this configuration.
num_in_channels (int): The number of input channels. This is a dummy attribute and has no real
functionality or meaning.
Expand All @@ -37,5 +37,5 @@ def verify(self) -> Tuple[bool, str]:
Returns:
tuple: A tuple containing a boolean validity flag and a reason message string.
"""
return False, "This is a DummyArchitectureConfig and is never valid"

return False, "This is a DummyArchitectureConfig and is never valid"
4 changes: 2 additions & 2 deletions dacapo/experiments/arraytypes/arraytype.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ class ArrayType(ABC):
@abstractmethod
def interpolatable(self) -> bool:
"""
This is an abstract method which should be overridden in each of the subclasses
This is an abstract method which should be overridden in each of the subclasses
to determine if an array is interpolatable or not.
Returns:
bool: True if the array is interpolatable, False otherwise.
"""
pass
pass
4 changes: 2 additions & 2 deletions dacapo/experiments/arraytypes/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class BinaryArray(ArrayType):
def interpolatable(self) -> bool:
"""
This function returns the interpolatable property value of the binary array.
Returns:
bool: Always returns False because interpolation is not possible.
"""
return False
return False
6 changes: 4 additions & 2 deletions dacapo/experiments/arraytypes/mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@

import attr


@attr.s
class Mask(ArrayType):
"""
A class that inherits the ArrayType class. This is a representation of a Mask in the system.
Methods
-------
interpolatable():
It is a method that returns False.
"""

@property
def interpolatable(self) -> bool:
"""
Expand All @@ -22,4 +24,4 @@ def interpolatable(self) -> bool:
bool
Returns a boolean value of False representing that the values are not interpolatable.
"""
return False
return False
8 changes: 4 additions & 4 deletions dacapo/experiments/arraytypes/probabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
@attr.s
class ProbabilityArray(ArrayType):
"""
Class to represent an array containing probability distributions for each voxel pointed by its coordinate.
Class to represent an array containing probability distributions for each voxel pointed by its coordinate.
The class defines a ProbabilityArray object with each voxel having a vector of length `c`, where `c` is the
The class defines a ProbabilityArray object with each voxel having a vector of length `c`, where `c` is the
number of classes. The l1 norm of this vector should always be 1. The class of each voxel can be
determined by simply taking the argmax.
determined by simply taking the argmax.
Attributes:
classes (List[str]): A mapping from channel to class on which distances were calculated.
Expand All @@ -30,4 +30,4 @@ def interpolatable(self) -> bool:
Returns:
bool: True indicating that the data can be interpolated.
"""
return True
return True
9 changes: 5 additions & 4 deletions dacapo/experiments/datasplits/datasets/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from abc import ABC
from typing import Optional, Any, List


class Dataset(ABC):
"""
A class to represent a dataset.
Expand All @@ -15,7 +16,7 @@ class Dataset(ABC):
weight (int, optional): The weight of the dataset.
sample_points (list[Coordinate], optional): The list of sample points in the dataset.
"""

name: str
raw: Array
gt: Optional[Array]
Expand Down Expand Up @@ -49,7 +50,7 @@ def __repr__(self) -> str:
Returns the official string representation of the dataset object.
Returns:
str: String representation of the dataset.
str: String representation of the dataset.
"""
return f"Dataset({self.name})"

Expand All @@ -58,7 +59,7 @@ def __str__(self) -> str:
Returns the string representation of the dataset object.
Returns:
str: String representation of the dataset.
str: String representation of the dataset.
"""
return f"Dataset({self.name})"

Expand Down Expand Up @@ -93,4 +94,4 @@ def _neuroglancer_layers(self, prefix="", exclude_layers=None):
and self.mask._source_name() not in exclude_layers
):
layers[self.mask._source_name()] = self.mask._neuroglancer_layer()
return layers
return layers
26 changes: 13 additions & 13 deletions dacapo/experiments/datasplits/datasets/dataset_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@

@attr.s
class DatasetConfig:
"""A class used to define configuration for datasets. This provides the
"""A class used to define configuration for datasets. This provides the
framework to create a Dataset instance.
Attributes:
name: str (eg: "sample_dataset").
A unique identifier to name the dataset.
It aids in easy identification and reusability of this dataset.
A unique identifier to name the dataset.
It aids in easy identification and reusability of this dataset.
Advised to keep it short and refrain from using special characters.
weight: int (default=1).
A numeric value that indicates how frequently this dataset should be
sampled in comparison to others. Higher the weight, more frequently it
A numeric value that indicates how frequently this dataset should be
sampled in comparison to others. Higher the weight, more frequently it
gets sampled.
Methods:
verify:
Checks and validates the dataset configuration. The specific rules for
verify:
Checks and validates the dataset configuration. The specific rules for
validation need to be defined by the user.
"""

name: str = attr.ib(
metadata={
"help_text": "A unique name for this dataset. This will be saved so you "
Expand All @@ -44,12 +44,12 @@ def verify(self) -> Tuple[bool, str]:
"""
Method to verify the dataset configuration.
Since there is no specific validation logic defined for this DataSet, this
method will always return True as default reaction and a message stating
Since there is no specific validation logic defined for this DataSet, this
method will always return True as default reaction and a message stating
the lack of validation.
Returns:
tuple: A tuple of boolean value indicating the check (True or False) and
tuple: A tuple of boolean value indicating the check (True or False) and
message specifying result of validation.
"""
return True, "No validation for this DataSet"
return True, "No validation for this DataSet"
5 changes: 3 additions & 2 deletions dacapo/experiments/datasplits/datasets/dummy_dataset.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from .dataset import Dataset
from .arrays import Array


class DummyDataset(Dataset):
"""DummyDataset is a child class of the Dataset. This class has property 'raw' of Array type and a name.
Args:
dataset_config (object): an instance of a configuration class.
"""

raw: Array

def __init__(self, dataset_config):
Expand All @@ -19,4 +20,4 @@ def __init__(self, dataset_config):
"""
super().__init__()
self.name = dataset_config.name
self.raw = dataset_config.raw_config.array_type(dataset_config.raw_config)
self.raw = dataset_config.raw_config.array_type(dataset_config.raw_config)
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ def verify(self) -> Tuple[bool, str]:
Returns:
A tuple of False and a message indicating the invalidity.
"""

return False, "This is a DummyDatasetConfig and is never valid"
13 changes: 7 additions & 6 deletions dacapo/experiments/datasplits/datasets/raw_gt_dataset_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ class RawGTDatasetConfig(DatasetConfig):
will be extracted.
Attributes:
dataset_type (class): The type of dataset that is being configured.
raw_config (Optional[ArrayConfig]): Configuration for the raw data associated with this dataset.
gt_config (Optional[ArrayConfig]): Configuration for the ground truth data associated with this dataset.
mask_config (Optional[ArrayConfig]): An optional mask configuration that sets the loss
dataset_type (class): The type of dataset that is being configured.
raw_config (Optional[ArrayConfig]): Configuration for the raw data associated with this dataset.
gt_config (Optional[ArrayConfig]): Configuration for the ground truth data associated with this dataset.
mask_config (Optional[ArrayConfig]): An optional mask configuration that sets the loss
equal to zero on voxels where the mask is 1.
sample_points (Optional[List[Coordinate]]): An optional list of points around which
sample_points (Optional[List[Coordinate]]): An optional list of points around which
training samples will be extracted.
"""

dataset_type = RawGTDataset

raw_config: Optional[ArrayConfig] = attr.ib(
Expand All @@ -53,4 +54,4 @@ class RawGTDatasetConfig(DatasetConfig):
"help_text": "An optional list of points around which training samples will be "
"extracted."
},
)
)
Loading

0 comments on commit 8f672ec

Please sign in to comment.