Skip to content
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

Adding NaN thresholding #32

Closed
kjdoore opened this issue Feb 15, 2024 · 3 comments · Fixed by #41
Closed

Adding NaN thresholding #32

kjdoore opened this issue Feb 15, 2024 · 3 comments · Fixed by #41
Labels
enhancement New feature or request

Comments

@kjdoore
Copy link
Collaborator

kjdoore commented Feb 15, 2024

It would be cool to add the ability to set the NaN thresholding similar to what is done in xESMF. Currently most_common and conservative have a NaN thresholding of 1, but it would be nice if a user could specify this value.

@kjdoore kjdoore added the enhancement New feature or request label Feb 15, 2024
@BSchilperoort
Copy link
Contributor

I am not sure how easy this will be for the conservative method. To make computations fast, we reduce the coordinates one at a time. So we can only define a nan threshold per reduction.

For example, a 3x3 grid is reduced to 1x1:

0, 1, 0
0, 0, 0
0, 0, NaN

First reduce first dim:

0.33,
0,
NaN (or 0)

Then reduce second dim:

NaN (or 0.16)

I guess the NaN threshold here can be 1/9. Which means that for 2 dimensions being reduced the NaN threshold is 1/3 per dimension 🤔

This also means that the for the second reduction the weights have to be adjusted. Currently if you'd not mask the NaNs out, the result would be 0.11 (as the NaN counts for value of 0).

@kjdoore
Copy link
Collaborator Author

kjdoore commented Feb 16, 2024

Yeah, I thought it may complicate the process, especially given the current methodology. I am having trouble thinking of a way to implement this efficiently. Tracking the NaN fraction and adjusting the threshold as you move across dimensions is likely no more efficient that utilizing the traditional methodology of conservative regridding...

@BSchilperoort
Copy link
Contributor

BSchilperoort commented Feb 19, 2024

I think it is possible, but not easy to do, especially if NaNs appear over time on one lat/lon location. There would be additional overhead in the computation too.

If there are just a few NaN values in your data then interpolating those before regridding is probably the best solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants