From 1a6b131da57bb7cbfe1969f4b0c71b30247f9316 Mon Sep 17 00:00:00 2001 From: Christopher Rhodes <christopher.rhodes@embl.de> Date: Mon, 30 Oct 2023 10:19:41 +0100 Subject: [PATCH] Clean test showing that modified HDF5 isn't providing correct results --- .../examples/test_modify_object_classifier.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/extensions/chaeo/examples/test_modify_object_classifier.py b/extensions/chaeo/examples/test_modify_object_classifier.py index 2cabba44..647f9461 100644 --- a/extensions/chaeo/examples/test_modify_object_classifier.py +++ b/extensions/chaeo/examples/test_modify_object_classifier.py @@ -7,17 +7,22 @@ import numpy as np from extensions.chaeo.accessors import MonoPatchStack, MonoPatchStackFromFile from extensions.chaeo.models import PatchStackObjectClassifier -def modify_ilastik_object_classifier(template_ilp: Path, lane=0): - where = template_ilp.parent + +def modify_ilastik_object_classifier(template_ilp: Path, lane: int = 0): + proj_dir = template_ilp.parent proj_name = template_ilp.stem - new_ilp = shutil.copy(template_ilp, where / ('mod_' + proj_name + '.ilp')) + proj_new_ilp = shutil.copy(template_ilp, proj_dir / ('mod_' + proj_name + '.ilp')) - with h5py.File(where / new_ilp, 'r+') as h5: + with h5py.File(where / proj_new_ilp, 'r+') as h5: # delete ObjectExtraction / RegionFeatures / 0000 # delete ObjectClassification/ClassifierForests - for key in [f'ObjectExtraction/RegionFeatures/{lane:04d}', 'ObjectExtraction/ClassifierForests']: - if (key) in h5.keys(): + keys_to_delete = [ + f'ObjectExtraction/RegionFeatures/{lane:04d}', + 'ObjectExtraction/ClassifierForests' + ] + for key in keys_to_delete: + if key in h5.keys(): del h5[key] assert key not in h5.keys() @@ -33,7 +38,7 @@ def modify_ilastik_object_classifier(template_ilp: Path, lane=0): h5[f'{key}/filePath'] = rel_pa assert h5[f'{key}/filePath'][()] == rel_pa.encode() - return new_ilp + return proj_new_ilp if __name__ == '__main__': -- GitLab