fmi-faim/faim-ipa

Histogram computation and ome-zarr metadata

imagejan opened this issue · 4 comments

When this was still named faim-hcs, we had this code to compute histograms and add it to the zarr attrs:

# Save histograms and add paths to attributes
histogram_paths = []
for i, (ch, hist) in enumerate(zip(ch_metadata, histograms)):
ch_name = ch["channel-name"].replace(" ", "_")
hist_name = f"C{str(i).zfill(2)}_{ch_name}_histogram.npz"
hist.save(join(img_group.store.path, img_group.path, hist_name))
histogram_paths.append(hist_name)
attrs["histograms"] = histogram_paths
img_group.attrs.put(attrs)

@tibuch what do you think, does it make sense to add the list of histogram paths to the metadata somehow, or should we just rely on the presence of those files inside the zarr directory tree?

Maybe we can come up with a small utility function that returns the histogram loaded from file if it's present, and otherwise computes the histogram on the fly and (optionally) saves it into the zarr (for future use).

What do you think?

A small utility function sounds like a useful start.

I think this would be a great opportunity to explore how we could create and use extensions with the ngff spec.

@tibuch How about extending zarr.Group with some histogram awareness:

from zarr import Group

class HistogramAwareZarrGroup(Group):
	def histogram(self) -> UIntHistogram:
		...

	def __compute_and_persist_histogram(self):
		...

(naming to be debated)

???

Not sure if we want this to be a class. Maybe a mixin would be better suited?