Skip to content

Commit b5653a0

Browse files
author
dcherian
committed
Merge branch 'master' into yohai-ds_scatter
* master: Remove broken Travis-CI builds (pydata#2661) Type checking with mypy (pydata#2655) Added Coarsen (pydata#2612) Improve test for GH 2649 (pydata#2654) revise top-level package description (pydata#2430) Convert ref_date to UTC in encode_cf_datetime (pydata#2651) Change an `==` to an `is`. Fix tests so that this won't happen again. (pydata#2648) ENH: switch Dataset and DataArray to use explicit indexes (pydata#2639) Use pycodestyle for lint checks. (pydata#2642) Switch whats-new for 0.11.2 -> 0.11.3 DOC: document v0.11.2 release Use built-in interp for interpolation with resample (pydata#2640) BUG: pytest-runner no required for setup.py (pydata#2643)
2 parents faf4302 + 6795fd0 commit b5653a0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1022
-496
lines changed

.pep8speaks.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
# File : .pep8speaks.yml
22

3+
# This should be kept in sync with the duplicate config in the [pycodestyle]
4+
# block of setup.cfg.
5+
36
scanner:
4-
diff_only: True # If True, errors caused by only the patch are shown
7+
diff_only: False # If True, errors caused by only the patch are shown
58

69
pycodestyle:
710
max-line-length: 79
811
ignore: # Errors and warnings to ignore
9-
- E402, # module level import not at top of file
10-
- E731, # do not assign a lambda expression, use a def
11-
- W503 # line break before binary operator
12-
- W504 # line break after binary operator
12+
- E402 # module level import not at top of file
13+
- E731 # do not assign a lambda expression, use a def
14+
- E741 # ambiguous variable name
15+
- W503 # line break before binary operator
16+
- W504 # line break after binary operator

.travis.yml

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,52 +17,35 @@ matrix:
1717
- env:
1818
- CONDA_ENV=py36
1919
- EXTRA_FLAGS="--run-flaky --run-network-tests"
20-
- env: CONDA_ENV=py36-netcdf4-dev
21-
addons:
22-
apt_packages:
23-
- libhdf5-serial-dev
24-
- netcdf-bin
25-
- libnetcdf-dev
2620
- env: CONDA_ENV=py36-dask-dev
2721
- env: CONDA_ENV=py36-pandas-dev
2822
- env: CONDA_ENV=py36-bottleneck-dev
29-
- env: CONDA_ENV=py36-condaforge-rc
30-
- env: CONDA_ENV=py36-pynio-dev
3123
- env: CONDA_ENV=py36-rasterio
3224
- env: CONDA_ENV=py36-zarr-dev
3325
- env: CONDA_ENV=docs
34-
- env: CONDA_ENV=flake8
26+
- env: CONDA_ENV=lint
3527
- env: CONDA_ENV=py36-hypothesis
3628

3729
allow_failures:
3830
- env:
3931
- CONDA_ENV=py36
4032
- EXTRA_FLAGS="--run-flaky --run-network-tests"
41-
- env: CONDA_ENV=py36-netcdf4-dev
42-
addons:
43-
apt_packages:
44-
- libhdf5-serial-dev
45-
- netcdf-bin
46-
- libnetcdf-dev
4733
- env: CONDA_ENV=py36-pandas-dev
4834
- env: CONDA_ENV=py36-bottleneck-dev
49-
- env: CONDA_ENV=py36-condaforge-rc
50-
- env: CONDA_ENV=py36-pynio-dev
5135
- env: CONDA_ENV=py36-zarr-dev
5236

5337
before_install:
54-
- wget http://repo.continuum.io/miniconda/Miniconda3-3.16.0-Linux-x86_64.sh -O miniconda.sh;
38+
- wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
5539
- bash miniconda.sh -b -p $HOME/miniconda
5640
- export PATH="$HOME/miniconda/bin:$PATH"
5741
- hash -r
5842
- conda config --set always_yes yes --set changeps1 no --set show_channel_urls true
59-
- conda update -q conda
6043
- conda info -a
6144

6245
install:
6346
- if [[ "$CONDA_ENV" == "docs" ]]; then
6447
conda env create -n test_env --file doc/environment.yml;
65-
elif [[ "$CONDA_ENV" == "flake8" ]]; then
48+
elif [[ "$CONDA_ENV" == "lint" ]]; then
6649
conda env create -n test_env --file ci/requirements-py37.yml;
6750
else
6851
conda env create -n test_env --file ci/requirements-$CONDA_ENV.yml;
@@ -79,8 +62,8 @@ script:
7962
- if [[ "$CONDA_ENV" == "docs" ]]; then
8063
conda install -c conda-forge sphinx sphinx_rtd_theme sphinx-gallery numpydoc;
8164
sphinx-build -n -j auto -b html -d _build/doctrees doc _build/html;
82-
elif [[ "$CONDA_ENV" == "flake8" ]]; then
83-
flake8 xarray ;
65+
elif [[ "$CONDA_ENV" == "lint" ]]; then
66+
pycodestyle xarray ;
8467
elif [[ "$CONDA_ENV" == "py36-hypothesis" ]]; then
8568
pytest properties ;
8669
else

README.rst

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,34 @@ xarray: N-D labeled arrays and datasets
1818
.. image:: https://img.shields.io/badge/powered%20by-NumFOCUS-orange.svg?style=flat&colorA=E1523D&colorB=007D8A
1919
:target: http://numfocus.org
2020

21-
**xarray** (formerly **xray**) is an open source project and Python package that aims to bring the
22-
labeled data power of pandas_ to the physical sciences, by providing
23-
N-dimensional variants of the core pandas data structures.
24-
25-
Our goal is to provide a pandas-like and pandas-compatible toolkit for
26-
analytics on multi-dimensional arrays, rather than the tabular data for which
27-
pandas excels. Our approach adopts the `Common Data Model`_ for self-
28-
describing scientific data in widespread use in the Earth sciences:
29-
``xarray.Dataset`` is an in-memory representation of a netCDF file.
30-
21+
**xarray** (formerly **xray**) is an open source project and Python package
22+
that makes working with labelled multi-dimensional arrays simple,
23+
efficient, and fun!
24+
25+
Multi-dimensional (a.k.a. N-dimensional, ND) arrays (sometimes called
26+
"tensors") are an essential part of computational science.
27+
They are encountered in a wide range of fields, including physics, astronomy,
28+
geoscience, bioinformatics, engineering, finance, and deep learning.
29+
In Python, NumPy_ provides the fundamental data structure and API for
30+
working with raw ND arrays.
31+
However, real-world datasets are usually more than just raw numbers;
32+
they have labels which encode information about how the array values map
33+
to locations in space, time, etc.
34+
35+
By introducing *dimensions*, *coordinates*, and *attributes* on top of raw
36+
NumPy-like arrays, xarray is able to understand these labels and use them to
37+
provide a more intuitive, more concise, and less error-prone experience.
38+
Xarray also provides a large and growing library of functions for advanced
39+
analytics and visualization with these data structures.
40+
Xarray was inspired by and borrows heavily from pandas_, the popular data
41+
analysis package focused on labelled tabular data.
42+
Xarray can read and write data from most common labeled ND-array storage
43+
formats and is particularly tailored to working with netCDF_ files, which were
44+
the source of xarray's data model.
45+
46+
.. _NumPy: http://www.numpy.org/
3147
.. _pandas: http://pandas.pydata.org
32-
.. _Common Data Model: http://www.unidata.ucar.edu/software/thredds/current/netcdf-java/CDM
3348
.. _netCDF: http://www.unidata.ucar.edu/software/netcdf
34-
.. _OPeNDAP: http://www.opendap.org/
3549

3650
Why xarray?
3751
-----------

ci/install_python.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
# Authors: Olivier Grisel, Jonathan Helmus and Kyle Kastner
33
# License: CC0 1.0 Universal: http://creativecommons.org/publicdomain/zero/1.0/
44

5-
$MINICONDA_URL = "http://repo.continuum.io/miniconda/"
5+
$MINICONDA_URL = "https://repo.anaconda.com/miniconda/"
66
$BASE_URL = "https://www.python.org/ftp/python/"
77

88

99
function DownloadMiniconda ($python_version, $platform_suffix) {
1010
$webclient = New-Object System.Net.WebClient
11-
if ($python_version -match "3.6") {
12-
$filename = "Miniconda3-latest-Windows-" + $platform_suffix + ".exe"
13-
} else {
11+
if ($python_version -match "2.7") {
1412
$filename = "Miniconda2-latest-Windows-" + $platform_suffix + ".exe"
13+
} else {
14+
$filename = "Miniconda3-latest-Windows-" + $platform_suffix + ".exe"
1515
}
1616
$url = $MINICONDA_URL + $filename
1717

ci/requirements-py35.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ dependencies:
1010
- matplotlib=1.5
1111
- netcdf4
1212
- pytest
13-
- pytest-env
1413
- pytest-cov
14+
- pytest-env
1515
- coveralls
1616
- flake8
1717
- numpy

ci/requirements-py36-bottleneck-dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ dependencies:
1111
- matplotlib
1212
- netcdf4
1313
- pytest
14-
- pytest-env
1514
- pytest-cov
15+
- pytest-env
1616
- coveralls
1717
- flake8
1818
- numpy

ci/requirements-py36-condaforge-rc.yml

Lines changed: 0 additions & 23 deletions
This file was deleted.

ci/requirements-py36-dask-dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ dependencies:
99
- matplotlib
1010
- netcdf4
1111
- pytest
12-
- pytest-env
1312
- pytest-cov
13+
- pytest-env
1414
- coveralls
1515
- flake8
1616
- numpy

ci/requirements-py36-hypothesis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ dependencies:
1010
- matplotlib
1111
- netcdf4
1212
- pytest
13-
- pytest-env
1413
- pytest-cov
14+
- pytest-env
1515
- coveralls
1616
- hypothesis
1717
- flake8

ci/requirements-py36-netcdf4-dev.yml

Lines changed: 0 additions & 23 deletions
This file was deleted.

ci/requirements-py36-pandas-dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ dependencies:
1212
- matplotlib
1313
- netcdf4
1414
- pytest
15-
- pytest-env
1615
- pytest-cov
16+
- pytest-env
1717
- coveralls
1818
- flake8
1919
- numpy

ci/requirements-py36-pynio-dev.yml

Lines changed: 0 additions & 26 deletions
This file was deleted.

ci/requirements-py36-rasterio.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ dependencies:
1111
- matplotlib
1212
- netcdf4
1313
- pytest
14-
- pytest-env
1514
- pytest-cov
15+
- pytest-env
1616
- coveralls
1717
- numpy
1818
- pandas

ci/requirements-py36-zarr-dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ dependencies:
88
- distributed
99
- matplotlib
1010
- pytest
11-
- pytest-env
1211
- pytest-cov
12+
- pytest-env
1313
- coveralls
1414
- flake8
1515
- numpy

ci/requirements-py36.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dependencies:
1414
- pytest-cov
1515
- pytest-env
1616
- coveralls
17-
- flake8
17+
- pycodestyle
1818
- numpy
1919
- pandas
2020
- scipy
@@ -32,3 +32,4 @@ dependencies:
3232
- lxml
3333
- pip:
3434
- cfgrib>=0.9.2
35+
- mypy==0.650

ci/requirements-py37.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dependencies:
1414
- pytest-cov
1515
- pytest-env
1616
- coveralls
17-
- flake8
17+
- pycodestyle
1818
- numpy
1919
- pandas
2020
- scipy
@@ -28,4 +28,5 @@ dependencies:
2828
- eccodes
2929
- pydap
3030
- pip:
31-
- cfgrib>=0.9.2
31+
- cfgrib>=0.9.2
32+
- mypy==0.650

doc/api.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ Computation
147147
Dataset.groupby
148148
Dataset.groupby_bins
149149
Dataset.rolling
150+
Dataset.coarsen
150151
Dataset.resample
151152
Dataset.diff
152153
Dataset.quantile
@@ -312,6 +313,7 @@ Computation
312313
DataArray.groupby
313314
DataArray.groupby_bins
314315
DataArray.rolling
316+
DataArray.coarsen
315317
DataArray.dt
316318
DataArray.resample
317319
DataArray.get_axis_num

doc/computation.rst

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,47 @@ You can also use ``construct`` to compute a weighted rolling sum:
199199
To avoid this, use ``skipna=False`` as the above example.
200200

201201

202+
.. _comput.coarsen:
203+
204+
Coarsen large arrays
205+
====================
206+
207+
``DataArray`` and ``Dataset`` objects include a
208+
:py:meth:`~xarray.DataArray.coarsen` and :py:meth:`~xarray.Dataset.coarsen`
209+
methods. This supports the block aggregation along multiple dimensions,
210+
211+
.. ipython:: python
212+
213+
x = np.linspace(0, 10, 300)
214+
t = pd.date_range('15/12/1999', periods=364)
215+
da = xr.DataArray(np.sin(x) * np.cos(np.linspace(0, 1, 364)[:, np.newaxis]),
216+
dims=['time', 'x'], coords={'time': t, 'x': x})
217+
da
218+
219+
In order to take a block mean for every 7 days along ``time`` dimension and
220+
every 2 points along ``x`` dimension,
221+
222+
.. ipython:: python
223+
224+
da.coarsen(time=7, x=2).mean()
225+
226+
:py:meth:`~xarray.DataArray.coarsen` raises an ``ValueError`` if the data
227+
length is not a multiple of the corresponding window size.
228+
You can choose ``boundary='trim'`` or ``boundary='pad'`` options for trimming
229+
the excess entries or padding ``nan`` to insufficient entries,
230+
231+
.. ipython:: python
232+
233+
da.coarsen(time=30, x=2, boundary='trim').mean()
234+
235+
If you want to apply a specific function to coordinate, you can pass the
236+
function or method name to ``coord_func`` option,
237+
238+
.. ipython:: python
239+
240+
da.coarsen(time=7, x=2, coord_func={'time': 'min'}).mean()
241+
242+
202243
Computation using Coordinates
203244
=============================
204245

0 commit comments

Comments
 (0)