Skip to content

feat: Add support for contrast limit #471

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

aranega
Copy link

@aranega aranega commented Mar 24, 2025

Description

This PR links the contrast limit computation provided by cryoet-data-portal-neuroglancer v1.2.1. The contrast limit is computed on the MRC file produced during the ingestion, and uses the gmm computation method by default.

@@ -253,6 +262,10 @@ def get_output_volume_info(self) -> VolumeInfo:
output_prefix = self.get_output_path()
return get_volume_info(self.config.fs, f"{output_prefix}.mrc")

def get_contrast_limits(self, method: Literal["gmm", "cdf"] = "gmm") -> tuple[float, float]:
output_prefix = self.get_output_path()
return get_volume_contrast_limits(self.config.fs, f"{output_prefix}.mrc", method=method)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the mrc instead of the zarr may possibly be problematic here due to memory issues

This computation was originally designed to run on the lowest resolution image from the zarr image pyramid

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that's the case, then I think we perhaps have a problem, when reaching this point, at least in the tests, it seems that the .zarr file isn't produced. I'm not sure if that's comes from the mocks in the tests, or if that's a normal behavior (to not have the .zarr file produce).

@@ -53,7 +53,7 @@ imageio = "^2.33.1"
pytest = "^8.3.2"
boto3-stubs = {extras = ["s3"], version = "^1.34.34"}
mypy = "^1.8.0"
cryoet-data-portal-neuroglancer = { git = "https://github.com/chanzuckerberg/cryoet-data-portal-neuroglancer.git", tag = "v1.0.1" }
cryoet-data-portal-neuroglancer = { git = "https://github.com/chanzuckerberg/cryoet-data-portal-neuroglancer.git", tag = "v1.2.1"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this now because the version is > 1.2.1

t = time()
print("Start contrast limit computation for", tomogram)
contrast_limits = tomogram.get_contrast_limits()
print("Took", (time() - t), "s")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could combine the print for the computed contrast limit and the time taken into one to reduce the number of prints

@aranega aranega requested a review from seankmartin April 23, 2025 14:25
@aranega aranega marked this pull request as ready for review April 23, 2025 14:25
Copy link
Contributor

@seankmartin seankmartin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@uermel uermel requested review from Bento007 and shlomnissan April 24, 2025 17:06
Copy link
Contributor

@Bento007 Bento007 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you left some debugging code

@@ -174,7 +177,11 @@ def _create_config(self, alignment_metadata_path: str) -> dict[str, Any]:
volume_info = tomogram.get_output_volume_info()
voxel_size = round(volume_info.voxel_size, 3)
resolution = (voxel_size * 1e-10,) * 3
layers = [self._to_tomogram_layer(tomogram, volume_info, resolution)]
t = time()
print("Start contrast limit computation for", tomogram)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to stay in the code? I assume it was here for performance tuning.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Bento007 Thanks for the feedback! Actually, we added some feedbacks as the contrast limit can take a little bit of time depending on the method, or the level of the pyramid that is used as input for the computation. The idea was to not have just the scripts that hangs for few seconds without any information about why it is. If that's something that you feel is not necessary, we can remove it.

Copy link
Contributor

@Bento007 Bento007 Apr 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, you can leave it. It would be worth adding a comment as to why we add this metric, since we aren't doing it anywhere else, but i'll leave that as optional.

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

Successfully merging this pull request may close these issues.

3 participants