Skip to content

Commit

Permalink
Merge branch 'main' into upsample
Browse files Browse the repository at this point in the history
  • Loading branch information
mzouink authored Jan 2, 2025
2 parents e7ca981 + 0b3e2d0 commit c09df8c
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ def array(self, mode="r") -> Array:
assert num_channels is None, "Input labels cannot have a channel dimension"

def group_array(data):
out = da.zeros((len(self.groupings), *array.physical_shape), dtype=np.uint8)
for i, (_, group_ids) in enumerate(self.groupings):
if len(group_ids) == 0:
out[i] = data != self.background
else:
out[i] = da.isin(data, group_ids)
groups = [
da.isin(data, group_ids)
if len(group_ids) > 0
else data != self.background
for _, group_ids in self.groupings
]
out = da.stack(groups, axis=0)
return out

data = group_array(array.data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from typing import List, Dict, Optional
from funlib.persistence import Array
import numpy as np
import dask.array as da


Expand Down Expand Up @@ -45,18 +44,15 @@ class ConcatArrayConfig(ArrayConfig):
def array(self, mode: str = "r") -> Array:
arrays = [config.array(mode) for _, config in self.source_array_configs.items()]

out_data = da.stack([array.data for array in arrays], axis=0)
out_array = Array(
da.zeros(len(arrays), *arrays[0].physical_shape, dtype=arrays[0].dtype),
out_data,
offset=arrays[0].offset,
voxel_size=arrays[0].voxel_size,
axis_names=["c^"] + arrays[0].axis_names,
units=arrays[0].units,
)

def set_channels(data):
for i, array in enumerate(arrays):
data[i] = array.data[:]
return data

out_array.lazy_op(set_channels)
# callable lazy op so funlib.persistence doesn't try to recoginize this data as writable
out_array.lazy_op(lambda data: data)
return out_array
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ def array(self, mode: str = "r") -> Array:
assert num_channels_from_array(array) is not None

out_array = Array(
da.zeros(*array.physical_shape, dtype=array.dtype),
da.zeros(array.physical_shape, dtype=array.dtype),
offset=array.offset,
voxel_size=array.voxel_size,
axis_names=array.axis_names[1:],
units=array.units,
)

out_array.data = da.maximum(array.data, axis=0)
out_array.data = da.max(array.data, axis=0)

# mark data as non-writable
out_array.lazy_op(lambda data: data)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from dacapo.experiments.arraytypes.probabilities import ProbabilityArray
from .predictor import Predictor
from dacapo.experiments import Model
from dacapo.experiments.arraytypes import DistanceArray
from dacapo.tmp import np_to_funlib_array
from dacapo.utils.balance_weights import balance_weights

Expand Down Expand Up @@ -394,6 +393,7 @@ def __find_boundaries(self, labels):
# bound.: 00000001000100000001000 2n - 1

logger.debug(f"computing boundaries for {labels.shape}")
labels = labels.astype(np.uint8)

dims = len(labels.shape)
in_shape = labels.shape
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ module = [
"napari.*",
"empanada.*",
"IPython.*",
"xarray_multiscale.*"
]
ignore_missing_imports = true

Expand Down
1 change: 0 additions & 1 deletion tests/components/test_gp_arraysource.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,5 @@ def test_gp_dacapo_array_source(array_config):
batch = source_node.request_batch(request)
data = batch[key].data
if data.dtype == bool:
raise ValueError("Data should not be bools")
data = data.astype(np.uint8)
assert (data - array[array.roi]).sum() == 0

0 comments on commit c09df8c

Please sign in to comment.