From a54188b6f961dd1aed899afedb55b07854f9696f Mon Sep 17 00:00:00 2001 From: William Moore Date: Tue, 3 Nov 2020 12:00:12 +0000 Subject: [PATCH 1/7] Add 'well' list of images to each column group --- src/omero_zarr/raw_pixels.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/omero_zarr/raw_pixels.py b/src/omero_zarr/raw_pixels.py index 0d57ed3..354b306 100644 --- a/src/omero_zarr/raw_pixels.py +++ b/src/omero_zarr/raw_pixels.py @@ -161,6 +161,7 @@ def plate_to_zarr(plate: omero.gateway._PlateWrapper, args: argparse.Namespace) for well in plate.listChildren(): row = plate.getRowLabels()[well.row] col = plate.getColumnLabels()[well.column] + well_paths = [] for field in range(n_fields[0], n_fields[1] + 1): ws = well.getWellSample(field) field_name = "Field_{}".format(field + 1) @@ -170,12 +171,15 @@ def plate_to_zarr(plate: omero.gateway._PlateWrapper, args: argparse.Namespace) ac = ws.getPlateAcquisition() ac_name = ac.getName() if ac else "0" paths.add(f"{ac_name}/{row}/{col}/{field_name}") + well_paths.append(field_name) ac_group = root.require_group(ac_name) row_group = ac_group.require_group(row) col_group = row_group.require_group(col) field_group = col_group.require_group(field_name) n_levels = add_image(img, field_group, cache_dir=cache_dir) add_group_metadata(field_group, img, n_levels) + # Update Well metadata after each image + col_group.attrs["well"] = {"images": [{"path": x} for x in well_paths]} print_status(int(t0), int(time.time()), count, total) # Update images after each Well From 5586646b325ed3db62e761c76ae6aeb326c4b820 Mon Sep 17 00:00:00 2001 From: William Moore Date: Tue, 3 Nov 2020 12:02:59 +0000 Subject: [PATCH 2/7] Fields named with field index --- src/omero_zarr/raw_pixels.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/omero_zarr/raw_pixels.py b/src/omero_zarr/raw_pixels.py index 354b306..9c45f4a 100644 --- a/src/omero_zarr/raw_pixels.py +++ b/src/omero_zarr/raw_pixels.py @@ -164,7 +164,7 @@ def plate_to_zarr(plate: omero.gateway._PlateWrapper, args: argparse.Namespace) well_paths = [] for field in range(n_fields[0], n_fields[1] + 1): ws = well.getWellSample(field) - field_name = "Field_{}".format(field + 1) + field_name = "%d" % field count += 1 if ws and ws.getImage(): img = ws.getImage() From 5360f53dcc48d0fe76ba7fc648857bc56efdfb49 Mon Sep 17 00:00:00 2001 From: William Moore Date: Tue, 3 Nov 2020 12:26:43 +0000 Subject: [PATCH 3/7] Update plate metadata: rows, columns, field_count --- src/omero_zarr/raw_pixels.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/omero_zarr/raw_pixels.py b/src/omero_zarr/raw_pixels.py index 9c45f4a..428b78a 100644 --- a/src/omero_zarr/raw_pixels.py +++ b/src/omero_zarr/raw_pixels.py @@ -137,6 +137,7 @@ def plate_to_zarr(plate: omero.gateway._PlateWrapper, args: argparse.Namespace) root = open_group(name, mode="w") count = 0 + max_fields = 0 t0 = time.time() row_names = set() @@ -150,10 +151,8 @@ def plate_to_zarr(plate: omero.gateway._PlateWrapper, args: argparse.Namespace) plate_metadata = { "name": plate.name, - "rows": len(row_names), - "columns": len(col_names), - "row_names": row_names, - "column_names": col_names, + "rows": [{"name": name} for name in row_names], + "columns": [{"name": name} for name in col_names], "plateAcquisitions": [{"path": x} for x in ac_names], } root.attrs["plate"] = plate_metadata @@ -180,10 +179,12 @@ def plate_to_zarr(plate: omero.gateway._PlateWrapper, args: argparse.Namespace) add_group_metadata(field_group, img, n_levels) # Update Well metadata after each image col_group.attrs["well"] = {"images": [{"path": x} for x in well_paths]} + max_fields = max(max_fields, field + 1) print_status(int(t0), int(time.time()), count, total) - # Update images after each Well + # Update plate_metadata after each Well plate_metadata["images"] = [{"path": x} for x in paths] + plate_metadata["field_count"] = max_fields root.attrs["plate"] = plate_metadata add_toplevel_metadata(root) From edbf7876bf400fcb17f54e71ac34d945caa502ed Mon Sep 17 00:00:00 2001 From: William Moore Date: Tue, 3 Nov 2020 12:27:27 +0000 Subject: [PATCH 4/7] Ignore potential ZeroDivisionError in print_status --- src/omero_zarr/raw_pixels.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/omero_zarr/raw_pixels.py b/src/omero_zarr/raw_pixels.py index 428b78a..76eea4f 100644 --- a/src/omero_zarr/raw_pixels.py +++ b/src/omero_zarr/raw_pixels.py @@ -198,13 +198,16 @@ def print_status(t0: int, t: int, count: int, total: int) -> None: count: number of tasks done total: total number of tasks """ - percent_done = float(count) * 100 / total - rate = float(count) / (t - t0) - eta = float(total - count) / rate - status = "{:.2f}% done, ETA: {}".format( - percent_done, time.strftime("%H:%M:%S", time.gmtime(eta)) - ) - print(status, end="\r", flush=True) + try: + percent_done = float(count) * 100 / total + rate = float(count) / (t - t0) + eta = float(total - count) / rate + status = "{:.2f}% done, ETA: {}".format( + percent_done, time.strftime("%H:%M:%S", time.gmtime(eta)) + ) + print(status, end="\r", flush=True) + except ZeroDivisionError: + pass def add_group_metadata( From 2344048b9ed6deed9a8a3b712c5d6825811457d6 Mon Sep 17 00:00:00 2001 From: William Moore Date: Tue, 3 Nov 2020 15:03:46 +0000 Subject: [PATCH 5/7] Write plate 'wells' e.g. path: '/0/A/1/' --- src/omero_zarr/raw_pixels.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/omero_zarr/raw_pixels.py b/src/omero_zarr/raw_pixels.py index 76eea4f..c968149 100644 --- a/src/omero_zarr/raw_pixels.py +++ b/src/omero_zarr/raw_pixels.py @@ -142,7 +142,7 @@ def plate_to_zarr(plate: omero.gateway._PlateWrapper, args: argparse.Namespace) row_names = set() col_names = set() - paths = set() + well_paths = set() col_names = plate.getColumnLabels() row_names = plate.getRowLabels() @@ -160,7 +160,7 @@ def plate_to_zarr(plate: omero.gateway._PlateWrapper, args: argparse.Namespace) for well in plate.listChildren(): row = plate.getRowLabels()[well.row] col = plate.getColumnLabels()[well.column] - well_paths = [] + field_paths = [] for field in range(n_fields[0], n_fields[1] + 1): ws = well.getWellSample(field) field_name = "%d" % field @@ -169,8 +169,8 @@ def plate_to_zarr(plate: omero.gateway._PlateWrapper, args: argparse.Namespace) img = ws.getImage() ac = ws.getPlateAcquisition() ac_name = ac.getName() if ac else "0" - paths.add(f"{ac_name}/{row}/{col}/{field_name}") - well_paths.append(field_name) + well_paths.add(f"{ac_name}/{row}/{col}/") + field_paths.append(f"{field_name}/") ac_group = root.require_group(ac_name) row_group = ac_group.require_group(row) col_group = row_group.require_group(col) @@ -178,12 +178,12 @@ def plate_to_zarr(plate: omero.gateway._PlateWrapper, args: argparse.Namespace) n_levels = add_image(img, field_group, cache_dir=cache_dir) add_group_metadata(field_group, img, n_levels) # Update Well metadata after each image - col_group.attrs["well"] = {"images": [{"path": x} for x in well_paths]} + col_group.attrs["well"] = {"images": [{"path": x} for x in field_paths]} max_fields = max(max_fields, field + 1) print_status(int(t0), int(time.time()), count, total) # Update plate_metadata after each Well - plate_metadata["images"] = [{"path": x} for x in paths] + plate_metadata["wells"] = [{"path": x} for x in well_paths] plate_metadata["field_count"] = max_fields root.attrs["plate"] = plate_metadata From 0e2df56c94b41f7d46f28b85a0f0e17e7f9f4eae Mon Sep 17 00:00:00 2001 From: William Moore Date: Thu, 5 Nov 2020 09:57:22 +0000 Subject: [PATCH 6/7] Ensure row and column names are strings, not numbers --- src/omero_zarr/raw_pixels.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/omero_zarr/raw_pixels.py b/src/omero_zarr/raw_pixels.py index c968149..330e97d 100644 --- a/src/omero_zarr/raw_pixels.py +++ b/src/omero_zarr/raw_pixels.py @@ -151,8 +151,8 @@ def plate_to_zarr(plate: omero.gateway._PlateWrapper, args: argparse.Namespace) plate_metadata = { "name": plate.name, - "rows": [{"name": name} for name in row_names], - "columns": [{"name": name} for name in col_names], + "rows": [{"name": str(name)} for name in row_names], + "columns": [{"name": str(name)} for name in col_names], "plateAcquisitions": [{"path": x} for x in ac_names], } root.attrs["plate"] = plate_metadata From 37c48d6c5bd8d9a3b5fd5af18441a7eeccfb351b Mon Sep 17 00:00:00 2001 From: William Moore Date: Thu, 5 Nov 2020 11:31:14 +0000 Subject: [PATCH 7/7] Fix 'plateAcquisitions' -> 'acquisitions' in plate.zattrs --- src/omero_zarr/raw_pixels.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/omero_zarr/raw_pixels.py b/src/omero_zarr/raw_pixels.py index 330e97d..1332b83 100644 --- a/src/omero_zarr/raw_pixels.py +++ b/src/omero_zarr/raw_pixels.py @@ -153,7 +153,7 @@ def plate_to_zarr(plate: omero.gateway._PlateWrapper, args: argparse.Namespace) "name": plate.name, "rows": [{"name": str(name)} for name in row_names], "columns": [{"name": str(name)} for name in col_names], - "plateAcquisitions": [{"path": x} for x in ac_names], + "acquisitions": [{"path": x} for x in ac_names], } root.attrs["plate"] = plate_metadata