1

Look at this NetCDF EURO-CORDEX file:

<xarray.Dataset>
Dimensions:       (bnds: 2, rlat: 412, rlon: 424, time: 1800)
Coordinates:
    lat           (rlat, rlon) float64 ...
    lon           (rlat, rlon) float64 ...
  * rlat          (rlat) float64 -23.38 -23.26 -23.16 ... 21.61 21.73 21.83
  * rlon          (rlon) float64 -28.38 -28.26 -28.16 ... 17.93 18.05 18.16
  * time          (time) object 2011-01-01 12:00:00 ... 2015-12-30 12:00:00
Dimensions without coordinates: bnds
Data variables:
    pr            (time, rlat, rlon) float32 ...
    rotated_pole  |S1 ...
    time_bnds     (time, bnds) object ...

When I attempt to clip it using xarray (in Python script) or nco (in the command line) by lat and lon coordinates, it is presumably not working as lat and lon are not dimensions. I read these are rather coordinates not associated with any variable. How can I associate them or make them dimensions? Do the asterisks by the coordinates rlat and rlon suggest something I am missing?

Note I achieve clipping by xarray.Dataset.where, nevertheless I am rather interested with manipulating the dimensions/coordinates such that usual clipping operations would work. Thanks!

ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86
janchytry
  • 320
  • 2
  • 12

1 Answers1

2

You should be able to clip this using CDO:

sellonlatbox,lonmin,lonmax,latmin,latmax infile outfile

CDO will figure out the smallest possible rectangle in the original dataset that will contain the specified box. This seems to be a rotated polar grid, so you will not get some grid cells outside the box.

NCO will also work, but you will need to crop using rlon and rlat. So, you will need to select an appropriate rlon and rlat that will result in the desired lon and lat.

Robert Wilson
  • 3,192
  • 11
  • 19
  • Interesting, CDO is really smart on this one and this works! Thanks. Nevertheless, is there any possibility I could exchange `rlat` and `rlon` for `lat` and `lon`? – janchytry Feb 14 '21 at 20:15
  • If I understand you correctly what you want to do is regrid the data from a rotated polar grid to a regular latlon grid. "Exchanging" them will probably make your file non cf-compliant and liable to errors when processing – Robert Wilson Feb 16 '21 at 06:52
  • Well, `lan` / `lon` coordinates are xarray.dataArrays that already represent the regridded rotated polar grid. These have been included by the data producer. However, they are 2D arrays and obviously not suitable for becoming `dimension` – janchytry Feb 16 '21 at 10:49
  • I guess `rlat` / `rlon` were primarily meant to be dimension coordinates (as they are now) because they are 1D arrays. Each pixel from the climatic variable then gets a combination of `rlat` and `rlon` to be spatially determined (+ `time` of course as the third dimension) – janchytry Feb 16 '21 at 10:53