From 07c9e0e3d663173a849586af7ecaad80cfb299dd Mon Sep 17 00:00:00 2001
From: Christopher Rhodes <christopher.rhodes@embl.de>
Date: Mon, 6 Nov 2023 16:06:05 +0100
Subject: [PATCH] Added pixel scale to CSV and Ecotaxa export

---
 extensions/chaeo/annotators.py                          | 2 +-
 extensions/chaeo/batch_jobs/20231023_Porto_EtOHfixed.py | 3 ++-
 extensions/chaeo/ecotaxa.py                             | 1 +
 extensions/chaeo/workflows.py                           | 8 ++++++--
 4 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/extensions/chaeo/annotators.py b/extensions/chaeo/annotators.py
index 145e1505..eb4996c3 100644
--- a/extensions/chaeo/annotators.py
+++ b/extensions/chaeo/annotators.py
@@ -24,7 +24,7 @@ def draw_boxes_on_2d_image(yx_img, boxes, **kwargs):
         draw.rectangle([(x0, y0), (x1, y1)], outline='white', width=linewidth)
 
         if kwargs.get('add_label') is True:
-            draw.text((xm, y0), f'Z{zi:04d}-L{la:04d}', fill='white', anchor='mb')
+            draw.text((xm, y0), f'{la:04d}', fill='white', anchor='mb')
 
     return pilimg
 
diff --git a/extensions/chaeo/batch_jobs/20231023_Porto_EtOHfixed.py b/extensions/chaeo/batch_jobs/20231023_Porto_EtOHfixed.py
index 45ee1130..ebfec6ce 100644
--- a/extensions/chaeo/batch_jobs/20231023_Porto_EtOHfixed.py
+++ b/extensions/chaeo/batch_jobs/20231023_Porto_EtOHfixed.py
@@ -34,7 +34,8 @@ if __name__ == '__main__':
         'export_patch_masks': True,
         'zmask_clip': 0.01,
         'rgb_overlay_channels': (1, None, None),
-        'rgb_overlay_weights': (0.2, 1.0, 1.0)
+        'rgb_overlay_weights': (0.2, 1.0, 1.0),
+        'draw_label_on_zstack': True,
     }
 
     input_files = get_matching_files(where_czi, 'czi', coord_filter={})
diff --git a/extensions/chaeo/ecotaxa.py b/extensions/chaeo/ecotaxa.py
index 770b5b74..12a8bb6d 100644
--- a/extensions/chaeo/ecotaxa.py
+++ b/extensions/chaeo/ecotaxa.py
@@ -26,6 +26,7 @@ def write_ecotaxa_tsv(patches_csv_path: str, where: str, sample_id: str, scope_i
     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]')]
+    df_patches.loc[:, ('acq_pixel_scale_in_micrometers', '[f]')] = df_patches.loc[:, ('pixel_scale_in_micrometers', '[f]')]
 
     cols_to_transfer = [
         'img_file_name',
diff --git a/extensions/chaeo/workflows.py b/extensions/chaeo/workflows.py
index 8da67916..57072bb8 100644
--- a/extensions/chaeo/workflows.py
+++ b/extensions/chaeo/workflows.py
@@ -67,6 +67,9 @@ def get_zmask_meta(
     )
     ti.click('generate_zmasks')
 
+    # record pixel scale
+    df['pixel_scale_in_micrometers'] = float(stack.pixel_scale_in_micrometers.get('X'))
+
     return ti, stack, fstem, obmask, pxmap, zmask, zmask_meta, df, interm
 
 
@@ -92,6 +95,7 @@ def export_patches_from_multichannel_zstack(
         draw_mask_on_2d_patch=False,
         export_3d_patches=True,
         export_annotated_zstack=True,
+        draw_label_on_zstack=False,
         export_patch_masks=True,
         rgb_overlay_channels=(None, None, None),
         rgb_overlay_weights=(1.0, 1.0, 1.0),
@@ -165,7 +169,6 @@ def export_patches_from_multichannel_zstack(
             make_3d=False,
             focus_metric='max_sobel',
         )
-        df_patches = pd.DataFrame(files)
         ti.click('export_2d_patches')
 
     if export_patch_masks:
@@ -180,7 +183,8 @@ def export_patches_from_multichannel_zstack(
         annotated = InMemoryDataAccessor(
             draw_boxes_on_3d_image(
                 stack.get_one_channel_data(patches_channel).data,
-                zmask_meta
+                zmask_meta,
+                add_label=draw_label_on_zstack,
             )
         )
         write_accessor_data_to_file(
-- 
GitLab