Skip to content
Snippets Groups Projects
Commit 35faa62c authored by Christopher Randolph Rhodes's avatar Christopher Randolph Rhodes
Browse files

Stable tests

parent 075aea6f
No related branches found
No related tags found
No related merge requests found
...@@ -55,7 +55,7 @@ def write_patch_to_file(where, fname, yxcz): ...@@ -55,7 +55,7 @@ def write_patch_to_file(where, fname, yxcz):
else: else:
raise Exception(f'Unsupported file extension: {ext}') raise Exception(f'Unsupported file extension: {ext}')
def get_patches_from_zmask_meta( def get_patches_from_zmask_meta(
stack: GenericImageDataAccessor, stack: GenericImageDataAccessor,
......
...@@ -72,7 +72,7 @@ class TestZStackDerivedDataProducts(unittest.TestCase): ...@@ -72,7 +72,7 @@ class TestZStackDerivedDataProducts(unittest.TestCase):
self.assertEqual(interm['label_map'].shape, zmask.shape[0:2]) self.assertEqual(interm['label_map'].shape, zmask.shape[0:2])
self.assertEqual(interm['argmax'].shape, zmask.shape[0:2]) self.assertEqual(interm['argmax'].shape, zmask.shape[0:2])
return zmask, meta return roiset
def test_zmask_works_on_non_zstacks(self, **kwargs): def test_zmask_works_on_non_zstacks(self, **kwargs):
acc_zstack_slice = InMemoryDataAccessor(self.stack_ch_pa.data[:, :, :, 0]) acc_zstack_slice = InMemoryDataAccessor(self.stack_ch_pa.data[:, :, :, 0])
...@@ -95,27 +95,27 @@ class TestZStackDerivedDataProducts(unittest.TestCase): ...@@ -95,27 +95,27 @@ class TestZStackDerivedDataProducts(unittest.TestCase):
return self.test_zmask_makes_correct_boxes(expand_box_by=(64, 2)) return self.test_zmask_makes_correct_boxes(expand_box_by=(64, 2))
def test_make_2d_patches_from_zmask(self): def test_make_2d_patches_from_zmask(self):
zmask, meta = self.test_zmask_makes_correct_boxes( roiset = self.test_zmask_makes_correct_boxes(
filters={'area': {'min': 1e3, 'max': 1e4}}, filters={'area': {'min': 1e3, 'max': 1e4}},
expand_box_by=(64, 2) expand_box_by=(64, 2)
) )
files = export_patches_from_zstack( files = export_patches_from_zstack(
output_path / '2d_patches', output_path / '2d_patches',
self.stack_ch_pa, self.stack_ch_pa,
meta, roiset.zmask_meta,
draw_bounding_box=True, draw_bounding_box=True,
) )
self.assertGreaterEqual(len(files), 1) self.assertGreaterEqual(len(files), 1)
def test_make_3d_patches_from_zmask(self): def test_make_3d_patches_from_zmask(self):
zmask, meta = self.test_zmask_makes_correct_boxes( roiset = self.test_zmask_makes_correct_boxes(
filters={'area': {'min': 1e3, 'max': 1e4}}, filters={'area': {'min': 1e3, 'max': 1e4}},
expand_box_by=(64, 2), expand_box_by=(64, 2),
) )
files = export_patches_from_zstack( files = export_patches_from_zstack(
output_path / '3d_patches', output_path / '3d_patches',
self.stack_ch_pa, self.stack_ch_pa,
meta, roiset.zmask_meta,
make_3d=True) make_3d=True)
self.assertGreaterEqual(len(files), 1) self.assertGreaterEqual(len(files), 1)
...@@ -145,14 +145,14 @@ class TestZStackDerivedDataProducts(unittest.TestCase): ...@@ -145,14 +145,14 @@ class TestZStackDerivedDataProducts(unittest.TestCase):
) )
def test_make_multichannel_2d_patches_from_zmask(self): def test_make_multichannel_2d_patches_from_zmask(self):
zmask, meta = self.test_zmask_makes_correct_boxes( roiset = self.test_zmask_makes_correct_boxes(
filters={'area': {'min': 1e3, 'max': 1e4}}, filters={'area': {'min': 1e3, 'max': 1e4}},
expand_box_by=(128, 2) expand_box_by=(128, 2)
) )
files = export_multichannel_patches_from_zstack( files = export_multichannel_patches_from_zstack(
output_path / '2d_patches_chlorophyl_bbox_overlay', output_path / '2d_patches_chlorophyl_bbox_overlay',
InMemoryDataAccessor(self.stack.data), InMemoryDataAccessor(self.stack.data),
meta, roiset.zmask_meta,
ch_white=4, ch_white=4,
draw_bounding_box=True, draw_bounding_box=True,
bounding_box_channel=1, bounding_box_channel=1,
...@@ -160,14 +160,14 @@ class TestZStackDerivedDataProducts(unittest.TestCase): ...@@ -160,14 +160,14 @@ class TestZStackDerivedDataProducts(unittest.TestCase):
self.assertGreaterEqual(len(files), 1) self.assertGreaterEqual(len(files), 1)
def test_make_multichannel_2d_patches_with_mask_overlay(self): def test_make_multichannel_2d_patches_with_mask_overlay(self):
zmask, meta = self.test_zmask_makes_correct_boxes( roiset = self.test_zmask_makes_correct_boxes(
filters={'area': {'min': 1e3, 'max': 1e4}}, filters={'area': {'min': 1e3, 'max': 1e4}},
expand_box_by=(128, 2) expand_box_by=(128, 2)
) )
files = export_multichannel_patches_from_zstack( files = export_multichannel_patches_from_zstack(
output_path / '2d_patches_chlorophyl_mask_overlay', output_path / '2d_patches_chlorophyl_mask_overlay',
InMemoryDataAccessor(self.stack.data), InMemoryDataAccessor(self.stack.data),
meta, roiset.zmask_meta,
ch_white=4, ch_white=4,
ch_rgb_overlay=(3, None, None), ch_rgb_overlay=(3, None, None),
draw_mask=True, draw_mask=True,
...@@ -177,14 +177,14 @@ class TestZStackDerivedDataProducts(unittest.TestCase): ...@@ -177,14 +177,14 @@ class TestZStackDerivedDataProducts(unittest.TestCase):
self.assertGreaterEqual(len(files), 1) self.assertGreaterEqual(len(files), 1)
def test_make_multichannel_2d_patches_with_contour_overlay(self): def test_make_multichannel_2d_patches_with_contour_overlay(self):
zmask, meta = self.test_zmask_makes_correct_boxes( roiset = self.test_zmask_makes_correct_boxes(
filters={'area': {'min': 1e3, 'max': 1e4}}, filters={'area': {'min': 1e3, 'max': 1e4}},
expand_box_by=(128, 2) expand_box_by=(128, 2)
) )
files = export_multichannel_patches_from_zstack( files = export_multichannel_patches_from_zstack(
output_path / '2d_patches_chlorophyl_contour_overlay', output_path / '2d_patches_chlorophyl_contour_overlay',
InMemoryDataAccessor(self.stack.data), InMemoryDataAccessor(self.stack.data),
meta, roiset.zmask_meta,
ch_white=4, ch_white=4,
ch_rgb_overlay=(3, None, None), ch_rgb_overlay=(3, None, None),
draw_contour=True, draw_contour=True,
...@@ -194,17 +194,13 @@ class TestZStackDerivedDataProducts(unittest.TestCase): ...@@ -194,17 +194,13 @@ class TestZStackDerivedDataProducts(unittest.TestCase):
self.assertGreaterEqual(len(files), 1) self.assertGreaterEqual(len(files), 1)
# TODO: rewrite with direct call to RoiSet methods # TODO: rewrite with direct call to RoiSet methods
# def test_make_binary_masks_from_zmask(self): def test_make_binary_masks_from_zmask(self):
# zmask, meta = self.test_zmask_makes_correct_boxes( roiset = self.test_zmask_makes_correct_boxes(
# filters={'area': {'min': 1e3, 'max': 1e4}}, filters={'area': {'min': 1e3, 'max': 1e4}},
# expand_box_by=(128, 2) expand_box_by=(128, 2)
# ) )
# files = export_patch_masks_from_zstack( files = roiset.export_patch_masks_from_zstack(output_path / '2d_mask_patches', )
# output_path / '2d_mask_patches', self.assertGreaterEqual(len(files), 1)
# InMemoryDataAccessor(self.stack.data),
# meta,
# )
# self.assertGreaterEqual(len(files), 1)
def test_object_map_workflow(self): def test_object_map_workflow(self):
pp = pipeline_params pp = pipeline_params
......
from uuid import uuid4 from uuid import uuid4
from math import floor
import numpy as np import numpy as np
import pandas as pd import pandas as pd
from pathlib import Path from pathlib import Path
...@@ -11,7 +12,7 @@ from sklearn.linear_model import LinearRegression ...@@ -11,7 +12,7 @@ from sklearn.linear_model import LinearRegression
from model_server.base.accessors import GenericImageDataAccessor, InMemoryDataAccessor, write_accessor_data_to_file from model_server.base.accessors import GenericImageDataAccessor, InMemoryDataAccessor, write_accessor_data_to_file
from model_server.base.models import InstanceSegmentationModel from model_server.base.models import InstanceSegmentationModel
from model_server.base.process import pad from model_server.base.process import pad, rescale, resample_to_8bit
from model_server.extensions.chaeo.annotators import draw_boxes_on_3d_image from model_server.extensions.chaeo.annotators import draw_boxes_on_3d_image
from model_server.extensions.chaeo.products import export_patches_from_zstack, export_multichannel_patches_from_zstack from model_server.extensions.chaeo.products import export_patches_from_zstack, export_multichannel_patches_from_zstack
...@@ -43,10 +44,8 @@ class RoiSet(object): ...@@ -43,10 +44,8 @@ class RoiSet(object):
self.object_id_labels = self.interm['label_map'] self.object_id_labels = self.interm['label_map']
self.object_class_map = None self.object_class_map = None
def get_argmax(self):
return self.interm.argmax
def get_multichannel_projection(self): def get_multichannel_projection(self): # TODO: document and test
dff = self.df[self.df['keeper']] dff = self.df[self.df['keeper']]
if self.count: if self.count:
projected = project_stack_from_focal_points( projected = project_stack_from_focal_points(
...@@ -100,7 +99,7 @@ class RoiSet(object): ...@@ -100,7 +99,7 @@ class RoiSet(object):
def get_zmask(self): # TODO: on-the-fly generation of zmask array def get_zmask(self): # TODO: on-the-fly generation of zmask array
return self.zmask return self.zmask
def export_patch_masks_from_zstack(self, where: Path, pad_to: int = 256, prefix='mask'): def export_patch_masks_from_zstack(self, where: Path, pad_to: int = 256, prefix='mask') -> List:
patches_acc = self.get_patch_masks(pad_to=pad_to) patches_acc = self.get_patch_masks(pad_to=pad_to)
exported = [] exported = []
......
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