Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
aliaksei-chareshneu committed Jun 21, 2024
2 parents c907786 + b619d74 commit 037fd46
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 71 deletions.
97 changes: 33 additions & 64 deletions preprocessor/cellstar_preprocessor/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,19 +560,19 @@ def _process_inputs(self, inputs: list[InputT]) -> list[TaskBase]:
tasks = []
nii_segmentation_inputs: list[NIISegmentationInput] = []
mask_segmentation_inputs: list[MaskInput] = []
for input in inputs:
if isinstance(input, ExtraDataInput):
for i in inputs:
if isinstance(i, ExtraDataInput):
tasks.append(
ProcessExtraDataTask(
path=input.input_path,
path=i.input_path,
intermediate_zarr_structure_path=self.intermediate_zarr_structure,
)
)
elif isinstance(input, MAPInput):
elif isinstance(i, MAPInput):
self.store_internal_volume(
internal_volume=InternalVolume(
intermediate_zarr_structure_path=self.intermediate_zarr_structure,
volume_input_path=input.input_path,
volume_input_path=i.input_path,
params_for_storing=self.preprocessor_input.storing_params,
volume_force_dtype=self.preprocessor_input.volume.force_volume_dtype,
quantize_dtype_str=self.preprocessor_input.volume.quantize_dtype_str,
Expand All @@ -589,11 +589,11 @@ def _process_inputs(self, inputs: list[InputT]) -> list[TaskBase]:
internal_volume=self.get_internal_volume()
)
)
elif isinstance(input, SFFInput):
elif isinstance(i, SFFInput):
self.store_internal_segmentation(
internal_segmentation=InternalSegmentation(
intermediate_zarr_structure_path=self.intermediate_zarr_structure,
segmentation_input_path=input.input_path,
segmentation_input_path=i.input_path,
params_for_storing=self.preprocessor_input.storing_params,
downsampling_parameters=self.preprocessor_input.downsampling,
entry_data=self.preprocessor_input.entry_data,
Expand All @@ -615,33 +615,14 @@ def _process_inputs(self, inputs: list[InputT]) -> list[TaskBase]:
)
)

elif isinstance(input, MaskInput):
mask_segmentation_inputs.append(input)
# self.store_internal_segmentation(
# internal_segmentation=InternalSegmentation(
# intermediate_zarr_structure_path=self.intermediate_zarr_structure,
# segmentation_input_path=input.input_path,
# params_for_storing=self.preprocessor_input.storing_params,
# downsampling_parameters=self.preprocessor_input.downsampling,
# entry_data=self.preprocessor_input.entry_data,
# )
# )
# tasks.append(
# MaskProcessSegmentationTask(
# internal_segmentation=self.get_internal_segmentation()
# )
# )
# tasks.append(
# MaskMetadataCollectionTask(
# internal_segmentation=self.get_internal_segmentation()
# )
# )

elif isinstance(input, OMEZARRInput):
elif isinstance(i, MaskInput):
mask_segmentation_inputs.append(i)

elif isinstance(i, OMEZARRInput):
self.store_internal_volume(
internal_volume=InternalVolume(
intermediate_zarr_structure_path=self.intermediate_zarr_structure,
volume_input_path=input.input_path,
volume_input_path=i.input_path,
params_for_storing=self.preprocessor_input.storing_params,
volume_force_dtype=self.preprocessor_input.volume.force_volume_dtype,
quantize_dtype_str=self.preprocessor_input.volume.quantize_dtype_str,
Expand All @@ -657,7 +638,7 @@ def _process_inputs(self, inputs: list[InputT]) -> list[TaskBase]:
self.store_internal_segmentation(
internal_segmentation=InternalSegmentation(
intermediate_zarr_structure_path=self.intermediate_zarr_structure,
segmentation_input_path=input.input_path,
segmentation_input_path=i.input_path,
params_for_storing=self.preprocessor_input.storing_params,
downsampling_parameters=self.preprocessor_input.downsampling,
entry_data=self.preprocessor_input.entry_data,
Expand All @@ -676,11 +657,11 @@ def _process_inputs(self, inputs: list[InputT]) -> list[TaskBase]:
OMEZARRAnnotationsCollectionTask(self.get_internal_volume())
)

elif isinstance(input, GeometricSegmentationInput):
elif isinstance(i, GeometricSegmentationInput):
self.store_internal_segmentation(
internal_segmentation=InternalSegmentation(
intermediate_zarr_structure_path=self.intermediate_zarr_structure,
segmentation_input_path=input.input_path,
segmentation_input_path=i.input_path,
params_for_storing=self.preprocessor_input.storing_params,
downsampling_parameters=self.preprocessor_input.downsampling,
entry_data=self.preprocessor_input.entry_data,
Expand All @@ -689,11 +670,11 @@ def _process_inputs(self, inputs: list[InputT]) -> list[TaskBase]:
tasks.append(
ProcessGeometricSegmentationTask(self.get_internal_segmentation())
)
elif isinstance(input, OMETIFFImageInput):
elif isinstance(i, OMETIFFImageInput):
self.store_internal_volume(
internal_volume=InternalVolume(
intermediate_zarr_structure_path=self.intermediate_zarr_structure,
volume_input_path=input.input_path,
volume_input_path=i.input_path,
params_for_storing=self.preprocessor_input.storing_params,
volume_force_dtype=self.preprocessor_input.volume.force_volume_dtype,
quantize_dtype_str=self.preprocessor_input.volume.quantize_dtype_str,
Expand All @@ -718,11 +699,11 @@ def _process_inputs(self, inputs: list[InputT]) -> list[TaskBase]:
internal_volume=self.get_internal_volume()
)
)
elif isinstance(input, OMETIFFSegmentationInput):
elif isinstance(i, OMETIFFSegmentationInput):
self.store_internal_segmentation(
internal_segmentation=InternalSegmentation(
intermediate_zarr_structure_path=self.intermediate_zarr_structure,
segmentation_input_path=input.input_path,
segmentation_input_path=i.input_path,
params_for_storing=self.preprocessor_input.storing_params,
downsampling_parameters=self.preprocessor_input.downsampling,
entry_data=self.preprocessor_input.entry_data,
Expand All @@ -741,11 +722,11 @@ def _process_inputs(self, inputs: list[InputT]) -> list[TaskBase]:
internal_segmentation=self.get_internal_segmentation()
)
)
elif isinstance(input, NIIVolumeInput):
elif isinstance(i, NIIVolumeInput):
self.store_internal_volume(
internal_volume=InternalVolume(
intermediate_zarr_structure_path=self.intermediate_zarr_structure,
volume_input_path=input.input_path,
volume_input_path=i.input_path,
params_for_storing=self.preprocessor_input.storing_params,
volume_force_dtype=self.preprocessor_input.volume.force_volume_dtype,
quantize_dtype_str=self.preprocessor_input.volume.quantize_dtype_str,
Expand All @@ -763,31 +744,12 @@ def _process_inputs(self, inputs: list[InputT]) -> list[TaskBase]:
)
)

elif isinstance(input, NIISegmentationInput):
nii_segmentation_inputs.append(input)
# self.store_internal_segmentation(
# internal_segmentation=InternalSegmentation(
# intermediate_zarr_structure_path=self.intermediate_zarr_structure,
# segmentation_input_path=input.input_path,
# params_for_storing=self.preprocessor_input.storing_params,
# downsampling_parameters=self.preprocessor_input.downsampling,
# entry_data=self.preprocessor_input.entry_data,
# )
# )
# tasks.append(
# NIIProcessSegmentationTask(
# internal_segmentation=self.get_internal_segmentation()
# )
# )
# tasks.append(
# NIISegmentationMetadataCollectionTask(
# internal_segmentation=self.get_internal_segmentation()
# )
# )
elif isinstance(input, CustomAnnotationsInput):
elif isinstance(i, NIISegmentationInput):
nii_segmentation_inputs.append(i)
elif isinstance(i, CustomAnnotationsInput):
tasks.append(
CustomAnnotationsCollectionTask(
input_path=input.input_path,
input_path=i.input_path,
intermediate_zarr_structure_path=self.intermediate_zarr_structure,
)
)
Expand Down Expand Up @@ -854,7 +816,7 @@ def _process_inputs(self, inputs: list[InputT]) -> list[TaskBase]:
)
)

if any(isinstance(input, GeometricSegmentationInput) for input in inputs):
if any(isinstance(i, GeometricSegmentationInput) for i in inputs):
# tasks.append(SaveGeometricSegmentationSets(self.intermediate_zarr_structure))
tasks.append(
GeometricSegmentationAnnotationsCollectionTask(
Expand All @@ -876,10 +838,17 @@ def _execute_tasks(self, tasks: list[TaskBase]):
for task in tasks:
task.execute()

def __check_if_inputs_exists(self, raw_inputs_list: list[tuple[Path, InputKind]]):
for input_item in raw_inputs_list:
p = input_item[0]
assert p.exists(), f'Input file {p} does not exist'

def _analyse_preprocessor_input(self) -> list[InputT]:
raw_inputs_list = self.preprocessor_input.inputs.files
analyzed_inputs: list[InputT] = []

self.__check_if_inputs_exists(raw_inputs_list)

for input_item in raw_inputs_list:
if input_item[1] == InputKind.extra_data:
analyzed_inputs.append(ExtraDataInput(input_path=input_item[0]))
Expand Down
16 changes: 13 additions & 3 deletions preprocessor/cellstar_preprocessor/tools/deploy_api/deploy_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def parse_script_args():
parser.add_argument("--db_path", type=str, default=DEFAULT_DB_PATH, help='path to db folder')
parser.add_argument("--api_port", type=str, help='api port', default=DEFAULT_PORT,)
parser.add_argument("--api_hostname", type=str, default=DEFAULT_HOST, help='default host')

parser.add_argument("--ssl-keyfile", type=str)
parser.add_argument("--ssl-certfile", type=str)
args=parser.parse_args()
return args

Expand Down Expand Up @@ -57,11 +58,20 @@ def run_api(args):

if args.api_port:
deploy_env['PORT'] = args.api_port

lst = [
"python", "serve.py"
"python", "serve.py",
]

if args.ssl_certfile and args.ssl_keyfile:
lst.extend(
[
"--ssl_keyfile",
str(Path(args.ssl_keyfile).resolve()),
"--ssl_certfile",
str(Path(args.ssl_certfile).resolve())
]
)

api_process = subprocess.Popen(lst, env=deploy_env, cwd='server/cellstar_server/')
PROCESS_IDS_LIST.append(api_process.pid)
print(f'API is running with args {vars(args)}')
Expand Down
23 changes: 19 additions & 4 deletions server/cellstar_server/serve.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
import argparse
from pathlib import Path
import uvicorn
from cellstar_server.app.settings import settings

if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--ssl_keyfile", type=str)
parser.add_argument("--ssl_certfile", type=str)
args = parser.parse_args()

print("Mol* Volume Server")
print(settings.dict())

uvicorn.run(
app="main:app", host=settings.HOST, port=settings.PORT, reload=settings.DEV_MODE
)
if args.ssl_certfile and args.ssl_keyfile:
uvicorn.run(
app="main:app", host=settings.HOST, port=settings.PORT, reload=settings.DEV_MODE,
ssl_keyfile=str(Path(args.ssl_keyfile).resolve()),
ssl_certfile=str(Path(args.ssl_certfile).resolve())
)
if not args.ssl_certfile and not args.ssl_keyfile:
uvicorn.run(
app="main:app", host=settings.HOST, port=settings.PORT, reload=settings.DEV_MODE
)
else:
print("ssl_certfile or ssl_keyfile was not provided")

0 comments on commit 037fd46

Please sign in to comment.