用python上的netcdf文件上的精确坐标提取点

发布于 2025-02-01 01:34:43 字数 1271 浏览 5 评论 0原文

对于我的项目,我想从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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小镇女孩 2025-02-08 01:34:43

要提取特定的网格点,您需要使用最近的邻居插值使用重新插值。我认为,使用Python界面

cdo.remapnn('lon=-26.45/lat=65.03', input="tos_1979-2014.nc", output="tos_1979-2014_2.nc")

(我认为) -

我有一个有关此主题的视频指南,以防有帮助:
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

cdo.remapnn('lon=-26.45/lat=65.03', input="tos_1979-2014.nc", output="tos_1979-2014_2.nc")

(I think) -

I have a video guide on this topic in case it is helpful:
https://www.youtube.com/watch?v=YdFo8YAbLTw

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文