二维数组中的纬度/经度索引

问题描述 投票:0回答:1

我有一个

.nc
文件,其中纬度和经度位于二维数组中。我想提取某些已知点的值。我没有找到找到已知点索引的方法。

数据结构如下:

OrderedDict([(u'lon', <type 'netCDF4._netCDF4.Variable'>
              float32 lon(y, x)
                  standard_name: longitude
                  long_name: longitude
                  units: degrees_east
                  _CoordinateAxisType: Lon
              unlimited dimensions: 
              current shape = (146, 209)
              filling off), (u'lat', <type 'netCDF4._netCDF4.Variable'>
              float32 lat(y, x)
                  standard_name: latitude
                  long_name: latitude
                  units: degrees_north
                  _CoordinateAxisType: Lat
              unlimited dimensions: 
              current shape = (146, 209)
              filling off), (u'time', <type 'netCDF4._netCDF4.Variable'>
              float64 time(time)
                  standard_name: time
                  units: seconds since 1949-12-1 00:00:00
                  calendar: proleptic_gregorian
                  axis: T
              unlimited dimensions: time
              current shape = (55152,)
              filling off), (u'TOT_PREC', <type 'netCDF4._netCDF4.Variable'>
              float32 TOT_PREC(time, y, x)
                  standard_name: precipitation_amount
                  long_name: total precipitation amount
                  units: kg m-2
                  coordinates: lat lon
                  cell_methods: time: sum
              unlimited dimensions: time
              current shape = (55152, 146, 209)
              filling off)])

假设我想提取坐标为:

lat=27.25
lon=85.75
的点的值,那么如何获取这些坐标的纬度和经度索引?

python netcdf python-xarray
1个回答
0
投票

首先,读取.nc文件和里面的变量

ds1 = NetCDFFile('file.nc')
ds2 = ...

lon = ds.variables['lon'][:]
lat = ds.variables['lat'][:]

然后使用 'for' 循环 {}{}{} lat,lon,data 写入文件 然后你就可以轻松读取数据了。 希望这是有道理的。

© www.soinside.com 2019 - 2024. All rights reserved.