Skip to content

Use scipy distance_transform_edt to replace slow loop#947

Open
trhille wants to merge 1 commit intoMPAS-Dev:mainfrom
trhille:landice/speed_up_distance_calculation
Open

Use scipy distance_transform_edt to replace slow loop#947
trhille wants to merge 1 commit intoMPAS-Dev:mainfrom
trhille:landice/speed_up_distance_calculation

Conversation

@trhille
Copy link
Copy Markdown
Collaborator

@trhille trhille commented Mar 25, 2026

Use scipy distance_transform_edt to replace slow loop, speeding up get_dist_to_edge_and_gl by orders of magnitude.

Checklist

  • Document (in a comment titled Testing in this PR) any testing that was used to verify the changes

@trhille
Copy link
Copy Markdown
Collaborator Author

trhille commented Mar 25, 2026

Testing

Testing on 8–30km Antarctica mesh.
With these changes: compass.landice.mesh.get_dist_to_edge_and_gl() took 0.05 seconds
With previous: compass.landice.mesh.get_dist_to_edge_and_gl() took 57.52 seconds

The resulting meshes differ by a few cells, so I can't directly difference them. Visually, they are very similar but not identical. Left is using main, right is using these changes:
image

I've saved out the arrays dist_to_edge and dist_to_grounding_line in each branch. RMSE and MAE for dist_to_edge are 0.0012467 and 0.00038777, respectively. For dist_to_grounding_line, RMSE and MAE are 0.00077373 and 0.0001492. For reference, distances range up to 200000.

@matthewhoffman matthewhoffman added land ice in progress This PR is not ready for review or merging labels Mar 29, 2026
@matthewhoffman matthewhoffman marked this pull request as draft March 29, 2026 16:46
@trhille trhille removed in progress This PR is not ready for review or merging labels Apr 3, 2026
Use scipy distance_transform_edt to replace slow loop, speeding up
get_dist_to_edge_and_gl by orders of magnitude.
@trhille trhille force-pushed the landice/speed_up_distance_calculation branch from 28b2391 to 88f5191 Compare April 3, 2026 04:12
@trhille
Copy link
Copy Markdown
Collaborator Author

trhille commented Apr 3, 2026

After rebasing onto main to include changes from #935, differences are still small, with MAE of 0.00038777 and 0.00034768 and RMSE of 0.0012467 and 0.0011817 for dist_to_edge and dist_to_grounding_line, respectively. Cell spacing looks slightly different from before #935 was merged, but still very similar to each other.
image

@trhille trhille marked this pull request as ready for review April 3, 2026 04:13
@trhille trhille requested a review from matthewhoffman April 3, 2026 04:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants