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

Corrected argument-forwarding error; set up job for porto data; split off...

Corrected argument-forwarding error; set up job for porto data; split off ecotaxa TSV generation into its own module
parent fc10b291
No related branches found
No related tags found
No related merge requests found
from pathlib import Path
from model_server.util import autonumber_new_directory, get_matching_files, loop_workflow
from extensions.chaeo.ecotaxa import write_ecotaxa_tsv
from extensions.chaeo.workflows import export_patches_from_multichannel_zstack
from extensions.ilastik.models import IlastikPixelClassifierModel
if __name__ == '__main__':
root = Path('c:/Users/rhodes/projects/proj0012-trec-handoff/owncloud-sync/TREC-HD/Images/')
where_czi = (root / 'TREC_STOP_26_Porto/231023_automic/20231023-175838_EtOHfixed/LowZoom').__str__()
where_output = autonumber_new_directory(
'c:/Users/rhodes/projects/proj0011-plankton-seg/exp0020/output',
'batch-output'
)
px_ilp = Path('c:/Users/rhodes/projects/proj0011-plankton-seg/exp0017/pxAF405_dim8bit.ilp').__str__()
params = {
'pxmap_threshold': 0.25,
'pxmap_foreground_channel': 0,
'segmentation_channel': 0,
'zmask_zindex': None,
'patches_channel': 2,
'zmask_type': 'boxes',
'zmask_filters': {'area': (1e3, 1e8)},
'zmask_expand_box_by': (128, 3),
'export_pixel_probabilities': True,
'export_2d_patches_for_training': True,
'draw_bounding_box_on_2d_patch': True,
'export_2d_patches_for_annotation': True,
'export_3d_patches': False,
'export_annotated_zstack': True,
'export_patch_masks': True,
'zmask_clip': 0.01,
'rgb_overlay_channels': (1, None, None),
'rgb_overlay_weights': (0.2, 1.0, 1.0)
}
input_files = get_matching_files(where_czi, 'czi', coord_filter={})
loop_workflow(
input_files,
where_output,
export_patches_from_multichannel_zstack,
[IlastikPixelClassifierModel(params={'project_file': Path(px_ilp)})],
params,
catch_and_continue=False,
)
csv_path = (Path(where_output) / 'workflow_data.csv').__str__()
write_ecotaxa_tsv(csv_path, where_output, sample_id='20231023-porto', scope_id='EMBL-MS-Zeiss-LSM900')
print('Finished')
\ No newline at end of file
from pathlib import Path
import pandas as pd
def write_ecotaxa_tsv(patches_csv_path: str, where: str, sample_id: str, scope_id: str):
# import patch output table
df_patches = pd.read_csv(patches_csv_path)
df_patches['img_file_name'] = df_patches['patch_filename'].apply(lambda x: '2d_patches_annotation/' + x)
# make second column index level to comply w/ EcoTaxa schema
df_patches.columns = pd.MultiIndex.from_frame(
pd.DataFrame([
df_patches.columns,
df_patches.dtypes.apply(
lambda x: '[f]' if x in ['float64'] else '[t]'
)
]).T,
names=['variable', 'data type']
)
# add new columns for ecotaxa
df_patches.loc[:, ('acq_instrument', '[t]')] = 'Other microscope'
df_patches.loc[:, ('acq_instrument_microscope', '[t]')] = scope_id
df_patches.loc[:, ('sample_id', '[t]')] = sample_id
df_patches.loc[:, ('acq_id', '[t]')] = df_patches.loc[:, ('input_file', '[t]')]
df_patches.loc[:, ('object_id', '[t]')] = df_patches.loc[:, ('patch_id', '[t]')]
df_patches.loc[:, ('process_id', '[t]')] = df_patches.loc[:, ('patch_id', '[t]')]
cols_to_transfer = [
'img_file_name',
'object_id',
'acq_id',
'acq_instrument',
'acq_instrument_microscope',
'sample_id',
'process_id'
]
df_export = df_patches.loc[:, pd.IndexSlice[cols_to_transfer, :]]
df_export.to_csv(Path(where) / 'ecotaxa.tsv', sep='\t', index=False)
\ No newline at end of file
......@@ -63,7 +63,7 @@ def get_zmask_meta(
stack.get_one_channel_data(segmentation_channel),
mask_type=zmask_type,
filters=zmask_filters,
**kwargs,
expand_box_by=kwargs['zmask_expand_box_by'],
)
ti.click('generate_zmasks')
......
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