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

Cleaned up batch runner script with filepath utility functions

parent b7738938
No related branches found
No related tags found
No related merge requests found
from pathlib import Path
import re
from time import localtime, strftime
# from time import localtime, strftime
import pandas as pd
from extensions.chaeo.util import autonumber_new_directory, get_matching_files
from extensions.chaeo.workflows import export_patches_from_multichannel_zstack
from model_server.accessors import InMemoryDataAccessor, write_accessor_data_to_file
if __name__ == '__main__':
where_czi = Path(
'z:/rhodes/projects/proj0004-marine-photoactivation/data/exp0038/AutoMic/20230906-163415/Selection'
)
where_output_root = Path(
'c:/Users/rhodes/projects/proj0011-plankton-seg/exp0009/output'
)
yyyymmdd = strftime('%Y%m%d', localtime())
idx = 0
for ff in Path(where_output_root).iterdir():
ma = re.match(f'batch-output-{yyyymmdd}-([\d]+)', ff.name)
if ma:
idx = max(idx, int(ma.groups()[0]) + 1 )
where_czi = 'z:/rhodes/projects/proj0004-marine-photoactivation/data/exp0038/AutoMic/20230906-163415/Selection'
where_output = Path(
where_output_root / f'batch-output-{yyyymmdd}-{idx:04d}'
where_output = autonumber_new_directory(
'c:/Users/rhodes/projects/proj0011-plankton-seg/exp0009/output',
'batch-output'
)
csv_args = {'mode': 'w', 'header': True} # when creating file
......@@ -32,25 +22,18 @@ if __name__ == '__main__':
#TODO: try/catch blocks and error handling around workflow calls
#TODO: pack JSON-serializable workflow inputs
for ff in where_czi.iterdir():
pattern = 'Selection--W([\d]+)--P([\d]+)-T([\d]+)'
ma = re.match(pattern, ff.stem)
print(ff)
if not ff.suffix.upper() == '.CZI':
continue
if int(ma.groups()[1]) > 10: # skip second half of set
continue
input_files = get_matching_files(where_czi, 'czi', coord_filter={'P': (0, 10)})
for ff in input_files:
export_kwargs = {
'input_zstack_path': (where_czi / ff).__str__(),
'input_zstack_path': Path(where_czi) / ff.__str__(),
'ilastik_project_file': px_ilp.__str__(),
'pxmap_threshold': 0.25,
'pixel_class': 0,
'zmask_channel': 0,
'patches_channel': 4,
'where_output': where_output.__str__(),
'where_output': where_output,
'mask_type': 'boxes',
'zmask_filters': {'area': (1e3, 1e8)},
'zmask_expand_box_by': (128, 3),
......
from pathlib import Path
import re
from time import localtime, strftime
def autonumber_new_directory(where: str, prefix: str) -> str:
yyyymmdd = strftime('%Y%m%d', localtime())
idx = 0
for ff in Path(where).iterdir():
ma = re.match(f'{prefix}-{yyyymmdd}-([\d]+)', ff.name)
if ma:
idx = max(idx, int(ma.groups()[0]) + 1)
return (Path(where) / f'batch-output-{yyyymmdd}-{idx:04d}').__str__()
def get_matching_files(where: str, ext: str, coord_filter: dict={}) -> str:
files = []
def is_filtered_out(ff):
if ff.suffix.upper() != f'.{ext}'.upper():
return True
coords = {
m[0]: int(m[1]) for m in re.findall('-([a-zA-Z])(\d+)', ff.name)
}
for fk in coord_filter.keys():
if fk in coords.keys():
cmin, cmax = coord_filter[fk]
if coords[fk] < cmin or coords[fk] > cmax:
return True
return False
for ff in Path(where).iterdir():
if is_filtered_out(ff):
continue
files.append(ff.__str__())
return files
\ No newline at end of file
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