load "$NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl" begin start_time = get_cpu_time() ;-----read data srcFileName = "AMSR_E_L3_DailySnow_V09_20100311.hdf" ; Source file eos_file = addfile(srcFileName + ".he2","r") lon2d = eos_file->GridLon_Northern_Hemisphere lat2d = eos_file->GridLat_Northern_Hemisphere ; Process NAN (1e51) fillValue for LAMAZ geolocation. lon2d@_FillValue = -999.0 lat2d@_FillValue = -999.0 lon2d=where(lon2d .gt. 1000, lon2d@_FillValue, lon2d) lat2d=where(lat2d .gt. 1000, lat2d@_FillValue, lat2d) hdf_file = addfile(srcFileName, "r") ; Read the dataset. hdf_data = hdf_file->SWE_NorthernDaily ; Filter out invalid range values. ; See "Table 2. Pixel Values ofr the SWE Feids" from [2]. hdf_data = where(hdf_data .gt. 240, hdf_data@_FillValue, hdf_data) ; Prepare data for plotting by converting type. swe2d = tofloat(hdf_data) swe2d@_FillValue = tofloat(hdf_data@_FillValue) ; Multiply by two according to data spec [2]. swe2d = 2 * swe2d ; You can get the description of data set from the data spec [2]. swe2d@long_name = "Northern Hemisphere 5-day Snow Water Equivalent ~C~ (" + hdf_data@hdf_name + ")" swe2d@units = "mm" ; Associate data with lat/lon. swe2d@lon2d = lon2d swe2d@lat2d = lat2d ;-----ESMF regridding Opt = True ; Options for regridding Opt@SrcFileName = "EASE_SCRIP.nc" ; Output files Opt@DstFileName = "NH_SCRIP.nc" Opt@WgtFileName = "EASE_2_NH_patch.nc" Opt@ForceOverwrite = True Opt@SrcMask2D = where(ismissing(lat2d).or.ismissing(swe2d),0,1) Opt@DstGridType = "0.25deg" ; Destination grid Opt@DstRegional = True Opt@DstLLCorner = (/ 0.25d,-180.00d/) Opt@DstURCorner = (/89.75d, 179.75d/) Opt@DstTitle = "Northern Hemisphere 0.25 resolution" Opt@InterpMethod = "bilinear" ; Careful! Patch method takes a long time Opt@Debug = True swe_regrid = ESMF_regrid(swe2d,Opt) ; Regrid swe, using lat2d/lon2d coords attached to swe printVarSummary(swe_regrid) ;---------------------------------------------------------------------- ; Plotting section ;---------------------------------------------------------------------- wks = gsn_open_wks("png","swe_regrid") ; send graphics to PNG file res = True ; Plot mods desired. res@gsnMaximize = True ; Maximize plot res@gsnDraw = False res@gsnFrame = False res@cnFillOn = True ; color plot desired res@cnFillPalette = "amwg" ; set color map res@cnLinesOn = False ; turn off contour lines res@cnLineLabelsOn = False ; turn off contour labels res@cnFillMode = "RasterFill" ; turn raster on res@cnLevelSelectionMode= "ExplicitLevels" ; set explicit contour levels res@cnLevels = (/-300,-250,-200,-150,-100, \ 0,1,5,10,25,100,200,300,400/) res@lbLabelBarOn = False ; turn on in panel res@trGridType = "TriangularMesh" ; allow missing coordinates res@gsnPolar = "NH" ; specify the hemisphere res@mpMinLatF = 35 res@mpGridAndLimbOn = False ; temporary while we figure out missing data issue ;---Plot original data. res@gsnAddCyclic = False res@tiMainString = "Original EASE grid (" + str_join(dimsizes(lat2d),",") + ")" ; res@trGridType = "TriangularMesh" res@cnFillMode = "RasterFill" plot_orig = gsn_csm_contour_map_polar(wks,swe2d,res) ;---Plot regridded data. res@gsnAddCyclic = True dims = tostring(dimsizes(swe_regrid)) res@tiMainString = "Regridded to 0.25 degree grid (" + \ str_join(dims," x ") + ")" plot_regrid = gsn_csm_contour_map_polar(wks,swe_regrid,res) ;---Compare the plots in a panel pres = True pres@gsnMaximize = True pres@gsnPanelLabelBar = True pres@lbLabelFontHeightF = 0.01 pres@pmLabelBarWidthF = 0.8 gsn_panel(wks,(/plot_orig,plot_regrid/),(/1,2/),pres) end_time = get_cpu_time() print("======================================================================") print("Elapsed time: " + (start_time - end_time)) print("======================================================================") end