[英]Python - How to get variable from netcdf file on a specific location and at different level
I am learning on how to plot various variables from WRF output netcdf file. 我正在学习如何从WRF输出netcdf文件中绘制各种变量。 My requirement is to extract variables for a certain lat/lon (8.4875° N, 76.9525° E) in order to plot SkewT profiles using the matplotlib package. 我的要求是提取某个经度/纬度(8.4875°N,76.9525°E)的变量,以便使用matplotlib软件包绘制SkewT轮廓。
I found a similar question on this SO page netcdf4 extract for subset of lat lon . 我在此SO页面netcdf4提取物中找到了一个类似的问题, 即lat lon的子集 。 However, its location is a set of boundaries. 但是,它的位置是一组边界。
Check out xray . 查看X射线 。 You'll have to do some work to make the SkewT chart but accessing and summarizing the netCDF Dataset and variables will be pretty easy. 您需要做一些工作来制作SkewT图表,但是访问和汇总netCDF数据集和变量将非常容易。 Just a few examples below. 下面只是几个例子。
import xray
ds = xray.open_dataset('your_wrf_file.nc')
ds_point = ds.sel(lon=76.9525, lat=8.4875)
ds_point['Temperature'].plot() # plot profile at point assuming Temperature had dimensions of (level, lat, lon)
df = ds_point.to_dataframe() # export dataset to Pandas.DataFrame
temp_array = ds_point['Temperature'].values # access the underlying numpy array of the "Temperature" variable
我通常要做的是在使用ncl,python,R等进行绘图之前,使用CDO从命令行中提取最接近网格点的列:
cdo remapnn,lon=76.9525/lat=8.4875 wrf_file.nc pnt_file.nc
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.