- 积分
- 1986
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2012-3-20
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 寒江雪(王训 于 2013-10-30 15:56 编辑
Recently, doing the regridding job for atmospheric model. There is a script I used to regrid the lat-lon to LLC.
The case likes:
Source: the soil organic matter data of China whose resolution is 30 seconds
Goal: 36 km lambert conformal conic netcdf file
Here is the script. Enjoying!
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl"
begin
;---We want to write the results to netcdf file
WRITE_RESULTS = True
;---The interpolation way we used
INTERP_METHOD = "bilinear"
;---Data file containing source curvilinear grid
src_file = "SOM.nc" ;;---Change (likely)
sfile = addfile(src_file,"r")
src_lat = sfile->lat ;;---Change (likely)
src_lon = sfile->lon ;;---Change (likely)
;---Get variable to regrid
varname = "SOM" ;;---Change (likely)
var = sfile->$varname$
som = var(0,:,:)
;---WRF file containing destination grid
dst_file = "wrfout.nc" ;;---Change (likely)
dfile = addfile(dst_file,"r")
dst_lat = dfile->XLAT(0,:,:) ;;---Change (maybe)
dst_lon = dfile->XLONG(0,:,:) ;;---Change (maybe)
;---Set up regridding options
Opt = True
;---"bilinear" is the default. "patch" and "conserve" are other options.
Opt@InterpMethod = "bilinear" ;;---Change (maybe)
Opt@WgtFileName = "rec_to_WRF.nc"
Opt@SrcGridLat = src_lat ; source grid
Opt@SrcGridLon = src_lon
Opt@SrcRegional = True ;;--Change (maybe)
Opt@SrcInputFileName = src_file ; optional, but good idea
; Opt@SrcMask2D = where(.not.ismissing(var),1,0) ; Necessary if has
; missing values.
Opt@DstGridLat = dst_lat ; destination grid
Opt@DstGridLon = dst_lon
Opt@DstRegional = True ;;--Change (maybe)
Opt@ForceOverwrite = True
Opt@PrintTimings = True
Opt@Debug = True
var_regrid = ESMF_regrid(som,Opt) ; Do the regridding
printVarSummary(var_regrid)
;----------------------------------------------------------------------
; Plotting section
;
; This section creates filled contour plots of both the original
; data and the regridded data, and panels them.
;----------------------------------------------------------------------
var@lat2d = src_lat ; Needed for plotting. "var_regrid"
var@lon2d = src_lon ; already has these attrs attached.
wks = gsn_open_wks("ps","curv_to_WRF")
res = True
res@gsnMaximize = True
res@gsnDraw = False
res@gsnFrame = False
res@cnFillOn = True
res@cnLinesOn = False
res@cnLineLabelsOn = False
res@cnFillMode = "RasterFill"
res@lbLabelBarOn = False ; Turn on later in panel
res@mpMinLatF = min(src_lat)
res@mpMaxLatF = max(src_lat)
res@mpMinLonF = min(src_lon)
res@mpMaxLonF = max(src_lon)
;;--Change (maybe)
mnmxint = nice_mnmxintvl( min(var), max(var), 100, False)
res@cnLevelSelectionMode = "ManualLevels"
res@cnMinLevelValF = mnmxint(0)
res@cnMaxLevelValF = mnmxint(1)
res@cnLevelSpacingF = mnmxint(2)
;---Resources for plotting regridded data
res@gsnAddCyclic = False ;;---Change (maybe)
res@tiMainString = "Data on WRF grid (" + Opt@InterpMethod + ")"
plot_regrid = gsn_csm_contour_map(wks,var_regrid,res)
;---Resources for plotting original data
res@gsnAddCyclic = False ;;---Change (maybe)
res@tiMainString = "Data on original grid"
plot_orig = gsn_csm_contour_map(wks,som,res)
;---Compare the plots in a panel
pres = True
pres@gsnMaximize = True
pres@gsnPanelLabelBar = True
gsn_panel(wks,(/plot_orig,plot_regrid/),(/2,1/),pres)
;----------------------------------------------------------------------
; Data writing section
; Write the regridded data to a NetCDF file
;----------------------------------------------------------------------
if(WRITE_RESULTS) then
rgrdFileName = "som_regrid.nc"
system("rm -f " + rgrdFileName)
rgrd_nc = addfile(rgrdFileName,"c")
;---Create variable to hold global file attributes
global = True
copy_VarAtts(sfile, global)
if (isatt(sfile,"title")) then
global@TITLE = "REMAPPED: " + sfile@title
end if
global@remap = "NCL: ESMF_regrid_with_weights (NCL version '" + \
get_ncl_version() + "')"
global@remap_method = INTERP_METHOD
global@creation_date = systemfunc("date")
fileattdef( rgrd_nc, global ) ; copy global file attributes
; filedimdef(rgrd_nc,"TIME",-1,True) ; force an unlimited dimension
;--- Write variables to file. Coordinate arrays will be written
;--- automatically
;
rgrd_nc->SOM = (/var_regrid/)
end if
end
|
|