-
-
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
xarray potential inconstistencies with cftime #2437
Comments
@sbiner these are all reasonable points of confusion. The current behavior in xarray regarding non-standard calendars is complicated, and we are working toward improving the situation. I've tried to provide a recommended solution based on your example as well as some historical/future context. Apologies for the long-winded answer! RecommendationFor accurate round-tripping of date types, I would recommend that you run your code to open the dataset with the xarray option
Here we can see that the time index is a
Note that
For more information on what is enabled and what is not enabled when using a CFTimeIndex for indexing, see this section in the documentation. Default behaviorThe default behavior can be traced back to the early days of xarray (see the original discussion in #118, #121, and #126). It boils down to coercing any dates decoded into The advantage of the default approach is that, when possible, it allows you to take advantage of all the nice features that a time coordinate indexed by a Connecting back to your example, we can see that if we don't open the dataset with
In this case, as noted above,
Future behaviorIn xarray we are slowly working towards better support for operations involving The two major outstanding issues on this front are probably:
Once those two remaining issues are addressed, one should be able to do most of the significant things one can do with |
@spencerkclark do you think it would make sense to enable cftimeindex by default in the next major xarray release? On the whole I think it's probably a win for usability at this point... |
@spencerkclark I made tests with Thanks for the complete answer. |
@shoyer I agree that seems like a good idea at this stage. Now that there are a number of functions in xarray that do depend differences in dates (as @sbiner notes upsampling with |
With #2516 already in released versions of xarray, and #2593 and #2665 recently merged, this situation has been significantly improved. I think it is safe now to close this general issue. @sbiner thanks for starting this conversation; feel free to post other issues related to cftime if they come up. |
How can I canvert julian to dmy index or datetime in pandas? , I have following dataset |
@hafez-ahmad could you provide more detail about your dataset? Does the |
Here screenshot of my data thank you |
Could you show me what the output of |
@spencerkclark: if the dataset linked to above is a good example, that would be ds.info()
so no |
Thanks @keewis. @hafez-ahmad by Julian date do you mean that the time coordinate represents "days since -4713-01-01T12:00:00" in a Julian calendar? Once we know the units (expressed as units = "days since -4713-01-01T12:00:00"
calendar = "julian"
ds["time"] = ds.time.assign_attrs(units=units, calendar=calendar)
ds = xr.decode_cf(ds) I'll admit though, with the values in your dataset, this assumption produces dates like |
@spencerkclark |
@hafez-ahmad yes, I'm trying to help, but in order to do that I need more information. What does 456852 represent? |
@spencerkclark |
the issue is that without more information (units, reference date, calendar), You will have to check either the data provider's website or contact them and ask for help (it seems they started offering their data as netcdf files about two weeks ago so this might actually be a issue with their conversion code). Once you have that information we can help you with the code necessary to convert using |
I believe the dates assocsiated with this particular dataset are days since "1700-01-01"
ds["time"] = ds.time.assign_attrs(units="days since 1700-01-01")
ds = xr.decode_cf(ds) |
I am trying to use xarray with different types of calendars. I made a few tests and wonder if somebody can help me make sense of the results. In my test, I generate a DataArray
da
time series with a 365_day calendar using cftime. I then write that DataArray in a netCDF file and read it in another DataArrayda2
Code Sample, a copy-pastable example if possible
Problem description
As seen in the code the resampledoes not work for
da
while it does forda2
. The problem is related to the the type ofda.time
which iscftime.DatetimeNoLeap
whileda2.time
is adatetime64
. I thought that xarray is using cftime to make the conversion from time numerical values to dates but it looks to me as if it is not the case.I wonder if this makes sense or if it is something that should eventually be corrected.
INSTALLED VERSIONS
In [6]: print (cftime.version)
1.0.1
xarray: 0.10.8
pandas: 0.23.0
numpy: 1.14.3
scipy: 1.1.0
netCDF4: 1.4.1
h5netcdf: None
h5py: 2.7.1
Nio: None
zarr: None
bottleneck: 1.2.1
cyordereddict: None
dask: 0.17.5
distributed: 1.21.8
matplotlib: 2.2.2
cartopy: None
seaborn: 0.8.1
setuptools: 39.1.0
pip: 10.0.1
conda: 4.5.11
pytest: 3.5.1
IPython: 6.4.0
sphinx: 1.7.4
The text was updated successfully, but these errors were encountered: