0

I am currently working with netcdf files. I want to plot a time series for a certain location. So far I used:

ds = xr.open_dataset('testing.nc')
lon_name = "lon"
lat_name = "lat"
time_name = "time"
point1 = {'x': 8.807176, 'y': 53.913996}

# Gets the closest point to the coordinates
df = ds.sel(lat=point1['y'], lon=point1['x'], method='nearest').to_dataframe()

This works fine, but now I got a dataset that uses two dimensional coordinates. Using info() gives me this:

xarray.Dataset {
dimensions:
    ny = 536 ;
    nx = 532 ;
variables:
    datetime64[ns] time() ;
        time:standard_name = time ;
    float32 lat(ny, nx) ;
        lat:units = degrees_north ;
        lat:long_name = latitude ;
        lat:standard_name = latitude ;
    float32 lon(ny, nx) ;
        lon:units = degrees_east ;
        lon:long_name = longitude ;
        lon:standard_name = longitude ;

So how do I extract my data now in the easiest way? Using my code from above gives me "KeyError: 'no index found for coordinate lat'". The coordinates I chose are inside the boundaries of the data. I assume that the problem is that the coordinates are two dimensional now.

AkariYukari
  • 338
  • 4
  • 16

1 Answers1

0

Just saw that this was already asked somewhere else (which I didn't find before): xarray select nearest lat/lon with multi-dimension coordinates

AkariYukari
  • 338
  • 4
  • 16