From cb8000e30e412780883b8d85c5817dab72a2710f Mon Sep 17 00:00:00 2001
From: Christopher Rhodes <christopher.rhodes@embl.de>
Date: Thu, 21 Dec 2023 13:20:01 +0100
Subject: [PATCH] Propagate filename to export products

---
 extensions/chaeo/workflows.py | 14 +++++++-------
 extensions/chaeo/zmask.py     | 15 ++++++++-------
 2 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/extensions/chaeo/workflows.py b/extensions/chaeo/workflows.py
index 5e13b819..9171aaa0 100644
--- a/extensions/chaeo/workflows.py
+++ b/extensions/chaeo/workflows.py
@@ -58,12 +58,12 @@ def infer_object_map_from_zstack(
     pxmap, _ = pixel_classifier.infer(mip)
     ti.click('infer_pixel_probability')
 
-    if exports.pixel_probabilities:
-        write_accessor_data_to_file(
-            Path(output_folder_path) / 'pixel_probabilities' / (fstem + '.tif'),
-            pxmap
-        )
-        ti.click('export_pixel_probability')
+    # if exports.pixel_probabilities:
+    #     write_accessor_data_to_file(
+    #         Path(output_folder_path) / 'pixel_probabilities' / (fstem + '.tif'),
+    #         pxmap
+    #     )
+    #     ti.click('export_pixel_probability')
 
     obmask = InMemoryDataAccessor(
         pxmap.data > pxmap_threshold
@@ -90,7 +90,7 @@ def infer_object_map_from_zstack(
     )
     ti.click('export_object_classes')
 
-    rois.run_exports(Path(output_folder_path), patches_channel, exports)
+    rois.run_exports(Path(output_folder_path), patches_channel, fstem, exports)
 
     return {
         'timer_results': ti.events,
diff --git a/extensions/chaeo/zmask.py b/extensions/chaeo/zmask.py
index 3e16b8ad..95d2a73f 100644
--- a/extensions/chaeo/zmask.py
+++ b/extensions/chaeo/zmask.py
@@ -98,40 +98,41 @@ class RoiSet(object):
     def get_object_map(self, filters: RoiFilter):
         pass
 
-    def run_exports(self, where, channel, params: RoiSetExportParams):
+    def run_exports(self, where, channel, prefix, params: RoiSetExportParams):
         if not self.count:
             return
         raw_ch = self.acc_raw.get_one_channel_data(channel)
         for k in params.dict().keys():
             subdir = where / k
+            pr = prefix
             kp = params.dict()[k]
             if k == 'meta' or kp is None:
                 continue
-            if k == '3d_patches':
+            if k == 'patches_3d':
                 files = export_patches_from_zstack(
-                    subdir, raw_ch, self.zmask_meta, prefix=k, make_3d=True, **kp
+                    subdir, raw_ch, self.zmask_meta, prefix=pr, make_3d=True, **kp
                 )
             if k == 'patches_2d_for_annotation':
                 files = export_multichannel_patches_from_zstack(
-                    subdir, self.acc_raw, self.zmask_meta, prefix=k, make_3d=False, ch_white=channel,
+                    subdir, self.acc_raw, self.zmask_meta, prefix=pr, make_3d=False, ch_white=channel,
                     bounding_box_channel=1, bounding_box_linewidth=2, **kp,
                 )
             if k == 'patches_2d_for_training':
                 files = export_multichannel_patches_from_zstack(
-                    subdir, self.acc_raw, self.zmask_meta, ch_white=channel, prefix=k, make_3d=False, **kp
+                    subdir, self.acc_raw, self.zmask_meta, ch_white=channel, prefix=pr, make_3d=False, **kp
                 )
                 df_patches = pd.DataFrame(files)
                 self.df = pd.merge(self.df, df_patches, left_index=True, right_on='df_index').drop(columns='df_index')
                 self.df['patch_id'] = self.df.apply(lambda _: uuid4(), axis=1)
             if k == 'patch_masks':
                 export_patch_masks_from_zstack(
-                    subdir, raw_ch, self.zmask_meta, prefix=k,
+                    subdir, raw_ch, self.zmask_meta, prefix=pr,
                 )
             if k == 'annotated_zstacks':
                 annotated = InMemoryDataAccessor(
                     draw_boxes_on_3d_image(raw_ch.data, self.zmask_meta, **kp)
                 )
-                write_accessor_data_to_file(subdir / (k + '.tif'), annotated)
+                write_accessor_data_to_file(subdir / (pr + '.tif'), annotated)
 
 
 
-- 
GitLab