用python上的netcdf文件上的精确坐标提取点
对于我的项目,我想从NETCDF文件中提取数据,我的文件代表纬度/经度功能的海面温度。我想精确的坐标选择点,然后在几个月内均值做一个均值。
import netCDF4 as nc
import numpy as np
import cdo
import os
import pandas as pd
from scipy.io import netcdf
from netCDF4 import Dataset
from netCDF4 import num2date
import matplotlib as mpl
import matplotlib.pylab as plt
from cdo import Cdo
cdo = Cdo()
data = "/Users/bf/Desktop/Stage
tos_Omon_EC-Earth3_historical_r5i1p1f1_gn_185001-201412.nc"
ds = nc.Dataset(data)
infile = "/Users/bf/Desktop/Stage/tos_Omon_EC-Earth3_historical_r5i1p1f1_gn_185001-201412.nc"
#to select years : 1979-2014
#new name for the file with the selected years : tos_1979-2014.nc
cdo.seldate('1979-01-01,2014-12-31', input=infile, output="tos_1979-2014.nc")
#to select longitute and latitute -> no important now
#new name for the file with the selected longitudes/latitudes : tos_1979-2014_2.nc
cdo.sellonlatbox('-26.45,65.03', input="tos_1979-2014.nc", output="tos_1979-2014_2.nc")
#ymonavg : multi-year monthly statistical values average
cdo.ymonavg(input="tos_1979-2014_2.nc", output="tos_1979-2014_mean_2.nc")
我想提取我的温度数据(自1979年至2014年以来每月的温度平均值),然后将它们放入数据框架中,以便在此后进行图形(使用Mathplolib)。 但是,在使用CDO
工具时,我不能只选择一个点。也许我必须使用另一个工具,但我不知道该怎么做。
感谢您的帮助 !
For my project I want to extract data from a netCDF file, my file represent the Ocean Surface Temperature in function of latitude/longitude. I want to select on point with precise coordinate and then do a mean for each months for several years.
import netCDF4 as nc
import numpy as np
import cdo
import os
import pandas as pd
from scipy.io import netcdf
from netCDF4 import Dataset
from netCDF4 import num2date
import matplotlib as mpl
import matplotlib.pylab as plt
from cdo import Cdo
cdo = Cdo()
data = "/Users/bf/Desktop/Stage
tos_Omon_EC-Earth3_historical_r5i1p1f1_gn_185001-201412.nc"
ds = nc.Dataset(data)
infile = "/Users/bf/Desktop/Stage/tos_Omon_EC-Earth3_historical_r5i1p1f1_gn_185001-201412.nc"
#to select years : 1979-2014
#new name for the file with the selected years : tos_1979-2014.nc
cdo.seldate('1979-01-01,2014-12-31', input=infile, output="tos_1979-2014.nc")
#to select longitute and latitute -> no important now
#new name for the file with the selected longitudes/latitudes : tos_1979-2014_2.nc
cdo.sellonlatbox('-26.45,65.03', input="tos_1979-2014.nc", output="tos_1979-2014_2.nc")
#ymonavg : multi-year monthly statistical values average
cdo.ymonavg(input="tos_1979-2014_2.nc", output="tos_1979-2014_mean_2.nc")
I thought of extract my temperature data (to do a mean of the temperature for each months since 1979 to 2014) and to put them in a data frame, to do graphics thereafter (with mathplolib).
But while using CDO
tool, I can't select just one point. Maybe I have to use another tool but I don't know how to do it.
Thanks for your help !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要提取特定的网格点,您需要使用最近的邻居插值使用重新插值。我认为,使用Python界面
(我认为) -
我有一个有关此主题的视频指南,以防有帮助:
https://www.youtube.com/watch?v=ydfo8yabltw
to extract a specific gridpoint you need to use remapping interpolation, with the nearest neighbor interpolation. I think with the python interface it would be
(I think) -
I have a video guide on this topic in case it is helpful:
https://www.youtube.com/watch?v=YdFo8YAbLTw