[ncl-talk] Problem with ESMF_regrid

Tomoko Koyama Tomoko.Koyama at Colorado.EDU
Mon Nov 13 16:44:16 MST 2017


Thank you very much, Dennis.

I modified the script following your suggestion and it worked except for IPSL-CM5A-LR output.

The error message is the same:
“Assignment type mismatch, right hand side can't be coerced to type of left hand side” occurring at
var_regrid = ESMF_regrid(var,Opt)

Could you tell me what I miss?

Tomoko

+++++++++++++++++
+ Error message +
+++++++++++++++++

 Copyright (C) 1995-2015 - All Rights Reserved
 University Corporation for Atmospheric Research
 NCAR Command Language Version 6.3.0
 The use of this software is governed by a License Agreement.
 See http://www.ncl.ucar.edu/ for more details.

Variable: var
Type: float
Total Size: 6176395680 bytes
            1544098920 values
Number of Dimensions: 3
Dimensions and sizes:	[time | 56940] x [j | 149] x [i | 182]
Coordinates: 
            time: [ 0.5..56939.5]
            j: [1..149]
            i: [1..182]
Number Of Attributes: 13
  standard_name :	sea_ice_area_fraction
  long_name :	Sea Ice Area Fraction
  comment :	fraction of grid cell covered by sea ice.
  units :	%
  original_name :	ileadfra
  original_units :	1
  history :	2011-07-03T20:18:11Z altered by CMOR: Converted units from '1' to '%'. 2011-07-03T20:18:11Z altered by CMOR: replaced missing value flag (9.96921e+36) with standard missing value (1e+20).
  cell_methods :	time: mean (interval: 30 minutes)
  cell_measures :	area: areacello
  missing_value :	1e+20
  _FillValue :	1e+20
  associated_files :	baseURL: http://cmip-pcmdi.llnl.gov/CMIP5/dataLocation gridspecFile: gridspec_seaIce_fx_IPSL-CM5A-LR_historical_r0i0p0.nc areacello: areacello_fx_IPSL-CM5A-LR_historical_r0i0p0.nc
  coordinates :	lat lon
(0)	get_src_grid_info: source lat dims = (149)
(0)	get_src_grid_info: source lon dims = (182)
(0)	get_src_grid_info: source grid type is 'rectilinear'
(0)	curvilinear_to_SCRIP: calculating grid corners...
(0)	curvilinear_to_SCRIP: one or more lat values are at the
(0)	       poles, so calculating grid corners using
(0)	       calc_SCRIP_corners_boundaries...
(0)	calc_SCRIP_corners_boundaries
(0)	     min/max original lat: 1/149
(0)	     min/max original lon: 1/182
fatal:Assignment type mismatch, right hand side can't be coerced to type of left hand side

fatal:["Execute.c":8575]:Execute: Error occurred at or near line 770 in file $NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl


fatal:["Execute.c":8575]:Execute: Error occurred at or near line 1744 in file $NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl


fatal:["Execute.c":8575]:Execute: Error occurred at or near line 1822 in file $NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl


fatal:["Execute.c":8575]:Execute: Error occurred at or near line 3851 in file $NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl


fatal:["Execute.c":8575]:Execute: Error occurred at or near line 3983 in file $NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl


fatal:["Execute.c":8573]:Execute: Error occurred at or near line 88


++++++++++
+ Script +
++++++++++

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       = "IPSL-CM5A-LR"

rdiri       = "/work/koyama_sice"
in_diri     = "/home/koyama/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 ="/home/koyama/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
    if (model.eq."CCSM4" .or. model.eq."NorESM1-M") then	; See "get_src_grid_info"
      var at lat2d	= sfile->lat					; when lat dims is 2D,
      var at lon2d	= sfile->lon					; this if close is necessary
    end if							; ref. ESFM regrid - example 24

    printVarSummary( var )

    lat1d = ndtooned(lat2d)
    lon1d = ndtooned(lon2d)
    lon1d = where(lon1d.lt.0,360.0+lon1d,lon1d)
    latlon_dims = dimsizes(lat2d)                 ; 180x180
  
    Opt                 = True

    Opt at ForceOverwrite  = 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 SrcInputFileName    = srcGridFili          ; optional, but good idea
    Opt at DstInputFileName    = dstGridFili

    Opt at SkipSrcGrid    = False
    Opt at SkipDstGrid    = False
    Opt at SkipWgtGen     = False
    Opt at DstESMF        = True

    Indexes = ind(.not.ismissing(lon1d))     
    Opt at DstGridType    = "unstructured"         ; Destination grid
    Opt at DstGridLat     = lat1d(Indexes)         ; Strip off missing data
    Opt at DstGridLon     = lon1d(Indexes)

    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 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 SrcGridMask      = where(ismissing(var(0,:,:)),0,1)

    var_regrid = ESMF_regrid(var,Opt)   ; Regrid var

    copy_VarAtts(var,var_regrid)
    var_regrid at _FillValue = 1.e+20
    var_regrid at missing_value = 1.e+20
    var_regrid at _FillValue = var at _FillValue

    var_regrid!0 = "time"
    var_regrid!1 = "i"
    var_regrid!2 = "j"

    if (model.eq."CCSM4") then
      time    = ispan(1,dSizes(3),1)
    else
      time    = ispan(1,dSizes(0),1)
    end if
    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(srcGridDiri+"/"+filo) .eq. True ) then
      system( "rm " + filo )
    end if

    setfileoption("nc","Format","LargeFile")
    fo = addfile( srcGridDiri + "/" + filo,"c")
    fo->sic = var_regrid
    fo->lat = lat2d
    fo->lon = lon2d

    ;; Clean up
    delete( var )
    delete( time )
    delete( sfile )
    delete( Opt )
    delete( filo )
    delete( fo )
    delete( var_regrid )

  end do

  delete( dfile )
  delete( lat2d )
  delete( lon2d )

end


> On Nov 13, 2017, at 8:26 AM, Dennis Shea <shea at ucar.edu> wrote:
> 
> See: 
> https://www.ncl.ucar.edu/Applications/ESMF.shtml <https://www.ncl.ucar.edu/Applications/ESMF.shtml>
> Example 24
> 
> Make appropriate changes: use 'bilinear' only
> 
> Your source file has
>         coordinates : lat lon
> 
> replace
>     x at lat2d        = sfile->TLAT
>     x at lon2d        = sfile->TLONG
> 
> with 
> 
>     x at lat2d        = sfile->lat
>     x at lon2d        = sfile->lon
> Good luck
> 
> On Sun, Nov 12, 2017 at 2:13 PM, Tomoko Koyama <Tomoko.Koyama at colorado.edu <mailto:Tomoko.Koyama at colorado.edu>> wrote:
> Here’s what I can get with printVarSummary(var);
> 
> Variable: var
> Type: float
> Total Size: 3588096000 bytes
>             897024000 values
> Number of Dimensions: 3
> Dimensions and sizes:   [time | 7300] x [j | 384] x [i | 320]
> Coordinates:
>             time: [719050.5..726349.5]
>             j: [1..384]
>             i: [1..320]
> Number Of Attributes: 12
>   standard_name :       sea_ice_area_fraction
>   long_name :   Sea Ice Area Fraction
>   comment :     aice_d no change, CMIP5_table_comment: fraction of grid cell covered by sea ice.
>   units :       %
>   original_name :       aice_d
>   cell_methods :        time: mean (interval: 30 days)
>   cell_measures :       area: areacello
>   history :     2014-09-29T18:12:07Z altered by CMOR: replaced missing value flag (1e+30) with standard missing value (1e+20).
>   missing_value :       1e+20
>   _FillValue :  1e+20
>   associated_files :    baseURL: http://cmip-pcmdi.llnl.gov/CMIP5/dataLocation <http://cmip-pcmdi.llnl.gov/CMIP5/dataLocation> gridspecFile: gridspec_seaIce_fx_CCSM4_historical_r0i0p0.nc <http://secure-web.cisco.com/1yCwSrw2YG46U8ckJsCmEFAmOAIgvR9BcggFxjdaRI5vRMFbCqGU2zNh0Xia-YOHgWeEUBwnsdMPrDBBYdSVo3nzBfkl4QIQmyK0niwjRIg3zpnluAI5PK4lIbhMVFHrj7zUA_xSp1SSDuiJTdQYhH6Fgc8TsdfnjWNQ8fpLfa-AU8Avh6nXboPIO7m_0XYJj1aV15QK_o5JAVI5LoDWvqbNiJersJuWFOxpCYQMjeLRLxcwrGmGWTB47dOYhdcJxkgNjKzL3Wqkk9XK2FnklJX0nxPXQf8Trv0HJu0hktwWUK8JKqpHROboONkDKzFv0MmFfIwzCT8_xGXglOlgrx8BeOZ7D-nwKjF10lh7Semd1XWsARasZ3xai1BIKDl-lFl1KV0tM5LHBgqYeihAze7TvWCrujoV5-bYWq5EehnMRFZ-9L3piibDzcBzeYafR/http%3A%2F%2Fhistorical_r0i0p0.nc> areacello: areacello_fx_CCSM4_historical_r0i0p0.nc <http://secure-web.cisco.com/14ZCWlRncW_i1YOy3Yp1Q9P7Hqe9PfKa2yT6_03GLOp4VsLue11kVzLwOsYRyxQR0g0VHuI8Zf9RaQgt5_34knBeHVIZYD_P2M8NjAp8Z_TbE8kF0vDeSE7NNN6AyNJvMgs1YXEBfaugiKrdLbqZA6gjcl4UM3NWR19H98dOvUnG0QMJIXabYQTGEMEZ4rHBGzSje0oCZ719lTBnDY7yhEb9fDLtlMSOQgnNPdFHYGpaw6JyPlo7t-u7eJ-hR7cloVlGsMka_8ZIkegX7vF_VHBL55HtiX-IA5QxV2e2gjqcg57LY6j4J5104TsrzmFwFp7R7BcZqVDrAndaF5sUKPaF6LpR3bYIAlpWGkgOhsIfKfYmrrYhwBsgdXF2jMgrAjTq3ZPti8Y_9dq8LYPdve1yOOiTPDEY_c3qj8bUnI0FqZqptTU9te9RF4NZAY48m/http%3A%2F%2Fr0i0p0.nc>
>   coordinates : lat lon
> 
> Thank you,
> Tomoko
> 
> 
>> On Nov 12, 2017, at 9:02 AM, music piano <musicpianoljy at gmail.com <mailto:musicpianoljy at gmail.com>> wrote:
>> 
>> Hi, Tomoko
>> 
>> Would you try to use printVarSummary(var) to see what type of the data is ? 
>> 
>> On Sat, Nov 11, 2017 at 10:50 PM, Tomoko Koyama <Tomoko.Koyama at colorado.edu <mailto:Tomoko.Koyama at colorado.edu>> wrote:
>> Hello,
>> 
>> I am trying to regrid Sea Ice Area Fraction and Sea Ice Thickness data from some CMIP5 daily data to EASE 100km grid.
>> The following script works for Sea Level Pressure, Near-Surface Temperature, Geopotential Height etc. but not for those ice parameters.
>> 
>> The error message is “Assignment type mismatch, right hand side can't be coerced to type of left hand side” occurring at regridding;
>> var_regrid = ESMF_regrid(var,Opt)
>> 
>> Does anyone see why this might be???
>> 
>> Thank you in advance,
>> Tomoko
>> 
>> 
>> +++++++++++++++++
>> + Error message +
>> +++++++++++++++++
>> 
>> Copyright (C) 1995-2015 - All Rights Reserved
>>  University Corporation for Atmospheric Research
>>  NCAR Command Language Version 6.3.0
>>  The use of this software is governed by a License Agreement.
>>  See http://www.ncl.ucar.edu/ <http://www.ncl.ucar.edu/> for more details.
>> (0)     get_src_grid_info: source lat dims = (384)
>> (0)     get_src_grid_info: source lon dims = (320)
>> (0)     get_src_grid_info: source grid type is 'rectilinear'
>> (0)     curvilinear_to_SCRIP: calculating grid corners...
>> (0)     curvilinear_to_SCRIP: one or more lat values are at the
>> (0)            poles, so calculating grid corners using
>> (0)            calc_SCRIP_corners_boundaries...
>> (0)     calc_SCRIP_corners_boundaries
>> (0)          min/max original lat: 1/384
>> (0)          min/max original lon: 1/320
>> fatal:Assignment type mismatch, right hand side can't be coerced to type of left hand side
>> ^Mfatal:["Execute.c":8575]:Execute: Error occurred at or near line 770 in file $NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl
>> 
>> ^Mfatal:["Execute.c":8575]:Execute: Error occurred at or near line 1744 in file $NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl
>> 
>> ^Mfatal:["Execute.c":8575]:Execute: Error occurred at or near line 1822 in file $NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl
>> 
>> ^Mfatal:["Execute.c":8575]:Execute: Error occurred at or near line 3851 in file $NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl
>> 
>> ^Mfatal:["Execute.c":8575]:Execute: Error occurred at or near line 3983 in file $NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl
>> 
>> ^Mfatal:["Execute.c":8573]:Execute: Error occurred at or near line 86
>> 
>> ++++++++++
>> + Script +
>> ++++++++++
>> 
>> 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       = "CCSM4"
>> gridtype    = "latlon"
>> 
>> rdiri       = "/work/koyama_sice"
>> in_diri     = "/home/koyama/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 ="/home/koyama/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
>> 
>>     lat1d = ndtooned(lat2d)
>>     lon1d = ndtooned(lon2d)
>>     lon1d = where(lon1d.lt.0,360.0+lon1d,lon1d)
>>     latlon_dims = dimsizes(lat2d)                 ; 180x180
>> 
>>     Opt                 = True
>> 
>>     Opt at ForceOverwrite  = 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 SrcInputFileName    = srcGridFili          ; optional, but good idea
>>     Opt at DstInputFileName    = dstGridFili
>> 
>>     Opt at SkipSrcGrid    = False
>>     Opt at SkipDstGrid    = False
>>     Opt at SkipWgtGen     = False
>>     Opt at DstESMF        = True
>> 
>>     Indexes = ind(.not.ismissing(lon1d))
>>     Opt at DstGridType    = "unstructured"         ; Destination grid
>>     Opt at DstGridLat     = lat1d(Indexes)         ; Strip off missing data
>>     Opt at DstGridLon     = lon1d(Indexes)
>> 
>>     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 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 SrcGridMask      = where(ismissing(var(0,:,:)),0,1)
>> 
>>     var_regrid = ESMF_regrid(var,Opt)   ; Regrid var
>> 
>>     copy_VarAtts(var,var_regrid)
>>     var_regrid at _FillValue = 1.e+20
>>     var_regrid at missing_value = 1.e+20
>>     var_regrid at _FillValue = var at _FillValue
>> 
>>     var_regrid!0 = "time"
>>     var_regrid!1 = "i"
>>     var_regrid!2 = "j"
>> 
>>     time    = ispan(1,dSizes(3),1)      ; CCSM4
>>     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 <http://secure-web.cisco.com/1qp3lTKKuGOiRenNSV2mBVPtaoJvr4FX79fNvr1SHNiH45LiiRgo791rBK5WvVJ328_9O9negnRBCXH87H-TT4hFZFC1Jx2Gv7S--nVCvs6J0xREDrJzfEWPXiFW0ZsKtPsAQY3KT5kCR2tSWv9ApyU_7pLbFlMoQoVPcHXKt28S2KbzbcZLHQW2uwsMY_9X1pYYswOB1CkCT8ykYCmwxrzjA3upf-XiQssRxyO-Hcq3GROvwl6HS6cRm8ADD85jf4dqfHXti59WTN27GCubmYXCahfUApc1vwD37weD2iAORkRo21fwXdt2L5agRiKwr_942CeBi4j5MClyorMHhE3J-G1fR5XRcSN3wOaf09LYw2mDSo2Lv64Q-tgRyuNz5JQkuXP8nMW1nYnEeI56nyx4oAO94r5Pl1Wt9GdAME62yUUhdRJKL9xMorz0xxBS1/http%3A%2F%2Frgrd.nc>"
>> 
>>     if ( isfilepresent(srcGridDiri+"/"+filo) .eq. True ) then
>>       system( "rm " + filo )
>>     end if
>> 
>>     setfileoption("nc","Format","LargeFile")
>>     fo = addfile( srcGridDiri + "/" + filo,"c")
>>     fo->var = var_regrid
>>     fo->lat = lat2d
>>     fo->lon = lon2d
>> 
>>     ;; Clean up
>>     delete( var )
>>     delete( sfile )
>>     delete( Opt )
>>     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 <mailto:ncl-talk at ucar.edu>
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk <http://mailman.ucar.edu/mailman/listinfo/ncl-talk>
>> 
> 
> 
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu <mailto:ncl-talk at ucar.edu>
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk <http://mailman.ucar.edu/mailman/listinfo/ncl-talk>
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20171113/b2f69f48/attachment.html>


More information about the ncl-talk mailing list