- 积分
- 37870
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2019-5-13
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 一大碗年糕 于 2022-4-4 15:55 编辑
今天处理模式的数据是模式原生非标准网格进行插值到等经纬度网格,自己python太菜没找到好用的函数,还是用回ncl了,ESMF这个函数属实太强了,记录一下
; This file still has to be loaded manually
; load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl"
begin
;---Read in netCDF file
source_dir= (/"/media/huangwenshuo/新加卷/relative_var_historical/tos/","/media/huangwenshuo/新加卷/relative_var_future/tos/"/)
out_dir = "/home/huangwenshuo/AR_work/AR_huangwenshuo/TOSCMIP/"
list_of_files = systemfunc("ls "+source_dir(1)+"/native/"+"*.nc")
out_list_of_files = str_get_field(list_of_files, 7, "/")
print(out_list_of_files)
file_number = dimsizes(list_of_files)
do f = 0, file_number-1
in = addfile(list_of_files(f),"r")
;---Read in data
temp = in->tos
temp@lon2d = in->lon
temp@lat2d = in->lat
;-- set resources
Opt = True
Opt@InterpMethod = "bilinear" ;-- interpolation method
Opt@SrcFileName = "CMIP5_native_grid.nc" ;-- source file name
Opt@DstFileName = "CMIP5_regrid.nc" ;-- destination file
Opt@WgtFileName = "CurvilintoWORLD_2.5x2.5_bilinear.nc"
;-- name of weights file, which will be generated
Opt@ForceOverwrite = True ;-- force overwrite
Opt@SrcMask2D = where(.not. ismissing(temp(0,:,:)),1,0) ;-- if data contains
;-- missing values
Opt@DstGridType = "2.5deg" ;-- Destination grid
Opt@DstTitle = "World Grid 2.5x2.5-degree Resolution bilinear";-- destination title
Opt@DstLLCorner = (/-90.0d, 0.0d /) ;-- destination lower;-- left corner
Opt@DstURCorner = (/ 90.0d, 357.5d /) ;-- destination upper;-- right corner
tos_regrid = ESMF_regrid(temp,Opt);-- call ESMF_regrid
nlon = dimsizes(tos_regrid&lon)
nlat = dimsizes(tos_regrid&lat)
;-- assign a output netcdf file for the new regridded data;
tosavg = dim_avg_n_Wrap(tos_regrid, (/1,2/))
system("rm -rf "+out_dir+out_list_of_files(f)) ;-- delete file if exists
out = addfile(out_dir+out_list_of_files(f), "c")
out->tos = tos_regrid
out->tos_global_mean = tosavg
ninotosavg = dim_avg_n_Wrap(tos_regrid(:,{-5:5},{190:240}), (/1,2/))
ninotos = tos_regrid(:,{-5:5},{190:240})
system("rm -rf "+out_dir+"nino3.4_"+out_list_of_files(f)) ;-- delete file if exists
nino = addfile(out_dir+"nino3.4_"+out_list_of_files(f), "c")
nino->ninotos = ninotos
nino->ninotos_mean = ninotosavg
print(list_of_files(f)+" is regridded, runaved and clipped")
delete(temp)
; delete(lon)
; delete(lat)
delete(Opt@SrcFileName)
delete(Opt@SrcMask2D)
delete(tos_regrid)
delete(tosavg)
delete(ninotosavg)
delete(ninotos)
end do
end
|
|