@@ -46,7 +46,8 @@ def _process_single_image(
46
46
This task:
47
47
48
48
1. Validates OME-NGFF image metadata, via `NgffImageMeta`;
49
- 2. Optionally generates and writes two ROI tables.
49
+ 2. Optionally generates and writes two ROI tables;
50
+ 3. Optionally update OME-NGFF omero metadata.
50
51
51
52
Args:
52
53
image_path: Absolute path to the image Zarr group.
@@ -107,12 +108,34 @@ def _process_single_image(
107
108
108
109
# Update Omero-channels metadata
109
110
if update_omero_metadata :
110
- if image_meta .omero is None or image_meta .omero .channels == []:
111
- # TODO: create omero-channels list from scratch
112
- raise NotImplementedError
113
- old_channels = [c .dict () for c in image_meta .omero .channels ]
111
+
112
+ # Extract number of channels from zarr array
113
+ try :
114
+ channel_axis_index = image_meta .axes_names .index ("c" )
115
+ except ValueError :
116
+ raise NotImplementedError (
117
+ f"Existing axes ({ image_meta .axes_names } ) do not "
118
+ 'include "c".'
119
+ )
120
+ num_channels_zarr = array .shape [channel_axis_index ]
121
+ print (num_channels_zarr )
122
+
123
+ old_omero = image_group .attrs .get ("omero" , {})
124
+ old_channels = old_omero .get ("channels" , [])
125
+ if old_channels != []:
126
+ # Case 1: omero/channels exist
127
+ if len (old_channels ) != num_channels_zarr :
128
+ error_msg = (
129
+ "Channels-number mismatch: Number of channels in the "
130
+ f"zarr array ({ num_channels_zarr } ) differ from number "
131
+ "of channels listed in NGFF omero metadata "
132
+ f"({ len (old_channels )} )."
133
+ )
134
+ raise ValueError (error_msg )
135
+ else :
136
+ # Case 2: omero or omero/channels do not exist
137
+ old_channels = [{} for ind in range (num_channels_zarr )]
114
138
new_channels = update_omero_channels (old_channels )
115
- old_omero = image_group .attrs ["omero" ]
116
139
new_omero = old_omero .copy ()
117
140
new_omero ["channels" ] = new_channels
118
141
image_group .attrs .update (omero = new_omero )
0 commit comments