Skip to content

adding granularity#11

Open
MikeLippincott wants to merge 1 commit intoWayScience:mainfrom
MikeLippincott:granularity
Open

adding granularity#11
MikeLippincott wants to merge 1 commit intoWayScience:mainfrom
MikeLippincott:granularity

Conversation

@MikeLippincott
Copy link
Copy Markdown
Member

Description

This PR adds granularity modules. Note that this might fail tests due to not having a key piece of image-loading code that is in another PR.

What kind of change(s) are included?

  • Documentation (changes docs or other related content)
  • Bug fix (fixes an issue).
  • Enhancement (adds functionality).
  • Breaking change (these changes would cause existing functionality to not work as expected).

Checklist

Please ensure that all boxes are checked before indicating that this pull request is ready for review.

  • I have read and followed the CONTRIBUTING.md guidelines.
  • I have searched for existing content to ensure this is not a duplicate.
  • I have performed a self-review of these additions (including spelling, grammar, and related).
  • These changes pass all pre-commit checks.
  • I have added comments to my code to help provide understanding
  • I have added a test which covers the code changes found within this PR
  • I have deleted all non-relevant text in this pull request template.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@MattsonCam
Copy link
Copy Markdown
Member

Are any of these test for granualrity? I'm not seeing any passing test, so if there is a granularity test it either isn't running or it failed

Copy link
Copy Markdown
Member

@MattsonCam MattsonCam left a comment

Choose a reason for hiding this comment

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

LGTM @MikeLippincott , good job! I left a few comments

def compute() -> dict[str, list[float]]:
"""Placeholder for granularity computation implementation."""
raise ZedProfilerError("granularity.compute is not implemented yet")
from zedprofiler.IO.loading_classes import ObjectLoader
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not seeing a src/zedprofiler/IO/ package, so this might raise a ModuleNotFoundError

Comment on lines +153 to +157
Returns
-------
Dict[str, list]
Dictionary with keys 'object_id', 'feature', 'value'.
Image-level measurements use object_id=0.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

From what I understand gs is the image-level granularity, but only per-object granularities (values / gss), feature, and object are returned in this dictionary

Comment on lines +304 to +313
if nobjects > 0:
label_range = numpy.arange(1, nobjects + 1)

# CellProfiler: self.labels[~im.mask] = 0
masked_labels = original_labels.copy()
masked_labels[~original_mask] = 0

per_object_current_mean = _fix_scipy_ndimage_result(
scipy.ndimage.mean(original_pixels, masked_labels, label_range)
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It looks like label_range is used to construct object ids. Will these ids always match correctly? For example, will every value in label_range always correspond to a label that is actually present in masked_labels in this scipy function?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Consider splitting this into helpers such as “subsample”, “background removal”, and “per-object measurement” to make review and future debugging easier

Comment on lines +114 to +116
assert result["object_id"] == [1, 1, 1]
assert result["feature"] == [1, 2, 3]
assert len(result["value"]) == EXPECTED_THREE_SCALES
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It looks like the tests validate shape/length and other integer values. Consider adding a test for numerical correctness of granularity if possible (e.g. my granularity calculation measure the expected granularity calculation)

Comment on lines +242 to +245
back_mask = (
scipy.ndimage.map_coordinates(mask.astype(float), (k, i, j))
> mask_threshold
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It looks like the order is is not specified here, so I think it will be cubic by default. Recommend setting this to a default like the others, such as 0 or 1

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