;-------------------------------------------------- ;regrid the nmme model provided by Yan to the grid used in the downscaling paper ;2/23/2025 ;-------------------------------------------------------------- begin ;-------------------------------------------------------------- pre_dir="/Projects/RISE/data/Maps/bias_corrected/GEM5.2-NEMO/19932020climo/Leave_One_Out/" out_dir="/Projects/RISE/xlong_downscaling/regrid/" year_start=1993 year_end=2020 nyear=year_end - year_start +1 nlead=12 nfiles=nyear*nlead f0:=addfile("/Datasets.private/oras5/Monthlies/monolevel/sossheig_ORAS5_1m_mon.mean.nc","r") ssh0=f0->sossheig(0,:,:) latDst=f0->lat lonDst=f0->lon delete(f0) flist=new(nfiles,"string") i=0 do iyear=0,nyear-1 year_str=tostring(iyear+year_start) do jlead=0,12-1 lead_str=tostring(jlead) fname="ssh.anomaly_monthlymean_1x1.grid."+year_str+".lag"+lead_str+".nc" flist(i)=pre_dir+fname ;print(tostring(flist(i))) ;print(isfilepresent(flist(i))) end do end do fc:=addfile(flist(0),"r") ssh=fc->ssh(0,0,:,:) latSrc=fc->lat lonSrc=fc->lon delete(fc) ;generate the weights Opt = True Opt@WgtFileName = "regrid.nc" ; default is "weights_file.nc" ; Opt@SrcInputFileName = srcFileName ; optional, but good idea Opt@SrcTitle = "ORAS5 Grid" Opt@SrcMask2D = where(ismissing(ssh),0,1) Opt@DstMask2D := where(ismissing(ssh0),0,1) Opt@ForceOverwrite = True Opt@SrcGridLat =latSrc Opt@SrcGridLon =lonSrc Opt@DstGridLat= latDst Opt@DstGridLon=lonDst ;;Opt@PrintTimings = True ;;Opt@Debug = True ssh_tmp:= ESMF_regrid(ssh,Opt) printVarSummary(ssh) printVarSummary(ssh_tmp) do iyear=0,nyear-1 year_str=tostring(iyear+year_start) do jlead=0,12-1 lead_str=tostring(jlead) fname="ssh.anomaly_monthlymean_1x1.grid."+year_str+".lag"+lead_str+".nc" fc:=addfile(pre_dir+fname,"r") print(tostring(pre_dir+fname)) ssh:=fc->ssh delete(fc) ssh_regrid=ESMF_regrid_with_weights(ssh,Opt@WgtFileName,Opt) printVarSummary(ssh_regrid) system("rm -f "+out_dir+"ssh.anomaly_monthlymean_1x1.REgrid."+year_str+".lag"+lead_str+".nc") fnc:=addfile(out_dir+"ssh.anomaly_monthlymean_1x1.REgrid."+year_str+".lag"+lead_str+".nc","c") fnc->ssh=ssh_regrid delete(ssh) delete(ssh_regrid) ; print(fnc) delete(fnc) end do end do end