问题描述
我在 Python 中解析 netcdf 时遇到了困难,似乎有一个简单的解决方案,但我无法解决。
我试图使表面温度接近这个纬度/经度(57.13156000,18.21576000),尽管它在 netcdf 文件中用破折号(--)表示。我明白这是因为该点在陆地上,我如何找到数据存在的最近点?
我可以在寻找最近的纬度/经度之前以某种方式掩盖它吗?
我使用哥白尼的 netcdf 文件,20210720000000-DMI-L4_GHRSST-sstfnd-DMI_OI-NSEABALTIC-v02.0-fv01.0.nc
import os
import netCDF4
import numpy as np
year = datetime.datetime.today().year
month = datetime.datetime.today().strftime('%m')
day = datetime.datetime.today().strftime('%d')
def geo_idx(dd,dd_array):
geo_idx = (np.abs(dd_array - dd)).argmin()
return geo_idx
pathtonc = 'copernicus.nc'
nci = netCDF4.Dataset(pathtonc)
analysed_sst = nci.variables['analysed_sst']
#lat lng of beach
in_lat = 57.13156000
in_lon = 18.21576000
lats = nci.variables['lat'][:]
lons = nci.variables['lon'][:]
lat_idx = geo_idx(in_lat,lats)
lon_idx = geo_idx(in_lon,lons)
analysed_sst_temp = analysed_sst[:,lat_idx,lon_idx]
print (lats[lat_idx])
print (lons[lon_idx])
print(analysed_sst_temp-273.15)
输出:
57.14
18.22
[--]
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)