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

Working on JSON dump of run data

parent f84c6411
No related branches found
No related tags found
No related merge requests found
import json
from pathlib import Path
import re
from time import localtime, strftime
......@@ -41,18 +42,33 @@ if __name__ == '__main__':
continue
result = export_patches_from_multichannel_zstack(
input_zstack_path=where_czi/ff,
px_model=px_model,
pxmap_threshold=0.25,
pixel_class=0,
zmask_channel=0,
patches_channel=4,
where_output=where_output,
mask_type='boxes',
zmask_filters={'area': (1e3, 1e8)},
zmask_expand_box_by=(128, 0),
)
export_kwargs = {
'input_zstack_path': (where_czi / ff).__str__(),
'px_model': px_model.model_id,
'pxmap_threshold': 0.25,
'pixel_class': 0,
'zmask_channel': 0,
'patches_channel': 4,
'where_output': where_output.__str__(),
'mask_type': 'boxes',
'zmask_filters': {'area': (1e3, 1e8)},
'zmask_expand_box_by': (128, 0),
}
# result = export_patches_from_multichannel_zstack(
# input_zstack_path=where_czi / ff,
# px_model=px_model,
# pxmap_threshold=0.25,
# pixel_class=0,
# zmask_channel=0,
# patches_channel=4,
# where_output=where_output,
# mask_type='boxes',
# zmask_filters={'area': (1e3, 1e8)},
# zmask_expand_box_by=(128, 0),
# )
result = export_patches_from_multichannel_zstack(**export_kwargs)
# parse and record results
df = result['dataframe']
......@@ -66,4 +82,5 @@ if __name__ == '__main__':
write_accessor_data_to_file(
where_output / k / (ff.stem + '.tif'),
InMemoryDataAccessor(result['interm'][k])
)
\ No newline at end of file
)
......@@ -12,21 +12,21 @@ from model_server.accessors import generate_file_accessor, InMemoryDataAccessor,
from model_server.workflows import Timer
def export_patches_from_multichannel_zstack(
input_zstack_path: Path,
px_model: IlastikPixelClassifierModel,
input_zstack_path: str,
px_model_id: str,
pxmap_threshold: float,
pixel_class: int,
zmask_channel: int,
patches_channel: int,
where_output: Path,
where_output: str,
mask_type: str = 'boxes',
zmask_filters: Dict = None,
zmask_expand_box_by: int = None,
) -> Dict:
ti = Timer()
stack = generate_file_accessor(input_zstack_path)
fstem = input_zstack_path.stem
stack = generate_file_accessor(Path(input_zstack_path))
fstem = Path(input_zstack_path).stem
ti.click('file_input')
assert stack.nz > 1, 'Expecting z-stack'
......@@ -34,11 +34,12 @@ def export_patches_from_multichannel_zstack(
mip = InMemoryDataAccessor(
stack.get_one_channel_data(channel=0).data.max(axis=-1, keepdims=True)
)
# px_model =
pxmap, _ = px_model.infer(mip)
ti.click('infer_pixel_probability')
write_accessor_data_to_file(
where_output / 'pixel_probabilities' / (fstem + '.tif'),
Path(where_output) / 'pixel_probabilities' / (fstem + '.tif'),
pxmap
)
ti.click('export_pixel_probability')
......@@ -61,7 +62,7 @@ def export_patches_from_multichannel_zstack(
# export patches
files = export_patches_from_zstack(
where_output / '2d_patches',
Path(where_output) / '2d_patches',
stack.get_one_channel_data(patches_channel),
zmask_meta,
prefix=fstem,
......@@ -78,14 +79,14 @@ def export_patches_from_multichannel_zstack(
)
)
write_accessor_data_to_file(
where_output / 'annotated_zstacks' / (fstem + '.tif'),
Path(where_output) / 'annotated_zstacks' / (fstem + '.tif'),
annotated
)
ti.click('export_annotated_zstack')
return {
'pixel_model_id': px_model.model_id,
'input_filepath': str(input_zstack_path),
'input_filepath': input_zstack_path,
'number_of_objects': len(zmask_meta),
'success': True,
'timer_results': ti.events,
......
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