Skip to content

Commit ee662b4

Browse files
committed
Merge remote-tracking branch 'upstream/master' into yohai-ds_scatter
* upstream/master: Rework whats-new for 0.12 Add whats-new for 0.12.1 Release 0.12.0 enable loading remote hdf5 files (pydata#2782) Push back finalizing deprecations for 0.12 (pydata#2809) Drop failing tests writing multi-dimensional arrays as attributes (pydata#2810) some docs updates (pydata#2746) Add support for cftime.datetime coordinates with coarsen (pydata#2778) Don't use deprecated np.asscalar() (pydata#2800) Improve name concat (pydata#2792) Add `Dataset.drop_dims` (pydata#2767) Quarter offset implemented (base is now latest pydata-master). (pydata#2721) Add use_cftime option to open_dataset (pydata#2759) Bugfix/reduce no axis (pydata#2769) 'standard' now refers to 'gregorian' in cftime_range (pydata#2771)
2 parents 8cd8722 + a5ca64a commit ee662b4

36 files changed

Lines changed: 1568 additions & 428 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ pip-log.txt
3535
.tox
3636
nosetests.xml
3737
.cache
38+
.mypy_cache
3839
.ropeproject/
3940
.tags*
4041
.testmon*

doc/api.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ Dataset contents
8787
Dataset.swap_dims
8888
Dataset.expand_dims
8989
Dataset.drop
90+
Dataset.drop_dims
9091
Dataset.set_coords
9192
Dataset.reset_coords
9293

doc/data-structures.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,13 @@ operations keep around coordinates:
408408
list(ds[['x']])
409409
list(ds.drop('temperature'))
410410
411+
To remove a dimension, you can use :py:meth:`~xarray.Dataset.drop_dims` method.
412+
Any variables using that dimension are dropped:
413+
414+
.. ipython:: python
415+
416+
ds.drop_dims('time')
417+
411418
As an alternate to dictionary-like modifications, you can use
412419
:py:meth:`~xarray.Dataset.assign` and :py:meth:`~xarray.Dataset.assign_coords`.
413420
These methods return a new dataset with additional (or replaced) or values:

doc/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Documentation
5252
* :doc:`reshaping`
5353
* :doc:`combining`
5454
* :doc:`time-series`
55+
* :doc:`weather-climate`
5556
* :doc:`pandas`
5657
* :doc:`io`
5758
* :doc:`dask`
@@ -70,6 +71,7 @@ Documentation
7071
reshaping
7172
combining
7273
time-series
74+
weather-climate
7375
pandas
7476
io
7577
dask

doc/indexing.rst

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ arrays). However, you can do normal indexing with dimension names:
229229
Using indexing to *assign* values to a subset of dataset (e.g.,
230230
``ds[dict(space=0)] = 1``) is not yet supported.
231231

232-
Dropping labels
233-
---------------
232+
Dropping labels and dimensions
233+
------------------------------
234234

235235
The :py:meth:`~xarray.Dataset.drop` method returns a new object with the listed
236236
index labels along a dimension dropped:
@@ -241,6 +241,13 @@ index labels along a dimension dropped:
241241
242242
``drop`` is both a ``Dataset`` and ``DataArray`` method.
243243

244+
Use :py:meth:`~xarray.Dataset.drop_dims` to drop a full dimension from a Dataset.
245+
Any variables with these dimensions are also dropped:
246+
247+
.. ipython:: python
248+
249+
ds.drop_dims('time')
250+
244251
245252
.. _masking with where:
246253

doc/io.rst

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
.. _io:
22

3-
Serialization and IO
4-
====================
3+
Reading and writing files
4+
=========================
55

66
xarray supports direct serialization and IO to several file formats, from
77
simple :ref:`io.pickle` files to the more flexible :ref:`io.netcdf`
8-
format.
8+
format (recommended).
99

1010
.. ipython:: python
1111
:suppress:
@@ -739,11 +739,14 @@ options are listed on the PseudoNetCDF page.
739739
.. _PseudoNetCDF: http://github.com/barronh/PseudoNetCDF
740740

741741

742-
Formats supported by Pandas
743-
---------------------------
742+
CSV and other formats supported by Pandas
743+
-----------------------------------------
744744

745745
For more options (tabular formats and CSV files in particular), consider
746746
exporting your objects to pandas and using its broad range of `IO tools`_.
747+
For CSV files, one might also consider `xarray_extras`_.
748+
749+
.. _xarray_extras: https://xarray-extras.readthedocs.io/en/latest/api/csv.html
747750

748751
.. _IO tools: http://pandas.pydata.org/pandas-docs/stable/io.html
749752

doc/plotting.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ For more extensive plotting applications consider the following projects:
4040
data structures for building even complex visualizations easily." Includes
4141
native support for xarray objects.
4242

43+
- `hvplot <https://hvplot.pyviz.org/>`_: ``hvplot`` makes it very easy to produce
44+
dynamic plots (backed by ``Holoviews`` or ``Geoviews``) by adding a ``hvplot``
45+
accessor to DataArrays.
46+
4347
- `Cartopy <http://scitools.org.uk/cartopy/>`_: Provides cartographic
4448
tools.
4549

doc/related-projects.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Geosciences
1313
- `aospy <https://aospy.readthedocs.io>`_: Automated analysis and management of gridded climate data.
1414
- `infinite-diff <https://github.com/spencerahill/infinite-diff>`_: xarray-based finite-differencing, focused on gridded climate/meterology data
1515
- `marc_analysis <https://github.com/darothen/marc_analysis>`_: Analysis package for CESM/MARC experiments and output.
16+
- `MetPy <https://unidata.github.io/MetPy/dev/index.html>`_: A collection of tools in Python for reading, visualizing, and performing calculations with weather data.
1617
- `MPAS-Analysis <http://mpas-analysis.readthedocs.io>`_: Analysis for simulations produced with Model for Prediction Across Scales (MPAS) components and the Accelerated Climate Model for Energy (ACME).
1718
- `OGGM <http://oggm.org/>`_: Open Global Glacier Model
1819
- `Oocgcm <https://oocgcm.readthedocs.io/>`_: Analysis of large gridded geophysical datasets

doc/time-series.rst

Lines changed: 0 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -212,140 +212,3 @@ Data that has indices outside of the given ``tolerance`` are set to ``NaN``.
212212
213213
For more examples of using grouped operations on a time dimension, see
214214
:ref:`toy weather data`.
215-
216-
217-
.. _CFTimeIndex:
218-
219-
Non-standard calendars and dates outside the Timestamp-valid range
220-
------------------------------------------------------------------
221-
222-
Through the standalone ``cftime`` library and a custom subclass of
223-
:py:class:`pandas.Index`, xarray supports a subset of the indexing
224-
functionality enabled through the standard :py:class:`pandas.DatetimeIndex` for
225-
dates from non-standard calendars commonly used in climate science or dates
226-
using a standard calendar, but outside the `Timestamp-valid range`_
227-
(approximately between years 1678 and 2262).
228-
229-
.. note::
230-
231-
As of xarray version 0.11, by default, :py:class:`cftime.datetime` objects
232-
will be used to represent times (either in indexes, as a
233-
:py:class:`~xarray.CFTimeIndex`, or in data arrays with dtype object) if
234-
any of the following are true:
235-
236-
- The dates are from a non-standard calendar
237-
- Any dates are outside the Timestamp-valid range.
238-
239-
Otherwise pandas-compatible dates from a standard calendar will be
240-
represented with the ``np.datetime64[ns]`` data type, enabling the use of a
241-
:py:class:`pandas.DatetimeIndex` or arrays with dtype ``np.datetime64[ns]``
242-
and their full set of associated features.
243-
244-
For example, you can create a DataArray indexed by a time
245-
coordinate with dates from a no-leap calendar and a
246-
:py:class:`~xarray.CFTimeIndex` will automatically be used:
247-
248-
.. ipython:: python
249-
250-
from itertools import product
251-
from cftime import DatetimeNoLeap
252-
dates = [DatetimeNoLeap(year, month, 1) for year, month in
253-
product(range(1, 3), range(1, 13))]
254-
da = xr.DataArray(np.arange(24), coords=[dates], dims=['time'], name='foo')
255-
256-
xarray also includes a :py:func:`~xarray.cftime_range` function, which enables
257-
creating a :py:class:`~xarray.CFTimeIndex` with regularly-spaced dates. For
258-
instance, we can create the same dates and DataArray we created above using:
259-
260-
.. ipython:: python
261-
262-
dates = xr.cftime_range(start='0001', periods=24, freq='MS', calendar='noleap')
263-
da = xr.DataArray(np.arange(24), coords=[dates], dims=['time'], name='foo')
264-
265-
For data indexed by a :py:class:`~xarray.CFTimeIndex` xarray currently supports:
266-
267-
- `Partial datetime string indexing`_ using strictly `ISO 8601-format`_ partial
268-
datetime strings:
269-
270-
.. ipython:: python
271-
272-
da.sel(time='0001')
273-
da.sel(time=slice('0001-05', '0002-02'))
274-
275-
- Access of basic datetime components via the ``dt`` accessor (in this case
276-
just "year", "month", "day", "hour", "minute", "second", "microsecond",
277-
"season", "dayofyear", and "dayofweek"):
278-
279-
.. ipython:: python
280-
281-
da.time.dt.year
282-
da.time.dt.month
283-
da.time.dt.season
284-
da.time.dt.dayofyear
285-
da.time.dt.dayofweek
286-
287-
- Group-by operations based on datetime accessor attributes (e.g. by month of
288-
the year):
289-
290-
.. ipython:: python
291-
292-
da.groupby('time.month').sum()
293-
294-
- Interpolation using :py:class:`cftime.datetime` objects:
295-
296-
.. ipython:: python
297-
298-
da.interp(time=[DatetimeNoLeap(1, 1, 15), DatetimeNoLeap(1, 2, 15)])
299-
300-
- Interpolation using datetime strings:
301-
302-
.. ipython:: python
303-
304-
da.interp(time=['0001-01-15', '0001-02-15'])
305-
306-
- Differentiation:
307-
308-
.. ipython:: python
309-
310-
da.differentiate('time')
311-
312-
- Serialization:
313-
314-
.. ipython:: python
315-
316-
da.to_netcdf('example-no-leap.nc')
317-
xr.open_dataset('example-no-leap.nc')
318-
319-
- And resampling along the time dimension for data indexed by a :py:class:`~xarray.CFTimeIndex`:
320-
321-
.. ipython:: python
322-
323-
da.resample(time='81T', closed='right', label='right', base=3).mean()
324-
325-
.. note::
326-
327-
328-
For some use-cases it may still be useful to convert from
329-
a :py:class:`~xarray.CFTimeIndex` to a :py:class:`pandas.DatetimeIndex`,
330-
despite the difference in calendar types. The recommended way of doing this
331-
is to use the built-in :py:meth:`~xarray.CFTimeIndex.to_datetimeindex`
332-
method:
333-
334-
.. ipython:: python
335-
:okwarning:
336-
337-
modern_times = xr.cftime_range('2000', periods=24, freq='MS', calendar='noleap')
338-
da = xr.DataArray(range(24), [('time', modern_times)])
339-
da
340-
datetimeindex = da.indexes['time'].to_datetimeindex()
341-
da['time'] = datetimeindex
342-
343-
However in this case one should use caution to only perform operations which
344-
do not depend on differences between dates (e.g. differentiation,
345-
interpolation, or upsampling with resample), as these could introduce subtle
346-
and silent errors due to the difference in calendar types between the dates
347-
encoded in your data and the dates stored in memory.
348-
349-
.. _Timestamp-valid range: https://pandas.pydata.org/pandas-docs/stable/timeseries.html#timestamp-limitations
350-
.. _ISO 8601-format: https://en.wikipedia.org/wiki/ISO_8601
351-
.. _partial datetime string indexing: https://pandas.pydata.org/pandas-docs/stable/timeseries.html#partial-string-indexing

0 commit comments

Comments
 (0)