Skip to content
Snippets Groups Projects
Commit 18dc1a37 authored by Alán Muñoz's avatar Alán Muñoz
Browse files

fix(extraction): pass axis to div0 mergefun

parent 9609a53f
No related branches found
No related tags found
No related merge requests found
...@@ -546,7 +546,7 @@ class Extractor(ProcessABC): ...@@ -546,7 +546,7 @@ class Extractor(ProcessABC):
) )
) == len(chs): ) == len(chs):
channels_stack = np.stack( channels_stack = np.stack(
[self.get_imgs(ch, tiles, tree_chs) for ch in chs] [self.get_imgs(ch, tiles, tree_chs) for ch in chs], axis=-1
) )
merged = RED_FUNS[merge_fun](channels_stack, axis=-1) merged = RED_FUNS[merge_fun](channels_stack, axis=-1)
d[name] = self.reduce_extract( d[name] = self.reduce_extract(
......
import numpy as np import numpy as np
def div0(a, b, fill=0): def div0(array, fill=0, axis=-1):
""" """
Divide array a by array b. Divide array a by array b.
...@@ -13,9 +13,19 @@ def div0(a, b, fill=0): ...@@ -13,9 +13,19 @@ def div0(a, b, fill=0):
---------- ----------
a: array a: array
b: array b: array
fill: float
**kwargs: kwargs
""" """
assert array.shape[axis] == 2, f"Array has the wrong shape in axis {axis}"
slices_0, slices_1 = [[slice(None)] * len(array.shape)] * 2
slices_0[axis] = 0
slices_1[axis] = 1
with np.errstate(divide="ignore", invalid="ignore"): with np.errstate(divide="ignore", invalid="ignore"):
c = np.true_divide(a, b) c = np.true_divide(
array[tuple(slices_0)],
array[tuple(slices_1)],
)
if np.isscalar(c): if np.isscalar(c):
return c if np.isfinite(c) else fill return c if np.isfinite(c) else fill
else: else:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment