Xarray Fundamentals
Contents
Xarray Fundamentals¶
Xarray data structures¶
Like Pandas, xarray has two fundamental data structures:
a
DataArray
, which holds a single multi-dimensional variable and its coordinatesa
Dataset
, which holds multiple variables that potentially share the same coordinates
DataArray¶
A DataArray
has four essential attributes:
values
: anumpy.ndarray
holding the array’s valuesdims
: dimension names for each axis (e.g.,('x', 'y', 'z')
)coords
: a dict-like container of arrays (coordinates) that label each point (e.g., 1-dimensional arrays of numbers, datetime objects or strings)attrs
: anOrderedDict
to hold arbitrary metadata (attributes)
Let’s start by constructing some DataArrays manually
import numpy as np
import xarray as xr
from matplotlib import pyplot as plt
%matplotlib inline
plt.rcParams['figure.figsize'] = (8,5)
A simple DataArray without dimensions or coordinates isn’t much use.
da = xr.DataArray([9, 0, 2, 1, 0])
da
<xarray.DataArray (dim_0: 5)> array([9, 0, 2, 1, 0]) Dimensions without coordinates: dim_0
- dim_0: 5
- 9 0 2 1 0
array([9, 0, 2, 1, 0])
We can add a dimension name…
da = xr.DataArray([9, 0, 2, 1, 0], dims=['x'])
da
<xarray.DataArray (x: 5)> array([9, 0, 2, 1, 0]) Dimensions without coordinates: x
- x: 5
- 9 0 2 1 0
array([9, 0, 2, 1, 0])
But things get most interesting when we add a coordinate:
da = xr.DataArray([9, 0, 2, 1, 0],
dims=['x'],
coords={'x': [10, 20, 30, 40, 50]})
da
<xarray.DataArray (x: 5)> array([9, 0, 2, 1, 0]) Coordinates: * x (x) int64 10 20 30 40 50
- x: 5
- 9 0 2 1 0
array([9, 0, 2, 1, 0])
- x(x)int6410 20 30 40 50
array([10, 20, 30, 40, 50])
This coordinate has been used to create an index, which works very similar to a Pandas index. In fact, under the hood, Xarray just reuses Pandas indexes.
da.indexes
x: Int64Index([10, 20, 30, 40, 50], dtype='int64', name='x')
Xarray has built-in plotting, like pandas.
da.plot(marker='o')
[<matplotlib.lines.Line2D at 0x7f797c8462e0>]

Multidimensional DataArray¶
If we are just dealing with 1D data, Pandas and Xarray have very similar capabilities. Xarray’s real potential comes with multidimensional data.
Let’s go back to the multidimensional ARGO data we loaded in the numpy lesson.
import pooch
url = "https://www.ldeo.columbia.edu/~rpa/float_data_4901412.zip"
files = pooch.retrieve(url, processor=pooch.Unzip(), known_hash="2a703c720302c682f1662181d329c9f22f9f10e1539dc2d6082160a469165009")
files
['/home/jovyan/.cache/pooch/7e6685dbe2a3c0b0870f770f3ef413d9-float_data_4901412.zip.unzip/float_data/T.npy',
'/home/jovyan/.cache/pooch/7e6685dbe2a3c0b0870f770f3ef413d9-float_data_4901412.zip.unzip/float_data/S.npy',
'/home/jovyan/.cache/pooch/7e6685dbe2a3c0b0870f770f3ef413d9-float_data_4901412.zip.unzip/float_data/date.npy',
'/home/jovyan/.cache/pooch/7e6685dbe2a3c0b0870f770f3ef413d9-float_data_4901412.zip.unzip/float_data/lon.npy',
'/home/jovyan/.cache/pooch/7e6685dbe2a3c0b0870f770f3ef413d9-float_data_4901412.zip.unzip/float_data/levels.npy',
'/home/jovyan/.cache/pooch/7e6685dbe2a3c0b0870f770f3ef413d9-float_data_4901412.zip.unzip/float_data/P.npy',
'/home/jovyan/.cache/pooch/7e6685dbe2a3c0b0870f770f3ef413d9-float_data_4901412.zip.unzip/float_data/lat.npy']
T = np.load(files[0])
S = np.load(files[1])
date = np.load(files[2])
lon = np.load(files[3])
levels = np.load(files[4])
P = np.load(files[5])
lat = np.load(files[6])
Let’s organize the data and coordinates of the salinity variable into a DataArray.
da_salinity = xr.DataArray(S, dims=['level', 'date'],
coords={'level': levels,
'date': date},)
da_salinity
<xarray.DataArray (level: 78, date: 75)> array([[35.6389389 , 35.51495743, 35.57297134, ..., 35.82093811, 35.77793884, 35.66891098], [35.63393784, 35.5219574 , 35.57397079, ..., 35.81093216, 35.58389664, 35.66791153], [35.6819458 , 35.52595901, 35.57297134, ..., 35.79592896, 35.66290665, 35.66591263], ..., [34.91585922, 34.92390442, 34.92390442, ..., 34.93481064, 34.94081116, 34.94680786], [34.91585922, 34.92390442, 34.92190552, ..., 34.93280792, 34.93680954, 34.94380951], [34.91785812, 34.92390442, 34.92390442, ..., nan, 34.93680954, nan]]) Coordinates: * level (level) int64 0 1 2 3 4 5 6 7 8 9 ... 68 69 70 71 72 73 74 75 76 77 * date (date) datetime64[ns] 2012-07-13T22:33:06.019200 ... 2014-07-24T...
- level: 78
- date: 75
- 35.64 35.51 35.57 35.4 35.45 35.5 ... 34.94 nan 34.94 nan 34.94 nan
array([[35.6389389 , 35.51495743, 35.57297134, ..., 35.82093811, 35.77793884, 35.66891098], [35.63393784, 35.5219574 , 35.57397079, ..., 35.81093216, 35.58389664, 35.66791153], [35.6819458 , 35.52595901, 35.57297134, ..., 35.79592896, 35.66290665, 35.66591263], ..., [34.91585922, 34.92390442, 34.92390442, ..., 34.93481064, 34.94081116, 34.94680786], [34.91585922, 34.92390442, 34.92190552, ..., 34.93280792, 34.93680954, 34.94380951], [34.91785812, 34.92390442, 34.92390442, ..., nan, 34.93680954, nan]])
- level(level)int640 1 2 3 4 5 6 ... 72 73 74 75 76 77
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77])
- date(date)datetime64[ns]2012-07-13T22:33:06.019200 ... 2...
array(['2012-07-13T22:33:06.019200000', '2012-07-23T22:54:59.990400000', '2012-08-02T22:55:52.003200000', '2012-08-12T23:08:59.971200000', '2012-08-22T23:29:01.968000000', '2012-09-01T23:17:38.976000000', '2012-09-12T02:59:18.960000000', '2012-09-21T23:18:37.036800000', '2012-10-02T03:00:17.971200000', '2012-10-11T23:13:27.984000000', '2012-10-22T02:50:32.006400000', '2012-10-31T23:36:39.974400000', '2012-11-11T02:40:46.041600000', '2012-11-20T23:08:29.990400000', '2012-12-01T02:47:51.993600000', '2012-12-10T23:23:16.972800000', '2012-12-21T02:58:48.979200000', '2012-12-30T23:07:23.030400000', '2013-01-10T02:56:43.008000000', '2013-01-19T23:24:26.956800000', '2013-01-30T02:43:53.011200000', '2013-02-08T23:15:27.043200000', '2013-02-19T01:12:50.976000000', '2013-02-28T23:07:13.008000000', '2013-03-11T02:43:30.979200000', '2013-03-20T23:17:22.992000000', '2013-03-31T01:50:38.025600000', '2013-04-09T23:19:07.968000000', '2013-04-20T02:53:29.990400000', '2013-04-29T23:28:33.024000000', '2013-05-10T02:50:18.009600000', '2013-05-19T23:21:05.990400000', '2013-05-30T02:50:30.969600000', '2013-06-08T23:32:49.027200000', '2013-06-19T03:42:51.004800000', '2013-06-28T23:32:16.022400000', '2013-07-09T03:28:30.979199999', '2013-07-18T23:33:57.974400000', '2013-07-29T03:15:42.019200000', '2013-08-07T23:25:02.035200000', '2013-08-18T01:47:44.966400000', '2013-08-28T03:02:59.020800000', '2013-09-07T03:03:51.984000000', '2013-09-16T23:32:07.987200000', '2013-09-27T04:08:27.974400000', '2013-10-06T23:25:39.964800000', '2013-10-17T02:55:50.995200000', '2013-10-27T03:45:47.001600000', '2013-11-06T01:14:52.022400000', '2013-11-16T03:29:54.009600000', '2013-11-26T03:03:56.995200000', '2013-12-05T23:33:59.011200000', '2013-12-16T02:58:01.977600000', '2013-12-25T23:22:43.017600000', '2014-01-05T02:52:06.009600000', '2014-01-14T23:41:18.009600000', '2014-01-25T03:00:43.977600000', '2014-02-03T23:29:13.977600000', '2014-02-14T02:50:11.961600000', '2014-02-23T23:03:21.974400000', '2014-03-06T02:58:03.964800000', '2014-03-15T23:10:28.012800000', '2014-03-26T02:51:22.032000000', '2014-04-04T23:25:58.972800000', '2014-04-15T03:00:45.964800000', '2014-04-24T23:24:40.003200000', '2014-05-05T02:56:22.012800000', '2014-05-15T00:10:06.009600000', '2014-05-25T03:02:43.036800000', '2014-06-03T23:34:53.961600000', '2014-06-14T03:01:23.980800000', '2014-06-23T23:24:31.968000000', '2014-07-04T03:08:30.019200000', '2014-07-13T23:47:43.008000000', '2014-07-24T03:02:33.014400000'], dtype='datetime64[ns]')
da_salinity.plot(yincrease=False)
<matplotlib.collections.QuadMesh at 0x7f797454df70>

Attributes can be used to store metadata. What metadata should you store? The CF Conventions are a great resource for thinking about climate metadata. Below we define two of the required CF-conventions attributes.
da_salinity.attrs['units'] = 'PSU'
da_salinity.attrs['standard_name'] = 'sea_water_salinity'
da_salinity
<xarray.DataArray (level: 78, date: 75)> array([[35.6389389 , 35.51495743, 35.57297134, ..., 35.82093811, 35.77793884, 35.66891098], [35.63393784, 35.5219574 , 35.57397079, ..., 35.81093216, 35.58389664, 35.66791153], [35.6819458 , 35.52595901, 35.57297134, ..., 35.79592896, 35.66290665, 35.66591263], ..., [34.91585922, 34.92390442, 34.92390442, ..., 34.93481064, 34.94081116, 34.94680786], [34.91585922, 34.92390442, 34.92190552, ..., 34.93280792, 34.93680954, 34.94380951], [34.91785812, 34.92390442, 34.92390442, ..., nan, 34.93680954, nan]]) Coordinates: * level (level) int64 0 1 2 3 4 5 6 7 8 9 ... 68 69 70 71 72 73 74 75 76 77 * date (date) datetime64[ns] 2012-07-13T22:33:06.019200 ... 2014-07-24T... Attributes: units: PSU standard_name: sea_water_salinity
- level: 78
- date: 75
- 35.64 35.51 35.57 35.4 35.45 35.5 ... 34.94 nan 34.94 nan 34.94 nan
array([[35.6389389 , 35.51495743, 35.57297134, ..., 35.82093811, 35.77793884, 35.66891098], [35.63393784, 35.5219574 , 35.57397079, ..., 35.81093216, 35.58389664, 35.66791153], [35.6819458 , 35.52595901, 35.57297134, ..., 35.79592896, 35.66290665, 35.66591263], ..., [34.91585922, 34.92390442, 34.92390442, ..., 34.93481064, 34.94081116, 34.94680786], [34.91585922, 34.92390442, 34.92190552, ..., 34.93280792, 34.93680954, 34.94380951], [34.91785812, 34.92390442, 34.92390442, ..., nan, 34.93680954, nan]])
- level(level)int640 1 2 3 4 5 6 ... 72 73 74 75 76 77
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77])
- date(date)datetime64[ns]2012-07-13T22:33:06.019200 ... 2...
array(['2012-07-13T22:33:06.019200000', '2012-07-23T22:54:59.990400000', '2012-08-02T22:55:52.003200000', '2012-08-12T23:08:59.971200000', '2012-08-22T23:29:01.968000000', '2012-09-01T23:17:38.976000000', '2012-09-12T02:59:18.960000000', '2012-09-21T23:18:37.036800000', '2012-10-02T03:00:17.971200000', '2012-10-11T23:13:27.984000000', '2012-10-22T02:50:32.006400000', '2012-10-31T23:36:39.974400000', '2012-11-11T02:40:46.041600000', '2012-11-20T23:08:29.990400000', '2012-12-01T02:47:51.993600000', '2012-12-10T23:23:16.972800000', '2012-12-21T02:58:48.979200000', '2012-12-30T23:07:23.030400000', '2013-01-10T02:56:43.008000000', '2013-01-19T23:24:26.956800000', '2013-01-30T02:43:53.011200000', '2013-02-08T23:15:27.043200000', '2013-02-19T01:12:50.976000000', '2013-02-28T23:07:13.008000000', '2013-03-11T02:43:30.979200000', '2013-03-20T23:17:22.992000000', '2013-03-31T01:50:38.025600000', '2013-04-09T23:19:07.968000000', '2013-04-20T02:53:29.990400000', '2013-04-29T23:28:33.024000000', '2013-05-10T02:50:18.009600000', '2013-05-19T23:21:05.990400000', '2013-05-30T02:50:30.969600000', '2013-06-08T23:32:49.027200000', '2013-06-19T03:42:51.004800000', '2013-06-28T23:32:16.022400000', '2013-07-09T03:28:30.979199999', '2013-07-18T23:33:57.974400000', '2013-07-29T03:15:42.019200000', '2013-08-07T23:25:02.035200000', '2013-08-18T01:47:44.966400000', '2013-08-28T03:02:59.020800000', '2013-09-07T03:03:51.984000000', '2013-09-16T23:32:07.987200000', '2013-09-27T04:08:27.974400000', '2013-10-06T23:25:39.964800000', '2013-10-17T02:55:50.995200000', '2013-10-27T03:45:47.001600000', '2013-11-06T01:14:52.022400000', '2013-11-16T03:29:54.009600000', '2013-11-26T03:03:56.995200000', '2013-12-05T23:33:59.011200000', '2013-12-16T02:58:01.977600000', '2013-12-25T23:22:43.017600000', '2014-01-05T02:52:06.009600000', '2014-01-14T23:41:18.009600000', '2014-01-25T03:00:43.977600000', '2014-02-03T23:29:13.977600000', '2014-02-14T02:50:11.961600000', '2014-02-23T23:03:21.974400000', '2014-03-06T02:58:03.964800000', '2014-03-15T23:10:28.012800000', '2014-03-26T02:51:22.032000000', '2014-04-04T23:25:58.972800000', '2014-04-15T03:00:45.964800000', '2014-04-24T23:24:40.003200000', '2014-05-05T02:56:22.012800000', '2014-05-15T00:10:06.009600000', '2014-05-25T03:02:43.036800000', '2014-06-03T23:34:53.961600000', '2014-06-14T03:01:23.980800000', '2014-06-23T23:24:31.968000000', '2014-07-04T03:08:30.019200000', '2014-07-13T23:47:43.008000000', '2014-07-24T03:02:33.014400000'], dtype='datetime64[ns]')
- units :
- PSU
- standard_name :
- sea_water_salinity
Now if we plot the data again, the name and units are automatically atachhed to the figure.
da_salinity.plot()
<matplotlib.collections.QuadMesh at 0x7f7974448a00>

Datasets¶
A Dataset holds many DataArrays which potentially can share coordinates. In analogy to pandas:
pandas.Series : pandas.Dataframe :: xarray.DataArray : xarray.Dataset
Constructing Datasets manually is a bit more involved in terms of syntax. The Dataset constructor takes three arguments:
data_vars
should be a dictionary with each key as the name of the variable and each value as one of:A
DataArray
or VariableA tuple of the form
(dims, data[, attrs])
, which is converted into arguments for VariableA pandas object, which is converted into a
DataArray
A 1D array or list, which is interpreted as values for a one dimensional coordinate variable along the same dimension as it’s name
coords
should be a dictionary of the same form as data_vars.attrs
should be a dictionary.
Let’s put together a Dataset with temperature, salinity and pressure all together
argo = xr.Dataset(
data_vars={
'salinity': (('level', 'date'), S),
'temperature': (('level', 'date'), T),
'pressure': (('level', 'date'), P)
},
coords={
'level': levels,
'date': date
}
)
argo
<xarray.Dataset> Dimensions: (level: 78, date: 75) Coordinates: * level (level) int64 0 1 2 3 4 5 6 7 8 ... 69 70 71 72 73 74 75 76 77 * date (date) datetime64[ns] 2012-07-13T22:33:06.019200 ... 2014-07... Data variables: salinity (level, date) float64 35.64 35.51 35.57 35.4 ... nan 34.94 nan temperature (level, date) float64 18.97 18.44 19.1 19.79 ... nan 3.714 nan pressure (level, date) float64 6.8 6.1 6.5 5.0 ... 2e+03 nan 2e+03 nan
- level: 78
- date: 75
- level(level)int640 1 2 3 4 5 6 ... 72 73 74 75 76 77
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77])
- date(date)datetime64[ns]2012-07-13T22:33:06.019200 ... 2...
array(['2012-07-13T22:33:06.019200000', '2012-07-23T22:54:59.990400000', '2012-08-02T22:55:52.003200000', '2012-08-12T23:08:59.971200000', '2012-08-22T23:29:01.968000000', '2012-09-01T23:17:38.976000000', '2012-09-12T02:59:18.960000000', '2012-09-21T23:18:37.036800000', '2012-10-02T03:00:17.971200000', '2012-10-11T23:13:27.984000000', '2012-10-22T02:50:32.006400000', '2012-10-31T23:36:39.974400000', '2012-11-11T02:40:46.041600000', '2012-11-20T23:08:29.990400000', '2012-12-01T02:47:51.993600000', '2012-12-10T23:23:16.972800000', '2012-12-21T02:58:48.979200000', '2012-12-30T23:07:23.030400000', '2013-01-10T02:56:43.008000000', '2013-01-19T23:24:26.956800000', '2013-01-30T02:43:53.011200000', '2013-02-08T23:15:27.043200000', '2013-02-19T01:12:50.976000000', '2013-02-28T23:07:13.008000000', '2013-03-11T02:43:30.979200000', '2013-03-20T23:17:22.992000000', '2013-03-31T01:50:38.025600000', '2013-04-09T23:19:07.968000000', '2013-04-20T02:53:29.990400000', '2013-04-29T23:28:33.024000000', '2013-05-10T02:50:18.009600000', '2013-05-19T23:21:05.990400000', '2013-05-30T02:50:30.969600000', '2013-06-08T23:32:49.027200000', '2013-06-19T03:42:51.004800000', '2013-06-28T23:32:16.022400000', '2013-07-09T03:28:30.979199999', '2013-07-18T23:33:57.974400000', '2013-07-29T03:15:42.019200000', '2013-08-07T23:25:02.035200000', '2013-08-18T01:47:44.966400000', '2013-08-28T03:02:59.020800000', '2013-09-07T03:03:51.984000000', '2013-09-16T23:32:07.987200000', '2013-09-27T04:08:27.974400000', '2013-10-06T23:25:39.964800000', '2013-10-17T02:55:50.995200000', '2013-10-27T03:45:47.001600000', '2013-11-06T01:14:52.022400000', '2013-11-16T03:29:54.009600000', '2013-11-26T03:03:56.995200000', '2013-12-05T23:33:59.011200000', '2013-12-16T02:58:01.977600000', '2013-12-25T23:22:43.017600000', '2014-01-05T02:52:06.009600000', '2014-01-14T23:41:18.009600000', '2014-01-25T03:00:43.977600000', '2014-02-03T23:29:13.977600000', '2014-02-14T02:50:11.961600000', '2014-02-23T23:03:21.974400000', '2014-03-06T02:58:03.964800000', '2014-03-15T23:10:28.012800000', '2014-03-26T02:51:22.032000000', '2014-04-04T23:25:58.972800000', '2014-04-15T03:00:45.964800000', '2014-04-24T23:24:40.003200000', '2014-05-05T02:56:22.012800000', '2014-05-15T00:10:06.009600000', '2014-05-25T03:02:43.036800000', '2014-06-03T23:34:53.961600000', '2014-06-14T03:01:23.980800000', '2014-06-23T23:24:31.968000000', '2014-07-04T03:08:30.019200000', '2014-07-13T23:47:43.008000000', '2014-07-24T03:02:33.014400000'], dtype='datetime64[ns]')
- salinity(level, date)float6435.64 35.51 35.57 ... nan 34.94 nan
array([[35.6389389 , 35.51495743, 35.57297134, ..., 35.82093811, 35.77793884, 35.66891098], [35.63393784, 35.5219574 , 35.57397079, ..., 35.81093216, 35.58389664, 35.66791153], [35.6819458 , 35.52595901, 35.57297134, ..., 35.79592896, 35.66290665, 35.66591263], ..., [34.91585922, 34.92390442, 34.92390442, ..., 34.93481064, 34.94081116, 34.94680786], [34.91585922, 34.92390442, 34.92190552, ..., 34.93280792, 34.93680954, 34.94380951], [34.91785812, 34.92390442, 34.92390442, ..., nan, 34.93680954, nan]])
- temperature(level, date)float6418.97 18.44 19.1 ... nan 3.714 nan
array([[18.97400093, 18.43700027, 19.09900093, ..., 19.11300087, 21.82299995, 20.13100052], [18.74099922, 18.39999962, 19.08200073, ..., 18.47200012, 19.45999908, 20.125 ], [18.37000084, 18.37400055, 19.06500053, ..., 18.22999954, 19.26199913, 20.07699966], ..., [ 3.79299998, 3.81399989, 3.80200005, ..., 3.80699992, 3.81100011, 3.8599999 ], [ 3.76399994, 3.77800012, 3.75699997, ..., 3.75399995, 3.74600005, 3.80599999], [ 3.74399996, 3.74600005, 3.7249999 , ..., nan, 3.71399999, nan]])
- pressure(level, date)float646.8 6.1 6.5 5.0 ... nan 2e+03 nan
array([[ 6.80000019, 6.0999999 , 6.5 , ..., 7.0999999 , 7.20000029, 6.5 ], [ 10.69999981, 10.59999943, 10.39999962, ..., 10.79999924, 11.09999943, 10.39999962], [ 15.69999981, 14.09999943, 14.89999962, ..., 15.89999962, 15.59999943, 15.89999962], ..., [1900.60009766, 1900. , 1900.19995117, ..., 1899.70007324, 1900.40002441, 1899.80004883], [1949.90002441, 1950. , 1949.89990234, ..., 1950.59997559, 1950.20007324, 1949.70007324], [1999.30004883, 1998. , 1998.5 , ..., nan, 2000.40002441, nan]])
What about lon and lat? We forgot them in the creation process, but we can add them after the fact.
argo.coords['lon'] = lon
argo
<xarray.Dataset> Dimensions: (level: 78, date: 75, lon: 75) Coordinates: * level (level) int64 0 1 2 3 4 5 6 7 8 ... 69 70 71 72 73 74 75 76 77 * date (date) datetime64[ns] 2012-07-13T22:33:06.019200 ... 2014-07... * lon (lon) float64 -39.13 -37.28 -36.9 ... -33.83 -34.11 -34.38 Data variables: salinity (level, date) float64 35.64 35.51 35.57 35.4 ... nan 34.94 nan temperature (level, date) float64 18.97 18.44 19.1 19.79 ... nan 3.714 nan pressure (level, date) float64 6.8 6.1 6.5 5.0 ... 2e+03 nan 2e+03 nan
- level: 78
- date: 75
- lon: 75
- level(level)int640 1 2 3 4 5 6 ... 72 73 74 75 76 77
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77])
- date(date)datetime64[ns]2012-07-13T22:33:06.019200 ... 2...
array(['2012-07-13T22:33:06.019200000', '2012-07-23T22:54:59.990400000', '2012-08-02T22:55:52.003200000', '2012-08-12T23:08:59.971200000', '2012-08-22T23:29:01.968000000', '2012-09-01T23:17:38.976000000', '2012-09-12T02:59:18.960000000', '2012-09-21T23:18:37.036800000', '2012-10-02T03:00:17.971200000', '2012-10-11T23:13:27.984000000', '2012-10-22T02:50:32.006400000', '2012-10-31T23:36:39.974400000', '2012-11-11T02:40:46.041600000', '2012-11-20T23:08:29.990400000', '2012-12-01T02:47:51.993600000', '2012-12-10T23:23:16.972800000', '2012-12-21T02:58:48.979200000', '2012-12-30T23:07:23.030400000', '2013-01-10T02:56:43.008000000', '2013-01-19T23:24:26.956800000', '2013-01-30T02:43:53.011200000', '2013-02-08T23:15:27.043200000', '2013-02-19T01:12:50.976000000', '2013-02-28T23:07:13.008000000', '2013-03-11T02:43:30.979200000', '2013-03-20T23:17:22.992000000', '2013-03-31T01:50:38.025600000', '2013-04-09T23:19:07.968000000', '2013-04-20T02:53:29.990400000', '2013-04-29T23:28:33.024000000', '2013-05-10T02:50:18.009600000', '2013-05-19T23:21:05.990400000', '2013-05-30T02:50:30.969600000', '2013-06-08T23:32:49.027200000', '2013-06-19T03:42:51.004800000', '2013-06-28T23:32:16.022400000', '2013-07-09T03:28:30.979199999', '2013-07-18T23:33:57.974400000', '2013-07-29T03:15:42.019200000', '2013-08-07T23:25:02.035200000', '2013-08-18T01:47:44.966400000', '2013-08-28T03:02:59.020800000', '2013-09-07T03:03:51.984000000', '2013-09-16T23:32:07.987200000', '2013-09-27T04:08:27.974400000', '2013-10-06T23:25:39.964800000', '2013-10-17T02:55:50.995200000', '2013-10-27T03:45:47.001600000', '2013-11-06T01:14:52.022400000', '2013-11-16T03:29:54.009600000', '2013-11-26T03:03:56.995200000', '2013-12-05T23:33:59.011200000', '2013-12-16T02:58:01.977600000', '2013-12-25T23:22:43.017600000', '2014-01-05T02:52:06.009600000', '2014-01-14T23:41:18.009600000', '2014-01-25T03:00:43.977600000', '2014-02-03T23:29:13.977600000', '2014-02-14T02:50:11.961600000', '2014-02-23T23:03:21.974400000', '2014-03-06T02:58:03.964800000', '2014-03-15T23:10:28.012800000', '2014-03-26T02:51:22.032000000', '2014-04-04T23:25:58.972800000', '2014-04-15T03:00:45.964800000', '2014-04-24T23:24:40.003200000', '2014-05-05T02:56:22.012800000', '2014-05-15T00:10:06.009600000', '2014-05-25T03:02:43.036800000', '2014-06-03T23:34:53.961600000', '2014-06-14T03:01:23.980800000', '2014-06-23T23:24:31.968000000', '2014-07-04T03:08:30.019200000', '2014-07-13T23:47:43.008000000', '2014-07-24T03:02:33.014400000'], dtype='datetime64[ns]')
- lon(lon)float64-39.13 -37.28 ... -34.11 -34.38
array([-39.13 , -37.282, -36.9 , -36.89 , -37.053, -36.658, -35.963, -35.184, -34.462, -33.784, -32.972, -32.546, -32.428, -32.292, -32.169, -31.998, -31.824, -31.624, -31.433, -31.312, -31.107, -31.147, -31.044, -31.14 , -31.417, -31.882, -32.145, -32.487, -32.537, -32.334, -32.042, -31.892, -31.861, -31.991, -31.883, -31.89 , -31.941, -31.889, -31.724, -31.412, -31.786, -31.561, -31.732, -31.553, -31.862, -32.389, -32.318, -32.19 , -32.224, -32.368, -32.306, -32.305, -32.65 , -33.093, -33.263, -33.199, -33.27 , -33.237, -33.221, -33.011, -32.844, -32.981, -32.784, -32.607, -32.87 , -33.196, -33.524, -33.956, -33.944, -33.71 , -33.621, -33.552, -33.828, -34.11 , -34.38 ])
- salinity(level, date)float6435.64 35.51 35.57 ... nan 34.94 nan
array([[35.6389389 , 35.51495743, 35.57297134, ..., 35.82093811, 35.77793884, 35.66891098], [35.63393784, 35.5219574 , 35.57397079, ..., 35.81093216, 35.58389664, 35.66791153], [35.6819458 , 35.52595901, 35.57297134, ..., 35.79592896, 35.66290665, 35.66591263], ..., [34.91585922, 34.92390442, 34.92390442, ..., 34.93481064, 34.94081116, 34.94680786], [34.91585922, 34.92390442, 34.92190552, ..., 34.93280792, 34.93680954, 34.94380951], [34.91785812, 34.92390442, 34.92390442, ..., nan, 34.93680954, nan]])
- temperature(level, date)float6418.97 18.44 19.1 ... nan 3.714 nan
array([[18.97400093, 18.43700027, 19.09900093, ..., 19.11300087, 21.82299995, 20.13100052], [18.74099922, 18.39999962, 19.08200073, ..., 18.47200012, 19.45999908, 20.125 ], [18.37000084, 18.37400055, 19.06500053, ..., 18.22999954, 19.26199913, 20.07699966], ..., [ 3.79299998, 3.81399989, 3.80200005, ..., 3.80699992, 3.81100011, 3.8599999 ], [ 3.76399994, 3.77800012, 3.75699997, ..., 3.75399995, 3.74600005, 3.80599999], [ 3.74399996, 3.74600005, 3.7249999 , ..., nan, 3.71399999, nan]])
- pressure(level, date)float646.8 6.1 6.5 5.0 ... nan 2e+03 nan
array([[ 6.80000019, 6.0999999 , 6.5 , ..., 7.0999999 , 7.20000029, 6.5 ], [ 10.69999981, 10.59999943, 10.39999962, ..., 10.79999924, 11.09999943, 10.39999962], [ 15.69999981, 14.09999943, 14.89999962, ..., 15.89999962, 15.59999943, 15.89999962], ..., [1900.60009766, 1900. , 1900.19995117, ..., 1899.70007324, 1900.40002441, 1899.80004883], [1949.90002441, 1950. , 1949.89990234, ..., 1950.59997559, 1950.20007324, 1949.70007324], [1999.30004883, 1998. , 1998.5 , ..., nan, 2000.40002441, nan]])
That was not quite right…we want lon to have dimension date
:
del argo['lon']
argo.coords['lon'] = ('date', lon)
argo.coords['lat'] = ('date', lat)
argo
<xarray.Dataset> Dimensions: (level: 78, date: 75) Coordinates: * level (level) int64 0 1 2 3 4 5 6 7 8 ... 69 70 71 72 73 74 75 76 77 * date (date) datetime64[ns] 2012-07-13T22:33:06.019200 ... 2014-07... lon (date) float64 -39.13 -37.28 -36.9 ... -33.83 -34.11 -34.38 lat (date) float64 47.19 46.72 46.45 46.23 ... 42.6 42.46 42.38 Data variables: salinity (level, date) float64 35.64 35.51 35.57 35.4 ... nan 34.94 nan temperature (level, date) float64 18.97 18.44 19.1 19.79 ... nan 3.714 nan pressure (level, date) float64 6.8 6.1 6.5 5.0 ... 2e+03 nan 2e+03 nan
- level: 78
- date: 75
- level(level)int640 1 2 3 4 5 6 ... 72 73 74 75 76 77
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77])
- date(date)datetime64[ns]2012-07-13T22:33:06.019200 ... 2...
array(['2012-07-13T22:33:06.019200000', '2012-07-23T22:54:59.990400000', '2012-08-02T22:55:52.003200000', '2012-08-12T23:08:59.971200000', '2012-08-22T23:29:01.968000000', '2012-09-01T23:17:38.976000000', '2012-09-12T02:59:18.960000000', '2012-09-21T23:18:37.036800000', '2012-10-02T03:00:17.971200000', '2012-10-11T23:13:27.984000000', '2012-10-22T02:50:32.006400000', '2012-10-31T23:36:39.974400000', '2012-11-11T02:40:46.041600000', '2012-11-20T23:08:29.990400000', '2012-12-01T02:47:51.993600000', '2012-12-10T23:23:16.972800000', '2012-12-21T02:58:48.979200000', '2012-12-30T23:07:23.030400000', '2013-01-10T02:56:43.008000000', '2013-01-19T23:24:26.956800000', '2013-01-30T02:43:53.011200000', '2013-02-08T23:15:27.043200000', '2013-02-19T01:12:50.976000000', '2013-02-28T23:07:13.008000000', '2013-03-11T02:43:30.979200000', '2013-03-20T23:17:22.992000000', '2013-03-31T01:50:38.025600000', '2013-04-09T23:19:07.968000000', '2013-04-20T02:53:29.990400000', '2013-04-29T23:28:33.024000000', '2013-05-10T02:50:18.009600000', '2013-05-19T23:21:05.990400000', '2013-05-30T02:50:30.969600000', '2013-06-08T23:32:49.027200000', '2013-06-19T03:42:51.004800000', '2013-06-28T23:32:16.022400000', '2013-07-09T03:28:30.979199999', '2013-07-18T23:33:57.974400000', '2013-07-29T03:15:42.019200000', '2013-08-07T23:25:02.035200000', '2013-08-18T01:47:44.966400000', '2013-08-28T03:02:59.020800000', '2013-09-07T03:03:51.984000000', '2013-09-16T23:32:07.987200000', '2013-09-27T04:08:27.974400000', '2013-10-06T23:25:39.964800000', '2013-10-17T02:55:50.995200000', '2013-10-27T03:45:47.001600000', '2013-11-06T01:14:52.022400000', '2013-11-16T03:29:54.009600000', '2013-11-26T03:03:56.995200000', '2013-12-05T23:33:59.011200000', '2013-12-16T02:58:01.977600000', '2013-12-25T23:22:43.017600000', '2014-01-05T02:52:06.009600000', '2014-01-14T23:41:18.009600000', '2014-01-25T03:00:43.977600000', '2014-02-03T23:29:13.977600000', '2014-02-14T02:50:11.961600000', '2014-02-23T23:03:21.974400000', '2014-03-06T02:58:03.964800000', '2014-03-15T23:10:28.012800000', '2014-03-26T02:51:22.032000000', '2014-04-04T23:25:58.972800000', '2014-04-15T03:00:45.964800000', '2014-04-24T23:24:40.003200000', '2014-05-05T02:56:22.012800000', '2014-05-15T00:10:06.009600000', '2014-05-25T03:02:43.036800000', '2014-06-03T23:34:53.961600000', '2014-06-14T03:01:23.980800000', '2014-06-23T23:24:31.968000000', '2014-07-04T03:08:30.019200000', '2014-07-13T23:47:43.008000000', '2014-07-24T03:02:33.014400000'], dtype='datetime64[ns]')
- lon(date)float64-39.13 -37.28 ... -34.11 -34.38
array([-39.13 , -37.282, -36.9 , -36.89 , -37.053, -36.658, -35.963, -35.184, -34.462, -33.784, -32.972, -32.546, -32.428, -32.292, -32.169, -31.998, -31.824, -31.624, -31.433, -31.312, -31.107, -31.147, -31.044, -31.14 , -31.417, -31.882, -32.145, -32.487, -32.537, -32.334, -32.042, -31.892, -31.861, -31.991, -31.883, -31.89 , -31.941, -31.889, -31.724, -31.412, -31.786, -31.561, -31.732, -31.553, -31.862, -32.389, -32.318, -32.19 , -32.224, -32.368, -32.306, -32.305, -32.65 , -33.093, -33.263, -33.199, -33.27 , -33.237, -33.221, -33.011, -32.844, -32.981, -32.784, -32.607, -32.87 , -33.196, -33.524, -33.956, -33.944, -33.71 , -33.621, -33.552, -33.828, -34.11 , -34.38 ])
- lat(date)float6447.19 46.72 46.45 ... 42.46 42.38
array([47.187, 46.716, 46.45 , 46.23 , 45.459, 44.833, 44.452, 44.839, 44.956, 44.676, 44.13 , 43.644, 43.067, 42.662, 42.513, 42.454, 42.396, 42.256, 42.089, 41.944, 41.712, 41.571, 41.596, 41.581, 41.351, 41.032, 40.912, 40.792, 40.495, 40.383, 40.478, 40.672, 41.032, 40.864, 40.651, 40.425, 40.228, 40.197, 40.483, 40.311, 40.457, 40.463, 40.164, 40.047, 39.963, 40.122, 40.57 , 40.476, 40.527, 40.589, 40.749, 40.993, 41.162, 41.237, 41.448, 41.65 , 42.053, 42.311, 42.096, 41.683, 41.661, 41.676, 42.018, 42.395, 42.532, 42.558, 42.504, 42.63 , 42.934, 42.952, 42.777, 42.722, 42.601, 42.457, 42.379])
- salinity(level, date)float6435.64 35.51 35.57 ... nan 34.94 nan
array([[35.6389389 , 35.51495743, 35.57297134, ..., 35.82093811, 35.77793884, 35.66891098], [35.63393784, 35.5219574 , 35.57397079, ..., 35.81093216, 35.58389664, 35.66791153], [35.6819458 , 35.52595901, 35.57297134, ..., 35.79592896, 35.66290665, 35.66591263], ..., [34.91585922, 34.92390442, 34.92390442, ..., 34.93481064, 34.94081116, 34.94680786], [34.91585922, 34.92390442, 34.92190552, ..., 34.93280792, 34.93680954, 34.94380951], [34.91785812, 34.92390442, 34.92390442, ..., nan, 34.93680954, nan]])
- temperature(level, date)float6418.97 18.44 19.1 ... nan 3.714 nan
array([[18.97400093, 18.43700027, 19.09900093, ..., 19.11300087, 21.82299995, 20.13100052], [18.74099922, 18.39999962, 19.08200073, ..., 18.47200012, 19.45999908, 20.125 ], [18.37000084, 18.37400055, 19.06500053, ..., 18.22999954, 19.26199913, 20.07699966], ..., [ 3.79299998, 3.81399989, 3.80200005, ..., 3.80699992, 3.81100011, 3.8599999 ], [ 3.76399994, 3.77800012, 3.75699997, ..., 3.75399995, 3.74600005, 3.80599999], [ 3.74399996, 3.74600005, 3.7249999 , ..., nan, 3.71399999, nan]])
- pressure(level, date)float646.8 6.1 6.5 5.0 ... nan 2e+03 nan
array([[ 6.80000019, 6.0999999 , 6.5 , ..., 7.0999999 , 7.20000029, 6.5 ], [ 10.69999981, 10.59999943, 10.39999962, ..., 10.79999924, 11.09999943, 10.39999962], [ 15.69999981, 14.09999943, 14.89999962, ..., 15.89999962, 15.59999943, 15.89999962], ..., [1900.60009766, 1900. , 1900.19995117, ..., 1899.70007324, 1900.40002441, 1899.80004883], [1949.90002441, 1950. , 1949.89990234, ..., 1950.59997559, 1950.20007324, 1949.70007324], [1999.30004883, 1998. , 1998.5 , ..., nan, 2000.40002441, nan]])
Coordinates vs. Data Variables¶
Data variables can be modified through arithmentic operations or other functions. Coordinates are always keept the same.
argo * 10000
<xarray.Dataset> Dimensions: (level: 78, date: 75) Coordinates: * level (level) int64 0 1 2 3 4 5 6 7 8 ... 69 70 71 72 73 74 75 76 77 * date (date) datetime64[ns] 2012-07-13T22:33:06.019200 ... 2014-07... lon (date) float64 -39.13 -37.28 -36.9 ... -33.83 -34.11 -34.38 lat (date) float64 47.19 46.72 46.45 46.23 ... 42.6 42.46 42.38 Data variables: salinity (level, date) float64 3.564e+05 3.551e+05 ... 3.494e+05 nan temperature (level, date) float64 1.897e+05 1.844e+05 ... 3.714e+04 nan pressure (level, date) float64 6.8e+04 6.1e+04 6.5e+04 ... nan 2e+07 nan
- level: 78
- date: 75
- level(level)int640 1 2 3 4 5 6 ... 72 73 74 75 76 77
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77])
- date(date)datetime64[ns]2012-07-13T22:33:06.019200 ... 2...
array(['2012-07-13T22:33:06.019200000', '2012-07-23T22:54:59.990400000', '2012-08-02T22:55:52.003200000', '2012-08-12T23:08:59.971200000', '2012-08-22T23:29:01.968000000', '2012-09-01T23:17:38.976000000', '2012-09-12T02:59:18.960000000', '2012-09-21T23:18:37.036800000', '2012-10-02T03:00:17.971200000', '2012-10-11T23:13:27.984000000', '2012-10-22T02:50:32.006400000', '2012-10-31T23:36:39.974400000', '2012-11-11T02:40:46.041600000', '2012-11-20T23:08:29.990400000', '2012-12-01T02:47:51.993600000', '2012-12-10T23:23:16.972800000', '2012-12-21T02:58:48.979200000', '2012-12-30T23:07:23.030400000', '2013-01-10T02:56:43.008000000', '2013-01-19T23:24:26.956800000', '2013-01-30T02:43:53.011200000', '2013-02-08T23:15:27.043200000', '2013-02-19T01:12:50.976000000', '2013-02-28T23:07:13.008000000', '2013-03-11T02:43:30.979200000', '2013-03-20T23:17:22.992000000', '2013-03-31T01:50:38.025600000', '2013-04-09T23:19:07.968000000', '2013-04-20T02:53:29.990400000', '2013-04-29T23:28:33.024000000', '2013-05-10T02:50:18.009600000', '2013-05-19T23:21:05.990400000', '2013-05-30T02:50:30.969600000', '2013-06-08T23:32:49.027200000', '2013-06-19T03:42:51.004800000', '2013-06-28T23:32:16.022400000', '2013-07-09T03:28:30.979199999', '2013-07-18T23:33:57.974400000', '2013-07-29T03:15:42.019200000', '2013-08-07T23:25:02.035200000', '2013-08-18T01:47:44.966400000', '2013-08-28T03:02:59.020800000', '2013-09-07T03:03:51.984000000', '2013-09-16T23:32:07.987200000', '2013-09-27T04:08:27.974400000', '2013-10-06T23:25:39.964800000', '2013-10-17T02:55:50.995200000', '2013-10-27T03:45:47.001600000', '2013-11-06T01:14:52.022400000', '2013-11-16T03:29:54.009600000', '2013-11-26T03:03:56.995200000', '2013-12-05T23:33:59.011200000', '2013-12-16T02:58:01.977600000', '2013-12-25T23:22:43.017600000', '2014-01-05T02:52:06.009600000', '2014-01-14T23:41:18.009600000', '2014-01-25T03:00:43.977600000', '2014-02-03T23:29:13.977600000', '2014-02-14T02:50:11.961600000', '2014-02-23T23:03:21.974400000', '2014-03-06T02:58:03.964800000', '2014-03-15T23:10:28.012800000', '2014-03-26T02:51:22.032000000', '2014-04-04T23:25:58.972800000', '2014-04-15T03:00:45.964800000', '2014-04-24T23:24:40.003200000', '2014-05-05T02:56:22.012800000', '2014-05-15T00:10:06.009600000', '2014-05-25T03:02:43.036800000', '2014-06-03T23:34:53.961600000', '2014-06-14T03:01:23.980800000', '2014-06-23T23:24:31.968000000', '2014-07-04T03:08:30.019200000', '2014-07-13T23:47:43.008000000', '2014-07-24T03:02:33.014400000'], dtype='datetime64[ns]')
- lon(date)float64-39.13 -37.28 ... -34.11 -34.38
array([-39.13 , -37.282, -36.9 , -36.89 , -37.053, -36.658, -35.963, -35.184, -34.462, -33.784, -32.972, -32.546, -32.428, -32.292, -32.169, -31.998, -31.824, -31.624, -31.433, -31.312, -31.107, -31.147, -31.044, -31.14 , -31.417, -31.882, -32.145, -32.487, -32.537, -32.334, -32.042, -31.892, -31.861, -31.991, -31.883, -31.89 , -31.941, -31.889, -31.724, -31.412, -31.786, -31.561, -31.732, -31.553, -31.862, -32.389, -32.318, -32.19 , -32.224, -32.368, -32.306, -32.305, -32.65 , -33.093, -33.263, -33.199, -33.27 , -33.237, -33.221, -33.011, -32.844, -32.981, -32.784, -32.607, -32.87 , -33.196, -33.524, -33.956, -33.944, -33.71 , -33.621, -33.552, -33.828, -34.11 , -34.38 ])
- lat(date)float6447.19 46.72 46.45 ... 42.46 42.38
array([47.187, 46.716, 46.45 , 46.23 , 45.459, 44.833, 44.452, 44.839, 44.956, 44.676, 44.13 , 43.644, 43.067, 42.662, 42.513, 42.454, 42.396, 42.256, 42.089, 41.944, 41.712, 41.571, 41.596, 41.581, 41.351, 41.032, 40.912, 40.792, 40.495, 40.383, 40.478, 40.672, 41.032, 40.864, 40.651, 40.425, 40.228, 40.197, 40.483, 40.311, 40.457, 40.463, 40.164, 40.047, 39.963, 40.122, 40.57 , 40.476, 40.527, 40.589, 40.749, 40.993, 41.162, 41.237, 41.448, 41.65 , 42.053, 42.311, 42.096, 41.683, 41.661, 41.676, 42.018, 42.395, 42.532, 42.558, 42.504, 42.63 , 42.934, 42.952, 42.777, 42.722, 42.601, 42.457, 42.379])
- salinity(level, date)float643.564e+05 3.551e+05 ... nan
array([[356389.38903809, 355149.57427979, 355729.71343994, ..., 358209.38110352, 357779.38842773, 356689.10980225], [356339.37835693, 355219.57397461, 355739.70794678, ..., 358109.32159424, 355838.96636963, 356679.11529541], [356819.45800781, 355259.59014893, 355729.71343994, ..., 357959.28955078, 356629.06646729, 356659.12628174], ..., [349158.59222412, 349239.04418945, 349239.04418945, ..., 349348.10638428, 349408.11157227, 349468.07861328], [349158.59222412, 349239.04418945, 349219.05517578, ..., 349328.07922363, 349368.09539795, 349438.09509277], [349178.58123779, 349239.04418945, 349239.04418945, ..., nan, 349368.09539795, nan]])
- temperature(level, date)float641.897e+05 1.844e+05 ... nan
array([[189740.00930786, 184370.00274658, 190990.00930786, ..., 191130.00869751, 218229.99954224, 201310.00518799], [187409.99221802, 183999.9961853 , 190820.00732422, ..., 184720.0012207 , 194599.99084473, 201250. ], [183700.00839233, 183740.00549316, 190650.00534058, ..., 182299.99542236, 192619.99130249, 200769.99664307], ..., [ 37929.99982834, 38139.99891281, 38020.00045776, ..., 38069.99921799, 38110.00108719, 38599.99895096], [ 37639.99938965, 37780.00116348, 37569.99969482, ..., 37539.99948502, 37460.00051498, 38059.99994278], [ 37439.99958038, 37460.00051498, 37249.99904633, ..., nan, 37139.99986649, nan]])
- pressure(level, date)float646.8e+04 6.1e+04 ... 2e+07 nan
array([[ 68000.00190735, 60999.99904633, 65000. , ..., 70999.99904633, 72000.00286102, 65000. ], [ 106999.99809265, 105999.99427795, 103999.9961853 , ..., 107999.99237061, 110999.99427795, 103999.9961853 ], [ 156999.99809265, 140999.99427795, 148999.9961853 , ..., 158999.9961853 , 155999.99427795, 158999.9961853 ], ..., [19006000.9765625 , 19000000. , 19001999.51171875, ..., 18997000.73242188, 19004000.24414062, 18998000.48828125], [19499000.24414062, 19500000. , 19498999.0234375 , ..., 19505999.75585938, 19502000.73242188, 19497000.73242188], [19993000.48828125, 19980000. , 19985000. , ..., nan, 20004000.24414062, nan]])
Clearly lon and lat are coordinates rather than data variables. We can change their status as follows:
argo = argo.set_coords(['lon', 'lat'])
argo
<xarray.Dataset> Dimensions: (level: 78, date: 75) Coordinates: * level (level) int64 0 1 2 3 4 5 6 7 8 ... 69 70 71 72 73 74 75 76 77 * date (date) datetime64[ns] 2012-07-13T22:33:06.019200 ... 2014-07... lon (date) float64 -39.13 -37.28 -36.9 ... -33.83 -34.11 -34.38 lat (date) float64 47.19 46.72 46.45 46.23 ... 42.6 42.46 42.38 Data variables: salinity (level, date) float64 35.64 35.51 35.57 35.4 ... nan 34.94 nan temperature (level, date) float64 18.97 18.44 19.1 19.79 ... nan 3.714 nan pressure (level, date) float64 6.8 6.1 6.5 5.0 ... 2e+03 nan 2e+03 nan
- level: 78
- date: 75
- level(level)int640 1 2 3 4 5 6 ... 72 73 74 75 76 77
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77])
- date(date)datetime64[ns]2012-07-13T22:33:06.019200 ... 2...
array(['2012-07-13T22:33:06.019200000', '2012-07-23T22:54:59.990400000', '2012-08-02T22:55:52.003200000', '2012-08-12T23:08:59.971200000', '2012-08-22T23:29:01.968000000', '2012-09-01T23:17:38.976000000', '2012-09-12T02:59:18.960000000', '2012-09-21T23:18:37.036800000', '2012-10-02T03:00:17.971200000', '2012-10-11T23:13:27.984000000', '2012-10-22T02:50:32.006400000', '2012-10-31T23:36:39.974400000', '2012-11-11T02:40:46.041600000', '2012-11-20T23:08:29.990400000', '2012-12-01T02:47:51.993600000', '2012-12-10T23:23:16.972800000', '2012-12-21T02:58:48.979200000', '2012-12-30T23:07:23.030400000', '2013-01-10T02:56:43.008000000', '2013-01-19T23:24:26.956800000', '2013-01-30T02:43:53.011200000', '2013-02-08T23:15:27.043200000', '2013-02-19T01:12:50.976000000', '2013-02-28T23:07:13.008000000', '2013-03-11T02:43:30.979200000', '2013-03-20T23:17:22.992000000', '2013-03-31T01:50:38.025600000', '2013-04-09T23:19:07.968000000', '2013-04-20T02:53:29.990400000', '2013-04-29T23:28:33.024000000', '2013-05-10T02:50:18.009600000', '2013-05-19T23:21:05.990400000', '2013-05-30T02:50:30.969600000', '2013-06-08T23:32:49.027200000', '2013-06-19T03:42:51.004800000', '2013-06-28T23:32:16.022400000', '2013-07-09T03:28:30.979199999', '2013-07-18T23:33:57.974400000', '2013-07-29T03:15:42.019200000', '2013-08-07T23:25:02.035200000', '2013-08-18T01:47:44.966400000', '2013-08-28T03:02:59.020800000', '2013-09-07T03:03:51.984000000', '2013-09-16T23:32:07.987200000', '2013-09-27T04:08:27.974400000', '2013-10-06T23:25:39.964800000', '2013-10-17T02:55:50.995200000', '2013-10-27T03:45:47.001600000', '2013-11-06T01:14:52.022400000', '2013-11-16T03:29:54.009600000', '2013-11-26T03:03:56.995200000', '2013-12-05T23:33:59.011200000', '2013-12-16T02:58:01.977600000', '2013-12-25T23:22:43.017600000', '2014-01-05T02:52:06.009600000', '2014-01-14T23:41:18.009600000', '2014-01-25T03:00:43.977600000', '2014-02-03T23:29:13.977600000', '2014-02-14T02:50:11.961600000', '2014-02-23T23:03:21.974400000', '2014-03-06T02:58:03.964800000', '2014-03-15T23:10:28.012800000', '2014-03-26T02:51:22.032000000', '2014-04-04T23:25:58.972800000', '2014-04-15T03:00:45.964800000', '2014-04-24T23:24:40.003200000', '2014-05-05T02:56:22.012800000', '2014-05-15T00:10:06.009600000', '2014-05-25T03:02:43.036800000', '2014-06-03T23:34:53.961600000', '2014-06-14T03:01:23.980800000', '2014-06-23T23:24:31.968000000', '2014-07-04T03:08:30.019200000', '2014-07-13T23:47:43.008000000', '2014-07-24T03:02:33.014400000'], dtype='datetime64[ns]')
- lon(date)float64-39.13 -37.28 ... -34.11 -34.38
array([-39.13 , -37.282, -36.9 , -36.89 , -37.053, -36.658, -35.963, -35.184, -34.462, -33.784, -32.972, -32.546, -32.428, -32.292, -32.169, -31.998, -31.824, -31.624, -31.433, -31.312, -31.107, -31.147, -31.044, -31.14 , -31.417, -31.882, -32.145, -32.487, -32.537, -32.334, -32.042, -31.892, -31.861, -31.991, -31.883, -31.89 , -31.941, -31.889, -31.724, -31.412, -31.786, -31.561, -31.732, -31.553, -31.862, -32.389, -32.318, -32.19 , -32.224, -32.368, -32.306, -32.305, -32.65 , -33.093, -33.263, -33.199, -33.27 , -33.237, -33.221, -33.011, -32.844, -32.981, -32.784, -32.607, -32.87 , -33.196, -33.524, -33.956, -33.944, -33.71 , -33.621, -33.552, -33.828, -34.11 , -34.38 ])
- lat(date)float6447.19 46.72 46.45 ... 42.46 42.38
array([47.187, 46.716, 46.45 , 46.23 , 45.459, 44.833, 44.452, 44.839, 44.956, 44.676, 44.13 , 43.644, 43.067, 42.662, 42.513, 42.454, 42.396, 42.256, 42.089, 41.944, 41.712, 41.571, 41.596, 41.581, 41.351, 41.032, 40.912, 40.792, 40.495, 40.383, 40.478, 40.672, 41.032, 40.864, 40.651, 40.425, 40.228, 40.197, 40.483, 40.311, 40.457, 40.463, 40.164, 40.047, 39.963, 40.122, 40.57 , 40.476, 40.527, 40.589, 40.749, 40.993, 41.162, 41.237, 41.448, 41.65 , 42.053, 42.311, 42.096, 41.683, 41.661, 41.676, 42.018, 42.395, 42.532, 42.558, 42.504, 42.63 , 42.934, 42.952, 42.777, 42.722, 42.601, 42.457, 42.379])
- salinity(level, date)float6435.64 35.51 35.57 ... nan 34.94 nan
array([[35.6389389 , 35.51495743, 35.57297134, ..., 35.82093811, 35.77793884, 35.66891098], [35.63393784, 35.5219574 , 35.57397079, ..., 35.81093216, 35.58389664, 35.66791153], [35.6819458 , 35.52595901, 35.57297134, ..., 35.79592896, 35.66290665, 35.66591263], ..., [34.91585922, 34.92390442, 34.92390442, ..., 34.93481064, 34.94081116, 34.94680786], [34.91585922, 34.92390442, 34.92190552, ..., 34.93280792, 34.93680954, 34.94380951], [34.91785812, 34.92390442, 34.92390442, ..., nan, 34.93680954, nan]])
- temperature(level, date)float6418.97 18.44 19.1 ... nan 3.714 nan
array([[18.97400093, 18.43700027, 19.09900093, ..., 19.11300087, 21.82299995, 20.13100052], [18.74099922, 18.39999962, 19.08200073, ..., 18.47200012, 19.45999908, 20.125 ], [18.37000084, 18.37400055, 19.06500053, ..., 18.22999954, 19.26199913, 20.07699966], ..., [ 3.79299998, 3.81399989, 3.80200005, ..., 3.80699992, 3.81100011, 3.8599999 ], [ 3.76399994, 3.77800012, 3.75699997, ..., 3.75399995, 3.74600005, 3.80599999], [ 3.74399996, 3.74600005, 3.7249999 , ..., nan, 3.71399999, nan]])
- pressure(level, date)float646.8 6.1 6.5 5.0 ... nan 2e+03 nan
array([[ 6.80000019, 6.0999999 , 6.5 , ..., 7.0999999 , 7.20000029, 6.5 ], [ 10.69999981, 10.59999943, 10.39999962, ..., 10.79999924, 11.09999943, 10.39999962], [ 15.69999981, 14.09999943, 14.89999962, ..., 15.89999962, 15.59999943, 15.89999962], ..., [1900.60009766, 1900. , 1900.19995117, ..., 1899.70007324, 1900.40002441, 1899.80004883], [1949.90002441, 1950. , 1949.89990234, ..., 1950.59997559, 1950.20007324, 1949.70007324], [1999.30004883, 1998. , 1998.5 , ..., nan, 2000.40002441, nan]])
The *
symbol in the representation above indicates that level
and date
are “dimension coordinates” (they describe the coordinates associated with data variable axes) while lon
and lat
are “non-dimension coordinates”. We can make any variable a non-dimension coordiante.
Alternatively, we could have assigned directly to coords as follows:
argo.coords['lon'] = ('date', lon)
argo.coords['lat'] = ('date', lat)
Selecting Data (Indexing)¶
We can always use regular numpy indexing and slicing on DataArrays
argo.salinity[2]
<xarray.DataArray 'salinity' (date: 75)> array([35.6819458 , 35.52595901, 35.57297134, 35.40494537, 35.45091629, 35.50192261, 35.62397766, 35.51696014, 35.62797546, 35.52292252, 35.47383118, 35.33785629, 35.81896591, 35.88694 , 35.90187836, 36.02391815, 36.00475693, 35.94187927, 35.91583252, 35.86392212, 35.81995392, 35.88601303, 35.95079422, 35.84091568, 35.87992477, nan, 35.92179108, 35.96979141, 36.0008316 , 35.98083115, 35.92887878, 35.98091888, 35.9838829 , 36.01884842, 35.99092484, 36.04689026, 36.04185867, nan, 36.19193268, 36.22789764, 36.20986557, 35.97589874, 36.2779007 , 36.25889969, 36.2418251 , 36.23685837, 36.19781876, 36.19785309, 36.17692184, 36.1048851 , 36.11392212, 36.09080505, nan, 36.05675888, 35.93374634, 36.04291534, 36.10183716, 35.97779083, 35.86592102, 35.87791824, 35.88392258, 35.92078781, 35.88601303, 36.05178833, 35.85883713, 35.94878769, 35.8938446 , 35.94379425, 35.90884018, 35.84893036, 35.83496857, 35.71691132, 35.79592896, 35.66290665, 35.66591263]) Coordinates: level int64 2 * date (date) datetime64[ns] 2012-07-13T22:33:06.019200 ... 2014-07-24T... lon (date) float64 -39.13 -37.28 -36.9 -36.89 ... -33.83 -34.11 -34.38 lat (date) float64 47.19 46.72 46.45 46.23 ... 42.72 42.6 42.46 42.38
- date: 75
- 35.68 35.53 35.57 35.4 35.45 35.5 ... 35.83 35.72 35.8 35.66 35.67
array([35.6819458 , 35.52595901, 35.57297134, 35.40494537, 35.45091629, 35.50192261, 35.62397766, 35.51696014, 35.62797546, 35.52292252, 35.47383118, 35.33785629, 35.81896591, 35.88694 , 35.90187836, 36.02391815, 36.00475693, 35.94187927, 35.91583252, 35.86392212, 35.81995392, 35.88601303, 35.95079422, 35.84091568, 35.87992477, nan, 35.92179108, 35.96979141, 36.0008316 , 35.98083115, 35.92887878, 35.98091888, 35.9838829 , 36.01884842, 35.99092484, 36.04689026, 36.04185867, nan, 36.19193268, 36.22789764, 36.20986557, 35.97589874, 36.2779007 , 36.25889969, 36.2418251 , 36.23685837, 36.19781876, 36.19785309, 36.17692184, 36.1048851 , 36.11392212, 36.09080505, nan, 36.05675888, 35.93374634, 36.04291534, 36.10183716, 35.97779083, 35.86592102, 35.87791824, 35.88392258, 35.92078781, 35.88601303, 36.05178833, 35.85883713, 35.94878769, 35.8938446 , 35.94379425, 35.90884018, 35.84893036, 35.83496857, 35.71691132, 35.79592896, 35.66290665, 35.66591263])
- level()int642
array(2)
- date(date)datetime64[ns]2012-07-13T22:33:06.019200 ... 2...
array(['2012-07-13T22:33:06.019200000', '2012-07-23T22:54:59.990400000', '2012-08-02T22:55:52.003200000', '2012-08-12T23:08:59.971200000', '2012-08-22T23:29:01.968000000', '2012-09-01T23:17:38.976000000', '2012-09-12T02:59:18.960000000', '2012-09-21T23:18:37.036800000', '2012-10-02T03:00:17.971200000', '2012-10-11T23:13:27.984000000', '2012-10-22T02:50:32.006400000', '2012-10-31T23:36:39.974400000', '2012-11-11T02:40:46.041600000', '2012-11-20T23:08:29.990400000', '2012-12-01T02:47:51.993600000', '2012-12-10T23:23:16.972800000', '2012-12-21T02:58:48.979200000', '2012-12-30T23:07:23.030400000', '2013-01-10T02:56:43.008000000', '2013-01-19T23:24:26.956800000', '2013-01-30T02:43:53.011200000', '2013-02-08T23:15:27.043200000', '2013-02-19T01:12:50.976000000', '2013-02-28T23:07:13.008000000', '2013-03-11T02:43:30.979200000', '2013-03-20T23:17:22.992000000', '2013-03-31T01:50:38.025600000', '2013-04-09T23:19:07.968000000', '2013-04-20T02:53:29.990400000', '2013-04-29T23:28:33.024000000', '2013-05-10T02:50:18.009600000', '2013-05-19T23:21:05.990400000', '2013-05-30T02:50:30.969600000', '2013-06-08T23:32:49.027200000', '2013-06-19T03:42:51.004800000', '2013-06-28T23:32:16.022400000', '2013-07-09T03:28:30.979199999', '2013-07-18T23:33:57.974400000', '2013-07-29T03:15:42.019200000', '2013-08-07T23:25:02.035200000', '2013-08-18T01:47:44.966400000', '2013-08-28T03:02:59.020800000', '2013-09-07T03:03:51.984000000', '2013-09-16T23:32:07.987200000', '2013-09-27T04:08:27.974400000', '2013-10-06T23:25:39.964800000', '2013-10-17T02:55:50.995200000', '2013-10-27T03:45:47.001600000', '2013-11-06T01:14:52.022400000', '2013-11-16T03:29:54.009600000', '2013-11-26T03:03:56.995200000', '2013-12-05T23:33:59.011200000', '2013-12-16T02:58:01.977600000', '2013-12-25T23:22:43.017600000', '2014-01-05T02:52:06.009600000', '2014-01-14T23:41:18.009600000', '2014-01-25T03:00:43.977600000', '2014-02-03T23:29:13.977600000', '2014-02-14T02:50:11.961600000', '2014-02-23T23:03:21.974400000', '2014-03-06T02:58:03.964800000', '2014-03-15T23:10:28.012800000', '2014-03-26T02:51:22.032000000', '2014-04-04T23:25:58.972800000', '2014-04-15T03:00:45.964800000', '2014-04-24T23:24:40.003200000', '2014-05-05T02:56:22.012800000', '2014-05-15T00:10:06.009600000', '2014-05-25T03:02:43.036800000', '2014-06-03T23:34:53.961600000', '2014-06-14T03:01:23.980800000', '2014-06-23T23:24:31.968000000', '2014-07-04T03:08:30.019200000', '2014-07-13T23:47:43.008000000', '2014-07-24T03:02:33.014400000'], dtype='datetime64[ns]')
- lon(date)float64-39.13 -37.28 ... -34.11 -34.38
array([-39.13 , -37.282, -36.9 , -36.89 , -37.053, -36.658, -35.963, -35.184, -34.462, -33.784, -32.972, -32.546, -32.428, -32.292, -32.169, -31.998, -31.824, -31.624, -31.433, -31.312, -31.107, -31.147, -31.044, -31.14 , -31.417, -31.882, -32.145, -32.487, -32.537, -32.334, -32.042, -31.892, -31.861, -31.991, -31.883, -31.89 , -31.941, -31.889, -31.724, -31.412, -31.786, -31.561, -31.732, -31.553, -31.862, -32.389, -32.318, -32.19 , -32.224, -32.368, -32.306, -32.305, -32.65 , -33.093, -33.263, -33.199, -33.27 , -33.237, -33.221, -33.011, -32.844, -32.981, -32.784, -32.607, -32.87 , -33.196, -33.524, -33.956, -33.944, -33.71 , -33.621, -33.552, -33.828, -34.11 , -34.38 ])
- lat(date)float6447.19 46.72 46.45 ... 42.46 42.38
array([47.187, 46.716, 46.45 , 46.23 , 45.459, 44.833, 44.452, 44.839, 44.956, 44.676, 44.13 , 43.644, 43.067, 42.662, 42.513, 42.454, 42.396, 42.256, 42.089, 41.944, 41.712, 41.571, 41.596, 41.581, 41.351, 41.032, 40.912, 40.792, 40.495, 40.383, 40.478, 40.672, 41.032, 40.864, 40.651, 40.425, 40.228, 40.197, 40.483, 40.311, 40.457, 40.463, 40.164, 40.047, 39.963, 40.122, 40.57 , 40.476, 40.527, 40.589, 40.749, 40.993, 41.162, 41.237, 41.448, 41.65 , 42.053, 42.311, 42.096, 41.683, 41.661, 41.676, 42.018, 42.395, 42.532, 42.558, 42.504, 42.63 , 42.934, 42.952, 42.777, 42.722, 42.601, 42.457, 42.379])
argo.salinity[2].plot()
[<matplotlib.lines.Line2D at 0x7f79743fd0d0>]

argo.salinity[:, 10]
<xarray.DataArray 'salinity' (level: 78)> array([35.47483063, 35.47483063, 35.47383118, 35.47383118, 35.47383118, 35.47483063, 35.48183441, 35.47983551, 35.4948349 , 35.51083755, 36.13380051, 36.09579849, 35.95479965, 35.93979645, 35.8958931 , 35.86388397, 35.87788773, 35.88188934, 35.90379333, 35.9067955 , 35.86588669, 35.8588829 , 35.86088181, 35.85188293, 35.85788345, 35.82787323, 35.78786469, 35.73185349, 35.69784927, 35.67684174, 35.677845 , 35.65784073, 35.64083481, 35.6238327 , 35.59682846, 35.57782364, 35.56182098, 35.55781937, 35.52181625, 35.49881363, 35.51381302, 35.49981308, 35.47280884, 35.47880936, 35.44780731, 35.39379501, 35.35879135, 35.28778076, 35.21878052, 35.20677567, 35.17777252, 35.15076828, 35.07276535, 35.01475525, 34.9797554 , 35.0117569 , 35.03975677, 35.05575562, 35.00975037, 34.96175385, 34.96775055, 34.95075226, 34.93775177, 34.93375015, 34.93775558, 34.9247551 , 34.92175674, 34.91975403, 34.91975403, 34.91975403, 34.92176056, 34.92375946, 34.92575836, 34.92575836, 34.92475891, 34.93076324, 34.92176437, nan]) Coordinates: * level (level) int64 0 1 2 3 4 5 6 7 8 9 ... 68 69 70 71 72 73 74 75 76 77 date datetime64[ns] 2012-10-22T02:50:32.006400 lon float64 -32.97 lat float64 44.13
- level: 78
- 35.47 35.47 35.47 35.47 35.47 35.47 ... 34.93 34.92 34.93 34.92 nan
array([35.47483063, 35.47483063, 35.47383118, 35.47383118, 35.47383118, 35.47483063, 35.48183441, 35.47983551, 35.4948349 , 35.51083755, 36.13380051, 36.09579849, 35.95479965, 35.93979645, 35.8958931 , 35.86388397, 35.87788773, 35.88188934, 35.90379333, 35.9067955 , 35.86588669, 35.8588829 , 35.86088181, 35.85188293, 35.85788345, 35.82787323, 35.78786469, 35.73185349, 35.69784927, 35.67684174, 35.677845 , 35.65784073, 35.64083481, 35.6238327 , 35.59682846, 35.57782364, 35.56182098, 35.55781937, 35.52181625, 35.49881363, 35.51381302, 35.49981308, 35.47280884, 35.47880936, 35.44780731, 35.39379501, 35.35879135, 35.28778076, 35.21878052, 35.20677567, 35.17777252, 35.15076828, 35.07276535, 35.01475525, 34.9797554 , 35.0117569 , 35.03975677, 35.05575562, 35.00975037, 34.96175385, 34.96775055, 34.95075226, 34.93775177, 34.93375015, 34.93775558, 34.9247551 , 34.92175674, 34.91975403, 34.91975403, 34.91975403, 34.92176056, 34.92375946, 34.92575836, 34.92575836, 34.92475891, 34.93076324, 34.92176437, nan])
- level(level)int640 1 2 3 4 5 6 ... 72 73 74 75 76 77
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77])
- date()datetime64[ns]2012-10-22T02:50:32.006400
array('2012-10-22T02:50:32.006400000', dtype='datetime64[ns]')
- lon()float64-32.97
array(-32.972)
- lat()float6444.13
array(44.13)
argo.salinity[:, 10].plot()
[<matplotlib.lines.Line2D at 0x7f797430ae50>]

However, it is often much more powerful to use xarray’s .sel()
method to use label-based indexing.
argo.salinity.sel(level=2)
<xarray.DataArray 'salinity' (date: 75)> array([35.6819458 , 35.52595901, 35.57297134, 35.40494537, 35.45091629, 35.50192261, 35.62397766, 35.51696014, 35.62797546, 35.52292252, 35.47383118, 35.33785629, 35.81896591, 35.88694 , 35.90187836, 36.02391815, 36.00475693, 35.94187927, 35.91583252, 35.86392212, 35.81995392, 35.88601303, 35.95079422, 35.84091568, 35.87992477, nan, 35.92179108, 35.96979141, 36.0008316 , 35.98083115, 35.92887878, 35.98091888, 35.9838829 , 36.01884842, 35.99092484, 36.04689026, 36.04185867, nan, 36.19193268, 36.22789764, 36.20986557, 35.97589874, 36.2779007 , 36.25889969, 36.2418251 , 36.23685837, 36.19781876, 36.19785309, 36.17692184, 36.1048851 , 36.11392212, 36.09080505, nan, 36.05675888, 35.93374634, 36.04291534, 36.10183716, 35.97779083, 35.86592102, 35.87791824, 35.88392258, 35.92078781, 35.88601303, 36.05178833, 35.85883713, 35.94878769, 35.8938446 , 35.94379425, 35.90884018, 35.84893036, 35.83496857, 35.71691132, 35.79592896, 35.66290665, 35.66591263]) Coordinates: level int64 2 * date (date) datetime64[ns] 2012-07-13T22:33:06.019200 ... 2014-07-24T... lon (date) float64 -39.13 -37.28 -36.9 -36.89 ... -33.83 -34.11 -34.38 lat (date) float64 47.19 46.72 46.45 46.23 ... 42.72 42.6 42.46 42.38
- date: 75
- 35.68 35.53 35.57 35.4 35.45 35.5 ... 35.83 35.72 35.8 35.66 35.67
array([35.6819458 , 35.52595901, 35.57297134, 35.40494537, 35.45091629, 35.50192261, 35.62397766, 35.51696014, 35.62797546, 35.52292252, 35.47383118, 35.33785629, 35.81896591, 35.88694 , 35.90187836, 36.02391815, 36.00475693, 35.94187927, 35.91583252, 35.86392212, 35.81995392, 35.88601303, 35.95079422, 35.84091568, 35.87992477, nan, 35.92179108, 35.96979141, 36.0008316 , 35.98083115, 35.92887878, 35.98091888, 35.9838829 , 36.01884842, 35.99092484, 36.04689026, 36.04185867, nan, 36.19193268, 36.22789764, 36.20986557, 35.97589874, 36.2779007 , 36.25889969, 36.2418251 , 36.23685837, 36.19781876, 36.19785309, 36.17692184, 36.1048851 , 36.11392212, 36.09080505, nan, 36.05675888, 35.93374634, 36.04291534, 36.10183716, 35.97779083, 35.86592102, 35.87791824, 35.88392258, 35.92078781, 35.88601303, 36.05178833, 35.85883713, 35.94878769, 35.8938446 , 35.94379425, 35.90884018, 35.84893036, 35.83496857, 35.71691132, 35.79592896, 35.66290665, 35.66591263])
- level()int642
array(2)
- date(date)datetime64[ns]2012-07-13T22:33:06.019200 ... 2...
array(['2012-07-13T22:33:06.019200000', '2012-07-23T22:54:59.990400000', '2012-08-02T22:55:52.003200000', '2012-08-12T23:08:59.971200000', '2012-08-22T23:29:01.968000000', '2012-09-01T23:17:38.976000000', '2012-09-12T02:59:18.960000000', '2012-09-21T23:18:37.036800000', '2012-10-02T03:00:17.971200000', '2012-10-11T23:13:27.984000000', '2012-10-22T02:50:32.006400000', '2012-10-31T23:36:39.974400000', '2012-11-11T02:40:46.041600000', '2012-11-20T23:08:29.990400000', '2012-12-01T02:47:51.993600000', '2012-12-10T23:23:16.972800000', '2012-12-21T02:58:48.979200000', '2012-12-30T23:07:23.030400000', '2013-01-10T02:56:43.008000000', '2013-01-19T23:24:26.956800000', '2013-01-30T02:43:53.011200000', '2013-02-08T23:15:27.043200000', '2013-02-19T01:12:50.976000000', '2013-02-28T23:07:13.008000000', '2013-03-11T02:43:30.979200000', '2013-03-20T23:17:22.992000000', '2013-03-31T01:50:38.025600000', '2013-04-09T23:19:07.968000000', '2013-04-20T02:53:29.990400000', '2013-04-29T23:28:33.024000000', '2013-05-10T02:50:18.009600000', '2013-05-19T23:21:05.990400000', '2013-05-30T02:50:30.969600000', '2013-06-08T23:32:49.027200000', '2013-06-19T03:42:51.004800000', '2013-06-28T23:32:16.022400000', '2013-07-09T03:28:30.979199999', '2013-07-18T23:33:57.974400000', '2013-07-29T03:15:42.019200000', '2013-08-07T23:25:02.035200000', '2013-08-18T01:47:44.966400000', '2013-08-28T03:02:59.020800000', '2013-09-07T03:03:51.984000000', '2013-09-16T23:32:07.987200000', '2013-09-27T04:08:27.974400000', '2013-10-06T23:25:39.964800000', '2013-10-17T02:55:50.995200000', '2013-10-27T03:45:47.001600000', '2013-11-06T01:14:52.022400000', '2013-11-16T03:29:54.009600000', '2013-11-26T03:03:56.995200000', '2013-12-05T23:33:59.011200000', '2013-12-16T02:58:01.977600000', '2013-12-25T23:22:43.017600000', '2014-01-05T02:52:06.009600000', '2014-01-14T23:41:18.009600000', '2014-01-25T03:00:43.977600000', '2014-02-03T23:29:13.977600000', '2014-02-14T02:50:11.961600000', '2014-02-23T23:03:21.974400000', '2014-03-06T02:58:03.964800000', '2014-03-15T23:10:28.012800000', '2014-03-26T02:51:22.032000000', '2014-04-04T23:25:58.972800000', '2014-04-15T03:00:45.964800000', '2014-04-24T23:24:40.003200000', '2014-05-05T02:56:22.012800000', '2014-05-15T00:10:06.009600000', '2014-05-25T03:02:43.036800000', '2014-06-03T23:34:53.961600000', '2014-06-14T03:01:23.980800000', '2014-06-23T23:24:31.968000000', '2014-07-04T03:08:30.019200000', '2014-07-13T23:47:43.008000000', '2014-07-24T03:02:33.014400000'], dtype='datetime64[ns]')
- lon(date)float64-39.13 -37.28 ... -34.11 -34.38
array([-39.13 , -37.282, -36.9 , -36.89 , -37.053, -36.658, -35.963, -35.184, -34.462, -33.784, -32.972, -32.546, -32.428, -32.292, -32.169, -31.998, -31.824, -31.624, -31.433, -31.312, -31.107, -31.147, -31.044, -31.14 , -31.417, -31.882, -32.145, -32.487, -32.537, -32.334, -32.042, -31.892, -31.861, -31.991, -31.883, -31.89 , -31.941, -31.889, -31.724, -31.412, -31.786, -31.561, -31.732, -31.553, -31.862, -32.389, -32.318, -32.19 , -32.224, -32.368, -32.306, -32.305, -32.65 , -33.093, -33.263, -33.199, -33.27 , -33.237, -33.221, -33.011, -32.844, -32.981, -32.784, -32.607, -32.87 , -33.196, -33.524, -33.956, -33.944, -33.71 , -33.621, -33.552, -33.828, -34.11 , -34.38 ])
- lat(date)float6447.19 46.72 46.45 ... 42.46 42.38
array([47.187, 46.716, 46.45 , 46.23 , 45.459, 44.833, 44.452, 44.839, 44.956, 44.676, 44.13 , 43.644, 43.067, 42.662, 42.513, 42.454, 42.396, 42.256, 42.089, 41.944, 41.712, 41.571, 41.596, 41.581, 41.351, 41.032, 40.912, 40.792, 40.495, 40.383, 40.478, 40.672, 41.032, 40.864, 40.651, 40.425, 40.228, 40.197, 40.483, 40.311, 40.457, 40.463, 40.164, 40.047, 39.963, 40.122, 40.57 , 40.476, 40.527, 40.589, 40.749, 40.993, 41.162, 41.237, 41.448, 41.65 , 42.053, 42.311, 42.096, 41.683, 41.661, 41.676, 42.018, 42.395, 42.532, 42.558, 42.504, 42.63 , 42.934, 42.952, 42.777, 42.722, 42.601, 42.457, 42.379])
argo.salinity.sel(level=2).plot()
[<matplotlib.lines.Line2D at 0x7f79742d0730>]

argo.salinity.sel(date='2012-10-22')
<xarray.DataArray 'salinity' (level: 78, date: 1)> array([[35.47483063], [35.47483063], [35.47383118], [35.47383118], [35.47383118], [35.47483063], [35.48183441], [35.47983551], [35.4948349 ], [35.51083755], [36.13380051], [36.09579849], [35.95479965], [35.93979645], [35.8958931 ], [35.86388397], [35.87788773], [35.88188934], [35.90379333], [35.9067955 ], ... [35.00975037], [34.96175385], [34.96775055], [34.95075226], [34.93775177], [34.93375015], [34.93775558], [34.9247551 ], [34.92175674], [34.91975403], [34.91975403], [34.91975403], [34.92176056], [34.92375946], [34.92575836], [34.92575836], [34.92475891], [34.93076324], [34.92176437], [ nan]]) Coordinates: * level (level) int64 0 1 2 3 4 5 6 7 8 9 ... 68 69 70 71 72 73 74 75 76 77 * date (date) datetime64[ns] 2012-10-22T02:50:32.006400 lon (date) float64 -32.97 lat (date) float64 44.13
- level: 78
- date: 1
- 35.47 35.47 35.47 35.47 35.47 35.47 ... 34.93 34.92 34.93 34.92 nan
array([[35.47483063], [35.47483063], [35.47383118], [35.47383118], [35.47383118], [35.47483063], [35.48183441], [35.47983551], [35.4948349 ], [35.51083755], [36.13380051], [36.09579849], [35.95479965], [35.93979645], [35.8958931 ], [35.86388397], [35.87788773], [35.88188934], [35.90379333], [35.9067955 ], ... [35.00975037], [34.96175385], [34.96775055], [34.95075226], [34.93775177], [34.93375015], [34.93775558], [34.9247551 ], [34.92175674], [34.91975403], [34.91975403], [34.91975403], [34.92176056], [34.92375946], [34.92575836], [34.92575836], [34.92475891], [34.93076324], [34.92176437], [ nan]])
- level(level)int640 1 2 3 4 5 6 ... 72 73 74 75 76 77
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77])
- date(date)datetime64[ns]2012-10-22T02:50:32.006400
array(['2012-10-22T02:50:32.006400000'], dtype='datetime64[ns]')
- lon(date)float64-32.97
array([-32.972])
- lat(date)float6444.13
array([44.13])
argo.salinity.sel(date='2012-10-22').plot(y='level', yincrease=False)
[<matplotlib.lines.Line2D at 0x7f7974269b20>]

.sel()
also supports slicing. Unfortunately we have to use a somewhat awkward syntax, but it still works.
argo.salinity.sel(date=slice('2012-10-01', '2012-12-01'))
<xarray.DataArray 'salinity' (level: 78, date: 7)> array([[35.63097763, 35.52592468, 35.47483063, 35.33785629, 35.81896591, 35.8889389 , 35.90187836], [35.63097763, 35.52292252, 35.47483063, 35.33685684, 35.81796646, 35.88793945, 35.90187836], [35.62797546, 35.52292252, 35.47383118, 35.33785629, 35.81896591, 35.88694 , 35.90187836], [35.62697601, 35.52192307, 35.47383118, 35.33785629, 35.81896591, 35.89193726, 35.90187836], [35.62797546, 35.52192307, 35.47383118, 35.33785629, 35.81996536, 35.88993835, 35.90187836], [35.62897873, 35.52292252, 35.47483063, 35.33785629, 35.81996536, 35.88993835, 35.90187836], [35.62997818, 35.51892471, 35.48183441, 35.33785629, 35.81996536, 35.88993835, 35.90187836], [35.63197708, 35.44991302, 35.47983551, 35.33785629, 35.81996536, 35.89683914, 35.90187836], [35.63097763, 35.38090134, 35.4948349 , 35.33785629, 35.81896591, 35.89583969, 35.90187836], [35.62697601, 35.58792114, 35.51083755, 35.33985519, 35.82497025, 35.89683914, 35.90187836], ... [34.91690445, 34.92385483, 34.91975403, 34.91980362, 34.92385483, 34.93680573, 34.93885422], [34.92190552, 34.92485428, 34.91975403, 34.92080688, 34.92485428, 34.94480515, 34.9328537 ], [34.92390442, 34.92285538, 34.92176056, 34.92280579, 34.92985535, 34.93280411, 34.92785645], [34.92390442, 34.92385483, 34.92375946, 34.92480469, 34.92685318, 34.93780899, 34.92485428], [34.92390442, 34.92285538, 34.92575836, 34.92181015, 34.92085648, 34.93680954, 34.92385483], [34.92590332, 34.9288559 , 34.92575836, 34.92181015, 34.92685318, 34.93481064, 34.92585373], [34.92490387, 34.92785645, 34.92475891, 34.92781067, 34.93385696, 34.93380737, 34.92385864], [34.92190552, 34.92385864, 34.93076324, 34.9268074 , 34.93585968, 34.93481064, 34.92985916], [34.92090607, 34.92185974, 34.92176437, 34.9228096 , 34.93285751, 34.93180847, 34.92786026], [ nan, 34.91985703, nan, 34.92181015, nan, 34.92181015, nan]]) Coordinates: * level (level) int64 0 1 2 3 4 5 6 7 8 9 ... 68 69 70 71 72 73 74 75 76 77 * date (date) datetime64[ns] 2012-10-02T03:00:17.971200 ... 2012-12-01T... lon (date) float64 -34.46 -33.78 -32.97 -32.55 -32.43 -32.29 -32.17 lat (date) float64 44.96 44.68 44.13 43.64 43.07 42.66 42.51
- level: 78
- date: 7
- 35.63 35.53 35.47 35.34 35.82 35.89 ... 34.92 nan 34.92 nan 34.92 nan
array([[35.63097763, 35.52592468, 35.47483063, 35.33785629, 35.81896591, 35.8889389 , 35.90187836], [35.63097763, 35.52292252, 35.47483063, 35.33685684, 35.81796646, 35.88793945, 35.90187836], [35.62797546, 35.52292252, 35.47383118, 35.33785629, 35.81896591, 35.88694 , 35.90187836], [35.62697601, 35.52192307, 35.47383118, 35.33785629, 35.81896591, 35.89193726, 35.90187836], [35.62797546, 35.52192307, 35.47383118, 35.33785629, 35.81996536, 35.88993835, 35.90187836], [35.62897873, 35.52292252, 35.47483063, 35.33785629, 35.81996536, 35.88993835, 35.90187836], [35.62997818, 35.51892471, 35.48183441, 35.33785629, 35.81996536, 35.88993835, 35.90187836], [35.63197708, 35.44991302, 35.47983551, 35.33785629, 35.81996536, 35.89683914, 35.90187836], [35.63097763, 35.38090134, 35.4948349 , 35.33785629, 35.81896591, 35.89583969, 35.90187836], [35.62697601, 35.58792114, 35.51083755, 35.33985519, 35.82497025, 35.89683914, 35.90187836], ... [34.91690445, 34.92385483, 34.91975403, 34.91980362, 34.92385483, 34.93680573, 34.93885422], [34.92190552, 34.92485428, 34.91975403, 34.92080688, 34.92485428, 34.94480515, 34.9328537 ], [34.92390442, 34.92285538, 34.92176056, 34.92280579, 34.92985535, 34.93280411, 34.92785645], [34.92390442, 34.92385483, 34.92375946, 34.92480469, 34.92685318, 34.93780899, 34.92485428], [34.92390442, 34.92285538, 34.92575836, 34.92181015, 34.92085648, 34.93680954, 34.92385483], [34.92590332, 34.9288559 , 34.92575836, 34.92181015, 34.92685318, 34.93481064, 34.92585373], [34.92490387, 34.92785645, 34.92475891, 34.92781067, 34.93385696, 34.93380737, 34.92385864], [34.92190552, 34.92385864, 34.93076324, 34.9268074 , 34.93585968, 34.93481064, 34.92985916], [34.92090607, 34.92185974, 34.92176437, 34.9228096 , 34.93285751, 34.93180847, 34.92786026], [ nan, 34.91985703, nan, 34.92181015, nan, 34.92181015, nan]])
- level(level)int640 1 2 3 4 5 6 ... 72 73 74 75 76 77
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77])
- date(date)datetime64[ns]2012-10-02T03:00:17.971200 ... 2...
array(['2012-10-02T03:00:17.971200000', '2012-10-11T23:13:27.984000000', '2012-10-22T02:50:32.006400000', '2012-10-31T23:36:39.974400000', '2012-11-11T02:40:46.041600000', '2012-11-20T23:08:29.990400000', '2012-12-01T02:47:51.993600000'], dtype='datetime64[ns]')
- lon(date)float64-34.46 -33.78 ... -32.29 -32.17
array([-34.462, -33.784, -32.972, -32.546, -32.428, -32.292, -32.169])
- lat(date)float6444.96 44.68 44.13 ... 42.66 42.51
array([44.956, 44.676, 44.13 , 43.644, 43.067, 42.662, 42.513])
argo.salinity.sel(date=slice('2012-10-01', '2012-12-01')).plot()
<matplotlib.collections.QuadMesh at 0x7f7974236e80>

.sel()
also works on the whole Dataset
argo.sel(date='2012-10-22')
<xarray.Dataset> Dimensions: (level: 78, date: 1) Coordinates: * level (level) int64 0 1 2 3 4 5 6 7 8 ... 69 70 71 72 73 74 75 76 77 * date (date) datetime64[ns] 2012-10-22T02:50:32.006400 lon (date) float64 -32.97 lat (date) float64 44.13 Data variables: salinity (level, date) float64 35.47 35.47 35.47 ... 34.93 34.92 nan temperature (level, date) float64 17.13 17.13 17.13 ... 3.736 3.639 nan pressure (level, date) float64 6.4 10.3 15.4 ... 1.9e+03 1.951e+03 nan
- level: 78
- date: 1
- level(level)int640 1 2 3 4 5 6 ... 72 73 74 75 76 77
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77])
- date(date)datetime64[ns]2012-10-22T02:50:32.006400
array(['2012-10-22T02:50:32.006400000'], dtype='datetime64[ns]')
- lon(date)float64-32.97
array([-32.972])
- lat(date)float6444.13
array([44.13])
- salinity(level, date)float6435.47 35.47 35.47 ... 34.92 nan
array([[35.47483063], [35.47483063], [35.47383118], [35.47383118], [35.47383118], [35.47483063], [35.48183441], [35.47983551], [35.4948349 ], [35.51083755], [36.13380051], [36.09579849], [35.95479965], [35.93979645], [35.8958931 ], [35.86388397], [35.87788773], [35.88188934], [35.90379333], [35.9067955 ], ... [35.00975037], [34.96175385], [34.96775055], [34.95075226], [34.93775177], [34.93375015], [34.93775558], [34.9247551 ], [34.92175674], [34.91975403], [34.91975403], [34.91975403], [34.92176056], [34.92375946], [34.92575836], [34.92575836], [34.92475891], [34.93076324], [34.92176437], [ nan]])
- temperature(level, date)float6417.13 17.13 17.13 ... 3.639 nan
array([[17.13299942], [17.13199997], [17.13299942], [17.13400078], [17.13500023], [17.13500023], [17.13199997], [17.13400078], [17.11300087], [17.09700012], [16.67099953], [16.40099907], [15.76000023], [15.58600044], [15.35299969], [15.18299961], [15.15299988], [15.05799961], [15.04399967], [14.99300003], ... [ 5.04799986], [ 4.69399977], [ 4.61399984], [ 4.42500019], [ 4.30600023], [ 4.23099995], [ 4.19500017], [ 4.07600021], [ 4.0170002 ], [ 3.95000005], [ 3.92499995], [ 3.87899995], [ 3.86800003], [ 3.84500003], [ 3.8210001 ], [ 3.77800012], [ 3.73799992], [ 3.73600006], [ 3.63899994], [ nan]])
- pressure(level, date)float646.4 10.3 15.4 ... 1.951e+03 nan
array([[ 6.4000001 ], [ 10.30000019], [ 15.39999962], [ 21. ], [ 26. ], [ 30.20000076], [ 35.40000153], [ 40.79999924], [ 44.79999924], [ 51.29999924], [ 60.20000076], [ 71. ], [ 80.59999847], [ 91. ], [ 100.80000305], [ 110.90000153], [ 121.09999847], [ 130.8999939 ], [ 140.69999695], [ 150.80000305], ... [1050. ], [1100.59997559], [1150.5 ], [1200.40002441], [1250.69995117], [1300.40002441], [1350.40002441], [1400.90002441], [1447.90002441], [1500.80004883], [1550.40002441], [1600.90002441], [1650.09997559], [1700.40002441], [1750.5 ], [1800.80004883], [1850.69995117], [1900.5 ], [1950.80004883], [ nan]])
Computation¶
Xarray dataarrays and datasets work seamlessly with arithmetic operators and numpy array functions.
temp_kelvin = argo.temperature + 273.15
temp_kelvin.plot(yincrease=False)
<matplotlib.collections.QuadMesh at 0x7f7974170d00>

We can also combine multiple xarray datasets in arithemtic operations
g = 9.8
buoyancy = g * (2e-4 * argo.temperature - 7e-4 * argo.salinity)
buoyancy.plot(yincrease=False)
<matplotlib.collections.QuadMesh at 0x7f7974068a00>

Broadcasting, Aligment, and Combining Data¶
Broadcasting¶
Broadcasting arrays in numpy is a nightmare. It is much easier when the data axes are labeled!
This is a useless calculation, but it illustrates how perfoming an operation on arrays with differenty coordinates will result in automatic broadcasting
level_times_lat = argo.level * argo.lat
level_times_lat
<xarray.DataArray (level: 78, date: 75)> array([[ 0. , 0. , 0. , ..., 0. , 0. , 0. ], [ 47.187, 46.716, 46.45 , ..., 42.601, 42.457, 42.379], [ 94.374, 93.432, 92.9 , ..., 85.202, 84.914, 84.758], ..., [3539.025, 3503.7 , 3483.75 , ..., 3195.075, 3184.275, 3178.425], [3586.212, 3550.416, 3530.2 , ..., 3237.676, 3226.732, 3220.804], [3633.399, 3597.132, 3576.65 , ..., 3280.277, 3269.189, 3263.183]]) Coordinates: * level (level) int64 0 1 2 3 4 5 6 7 8 9 ... 68 69 70 71 72 73 74 75 76 77 * date (date) datetime64[ns] 2012-07-13T22:33:06.019200 ... 2014-07-24T... lon (date) float64 -39.13 -37.28 -36.9 -36.89 ... -33.83 -34.11 -34.38 lat (date) float64 47.19 46.72 46.45 46.23 ... 42.72 42.6 42.46 42.38
- level: 78
- date: 75
- 0.0 0.0 0.0 0.0 0.0 ... 3.29e+03 3.28e+03 3.269e+03 3.263e+03
array([[ 0. , 0. , 0. , ..., 0. , 0. , 0. ], [ 47.187, 46.716, 46.45 , ..., 42.601, 42.457, 42.379], [ 94.374, 93.432, 92.9 , ..., 85.202, 84.914, 84.758], ..., [3539.025, 3503.7 , 3483.75 , ..., 3195.075, 3184.275, 3178.425], [3586.212, 3550.416, 3530.2 , ..., 3237.676, 3226.732, 3220.804], [3633.399, 3597.132, 3576.65 , ..., 3280.277, 3269.189, 3263.183]])
- level(level)int640 1 2 3 4 5 6 ... 72 73 74 75 76 77
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77])
- date(date)datetime64[ns]2012-07-13T22:33:06.019200 ... 2...
array(['2012-07-13T22:33:06.019200000', '2012-07-23T22:54:59.990400000', '2012-08-02T22:55:52.003200000', '2012-08-12T23:08:59.971200000', '2012-08-22T23:29:01.968000000', '2012-09-01T23:17:38.976000000', '2012-09-12T02:59:18.960000000', '2012-09-21T23:18:37.036800000', '2012-10-02T03:00:17.971200000', '2012-10-11T23:13:27.984000000', '2012-10-22T02:50:32.006400000', '2012-10-31T23:36:39.974400000', '2012-11-11T02:40:46.041600000', '2012-11-20T23:08:29.990400000', '2012-12-01T02:47:51.993600000', '2012-12-10T23:23:16.972800000', '2012-12-21T02:58:48.979200000', '2012-12-30T23:07:23.030400000', '2013-01-10T02:56:43.008000000', '2013-01-19T23:24:26.956800000', '2013-01-30T02:43:53.011200000', '2013-02-08T23:15:27.043200000', '2013-02-19T01:12:50.976000000', '2013-02-28T23:07:13.008000000', '2013-03-11T02:43:30.979200000', '2013-03-20T23:17:22.992000000', '2013-03-31T01:50:38.025600000', '2013-04-09T23:19:07.968000000', '2013-04-20T02:53:29.990400000', '2013-04-29T23:28:33.024000000', '2013-05-10T02:50:18.009600000', '2013-05-19T23:21:05.990400000', '2013-05-30T02:50:30.969600000', '2013-06-08T23:32:49.027200000', '2013-06-19T03:42:51.004800000', '2013-06-28T23:32:16.022400000', '2013-07-09T03:28:30.979199999', '2013-07-18T23:33:57.974400000', '2013-07-29T03:15:42.019200000', '2013-08-07T23:25:02.035200000', '2013-08-18T01:47:44.966400000', '2013-08-28T03:02:59.020800000', '2013-09-07T03:03:51.984000000', '2013-09-16T23:32:07.987200000', '2013-09-27T04:08:27.974400000', '2013-10-06T23:25:39.964800000', '2013-10-17T02:55:50.995200000', '2013-10-27T03:45:47.001600000', '2013-11-06T01:14:52.022400000', '2013-11-16T03:29:54.009600000', '2013-11-26T03:03:56.995200000', '2013-12-05T23:33:59.011200000', '2013-12-16T02:58:01.977600000', '2013-12-25T23:22:43.017600000', '2014-01-05T02:52:06.009600000', '2014-01-14T23:41:18.009600000', '2014-01-25T03:00:43.977600000', '2014-02-03T23:29:13.977600000', '2014-02-14T02:50:11.961600000', '2014-02-23T23:03:21.974400000', '2014-03-06T02:58:03.964800000', '2014-03-15T23:10:28.012800000', '2014-03-26T02:51:22.032000000', '2014-04-04T23:25:58.972800000', '2014-04-15T03:00:45.964800000', '2014-04-24T23:24:40.003200000', '2014-05-05T02:56:22.012800000', '2014-05-15T00:10:06.009600000', '2014-05-25T03:02:43.036800000', '2014-06-03T23:34:53.961600000', '2014-06-14T03:01:23.980800000', '2014-06-23T23:24:31.968000000', '2014-07-04T03:08:30.019200000', '2014-07-13T23:47:43.008000000', '2014-07-24T03:02:33.014400000'], dtype='datetime64[ns]')
- lon(date)float64-39.13 -37.28 ... -34.11 -34.38
array([-39.13 , -37.282, -36.9 , -36.89 , -37.053, -36.658, -35.963, -35.184, -34.462, -33.784, -32.972, -32.546, -32.428, -32.292, -32.169, -31.998, -31.824, -31.624, -31.433, -31.312, -31.107, -31.147, -31.044, -31.14 , -31.417, -31.882, -32.145, -32.487, -32.537, -32.334, -32.042, -31.892, -31.861, -31.991, -31.883, -31.89 , -31.941, -31.889, -31.724, -31.412, -31.786, -31.561, -31.732, -31.553, -31.862, -32.389, -32.318, -32.19 , -32.224, -32.368, -32.306, -32.305, -32.65 , -33.093, -33.263, -33.199, -33.27 , -33.237, -33.221, -33.011, -32.844, -32.981, -32.784, -32.607, -32.87 , -33.196, -33.524, -33.956, -33.944, -33.71 , -33.621, -33.552, -33.828, -34.11 , -34.38 ])
- lat(date)float6447.19 46.72 46.45 ... 42.46 42.38
array([47.187, 46.716, 46.45 , 46.23 , 45.459, 44.833, 44.452, 44.839, 44.956, 44.676, 44.13 , 43.644, 43.067, 42.662, 42.513, 42.454, 42.396, 42.256, 42.089, 41.944, 41.712, 41.571, 41.596, 41.581, 41.351, 41.032, 40.912, 40.792, 40.495, 40.383, 40.478, 40.672, 41.032, 40.864, 40.651, 40.425, 40.228, 40.197, 40.483, 40.311, 40.457, 40.463, 40.164, 40.047, 39.963, 40.122, 40.57 , 40.476, 40.527, 40.589, 40.749, 40.993, 41.162, 41.237, 41.448, 41.65 , 42.053, 42.311, 42.096, 41.683, 41.661, 41.676, 42.018, 42.395, 42.532, 42.558, 42.504, 42.63 , 42.934, 42.952, 42.777, 42.722, 42.601, 42.457, 42.379])
level_times_lat.plot()
<matplotlib.collections.QuadMesh at 0x7f7973fffd90>

Alignment¶
If you try to perform operations on DataArrays that share a dimension name, Xarray will try to align them first. This works nearly identically to Pandas, except that there can be multiple dimensions to align over.
To see how alignment works, we will create some subsets of our original data.
sa_surf = argo.salinity.isel(level=slice(0, 20))
sa_mid = argo.salinity.isel(level=slice(10, 30))
By default, when we combine multiple arrays in mathematical operations, Xarray performs an “inner join”.
(sa_surf * sa_mid).level
<xarray.DataArray 'level' (level: 10)> array([10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) Coordinates: * level (level) int64 10 11 12 13 14 15 16 17 18 19
- level: 10
- 10 11 12 13 14 15 16 17 18 19
array([10, 11, 12, 13, 14, 15, 16, 17, 18, 19])
- level(level)int6410 11 12 13 14 15 16 17 18 19
array([10, 11, 12, 13, 14, 15, 16, 17, 18, 19])
We can override this behavior by manually aligning the data
sa_surf_outer, sa_mid_outer = xr.align(sa_surf, sa_mid, join='outer')
sa_surf_outer.level
<xarray.DataArray 'level' (level: 30)> array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]) Coordinates: * level (level) int64 0 1 2 3 4 5 6 7 8 9 ... 20 21 22 23 24 25 26 27 28 29
- level: 30
- 0 1 2 3 4 5 6 7 8 9 10 11 12 ... 18 19 20 21 22 23 24 25 26 27 28 29
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29])
- level(level)int640 1 2 3 4 5 6 ... 24 25 26 27 28 29
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29])
As we can see, missing data (NaNs) have been filled in where the array was extended.
sa_surf_outer.plot(yincrease=False)
<matplotlib.collections.QuadMesh at 0x7f7973ed1d30>

We can also use join='right'
and join='left'
.
Combing Data: Concat and Merge¶
The ability to combine many smaller arrays into a single big Dataset is one of the main advantages of Xarray. To take advantage of this, we need to learn two operations that help us combine data:
xr.contact
: to concatenate multiple arrays into one bigger array along their dimensionsxr.merge
: to combine multiple different arrays into a dataset
First let’s look at concat. Let’s re-combine the subsetted data from the previous step.
sa_surf_mid = xr.concat([sa_surf, sa_mid], dim='level')
sa_surf_mid
<xarray.DataArray 'salinity' (level: 40, date: 75)> array([[35.6389389 , 35.51495743, 35.57297134, ..., 35.82093811, 35.77793884, 35.66891098], [35.63393784, 35.5219574 , 35.57397079, ..., 35.81093216, 35.58389664, 35.66791153], [35.6819458 , 35.52595901, 35.57297134, ..., 35.79592896, 35.66290665, 35.66591263], ..., [35.78895187, 35.7829895 , 35.85100555, ..., 35.84291458, 35.81891251, 35.7779007 ], [35.76794815, 35.75598526, 35.84500504, ..., 35.84891891, 35.83391571, 35.76390076], [35.75194168, 35.71097565, 35.83100128, ..., 35.80690765, 35.85292053, 35.75489807]]) Coordinates: * level (level) int64 0 1 2 3 4 5 6 7 8 9 ... 20 21 22 23 24 25 26 27 28 29 * date (date) datetime64[ns] 2012-07-13T22:33:06.019200 ... 2014-07-24T... lon (date) float64 -39.13 -37.28 -36.9 -36.89 ... -33.83 -34.11 -34.38 lat (date) float64 47.19 46.72 46.45 46.23 ... 42.72 42.6 42.46 42.38
- level: 40
- date: 75
- 35.64 35.51 35.57 35.4 35.45 35.5 ... 35.64 35.82 35.81 35.85 35.75
array([[35.6389389 , 35.51495743, 35.57297134, ..., 35.82093811, 35.77793884, 35.66891098], [35.63393784, 35.5219574 , 35.57397079, ..., 35.81093216, 35.58389664, 35.66791153], [35.6819458 , 35.52595901, 35.57297134, ..., 35.79592896, 35.66290665, 35.66591263], ..., [35.78895187, 35.7829895 , 35.85100555, ..., 35.84291458, 35.81891251, 35.7779007 ], [35.76794815, 35.75598526, 35.84500504, ..., 35.84891891, 35.83391571, 35.76390076], [35.75194168, 35.71097565, 35.83100128, ..., 35.80690765, 35.85292053, 35.75489807]])
- level(level)int640 1 2 3 4 5 6 ... 24 25 26 27 28 29
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29])
- date(date)datetime64[ns]2012-07-13T22:33:06.019200 ... 2...
array(['2012-07-13T22:33:06.019200000', '2012-07-23T22:54:59.990400000', '2012-08-02T22:55:52.003200000', '2012-08-12T23:08:59.971200000', '2012-08-22T23:29:01.968000000', '2012-09-01T23:17:38.976000000', '2012-09-12T02:59:18.960000000', '2012-09-21T23:18:37.036800000', '2012-10-02T03:00:17.971200000', '2012-10-11T23:13:27.984000000', '2012-10-22T02:50:32.006400000', '2012-10-31T23:36:39.974400000', '2012-11-11T02:40:46.041600000', '2012-11-20T23:08:29.990400000', '2012-12-01T02:47:51.993600000', '2012-12-10T23:23:16.972800000', '2012-12-21T02:58:48.979200000', '2012-12-30T23:07:23.030400000', '2013-01-10T02:56:43.008000000', '2013-01-19T23:24:26.956800000', '2013-01-30T02:43:53.011200000', '2013-02-08T23:15:27.043200000', '2013-02-19T01:12:50.976000000', '2013-02-28T23:07:13.008000000', '2013-03-11T02:43:30.979200000', '2013-03-20T23:17:22.992000000', '2013-03-31T01:50:38.025600000', '2013-04-09T23:19:07.968000000', '2013-04-20T02:53:29.990400000', '2013-04-29T23:28:33.024000000', '2013-05-10T02:50:18.009600000', '2013-05-19T23:21:05.990400000', '2013-05-30T02:50:30.969600000', '2013-06-08T23:32:49.027200000', '2013-06-19T03:42:51.004800000', '2013-06-28T23:32:16.022400000', '2013-07-09T03:28:30.979199999', '2013-07-18T23:33:57.974400000', '2013-07-29T03:15:42.019200000', '2013-08-07T23:25:02.035200000', '2013-08-18T01:47:44.966400000', '2013-08-28T03:02:59.020800000', '2013-09-07T03:03:51.984000000', '2013-09-16T23:32:07.987200000', '2013-09-27T04:08:27.974400000', '2013-10-06T23:25:39.964800000', '2013-10-17T02:55:50.995200000', '2013-10-27T03:45:47.001600000', '2013-11-06T01:14:52.022400000', '2013-11-16T03:29:54.009600000', '2013-11-26T03:03:56.995200000', '2013-12-05T23:33:59.011200000', '2013-12-16T02:58:01.977600000', '2013-12-25T23:22:43.017600000', '2014-01-05T02:52:06.009600000', '2014-01-14T23:41:18.009600000', '2014-01-25T03:00:43.977600000', '2014-02-03T23:29:13.977600000', '2014-02-14T02:50:11.961600000', '2014-02-23T23:03:21.974400000', '2014-03-06T02:58:03.964800000', '2014-03-15T23:10:28.012800000', '2014-03-26T02:51:22.032000000', '2014-04-04T23:25:58.972800000', '2014-04-15T03:00:45.964800000', '2014-04-24T23:24:40.003200000', '2014-05-05T02:56:22.012800000', '2014-05-15T00:10:06.009600000', '2014-05-25T03:02:43.036800000', '2014-06-03T23:34:53.961600000', '2014-06-14T03:01:23.980800000', '2014-06-23T23:24:31.968000000', '2014-07-04T03:08:30.019200000', '2014-07-13T23:47:43.008000000', '2014-07-24T03:02:33.014400000'], dtype='datetime64[ns]')
- lon(date)float64-39.13 -37.28 ... -34.11 -34.38
array([-39.13 , -37.282, -36.9 , -36.89 , -37.053, -36.658, -35.963, -35.184, -34.462, -33.784, -32.972, -32.546, -32.428, -32.292, -32.169, -31.998, -31.824, -31.624, -31.433, -31.312, -31.107, -31.147, -31.044, -31.14 , -31.417, -31.882, -32.145, -32.487, -32.537, -32.334, -32.042, -31.892, -31.861, -31.991, -31.883, -31.89 , -31.941, -31.889, -31.724, -31.412, -31.786, -31.561, -31.732, -31.553, -31.862, -32.389, -32.318, -32.19 , -32.224, -32.368, -32.306, -32.305, -32.65 , -33.093, -33.263, -33.199, -33.27 , -33.237, -33.221, -33.011, -32.844, -32.981, -32.784, -32.607, -32.87 , -33.196, -33.524, -33.956, -33.944, -33.71 , -33.621, -33.552, -33.828, -34.11 , -34.38 ])
- lat(date)float6447.19 46.72 46.45 ... 42.46 42.38
array([47.187, 46.716, 46.45 , 46.23 , 45.459, 44.833, 44.452, 44.839, 44.956, 44.676, 44.13 , 43.644, 43.067, 42.662, 42.513, 42.454, 42.396, 42.256, 42.089, 41.944, 41.712, 41.571, 41.596, 41.581, 41.351, 41.032, 40.912, 40.792, 40.495, 40.383, 40.478, 40.672, 41.032, 40.864, 40.651, 40.425, 40.228, 40.197, 40.483, 40.311, 40.457, 40.463, 40.164, 40.047, 39.963, 40.122, 40.57 , 40.476, 40.527, 40.589, 40.749, 40.993, 41.162, 41.237, 41.448, 41.65 , 42.053, 42.311, 42.096, 41.683, 41.661, 41.676, 42.018, 42.395, 42.532, 42.558, 42.504, 42.63 , 42.934, 42.952, 42.777, 42.722, 42.601, 42.457, 42.379])
Warning
Xarray won’t check the values of the coordinates before concat
. It will just stick everything together into a new array.
In this case, we had overlapping data. We can see this by looking at the level
coordinate.
sa_surf_mid.level
<xarray.DataArray 'level' (level: 40)> array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]) Coordinates: * level (level) int64 0 1 2 3 4 5 6 7 8 9 ... 20 21 22 23 24 25 26 27 28 29
- level: 40
- 0 1 2 3 4 5 6 7 8 9 10 11 12 ... 18 19 20 21 22 23 24 25 26 27 28 29
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29])
- level(level)int640 1 2 3 4 5 6 ... 24 25 26 27 28 29
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29])
plt.plot(sa_surf_mid.level.values, marker='o')
[<matplotlib.lines.Line2D at 0x7f7974154fa0>]

We can also concat data along a new dimension, e.g.
sa_concat_new = xr.concat([sa_surf, sa_mid], dim='newdim')
sa_concat_new
<xarray.DataArray 'salinity' (newdim: 2, level: 30, date: 75)> array([[[35.6389389 , 35.51495743, 35.57297134, ..., 35.82093811, 35.77793884, 35.66891098], [35.63393784, 35.5219574 , 35.57397079, ..., 35.81093216, 35.58389664, 35.66791153], [35.6819458 , 35.52595901, 35.57297134, ..., 35.79592896, 35.66290665, 35.66591263], ..., [ nan, nan, nan, ..., nan, nan, nan], [ nan, nan, nan, ..., nan, nan, nan], [ nan, nan, nan, ..., nan, nan, nan]], [[ nan, nan, nan, ..., nan, nan, nan], [ nan, nan, nan, ..., nan, nan, nan], [ nan, nan, nan, ..., nan, nan, nan], ..., [35.78895187, 35.7829895 , 35.85100555, ..., 35.84291458, 35.81891251, 35.7779007 ], [35.76794815, 35.75598526, 35.84500504, ..., 35.84891891, 35.83391571, 35.76390076], [35.75194168, 35.71097565, 35.83100128, ..., 35.80690765, 35.85292053, 35.75489807]]]) Coordinates: * level (level) int64 0 1 2 3 4 5 6 7 8 9 ... 20 21 22 23 24 25 26 27 28 29 * date (date) datetime64[ns] 2012-07-13T22:33:06.019200 ... 2014-07-24T... lon (date) float64 -39.13 -37.28 -36.9 -36.89 ... -33.83 -34.11 -34.38 lat (date) float64 47.19 46.72 46.45 46.23 ... 42.72 42.6 42.46 42.38 Dimensions without coordinates: newdim
- newdim: 2
- level: 30
- date: 75
- 35.64 35.51 35.57 35.4 35.45 35.5 ... 35.64 35.82 35.81 35.85 35.75
array([[[35.6389389 , 35.51495743, 35.57297134, ..., 35.82093811, 35.77793884, 35.66891098], [35.63393784, 35.5219574 , 35.57397079, ..., 35.81093216, 35.58389664, 35.66791153], [35.6819458 , 35.52595901, 35.57297134, ..., 35.79592896, 35.66290665, 35.66591263], ..., [ nan, nan, nan, ..., nan, nan, nan], [ nan, nan, nan, ..., nan, nan, nan], [ nan, nan, nan, ..., nan, nan, nan]], [[ nan, nan, nan, ..., nan, nan, nan], [ nan, nan, nan, ..., nan, nan, nan], [ nan, nan, nan, ..., nan, nan, nan], ..., [35.78895187, 35.7829895 , 35.85100555, ..., 35.84291458, 35.81891251, 35.7779007 ], [35.76794815, 35.75598526, 35.84500504, ..., 35.84891891, 35.83391571, 35.76390076], [35.75194168, 35.71097565, 35.83100128, ..., 35.80690765, 35.85292053, 35.75489807]]])
- level(level)int640 1 2 3 4 5 6 ... 24 25 26 27 28 29
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29])
- date(date)datetime64[ns]2012-07-13T22:33:06.019200 ... 2...
array(['2012-07-13T22:33:06.019200000', '2012-07-23T22:54:59.990400000', '2012-08-02T22:55:52.003200000', '2012-08-12T23:08:59.971200000', '2012-08-22T23:29:01.968000000', '2012-09-01T23:17:38.976000000', '2012-09-12T02:59:18.960000000', '2012-09-21T23:18:37.036800000', '2012-10-02T03:00:17.971200000', '2012-10-11T23:13:27.984000000', '2012-10-22T02:50:32.006400000', '2012-10-31T23:36:39.974400000', '2012-11-11T02:40:46.041600000', '2012-11-20T23:08:29.990400000', '2012-12-01T02:47:51.993600000', '2012-12-10T23:23:16.972800000', '2012-12-21T02:58:48.979200000', '2012-12-30T23:07:23.030400000', '2013-01-10T02:56:43.008000000', '2013-01-19T23:24:26.956800000', '2013-01-30T02:43:53.011200000', '2013-02-08T23:15:27.043200000', '2013-02-19T01:12:50.976000000', '2013-02-28T23:07:13.008000000', '2013-03-11T02:43:30.979200000', '2013-03-20T23:17:22.992000000', '2013-03-31T01:50:38.025600000', '2013-04-09T23:19:07.968000000', '2013-04-20T02:53:29.990400000', '2013-04-29T23:28:33.024000000', '2013-05-10T02:50:18.009600000', '2013-05-19T23:21:05.990400000', '2013-05-30T02:50:30.969600000', '2013-06-08T23:32:49.027200000', '2013-06-19T03:42:51.004800000', '2013-06-28T23:32:16.022400000', '2013-07-09T03:28:30.979199999', '2013-07-18T23:33:57.974400000', '2013-07-29T03:15:42.019200000', '2013-08-07T23:25:02.035200000', '2013-08-18T01:47:44.966400000', '2013-08-28T03:02:59.020800000', '2013-09-07T03:03:51.984000000', '2013-09-16T23:32:07.987200000', '2013-09-27T04:08:27.974400000', '2013-10-06T23:25:39.964800000', '2013-10-17T02:55:50.995200000', '2013-10-27T03:45:47.001600000', '2013-11-06T01:14:52.022400000', '2013-11-16T03:29:54.009600000', '2013-11-26T03:03:56.995200000', '2013-12-05T23:33:59.011200000', '2013-12-16T02:58:01.977600000', '2013-12-25T23:22:43.017600000', '2014-01-05T02:52:06.009600000', '2014-01-14T23:41:18.009600000', '2014-01-25T03:00:43.977600000', '2014-02-03T23:29:13.977600000', '2014-02-14T02:50:11.961600000', '2014-02-23T23:03:21.974400000', '2014-03-06T02:58:03.964800000', '2014-03-15T23:10:28.012800000', '2014-03-26T02:51:22.032000000', '2014-04-04T23:25:58.972800000', '2014-04-15T03:00:45.964800000', '2014-04-24T23:24:40.003200000', '2014-05-05T02:56:22.012800000', '2014-05-15T00:10:06.009600000', '2014-05-25T03:02:43.036800000', '2014-06-03T23:34:53.961600000', '2014-06-14T03:01:23.980800000', '2014-06-23T23:24:31.968000000', '2014-07-04T03:08:30.019200000', '2014-07-13T23:47:43.008000000', '2014-07-24T03:02:33.014400000'], dtype='datetime64[ns]')
- lon(date)float64-39.13 -37.28 ... -34.11 -34.38
array([-39.13 , -37.282, -36.9 , -36.89 , -37.053, -36.658, -35.963, -35.184, -34.462, -33.784, -32.972, -32.546, -32.428, -32.292, -32.169, -31.998, -31.824, -31.624, -31.433, -31.312, -31.107, -31.147, -31.044, -31.14 , -31.417, -31.882, -32.145, -32.487, -32.537, -32.334, -32.042, -31.892, -31.861, -31.991, -31.883, -31.89 , -31.941, -31.889, -31.724, -31.412, -31.786, -31.561, -31.732, -31.553, -31.862, -32.389, -32.318, -32.19 , -32.224, -32.368, -32.306, -32.305, -32.65 , -33.093, -33.263, -33.199, -33.27 , -33.237, -33.221, -33.011, -32.844, -32.981, -32.784, -32.607, -32.87 , -33.196, -33.524, -33.956, -33.944, -33.71 , -33.621, -33.552, -33.828, -34.11 , -34.38 ])
- lat(date)float6447.19 46.72 46.45 ... 42.46 42.38
array([47.187, 46.716, 46.45 , 46.23 , 45.459, 44.833, 44.452, 44.839, 44.956, 44.676, 44.13 , 43.644, 43.067, 42.662, 42.513, 42.454, 42.396, 42.256, 42.089, 41.944, 41.712, 41.571, 41.596, 41.581, 41.351, 41.032, 40.912, 40.792, 40.495, 40.383, 40.478, 40.672, 41.032, 40.864, 40.651, 40.425, 40.228, 40.197, 40.483, 40.311, 40.457, 40.463, 40.164, 40.047, 39.963, 40.122, 40.57 , 40.476, 40.527, 40.589, 40.749, 40.993, 41.162, 41.237, 41.448, 41.65 , 42.053, 42.311, 42.096, 41.683, 41.661, 41.676, 42.018, 42.395, 42.532, 42.558, 42.504, 42.63 , 42.934, 42.952, 42.777, 42.722, 42.601, 42.457, 42.379])
Note that the data were aligned using an outer join along the non-concat dimensions.
Instead of specifying a new dimension name, we can pass a new Pandas index object explicitly to concat
.
This will create a new dimension coordinate and corresponding index.
We can merge both DataArrays and Datasets.
xr.merge([argo.salinity, argo.temperature])
<xarray.Dataset> Dimensions: (level: 78, date: 75) Coordinates: * level (level) int64 0 1 2 3 4 5 6 7 8 ... 69 70 71 72 73 74 75 76 77 * date (date) datetime64[ns] 2012-07-13T22:33:06.019200 ... 2014-07... lon (date) float64 -39.13 -37.28 -36.9 ... -33.83 -34.11 -34.38 lat (date) float64 47.19 46.72 46.45 46.23 ... 42.6 42.46 42.38 Data variables: salinity (level, date) float64 35.64 35.51 35.57 35.4 ... nan 34.94 nan temperature (level, date) float64 18.97 18.44 19.1 19.79 ... nan 3.714 nan
- level: 78
- date: 75
- level(level)int640 1 2 3 4 5 6 ... 72 73 74 75 76 77
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77])
- date(date)datetime64[ns]2012-07-13T22:33:06.019200 ... 2...
array(['2012-07-13T22:33:06.019200000', '2012-07-23T22:54:59.990400000', '2012-08-02T22:55:52.003200000', '2012-08-12T23:08:59.971200000', '2012-08-22T23:29:01.968000000', '2012-09-01T23:17:38.976000000', '2012-09-12T02:59:18.960000000', '2012-09-21T23:18:37.036800000', '2012-10-02T03:00:17.971200000', '2012-10-11T23:13:27.984000000', '2012-10-22T02:50:32.006400000', '2012-10-31T23:36:39.974400000', '2012-11-11T02:40:46.041600000', '2012-11-20T23:08:29.990400000', '2012-12-01T02:47:51.993600000', '2012-12-10T23:23:16.972800000', '2012-12-21T02:58:48.979200000', '2012-12-30T23:07:23.030400000', '2013-01-10T02:56:43.008000000', '2013-01-19T23:24:26.956800000', '2013-01-30T02:43:53.011200000', '2013-02-08T23:15:27.043200000', '2013-02-19T01:12:50.976000000', '2013-02-28T23:07:13.008000000', '2013-03-11T02:43:30.979200000', '2013-03-20T23:17:22.992000000', '2013-03-31T01:50:38.025600000', '2013-04-09T23:19:07.968000000', '2013-04-20T02:53:29.990400000', '2013-04-29T23:28:33.024000000', '2013-05-10T02:50:18.009600000', '2013-05-19T23:21:05.990400000', '2013-05-30T02:50:30.969600000', '2013-06-08T23:32:49.027200000', '2013-06-19T03:42:51.004800000', '2013-06-28T23:32:16.022400000', '2013-07-09T03:28:30.979199999', '2013-07-18T23:33:57.974400000', '2013-07-29T03:15:42.019200000', '2013-08-07T23:25:02.035200000', '2013-08-18T01:47:44.966400000', '2013-08-28T03:02:59.020800000', '2013-09-07T03:03:51.984000000', '2013-09-16T23:32:07.987200000', '2013-09-27T04:08:27.974400000', '2013-10-06T23:25:39.964800000', '2013-10-17T02:55:50.995200000', '2013-10-27T03:45:47.001600000', '2013-11-06T01:14:52.022400000', '2013-11-16T03:29:54.009600000', '2013-11-26T03:03:56.995200000', '2013-12-05T23:33:59.011200000', '2013-12-16T02:58:01.977600000', '2013-12-25T23:22:43.017600000', '2014-01-05T02:52:06.009600000', '2014-01-14T23:41:18.009600000', '2014-01-25T03:00:43.977600000', '2014-02-03T23:29:13.977600000', '2014-02-14T02:50:11.961600000', '2014-02-23T23:03:21.974400000', '2014-03-06T02:58:03.964800000', '2014-03-15T23:10:28.012800000', '2014-03-26T02:51:22.032000000', '2014-04-04T23:25:58.972800000', '2014-04-15T03:00:45.964800000', '2014-04-24T23:24:40.003200000', '2014-05-05T02:56:22.012800000', '2014-05-15T00:10:06.009600000', '2014-05-25T03:02:43.036800000', '2014-06-03T23:34:53.961600000', '2014-06-14T03:01:23.980800000', '2014-06-23T23:24:31.968000000', '2014-07-04T03:08:30.019200000', '2014-07-13T23:47:43.008000000', '2014-07-24T03:02:33.014400000'], dtype='datetime64[ns]')
- lon(date)float64-39.13 -37.28 ... -34.11 -34.38
array([-39.13 , -37.282, -36.9 , -36.89 , -37.053, -36.658, -35.963, -35.184, -34.462, -33.784, -32.972, -32.546, -32.428, -32.292, -32.169, -31.998, -31.824, -31.624, -31.433, -31.312, -31.107, -31.147, -31.044, -31.14 , -31.417, -31.882, -32.145, -32.487, -32.537, -32.334, -32.042, -31.892, -31.861, -31.991, -31.883, -31.89 , -31.941, -31.889, -31.724, -31.412, -31.786, -31.561, -31.732, -31.553, -31.862, -32.389, -32.318, -32.19 , -32.224, -32.368, -32.306, -32.305, -32.65 , -33.093, -33.263, -33.199, -33.27 , -33.237, -33.221, -33.011, -32.844, -32.981, -32.784, -32.607, -32.87 , -33.196, -33.524, -33.956, -33.944, -33.71 , -33.621, -33.552, -33.828, -34.11 , -34.38 ])
- lat(date)float6447.19 46.72 46.45 ... 42.46 42.38
array([47.187, 46.716, 46.45 , 46.23 , 45.459, 44.833, 44.452, 44.839, 44.956, 44.676, 44.13 , 43.644, 43.067, 42.662, 42.513, 42.454, 42.396, 42.256, 42.089, 41.944, 41.712, 41.571, 41.596, 41.581, 41.351, 41.032, 40.912, 40.792, 40.495, 40.383, 40.478, 40.672, 41.032, 40.864, 40.651, 40.425, 40.228, 40.197, 40.483, 40.311, 40.457, 40.463, 40.164, 40.047, 39.963, 40.122, 40.57 , 40.476, 40.527, 40.589, 40.749, 40.993, 41.162, 41.237, 41.448, 41.65 , 42.053, 42.311, 42.096, 41.683, 41.661, 41.676, 42.018, 42.395, 42.532, 42.558, 42.504, 42.63 , 42.934, 42.952, 42.777, 42.722, 42.601, 42.457, 42.379])
- salinity(level, date)float6435.64 35.51 35.57 ... nan 34.94 nan
array([[35.6389389 , 35.51495743, 35.57297134, ..., 35.82093811, 35.77793884, 35.66891098], [35.63393784, 35.5219574 , 35.57397079, ..., 35.81093216, 35.58389664, 35.66791153], [35.6819458 , 35.52595901, 35.57297134, ..., 35.79592896, 35.66290665, 35.66591263], ..., [34.91585922, 34.92390442, 34.92390442, ..., 34.93481064, 34.94081116, 34.94680786], [34.91585922, 34.92390442, 34.92190552, ..., 34.93280792, 34.93680954, 34.94380951], [34.91785812, 34.92390442, 34.92390442, ..., nan, 34.93680954, nan]])
- temperature(level, date)float6418.97 18.44 19.1 ... nan 3.714 nan
array([[18.97400093, 18.43700027, 19.09900093, ..., 19.11300087, 21.82299995, 20.13100052], [18.74099922, 18.39999962, 19.08200073, ..., 18.47200012, 19.45999908, 20.125 ], [18.37000084, 18.37400055, 19.06500053, ..., 18.22999954, 19.26199913, 20.07699966], ..., [ 3.79299998, 3.81399989, 3.80200005, ..., 3.80699992, 3.81100011, 3.8599999 ], [ 3.76399994, 3.77800012, 3.75699997, ..., 3.75399995, 3.74600005, 3.80599999], [ 3.74399996, 3.74600005, 3.7249999 , ..., nan, 3.71399999, nan]])
If the data are not aligned, they will be aligned before merge.
We can specify the join options in merge
.
xr.merge([
argo.salinity.sel(level=slice(0, 30)),
argo.temperature.sel(level=slice(30, None))
])
<xarray.Dataset> Dimensions: (level: 78, date: 75) Coordinates: * level (level) int64 0 1 2 3 4 5 6 7 8 ... 69 70 71 72 73 74 75 76 77 * date (date) datetime64[ns] 2012-07-13T22:33:06.019200 ... 2014-07... lon (date) float64 -39.13 -37.28 -36.9 ... -33.83 -34.11 -34.38 lat (date) float64 47.19 46.72 46.45 46.23 ... 42.6 42.46 42.38 Data variables: salinity (level, date) float64 35.64 35.51 35.57 35.4 ... nan nan nan temperature (level, date) float64 nan nan nan nan ... 3.728 nan 3.714 nan
- level: 78
- date: 75
- level(level)int640 1 2 3 4 5 6 ... 72 73 74 75 76 77
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77])
- date(date)datetime64[ns]2012-07-13T22:33:06.019200 ... 2...
array(['2012-07-13T22:33:06.019200000', '2012-07-23T22:54:59.990400000', '2012-08-02T22:55:52.003200000', '2012-08-12T23:08:59.971200000', '2012-08-22T23:29:01.968000000', '2012-09-01T23:17:38.976000000', '2012-09-12T02:59:18.960000000', '2012-09-21T23:18:37.036800000', '2012-10-02T03:00:17.971200000', '2012-10-11T23:13:27.984000000', '2012-10-22T02:50:32.006400000', '2012-10-31T23:36:39.974400000', '2012-11-11T02:40:46.041600000', '2012-11-20T23:08:29.990400000', '2012-12-01T02:47:51.993600000', '2012-12-10T23:23:16.972800000', '2012-12-21T02:58:48.979200000', '2012-12-30T23:07:23.030400000', '2013-01-10T02:56:43.008000000', '2013-01-19T23:24:26.956800000', '2013-01-30T02:43:53.011200000', '2013-02-08T23:15:27.043200000', '2013-02-19T01:12:50.976000000', '2013-02-28T23:07:13.008000000', '2013-03-11T02:43:30.979200000', '2013-03-20T23:17:22.992000000', '2013-03-31T01:50:38.025600000', '2013-04-09T23:19:07.968000000', '2013-04-20T02:53:29.990400000', '2013-04-29T23:28:33.024000000', '2013-05-10T02:50:18.009600000', '2013-05-19T23:21:05.990400000', '2013-05-30T02:50:30.969600000', '2013-06-08T23:32:49.027200000', '2013-06-19T03:42:51.004800000', '2013-06-28T23:32:16.022400000', '2013-07-09T03:28:30.979199999', '2013-07-18T23:33:57.974400000', '2013-07-29T03:15:42.019200000', '2013-08-07T23:25:02.035200000', '2013-08-18T01:47:44.966400000', '2013-08-28T03:02:59.020800000', '2013-09-07T03:03:51.984000000', '2013-09-16T23:32:07.987200000', '2013-09-27T04:08:27.974400000', '2013-10-06T23:25:39.964800000', '2013-10-17T02:55:50.995200000', '2013-10-27T03:45:47.001600000', '2013-11-06T01:14:52.022400000', '2013-11-16T03:29:54.009600000', '2013-11-26T03:03:56.995200000', '2013-12-05T23:33:59.011200000', '2013-12-16T02:58:01.977600000', '2013-12-25T23:22:43.017600000', '2014-01-05T02:52:06.009600000', '2014-01-14T23:41:18.009600000', '2014-01-25T03:00:43.977600000', '2014-02-03T23:29:13.977600000', '2014-02-14T02:50:11.961600000', '2014-02-23T23:03:21.974400000', '2014-03-06T02:58:03.964800000', '2014-03-15T23:10:28.012800000', '2014-03-26T02:51:22.032000000', '2014-04-04T23:25:58.972800000', '2014-04-15T03:00:45.964800000', '2014-04-24T23:24:40.003200000', '2014-05-05T02:56:22.012800000', '2014-05-15T00:10:06.009600000', '2014-05-25T03:02:43.036800000', '2014-06-03T23:34:53.961600000', '2014-06-14T03:01:23.980800000', '2014-06-23T23:24:31.968000000', '2014-07-04T03:08:30.019200000', '2014-07-13T23:47:43.008000000', '2014-07-24T03:02:33.014400000'], dtype='datetime64[ns]')
- lon(date)float64-39.13 -37.28 ... -34.11 -34.38
array([-39.13 , -37.282, -36.9 , -36.89 , -37.053, -36.658, -35.963, -35.184, -34.462, -33.784, -32.972, -32.546, -32.428, -32.292, -32.169, -31.998, -31.824, -31.624, -31.433, -31.312, -31.107, -31.147, -31.044, -31.14 , -31.417, -31.882, -32.145, -32.487, -32.537, -32.334, -32.042, -31.892, -31.861, -31.991, -31.883, -31.89 , -31.941, -31.889, -31.724, -31.412, -31.786, -31.561, -31.732, -31.553, -31.862, -32.389, -32.318, -32.19 , -32.224, -32.368, -32.306, -32.305, -32.65 , -33.093, -33.263, -33.199, -33.27 , -33.237, -33.221, -33.011, -32.844, -32.981, -32.784, -32.607, -32.87 , -33.196, -33.524, -33.956, -33.944, -33.71 , -33.621, -33.552, -33.828, -34.11 , -34.38 ])
- lat(date)float6447.19 46.72 46.45 ... 42.46 42.38
array([47.187, 46.716, 46.45 , 46.23 , 45.459, 44.833, 44.452, 44.839, 44.956, 44.676, 44.13 , 43.644, 43.067, 42.662, 42.513, 42.454, 42.396, 42.256, 42.089, 41.944, 41.712, 41.571, 41.596, 41.581, 41.351, 41.032, 40.912, 40.792, 40.495, 40.383, 40.478, 40.672, 41.032, 40.864, 40.651, 40.425, 40.228, 40.197, 40.483, 40.311, 40.457, 40.463, 40.164, 40.047, 39.963, 40.122, 40.57 , 40.476, 40.527, 40.589, 40.749, 40.993, 41.162, 41.237, 41.448, 41.65 , 42.053, 42.311, 42.096, 41.683, 41.661, 41.676, 42.018, 42.395, 42.532, 42.558, 42.504, 42.63 , 42.934, 42.952, 42.777, 42.722, 42.601, 42.457, 42.379])
- salinity(level, date)float6435.64 35.51 35.57 ... nan nan nan
array([[35.6389389 , 35.51495743, 35.57297134, ..., 35.82093811, 35.77793884, 35.66891098], [35.63393784, 35.5219574 , 35.57397079, ..., 35.81093216, 35.58389664, 35.66791153], [35.6819458 , 35.52595901, 35.57297134, ..., 35.79592896, 35.66290665, 35.66591263], ..., [ nan, nan, nan, ..., nan, nan, nan], [ nan, nan, nan, ..., nan, nan, nan], [ nan, nan, nan, ..., nan, nan, nan]])
- temperature(level, date)float64nan nan nan nan ... nan 3.714 nan
array([[ nan, nan, nan, ..., nan, nan, nan], [ nan, nan, nan, ..., nan, nan, nan], [ nan, nan, nan, ..., nan, nan, nan], ..., [3.79299998, 3.81399989, 3.80200005, ..., 3.80699992, 3.81100011, 3.8599999 ], [3.76399994, 3.77800012, 3.75699997, ..., 3.75399995, 3.74600005, 3.80599999], [3.74399996, 3.74600005, 3.7249999 , ..., nan, 3.71399999, nan]])
xr.merge([
argo.salinity.sel(level=slice(0, 30)),
argo.temperature.sel(level=slice(30, None))
], join='left')
<xarray.Dataset> Dimensions: (level: 31, date: 75) Coordinates: * level (level) int64 0 1 2 3 4 5 6 7 8 ... 22 23 24 25 26 27 28 29 30 * date (date) datetime64[ns] 2012-07-13T22:33:06.019200 ... 2014-07... lon (date) float64 -39.13 -37.28 -36.9 ... -33.83 -34.11 -34.38 lat (date) float64 47.19 46.72 46.45 46.23 ... 42.6 42.46 42.38 Data variables: salinity (level, date) float64 35.64 35.51 35.57 ... 35.78 35.83 35.76 temperature (level, date) float64 nan nan nan nan ... 13.59 13.74 13.31
- level: 31
- date: 75
- level(level)int640 1 2 3 4 5 6 ... 25 26 27 28 29 30
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30])
- date(date)datetime64[ns]2012-07-13T22:33:06.019200 ... 2...
array(['2012-07-13T22:33:06.019200000', '2012-07-23T22:54:59.990400000', '2012-08-02T22:55:52.003200000', '2012-08-12T23:08:59.971200000', '2012-08-22T23:29:01.968000000', '2012-09-01T23:17:38.976000000', '2012-09-12T02:59:18.960000000', '2012-09-21T23:18:37.036800000', '2012-10-02T03:00:17.971200000', '2012-10-11T23:13:27.984000000', '2012-10-22T02:50:32.006400000', '2012-10-31T23:36:39.974400000', '2012-11-11T02:40:46.041600000', '2012-11-20T23:08:29.990400000', '2012-12-01T02:47:51.993600000', '2012-12-10T23:23:16.972800000', '2012-12-21T02:58:48.979200000', '2012-12-30T23:07:23.030400000', '2013-01-10T02:56:43.008000000', '2013-01-19T23:24:26.956800000', '2013-01-30T02:43:53.011200000', '2013-02-08T23:15:27.043200000', '2013-02-19T01:12:50.976000000', '2013-02-28T23:07:13.008000000', '2013-03-11T02:43:30.979200000', '2013-03-20T23:17:22.992000000', '2013-03-31T01:50:38.025600000', '2013-04-09T23:19:07.968000000', '2013-04-20T02:53:29.990400000', '2013-04-29T23:28:33.024000000', '2013-05-10T02:50:18.009600000', '2013-05-19T23:21:05.990400000', '2013-05-30T02:50:30.969600000', '2013-06-08T23:32:49.027200000', '2013-06-19T03:42:51.004800000', '2013-06-28T23:32:16.022400000', '2013-07-09T03:28:30.979199999', '2013-07-18T23:33:57.974400000', '2013-07-29T03:15:42.019200000', '2013-08-07T23:25:02.035200000', '2013-08-18T01:47:44.966400000', '2013-08-28T03:02:59.020800000', '2013-09-07T03:03:51.984000000', '2013-09-16T23:32:07.987200000', '2013-09-27T04:08:27.974400000', '2013-10-06T23:25:39.964800000', '2013-10-17T02:55:50.995200000', '2013-10-27T03:45:47.001600000', '2013-11-06T01:14:52.022400000', '2013-11-16T03:29:54.009600000', '2013-11-26T03:03:56.995200000', '2013-12-05T23:33:59.011200000', '2013-12-16T02:58:01.977600000', '2013-12-25T23:22:43.017600000', '2014-01-05T02:52:06.009600000', '2014-01-14T23:41:18.009600000', '2014-01-25T03:00:43.977600000', '2014-02-03T23:29:13.977600000', '2014-02-14T02:50:11.961600000', '2014-02-23T23:03:21.974400000', '2014-03-06T02:58:03.964800000', '2014-03-15T23:10:28.012800000', '2014-03-26T02:51:22.032000000', '2014-04-04T23:25:58.972800000', '2014-04-15T03:00:45.964800000', '2014-04-24T23:24:40.003200000', '2014-05-05T02:56:22.012800000', '2014-05-15T00:10:06.009600000', '2014-05-25T03:02:43.036800000', '2014-06-03T23:34:53.961600000', '2014-06-14T03:01:23.980800000', '2014-06-23T23:24:31.968000000', '2014-07-04T03:08:30.019200000', '2014-07-13T23:47:43.008000000', '2014-07-24T03:02:33.014400000'], dtype='datetime64[ns]')
- lon(date)float64-39.13 -37.28 ... -34.11 -34.38
array([-39.13 , -37.282, -36.9 , -36.89 , -37.053, -36.658, -35.963, -35.184, -34.462, -33.784, -32.972, -32.546, -32.428, -32.292, -32.169, -31.998, -31.824, -31.624, -31.433, -31.312, -31.107, -31.147, -31.044, -31.14 , -31.417, -31.882, -32.145, -32.487, -32.537, -32.334, -32.042, -31.892, -31.861, -31.991, -31.883, -31.89 , -31.941, -31.889, -31.724, -31.412, -31.786, -31.561, -31.732, -31.553, -31.862, -32.389, -32.318, -32.19 , -32.224, -32.368, -32.306, -32.305, -32.65 , -33.093, -33.263, -33.199, -33.27 , -33.237, -33.221, -33.011, -32.844, -32.981, -32.784, -32.607, -32.87 , -33.196, -33.524, -33.956, -33.944, -33.71 , -33.621, -33.552, -33.828, -34.11 , -34.38 ])
- lat(date)float6447.19 46.72 46.45 ... 42.46 42.38
array([47.187, 46.716, 46.45 , 46.23 , 45.459, 44.833, 44.452, 44.839, 44.956, 44.676, 44.13 , 43.644, 43.067, 42.662, 42.513, 42.454, 42.396, 42.256, 42.089, 41.944, 41.712, 41.571, 41.596, 41.581, 41.351, 41.032, 40.912, 40.792, 40.495, 40.383, 40.478, 40.672, 41.032, 40.864, 40.651, 40.425, 40.228, 40.197, 40.483, 40.311, 40.457, 40.463, 40.164, 40.047, 39.963, 40.122, 40.57 , 40.476, 40.527, 40.589, 40.749, 40.993, 41.162, 41.237, 41.448, 41.65 , 42.053, 42.311, 42.096, 41.683, 41.661, 41.676, 42.018, 42.395, 42.532, 42.558, 42.504, 42.63 , 42.934, 42.952, 42.777, 42.722, 42.601, 42.457, 42.379])
- salinity(level, date)float6435.64 35.51 35.57 ... 35.83 35.76
array([[35.6389389 , 35.51495743, 35.57297134, ..., 35.82093811, 35.77793884, 35.66891098], [35.63393784, 35.5219574 , 35.57397079, ..., 35.81093216, 35.58389664, 35.66791153], [35.6819458 , 35.52595901, 35.57297134, ..., 35.79592896, 35.66290665, 35.66591263], ..., [35.76794815, 35.75598526, 35.84500504, ..., 35.84891891, 35.83391571, 35.76390076], [35.75194168, 35.71097565, 35.83100128, ..., 35.80690765, 35.85292053, 35.75489807], [35.73593903, 35.69297409, 35.81199646, ..., 35.78390503, 35.82591248, 35.75789642]])
- temperature(level, date)float64nan nan nan ... 13.59 13.74 13.31
array([[ nan, nan, nan, ..., nan, nan, nan], [ nan, nan, nan, ..., nan, nan, nan], [ nan, nan, nan, ..., nan, nan, nan], ..., [ nan, nan, nan, ..., nan, nan, nan], [ nan, nan, nan, ..., nan, nan, nan], [13.70600033, 13.44799995, 14.14000034, ..., 13.58699989, 13.73700047, 13.31000042]])
Reductions¶
Just like in numpy, we can reduce xarray DataArrays along any number of axes:
argo.temperature.mean(axis=0)
<xarray.DataArray 'temperature' (date: 75)> array([10.88915385, 10.7282564 , 10.9336282 , 10.75679484, 10.38166666, 10.08619236, 10.58194804, 10.50066671, 10.56841555, 10.53705122, 10.81131168, 11.01932052, 11.39205196, 11.40823073, 11.3642208 , 11.35821797, 11.39444157, 11.10514098, 11.02870125, 10.80894868, 10.93076625, 11.01069231, 11.88195654, 10.57373078, 10.66359736, 10.56573237, 11.08854546, 10.87921792, 11.21384416, 11.24991028, 11.29168825, 11.06203848, 11.32829864, 11.20401279, 11.25300001, 11.32106403, 11.40112986, 6.07053117, 11.7748052 , 11.7466795 , 12.03732056, 11.92653251, 12.08844156, 12.20543591, 12.23402598, 12.03365387, 11.9919221 , 11.92087012, 11.84273071, 11.79711684, 11.7895325 , 11.55385894, 11.19083561, 11.266282 , 11.0611948 , 11.0307179 , 11.06566232, 10.79799995, 10.787 , 10.41173077, 10.44170127, 10.32649998, 10.38242857, 10.88080769, 10.86177921, 10.98787178, 10.93602596, 10.73039743, 11.09251948, 10.93983334, 10.65942862, 11.01814097, 11.21918184, 11.19080765, 11.13364934]) Coordinates: * date (date) datetime64[ns] 2012-07-13T22:33:06.019200 ... 2014-07-24T... lon (date) float64 -39.13 -37.28 -36.9 -36.89 ... -33.83 -34.11 -34.38 lat (date) float64 47.19 46.72 46.45 46.23 ... 42.72 42.6 42.46 42.38
- date: 75
- 10.89 10.73 10.93 10.76 10.38 10.09 ... 10.66 11.02 11.22 11.19 11.13
array([10.88915385, 10.7282564 , 10.9336282 , 10.75679484, 10.38166666, 10.08619236, 10.58194804, 10.50066671, 10.56841555, 10.53705122, 10.81131168, 11.01932052, 11.39205196, 11.40823073, 11.3642208 , 11.35821797, 11.39444157, 11.10514098, 11.02870125, 10.80894868, 10.93076625, 11.01069231, 11.88195654, 10.57373078, 10.66359736, 10.56573237, 11.08854546, 10.87921792, 11.21384416, 11.24991028, 11.29168825, 11.06203848, 11.32829864, 11.20401279, 11.25300001, 11.32106403, 11.40112986, 6.07053117, 11.7748052 , 11.7466795 , 12.03732056, 11.92653251, 12.08844156, 12.20543591, 12.23402598, 12.03365387, 11.9919221 , 11.92087012, 11.84273071, 11.79711684, 11.7895325 , 11.55385894, 11.19083561, 11.266282 , 11.0611948 , 11.0307179 , 11.06566232, 10.79799995, 10.787 , 10.41173077, 10.44170127, 10.32649998, 10.38242857, 10.88080769, 10.86177921, 10.98787178, 10.93602596, 10.73039743, 11.09251948, 10.93983334, 10.65942862, 11.01814097, 11.21918184, 11.19080765, 11.13364934])
- date(date)datetime64[ns]2012-07-13T22:33:06.019200 ... 2...
array(['2012-07-13T22:33:06.019200000', '2012-07-23T22:54:59.990400000', '2012-08-02T22:55:52.003200000', '2012-08-12T23:08:59.971200000', '2012-08-22T23:29:01.968000000', '2012-09-01T23:17:38.976000000', '2012-09-12T02:59:18.960000000', '2012-09-21T23:18:37.036800000', '2012-10-02T03:00:17.971200000', '2012-10-11T23:13:27.984000000', '2012-10-22T02:50:32.006400000', '2012-10-31T23:36:39.974400000', '2012-11-11T02:40:46.041600000', '2012-11-20T23:08:29.990400000', '2012-12-01T02:47:51.993600000', '2012-12-10T23:23:16.972800000', '2012-12-21T02:58:48.979200000', '2012-12-30T23:07:23.030400000', '2013-01-10T02:56:43.008000000', '2013-01-19T23:24:26.956800000', '2013-01-30T02:43:53.011200000', '2013-02-08T23:15:27.043200000', '2013-02-19T01:12:50.976000000', '2013-02-28T23:07:13.008000000', '2013-03-11T02:43:30.979200000', '2013-03-20T23:17:22.992000000', '2013-03-31T01:50:38.025600000', '2013-04-09T23:19:07.968000000', '2013-04-20T02:53:29.990400000', '2013-04-29T23:28:33.024000000', '2013-05-10T02:50:18.009600000', '2013-05-19T23:21:05.990400000', '2013-05-30T02:50:30.969600000', '2013-06-08T23:32:49.027200000', '2013-06-19T03:42:51.004800000', '2013-06-28T23:32:16.022400000', '2013-07-09T03:28:30.979199999', '2013-07-18T23:33:57.974400000', '2013-07-29T03:15:42.019200000', '2013-08-07T23:25:02.035200000', '2013-08-18T01:47:44.966400000', '2013-08-28T03:02:59.020800000', '2013-09-07T03:03:51.984000000', '2013-09-16T23:32:07.987200000', '2013-09-27T04:08:27.974400000', '2013-10-06T23:25:39.964800000', '2013-10-17T02:55:50.995200000', '2013-10-27T03:45:47.001600000', '2013-11-06T01:14:52.022400000', '2013-11-16T03:29:54.009600000', '2013-11-26T03:03:56.995200000', '2013-12-05T23:33:59.011200000', '2013-12-16T02:58:01.977600000', '2013-12-25T23:22:43.017600000', '2014-01-05T02:52:06.009600000', '2014-01-14T23:41:18.009600000', '2014-01-25T03:00:43.977600000', '2014-02-03T23:29:13.977600000', '2014-02-14T02:50:11.961600000', '2014-02-23T23:03:21.974400000', '2014-03-06T02:58:03.964800000', '2014-03-15T23:10:28.012800000', '2014-03-26T02:51:22.032000000', '2014-04-04T23:25:58.972800000', '2014-04-15T03:00:45.964800000', '2014-04-24T23:24:40.003200000', '2014-05-05T02:56:22.012800000', '2014-05-15T00:10:06.009600000', '2014-05-25T03:02:43.036800000', '2014-06-03T23:34:53.961600000', '2014-06-14T03:01:23.980800000', '2014-06-23T23:24:31.968000000', '2014-07-04T03:08:30.019200000', '2014-07-13T23:47:43.008000000', '2014-07-24T03:02:33.014400000'], dtype='datetime64[ns]')
- lon(date)float64-39.13 -37.28 ... -34.11 -34.38
array([-39.13 , -37.282, -36.9 , -36.89 , -37.053, -36.658, -35.963, -35.184, -34.462, -33.784, -32.972, -32.546, -32.428, -32.292, -32.169, -31.998, -31.824, -31.624, -31.433, -31.312, -31.107, -31.147, -31.044, -31.14 , -31.417, -31.882, -32.145, -32.487, -32.537, -32.334, -32.042, -31.892, -31.861, -31.991, -31.883, -31.89 , -31.941, -31.889, -31.724, -31.412, -31.786, -31.561, -31.732, -31.553, -31.862, -32.389, -32.318, -32.19 , -32.224, -32.368, -32.306, -32.305, -32.65 , -33.093, -33.263, -33.199, -33.27 , -33.237, -33.221, -33.011, -32.844, -32.981, -32.784, -32.607, -32.87 , -33.196, -33.524, -33.956, -33.944, -33.71 , -33.621, -33.552, -33.828, -34.11 , -34.38 ])
- lat(date)float6447.19 46.72 46.45 ... 42.46 42.38
array([47.187, 46.716, 46.45 , 46.23 , 45.459, 44.833, 44.452, 44.839, 44.956, 44.676, 44.13 , 43.644, 43.067, 42.662, 42.513, 42.454, 42.396, 42.256, 42.089, 41.944, 41.712, 41.571, 41.596, 41.581, 41.351, 41.032, 40.912, 40.792, 40.495, 40.383, 40.478, 40.672, 41.032, 40.864, 40.651, 40.425, 40.228, 40.197, 40.483, 40.311, 40.457, 40.463, 40.164, 40.047, 39.963, 40.122, 40.57 , 40.476, 40.527, 40.589, 40.749, 40.993, 41.162, 41.237, 41.448, 41.65 , 42.053, 42.311, 42.096, 41.683, 41.661, 41.676, 42.018, 42.395, 42.532, 42.558, 42.504, 42.63 , 42.934, 42.952, 42.777, 42.722, 42.601, 42.457, 42.379])
argo.temperature.mean(axis=1)
<xarray.DataArray 'temperature' (level: 78)> array([17.60172602, 17.57223609, 17.5145833 , 17.42326395, 17.24943838, 17.03730134, 16.76787661, 16.44609588, 16.17439195, 16.04501356, 15.65827023, 15.4607296 , 15.26114862, 15.12489191, 14.99133783, 14.90160808, 14.81990544, 14.74535139, 14.66822971, 14.585027 , 14.49732434, 14.41904053, 14.35412163, 14.27102702, 14.19081082, 14.11487838, 14.04347293, 13.98067566, 13.90994595, 13.83274319, 13.76139196, 13.69836479, 13.62335132, 13.54185131, 13.46647295, 13.39395946, 13.32541891, 13.25205403, 13.18131082, 13.10233782, 12.89268916, 12.67795943, 12.4649189 , 12.2178513 , 11.98270268, 11.1281081 , 10.80430666, 10.49702667, 10.1749066 , 9.83453334, 9.48625332, 9.19793334, 8.66010666, 8.12324001, 7.60221333, 7.15289333, 6.74250667, 6.39543999, 6.04598667, 5.74538665, 5.48913333, 5.26604001, 5.08768 , 4.93479998, 4.77769334, 4.65368 , 4.54237334, 4.44274664, 4.35933333, 4.2653784 , 4.17290539, 4.08902703, 3.99864865, 3.92163514, 3.85617567, 3.78916217, 3.72950001, 3.66207691]) Coordinates: * level (level) int64 0 1 2 3 4 5 6 7 8 9 ... 68 69 70 71 72 73 74 75 76 77
- level: 78
- 17.6 17.57 17.51 17.42 17.25 17.04 ... 3.922 3.856 3.789 3.73 3.662
array([17.60172602, 17.57223609, 17.5145833 , 17.42326395, 17.24943838, 17.03730134, 16.76787661, 16.44609588, 16.17439195, 16.04501356, 15.65827023, 15.4607296 , 15.26114862, 15.12489191, 14.99133783, 14.90160808, 14.81990544, 14.74535139, 14.66822971, 14.585027 , 14.49732434, 14.41904053, 14.35412163, 14.27102702, 14.19081082, 14.11487838, 14.04347293, 13.98067566, 13.90994595, 13.83274319, 13.76139196, 13.69836479, 13.62335132, 13.54185131, 13.46647295, 13.39395946, 13.32541891, 13.25205403, 13.18131082, 13.10233782, 12.89268916, 12.67795943, 12.4649189 , 12.2178513 , 11.98270268, 11.1281081 , 10.80430666, 10.49702667, 10.1749066 , 9.83453334, 9.48625332, 9.19793334, 8.66010666, 8.12324001, 7.60221333, 7.15289333, 6.74250667, 6.39543999, 6.04598667, 5.74538665, 5.48913333, 5.26604001, 5.08768 , 4.93479998, 4.77769334, 4.65368 , 4.54237334, 4.44274664, 4.35933333, 4.2653784 , 4.17290539, 4.08902703, 3.99864865, 3.92163514, 3.85617567, 3.78916217, 3.72950001, 3.66207691])
- level(level)int640 1 2 3 4 5 6 ... 72 73 74 75 76 77
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77])
However, rather than performing reductions on axes (as in numpy), we can perform them on dimensions. This turns out to be a huge convenience
argo_mean = argo.mean(dim='date')
argo_mean
<xarray.Dataset> Dimensions: (level: 78) Coordinates: * level (level) int64 0 1 2 3 4 5 6 7 8 ... 69 70 71 72 73 74 75 76 77 Data variables: salinity (level) float64 35.91 35.9 35.9 35.9 ... 34.94 34.94 34.93 temperature (level) float64 17.6 17.57 17.51 17.42 ... 3.789 3.73 3.662 pressure (level) float64 6.435 10.57 15.54 ... 1.95e+03 1.999e+03
- level: 78
- level(level)int640 1 2 3 4 5 6 ... 72 73 74 75 76 77
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77])
- salinity(level)float6435.91 35.9 35.9 ... 34.94 34.93
array([35.9063218 , 35.90223138, 35.90313435, 35.90173139, 35.90544583, 35.9100359 , 35.90946015, 35.91343146, 35.91967712, 35.92615988, 35.93195456, 35.94055356, 35.94091596, 35.93905366, 35.93931069, 35.93786745, 35.93525794, 35.93118039, 35.92534328, 35.91652257, 35.90671895, 35.89617843, 35.88888019, 35.8789927 , 35.86946183, 35.8598671 , 35.85061713, 35.84211978, 35.83150467, 35.81969395, 35.80945061, 35.80092265, 35.79078674, 35.77886525, 35.76833627, 35.75838795, 35.74923783, 35.73923559, 35.73000444, 35.71877237, 35.68864513, 35.65607159, 35.62678265, 35.59231774, 35.56205662, 35.45401408, 35.41392634, 35.3810557 , 35.34845245, 35.31531555, 35.28392568, 35.26568334, 35.2389473 , 35.21583745, 35.19686081, 35.18231257, 35.1648436 , 35.15073542, 35.12509338, 35.10155869, 35.08199799, 35.06317012, 35.0490097 , 35.03678253, 35.02174266, 35.01135579, 35.00212936, 34.99386297, 34.98810328, 34.98008094, 34.97214884, 34.96517645, 34.95664983, 34.9507985 , 34.9465696 , 34.94198907, 34.93844852, 34.93290652])
- temperature(level)float6417.6 17.57 17.51 ... 3.73 3.662
array([17.60172602, 17.57223609, 17.5145833 , 17.42326395, 17.24943838, 17.03730134, 16.76787661, 16.44609588, 16.17439195, 16.04501356, 15.65827023, 15.4607296 , 15.26114862, 15.12489191, 14.99133783, 14.90160808, 14.81990544, 14.74535139, 14.66822971, 14.585027 , 14.49732434, 14.41904053, 14.35412163, 14.27102702, 14.19081082, 14.11487838, 14.04347293, 13.98067566, 13.90994595, 13.83274319, 13.76139196, 13.69836479, 13.62335132, 13.54185131, 13.46647295, 13.39395946, 13.32541891, 13.25205403, 13.18131082, 13.10233782, 12.89268916, 12.67795943, 12.4649189 , 12.2178513 , 11.98270268, 11.1281081 , 10.80430666, 10.49702667, 10.1749066 , 9.83453334, 9.48625332, 9.19793334, 8.66010666, 8.12324001, 7.60221333, 7.15289333, 6.74250667, 6.39543999, 6.04598667, 5.74538665, 5.48913333, 5.26604001, 5.08768 , 4.93479998, 4.77769334, 4.65368 , 4.54237334, 4.44274664, 4.35933333, 4.2653784 , 4.17290539, 4.08902703, 3.99864865, 3.92163514, 3.85617567, 3.78916217, 3.72950001, 3.66207691])
- pressure(level)float646.435 10.57 ... 1.95e+03 1.999e+03
array([ 6.43466671, 10.56891882, 15.54246568, 20.46301361, 25.42567552, 30.44459441, 35.44324375, 40.4391894 , 45.40810832, 50.37837879, 60.47297323, 70.48378413, 80.40270347, 90.48243311, 100.51216311, 110.46081151, 120.52702795, 130.49459282, 140.51216064, 150.40540376, 160.40810559, 170.36216035, 180.41080949, 190.4108097 , 200.39999761, 210.34729499, 220.32026858, 230.31351224, 240.28918808, 250.41486297, 260.39999843, 270.36891752, 280.42432136, 290.42297075, 300.4229691 , 310.46351087, 320.50675346, 330.5297266 , 340.41891521, 350.49729383, 375.41080867, 400.3797294 , 425.29864626, 450.38378205, 475.30675403, 550.47703016, 575.68400146, 600.42400716, 625.30800456, 650.34533773, 675.33333984, 700.37067546, 750.42400716, 800.36666992, 850.38534017, 900.4613387 , 950.45067383, 1000.38534261, 1050.38534668, 1100.45734212, 1150.45201335, 1200.40534505, 1250.25067383, 1300.49467773, 1350.40268392, 1400.41734538, 1450.25734212, 1500.40267253, 1550.46401367, 1600.44055011, 1650.34595056, 1700.42163251, 1750.42299013, 1800.35677358, 1850.33379467, 1900.20676401, 1950.20946771, 1999.28975423])
argo_mean.salinity.plot(y='level', yincrease=False)
[<matplotlib.lines.Line2D at 0x7f7973d9f280>]

argo_std = argo.std(dim='date')
argo_std.salinity.plot(y='level', yincrease=False)
[<matplotlib.lines.Line2D at 0x7f7973d81970>]

Weighted Reductions¶
Sometimes we want to perform a reduction (e.g. a mean) where we assign different weight factors to each point in the array. Xarray supports this via weighted array reductions.
As a toy example, imagine we want to weight values in the upper ocean more than the lower ocean. We could imagine creating a weight array exponentially proportional to pressure as follows:
mean_pressure = argo.pressure.mean(dim='date')
p0 = 250 # dbat
weights = np.exp(-mean_pressure / p0)
weights.plot()
[<matplotlib.lines.Line2D at 0x7f7973cf2310>]

The weighted mean over the level
dimensions is calculated as follows:
temp_weighted_mean = argo.temperature.weighted(weights).mean('level')
Comparing to the unweighted mean, we see the difference:
temp_weighted_mean.plot(label='weighted')
argo.temperature.mean(dim='level').plot(label='unweighted')
plt.legend()
<matplotlib.legend.Legend at 0x7f7973c49430>

Loading Data from netCDF Files¶
NetCDF (Network Common Data Format) is the most widely used format for distributing geoscience data. NetCDF is maintained by the Unidata organization.
Below we quote from the NetCDF website:
NetCDF (network Common Data Form) is a set of interfaces for array-oriented data access and a freely distributed collection of data access libraries for C, Fortran, C++, Java, and other languages. The netCDF libraries support a machine-independent format for representing scientific data. Together, the interfaces, libraries, and format support the creation, access, and sharing of scientific data.
NetCDF data is:
Self-Describing. A netCDF file includes information about the data it contains.
Portable. A netCDF file can be accessed by computers with different ways of storing integers, characters, and floating-point numbers.
Scalable. A small subset of a large dataset may be accessed efficiently.
Appendable. Data may be appended to a properly structured netCDF file without copying the dataset or redefining its structure.
Sharable. One writer and multiple readers may simultaneously access the same netCDF file.
Archivable. Access to all earlier forms of netCDF data will be supported by current and future versions of the software.
Xarray was designed to make reading netCDF files in python as easy, powerful, and flexible as possible. (See xarray netCDF docs for more details.)
Below we download and load some the NASA GISSTemp global temperature anomaly dataset.
gistemp_file = pooch.retrieve(
'https://data.giss.nasa.gov/pub/gistemp/gistemp1200_GHCNv4_ERSSTv5.nc.gz',
known_hash='eb645c5de8f43f0850cffac446066ea7e593b156ea26df4b5117f96ba757e654',
processor=pooch.Decompress(),
)
ds = xr.open_dataset(gistemp_file)
ds
<xarray.Dataset> Dimensions: (lat: 90, lon: 180, time: 1701, nv: 2) Coordinates: * lat (lat) float32 -89.0 -87.0 -85.0 -83.0 ... 83.0 85.0 87.0 89.0 * lon (lon) float32 -179.0 -177.0 -175.0 -173.0 ... 175.0 177.0 179.0 * time (time) datetime64[ns] 1880-01-15 1880-02-15 ... 2021-09-15 Dimensions without coordinates: nv Data variables: time_bnds (time, nv) datetime64[ns] 1880-01-01 1880-02-01 ... 2021-10-01 tempanomaly (time, lat, lon) float32 ... Attributes: title: GISTEMP Surface Temperature Analysis institution: NASA Goddard Institute for Space Studies source: http://data.giss.nasa.gov/gistemp/ Conventions: CF-1.6 history: Created 2021-10-11 08:04:07 by SBBX_to_nc 2.0 - ILAND=1200,...
- lat: 90
- lon: 180
- time: 1701
- nv: 2
- lat(lat)float32-89.0 -87.0 -85.0 ... 87.0 89.0
- standard_name :
- latitude
- long_name :
- Latitude
- units :
- degrees_north
array([-89., -87., -85., -83., -81., -79., -77., -75., -73., -71., -69., -67., -65., -63., -61., -59., -57., -55., -53., -51., -49., -47., -45., -43., -41., -39., -37., -35., -33., -31., -29., -27., -25., -23., -21., -19., -17., -15., -13., -11., -9., -7., -5., -3., -1., 1., 3., 5., 7., 9., 11., 13., 15., 17., 19., 21., 23., 25., 27., 29., 31., 33., 35., 37., 39., 41., 43., 45., 47., 49., 51., 53., 55., 57., 59., 61., 63., 65., 67., 69., 71., 73., 75., 77., 79., 81., 83., 85., 87., 89.], dtype=float32)
- lon(lon)float32-179.0 -177.0 ... 177.0 179.0
- standard_name :
- longitude
- long_name :
- Longitude
- units :
- degrees_east
array([-179., -177., -175., -173., -171., -169., -167., -165., -163., -161., -159., -157., -155., -153., -151., -149., -147., -145., -143., -141., -139., -137., -135., -133., -131., -129., -127., -125., -123., -121., -119., -117., -115., -113., -111., -109., -107., -105., -103., -101., -99., -97., -95., -93., -91., -89., -87., -85., -83., -81., -79., -77., -75., -73., -71., -69., -67., -65., -63., -61., -59., -57., -55., -53., -51., -49., -47., -45., -43., -41., -39., -37., -35., -33., -31., -29., -27., -25., -23., -21., -19., -17., -15., -13., -11., -9., -7., -5., -3., -1., 1., 3., 5., 7., 9., 11., 13., 15., 17., 19., 21., 23., 25., 27., 29., 31., 33., 35., 37., 39., 41., 43., 45., 47., 49., 51., 53., 55., 57., 59., 61., 63., 65., 67., 69., 71., 73., 75., 77., 79., 81., 83., 85., 87., 89., 91., 93., 95., 97., 99., 101., 103., 105., 107., 109., 111., 113., 115., 117., 119., 121., 123., 125., 127., 129., 131., 133., 135., 137., 139., 141., 143., 145., 147., 149., 151., 153., 155., 157., 159., 161., 163., 165., 167., 169., 171., 173., 175., 177., 179.], dtype=float32)
- time(time)datetime64[ns]1880-01-15 ... 2021-09-15
- long_name :
- time
- bounds :
- time_bnds
array(['1880-01-15T00:00:00.000000000', '1880-02-15T00:00:00.000000000', '1880-03-15T00:00:00.000000000', ..., '2021-07-15T00:00:00.000000000', '2021-08-15T00:00:00.000000000', '2021-09-15T00:00:00.000000000'], dtype='datetime64[ns]')
- time_bnds(time, nv)datetime64[ns]...
array([['1880-01-01T00:00:00.000000000', '1880-02-01T00:00:00.000000000'], ['1880-02-01T00:00:00.000000000', '1880-03-01T00:00:00.000000000'], ['1880-03-01T00:00:00.000000000', '1880-04-01T00:00:00.000000000'], ..., ['2021-07-01T00:00:00.000000000', '2021-08-01T00:00:00.000000000'], ['2021-08-01T00:00:00.000000000', '2021-09-01T00:00:00.000000000'], ['2021-09-01T00:00:00.000000000', '2021-10-01T00:00:00.000000000']], dtype='datetime64[ns]')
- tempanomaly(time, lat, lon)float32...
- long_name :
- Surface temperature anomaly
- units :
- K
- cell_methods :
- time: mean
[27556200 values with dtype=float32]
- title :
- GISTEMP Surface Temperature Analysis
- institution :
- NASA Goddard Institute for Space Studies
- source :
- http://data.giss.nasa.gov/gistemp/
- Conventions :
- CF-1.6
- history :
- Created 2021-10-11 08:04:07 by SBBX_to_nc 2.0 - ILAND=1200, IOCEAN=NCDC/ER5, Base: 1951-1980
ds.tempanomaly.isel(time=-1).plot()
<matplotlib.collections.QuadMesh at 0x7f796c46a430>

ds.tempanomaly.mean(dim=('lon', 'lat')).plot()
[<matplotlib.lines.Line2D at 0x7f7965a670a0>]
