python - 二维数组中的纬度/经度索引
问题描述
我有一个.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
那么如何获取这些坐标的 lat 和 lon 索引。
任何帮助或建议将不胜感激!
解决方案
首先,您阅读 .nc 文件和里面的变量
ds1 = NetCDFFile('file.nc')
ds2 = ...
lon = ds.variables['lon'][:]
lat = ds.variables['lat'][:]
然后使用“for”循环 {}{}{} lat,lon,data 写入文件,然后您可以轻松读取数据。希望这有点道理。
推荐阅读
- powershell - “-split” - 从“-stream”输出?
- glassfish-4 - 启动 GlassFish 4.0 时无法找到或加载主类 Files.Microsoft
- oracle - 计算两个字段之间的日期
- mysql - 在 MySQL 中转换日期
- android - 我可以根据我的应用主题为我的应用中的所有 AppBarLayout 设置样式吗?
- sql-server - 尝试在 SSAS 多维数据集中使用连接,但它们似乎不起作用
- javascript - 在 javascript + D3/mapbox 中可视化大量数据的高效/高性能方式
- java - 为什么bucket4j中的计算先乘然后除?
- crystal-lang - 将动态类型传递到管道容器中
- javascript - 为什么当我在 Apache 上运行我的 react 构建时...只是出现空白页..?