Skip to content

Conversation

@sol1105
Copy link
Contributor

@sol1105 sol1105 commented Aug 12, 2025

Enabling target masks for LocStream input

  • For LocStream input or output, masks are generally filtered/ignored and not handed to ESMF, as ESMF apparently crashes in that case
  • This PR adds the new function xesmf.smm.post_apply_target_mask_to_weights to zero out weights of masked target grid cells post weight generation
  • The weights are automatically adjusted with above new function in BaseRegridder in the case of all the following conditions being True:
    • LocStream input
    • Grid output
    • grid_out having a mask defined
    • method set to nearest_s2d (for LocStream input, the only other option would anyways only be nearest_d2s)
  • This may lead to unexpected results when not using with nearest_s2d, which is why the automatic application is restricted to that method. To my understanding, as the masking is applied post weight generation, the resulting weights may differ from the "masking during the weights generation" if the mapping between source <--> target may be influenced by the location of masked cells. But this would be the case for nearest_d2s.

I set this up to allow making use of land-sea-masks when remapping from unstructured grids with the "trick" described in #115 - without land-sea-mask there was undesired extrapolation happening outside the source domain:

Scatter plot of source grid cell locations (AWI-CM-1-1-MR FESOM unstructured ocean model grid)

image

Remapped result before - even when target mask was defined (nearest_s2d)

image

Remapped result after - with target mask defined (nearest_s2d)

image

- Adding function xesmf.smm.post_apply_target_mask_to_weights
  to zero out weights of masked target grid cells
- Adding application of this function to BaseRegridder in the case
  of LocStream input, Grid output incl. mask
- This may lead to unexpected results when not using with nearest_s2d,
  as the masking is applied *post* weight generation
@sol1105
Copy link
Contributor Author

sol1105 commented Sep 4, 2025

Hi, I just wanted to confirm, the two PRs I opened (#444 and #445) are ready for review from my side. Whenever it’s convenient on your end. Thanks a lot!

@raphaeldussin
Copy link
Contributor

@sol1105 thank you for these 2 contribs, this looks very useful and I'll take a deeper look at the code later next week when I'm back from leave.

Copy link
Collaborator

@aulemahal aulemahal left a comment

Choose a reason for hiding this comment

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

This looks good to me!

AFAIU, the only methods available when starting from a LocStream are the two nearest directions. And this method wouldn't make sense for "d2s", indeed, so this implementation seems to cover "all" meaningful cases.

@aulemahal
Copy link
Collaborator

Ah and same comment as the other PR, could you please add a changelog line ?

@sol1105
Copy link
Contributor Author

sol1105 commented Oct 15, 2025

@aulemahal Thanks for dealing with the failing test. When this is merged I can sort out the merge conflicts for #444

Currently, there is still the cf_xarray pin set in requirements.txt and ci/environment.yml

@aulemahal aulemahal merged commit 336424a into pangeo-data:master Oct 15, 2025
12 checks passed
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