Regrid xarray Dataset with multiple variables

[1]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import xarray as xr
import xesmf as xe

Starting v0.2.0, xESMF is able to take xarray.Dataset as input data, and automatically loop over all variables.

A simple example

Prepare input data

[2]:
ds = xr.tutorial.open_dataset("air_temperature")
ds  # air temperature in Kelvin
[2]:
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
      ...
      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 ]
      [3869000 values with dtype=float32]
  • 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
[3]:
# input dataset can contain variables of different shapes (e.g. 2D, 3D, 4D), as long as horizontal shapes are the same.
ds["celsius"] = ds["air"] - 273.15  # Kelvin -> celsius
ds["slice"] = ds["air"].isel(time=0)
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
      241.2 242.5 243.5 ... 296.19 295.69
      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([[[241.2    , 242.5    , ..., 235.5    , 238.59999],
              [243.79999, 244.5    , ..., 235.29999, 239.29999],
              ...,
              [295.9    , 296.19998, ..., 295.9    , 295.19998],
              [296.29   , 296.79   , ..., 296.79   , 296.6    ]],
      
             [[242.09999, 242.7    , ..., 233.59999, 235.79999],
              [243.59999, 244.09999, ..., 232.5    , 235.7    ],
              ...,
              [296.19998, 296.69998, ..., 295.5    , 295.1    ],
              [296.29   , 297.19998, ..., 296.4    , 296.6    ]],
      
             ...,
      
             [[245.79   , 244.79   , ..., 243.98999, 244.79   ],
              [249.89   , 249.29   , ..., 242.48999, 244.29   ],
              ...,
              [296.29   , 297.19   , ..., 295.09   , 294.38998],
              [297.79   , 298.38998, ..., 295.49   , 295.19   ]],
      
             [[245.09   , 244.29   , ..., 241.48999, 241.79   ],
              [249.89   , 249.29   , ..., 240.29   , 241.68999],
              ...,
              [296.09   , 296.88998, ..., 295.69   , 295.19   ],
              [297.69   , 298.09   , ..., 296.19   , 295.69   ]]], dtype=float32)
    • celsius
      (time, lat, lon)
      float32
      -31.949997 -30.649994 ... 22.540009
      array([[[-31.949997, -30.649994, -29.649994, ..., -40.350006,
               -37.649994, -34.550003],
              [-29.350006, -28.649994, -28.449997, ..., -40.350006,
               -37.850006, -33.850006],
              [-23.149994, -23.350006, -24.259995, ..., -39.949997,
               -36.759995, -31.449997],
              ...,
              [ 23.450012,  23.049988,  23.25    , ...,  22.25    ,
                21.950012,  21.549988],
              [ 22.75    ,  23.049988,  23.640015, ...,  22.75    ,
                22.75    ,  22.049988],
              [ 23.140015,  23.640015,  23.950012, ...,  23.75    ,
                23.640015,  23.450012]],
      
             [[-31.050003, -30.449997, -30.050003, ..., -41.149994,
               -39.550003, -37.350006],
              [-29.550003, -29.050003, -28.949997, ..., -42.149994,
               -40.649994, -37.449997],
              [-19.949997, -20.259995, -21.050003, ..., -42.350006,
               -39.759995, -34.649994],
              ...,
              [ 23.25    ,  22.75    ,  23.049988, ...,  22.25    ,
                21.950012,  21.640015],
              [ 23.049988,  23.549988,  23.640015, ...,  22.450012,
                22.350006,  21.950012],
              [ 23.140015,  24.049988,  24.25    , ...,  23.25    ,
                23.25    ,  23.450012]],
      
             [[-30.850006, -30.949997, -30.850006, ..., -38.850006,
               -37.050003, -34.449997],
              [-28.550003, -28.759995, -29.149994, ..., -42.850006,
               -41.149994, -37.449997],
              [-16.950012, -17.649994, -18.949997, ..., -41.949997,
               -39.949997, -34.949997],
              ...,
              [ 22.450012,  22.25    ,  22.25    , ...,  23.140015,
                22.140015,  21.850006],
              [ 23.049988,  23.350006,  23.140015, ...,  23.25    ,
                22.850006,  22.450012],
              [ 23.25    ,  23.140015,  23.25    , ...,  23.850006,
                23.850006,  23.640015]],
      
             ...,
      
             [[-29.660004, -30.160004, -31.059998, ..., -28.960007,
               -28.660004, -28.259995],
              [-24.059998, -24.160004, -24.559998, ..., -32.559998,
               -31.86    , -30.460007],
              [-10.459991, -10.959991, -11.459991, ..., -33.759995,
               -31.460007, -27.960007],
              ...,
              [ 21.640015,  22.140015,  24.339996, ...,  22.339996,
                22.23999 ,  21.540009],
              [ 23.640015,  24.73999 ,  25.140015, ...,  22.339996,
                22.339996,  21.640015],
              [ 25.040009,  26.040009,  25.640015, ...,  22.940002,
                22.640015,  22.640015]],
      
             [[-27.36    , -28.36    , -29.660004, ..., -29.86    ,
               -29.160004, -28.36    ],
              [-23.259995, -23.86    , -24.660004, ..., -31.86    ,
               -30.660004, -28.86    ],
              [-10.76001 , -11.359985, -11.859985, ..., -32.660004,
               -30.059998, -26.259995],
              ...,
              [ 20.540009,  20.73999 ,  22.23999 , ...,  21.940002,
                21.540009,  21.140015],
              [ 23.140015,  24.040009,  24.440002, ...,  22.140015,
                21.940002,  21.23999 ],
              [ 24.640015,  25.23999 ,  25.339996, ...,  22.540009,
                22.339996,  22.040009]],
      
             [[-28.059998, -28.86    , -29.86    , ..., -31.460007,
               -31.660004, -31.36    ],
              [-23.259995, -23.86    , -24.759995, ..., -33.559998,
               -32.86    , -31.460007],
              [-10.160004, -10.959991, -11.76001 , ..., -33.259995,
               -30.559998, -26.86    ],
              ...,
              [ 20.640015,  20.540009,  21.940002, ...,  22.140015,
                21.940002,  21.540009],
              [ 22.940002,  23.73999 ,  24.040009, ...,  22.540009,
                22.540009,  22.040009],
              [ 24.540009,  24.940002,  24.940002, ...,  23.339996,
                23.040009,  22.540009]]], dtype=float32)
    • slice
      (lat, lon)
      float32
      241.2 242.5 243.5 ... 296.79 296.6
      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([[241.2    , 242.5    , 243.5    , ..., 232.79999, 235.5    , 238.59999],
             [243.79999, 244.5    , 244.7    , ..., 232.79999, 235.29999, 239.29999],
             [250.     , 249.79999, 248.89   , ..., 233.2    , 236.39   , 241.7    ],
             ...,
             [296.6    , 296.19998, 296.4    , ..., 295.4    , 295.1    , 294.69998],
             [295.9    , 296.19998, 296.79   , ..., 295.9    , 295.9    , 295.19998],
             [296.29   , 296.79   , 297.1    , ..., 296.9    , 296.79   , 296.6    ]],
            dtype=float32)
  • 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

Build regridder

[4]:
ds_out = xr.Dataset(
    {
        "lat": (["lat"], np.arange(16, 75, 1.0)),
        "lon": (["lon"], np.arange(200, 330, 1.5)),
    }
)

regridder = xe.Regridder(ds, ds_out, "bilinear")
regridder
[4]:
xESMF Regridder
Regridding algorithm:       bilinear
Input grid shape:           (25, 53)
Output grid shape:          (59, 87)
Output grid dimension name: ('lat', 'lon')
Periodic in longitude?      False

Apply to data

[5]:
# the entire dataset can be processed at once
ds_out = regridder(ds)
ds_out
using dimensions ('lat', 'lon') from data variable air as the horizontal dimensions for this dataset.
[5]:
Show/Hide data repr Show/Hide attributes
xarray.Dataset
    • lat: 59
    • lon: 87
    • time: 2920
    • 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]')
    • lon
      (lon)
      float64
      200.0 201.5 203.0 ... 327.5 329.0
      array([200. , 201.5, 203. , 204.5, 206. , 207.5, 209. , 210.5, 212. , 213.5,
             215. , 216.5, 218. , 219.5, 221. , 222.5, 224. , 225.5, 227. , 228.5,
             230. , 231.5, 233. , 234.5, 236. , 237.5, 239. , 240.5, 242. , 243.5,
             245. , 246.5, 248. , 249.5, 251. , 252.5, 254. , 255.5, 257. , 258.5,
             260. , 261.5, 263. , 264.5, 266. , 267.5, 269. , 270.5, 272. , 273.5,
             275. , 276.5, 278. , 279.5, 281. , 282.5, 284. , 285.5, 287. , 288.5,
             290. , 291.5, 293. , 294.5, 296. , 297.5, 299. , 300.5, 302. , 303.5,
             305. , 306.5, 308. , 309.5, 311. , 312.5, 314. , 315.5, 317. , 318.5,
             320. , 321.5, 323. , 324.5, 326. , 327.5, 329. ])
    • lat
      (lat)
      float64
      16.0 17.0 18.0 ... 72.0 73.0 74.0
      array([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.])
    • air
      (time, lat, lon)
      float64
      296.1 296.4 296.6 ... 241.0 241.5
      array([[[296.13399675, 296.38669304, 296.63889823, ..., 296.47490793,
               296.43398913, 296.19924566],
              [295.97800871, 296.18274797, 296.42534501, ..., 296.09262341,
               296.07802394, 295.72098714],
              [296.04001766, 296.13556275, 296.30247974, ..., 295.77692914,
               295.73997197, 295.35693248],
              ...,
              [245.04017912, 245.36087049, 245.56096188, ..., 233.93629106,
               235.51802332, 238.0780694 ],
              [243.27991042, 243.77519503, 244.17375053, ..., 233.81591274,
               235.33999633, 237.63241841],
              [242.24003289, 242.87912303, 243.43775032, ..., 233.84791841,
               235.41999207, 237.49641598]],
      
             [[296.25399643, 296.70203773, 297.03166485, ..., 296.06514956,
               296.03998263, 296.01773136],
              [296.2179898 , 296.56767711, 296.82291528, ..., 295.7292558 ,
               295.6800262 , 295.5138904 ],
              [296.23999022, 296.42058286, 296.56714652, ..., 295.50442291,
               295.41998903, 295.19133215],
              ...,
              [245.52028453, 245.73709231, 245.85148963, ..., 231.64759509,
               232.67802699, 234.83033953],
              [243.29994515, 243.61404829, 243.85326489, ..., 231.80653129,
               232.72003168, 234.51923375],
              [242.70001369, 243.03800427, 243.31726258, ..., 232.22256285,
               233.15997775, 234.71925176]],
      
             [[296.31998597, 296.35233477, 296.37027072, ..., 296.69703874,
               296.59998477, 296.42993717],
              [296.23999022, 296.37072264, 296.42865111, ..., 296.39312798,
               296.20003046, 295.98447426],
              [296.07996829, 296.20134835, 296.24744824, ..., 296.17051878,
               295.85798008, 295.63218076],
              ...,
              [246.92034241, 246.75294557, 246.50912779, ..., 231.18562131,
               232.24003595, 234.61904532],
              [244.13992017, 244.03040136, 243.89556811, ..., 231.78222568,
               232.82012307, 234.90301222],
              [243.22002405, 243.13672999, 243.05876072, ..., 233.39835074,
               234.45993206, 236.27912467]],
      
             ...,
      
             [[297.62998356, 298.25582152, 298.65503226, ..., 295.7786526 ,
               295.66999665, 295.50299763],
              [297.07004997, 297.7199817 , 298.19914665, ..., 295.58670885,
               295.55000304, 295.2150872 ],
              [296.38994762, 296.98154159, 297.52424514, ..., 295.48204978,
               295.46998597, 295.05016151],
              ...,
              [251.81041188, 251.72296686, 251.55990593, ..., 240.75713161,
               241.37000425, 242.46456685],
              [247.96982451, 247.87036819, 247.69574495, ..., 241.55307104,
               241.93009016, 242.64624471],
              [245.73007797, 245.53418764, 245.25570503, ..., 242.92917313,
               243.20994271, 243.68633428]],
      
             [[297.1899857 , 297.6237982 , 297.95503528, ..., 295.4505457 ,
               295.32998658, 295.05487915],
              [296.59005424, 297.09596253, 297.49915579, ..., 295.29059716,
               295.1700073 , 294.7989566 ],
              [295.76992812, 296.23054587, 296.65708274, ..., 295.15442138,
               295.00998537, 294.626334  ],
              ...,
              [252.39037715, 252.04962511, 251.65524335, ..., 241.72163807,
               242.61000973, 243.93278497],
              [249.06987326, 248.66822819, 248.21431545, ..., 242.12742803,
               242.79003593, 243.74867727],
              [247.43005818, 246.93209439, 246.37428385, ..., 242.84748108,
               243.38996739, 244.10871142]],
      
             [[297.04997563, 297.38785212, 297.63503348, ..., 296.09892817,
               295.98999483, 295.690696  ],
              [296.4100463 , 296.84401245, 297.17914422, ..., 295.82701626,
               295.79001767, 295.49075727],
              [295.62992871, 296.00626644, 296.35697279, ..., 295.59472609,
               295.56998294, 295.28282378],
              ...,
              [252.51039665, 252.14637887, 251.70761893, ..., 240.09173906,
               240.75006397, 241.87173824],
              [248.92985255, 248.55305942, 248.11071361, ..., 240.21550695,
               240.53002923, 241.23719787],
              [247.01007067, 246.58490681, 246.10268406, ..., 240.91155301,
               241.00997318, 241.45322238]]])
    • celsius
      (time, lat, lon)
      float64
      22.98 23.24 23.49 ... -32.14 -31.7
      array([[[ 22.98400285,  23.23669915,  23.48890434, ...,  23.32491403,
                23.28399523,  23.04925177],
              [ 22.82801481,  23.03275408,  23.27535111, ...,  22.94262952,
                22.92803004,  22.57099324],
              [ 22.89002377,  22.98556885,  23.15248584, ...,  22.62693524,
                22.58997807,  22.20693858],
              ...,
              [-28.10981478, -27.7891234 , -27.58903202, ..., -39.21370283,
               -37.63197058, -35.0719245 ],
              [-29.87008348, -29.37479887, -28.97624337, ..., -39.33408115,
               -37.80999757, -35.51757549],
              [-30.90996101, -30.27087087, -29.71224358, ..., -39.30207549,
               -37.73000183, -35.65357792]],
      
             [[ 23.10400254,  23.55204383,  23.88167095, ...,  22.91515567,
                22.88998873,  22.86773746],
              [ 23.06799591,  23.41768321,  23.67292138, ...,  22.5792619 ,
                22.5300323 ,  22.3638965 ],
              [ 23.08999633,  23.27058897,  23.41715262, ...,  22.35442901,
                22.26999514,  22.04133825],
              ...,
              [-27.62970937, -27.41290159, -27.29850427, ..., -41.50239881,
               -40.4719669 , -38.31965437],
              [-29.85004875, -29.5359456 , -29.29672901, ..., -41.3434626 ,
               -40.42996222, -38.63076015],
              [-30.4499802 , -30.11198963, -29.83273132, ..., -40.92743105,
               -39.99001614, -38.43074214]],
      
             [[ 23.16999207,  23.20234088,  23.22027682, ...,  23.54704484,
                23.44999087,  23.27994327],
              [ 23.08999633,  23.22072874,  23.27865721, ...,  23.24313408,
                23.05003657,  22.83448036],
              [ 22.9299744 ,  23.05135446,  23.09745435, ...,  23.02052488,
                22.70798618,  22.48218686],
              ...,
              [-26.22965149, -26.39704832, -26.64086611, ..., -41.96437258,
               -40.90995795, -38.53094857],
              [-29.01007373, -29.11959253, -29.25442578, ..., -41.36776822,
               -40.32987082, -38.24698168],
              [-29.92996985, -30.0132639 , -30.09123317, ..., -39.75164316,
               -38.69006184, -36.87086923]],
      
             ...,
      
             [[ 24.47998966,  25.10582762,  25.50503836, ...,  22.6286587 ,
                22.52000275,  22.35300373],
              [ 23.92005608,  24.56998781,  25.04915275, ...,  22.43671496,
                22.40000914,  22.0650933 ],
              [ 23.23995372,  23.83154769,  24.37425124, ...,  22.33205589,
                22.31999207,  21.90016761],
              ...,
              [-21.33958202, -21.42702704, -21.59008797, ..., -32.39286229,
               -31.77998965, -30.68542705],
              [-25.18016938, -25.27962571, -25.45424895, ..., -31.59692286,
               -31.21990373, -30.50374918],
              [-27.41991592, -27.61580626, -27.89428887, ..., -30.22082077,
               -29.94005118, -29.46365962]],
      
             [[ 24.0399918 ,  24.4738043 ,  24.80504138, ...,  22.3005518 ,
                22.17999269,  21.90488526],
              [ 23.44006035,  23.94596863,  24.34916189, ...,  22.14060326,
                22.02001341,  21.64896271],
              [ 22.61993422,  23.08055197,  23.50708884, ...,  22.00442749,
                21.85999148,  21.4763401 ],
              ...,
              [-20.75961675, -21.10036879, -21.49475055, ..., -31.42835583,
               -30.53998416, -29.21720893],
              [-24.08012063, -24.48176571, -24.93567845, ..., -31.02256587,
               -30.35995796, -29.40131662],
              [-25.71993572, -26.21789951, -26.77571005, ..., -30.30251281,
               -29.76002651, -29.04128248]],
      
             [[ 23.89998173,  24.23785823,  24.48503958, ...,  22.94893427,
                22.84000093,  22.5407021 ],
              [ 23.26005241,  23.69401855,  24.02915032, ...,  22.67702236,
                22.64002378,  22.34076337],
              [ 22.47993481,  22.85627254,  23.20697889, ...,  22.44473219,
                22.41998905,  22.13282989],
              ...,
              [-20.63959725, -21.00361502, -21.44237497, ..., -33.05825483,
               -32.39992993, -31.27825565],
              [-24.22014135, -24.59693448, -25.03928029, ..., -32.93448695,
               -32.61996466, -31.91279602],
              [-26.13992323, -26.56508709, -27.04730983, ..., -32.23844089,
               -32.14002072, -31.69677152]]])
    • slice
      (lat, lon)
      float64
      296.1 296.4 296.6 ... 235.4 237.5
      array([[296.13399675, 296.38669304, 296.63889823, ..., 296.47490793,
              296.43398913, 296.19924566],
             [295.97800871, 296.18274797, 296.42534501, ..., 296.09262341,
              296.07802394, 295.72098714],
             [296.04001766, 296.13556275, 296.30247974, ..., 295.77692914,
              295.73997197, 295.35693248],
             ...,
             [245.04017912, 245.36087049, 245.56096188, ..., 233.93629106,
              235.51802332, 238.0780694 ],
             [243.27991042, 243.77519503, 244.17375053, ..., 233.81591274,
              235.33999633, 237.63241841],
             [242.24003289, 242.87912303, 243.43775032, ..., 233.84791841,
              235.41999207, 237.49641598]])
  • regrid_method :
    bilinear
[6]:
# verify that the result is the same as regridding each variable one-by-one
for k in ds.data_vars:
    print(k, ds_out[k].equals(regridder(ds[k])))
air True
celsius True
slice True

Invalid dimension orderings to avoid

xESMF assumes the horizontal dimensions are the last/rightmost dimensions, which matches the convention of most NetCDF data.

[7]:
# xESMF doesn't like horizontal dimensions to be the first/leftmost dimensions
ds_bad = ds.copy()
ds_bad["air"] = ds_bad["air"].transpose()
ds_bad
[7]:
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
      (lon, lat, time)
      float32
      241.2 242.09999 ... 295.19 295.69
      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([[[241.2    , 242.09999, 242.29999, ..., 243.48999, 245.79   ,
               245.09   ],
              [243.79999, 243.59999, 244.59999, ..., 249.09   , 249.89   ,
               249.89   ],
              [250.     , 253.2    , 256.19998, ..., 262.69   , 262.38998,
               262.99   ],
              ...,
              [296.6    , 296.4    , 295.6    , ..., 294.79   , 293.69   ,
               293.79   ],
              [295.9    , 296.19998, 296.19998, ..., 296.79   , 296.29   ,
               296.09   ],
              [296.29   , 296.29   , 296.4    , ..., 298.19   , 297.79   ,
               297.69   ]],
      
             [[242.5    , 242.7    , 242.2    , ..., 242.98999, 244.79   ,
               244.29   ],
              [244.5    , 244.09999, 244.39   , ..., 248.98999, 249.29   ,
               249.29   ],
              [249.79999, 252.89   , 255.5    , ..., 262.19   , 261.79   ,
               262.19   ],
              ...,
              [296.19998, 295.9    , 295.4    , ..., 295.29   , 293.88998,
               293.69   ],
              [296.19998, 296.69998, 296.5    , ..., 297.88998, 297.19   ,
               296.88998],
              [296.79   , 297.19998, 296.29   , ..., 299.19   , 298.38998,
               298.09   ]],
      
             [[243.5    , 243.09999, 242.29999, ..., 242.09   , 243.48999,
               243.29   ],
              [244.7    , 244.2    , 244.     , ..., 248.59   , 248.48999,
               248.39   ],
              [248.89   , 252.09999, 254.2    , ..., 261.69   , 261.29   ,
               261.38998],
              ...,
              [296.4    , 296.19998, 295.4    , ..., 297.49   , 295.38998,
               295.09   ],
              [296.79   , 296.79   , 296.29   , ..., 298.29   , 297.59   ,
               297.19   ],
              [297.1    , 297.4    , 296.4    , ..., 298.79   , 298.49   ,
               298.09   ]],
      
             ...,
      
             [[232.79999, 232.     , 234.29999, ..., 244.18999, 243.29   ,
               241.68999],
              [232.79999, 231.     , 230.29999, ..., 240.59   , 241.29   ,
               239.59   ],
              [233.2    , 230.79999, 231.2    , ..., 239.39   , 240.48999,
               239.89   ],
              ...,
              [295.4    , 295.4    , 296.29   , ..., 295.49   , 295.09   ,
               295.29   ],
              [295.9    , 295.6    , 296.4    , ..., 295.49   , 295.29   ,
               295.69   ],
              [296.9    , 296.4    , 297.     , ..., 296.09   , 295.69   ,
               296.49   ]],
      
             [[235.5    , 233.59999, 236.09999, ..., 244.48999, 243.98999,
               241.48999],
              [235.29999, 232.5    , 232.     , ..., 241.29   , 242.48999,
               240.29   ],
              [236.39   , 233.39   , 233.2    , ..., 241.68999, 243.09   ,
               242.59   ],
              ...,
              [295.1    , 295.1    , 295.29   , ..., 295.38998, 294.69   ,
               295.09   ],
              [295.9    , 295.5    , 296.     , ..., 295.49   , 295.09   ,
               295.69   ],
              [296.79   , 296.4    , 297.     , ..., 295.79   , 295.49   ,
               296.19   ]],
      
             [[238.59999, 235.79999, 238.7    , ..., 244.89   , 244.79   ,
               241.79   ],
              [239.29999, 235.7    , 235.7    , ..., 242.68999, 244.29   ,
               241.68999],
              [241.7    , 238.5    , 238.2    , ..., 245.18999, 246.89   ,
               246.29   ],
              ...,
              [294.69998, 294.79   , 295.     , ..., 294.69   , 294.29   ,
               294.69   ],
              [295.19998, 295.1    , 295.6    , ..., 294.79   , 294.38998,
               295.19   ],
              [296.6    , 296.6    , 296.79   , ..., 295.79   , 295.19   ,
               295.69   ]]], dtype=float32)
    • celsius
      (time, lat, lon)
      float32
      -31.949997 -30.649994 ... 22.540009
      array([[[-31.949997, -30.649994, -29.649994, ..., -40.350006,
               -37.649994, -34.550003],
              [-29.350006, -28.649994, -28.449997, ..., -40.350006,
               -37.850006, -33.850006],
              [-23.149994, -23.350006, -24.259995, ..., -39.949997,
               -36.759995, -31.449997],
              ...,
              [ 23.450012,  23.049988,  23.25    , ...,  22.25    ,
                21.950012,  21.549988],
              [ 22.75    ,  23.049988,  23.640015, ...,  22.75    ,
                22.75    ,  22.049988],
              [ 23.140015,  23.640015,  23.950012, ...,  23.75    ,
                23.640015,  23.450012]],
      
             [[-31.050003, -30.449997, -30.050003, ..., -41.149994,
               -39.550003, -37.350006],
              [-29.550003, -29.050003, -28.949997, ..., -42.149994,
               -40.649994, -37.449997],
              [-19.949997, -20.259995, -21.050003, ..., -42.350006,
               -39.759995, -34.649994],
              ...,
              [ 23.25    ,  22.75    ,  23.049988, ...,  22.25    ,
                21.950012,  21.640015],
              [ 23.049988,  23.549988,  23.640015, ...,  22.450012,
                22.350006,  21.950012],
              [ 23.140015,  24.049988,  24.25    , ...,  23.25    ,
                23.25    ,  23.450012]],
      
             [[-30.850006, -30.949997, -30.850006, ..., -38.850006,
               -37.050003, -34.449997],
              [-28.550003, -28.759995, -29.149994, ..., -42.850006,
               -41.149994, -37.449997],
              [-16.950012, -17.649994, -18.949997, ..., -41.949997,
               -39.949997, -34.949997],
              ...,
              [ 22.450012,  22.25    ,  22.25    , ...,  23.140015,
                22.140015,  21.850006],
              [ 23.049988,  23.350006,  23.140015, ...,  23.25    ,
                22.850006,  22.450012],
              [ 23.25    ,  23.140015,  23.25    , ...,  23.850006,
                23.850006,  23.640015]],
      
             ...,
      
             [[-29.660004, -30.160004, -31.059998, ..., -28.960007,
               -28.660004, -28.259995],
              [-24.059998, -24.160004, -24.559998, ..., -32.559998,
               -31.86    , -30.460007],
              [-10.459991, -10.959991, -11.459991, ..., -33.759995,
               -31.460007, -27.960007],
              ...,
              [ 21.640015,  22.140015,  24.339996, ...,  22.339996,
                22.23999 ,  21.540009],
              [ 23.640015,  24.73999 ,  25.140015, ...,  22.339996,
                22.339996,  21.640015],
              [ 25.040009,  26.040009,  25.640015, ...,  22.940002,
                22.640015,  22.640015]],
      
             [[-27.36    , -28.36    , -29.660004, ..., -29.86    ,
               -29.160004, -28.36    ],
              [-23.259995, -23.86    , -24.660004, ..., -31.86    ,
               -30.660004, -28.86    ],
              [-10.76001 , -11.359985, -11.859985, ..., -32.660004,
               -30.059998, -26.259995],
              ...,
              [ 20.540009,  20.73999 ,  22.23999 , ...,  21.940002,
                21.540009,  21.140015],
              [ 23.140015,  24.040009,  24.440002, ...,  22.140015,
                21.940002,  21.23999 ],
              [ 24.640015,  25.23999 ,  25.339996, ...,  22.540009,
                22.339996,  22.040009]],
      
             [[-28.059998, -28.86    , -29.86    , ..., -31.460007,
               -31.660004, -31.36    ],
              [-23.259995, -23.86    , -24.759995, ..., -33.559998,
               -32.86    , -31.460007],
              [-10.160004, -10.959991, -11.76001 , ..., -33.259995,
               -30.559998, -26.86    ],
              ...,
              [ 20.640015,  20.540009,  21.940002, ...,  22.140015,
                21.940002,  21.540009],
              [ 22.940002,  23.73999 ,  24.040009, ...,  22.540009,
                22.540009,  22.040009],
              [ 24.540009,  24.940002,  24.940002, ...,  23.339996,
                23.040009,  22.540009]]], dtype=float32)
    • slice
      (lat, lon)
      float32
      241.2 242.5 243.5 ... 296.79 296.6
      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([[241.2    , 242.5    , 243.5    , ..., 232.79999, 235.5    , 238.59999],
             [243.79999, 244.5    , 244.7    , ..., 232.79999, 235.29999, 239.29999],
             [250.     , 249.79999, 248.89   , ..., 233.2    , 236.39   , 241.7    ],
             ...,
             [296.6    , 296.19998, 296.4    , ..., 295.4    , 295.1    , 294.69998],
             [295.9    , 296.19998, 296.79   , ..., 295.9    , 295.9    , 295.19998],
             [296.29   , 296.79   , 297.1    , ..., 296.9    , 296.79   , 296.6    ]],
            dtype=float32)
  • 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
[8]:
# regridder(ds_bad)  # comment this line to see the error message
[9]:
# besides ordering dimensions properly, another simple fix is to drop bad variables
regridder(ds_bad.drop("air"))
using dimensions ('lat', 'lon') from data variable celsius as the horizontal dimensions for this dataset.
[9]:
Show/Hide data repr Show/Hide attributes
xarray.Dataset
    • lat: 59
    • lon: 87
    • time: 2920
    • 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]')
    • lon
      (lon)
      float64
      200.0 201.5 203.0 ... 327.5 329.0
      array([200. , 201.5, 203. , 204.5, 206. , 207.5, 209. , 210.5, 212. , 213.5,
             215. , 216.5, 218. , 219.5, 221. , 222.5, 224. , 225.5, 227. , 228.5,
             230. , 231.5, 233. , 234.5, 236. , 237.5, 239. , 240.5, 242. , 243.5,
             245. , 246.5, 248. , 249.5, 251. , 252.5, 254. , 255.5, 257. , 258.5,
             260. , 261.5, 263. , 264.5, 266. , 267.5, 269. , 270.5, 272. , 273.5,
             275. , 276.5, 278. , 279.5, 281. , 282.5, 284. , 285.5, 287. , 288.5,
             290. , 291.5, 293. , 294.5, 296. , 297.5, 299. , 300.5, 302. , 303.5,
             305. , 306.5, 308. , 309.5, 311. , 312.5, 314. , 315.5, 317. , 318.5,
             320. , 321.5, 323. , 324.5, 326. , 327.5, 329. ])
    • lat
      (lat)
      float64
      16.0 17.0 18.0 ... 72.0 73.0 74.0
      array([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.])
    • celsius
      (time, lat, lon)
      float64
      22.98 23.24 23.49 ... -32.14 -31.7
      array([[[ 22.98400285,  23.23669915,  23.48890434, ...,  23.32491403,
                23.28399523,  23.04925177],
              [ 22.82801481,  23.03275408,  23.27535111, ...,  22.94262952,
                22.92803004,  22.57099324],
              [ 22.89002377,  22.98556885,  23.15248584, ...,  22.62693524,
                22.58997807,  22.20693858],
              ...,
              [-28.10981478, -27.7891234 , -27.58903202, ..., -39.21370283,
               -37.63197058, -35.0719245 ],
              [-29.87008348, -29.37479887, -28.97624337, ..., -39.33408115,
               -37.80999757, -35.51757549],
              [-30.90996101, -30.27087087, -29.71224358, ..., -39.30207549,
               -37.73000183, -35.65357792]],
      
             [[ 23.10400254,  23.55204383,  23.88167095, ...,  22.91515567,
                22.88998873,  22.86773746],
              [ 23.06799591,  23.41768321,  23.67292138, ...,  22.5792619 ,
                22.5300323 ,  22.3638965 ],
              [ 23.08999633,  23.27058897,  23.41715262, ...,  22.35442901,
                22.26999514,  22.04133825],
              ...,
              [-27.62970937, -27.41290159, -27.29850427, ..., -41.50239881,
               -40.4719669 , -38.31965437],
              [-29.85004875, -29.5359456 , -29.29672901, ..., -41.3434626 ,
               -40.42996222, -38.63076015],
              [-30.4499802 , -30.11198963, -29.83273132, ..., -40.92743105,
               -39.99001614, -38.43074214]],
      
             [[ 23.16999207,  23.20234088,  23.22027682, ...,  23.54704484,
                23.44999087,  23.27994327],
              [ 23.08999633,  23.22072874,  23.27865721, ...,  23.24313408,
                23.05003657,  22.83448036],
              [ 22.9299744 ,  23.05135446,  23.09745435, ...,  23.02052488,
                22.70798618,  22.48218686],
              ...,
              [-26.22965149, -26.39704832, -26.64086611, ..., -41.96437258,
               -40.90995795, -38.53094857],
              [-29.01007373, -29.11959253, -29.25442578, ..., -41.36776822,
               -40.32987082, -38.24698168],
              [-29.92996985, -30.0132639 , -30.09123317, ..., -39.75164316,
               -38.69006184, -36.87086923]],
      
             ...,
      
             [[ 24.47998966,  25.10582762,  25.50503836, ...,  22.6286587 ,
                22.52000275,  22.35300373],
              [ 23.92005608,  24.56998781,  25.04915275, ...,  22.43671496,
                22.40000914,  22.0650933 ],
              [ 23.23995372,  23.83154769,  24.37425124, ...,  22.33205589,
                22.31999207,  21.90016761],
              ...,
              [-21.33958202, -21.42702704, -21.59008797, ..., -32.39286229,
               -31.77998965, -30.68542705],
              [-25.18016938, -25.27962571, -25.45424895, ..., -31.59692286,
               -31.21990373, -30.50374918],
              [-27.41991592, -27.61580626, -27.89428887, ..., -30.22082077,
               -29.94005118, -29.46365962]],
      
             [[ 24.0399918 ,  24.4738043 ,  24.80504138, ...,  22.3005518 ,
                22.17999269,  21.90488526],
              [ 23.44006035,  23.94596863,  24.34916189, ...,  22.14060326,
                22.02001341,  21.64896271],
              [ 22.61993422,  23.08055197,  23.50708884, ...,  22.00442749,
                21.85999148,  21.4763401 ],
              ...,
              [-20.75961675, -21.10036879, -21.49475055, ..., -31.42835583,
               -30.53998416, -29.21720893],
              [-24.08012063, -24.48176571, -24.93567845, ..., -31.02256587,
               -30.35995796, -29.40131662],
              [-25.71993572, -26.21789951, -26.77571005, ..., -30.30251281,
               -29.76002651, -29.04128248]],
      
             [[ 23.89998173,  24.23785823,  24.48503958, ...,  22.94893427,
                22.84000093,  22.5407021 ],
              [ 23.26005241,  23.69401855,  24.02915032, ...,  22.67702236,
                22.64002378,  22.34076337],
              [ 22.47993481,  22.85627254,  23.20697889, ...,  22.44473219,
                22.41998905,  22.13282989],
              ...,
              [-20.63959725, -21.00361502, -21.44237497, ..., -33.05825483,
               -32.39992993, -31.27825565],
              [-24.22014135, -24.59693448, -25.03928029, ..., -32.93448695,
               -32.61996466, -31.91279602],
              [-26.13992323, -26.56508709, -27.04730983, ..., -32.23844089,
               -32.14002072, -31.69677152]]])
    • slice
      (lat, lon)
      float64
      296.1 296.4 296.6 ... 235.4 237.5
      array([[296.13399675, 296.38669304, 296.63889823, ..., 296.47490793,
              296.43398913, 296.19924566],
             [295.97800871, 296.18274797, 296.42534501, ..., 296.09262341,
              296.07802394, 295.72098714],
             [296.04001766, 296.13556275, 296.30247974, ..., 295.77692914,
              295.73997197, 295.35693248],
             ...,
             [245.04017912, 245.36087049, 245.56096188, ..., 233.93629106,
              235.51802332, 238.0780694 ],
             [243.27991042, 243.77519503, 244.17375053, ..., 233.81591274,
              235.33999633, 237.63241841],
             [242.24003289, 242.87912303, 243.43775032, ..., 233.84791841,
              235.41999207, 237.49641598]])
  • regrid_method :
    bilinear