;====================================================================== ; Create NetCDF of the Regridded NARR data ; IMPORTANT! Must already have produced weight files using NARR_Regrid_0.5_weight.ncl ; ;====================================================================== ; Load files here load "$NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl" ;====================================================================== begin WRITE_RESULTS = False ;---------------------------------------------------------------------- ; Regridding section ;---------------------------------------------------------------------- ;---Read data from input file containing source grid srcDirName = "./" srcFileName = "uwnd.mon.mean.nc" srcFilePath = srcDirName + srcFileName sfile = addfile(srcFilePath,"r") uwnd = sfile->uwnd ; time, level, y, x lat2d = sfile->lat(:,:) lon2d = sfile->lon(:,:) uwnd@_FillValue = uwnd@missing_value ; NCL does not understand missing values by default delete(uwnd@missing_value) ;printVarSummary(uwnd) ;---Selecting the time period narrtime = sfile->time narrTIME = ut_calendar(narrtime,0) narryear = floattointeger(narrTIME(:,0)) nddd = ind(narryear.ge.2000.and.narryear.le.2000) ;CHANGE as needed var = sfile->uwnd(nddd,:,:,:) ;---Performing the Regrid j = 0 nmon = dimsizes(var&time) year = ispan(2000,2000,1) ;CHANGE as above do i = 0, nmon-1, 12 var_regrid = ESMF_regrid_with_weights(var(i:i+11,:,:,:),"NARR_to_Rect.WgtFile_bilinear.nc", False) var_regrid@_FillValue = var_regrid@missing_value delete(var_regrid@missing_value) ;printVarSummary(var_regrid) ;This is the regridded variable ;---------------------------------------------------------------------- ; Creating netcdf of regridded variable ;---------------------------------------------------------------------- if (WRITE_RESULTS) then rgrdFileName = "NARR_uwnd_monmean_regrid0.5_"+year(j)+".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 = "bilinear" ;CHANGE as per method used global@creation_date = systemfunc("date") fileattdef( rgrd_nc, global) filedimdef(rgrd_nc,"TIME",-1,True) rgrd_nc->uwnd = var_regrid end if j = j + 1 end do ;---------------------------------------------------------------------- ; Plot the original and regridded data ;---------------------------------------------------------------------- wks = gsn_open_wks("png","ESMF_wgts_test") ; send graphics to PNG file plot = new(2,graphic) ; create a plot array res = True res@gsnDraw = False ; don't draw res@gsnFrame = False ; don't advance frame res@gsnAddCyclic = False ; regional data res@cnInfoLabelOn = False ; turn off cn info label res@cnFillOn = True ; turn on color ;res@cnFillMode = "RasterFill" res@cnLinesOn = False res@cnLineLabelsOn = False res@lbLabelBarOn = False ; turn off individual cb's ;res@cnLevelSelectionMode = "ManualLevels" ;res@cnMinLevelValF = -50 ;res@cnMaxLevelValF = 100 ;res@cnLevelSpacingF = 10 res@mpMinLatF = min(lat2d) ; range to zoom in on res@mpMaxLatF = max(lat2d) res@mpMinLonF = min(lon2d) res@mpMaxLonF = max(lon2d) res@mpCenterLonF = -107.0 ; from file (253-360) res@mpFillOn = False ;res@mpGridAndLimbOn = True ;res@mpGridLineDashPattern= 10 ; lat/lon lines as dashed res@gsnLeftString = "" res@gsnRightString= "" res@gsnCenterString= "NARR Original - uwnd@1000hPa" plot(0) = gsn_csm_contour_map(wks,uwnd(0,0,:,:) ,res) res@gsnCenterString= "NARR Rectilinear Grid - uwnd@1000hPa" plot(1) = gsn_csm_contour_map(wks,var_regrid(0,0,:,:),res) ; create panel resP = True ; modify the panel plot resP@gsnPanelLabelBar = True ; add common colorbar resP@gsnMaximize = True gsn_panel(wks,plot,(/2,1/),resP) ; now draw as one plot end