Skip to content

Commit

Permalink
fix mypy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
pattonw committed Nov 5, 2024
1 parent 41cf3a9 commit 215d8b4
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 23 deletions.
1 change: 1 addition & 0 deletions dacapo/blockwise/argmax_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from dacapo.store.array_store import LocalArrayIdentifier
from dacapo.compute_context import create_compute_context
from dacapo.tmp import open_from_identifier

import daisy

Expand Down
1 change: 1 addition & 0 deletions dacapo/blockwise/segment_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import numpy as np
import yaml
from dacapo.compute_context import create_compute_context
from dacapo.tmp import open_from_identifier


from dacapo.store.array_store import LocalArrayIdentifier
Expand Down
1 change: 1 addition & 0 deletions dacapo/blockwise/threshold_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from dacapo.store.array_store import LocalArrayIdentifier
from dacapo.compute_context import create_compute_context
from dacapo.tmp import open_from_identifier

import daisy

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ConcatArrayConfig(ArrayConfig):
)

def array(self, mode: str = "r") -> Array:
arrays = [config.array(mode) for _, config in self.source_array_configs]
arrays = [config.array(mode) for _, config in self.source_array_configs.items()]

out_array = Array(
da.zeros(len(arrays), *arrays[0].physical_shape, dtype=arrays[0].dtype),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class CropArrayConfig(ArrayConfig):

def array(self, mode: str = "r") -> Array:
source_array = self.source_array_config.array(mode)
roi_slices = source_array._Array__slices(self.roi)
roi_slices = getattr(source_array, "_Array__slices")(self.roi)
out_array = Array(
source_array.data[roi_slices],
self.roi.offset,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def array(self, mode: str = "r") -> Array:
# To handle this case we would need to subclass `funlib.persistence.Array` to
# directly read from DVID
raise NotImplementedError("NotImplemented")
"""
from dacapo.ext import NoSuchModule
try:
Expand All @@ -47,6 +48,7 @@ def array(self, mode: str = "r") -> Array:
)
dtype = np.dtype(self.attrs["Extended"]["Values"][0]["DataType"])
raise NotImplementedError
"""

def verify(self) -> Tuple[bool, str]:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ class MissingAnnotationsMaskConfig(ArrayConfig):

def array(self, mode: str = "r") -> Array:
labels = self.source_array_config.array(mode)
grouped = da.ones((len(self._groupings), *labels.shape), dtype=bool)
grouped[:] = labels > 0
labels_list = LabelList.parse_obj({"labels": self.attrs["labels"]}).labels
grouped = da.ones((len(self.groupings), *labels.shape), dtype=bool)
grouped[:] = labels.data > 0
labels_list = LabelList.parse_obj({"labels": labels._source_data.attrs["labels"]}).labels
present_not_annotated = set(
[
label.value
for label in labels_list
if label.annotationState.present and not label.annotationState.annotated
]
)
for i, (_, ids) in enumerate(self._groupings):
for i, (_, ids) in enumerate(self.groupings):
if any([id in present_not_annotated for id in ids]):
grouped[i] = 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class TiffArrayConfig(ArrayConfig):
def array(self, mode: str = "r") -> Array:

return Array(
data=tifffile.TiffFile(self._file_name).values,
data=tifffile.TiffFile(self.file_name).values,
offset=self.offset,
voxel_size=self.voxel_size,
axis_names=self.axis_names,
Expand Down
1 change: 1 addition & 0 deletions dacapo/experiments/datasplits/datasplit_generator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from dacapo.experiments.tasks import TaskConfig
from dacapo.experiments.datasplits.datasets.arrays import ArrayConfig
from upath import UPath as Path
from typing import List, Union, Optional, Sequence
from enum import Enum, EnumMeta
Expand Down
4 changes: 2 additions & 2 deletions dacapo/experiments/tasks/evaluators/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
from typing import Tuple, Dict, Optional, List, TYPE_CHECKING, Union
import math
import itertools
from funlib.persistence import Array

if TYPE_CHECKING:
from dacapo.experiments.tasks.evaluators.evaluation_scores import EvaluationScores
from dacapo.experiments.datasplits.datasets import Dataset
from dacapo.experiments.datasplits.datasets.arrays import Array
from dacapo.store.local_array_store import LocalArrayIdentifier
from dacapo.experiments.tasks.post_processors import PostProcessorParameters
from dacapo.experiments.validation_scores import ValidationScores
Expand Down Expand Up @@ -57,7 +57,7 @@ class Evaluator(ABC):

@abstractmethod
def evaluate(
self, output_array_identifier: "LocalArrayIdentifier", evaluation_array: "Array"
self, output_array_identifier: "LocalArrayIdentifier", evaluation_array: Array
) -> "EvaluationScores":
"""
Compares and evaluates the output array against the evaluation array.
Expand Down
4 changes: 2 additions & 2 deletions dacapo/experiments/tasks/post_processors/post_processor.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from abc import ABC, abstractmethod
from funlib.geometry import Coordinate
from funlib.persistence import Array

from typing import Iterable, TYPE_CHECKING

if TYPE_CHECKING:
from dacapo.experiments.tasks.post_processors.post_processor_parameters import (
PostProcessorParameters,
)
from dacapo.experiments.datasplits.datasets.arrays import Array
from dacapo.store.local_array_store import LocalArrayIdentifier


Expand Down Expand Up @@ -86,7 +86,7 @@ def process(
output_array_identifier: "LocalArrayIdentifier",
num_workers: int = 16,
chunk_size: Coordinate = Coordinate((64, 64, 64)),
) -> "Array":
) -> Array:
"""
Convert predictions into the final output.
Expand Down
16 changes: 8 additions & 8 deletions dacapo/experiments/tasks/predictors/predictor.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from funlib.geometry import Coordinate
from funlib.persistence import Array

from abc import ABC, abstractmethod
from typing import TYPE_CHECKING, Any, Tuple

if TYPE_CHECKING:
from dacapo.experiments.architectures.architecture import Architecture
from dacapo.experiments.model import Model
from dacapo.experiments.datasplits.datasets.arrays import Array


class Predictor(ABC):
Expand All @@ -19,8 +19,8 @@ class Predictor(ABC):
Methods:
create_model(self, architecture: "Architecture") -> "Model": Given a training architecture, create a model for this predictor.
create_target(self, gt: "Array") -> "Array": Create the target array for training, given a ground-truth array.
create_weight(self, gt: "Array", target: "Array", mask: "Array", moving_class_counts: Any) -> Tuple["Array", Any]: Create the weight array for training, given a ground-truth and associated target array.
create_target(self, gt: Array) -> Array: Create the target array for training, given a ground-truth array.
create_weight(self, gt: Array, target: Array, mask: Array, moving_class_counts: Any) -> Tuple[Array, Any]: Create the weight array for training, given a ground-truth and associated target array.
gt_region_for_roi(self, target_spec): Report how much spatial context this predictor needs to generate a target for the given ROI.
padding(self, gt_voxel_size: Coordinate) -> Coordinate: Return the padding needed for the ground-truth array.
Notes:
Expand Down Expand Up @@ -48,7 +48,7 @@ def create_model(self, architecture: "Architecture") -> "Model":
pass

@abstractmethod
def create_target(self, gt: "Array") -> "Array":
def create_target(self, gt: Array) -> Array:
"""
Create the target array for training, given a ground-truth array.
Expand Down Expand Up @@ -83,11 +83,11 @@ def create_target(self, gt: "Array") -> "Array":
@abstractmethod
def create_weight(
self,
gt: "Array",
target: "Array",
mask: "Array",
gt: Array,
target: Array,
mask: Array,
moving_class_counts: Any,
) -> Tuple["Array", Any]:
) -> Tuple[Array, Any]:
"""
Create the weight array for training, given a ground-truth and
associated target array.
Expand Down
7 changes: 6 additions & 1 deletion dacapo/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,15 @@ def predict(
axis_names = ["c^"] + raw_array.axis_names
else:
axis_names = raw_array.axis_names

if isinstance(output_roi, Roi):
out_roi: Roi = output_roi
else:
raise ValueError("out_roi must be a roi")
create_from_identifier(
output_array_identifier,
axis_names,
output_roi,
out_roi,
num_out_channels,
output_voxel_size,
output_dtype,
Expand Down
6 changes: 3 additions & 3 deletions dacapo/tmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,16 @@ def create_from_identifier(
if not out_path.parent.exists():
out_path.parent.mkdir(parents=True)

num_channels = [num_channels] if num_channels is not None else []
list_num_channels = [num_channels] if num_channels is not None else []
return prepare_ds(
out_path,
shape=(*num_channels, *roi.shape / voxel_size),
shape=(*list_num_channels, *roi.shape / voxel_size),
offset=roi.offset / voxel_size,
voxel_size=voxel_size,
axis_names=axis_names,
dtype=dtype,
chunk_shape=(
(*num_channels, *write_size / voxel_size)
(*list_num_channels, *write_size / voxel_size)
if write_size is not None
else None
),
Expand Down

0 comments on commit 215d8b4

Please sign in to comment.