[ncl-talk] Problem with ESMF_regrid

Mary Haley haley at ucar.edu
Wed Mar 1 12:18:46 MST 2017


I think this is related to a bug we fixed in NCL V6.4.0, which we just
released yesterday.

If you can provide me with the input files, I can try it here and see if
6.4.0 works.

Or, you can upgrade to NCL V6.4.0 and try it yourself.

http://www.ncl.ucar.edu/Download/

--Mary


On Mon, Feb 27, 2017 at 10:15 PM, Tomoko Koyama <Tomoko.Koyama at colorado.edu>
wrote:

> Hello,
>
> I am trying to regrid MIROC5 Sea Ice Area Fraction (and other CMIP5
> output) to EASE 100km grid.
> The following script works for NorESM1-M sic data, but it doesn’t work for
> MIROC5.
> ==============================
>>>> (0) ESMF_regrid_with_weights: retrieving interpolation weights ...
> (0) ESMF_regrid_with_weights: calling sparse_matrix_mult to apply
> weights...
> (0) ESMF_regrid_with_weights: putting interpolated values back onto
> larger 2D grid...
> fatal:reshape_ind: the number of indexes must be the same as the rightmost
> dimension of x
> fatal:["Execute.c":8567]:Execute: Error occurred at or near line 2797 in
> file $NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl
>
> fatal:["Execute.c":8567]:Execute: Error occurred at or near line 3489 in
> file $NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl
>
> fatal:["Execute.c":8567]:Execute: Error occurred at or near line 92 in
> file MIROC5_regrid_ice.ncl
>
> ==============================
>
> Does anyone see why this might be?
>
> Thank you in advance,
> Tomoko
>
>
>
>
> ;;----------------------------------------------------------------------
> ;; A test routine to regrid MIROC5 to EASE 100km grid
> ;;
> ;; 2017-02-27 Tomoko Koyama
> ;;----------------------------------------------------------------------
> ;; This code is based on "ESMF_regrid_12.ncl"
> ;; (http://www.ncl.ucar.edu/Applications/Scripts/ESMF_regrid_12.ncl)
> ;;----------------------------------------------------------------------
> 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/esmf/ESMF_regridding.ncl"
>
> method      = "bilinear"
> model       = "MIROC5"
> gridtype    = "latlon"
>
> doplot = 0
>
>
> rdiri   = "/Users/tomoko/CMIP5/data"
> in_diri = "/Users/tomoko/CMIP5/data/input"
> esmf_diri           = in_diri + "/" + model
>
> begin
>  ; Source grid
>  srcGridDiri = rdiri + "/" + model
>  fili        = systemfunc("cd " + srcGridDiri + " ; ls sic_*.nc")
>  nfil        = dimsizes(fili)
>
>  ; Destination grid
>  dstGridDiri ="/Users/tomoko/CMIP5/data/grid_coord"
>  dstFileName = "NRims180x180.nc"
>  dstGridFili = dstGridDiri + "/" + dstFileName
>  dfile       = addfile(dstGridDiri + "/" + dstFileName, "r")
>  lat2d = dfile->latitude
>  lon2d = dfile->longitude
>
>  do ifil = 0, nfil-1
>    srcGridFili = fili(ifil)
>    sfile       = addfile(srcGridDiri + "/" + srcGridFili, "r")
>    dSizes      = getfiledimsizes(sfile)
>    var         = sfile->sic
>
> ;printVarSummary( var )
>
>    lat1d = ndtooned(lat2d)
>    lon1d = ndtooned(lon2d)
>    lon1d = where(lon1d.lt.0,360.0+lon1d,lon1d)
>    latlon_dims = dimsizes(lat2d)                 ; 180x180
>
>    Indexes = ind(.not.ismissing(lon1d))
>
>    Opt                 = True
>
>    Opt at SrcFileName     = esmf_diri + "/" + model +"_SCRIP.nc"      ;
> output file names
>    Opt at DstFileName     = esmf_diri + "/" + "EASE_ESMF.nc"
>    Opt at WgtFileName     = esmf_diri + "/" + model +"_2_EASE_"+method+".nc"
>    Opt at ForceOverwrite  = True
>
>    Opt at SrcInputFileName    = srcGridFili          ; optional, but good
> idea
>    Opt at DstInputFileName    = dstGridFili
>
>    Opt at SkipSrcGrid     = True ;False
>    Opt at SkipDstGrid     = True ;False
>    Opt at SkipWgtGen      = True ;False
>    Opt at DstESMF         = True
>
>    Opt at DstGridType     = "unstructured"         ; Destination grid
>    Opt at DstGridLat      = lat1d(Indexes)         ; Strip off missing data
>    Opt at DstGridLon      = lon1d(Indexes)
>    delete(lat1d)
>    delete(lon1d)
>
>    Opt at RemapIndexes    = True                   ; This is necessary to
> remap
>    Opt at Indexes         = Indexes                ; regridded values back
> to
>    Opt at IndexesDims     = latlon_dims            ; locations on
> destination grid
>
>    Opt at InterpMethod    = method
>
>    Opt at Debug           = True
>    Opt at PrintTimings    = True
>    Opt at NoPETLog        = True
>
>    Opt at CopyVarCoords   = False                 ; we can't copy the coords
> because
>                                                ; the weights on the file
> are only
>                                                ; for the non-missing
> lat/lon values.
>
>
>    Opt at SrcMask2D       = where(ismissing(var(0,:,:)),0,1)
>
>    var_regrid = ESMF_regrid(var,Opt)    ; Regrid var
>
>
>    copy_VarAtts(var,var_regrid)
>    var_regrid at _FillValue = var at _FillValue
>
>    var_regrid!0 = "time"
>    var_regrid!1 = "i"
>    var_regrid!2 = "j"
>
>    time    = ispan(1,dSizes(0),1)
>    time!0  = "time"
>    time at long_name  = "time"
>    time at units      = "month"
>    time&time       = time
>
>    var_regrid&time = time
>    var_regrid&i = lat2d&i
>    var_regrid&j = lat2d&j
>
>    delete( var_regrid at lat1d )
>    delete( var_regrid at lon1d )
>    if ( isatt( var_regrid, "lat2d" ) ) then
>      delete( var_regrid at lat2d )
>    end if
>    if ( isatt( var_regrid, "lon2d" ) ) then
>      delete( var_regrid at lon2d )
>    end if
>
> ;;----------------------------------------------------------------------
> ;; Write regridded data to file
> ;;----------------------------------------------------------------------
>    str     = str_split(srcGridFili, ".")
>    filo    = str(0) + ".rgrd.nc"
>
>    if ( isfilepresent(filo) .eq. True ) then
>      system( "rm " + filo )
>    end if
>
>    setfileoption("nc","Format","LargeFile")
>
>    fo = addfile( srcGridDiri + "/" + filo,"c")
>    fo->sic     = var_regrid
>    ;fo->plev    = plev
>    fo->lat     = lat2d
>    fo->lon     = lon2d
>
> ;;----------------------------------------------------------------------
> ;; Plot results
> ;;----------------------------------------------------------------------
>
>    if ( doplot .eq. 1 ) then
>
>      printMinMax( var, True )
>
>      var = where( var .le. 0.0, var at _FillValue, var )
>      var_regrid = where( var_regrid .le. 0.0, var_regrid at _FillValue,
> var_regrid )
>
>      print ( "% esmf_regrid_test: Plotting results...." )
>      wks = gsn_open_wks("png","monitor/" + model + "_all_regrid")
>      gsn_define_colormap(wks,"amwg")
>
>      res                       = True
>
>      res at gsnMaximize           = True              ; Maximize plot
>      res at gsnDraw               = False
>      res at gsnFrame              = False
>
>      res at cnLevelSelectionMode  = "ManualLevels"
>      res at cnMinLevelValF        =  230.
>      res at cnMaxLevelValF        =  300.
>      res at cnLevelSpacingF       =  10.
>
>      res at cnFillOn              = True              ; color plot desired
>      res at cnLinesOn             = False             ; turn off contour
> lines
>      res at cnFillMode            = "RasterFill"
>
>      res at lbLabelBarOn          = False
>
>      res at gsnPolar              = "NH"              ; specify the
> hemisphere
>      res at mpMinLatF             = 60.
>
>      res at trGridType            = "TriangularMesh"  ; allow missing
> coordinates
>
>
> ;---Plot original data
>      res at tiMainString = "Original "+model +" grid (" + \
>      str_join(tostring(dimsizes(var))," x ") + ")"
>
>      plot_orig1 = gsn_csm_contour_map_polar(wks,var(2,:,:),res)
>      plot_orig2 = gsn_csm_contour_map_polar(wks,var(8,:,:),res)
>
> ;---Plot regridded data
>      res at gsnAddCyclic = False
>      res at sfXArray     = lon2d
>      res at sfYArray     = lat2d
>
>      res at tiMainString = "Regridded to EASE grid (" + \
>      str_join(tostring(dimsizes(var_regrid))," x ") + ")"
>
>      plot_regrid1 = gsn_csm_contour_map_polar(wks,var_regrid(2,:,:),res)
>
>      plot_regrid2 = gsn_csm_contour_map_polar(wks,var_regrid(8,:,:),res)
>
>
> ;---Panel these two plots
>      pres                    = True
>      pres at gsnMaximize        = True
>      pres at gsnPanelLabelBar   = True
>      pres at pmLabelBarWidthF   = 0.9
>      pres at lbLabelFontHeightF = 0.01
>
>      gsn_panel(wks,(/plot_orig1,plot_regrid1,plot_orig2,
> plot_regrid2/),(/2,2/),pres)
>
>      delete( res )
>      delete( pres )
>
>    end if
>
>    ;; Clean up
>    delete( var )
>    delete( sfile )
>    delete( dSizes )
>    delete( Opt )
>    delete( time )
>    delete( filo )
>    delete( fo )
>    delete( var_regrid )
>
>  end do
>
>  delete( dfile )
>  delete( lat2d )
>  delete( lon2d )
>
> end
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170301/909742ec/attachment.html 


More information about the ncl-talk mailing list