Skip to content

add neighbors module#13

Open
MikeLippincott wants to merge 2 commits intoWayScience:mainfrom
MikeLippincott:neighbors
Open

add neighbors module#13
MikeLippincott wants to merge 2 commits intoWayScience:mainfrom
MikeLippincott:neighbors

Conversation

@MikeLippincott
Copy link
Copy Markdown
Member

Description

This PR adds the neighbors module/

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.

Copy link
Copy Markdown
Member

@axiomcura axiomcura left a comment

Choose a reason for hiding this comment

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

LGTM! left some comments!

Comment on lines +388 to +393
max_distance = numpy.percentile(
distances, 95
) # Use 95 percentile to avoid outliers
# max_distance = numpy.max(distances)
max_distance = numpy.max(distances)
if max_distance == 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.

Is this intentional, or is the percentile calculation meant to be used? Because max_distance gets overwritten.



def classify_cells_into_shells(
coords: pandas.DataFrame or dict,
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 think you meant this?

Suggested change
coords: pandas.DataFrame or dict,
coords: pandas.DataFrame | dict,

Comment on lines +216 to +220
object_mask = nuclei_mask.copy()
object_mask[object_mask != obj_id] = 0
object_mask[object_mask == obj_id] = 1
# Get the centroid of the object
z, y, x = numpy.where(object_mask == 1)
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 don't think the copy is necessary. you can get away by doing this. Please double check c:

Suggested change
object_mask = nuclei_mask.copy()
object_mask[object_mask != obj_id] = 0
object_mask[object_mask == obj_id] = 1
# Get the centroid of the object
z, y, x = numpy.where(object_mask == 1)
z, y, x = numpy.where(nuclei_mask == obj_id)

Comment on lines +305 to +310
distances = numpy.array(
[
numpy.sqrt((coord - centroid).T @ inv_cov @ (coord - centroid))
for coord in coords
]
)
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.

Doing it in a for loops is really slow. Here's a fater alternative.

Suggested change
distances = numpy.array(
[
numpy.sqrt((coord - centroid).T @ inv_cov @ (coord - centroid))
for coord in coords
]
)
diff = coords - centroid
distances = numpy.sqrt(numpy.einsum("ij,jk,ik->i", diff, inv_cov, diff))

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