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