-
-
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
holoviews / bokeh doesn't like cftime coords #2164
Comments
Thanks for the detailed example, I've been able to reproduce the issue. Part of it is that we need to add the new type(s) to |
I agree it would be very nice to enable plotting data with |
I encountered this problem right now with the xarray built-in plotting. Does anybody know a workaround for the xarray plotting by any chance? |
@jbusecke I recently stumbled upon https://github.com/SciTools/nc-time-axis. You can install it through conda-forge:
However, for now you won't be able to use xarray's built in plotting, since xarray will raise an error if you try to plot anything with coordinates that aren't numeric or of type |
Darn. Just when I thought the time stuff was sorted. This is (yet another) deal breaker as far as recommending mass adoption goes. Is there an estimate when, or if, |
@aidanheerdegen -- support for unconventional time coordinates (via cftime) is not a trivial problem--there are many special cases and complex logic to deal with. Rather than being discouraged by this bug, I encourage you to take a longer view to see how much this support has improved over the past year. One year ago, xarray could not have decoded this time coordinate at all! I'm curious what you are referring to with your comment about "mass adoption." To whom are you making recommendations about adoption of xarray? And what do you consider the numerous other dealbreakers to be? I hope you see that these blanket comments could be read as quite discouraging and negative to the volunteer developers working hard on xarray.
The work on cftimeindex is being done entirely on a volunteer basis by graduate students like @spencerkclark (👏 👏 👏). In order to make xarray development progress faster, we need more contributors to the project. In my view, the ideal place to recruit such contributors is from within the paid computational support staff from major climate modeling centers. These people are ideally poised to understand what features are most important to users, and they are actually paid to help develop tools (like xarray) to help users be more productive. We recently created a contributor guide to make it easier for new contributors to come on board. If you can think of anyone who might be interested in contributing to xarray, please let us know, either here or via a private channel. |
Hi @rabernat, I apologise if what I said is discouraging. I didn't intend it that way. It was the result of exasperation, as I think array is a fantastic tool, and I thought with the development of cftime support all barriers to widespread adoption had pretty much been overcome. When I said "another" it was in reference to the previous barrier of not supporting long time, or old time, indices which had since been overcome As far as recommending, it is to the researchers at the centre of excellence where I am one of the people who is paid to support climate models and the support infrastructure to run and analyse their outputs. I guess I've outed myself as one of those paid computational support staff you referred to. My initial comment above was a clumsy attempt to highlight what I thought was an important feature to support to further increase xarray adoption. From my perspective as someone who has to support users I'm often having to decide what I think the majority of users will be able to use efficiently, taking into account very wide levels of expertise and motivation. Before the cftime upgrades I did not wholeheartedly evangelise for xarray adoption because I knew there were many cases where it was not simple and easy to use. For every edge and corner case I have to support users when they encounter them. In some ways, having a tool that can do such amazing things as xarray, but which don't work in some circumstances for some datasets is very frustrating for users. It can take a lot of work to find out what doesn't work. Having said which, we're currently doing half way through a 2 hour training session for xarray for researchers in the CoE who are interested, but not being able to easily plot cftime datasets will harm adoption, and all those who are volunteering their time developing xarray want it to be adopted as widely as possible right? Thanks for the pointer to the contributor guide, I did read it, and I will try and find some time to make a positive contribution to xarray. I had started down that path already (#2244) |
Thanks for your follow up comment. I understand much better where you are coming from now! We do sincerely appreciate your feedback and contributions. Yes: we definitely want xarray to be adopted widely! There is no doubt that these weird calendars are a continuous source of frustration. The challenge is compounded by the fast that, basically, only the climate community needs them. All of the fancy time indexing stuff in pandas is most likely there because of its value to the finance community. Maybe a good path forward would be for @spencerkclark to outline what steps might be needed to get xarray's built in plotting to work with cftimeindex. That way, anyone who urgently needs this feature has some sort of roadmap for starting to implement it themselves. |
Sounds like a great idea. |
I think a quick and dirty fix could be to add nc-time-axis as an optional dependency, and convert any But I wonder if there is potentially room for improvement upstream in cftime? Should we need to convert to these proxy objects before plotting or might there be a way to make cftime objects themselves more friendly to use with matplotlib? That could have benefits for multiple libraries (not just xarray). @pelson @lbdreyer @ocefpaf (developers of nc-time-axis and Iris) -- it seems you have grappled with this problem a fair bit already. Have you thought about those questions before? |
From a cursory examination, it sure looks (to me) that |
Why a separate package and not in nc-time-axis? (Or alternatively, just in cftime, as you say) FWIW SciTools/nc-time-axis#16 tried to get the ball rolling on clarifications around the CalendarDateTime object. That was necessary in the days when there was a single PhoneyDateTime object, that didn't have calendar information associated with it. It seems that some refactoring is very plausible in nc-time-axis at this point. |
Yes, of course, that would probably be preferred. 👍 |
Thanks @pelson, that's good to hear that you would be open to someone doing some refactoring in nc-time-axis. @rabernat @aidanheerdegen @jbusecke I think the cleanest approach for someone interested in fixing the built-in plotting issue then would be to engage with the nc-time-axis folks to see if there is a way to enable plotting with |
For those interested in this topic, see SciTools/nc-time-axis#42. I'll also note that @philippjfr has already added support for plotting cftime types in holoviews, holoviz/holoviews#2728, making use of the |
I have taken a swing at restoring the internal plotting capabilities in #2665. |
Code Sample, a copy-pastable example if possible
Consider a simple working example of converting an xarray dataset to holoviews for plotting:
This gives
and
Problem description
Now change
ref_date = '0181-01-01'
(or anything outside of the valid range for regular pandas datetime index). We get a beautiful new cftimeindexbut holoviews / bokeh doesn't like it
Similar but slightly different errors arise for different holoviews types (e.g.
hv.Image
) and contexts (using time as a holoviews kdim).Expected Output
This should work.
I'm not sure if this is really an xarray problem. Maybe it needs a fix in holoviews (or bokeh). But I'm raising it here first since clearly we have introduced this new wrinkle in the stack. Cc'ing @philippjfr since he is the expert on all things holoviews.
Output of
xr.show_versions()
xarray: 0.10.4
pandas: 0.23.0
numpy: 1.14.3
scipy: 1.1.0
netCDF4: 1.4.0
h5netcdf: None
h5py: None
Nio: None
zarr: 2.2.0
bottleneck: None
cyordereddict: None
dask: 0.17.5
distributed: 1.21.8
matplotlib: 2.2.2
cartopy: None
seaborn: None
setuptools: 39.0.1
pip: 10.0.1
conda: 4.3.34
pytest: 3.5.1
IPython: 6.3.1
sphinx: None
The text was updated successfully, but these errors were encountered: