当纬度和经度是数据集坐标的函数时,如何找到最近的网格点?
我有一个网格温度数据的NetCDF文件,还有一个天气站的CSV。我正在尝试找到最接近气象站的网格点。我遇到的问题是NetCDF文件的纬度和经度是X和Y值的函数。 过去,这是我为找到最近的网格点所做的:
#import libraries
import os
import matplotlib.pyplot as plt
from netCDF4 import Dataset as netcdf_dataset
import numpy as np
import xarray as xr
import pandas as pd
#open netcdf file of gridded temperature
df=xr.open_dataset('/home/mmartin/LauNath/air.2m.2015.nc')
#open csv of weather stations
CMStations=pd.read_csv('Slope95.csv')
#Pull out variables
StationList=CMStations.station
City=CMStations.city
Lat=CMStations.lat
Lon=CMStations.lon
#find nearest grid points
NearGrid=df.sel(lat=Lat.to_xarray(), lon=Lon.to_xarray(), method='nearest')
这当然不起作用: 'ValueError:尺寸或多指数级别['lat','lon'不存在', 但是我不确定如何修改它。如何将此方法与此嵌套的NetCDF文件一起使用?
I have a netcdf file of gridded temperature data, and a csv of weather stations. I am trying to find the grid points that are closest to the weather stations. The problem I'm having is that the latitude and longitude of the netcdf file are functions of x and y values.
In the past this is what I've done to find nearest grid points:
#import libraries
import os
import matplotlib.pyplot as plt
from netCDF4 import Dataset as netcdf_dataset
import numpy as np
import xarray as xr
import pandas as pd
#open netcdf file of gridded temperature
df=xr.open_dataset('/home/mmartin/LauNath/air.2m.2015.nc')
#open csv of weather stations
CMStations=pd.read_csv('Slope95.csv')
#Pull out variables
StationList=CMStations.station
City=CMStations.city
Lat=CMStations.lat
Lon=CMStations.lon
#find nearest grid points
NearGrid=df.sel(lat=Lat.to_xarray(), lon=Lon.to_xarray(), method='nearest')
This of course doesn't work:
'ValueError: dimensions or multi-index levels ['lat', 'lon'] do not exist',
but I am unsure how to modify it. How can I use this method with this nested netcdf file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论