gpt4 book ai didi

python - GCM 数据的重新网格化/重新映射

转载 作者:太空宇宙 更新时间:2023-11-03 21:44:13 24 4
gpt4 key购买 nike

我从 CMIP5 数据库下载了 netCDF 文件中的降水数据。我能够制作该文件的子集,并获得了下面给出的属性。这些数据具有 2.5 X 3.75 度的空间分辨率。现在我需要将其转换为 0.05 度的空间分辨率。有没有人可以帮助我写一下如何使用 Python 来完成它。

请记住,我在 Windows 机器上使用 python 3.7。 CDO 或 NCO 不适合 Windows。数据属性在这里。

Dimensions:    (bnds: 2, lat: 15, lon: 13, time: 122)
Coordinates:
* time (time) float64 15.0 45.0 75.0 ... 3.585e+03 3.615e+03 3.645e+03
* lat (lat) float64 -42.5 -40.0 -37.5 -35.0 ... -15.0 -12.5 -10.0 -7.5
* lon (lon) float64 112.5 116.2 120.0 123.8 ... 146.2 150.0 153.8 157.5

Dimensions without coordinates: bnds
Data variables:
time_bnds (time, bnds) float64 ...
lat_bnds (lat, bnds) float64 ...
lon_bnds (lon, bnds) float64 ...
pr (time, lat, lon) float32 ...

如果有人能帮助我,我将不胜感激。提前致谢。

最佳答案

我可以使用一些随机数据提出一些像这样的解决方案,其中我将数据从一种分辨率重新网格到另一种分辨率。

#!/usr/bin/env ipython
# ---------------------
import numpy as np
from netCDF4 import Dataset,num2date,date2num
# -----------------------------
ntime,nlon,nlat=10,10,10;
lonin=np.linspace(0.,1.,10);
latin=np.linspace(0.,1.,10);
dataout=np.random.random((ntime,nlat,nlon));
unout='seconds since 2018-01-01 00:00:00'
# ---------------------
# make data:
ncout=Dataset('in.nc','w','NETCDF3_CLASSIC');
ncout.createDimension('lon',nlon);
ncout.createDimension('lat',nlat);
ncout.createDimension('time',None);
ncout.createVariable('lon','float32',('lon'));ncout.variables['lon'][:]=lonin;
ncout.createVariable('lat','float32',('lat'));ncout.variables['lat'][:]=latin;
ncout.createVariable('time','float64',('time'));ncout.variables['time'].setncattr('units',unout);ncout.variables['time'][:]=np.linspace(0,3600*ntime,ntime);
ncout.createVariable('randomdata','float32',('time','lat','lon'));ncout.variables['randomdata'][:]=dataout;
ncout.close()
# ----------------------
# regrid:
from scipy.interpolate import griddata
lonout=np.linspace(0.,1.,20);
latout=np.linspace(0.,1.,20);
ncout=Dataset('out.nc','w','NETCDF3_CLASSIC');
ncout.createDimension('lon',np.size(lonout));
ncout.createDimension('lat',np.size(latout));
ncout.createDimension('time',None);
ncout.createVariable('lon','float32',('lon'));ncout.variables['lon'][:]=lonout;
ncout.createVariable('lat','float32',('lat'));ncout.variables['lat'][:]=latout;
ncout.createVariable('time','float64',('time'));ncout.variables['time'].setncattr('units',unout);ncout.variables['time'][:]=np.linspace(0,3600*ntime,ntime);
ncout.createVariable('randomdata','float32',('time','lat','lon'));
ncin=Dataset('in.nc');
lonin=ncin.variables['lon'][:];latin=ncin.variables['lat'][:];
lonmin,latmin=np.meshgrid(lonin,latin);
lonmout,latmout=np.meshgrid(lonout,latout);
for itime in range(np.size(ncin.variables['time'][:])):
zout=griddata((lonmin.flatten(),latmin.flatten()),ncin.variables['randomdata'][itime,:,:].flatten(),(lonmout,latmout),'linear');
ncout.variables['randomdata'][itime,:]=zout;
ncin.close();ncout.close()

关于python - GCM 数据的重新网格化/重新映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52606419/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com