[ncl-talk] Problem with ESMF_regrid
Dennis Shea
shea at ucar.edu
Mon Nov 13 08:26:18 MST 2017
See:
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>
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 gridspecFile: gridspec_seaIce_fx_CCSM4_
> historical_r0i0p0.nc areacello: areacello_fx_CCSM4_historical_r0i0p0.nc
> coordinates : lat lon
>
> Thank you,
> Tomoko
>
>
> On Nov 12, 2017, at 9:02 AM, music piano <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> 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/ 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
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>
>
>
> _______________________________________________
> 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/20171113/887bb14b/attachment.html>
More information about the ncl-talk
mailing list