Skip to content

Consistently use shorter names: always use 'attrs', 'coords' and 'dims' #194

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

Merged
merged 4 commits into from
Aug 14, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/_static/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
examples*.png
8 changes: 4 additions & 4 deletions doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ Attributes and underlying data
.. autosummary::
:toctree: generated/

Dataset.coordinates
Dataset.coords
Dataset.noncoordinates
Dataset.dimensions
Dataset.dims
Dataset.attrs

Dataset contents
Expand Down Expand Up @@ -98,7 +98,6 @@ IO / Conversion

Dataset.to_netcdf
Dataset.dumps
Dataset.dump_to_store
Dataset.close
Dataset.to_dataframe
Dataset.from_dataframe
Expand Down Expand Up @@ -147,7 +146,8 @@ Attributes and underlying data

DataArray.values
DataArray.as_index
DataArray.coordinates
DataArray.coords
DataArray.dims
DataArray.name
DataArray.dataset
DataArray.attrs
Expand Down
6 changes: 3 additions & 3 deletions doc/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Monthly averaging
with values given by the first date of the month in which each time
falls.
"""
time = xray_obj.coordinates['time']
time = xray_obj.coords['time']
values = pd.Index(time).to_period('M').to_timestamp()
return xray.DataArray(values, [time], name='year_month')

Expand All @@ -74,7 +74,7 @@ Monthly averaging
:suppress:

def year_month(xray_obj):
time = xray_obj.coordinates['time']
time = xray_obj.coords['time']
values = time.as_index.to_period('M').to_timestamp()
return xray.DataArray(values, [time], name='year_month')

Expand All @@ -83,7 +83,7 @@ Monthly averaging

monthly_avg = ds.groupby(year_month(ds)).mean('time')

@savefig examples_tmin_tmax_plot2.png width=4in
@savefig examples_tmin_tmax_plot_mean.png width=4in
monthly_avg.mean('x').to_dataframe().plot(style='s-')


Expand Down
6 changes: 3 additions & 3 deletions doc/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ and coordinates, xray supports arbitrary metadata in the form of global

Automatic interpretation of labels is powerful but also reduces flexibility.
With xray, we draw a firm line between labels that the library understands
(``dimensions`` and ``coordinates``) and labels for users and user code
(``attrs``). For example, we do not automatically intrepret and enforce units
or `CF conventions`_. (An exception is serialization to netCDF with
(``dims`` and ``coords``) and labels for users and user code (``attrs``). For
example, we do not automatically intrepret and enforce units or `CF
conventions`_. (An exception is serialization to netCDF with
``cf_conventions=True``.)

.. _CF conventions: http://cf-pcmdi.llnl.gov/documents/cf-conventions/1.6/cf-conventions.html
Expand Down
29 changes: 14 additions & 15 deletions doc/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ To get started, we will import numpy, pandas and xray:
multi-dimensional array. It has three key properties:

- ``values``: a numpy.ndarray holding the array's values
- ``dimensions``: names for each axis, e.g., ``('x', 'y', 'z')``
- ``coordinates``: tick labels along each dimension, e.g., 1-dimensional arrays
of numbers, datetime objects or strings.
- ``dims``: dimension names for each axis, e.g., ``('x', 'y', 'z')``
- ``coords``: tick labels along each dimension, e.g., 1-dimensional
arrays of numbers, datetime objects or strings.

xray uses ``dimensions`` and ``coordinates`` to enable its core metadata aware
xray uses ``dims`` and ``coords`` to enable its core metadata aware
operations. Dimensions provide names that xray uses instead of the ``axis``
argument found in many numpy functions. Coordinates enable fast label based
indexing and alignment, like the ``index`` found on a pandas
Expand All @@ -48,8 +48,7 @@ a numpy ndarray), a list of coordinates labels and a list of dimension names:
data = np.random.rand(4, 3)
locs = ['IA', 'IL', 'IN']
times = pd.date_range('2000-01-01', periods=4)
foo = xray.DataArray(data, coordinates=[times, locs],
dimensions=['time', 'space'])
foo = xray.DataArray(data, coords=[times, locs], dims=['time', 'space'])
foo

All of these arguments (except for ``data``) are optional, and will be filled
Expand Down Expand Up @@ -86,8 +85,8 @@ Let's take a look at the important properties on our array:
.. ipython:: python

foo.values
foo.dimensions
foo.coordinates
foo.dims
foo.coords
foo.attrs
print(foo.name)

Expand All @@ -99,13 +98,13 @@ Now fill in some of that missing metadata:
foo.attrs['units'] = 'meters'
foo

The ``coordinates`` property is ``dict`` like. Individual coordinates can be
The ``coords`` property is ``dict`` like. Individual coordinates can be
accessed by name or axis number:

.. ipython:: python

foo.coordinates['time']
foo.coordinates[0]
foo.coords['time']
foo.coords[0]

These are :py:class:`xray.Coordinate` objects, which contain tick-labels for
each dimension.
Expand Down Expand Up @@ -197,7 +196,7 @@ was filled with an array of ascending integers of the proper length:

Noncoordinate and coordinates are listed explicitly by the
:py:attr:`~xray.Dataset.noncoordinates` and
:py:attr:`~xray.Dataset.coordinates` attributes.
:py:attr:`~xray.Dataset.coords` attributes.

There are also a few derived variables based on datetime coordinates that you
can access from a dataset (e.g., "year", "month" and "day"), even if you didn't
Expand Down Expand Up @@ -399,7 +398,7 @@ operation over any or all non-coordinates in a dataset by using
Aggregation
~~~~~~~~~~~

Aggregation methods from ndarray have been updated to take a `dimension`
Aggregation methods from ndarray have been updated to take a `dim`
argument instead of `axis`. This allows for very intuitive syntax for
aggregation methods that are applied along particular dimension(s):

Expand Down Expand Up @@ -453,7 +452,7 @@ arrays with different sizes aligned along different dimensions:

a = xray.DataArray([1, 2, 3, 4], [['a', 'b', 'c', 'd']], ['x'])
a
b = xray.DataArray([-1, -2, -3], dimensions=['y'])
b = xray.DataArray([-1, -2, -3], dims=['y'])
b

With xray, we can apply binary mathematical operations to these arrays, and
Expand Down Expand Up @@ -1112,7 +1111,7 @@ and DataArray variables. It supports the numpy ndarray interface, but is
extended to support and use basic metadata (not including index values). It
consists of:

1. ``dimensions``: A tuple of dimension names.
1. ``dims``: A tuple of dimension names.
2. ``values``: The N-dimensional array (for example, of type
:py:class:`numpy.ndarray`) storing the array's data. It must have the same
number of dimensions as the length of ``dimensions``.
Expand Down
10 changes: 5 additions & 5 deletions test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def assertVariableIdentical(self, v1, v2):
assert as_variable(v1).identical(v2), (v1, v2)

def assertVariableAllClose(self, v1, v2, rtol=1e-05, atol=1e-08):
self.assertEqual(v1.dimensions, v2.dimensions)
self.assertEqual(v1.dims, v2.dims)
allclose = data_allclose_or_equiv(
v1.values, v2.values, rtol=rtol, atol=atol)
assert allclose, (v1.values, v2.values)
Expand Down Expand Up @@ -113,10 +113,10 @@ def assertDatasetAllClose(self, d1, d2, rtol=1e-05, atol=1e-08):
self.assertVariableAllClose(v1, v2, rtol=rtol, atol=atol)

def assertCoordinatesEqual(self, d1, d2):
self.assertEqual(sorted(d1.coordinates), sorted(d2.coordinates))
for k in d1.coordinates:
v1 = d1.coordinates[k]
v2 = d2.coordinates[k]
self.assertEqual(sorted(d1.coords), sorted(d2.coords))
for k in d1.coords:
v1 = d1.coords[k]
v2 = d2.coords[k]
self.assertVariableEqual(v1, v2)

def assertDataArrayEqual(self, ar1, ar2):
Expand Down
Loading