0
votes

So I have an Xarray dataset, ds, with 3 variables in it: (example data)

Data variables:
    CO2      (time, data) float32 400.0 400.0 ... 400.0
    ...

Where the data dimension is a 1D array, for which I have 1D arrays of matching length containing latitude and longitude for each entry in data. The latitudes and longitudes are not sampled regularly. Ideally I would add the lat and lon so it showed up like this:

Data variables:
    CO2      (time, data, lat, lon) float32 400.0 400.0 ... 400.0
    ...

How can I add the lat/lon as a dimension so that I can interpolate along it using the Xarray interp function? (or is there some other, better way to interpolate this data?)

Eg: ds_interp = ds.interp(time=dt, lat=dlat, lon=dlon, assume_sorted=False)

1

1 Answers

0
votes

In the xarray documentation, at the bottom of this section, you can see a note saying the interpolation only works over regular grids. I will have to either grid the data and interpolate it, which I was hoping to avoid, or interpolate it as numpy arrays manually with scipy.interpolate, which supports irregular grids.