简体   繁体   English

Python-如何从netcdf文件中的特定位置和不同级别获取变量

[英]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.

相关问题 如何使用python从netcdf文件的标题中获取特定信息? - How to get a specific information from the header of a netcdf file using python? 通过 python 从.netCDF 中提取特定位置的数据 - Extracting data for a specific location from netCDF by python 如何通过特定变量值从 netcdf 文件中获取 select 数据? - How to select data from netcdf file by specific variable value? 如何将变量从一个 netcdf 文件添加到 python 中的另一个 netcdf 文件? - How can you add a variable from one netcdf file to another netcdf file in python? 使用 python 从 netCDF 读取特定位置的时间序列,时间以秒为单位 - Reading Time Series from netCDF with python for a specific location and time is in seconds 特定地理位置的 CMEMS.netcdf 文件中的温度和盐度 - Temperature and Salinty from CMEMS netcdf file for specific geographical location 如何使用python netCDF4创建netCDF文件? - How to create a netCDF file with python netCDF4? 使用Python从netCDF文件打印一个变量 - Printing one variable from a netCDF file using Python 如何在 python 的 netcdf 文件中读取变量的值? - How can I read values of a variable in a netcdf file in python? 如何使用python在NetCDF文件中写入变量属性 - How to write variable attributes in NetCDF file using python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM