[ncl-talk] regrid problem (fill value for output)
LSL
lslrsgis at whu.edu.cn
Mon Mar 11 04:59:16 MDT 2019
Dear NCL community,
I am using ncl ESMF_regrid function to convert projection from (1)
latlon to (2) wrf lambert.
The purpose is to compare (1) Observation (latlon projection/rectilinear
grids in .txt file) with (2) Simulation (lambert projection/curvilinear
grids in .nc file).
However, the regrid output is all fill value -9999. Illustration map for
one day 20150106, log file, and source code is attached. Anyone can give
indications? Thanks very much.
Liang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190311/d5bd1bb0/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Regrid_Latlon_WRF_Daily_Precipitation.log
Type: text/x-log
Size: 5599 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190311/d5bd1bb0/attachment-0001.bin>
-------------- next part --------------
;======================================================================
; ESMF_regrid_19.ncl
;
; Concepts illustrated:
; - Interpolating from one grid to another using ESMF_regrid
; - Interpolating data from HOMME unstructured grid to a POP grid
;======================================================================
; This example uses ESMF regridding software to regrid data on a
; HOMME unstructured grid to a POP gx1v3 grid (384 x 320).
;======================================================================
; This script uses ESMF regridding functions that are only available in
; NCL V6.1.0-beta and later.
;======================================================================
;
; These files are loaded by default in NCL V6.2.0 and newer
; 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"
;
; This file still has to be loaded manually
load "$NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl"
begin
;==========================================================================================
;--Read in files
DIR="/home/lsl/Downloads/DATA/CMA_Prep_Daily_05D/PRE_DAY_GRID/"
; flnm="SURF_CLI_CHN_PRE_DAY_GRID_0.5-"+20150622+".txt"
days_in_feb=28
days = (/31,days_in_feb,31,30,31,30,31,31,30,31,30,31,31/)
nCOL=128
nROW=72
matrix_prep = new((/72,128/),float)
matrix_prep at _FillValue=-9999.0
matrix_lat = new((/72,128/),float)
matrix_lon = new((/72,128/),float)
;--Generate lat/lon matrix
lat=fspan(18.25, 53.75, 72)
lon=fspan(72.25,135.75,128)
; print(lat)
; print(lon)
do iROW=1,72
matrix_lon(iROW-1,:)=lon
end do
do iCOL=1,128
matrix_lat(:,iCOL-1)=lat
end do
;--Loop through year/month/day
do iYY=2015,2015
; do iMM=1,6
do iMM=1,1
nDD=days(iMM-1)
; nDD=1
; do iDD=1,nDD
do iDD=6,6
sYY=tostring_with_format(iYY, "%4.4d")
sMM=tostring_with_format(iMM, "%2.2d")
sDD=tostring_with_format(iDD, "%2.2d")
; flnm="SURF_CLI_CHN_PRE_DAY_GRID_0.5-"+20150622+".txt"
flnm = "SURF_CLI_CHN_PRE_DAY_GRID_0.5-"+sYY+sMM+sDD+".txt"
print("Now is processing FILE "+flnm+"....................")
strs = asciiread(DIR+flnm,-1,"string")
; print(strs)
;==Read Precipitation TXT File==============================
strs_data=strs(6:6+nROW-1)
do iROW=1,72
delim = " "
nfields = str_fields_count(strs_data(0), delim)
do iCOL=1,128
; printVarSummary(str_get_field(strs_data, iCOL, delim))
; printVarSummary(nfields)
; print(matrix_prep(:,iCOL-1))
matrix_prep(:,iCOL-1) = stringtofloat(str_get_field(strs_data, iCOL, delim))
; print(matrix_prep)
end do
end do
delete(strs)
delete(strs_data)
;==Read Precipitation WRF File==============================
;XLAT, XLONG
DIR_WRF="/home/lsl/Downloads/DATA/wrfout_2015/"
fwrf="wrfout_d01.nc"
f=addfile(DIR_WRF+fwrf,"r")
XLAT=f->XLAT(0,:,:)
XLON=f->XLONG(0,:,:)
delete(f)
dst_minlat = min(XLAT) ; Used for plotting later.
dst_maxlat = max(XLAT)
dst_minlon = min(XLON)
dst_maxlon = max(XLON)
;==Regrid lat/lon to WRF
;---Set up regridding options
Opt = True
interp_method = "bilinear"
; interp_method = "neareststod"
wgt_file = "latlon_lambert.nc"
;---"bilinear" is the default. "patch" and "conserve" are other options.
Opt at InterpMethod = interp_method
Opt at WgtFileName = wgt_file
Opt at SrcGridLat = matrix_lat
Opt at SrcGridLon = matrix_lon
Opt at SrcInputFileName = flnm
;
dst_dims = (/62,91/) ; Fortran ordering
wrf_dims = tostring(dimsizes(matrix_lat))
mm5_dims = tostring(dimsizes(XLAT))
Opt at DstGridLat = XLAT
Opt at DstGridLon = XLON
; Opt at DstMask2D = reshape(dfile->mask_b,dst_dims)
Opt at ForceOverwrite = True
Opt at Debug = True
Opt at PrintTimings = True
var=matrix_prep(::-1,:) ; Reverse matrix
var_regrid = ESMF_regrid(var,Opt) ; Do the regridding
printVarSummary(var_regrid)
print("-------var_regrid---------")
printVarSummary(var_regrid)
printMinMax(var_regrid,0)
;----------------------------------------------------------------------
; Code to plot the original and regridded data in a panel plot.
;----------------------------------------------------------------------
var at lat2d = matrix_lat ; Needed for plotting. "var_regrid"
var at lon2d = matrix_lon ; already has these attrs attached.
wks = gsn_open_wks("png","/home/lsl/Downloads/EXPR/Scripts/ESMF_regrid_"+sYY+sMM+sDD) ; send graphics to PNG file
res = True ; Plot mods desired.
;---General resources
res at gsnDraw = False ; We will panel later.
res at gsnFrame = False
res at gsnMaximize = True ; Maximize plot
;---Contour and labelbar resources
res at cnFillOn = True ; Color plot desired.
res at cnLinesOn = False ; Turn off contour lines.
res at cnLineLabelsOn = False ; Turn off contour labels.
res at lbLabelBarOn = False ; Labelbar will be in panel.
res at gsnAddCyclic = False ; Data is regional.
;---Map resources
res at mpDataBaseVersion = "MediumRes"
res at mpFillOn = False
res at mpOutlineBoundarySets = "AllBoundaries"
res at mpUSStateLineColor = "gray"
res at mpGeophysicalLineColor = "gray"
res at mpNationalLineColor = "gray"
;---Zoom in on map
res at mpMinLatF = dst_minlat-0.03 ; Leave a little bit
res at mpMinLonF = dst_minlon-0.03 ; of a margin.
res at mpMaxLatF = dst_maxlat+0.03
res at mpMaxLonF = dst_maxlon+0.03
;---Titles and tickmarks
res at pmTickMarkDisplayMode = True ; Better tickmarks
res at tmYROn = False
res at tmXTOn = False
res at tmXBLabelFontHeightF = 0.01
res at tmYLLabelFontHeightF = 0.01
res at gsnLeftString = ""
res at gsnRightString = ""
res at tiMainFontHeightF = 0.020
res at tiMainOffsetYF = -0.02 ; move closer to plot
res at gsnStringFontHeightF = 0.015
;---Resources for paneling
pres = True
; Loop through each level and create a panel plot comparing
; the original data against the regridded data.
;
; Note that each set of plots has a different colorbar,
; depending on the min/max of the data at that level.
;
; If you are plotting across time, or, if you want the same
; color bar for each level, set SAME_COLORBAR = True.
;
SAME_COLORBAR = False
if(SAME_COLORBAR) then
mnmxint = nice_mnmxintvl( min(var_regrid), max(var_regrid), 18, False)
res at cnLevelSelectionMode = "ManualLevels"
res at cnMinLevelValF = mnmxint(0)
res at cnMaxLevelValF = mnmxint(1)
res at cnLevelSpacingF = mnmxint(2)
end if
nlev = 1
var_ndims=2
do i=0,nlev-1
res at tiMainString = "Regridded data (" + \
str_join(mm5_dims," x ") + ")"
if(var_ndims.eq.2) then
plot_regrid = gsn_csm_contour_map(wks,var_regrid,res)
else if(var_ndims.eq.3) then
; level = p(i,0,0)
print("level = " + level)
plot_regrid = gsn_csm_contour_map(wks,var_regrid(i,:,:),res)
end if
end if
;---Make sure same contours levels are used for both plots.
if(.not.SAME_COLORBAR) then
getvalues plot_regrid at contour
"cnLevels" : levels
end getvalues
res at cnLevels = levels
res at cnLevelSelectionMode = "ExplicitLevels"
end if
res at tiMainString = "Original data (" + \
str_join(wrf_dims," x ") + ")"
if(var_ndims.eq.2) then
plot_orig = gsn_csm_contour_map(wks,var,res)
else if(var_ndims.eq.3) then
plot_orig = gsn_csm_contour_map(wks,var(i,:,:),res)
end if
end if
if(var_ndims.eq.2) then
; pres at gsnPanelMainString = var at description + " (" + var at units + ")"
pres at gsnPanelMainString = sYY+sMM+sDD
else
pres at gsnPanelMainString = var at description + " (" + var at units + ")" + \
" (level=" + level + " " + p at units + ")"
end if
gsn_panel(wks,(/plot_orig,plot_regrid/),(/1,2/),pres)
;---Clean up before next time in loop.
if(.not.SAME_COLORBAR) then
; delete(levels)
delete(res at cnLevelSelectionMode)
delete(res at cnLevels)
end if
end do
end do
end do
end do
;=========================================================================================
end
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ESMF_regrid_20150106.png
Type: image/png
Size: 57633 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190311/d5bd1bb0/attachment-0006.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ESMF_regrid_20150105.png
Type: image/png
Size: 62174 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190311/d5bd1bb0/attachment-0007.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ESMF_regrid_20150104.png
Type: image/png
Size: 50068 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190311/d5bd1bb0/attachment-0008.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ESMF_regrid_20150103.png
Type: image/png
Size: 46432 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190311/d5bd1bb0/attachment-0009.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ESMF_regrid_20150102.png
Type: image/png
Size: 45700 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190311/d5bd1bb0/attachment-0010.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ESMF_regrid_20150101.png
Type: image/png
Size: 45456 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190311/d5bd1bb0/attachment-0011.png>
More information about the ncl-talk
mailing list