Live Notebook

You can run this notebook in a live session Binder or view it on Github.

Xarray with Dask Arrays

Xarray Dataset

Xarray is an open source project and Python package that extends the labeled data functionality of Pandas to N-dimensional array-like datasets. It shares a similar API to NumPy and Pandas and supports both Dask and NumPy arrays under the hood.

[1]:
%matplotlib inline

from dask.distributed import Client
import xarray as xr

Start Dask Client for Dashboard

Starting the Dask Client is optional. It will provide a dashboard which is useful to gain insight on the computation.

The link to the dashboard will become visible when you create the client below. We recommend having it open on one side of your screen while using your notebook on the other side. This can take some effort to arrange your windows, but seeing them both at the same is very useful when learning.

[2]:
client = Client(n_workers=2, threads_per_worker=2, memory_limit='1GB')
client
[2]:

Client

Cluster

  • Workers: 2
  • Cores: 4
  • Memory: 2.00 GB

Open a sample dataset

We will use some of xarray’s tutorial data for this example. By specifying the chunk shape, xarray will automatically create Dask arrays for each data variable in the Dataset. In xarray, Datasets are dict-like container of labeled arrays, analogous to the pandas.DataFrame. Note that we’re taking advantage of xarray’s dimension labels when specifying chunk shapes.

[3]:
ds = xr.tutorial.open_dataset('air_temperature',
                              chunks={'lat': 25, 'lon': 25, 'time': -1})
ds
[3]:
Show/Hide data repr Show/Hide attributes
xarray.Dataset
    • lat: 25
    • lon: 53
    • time: 2920
    • lat
      (lat)
      float32
      75.0 72.5 70.0 ... 20.0 17.5 15.0
      standard_name :
      latitude
      long_name :
      Latitude
      units :
      degrees_north
      axis :
      Y
      array([75. , 72.5, 70. , 67.5, 65. , 62.5, 60. , 57.5, 55. , 52.5, 50. , 47.5,
             45. , 42.5, 40. , 37.5, 35. , 32.5, 30. , 27.5, 25. , 22.5, 20. , 17.5,
             15. ], dtype=float32)
    • lon
      (lon)
      float32
      200.0 202.5 205.0 ... 327.5 330.0
      standard_name :
      longitude
      long_name :
      Longitude
      units :
      degrees_east
      axis :
      X
      array([200. , 202.5, 205. , 207.5, 210. , 212.5, 215. , 217.5, 220. , 222.5,
             225. , 227.5, 230. , 232.5, 235. , 237.5, 240. , 242.5, 245. , 247.5,
             250. , 252.5, 255. , 257.5, 260. , 262.5, 265. , 267.5, 270. , 272.5,
             275. , 277.5, 280. , 282.5, 285. , 287.5, 290. , 292.5, 295. , 297.5,
             300. , 302.5, 305. , 307.5, 310. , 312.5, 315. , 317.5, 320. , 322.5,
             325. , 327.5, 330. ], dtype=float32)
    • time
      (time)
      datetime64[ns]
      2013-01-01 ... 2014-12-31T18:00:00
      standard_name :
      time
      long_name :
      Time
      array(['2013-01-01T00:00:00.000000000', '2013-01-01T06:00:00.000000000',
             '2013-01-01T12:00:00.000000000', ..., '2014-12-31T06:00:00.000000000',
             '2014-12-31T12:00:00.000000000', '2014-12-31T18:00:00.000000000'],
            dtype='datetime64[ns]')
    • air
      (time, lat, lon)
      float32
      dask.array<chunksize=(2920, 25, 25), meta=np.ndarray>
      long_name :
      4xDaily Air temperature at sigma level 995
      units :
      degK
      precision :
      2
      GRIB_id :
      11
      GRIB_name :
      TMP
      var_desc :
      Air temperature
      dataset :
      NMC Reanalysis
      level_desc :
      Surface
      statistic :
      Individual Obs
      parent_stat :
      Other
      actual_range :
      [185.16 322.1 ]
      Array Chunk
      Bytes 15.48 MB 7.30 MB
      Shape (2920, 25, 53) (2920, 25, 25)
      Count 4 Tasks 3 Chunks
      Type float32 numpy.ndarray
      53 25 2920
  • Conventions :
    COARDS
    title :
    4x daily NMC reanalysis (1948)
    description :
    Data is from NMC initialized reanalysis (4x/day). These are the 0.9950 sigma level values.
    platform :
    Model
    references :
    http://www.esrl.noaa.gov/psd/data/gridded/data.ncep.reanalysis.html

Quickly inspecting the Dataset above, we’ll note that this Dataset has three dimensions akin to axes in NumPy (lat, lon, and time), three coordinate variables akin to pandas.Index objects (also named lat, lon, and time), and one data variable (air). Xarray also holds Dataset specific metadata in as attributes.

[4]:
da = ds['air']
da
[4]:
Show/Hide data repr Show/Hide attributes
xarray.DataArray
'air'
  • time: 2920
  • lat: 25
  • lon: 53
  • dask.array<chunksize=(2920, 25, 25), meta=np.ndarray>
    Array Chunk
    Bytes 15.48 MB 7.30 MB
    Shape (2920, 25, 53) (2920, 25, 25)
    Count 4 Tasks 3 Chunks
    Type float32 numpy.ndarray
    53 25 2920
    • lat
      (lat)
      float32
      75.0 72.5 70.0 ... 20.0 17.5 15.0
      standard_name :
      latitude
      long_name :
      Latitude
      units :
      degrees_north
      axis :
      Y
      array([75. , 72.5, 70. , 67.5, 65. , 62.5, 60. , 57.5, 55. , 52.5, 50. , 47.5,
             45. , 42.5, 40. , 37.5, 35. , 32.5, 30. , 27.5, 25. , 22.5, 20. , 17.5,
             15. ], dtype=float32)
    • lon
      (lon)
      float32
      200.0 202.5 205.0 ... 327.5 330.0
      standard_name :
      longitude
      long_name :
      Longitude
      units :
      degrees_east
      axis :
      X
      array([200. , 202.5, 205. , 207.5, 210. , 212.5, 215. , 217.5, 220. , 222.5,
             225. , 227.5, 230. , 232.5, 235. , 237.5, 240. , 242.5, 245. , 247.5,
             250. , 252.5, 255. , 257.5, 260. , 262.5, 265. , 267.5, 270. , 272.5,
             275. , 277.5, 280. , 282.5, 285. , 287.5, 290. , 292.5, 295. , 297.5,
             300. , 302.5, 305. , 307.5, 310. , 312.5, 315. , 317.5, 320. , 322.5,
             325. , 327.5, 330. ], dtype=float32)
    • time
      (time)
      datetime64[ns]
      2013-01-01 ... 2014-12-31T18:00:00
      standard_name :
      time
      long_name :
      Time
      array(['2013-01-01T00:00:00.000000000', '2013-01-01T06:00:00.000000000',
             '2013-01-01T12:00:00.000000000', ..., '2014-12-31T06:00:00.000000000',
             '2014-12-31T12:00:00.000000000', '2014-12-31T18:00:00.000000000'],
            dtype='datetime64[ns]')
  • long_name :
    4xDaily Air temperature at sigma level 995
    units :
    degK
    precision :
    2
    GRIB_id :
    11
    GRIB_name :
    TMP
    var_desc :
    Air temperature
    dataset :
    NMC Reanalysis
    level_desc :
    Surface
    statistic :
    Individual Obs
    parent_stat :
    Other
    actual_range :
    [185.16 322.1 ]

Each data variable in xarray is called a DataArray. These are the fundemental labeled array object in xarray. Much like the Dataset, DataArrays also have dimensions and coordinates that support many of its label-based opperations.

[5]:
da.data
[5]:
Array Chunk
Bytes 15.48 MB 7.30 MB
Shape (2920, 25, 53) (2920, 25, 25)
Count 4 Tasks 3 Chunks
Type float32 numpy.ndarray
53 25 2920

Accessing the underlying array of data is done via the data property. Here we can see that we have a Dask array. If this array were to be backed by a NumPy array, this property would point to the actual values in the array.

Use Standard Xarray Operations

In almost all cases, operations using xarray objects are identical, regardless if the underlying data is stored as a Dask array or a NumPy array.

[6]:
da2 = da.groupby('time.month').mean('time')
da3 = da - da2
da3
[6]:
Show/Hide data repr Show/Hide attributes
xarray.DataArray
'air'
  • time: 2920
  • lat: 25
  • lon: 53
  • month: 12
  • dask.array<chunksize=(2920, 25, 25, 1), meta=np.ndarray>
    Array Chunk
    Bytes 185.71 MB 7.30 MB
    Shape (2920, 25, 53, 12) (2920, 25, 25, 1)
    Count 262 Tasks 36 Chunks
    Type float32 numpy.ndarray
    2920 1 12 53 25
    • lat
      (lat)
      float32
      75.0 72.5 70.0 ... 20.0 17.5 15.0
      standard_name :
      latitude
      long_name :
      Latitude
      units :
      degrees_north
      axis :
      Y
      array([75. , 72.5, 70. , 67.5, 65. , 62.5, 60. , 57.5, 55. , 52.5, 50. , 47.5,
             45. , 42.5, 40. , 37.5, 35. , 32.5, 30. , 27.5, 25. , 22.5, 20. , 17.5,
             15. ], dtype=float32)
    • lon
      (lon)
      float32
      200.0 202.5 205.0 ... 327.5 330.0
      standard_name :
      longitude
      long_name :
      Longitude
      units :
      degrees_east
      axis :
      X
      array([200. , 202.5, 205. , 207.5, 210. , 212.5, 215. , 217.5, 220. , 222.5,
             225. , 227.5, 230. , 232.5, 235. , 237.5, 240. , 242.5, 245. , 247.5,
             250. , 252.5, 255. , 257.5, 260. , 262.5, 265. , 267.5, 270. , 272.5,
             275. , 277.5, 280. , 282.5, 285. , 287.5, 290. , 292.5, 295. , 297.5,
             300. , 302.5, 305. , 307.5, 310. , 312.5, 315. , 317.5, 320. , 322.5,
             325. , 327.5, 330. ], dtype=float32)
    • time
      (time)
      datetime64[ns]
      2013-01-01 ... 2014-12-31T18:00:00
      standard_name :
      time
      long_name :
      Time
      array(['2013-01-01T00:00:00.000000000', '2013-01-01T06:00:00.000000000',
             '2013-01-01T12:00:00.000000000', ..., '2014-12-31T06:00:00.000000000',
             '2014-12-31T12:00:00.000000000', '2014-12-31T18:00:00.000000000'],
            dtype='datetime64[ns]')
    • month
      (month)
      int64
      1 2 3 4 5 6 7 8 9 10 11 12
      array([ 1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12])

Call .compute() or .load() when you want your result as a xarray.DataArray with data stored as NumPy arrays.

If you started Client() above then you may want to watch the status page during computation.

[7]:
computed_da = da3.load()
type(computed_da.data)
[7]:
numpy.ndarray
[8]:
computed_da
[8]:
Show/Hide data repr Show/Hide attributes
xarray.DataArray
'air'
  • time: 2920
  • lat: 25
  • lon: 53
  • month: 12
  • -5.149872 -5.4771576 -9.83168 ... -4.0723267 -3.1289062 -1.8476257
    array([[[[-5.14987183e+00, -5.47715759e+00, -9.83168030e+00, ...,
              -2.06136017e+01, -1.25448456e+01, -6.77099609e+00],
             [-3.88607788e+00, -3.90576172e+00, -8.17987061e+00, ...,
              -1.87125549e+01, -1.11448669e+01, -5.52117920e+00],
             [-2.71517944e+00, -2.44839478e+00, -6.68945312e+00, ...,
              -1.70036011e+01, -9.99716187e+00, -4.41302490e+00],
             ...,
             [-1.02611389e+01, -9.05839539e+00, -9.39399719e+00, ...,
              -1.53933716e+01, -1.01606750e+01, -6.97190857e+00],
             [-8.58795166e+00, -7.50210571e+00, -7.61483765e+00, ...,
              -1.35699463e+01, -8.43449402e+00, -5.52383423e+00],
             [-7.04670715e+00, -5.84384155e+00, -5.70956421e+00, ...,
              -1.18162537e+01, -6.54209900e+00, -4.02824402e+00]],
    
            [[-5.05761719e+00, -4.00010681e+00, -9.17195129e+00, ...,
              -2.52222595e+01, -1.53296814e+01, -5.93362427e+00],
             [-4.40733337e+00, -3.25991821e+00, -8.36616516e+00, ...,
              -2.44294434e+01, -1.41292725e+01, -5.66036987e+00],
             [-4.01040649e+00, -2.77757263e+00, -7.87347412e+00, ...,
              -2.40147858e+01, -1.34914398e+01, -5.78581238e+00],
             ...,
             [-8.72866821e+00, -7.84707642e+00, -8.81103516e+00, ...,
              -1.36155548e+01, -9.04922485e+00, -5.98965454e+00],
             [-8.20866394e+00, -6.96633911e+00, -7.72509766e+00, ...,
              -1.28683472e+01, -7.77966309e+00, -5.66470337e+00],
             [-7.45472717e+00, -5.76663208e+00, -6.08197021e+00, ...,
              -1.18489838e+01, -6.16625977e+00, -4.81626892e+00]],
    
            [[-1.57711792e+00,  9.29214478e-01, -4.46768188e+00, ...,
              -1.96401672e+01, -1.10422668e+01, -2.02960205e+00],
             [-1.39662170e+00,  1.22764587e+00, -4.29142761e+00, ...,
              -1.89958191e+01, -9.03536987e+00, -1.73136902e+00],
             [-1.82463074e+00,  9.47463989e-01, -4.74427795e+00, ...,
              -1.95648346e+01, -8.62193298e+00, -2.47628784e+00],
             ...,
             [-1.01989136e+01, -9.22874451e+00, -8.47184753e+00, ...,
              -1.28121490e+01, -9.18234253e+00, -4.87542725e+00],
             [-1.03946228e+01, -8.94348145e+00, -8.10664368e+00, ...,
              -1.32274017e+01, -8.74662781e+00, -5.52293396e+00],
             [-9.86572266e+00, -8.02273560e+00, -7.04258728e+00, ...,
              -1.29959869e+01, -7.82368469e+00, -5.36987305e+00]],
    
            ...,
    
            [[ 7.49725342e-01,  6.71142578e-01,  9.43481445e-01, ...,
              -2.49722290e+00, -1.24258423e+00, -1.65069580e-01],
             [ 9.55932617e-01,  7.82104492e-01,  9.54162598e-01, ...,
              -2.10467529e+00, -9.40612793e-01,  2.23297119e-01],
             [ 1.17315674e+00,  1.23397827e+00,  1.17535400e+00, ...,
              -1.59451294e+00, -5.87738037e-01,  5.10772705e-01],
             ...,
             [ 2.13745117e-01,  9.55688477e-01,  6.33697510e-01, ...,
              -3.69454956e+00, -2.56884766e+00, -1.05606079e+00],
             [ 4.42932129e-01,  1.31857300e+00,  9.35882568e-01, ...,
              -3.59548950e+00, -2.46887207e+00, -9.91363525e-01],
             [ 6.51489258e-01,  1.51733398e+00,  1.02706909e+00, ...,
              -3.59484863e+00, -2.46112061e+00, -9.57580566e-01]],
    
            [[-6.44592285e-01, -8.87542725e-01, -8.02947998e-01, ...,
              -3.53155518e+00, -2.68783569e+00, -1.56814575e+00],
             [-2.69836426e-01, -4.34448242e-01, -4.87579346e-01, ...,
              -3.03854370e+00, -2.22027588e+00, -1.18026733e+00],
             [ 6.30065918e-01,  6.32934570e-01,  4.07623291e-01, ...,
              -1.94747925e+00, -1.17895508e+00, -2.54272461e-01],
             ...,
             [ 5.44067383e-01,  1.38833618e+00,  1.04916382e+00, ...,
              -3.35891724e+00, -2.26412964e+00, -9.55596924e-01],
             [ 8.18786621e-01,  1.68218994e+00,  1.32965088e+00, ...,
              -3.38873291e+00, -2.29397583e+00, -9.46685791e-01],
             [ 6.69921875e-01,  1.49740601e+00,  1.04785156e+00, ...,
              -3.83630371e+00, -2.70831299e+00, -1.32135010e+00]],
    
            [[-8.64166260e-01, -9.98901367e-01, -1.09173584e+00, ...,
              -3.08053589e+00, -2.52142334e+00, -1.59088135e+00],
             [-4.48303223e-01, -4.26483154e-01, -6.73095703e-01, ...,
              -2.63461304e+00, -2.06658936e+00, -1.19677734e+00],
             [ 5.10864258e-02,  2.42034912e-01, -1.26678467e-01, ...,
              -2.05606079e+00, -1.52102661e+00, -6.75537109e-01],
             ...,
             [ 8.82019043e-01,  1.73941040e+00,  1.56509399e+00, ...,
              -2.82403564e+00, -1.82955933e+00, -7.00347900e-01],
             [ 1.01446533e+00,  1.83419800e+00,  1.67877197e+00, ...,
              -2.87310791e+00, -1.96188354e+00, -7.75482178e-01],
             [ 9.63531494e-01,  1.72033691e+00,  1.58346558e+00, ...,
              -3.16232300e+00, -2.21890259e+00, -9.37622070e-01]]],
    
    
           [[[-4.24987793e+00, -4.57716370e+00, -8.93168640e+00, ...,
              -1.97136078e+01, -1.16448517e+01, -5.87100220e+00],
             [-3.68608093e+00, -3.70576477e+00, -7.97987366e+00, ...,
              -1.85125580e+01, -1.09448700e+01, -5.32118225e+00],
             [-3.11518860e+00, -2.84840393e+00, -7.08946228e+00, ...,
              -1.74036102e+01, -1.03971710e+01, -4.81303406e+00],
             ...,
             [-1.10611267e+01, -9.85838318e+00, -1.01939850e+01, ...,
              -1.61933594e+01, -1.09606628e+01, -7.77189636e+00],
             [-1.04879608e+01, -9.40211487e+00, -9.51484680e+00, ...,
              -1.54699554e+01, -1.03345032e+01, -7.42384338e+00],
             [-9.84671021e+00, -8.64384460e+00, -8.50956726e+00, ...,
              -1.46162567e+01, -9.34210205e+00, -6.82824707e+00]],
    
            [[-5.25761414e+00, -4.20010376e+00, -9.37194824e+00, ...,
              -2.54222565e+01, -1.55296783e+01, -6.13362122e+00],
             [-4.80734253e+00, -3.65992737e+00, -8.76617432e+00, ...,
              -2.48294525e+01, -1.45292816e+01, -6.06037903e+00],
             [-4.51040649e+00, -3.27757263e+00, -8.37347412e+00, ...,
              -2.45147858e+01, -1.39914398e+01, -6.28581238e+00],
             ...,
             [-1.05286560e+01, -9.64706421e+00, -1.06110229e+01, ...,
              -1.54155426e+01, -1.08492126e+01, -7.78964233e+00],
             [-1.10086517e+01, -9.76632690e+00, -1.05250854e+01, ...,
              -1.56683350e+01, -1.05796509e+01, -8.46469116e+00],
             [-1.10547180e+01, -9.36662292e+00, -9.68196106e+00, ...,
              -1.54489746e+01, -9.76625061e+00, -8.41625977e+00]],
    
            [[ 1.62287903e+00,  4.12921143e+00, -1.26768494e+00, ...,
              -1.64401703e+01, -7.84226990e+00,  1.17039490e+00],
             [ 1.69338989e+00,  4.31765747e+00, -1.20141602e+00, ...,
              -1.59058075e+01, -5.94535828e+00,  1.35864258e+00],
             [ 1.38536072e+00,  4.15745544e+00, -1.53428650e+00, ...,
              -1.63548431e+01, -5.41194153e+00,  7.33703613e-01],
             ...,
             [-1.25989227e+01, -1.16287537e+01, -1.08718567e+01, ...,
              -1.52121582e+01, -1.15823517e+01, -7.27543640e+00],
             [-1.33946228e+01, -1.19434814e+01, -1.11066437e+01, ...,
              -1.62274017e+01, -1.17466278e+01, -8.52293396e+00],
             [-1.30657196e+01, -1.12227325e+01, -1.02425842e+01, ...,
              -1.61959839e+01, -1.10236816e+01, -8.56987000e+00]],
    
            ...,
    
            [[ 5.49713135e-01,  4.71130371e-01,  7.43469238e-01, ...,
              -2.69723511e+00, -1.44259644e+00, -3.65081787e-01],
             [ 6.55944824e-01,  4.82116699e-01,  6.54174805e-01, ...,
              -2.40466309e+00, -1.24060059e+00, -7.66906738e-02],
             [ 9.73144531e-01,  1.03396606e+00,  9.75341797e-01, ...,
              -1.79452515e+00, -7.87750244e-01,  3.10760498e-01],
             ...,
             [ 2.13745117e-01,  9.55688477e-01,  6.33697510e-01, ...,
              -3.69454956e+00, -2.56884766e+00, -1.05606079e+00],
             [ 4.42932129e-01,  1.31857300e+00,  9.35882568e-01, ...,
              -3.59548950e+00, -2.46887207e+00, -9.91363525e-01],
             [ 7.41516113e-01,  1.60736084e+00,  1.11709595e+00, ...,
              -3.50482178e+00, -2.37109375e+00, -8.67553711e-01]],
    
            [[-3.44604492e-01, -5.87554932e-01, -5.02960205e-01, ...,
              -3.23156738e+00, -2.38784790e+00, -1.26815796e+00],
             [ 2.30163574e-01,  6.55517578e-02,  1.24206543e-02, ...,
              -2.53854370e+00, -1.72027588e+00, -6.80267334e-01],
             [ 6.30065918e-01,  6.32934570e-01,  4.07623291e-01, ...,
              -1.94747925e+00, -1.17895508e+00, -2.54272461e-01],
             ...,
             [ 2.44079590e-01,  1.08834839e+00,  7.49176025e-01, ...,
              -3.65890503e+00, -2.56411743e+00, -1.25558472e+00],
             [ 4.18792725e-01,  1.28219604e+00,  9.29656982e-01, ...,
              -3.78872681e+00, -2.69396973e+00, -1.34667969e+00],
             [ 5.69946289e-01,  1.39743042e+00,  9.47875977e-01, ...,
              -3.93627930e+00, -2.80828857e+00, -1.42132568e+00]],
    
            [[-8.64166260e-01, -9.98901367e-01, -1.09173584e+00, ...,
              -3.08053589e+00, -2.52142334e+00, -1.59088135e+00],
             [-3.83300781e-02, -1.65100098e-02, -2.63122559e-01, ...,
              -2.22463989e+00, -1.65661621e+00, -7.86804199e-01],
             [ 3.51074219e-01,  5.42022705e-01,  1.73309326e-01, ...,
              -1.75607300e+00, -1.22103882e+00, -3.75549316e-01],
             ...,
             [ 3.82019043e-01,  1.23941040e+00,  1.06509399e+00, ...,
              -3.32403564e+00, -2.32955933e+00, -1.20034790e+00],
             [ 6.24450684e-01,  1.44418335e+00,  1.28875732e+00, ...,
              -3.26312256e+00, -2.35189819e+00, -1.16549683e+00],
             [ 9.63531494e-01,  1.72033691e+00,  1.58346558e+00, ...,
              -3.16232300e+00, -2.21890259e+00, -9.37622070e-01]]],
    
    
           [[[-4.04988098e+00, -4.37716675e+00, -8.73168945e+00, ...,
              -1.95136108e+01, -1.14448547e+01, -5.67100525e+00],
             [-4.18608093e+00, -4.20576477e+00, -8.47987366e+00, ...,
              -1.90125580e+01, -1.14448700e+01, -5.82118225e+00],
             [-3.91519165e+00, -3.64840698e+00, -7.88946533e+00, ...,
              -1.82036133e+01, -1.11971741e+01, -5.61303711e+00],
             ...,
             [-8.76113892e+00, -7.55839539e+00, -7.89399719e+00, ...,
              -1.38933716e+01, -8.66067505e+00, -5.47190857e+00],
             [-7.98796082e+00, -6.90211487e+00, -7.01484680e+00, ...,
              -1.29699554e+01, -7.83450317e+00, -4.92384338e+00],
             [-6.94670105e+00, -5.74383545e+00, -5.60955811e+00, ...,
              -1.17162476e+01, -6.44209290e+00, -3.92823792e+00]],
    
            [[-4.25761414e+00, -3.20010376e+00, -8.37194824e+00, ...,
              -2.44222565e+01, -1.45296783e+01, -5.13362122e+00],
             [-4.51733398e+00, -3.36991882e+00, -8.47616577e+00, ...,
              -2.45394440e+01, -1.42392731e+01, -5.77037048e+00],
             [-4.71040344e+00, -3.47756958e+00, -8.57347107e+00, ...,
              -2.47147827e+01, -1.41914368e+01, -6.48580933e+00],
             ...,
             [-1.12286682e+01, -1.03470764e+01, -1.13110352e+01, ...,
              -1.61155548e+01, -1.15492249e+01, -8.48965454e+00],
             [-1.15086517e+01, -1.02663269e+01, -1.10250854e+01, ...,
              -1.61683350e+01, -1.10796509e+01, -8.96469116e+00],
             [-1.10547180e+01, -9.36662292e+00, -9.68196106e+00, ...,
              -1.54489746e+01, -9.76625061e+00, -8.41625977e+00]],
    
            [[ 4.62286377e+00,  7.12919617e+00,  1.73229980e+00, ...,
              -1.34401855e+01, -4.84228516e+00,  4.17037964e+00],
             [ 4.30339050e+00,  6.92765808e+00,  1.40858459e+00, ...,
              -1.32958069e+01, -3.33535767e+00,  3.96864319e+00],
             [ 3.48536682e+00,  6.25746155e+00,  5.65719604e-01, ...,
              -1.42548370e+01, -3.31193542e+00,  2.83370972e+00],
             ...,
             [-1.21989136e+01, -1.12287445e+01, -1.04718475e+01, ...,
              -1.48121490e+01, -1.11823425e+01, -6.87542725e+00],
             [-1.35846252e+01, -1.21334839e+01, -1.12966461e+01, ...,
              -1.64174042e+01, -1.19366302e+01, -8.71293640e+00],
             [-1.33657227e+01, -1.15227356e+01, -1.05425873e+01, ...,
              -1.64959869e+01, -1.13236847e+01, -8.86987305e+00]],
    
            ...,
    
            [[-2.50274658e-01, -3.28857422e-01, -5.65185547e-02, ...,
              -3.49722290e+00, -2.24258423e+00, -1.16506958e+00],
             [ 1.55944824e-01, -1.78833008e-02,  1.54174805e-01, ...,
              -2.90466309e+00, -1.74060059e+00, -5.76690674e-01],
             [ 1.73156738e-01,  2.33978271e-01,  1.75354004e-01, ...,
              -2.59451294e+00, -1.58773804e+00, -4.89227295e-01],
             ...,
             [ 1.10375977e+00,  1.84570312e+00,  1.52371216e+00, ...,
              -2.80453491e+00, -1.67883301e+00, -1.66046143e-01],
             [ 6.32934570e-01,  1.50857544e+00,  1.12588501e+00, ...,
              -3.40548706e+00, -2.27886963e+00, -8.01361084e-01],
             [ 9.51507568e-01,  1.81735229e+00,  1.32708740e+00, ...,
              -3.29483032e+00, -2.16110229e+00, -6.57562256e-01]],
    
            [[-3.44604492e-01, -5.87554932e-01, -5.02960205e-01, ...,
              -3.23156738e+00, -2.38784790e+00, -1.26815796e+00],
             [ 3.01818848e-02, -1.34429932e-01, -1.87561035e-01, ...,
              -2.73852539e+00, -1.92025757e+00, -8.80249023e-01],
             [ 1.30065918e-01,  1.32934570e-01, -9.23767090e-02, ...,
              -2.44747925e+00, -1.67895508e+00, -7.54272461e-01],
             ...,
             [ 1.04406738e+00,  1.88833618e+00,  1.54916382e+00, ...,
              -2.85891724e+00, -1.76412964e+00, -4.55596924e-01],
             [ 9.18792725e-01,  1.78219604e+00,  1.42965698e+00, ...,
              -3.28872681e+00, -2.19396973e+00, -8.46679688e-01],
             [ 1.06994629e+00,  1.89743042e+00,  1.44787598e+00, ...,
              -3.43627930e+00, -2.30828857e+00, -9.21325684e-01]],
    
            [[-7.54180908e-01, -8.88916016e-01, -9.81750488e-01, ...,
              -2.97055054e+00, -2.41143799e+00, -1.48089600e+00],
             [-9.48303223e-01, -9.26483154e-01, -1.17309570e+00, ...,
              -3.13461304e+00, -2.56658936e+00, -1.69677734e+00],
             [-6.48925781e-01, -4.57977295e-01, -8.26690674e-01, ...,
              -2.75607300e+00, -2.22103882e+00, -1.37554932e+00],
             ...,
             [ 9.82025146e-01,  1.83941650e+00,  1.66510010e+00, ...,
              -2.72402954e+00, -1.72955322e+00, -6.00341797e-01],
             [ 1.22445679e+00,  2.04418945e+00,  1.88876343e+00, ...,
              -2.66311646e+00, -1.75189209e+00, -5.65490723e-01],
             [ 1.15353394e+00,  1.91033936e+00,  1.77346802e+00, ...,
              -2.97232056e+00, -2.02890015e+00, -7.47619629e-01]]],
    
    
           ...,
    
    
           [[[-2.85987854e+00, -3.18716431e+00, -7.54168701e+00, ...,
              -1.83236084e+01, -1.02548523e+01, -4.48100281e+00],
             [-3.39608765e+00, -3.41577148e+00, -7.68988037e+00, ...,
              -1.82225647e+01, -1.06548767e+01, -5.03118896e+00],
             [-4.12518311e+00, -3.85839844e+00, -8.09945679e+00, ...,
              -1.84136047e+01, -1.14071655e+01, -5.82302856e+00],
             ...,
             [ 1.12886047e+00,  2.33160400e+00,  1.99600220e+00, ...,
              -4.00337219e+00,  1.22932434e+00,  4.41809082e+00],
             [ 4.02038574e-01,  1.48788452e+00,  1.37515259e+00, ...,
              -4.57995605e+00,  5.55496216e-01,  3.46615601e+00],
             [-7.56698608e-01,  4.46166992e-01,  5.80444336e-01, ...,
              -5.52624512e+00, -2.52090454e-01,  2.26176453e+00]],
    
            [[ 2.32391357e-01,  1.28990173e+00, -3.88194275e+00, ...,
              -1.99322510e+01, -1.00396729e+01, -6.43615723e-01],
             [ 8.26568604e-02,  1.23007202e+00, -3.87617493e+00, ...,
              -1.99394531e+01, -9.63928223e+00, -1.17037964e+00],
             [-1.20407104e-01,  1.11242676e+00, -3.98347473e+00, ...,
              -2.01247864e+01, -9.60144043e+00, -1.89581299e+00],
             ...,
             [-9.38659668e-01, -5.70678711e-02, -1.02102661e+00, ...,
              -5.82554626e+00, -1.25921631e+00,  1.80035400e+00],
             [-2.21865845e+00, -9.76333618e-01, -1.73509216e+00, ...,
              -6.87834167e+00, -1.78965759e+00,  3.25302124e-01],
             [-4.06472778e+00, -2.37663269e+00, -2.69197083e+00, ...,
              -8.45898438e+00, -2.77626038e+00, -1.42626953e+00]],
    
            [[ 1.11128845e+01,  1.36192169e+01,  8.22232056e+00, ...,
              -6.95016479e+00,  1.64773560e+00,  1.06604004e+01],
             [ 1.09933929e+01,  1.36176605e+01,  8.09858704e+00, ...,
              -6.60580444e+00,  3.35464478e+00,  1.06586456e+01],
             [ 1.09753723e+01,  1.37474670e+01,  8.05572510e+00, ...,
              -6.76483154e+00,  4.17807007e+00,  1.03237152e+01],
             ...,
             [-4.00891113e+00, -3.03874207e+00, -2.28184509e+00, ...,
              -6.62214661e+00, -2.99234009e+00,  1.31457520e+00],
             [-5.09463501e+00, -3.64349365e+00, -2.80665588e+00, ...,
              -7.92741394e+00, -3.44664001e+00, -2.22946167e-01],
             [-6.37573242e+00, -4.53274536e+00, -3.55259705e+00, ...,
              -9.50599670e+00, -4.33369446e+00, -1.87988281e+00]],
    
            ...,
    
            [[-1.06027222e+00, -1.13885498e+00, -8.66516113e-01, ...,
              -4.30722046e+00, -3.05258179e+00, -1.97506714e+00],
             [ 4.59594727e-02, -1.27868652e-01,  4.41894531e-02, ...,
              -3.01464844e+00, -1.85058594e+00, -6.86676025e-01],
             [ 2.26315308e+00,  2.32397461e+00,  2.26535034e+00, ...,
              -5.04516602e-01,  5.02258301e-01,  1.60076904e+00],
             ...,
             [ 3.03741455e-01,  1.04568481e+00,  7.23693848e-01, ...,
              -3.60455322e+00, -2.47885132e+00, -9.66064453e-01],
             [ 7.32910156e-01,  1.60855103e+00,  1.22586060e+00, ...,
              -3.30551147e+00, -2.17889404e+00, -7.01385498e-01],
             [ 6.41510010e-01,  1.50735474e+00,  1.01708984e+00, ...,
              -3.60482788e+00, -2.47109985e+00, -9.67559814e-01]],
    
            [[ 2.45422363e-01,  2.47192383e-03,  8.70666504e-02, ...,
              -2.64154053e+00, -1.79782104e+00, -6.78131104e-01],
             [ 1.42016602e+00,  1.25555420e+00,  1.20242310e+00, ...,
              -1.34854126e+00, -5.30273438e-01,  5.09735107e-01],
             [ 2.13006592e+00,  2.13293457e+00,  1.90762329e+00, ...,
              -4.47479248e-01,  3.21044922e-01,  1.24572754e+00],
             ...,
             [ 1.34063721e-01,  9.78332520e-01,  6.39160156e-01, ...,
              -3.76892090e+00, -2.67413330e+00, -1.36560059e+00],
             [ 4.08782959e-01,  1.27218628e+00,  9.19647217e-01, ...,
              -3.79873657e+00, -2.70397949e+00, -1.35668945e+00],
             [ 2.59948730e-01,  1.08743286e+00,  6.37878418e-01, ...,
              -4.24627686e+00, -3.11828613e+00, -1.73132324e+00]],
    
            [[ 1.03582764e+00,  9.01092529e-01,  8.08258057e-01, ...,
              -1.18054199e+00, -6.21429443e-01,  3.09112549e-01],
             [ 1.95169067e+00,  1.97351074e+00,  1.72689819e+00, ...,
              -2.34619141e-01,  3.33404541e-01,  1.20321655e+00],
             [ 1.74108887e+00,  1.93203735e+00,  1.56332397e+00, ...,
              -3.66058350e-01,  1.68975830e-01,  1.01446533e+00],
             ...,
             [ 7.20214844e-02,  9.29412842e-01,  7.55096436e-01, ...,
              -3.63403320e+00, -2.63955688e+00, -1.51034546e+00],
             [ 1.44653320e-02,  8.34197998e-01,  6.78771973e-01, ...,
              -3.87310791e+00, -2.96188354e+00, -1.77548218e+00],
             [ 1.53533936e-01,  9.10339355e-01,  7.73468018e-01, ...,
              -3.97232056e+00, -3.02890015e+00, -1.74761963e+00]]],
    
    
           [[[-5.59875488e-01, -8.87161255e-01, -5.24168396e+00, ...,
              -1.60236053e+01, -7.95484924e+00, -2.18099976e+00],
             [-1.59608459e+00, -1.61576843e+00, -5.88987732e+00, ...,
              -1.64225616e+01, -8.85487366e+00, -3.23118591e+00],
             [-2.72518921e+00, -2.45840454e+00, -6.69946289e+00, ...,
              -1.70136108e+01, -1.00071716e+01, -4.42303467e+00],
             ...,
             [ 2.28866577e-01,  1.43161011e+00,  1.09600830e+00, ...,
              -4.90336609e+00,  3.29330444e-01,  3.51809692e+00],
             [-9.79614258e-02,  9.87884521e-01,  8.75152588e-01, ...,
              -5.07995605e+00,  5.54962158e-02,  2.96615601e+00],
             [-8.56704712e-01,  3.46160889e-01,  4.80438232e-01, ...,
              -5.62625122e+00, -3.52096558e-01,  2.16175842e+00]],
    
            [[ 1.03239441e+00,  2.08990479e+00, -3.08193970e+00, ...,
              -1.91322479e+01, -9.23966980e+00,  1.56387329e-01],
             [ 3.82659912e-01,  1.53007507e+00, -3.57617188e+00, ...,
              -1.96394501e+01, -9.33927917e+00, -8.70376587e-01],
             [-2.20413208e-01,  1.01242065e+00, -4.08348083e+00, ...,
              -2.02247925e+01, -9.70144653e+00, -1.99581909e+00],
             ...,
             [-2.38662720e-01,  6.42929077e-01, -3.21029663e-01, ...,
              -5.12554932e+00, -5.59219360e-01,  2.50035095e+00],
             [-1.01866150e+00,  2.23663330e-01, -5.35095215e-01, ...,
              -5.67834473e+00, -5.89660645e-01,  1.52529907e+00],
             [-2.46472168e+00, -7.76626587e-01, -1.09196472e+00, ...,
              -6.85897827e+00, -1.17625427e+00,  1.73736572e-01]],
    
            [[ 1.08128662e+01,  1.33191986e+01,  7.92230225e+00, ...,
              -7.25018311e+00,  1.34771729e+00,  1.03603821e+01],
             [ 1.05933990e+01,  1.32176666e+01,  7.69859314e+00, ...,
              -7.00579834e+00,  2.95465088e+00,  1.02586517e+01],
             [ 1.05753784e+01,  1.33474731e+01,  7.65573120e+00, ...,
              -7.16482544e+00,  3.77807617e+00,  9.92372131e+00],
             ...,
             [-2.90892029e+00, -1.93875122e+00, -1.18185425e+00, ...,
              -5.52215576e+00, -1.89234924e+00,  2.41456604e+00],
             [-3.69462585e+00, -2.24348450e+00, -1.40664673e+00, ...,
              -6.52740479e+00, -2.04663086e+00,  1.17706299e+00],
             [-4.67572021e+00, -2.83273315e+00, -1.85258484e+00, ...,
              -7.80598450e+00, -2.63368225e+00, -1.79870605e-01]],
    
            ...,
    
            [[-2.16027832e+00, -2.23886108e+00, -1.96652222e+00, ...,
              -5.40722656e+00, -4.15258789e+00, -3.07507324e+00],
             [-1.35406494e+00, -1.52789307e+00, -1.35583496e+00, ...,
              -4.41467285e+00, -3.25061035e+00, -2.08670044e+00],
             [ 1.63146973e-01,  2.23968506e-01,  1.65344238e-01, ...,
              -2.60452271e+00, -1.59774780e+00, -4.99237061e-01],
             ...,
             [-9.62524414e-02,  6.45690918e-01,  3.23699951e-01, ...,
              -4.00454712e+00, -2.87884521e+00, -1.36605835e+00],
             [ 3.29284668e-02,  9.08569336e-01,  5.25878906e-01, ...,
              -4.00549316e+00, -2.87887573e+00, -1.40136719e+00],
             [ 2.41516113e-01,  1.10736084e+00,  6.17095947e-01, ...,
              -4.00482178e+00, -2.87109375e+00, -1.36755371e+00]],
    
            [[-2.54577637e-01, -4.97528076e-01, -4.12933350e-01, ...,
              -3.14154053e+00, -2.29782104e+00, -1.17813110e+00],
             [ 7.20184326e-01,  5.55572510e-01,  5.02441406e-01, ...,
              -2.04852295e+00, -1.23025513e+00, -1.90246582e-01],
             [ 1.43005371e+00,  1.43292236e+00,  1.20761108e+00, ...,
              -1.14749146e+00, -3.78967285e-01,  5.45715332e-01],
             ...,
             [-6.59179688e-02,  7.78350830e-01,  4.39178467e-01, ...,
              -3.96890259e+00, -2.87411499e+00, -1.56558228e+00],
             [ 8.78906250e-03,  8.72192383e-01,  5.19653320e-01, ...,
              -4.19873047e+00, -3.10397339e+00, -1.75668335e+00],
             [-1.40075684e-01,  6.87408447e-01,  2.37854004e-01, ...,
              -4.64630127e+00, -3.51831055e+00, -2.13134766e+00]],
    
            [[ 6.35833740e-01,  5.01098633e-01,  4.08264160e-01, ...,
              -1.58053589e+00, -1.02142334e+00, -9.08813477e-02],
             [ 1.15167236e+00,  1.17349243e+00,  9.26879883e-01, ...,
              -1.03463745e+00, -4.66613770e-01,  4.03198242e-01],
             [ 1.44107056e+00,  1.63201904e+00,  1.26330566e+00, ...,
              -6.66076660e-01, -1.31042480e-01,  7.14447021e-01],
             ...,
             [-3.27972412e-01,  5.29418945e-01,  3.55102539e-01, ...,
              -4.03402710e+00, -3.03955078e+00, -1.91033936e+00],
             [-2.85552979e-01,  5.34179688e-01,  3.78753662e-01, ...,
              -4.17312622e+00, -3.26190186e+00, -2.07550049e+00],
             [-4.46472168e-01,  3.10333252e-01,  1.73461914e-01, ...,
              -4.57232666e+00, -3.62890625e+00, -2.34762573e+00]]],
    
    
           [[[-1.25987244e+00, -1.58715820e+00, -5.94168091e+00, ...,
              -1.67236023e+01, -8.65484619e+00, -2.88099670e+00],
             [-2.09608459e+00, -2.11576843e+00, -6.38987732e+00, ...,
              -1.69225616e+01, -9.35487366e+00, -3.73118591e+00],
             [-2.92518616e+00, -2.65840149e+00, -6.89945984e+00, ...,
              -1.72136078e+01, -1.02071686e+01, -4.62303162e+00],
             ...,
             [-1.37113953e+00, -1.68395996e-01, -5.03997803e-01, ...,
              -6.50337219e+00, -1.27067566e+00,  1.91809082e+00],
             [-2.59796143e+00, -1.51211548e+00, -1.62484741e+00, ...,
              -7.57995605e+00, -2.44450378e+00,  4.66156006e-01],
             [-3.85670471e+00, -2.65383911e+00, -2.51956177e+00, ...,
              -8.62625122e+00, -3.35209656e+00, -8.38241577e-01]],
    
            [[ 1.03239441e+00,  2.08990479e+00, -3.08193970e+00, ...,
              -1.91322479e+01, -9.23966980e+00,  1.56387329e-01],
             [ 3.82659912e-01,  1.53007507e+00, -3.57617188e+00, ...,
              -1.96394501e+01, -9.33927917e+00, -8.70376587e-01],
             [-3.20404053e-01,  9.12429810e-01, -4.18347168e+00, ...,
              -2.03247833e+01, -9.80143738e+00, -2.09580994e+00],
             ...,
             [-1.93865967e+00, -1.05706787e+00, -2.02102661e+00, ...,
              -6.82554626e+00, -2.25921631e+00,  8.00354004e-01],
             [-3.21865845e+00, -1.97633362e+00, -2.73509216e+00, ...,
              -7.87834167e+00, -2.78965759e+00, -6.74697876e-01],
             [-5.06472778e+00, -3.37663269e+00, -3.69197083e+00, ...,
              -9.45898438e+00, -3.77626038e+00, -2.42626953e+00]],
    
            [[ 1.14128723e+01,  1.39192047e+01,  8.52230835e+00, ...,
              -6.65017700e+00,  1.94772339e+00,  1.09603882e+01],
             [ 1.09933929e+01,  1.36176605e+01,  8.09858704e+00, ...,
              -6.60580444e+00,  3.35464478e+00,  1.06586456e+01],
             [ 1.06753540e+01,  1.34474487e+01,  7.75570679e+00, ...,
              -7.06484985e+00,  3.87805176e+00,  1.00236969e+01],
             ...,
             [-3.50891113e+00, -2.53874207e+00, -1.78184509e+00, ...,
              -6.12214661e+00, -2.49234009e+00,  1.81457520e+00],
             [-4.19462585e+00, -2.74348450e+00, -1.90664673e+00, ...,
              -7.02740479e+00, -2.54663086e+00,  6.77062988e-01],
             [-5.27572632e+00, -3.43273926e+00, -2.45259094e+00, ...,
              -8.40599060e+00, -3.23368835e+00, -7.79876709e-01]],
    
            ...,
    
            [[-2.06027222e+00, -2.13885498e+00, -1.86651611e+00, ...,
              -5.30722046e+00, -4.05258179e+00, -2.97506714e+00],
             [-1.55404663e+00, -1.72787476e+00, -1.55581665e+00, ...,
              -4.61465454e+00, -3.45059204e+00, -2.28668213e+00],
             [-1.36840820e-01, -7.60192871e-02, -1.34643555e-01, ...,
              -2.90451050e+00, -1.89773560e+00, -7.99224854e-01],
             ...,
             [ 1.03759766e-01,  8.45703125e-01,  5.23712158e-01, ...,
              -3.80453491e+00, -2.67883301e+00, -1.16604614e+00],
             [ 4.32922363e-01,  1.30856323e+00,  9.25872803e-01, ...,
              -3.60549927e+00, -2.47888184e+00, -1.00137329e+00],
             [ 6.41510010e-01,  1.50735474e+00,  1.01708984e+00, ...,
              -3.60482788e+00, -2.47109985e+00, -9.67559814e-01]],
    
            [[-4.54589844e-01, -6.97540283e-01, -6.12945557e-01, ...,
              -3.34155273e+00, -2.49783325e+00, -1.37814331e+00],
             [ 4.20166016e-01,  2.55554199e-01,  2.02423096e-01, ...,
              -2.34854126e+00, -1.53027344e+00, -4.90264893e-01],
             [ 1.03005981e+00,  1.03292847e+00,  8.07617188e-01, ...,
              -1.54748535e+00, -7.78961182e-01,  1.45721436e-01],
             ...,
             [ 3.34075928e-01,  1.17834473e+00,  8.39172363e-01, ...,
              -3.56890869e+00, -2.47412109e+00, -1.16558838e+00],
             [ 6.08795166e-01,  1.47219849e+00,  1.11965942e+00, ...,
              -3.59872437e+00, -2.50396729e+00, -1.15667725e+00],
             [ 6.59942627e-01,  1.48742676e+00,  1.03787231e+00, ...,
              -3.84628296e+00, -2.71829224e+00, -1.33132935e+00]],
    
            [[ 5.35827637e-01,  4.01092529e-01,  3.08258057e-01, ...,
              -1.68054199e+00, -1.12142944e+00, -1.90887451e-01],
             [ 8.51684570e-01,  8.73504639e-01,  6.26892090e-01, ...,
              -1.33462524e+00, -7.66601562e-01,  1.03210449e-01],
             [ 1.04107666e+00,  1.23202515e+00,  8.63311768e-01, ...,
              -1.06607056e+00, -5.31036377e-01,  3.14453125e-01],
             ...,
             [ 4.72015381e-01,  1.32940674e+00,  1.15509033e+00, ...,
              -3.23403931e+00, -2.23956299e+00, -1.11035156e+00],
             [ 4.14459229e-01,  1.23419189e+00,  1.07876587e+00, ...,
              -3.47311401e+00, -2.56188965e+00, -1.37548828e+00],
             [ 5.35278320e-02,  8.10333252e-01,  6.73461914e-01, ...,
              -4.07232666e+00, -3.12890625e+00, -1.84762573e+00]]]],
          dtype=float32)
    • lat
      (lat)
      float32
      75.0 72.5 70.0 ... 20.0 17.5 15.0
      standard_name :
      latitude
      long_name :
      Latitude
      units :
      degrees_north
      axis :
      Y
      array([75. , 72.5, 70. , 67.5, 65. , 62.5, 60. , 57.5, 55. , 52.5, 50. , 47.5,
             45. , 42.5, 40. , 37.5, 35. , 32.5, 30. , 27.5, 25. , 22.5, 20. , 17.5,
             15. ], dtype=float32)
    • lon
      (lon)
      float32
      200.0 202.5 205.0 ... 327.5 330.0
      standard_name :
      longitude
      long_name :
      Longitude
      units :
      degrees_east
      axis :
      X
      array([200. , 202.5, 205. , 207.5, 210. , 212.5, 215. , 217.5, 220. , 222.5,
             225. , 227.5, 230. , 232.5, 235. , 237.5, 240. , 242.5, 245. , 247.5,
             250. , 252.5, 255. , 257.5, 260. , 262.5, 265. , 267.5, 270. , 272.5,
             275. , 277.5, 280. , 282.5, 285. , 287.5, 290. , 292.5, 295. , 297.5,
             300. , 302.5, 305. , 307.5, 310. , 312.5, 315. , 317.5, 320. , 322.5,
             325. , 327.5, 330. ], dtype=float32)
    • time
      (time)
      datetime64[ns]
      2013-01-01 ... 2014-12-31T18:00:00
      standard_name :
      time
      long_name :
      Time
      array(['2013-01-01T00:00:00.000000000', '2013-01-01T06:00:00.000000000',
             '2013-01-01T12:00:00.000000000', ..., '2014-12-31T06:00:00.000000000',
             '2014-12-31T12:00:00.000000000', '2014-12-31T18:00:00.000000000'],
            dtype='datetime64[ns]')
    • month
      (month)
      int64
      1 2 3 4 5 6 7 8 9 10 11 12
      array([ 1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12])

Persist data in memory

If you have the available RAM for your dataset then you can persist data in memory.

This allows future computations to be much faster.

[9]:
da = da.persist()

Time Series Operations

Because we have a datetime index time-series operations work efficiently. Here we demo the use of xarray’s resample method:

[10]:
da.resample(time='1w').mean('time').std('time')
[10]:
Show/Hide data repr Show/Hide attributes
xarray.DataArray
'air'
  • lat: 25
  • lon: 53
  • dask.array<chunksize=(25, 25), meta=np.ndarray>
    Array Chunk
    Bytes 5.30 kB 2.50 kB
    Shape (25, 53) (25, 25)
    Count 1692 Tasks 3 Chunks
    Type float32 numpy.ndarray
    53 25
    • lat
      (lat)
      float32
      75.0 72.5 70.0 ... 20.0 17.5 15.0
      standard_name :
      latitude
      long_name :
      Latitude
      units :
      degrees_north
      axis :
      Y
      array([75. , 72.5, 70. , 67.5, 65. , 62.5, 60. , 57.5, 55. , 52.5, 50. , 47.5,
             45. , 42.5, 40. , 37.5, 35. , 32.5, 30. , 27.5, 25. , 22.5, 20. , 17.5,
             15. ], dtype=float32)
    • lon
      (lon)
      float32
      200.0 202.5 205.0 ... 327.5 330.0
      standard_name :
      longitude
      long_name :
      Longitude
      units :
      degrees_east
      axis :
      X
      array([200. , 202.5, 205. , 207.5, 210. , 212.5, 215. , 217.5, 220. , 222.5,
             225. , 227.5, 230. , 232.5, 235. , 237.5, 240. , 242.5, 245. , 247.5,
             250. , 252.5, 255. , 257.5, 260. , 262.5, 265. , 267.5, 270. , 272.5,
             275. , 277.5, 280. , 282.5, 285. , 287.5, 290. , 292.5, 295. , 297.5,
             300. , 302.5, 305. , 307.5, 310. , 312.5, 315. , 317.5, 320. , 322.5,
             325. , 327.5, 330. ], dtype=float32)
[11]:
da.resample(time='1w').mean('time').std('time').load().plot(figsize=(12, 8))
[11]:
<matplotlib.collections.QuadMesh at 0x7f994f7c8b10>
_images/xarray_20_1.png

and rolling window operations:

[12]:
da_smooth = da.rolling(time=30).mean().persist()
da_smooth
[12]:
Show/Hide data repr Show/Hide attributes
xarray.DataArray
  • time: 2920
  • lat: 25
  • lon: 53
  • dask.array<chunksize=(15, 25, 25), meta=np.ndarray>
    Array Chunk
    Bytes 15.48 MB 7.26 MB
    Shape (2920, 25, 53) (2905, 25, 25)
    Count 6 Tasks 6 Chunks
    Type float32 numpy.ndarray
    53 25 2920
    • lat
      (lat)
      float32
      75.0 72.5 70.0 ... 20.0 17.5 15.0
      standard_name :
      latitude
      long_name :
      Latitude
      units :
      degrees_north
      axis :
      Y
      array([75. , 72.5, 70. , 67.5, 65. , 62.5, 60. , 57.5, 55. , 52.5, 50. , 47.5,
             45. , 42.5, 40. , 37.5, 35. , 32.5, 30. , 27.5, 25. , 22.5, 20. , 17.5,
             15. ], dtype=float32)
    • lon
      (lon)
      float32
      200.0 202.5 205.0 ... 327.5 330.0
      standard_name :
      longitude
      long_name :
      Longitude
      units :
      degrees_east
      axis :
      X
      array([200. , 202.5, 205. , 207.5, 210. , 212.5, 215. , 217.5, 220. , 222.5,
             225. , 227.5, 230. , 232.5, 235. , 237.5, 240. , 242.5, 245. , 247.5,
             250. , 252.5, 255. , 257.5, 260. , 262.5, 265. , 267.5, 270. , 272.5,
             275. , 277.5, 280. , 282.5, 285. , 287.5, 290. , 292.5, 295. , 297.5,
             300. , 302.5, 305. , 307.5, 310. , 312.5, 315. , 317.5, 320. , 322.5,
             325. , 327.5, 330. ], dtype=float32)
    • time
      (time)
      datetime64[ns]
      2013-01-01 ... 2014-12-31T18:00:00
      standard_name :
      time
      long_name :
      Time
      array(['2013-01-01T00:00:00.000000000', '2013-01-01T06:00:00.000000000',
             '2013-01-01T12:00:00.000000000', ..., '2014-12-31T06:00:00.000000000',
             '2014-12-31T12:00:00.000000000', '2014-12-31T18:00:00.000000000'],
            dtype='datetime64[ns]')

Since xarray stores each of its coordinate variables in memory, slicing by label is trivial and entirely lazy.

[13]:
%time da.sel(time='2013-01-01T18:00:00')
CPU times: user 11.2 ms, sys: 544 µs, total: 11.7 ms
Wall time: 17.3 ms
[13]:
Show/Hide data repr Show/Hide attributes
xarray.DataArray
'air'
  • lat: 25
  • lon: 53
  • dask.array<chunksize=(25, 25), meta=np.ndarray>
    Array Chunk
    Bytes 5.30 kB 2.50 kB
    Shape (25, 53) (25, 25)
    Count 6 Tasks 3 Chunks
    Type float32 numpy.ndarray
    53 25
    • lat
      (lat)
      float32
      75.0 72.5 70.0 ... 20.0 17.5 15.0
      standard_name :
      latitude
      long_name :
      Latitude
      units :
      degrees_north
      axis :
      Y
      array([75. , 72.5, 70. , 67.5, 65. , 62.5, 60. , 57.5, 55. , 52.5, 50. , 47.5,
             45. , 42.5, 40. , 37.5, 35. , 32.5, 30. , 27.5, 25. , 22.5, 20. , 17.5,
             15. ], dtype=float32)
    • lon
      (lon)
      float32
      200.0 202.5 205.0 ... 327.5 330.0
      standard_name :
      longitude
      long_name :
      Longitude
      units :
      degrees_east
      axis :
      X
      array([200. , 202.5, 205. , 207.5, 210. , 212.5, 215. , 217.5, 220. , 222.5,
             225. , 227.5, 230. , 232.5, 235. , 237.5, 240. , 242.5, 245. , 247.5,
             250. , 252.5, 255. , 257.5, 260. , 262.5, 265. , 267.5, 270. , 272.5,
             275. , 277.5, 280. , 282.5, 285. , 287.5, 290. , 292.5, 295. , 297.5,
             300. , 302.5, 305. , 307.5, 310. , 312.5, 315. , 317.5, 320. , 322.5,
             325. , 327.5, 330. ], dtype=float32)
    • time
      ()
      datetime64[ns]
      2013-01-01T18:00:00
      standard_name :
      time
      long_name :
      Time
      array('2013-01-01T18:00:00.000000000', dtype='datetime64[ns]')
  • long_name :
    4xDaily Air temperature at sigma level 995
    units :
    degK
    precision :
    2
    GRIB_id :
    11
    GRIB_name :
    TMP
    var_desc :
    Air temperature
    dataset :
    NMC Reanalysis
    level_desc :
    Surface
    statistic :
    Individual Obs
    parent_stat :
    Other
    actual_range :
    [185.16 322.1 ]
[14]:
%time da.sel(time='2013-01-01T18:00:00').load()
CPU times: user 22.1 ms, sys: 0 ns, total: 22.1 ms
Wall time: 34 ms
[14]:
Show/Hide data repr Show/Hide attributes
xarray.DataArray
'air'
  • lat: 25
  • lon: 53
  • 241.89 241.79999 241.79999 242.09999 ... 298.19998 297.79 298.0 297.9
    array([[241.89   , 241.79999, 241.79999, ..., 234.39   , 235.5    ,
            237.59999],
           [246.29999, 245.29999, 244.2    , ..., 230.89   , 231.5    ,
            234.5    ],
           [256.6    , 254.7    , 252.09999, ..., 230.7    , 231.79999,
            236.09999],
           ...,
           [296.6    , 296.4    , 296.     , ..., 296.5    , 295.79   ,
            295.29   ],
           [297.     , 297.5    , 297.1    , ..., 296.79   , 296.6    ,
            296.29   ],
           [297.5    , 297.69998, 297.5    , ..., 297.79   , 298.     ,
            297.9    ]], dtype=float32)
    • lat
      (lat)
      float32
      75.0 72.5 70.0 ... 20.0 17.5 15.0
      standard_name :
      latitude
      long_name :
      Latitude
      units :
      degrees_north
      axis :
      Y
      array([75. , 72.5, 70. , 67.5, 65. , 62.5, 60. , 57.5, 55. , 52.5, 50. , 47.5,
             45. , 42.5, 40. , 37.5, 35. , 32.5, 30. , 27.5, 25. , 22.5, 20. , 17.5,
             15. ], dtype=float32)
    • lon
      (lon)
      float32
      200.0 202.5 205.0 ... 327.5 330.0
      standard_name :
      longitude
      long_name :
      Longitude
      units :
      degrees_east
      axis :
      X
      array([200. , 202.5, 205. , 207.5, 210. , 212.5, 215. , 217.5, 220. , 222.5,
             225. , 227.5, 230. , 232.5, 235. , 237.5, 240. , 242.5, 245. , 247.5,
             250. , 252.5, 255. , 257.5, 260. , 262.5, 265. , 267.5, 270. , 272.5,
             275. , 277.5, 280. , 282.5, 285. , 287.5, 290. , 292.5, 295. , 297.5,
             300. , 302.5, 305. , 307.5, 310. , 312.5, 315. , 317.5, 320. , 322.5,
             325. , 327.5, 330. ], dtype=float32)
    • time
      ()
      datetime64[ns]
      2013-01-01T18:00:00
      standard_name :
      time
      long_name :
      Time
      array('2013-01-01T18:00:00.000000000', dtype='datetime64[ns]')
  • long_name :
    4xDaily Air temperature at sigma level 995
    units :
    degK
    precision :
    2
    GRIB_id :
    11
    GRIB_name :
    TMP
    var_desc :
    Air temperature
    dataset :
    NMC Reanalysis
    level_desc :
    Surface
    statistic :
    Individual Obs
    parent_stat :
    Other
    actual_range :
    [185.16 322.1 ]

Custom workflows and automatic parallelization

Almost all of xarray’s built-in operations work on Dask arrays. If you want to use a function that isn’t wrapped by xarray, one option is to extract Dask arrays from xarray objects (.data) and use Dask directly.

Another option is to use xarray’s apply_ufunc() function, which can automate embarrassingly parallel “map” type operations where a functions written for processing NumPy arrays should be repeatedly applied to xarray objects containing Dask arrays. It works similarly to dask.array.map_blocks() and dask.array.atop(), but without requiring an intermediate layer of abstraction.

Here we show an example using NumPy operations and a fast function from bottleneck, which we use to calculate Spearman’s rank-correlation coefficient:

[15]:
import numpy as np
import xarray as xr
import bottleneck

def covariance_gufunc(x, y):
    return ((x - x.mean(axis=-1, keepdims=True))
            * (y - y.mean(axis=-1, keepdims=True))).mean(axis=-1)

def pearson_correlation_gufunc(x, y):
    return covariance_gufunc(x, y) / (x.std(axis=-1) * y.std(axis=-1))

def spearman_correlation_gufunc(x, y):
    x_ranks = bottleneck.rankdata(x, axis=-1)
    y_ranks = bottleneck.rankdata(y, axis=-1)
    return pearson_correlation_gufunc(x_ranks, y_ranks)

def spearman_correlation(x, y, dim):
    return xr.apply_ufunc(
        spearman_correlation_gufunc, x, y,
        input_core_dims=[[dim], [dim]],
        dask='parallelized',
        output_dtypes=[float])

In the examples above, we were working with an some air temperature data. For this example, we’ll calculate the spearman correlation using the raw air temperature data with the smoothed version that we also created (da_smooth). For this, we’ll also have to rechunk the data ahead of time.

[16]:
corr = spearman_correlation(da.chunk({'time': -1}),
                            da_smooth.chunk({'time': -1}),
                            'time')
corr
[16]:
Show/Hide data repr Show/Hide attributes
xarray.DataArray
  • lat: 25
  • lon: 53
  • dask.array<chunksize=(25, 25), meta=np.ndarray>
    Array Chunk
    Bytes 10.60 kB 5.00 kB
    Shape (25, 53) (25, 25)
    Count 21 Tasks 3 Chunks
    Type float64 numpy.ndarray
    53 25
    • lat
      (lat)
      float32
      75.0 72.5 70.0 ... 20.0 17.5 15.0
      standard_name :
      latitude
      long_name :
      Latitude
      units :
      degrees_north
      axis :
      Y
      array([75. , 72.5, 70. , 67.5, 65. , 62.5, 60. , 57.5, 55. , 52.5, 50. , 47.5,
             45. , 42.5, 40. , 37.5, 35. , 32.5, 30. , 27.5, 25. , 22.5, 20. , 17.5,
             15. ], dtype=float32)
    • lon
      (lon)
      float32
      200.0 202.5 205.0 ... 327.5 330.0
      standard_name :
      longitude
      long_name :
      Longitude
      units :
      degrees_east
      axis :
      X
      array([200. , 202.5, 205. , 207.5, 210. , 212.5, 215. , 217.5, 220. , 222.5,
             225. , 227.5, 230. , 232.5, 235. , 237.5, 240. , 242.5, 245. , 247.5,
             250. , 252.5, 255. , 257.5, 260. , 262.5, 265. , 267.5, 270. , 272.5,
             275. , 277.5, 280. , 282.5, 285. , 287.5, 290. , 292.5, 295. , 297.5,
             300. , 302.5, 305. , 307.5, 310. , 312.5, 315. , 317.5, 320. , 322.5,
             325. , 327.5, 330. ], dtype=float32)
[17]:
corr.plot(figsize=(12, 8))
[17]:
<matplotlib.collections.QuadMesh at 0x7f99786f1e10>
_images/xarray_31_1.png
[ ]: