Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Histogram computation and ome-zarr metadata #147

Open
imagejan opened this issue Jun 20, 2024 · 3 comments
Open

Histogram computation and ome-zarr metadata #147

imagejan opened this issue Jun 20, 2024 · 3 comments

Comments

@imagejan
Copy link
Member

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?

@tibuch
Copy link
Contributor

tibuch commented Jun 20, 2024

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.

@imagejan
Copy link
Member Author

imagejan commented Jul 1, 2024

@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)

???

@tibuch
Copy link
Contributor

tibuch commented Jul 1, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants