-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Shape preserving diff
via new keywords
#1332
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
Comments
Would it fill the same need to add a wrapped version of |
FYI @pwolfram, if you are interested in more "grid-aware" finite differencing, you might have a look at xgcm. We are working on it again and have implemented some basic difference and interpolation operators: |
@shoyer, I'm not sure we want to wrap Fundamentally, I want something that is like an inverse of |
Maybe for the xarray community, but not the xgcm community ;) We definitely want round-trip-compatibly diff and cumsum operations (see xgcm/xgcm#49, which is very close to implemented) |
@rabernat, do you think that the proposed keyword additions should be included in xarray or not? I personally would like to see them in xarray but don't know if it is just me or not. If you think they should be in xarray, are you ok with the api above? |
Certainly grid-aware differencing and integral operators are preferred when the grid information is known and available, but I'm not sure that therefore a more naive version akin to np.gradient would not be useful. It's quite likely that there are xarray users (e.g. in non climate/weather/ocean-related fields) wherein a 'c' grid is meaningless to them, yet they still would appreciate being able to easily compute derivatives via xarray operations. But then we're back to the valid questions raised before re: what is the appropriate scope of xarray functionality, c.f. #1288 (comment) and subsequent in that thread |
As I mentioned in #1288, I think basic functionality like I recall now that people have requested similar functionality for |
If you are going to have I also agree we should copy numpy wherever possible. |
I'm not sure where we stand on this issue, but I think since On the same topic, it bothers me that |
I agree that we should have a "middle" or "centered" option for xarray.diff.
…On Mon, Sep 3, 2018 at 9:14 AM T. Chor ***@***.***> wrote:
I'm not sure where we stand on this issue, but I think since
numpy.gradient already exists, it makes more sense to wrap that function
for the sake of simplicity instead of making xr.diff differ from the
original premise of np.diff.
On the same topic, it bothers me that xr.diff only accepts "upper" and
"lower" arguments for the label. The most obvious (and useful) value in
my opinion would be "middle", which would correspond to a centered finite
differences. Is there any special reason why that option isn't there?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1332 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABKS1pWdcdpNtLK18J8v6z8AimuBryT_ks5uXVV3gaJpZM4Mq3x->
.
|
Currently, an operation such as
ds.diff('x')
will result in a smaller size dimension, e.g.,However, there are cases where the same size would be beneficial to keep so that you would get
Is there interest in addition of a
preserve_shape=True
keyword such that it results in this shape-preserving behavior? I'm proposing you could use this withlabel='upper'
andlabel='lower'
.empty_value
could be a value orempty_index
could be an index for the fill value. Ifempty_value=None
andempty_index=None
, it would produce anan
.The reason I'm asking the community is because this is at least the second time I've encountered an application where this behavior would be helpful, e.g., computing ocean layer thicknesses from bottom depths. A previous application was computation of a time step from time slice output and the desire to use this product in an approximated integral, e.g.,
where
y
andt
are both of sizen
, which is effectively a left-sided Riemann sum.The text was updated successfully, but these errors were encountered: