-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Keep attrs & Add a 'keep_coords' argument to Dataset.apply #688
Comments
I would be fine with a I'm wary of always keeping coordinates, because some applied operations could make existing coordinates no longer valid. For example, suppose you want to use pandas's faster time-resampling, i.e., |
Great @shoyer, agreed |
Also |
Is there plans for a 'keep_coords' for Dataset.resample as well? |
@snowman2 Possibly yes, though we would want to think through the use-cases for this first. Arguably, you should explicitly preserve coordinates in your custom callable instead. |
You could do it in the custom callable, but it requires less expertise and fewer lines of code to add that as an option. The use case I have is land surface model output with x,y coordinates that I would like to preserve. |
@snowman2 Can you give a concrete example of the sort of function you would want to apply? |
I need input data for a hydrology model in an hourly timestep. So, I use the |
@snowman2 I tried to reproduce your issue, but I couldn't make In [21]: ds = xarray.tutorial.load_dataset('rasm')
In [22]: ds.resample('AS', 'time', how=np.sum)
Out[22]:
<xarray.Dataset>
Dimensions: (time: 4, x: 275, y: 205)
Coordinates:
yc (y, x) float64 16.53 16.78 17.02 17.27 17.51 17.76 18.0 18.25 ...
xc (y, x) float64 189.2 189.4 189.6 189.7 189.9 190.1 190.2 190.4 ...
* time (time) datetime64[ns] 1980-01-01 1981-01-01 1982-01-01 1983-01-01
Dimensions without coordinates: x, y
Data variables:
Tair (time, y, x) float64 nan nan nan nan nan nan nan nan nan nan ... |
@shoyer, thanks for looking into it. I am resampling from 3hr data to 1hr data. resampled_ds = ds.resample('1H', dim='time', keep_attrs=True) I am using it here: I ran into the issue there and had to add code to make sure the coordinates were copied. Thanks! |
@snowman2 can you print an example of what |
Strange. But I can't seem to re-produce the issue. Maybe it was on a Windows machine or maybe it is fixed now. |
In order to maintain a list of currently relevant issues, we mark issues as stale after a period of inactivity If this issue remains relevant, please comment here or remove the |
Closing as stale |
Generally this isn't a problem, since the coords are carried over by the resulting
DataArray
s:But if there's an operation that removes the coords from the
DataArray
s, the coords are not there on the result (noticec
below).Should the
Dataset
retain them? Either always or with akeep_coords
argument, similar tokeep_attrs
.The text was updated successfully, but these errors were encountered: