8

I have a netCDF file with foll. structure:

<xarray.Dataset>
Dimensions:    (latitude: 94, longitude: 192, time: 366)
Coordinates:
  * longitude  (longitude) float32 -180.0 -178.125 -176.25 -174.375 -172.5 ...
  * latitude   (latitude) float32 88.5419 86.6532 84.7532 82.8508 80.9474 ...
  * time       (time) datetime64[ns] 2016-01-01 2016-01-02 2016-01-03 ...
Data variables:
    m2t      (time, latitude, longitude) float64 246.5 246.4 246.4 246.4
    pre      (time, latitude, longitude) float64 9.988e-08 9.988e-08 ...
Attributes:
    Conventions: CF-1.0

How do I extract values for a grid cell for a specific latitude and longitude (say 86.45, -156.25) and time (say 2016-01-10)? It is possible that the exact latitude/longitude value is not in the coordinates in which case we want the closest latitude/longitude value

I can extract value for a specific longitude like this:

_hndl_nc.sel(longitude=(_hndl_nc.longitude == -20))

However, since -20 is not present in coordinates for longitude, this does not work.

0

1 Answer 1

16

You are quite close although you don't have quite the right syntax yet:

_hndl_nc.sel(time='2016-01-10', longitude=-170.0, latitude=-20.0, method='nearest')

see also: Read multiple coordinates with xarray

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.