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

Interpolation (not centred) #145

Open
rcaneill opened this issue Jul 23, 2019 · 10 comments
Open

Interpolation (not centred) #145

rcaneill opened this issue Jul 23, 2019 · 10 comments
Labels

Comments

@rcaneill
Copy link
Contributor

Hello,
I am trying to figure how to do interpolation that are not centred, e.g. when a "center" point is not at the middle point of 2 "right" points. I tried different ways but I did not manage to find a satisfying way that would fit in the xgcm.Axis class.
My idea was to implement a new function for interpolation between data_left and data_right, taking also a weight representing the distance to the new position for each data, and use it instead of raw_interp_function:

def interp_function(data_left, data_right, weight_left, weight_right):
    return (data_left * weight_left + data_right * weight_right) / (weight_left + weight_right)

For an interpolation from "right" to "center", weights would be (C: "center, R: "right", wl: "weight_left", wr: "weight_right"):

    |-----------------|----------------|----------------|
            C         R           C    R           C    R
                  data_left        data_right           
                       <---------> <--> 
                            wr      wl 

I did not really find how to implement this solution without changing too much code, as I am not yet familiar with xgcm. Maybe it is necessary to reshape some parts.
Does someone has an idea of the rough lines? Or another solution?

@rabernat
Copy link
Contributor

rabernat commented Aug 6, 2019

Hi @rcaneill - thanks for this useful idea.

So far, xgcm only supports grids in which the variables are assumed to be centered. But I know this is not the case for some models, like MOM5 / MOM6. Could you let us know what is your specific use case here?

As you have already seen, the interpolation function is exceedingly simple:

xgcm/xgcm/grid.py

Lines 1249 to 1252 in cac66af

def raw_interp_function(data_left, data_right):
# linear, centered interpolation
# TODO: generalize to higher order interpolation
return 0.5 * (data_left + data_right)

I would definitely be open to extending this to the more general case where the interpolation weights vary spatially. There would be some design questions to answer here, such as

  • Are there any existing metadata standards for providing weights in netCDF files?
  • Where in xgcm's data model should the weights be stored?
  • How should the user-facing API specify these weights?

@rcaneill
Copy link
Contributor Author

Hi,
I am using NEMO in s coordinates, where the vertical variable are not necessarily centered.
I'll think about the design questions and keep you in touch if I find a clean solution.

@github-actions
Copy link

This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!

@github-actions github-actions bot added the Stale label Jun 11, 2021
@github-actions
Copy link

This issue has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details.

@jbusecke
Copy link
Contributor

Can this be achieved in principal with #344 ?

@jbusecke jbusecke reopened this Jun 24, 2021
@github-actions
Copy link

github-actions bot commented Jul 2, 2021

This issue has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details.

@github-actions github-actions bot closed this as completed Jul 2, 2021
@jbusecke
Copy link
Contributor

jbusecke commented Jul 2, 2021

@andersy005 This now seems too early? Shouldnt my post count as activity?

@andersy005
Copy link
Member

@andersy005 This now seems too early? Shouldnt my post count as activity?

You're right... My hunch is that this is related to this bug: actions/stale#509. I will look into it sometime next week.

@andersy005 andersy005 reopened this Jul 4, 2021
@andersy005 andersy005 removed the Stale label Jul 4, 2021
@jbusecke
Copy link
Contributor

jbusecke commented Jul 7, 2021

Thanks @andersy005

@andersy005 andersy005 mentioned this issue Jul 8, 2021
1 task
@github-actions
Copy link

github-actions bot commented Sep 6, 2021

This issue has been marked 'stale' due to lack of recent activity.
If there is no further activity, the issue will be closed in another 30 days.

Thank you for your contribution!

@github-actions github-actions bot added the Stale label Sep 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants