[ncl-talk] Why the source grid be recognized as curvilinear grid?

Mary Haley haley at ucar.edu
Mon Dec 19 14:55:28 MST 2016


Lin,

I believe your problem is with these two lines:

    thetao at lat2d = sfile->lat
    thetao at lon2d = sfile->lon

The lat2d/lon2d are special attributes used by the ESMF_regrid function to
pass in 2D curvilinear coordinates. If your data is rectilinear, then this
usually implies that the 1D lat/lon coordinate arrays are already attached
to the data, and you should NOT be setting these lat2d/lon2d coordinates.
This just confuses the ESMF_regrid routine.

You will need to put an "if" test in your code to test if the incoming
lat/lon grid is rectilinear or curvilinear, and only set lat2d/lon2d if
it's curvilinear.

You might want to create a function, call it "is_rectilinear" that looks
something like this:

function is_rectilinear(data)
local rank, latdim, londim
begin
  rank = dimsizes(dimsizes(data))
  if(rank.ge.2) then
    latdim = rank-2
    londim = rank-1

if((.not.ismissing(thetao!latdim).and.iscoord(thetao,thetao!latdim)).and.\
       (.not.ismissing(thetao!londim).and.iscoord(thetao,thetao!londim)))
then
      return(True)
    end if
  end if
  return(False)
end

and then in your main code:

    if(.not.is_rectilinear(thetao)) then
      thetao at lat2d = sfile->lat
      thetao at lon2d = sfile->lon
    end if

Note that the "is_rectilinear" code is assuming that your rightmost two
dimensions are lat x lon. If this assumption is not correct, then you may
need to further edit this function to perhaps add a check that the "units"
are valid, say, "degrees_east" for longitude coordinates, and
"degrees_north" for latitude coordinates.

--Mary


On Mon, Dec 19, 2016 at 3:54 AM, 林祥 <xianglin72 at icloud.com> wrote:

> i’ve resolved the problem. Thanks!
>
>
>
>
>
>
>
> 在 2016年12月19日,01:14,林祥 <xianglin72 at icloud.com> 写道:
>
> Hi, all
>
>     I’m regridding multiple CMIP5 model output with ESMF_regrid function,
>  among all the data file, lat/lon coordinate array  can be 1-dimension or 2
> dimension.
>
> Now I met a problem ,  Please see the below message output from the
> scripts:
>
>
> (0) 4.     /data1/linx/CMIP5_SIC/historical/BNU-ESM/sic_OImon_
> BNU-ESM_historical_r1i1p1_185001-200512.nc    ; ( Loop 4 )
>
>
> Variable: Opt
> Type: logical
> Total Size: 4 bytes
>             1 values
> Number of Dimensions: 1
> Dimensions and sizes: [1]
> Coordinates:
> Number Of Attributes: 9
>   Debug : True
>   PrintTimings : True
>   DstGridLon : <ARRAY of 360 elements>
>   DstGridLat : <ARRAY of 180 elements>
>   DstGridMask : <ARRAY of 64800 elements>
>   SrcGridMask : <ARRAY of 72000 elements>
>   ForceOverwrite : True
>   DstFileName : destination_grid_file.nc
>   SrcFileName : source_grid_file.nc
> (0) True
> (0) Generating interpolation weights from CMIP5 to
> (0) World 1 degree grid using the bilinear method.
> (0) get_src_grid_info: source lat dims = (200,360)
> (0) get_src_grid_info: source lon dims = (200,360)
> (0) get_src_grid_info: source grid type is 'curvilinear'
> (0) curvilinear_to_SCRIP: calculating grid corners...
> (0) curvilinear_to_SCRIP: no lat values are at the poles, so
> (0)       calculating grid corners using
> (0)       calc_SCRIP_corners_noboundaries...
> (0) calc_SCRIP_corners_noboundaries
> (0)     min/max original lat: -81.5003/89.4879
> (0)     min/max original lon: 0.0457764/359.949
> (0) calc_SCRIP_corners_noboundaries
> (0)     min/max Extlat2d: -82.5003/90.4798
> (0)     min/max Extlon2d: -358.806/360.995
> (0) calc_SCRIP_corners_noboundaries
> (0)     min/max ExtGridCenter_lat: -82.0003/89.9838
> (0)     min/max ExtGridCenter_lon: -179.22/360.397
> (0) =====> CPU Elapsed Time: curvilinear_to_SCRIP: 0.164974 seconds <=====
> (0) get_dst_grid_info: destination lat dims = (180)
> (0) get_dst_grid_info: destination lon dims = (360)
> (0) curvilinear_to_SCRIP: calculating grid corners...
> (0) curvilinear_to_SCRIP: no lat values are at the poles, so
> (0)       calculating grid corners using
> (0)       calc_SCRIP_corners_noboundaries...
> (0) calc_SCRIP_corners_noboundaries
> (0)     min/max original lat: -89.5/89.5
> (0)     min/max original lon: -179.5/179.5
> (0) calc_SCRIP_corners_noboundaries
> (0)     min/max Extlat2d: -90.5/90.5
> (0)     min/max Extlon2d: -180.5/180.5
> (0) calc_SCRIP_corners_noboundaries
> (0)     min/max ExtGridCenter_lat: -90/90
> (0)     min/max ExtGridCenter_lon: -180/180
> (0) =====> CPU Elapsed Time: rectilinear_to_SCRIP: 0.155979 seconds <=====
> (0) ESMF_regrid_gen_weights: number of processors used: 1
> (0) --------------------------------------------------
> (0) ESMF_regrid_gen_weights: the following command is about to be
> executed on the system:
> (0) 'ESMF_RegridWeightGen --source source_grid_file.nc --destination
> destination_grid_file.nc --weight ESMF_regrid_wgt_bilinear.nc --method
> bilinear -i'
> (0) --------------------------------------------------
> (0) ESMF_regrid_gen_weights: output from 'ESMF_RegridWeightGen':
> (0)       Starting weight generation with these inputs:
> (1)         Source File: source_grid_file.nc
> (2)         Destination File: destination_grid_file.nc
> (3)         Weight File: ESMF_regrid_wgt_bilinear.nc
> (4)         Source File is in SCRIP format
> (5)         Source Grid is a global grid
> (6)         Source Grid is a logically rectangular grid
> (7)         Destination File is in SCRIP format
> (8)         Destination Grid is a global grid
> (9)         Destination Grid is a logically rectangular grid
> (10)         Regrid Method: bilinear
> (11)         Pole option: ALL
> (12)         Ignore unmapped destination points
> (13)
> (14)       Completed weight generation successfully.
> (15)
> (0) --------------------------------------------------
> (0) ESMF_regrid_gen_weights: 'ESMF_RegridWeightGen' was successful.
> (0) =====> CPU Elapsed Time: ESMF_regrid_gen_weights: 0.0169983 seconds
> <=====
> (0) ESMF_regrid_with_weights: regridding using interpolation weights ...
> (0) ESMF_regrid_with_weights: warning: destination grid is not
> (0)     completely covered by the source grid. This is not an error.
> (0)     It just means your destination grid covers a larger area
> (0)     than your source grid.
> (0) ESMF_regrid_with_weights: Source Grid:
> (0)                           rank:      2
> (0)                           dimensions: 200 360
> (0)                           original source rank: 3
> (0)                           latitude min/max: -81.50032043457031/89.
> 48786163330078
> (0)                           longitude min/max:0.0457763671875/359.
> 9493103027344
> (0) ESMF_regrid_with_weights: Destination Grid:
> (0)                           dimensions: 180 360
> (0)                           latitude min/max: -89.5/89.5
> (0)                           longitude min/max:-179.5/179.5
> (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: dstData
> (0)                           Dimensions: 1872 180 360
> (0)                           minSrcData: 0
> (0)                           maxSrcData: 99.9994
> (0)                           minDstData: -2.50832e-12
> (0)                           maxDstData: 99.9981
> (0) =====> CPU Elapsed Time: ESMF_regrid_with_weights: 122.265 seconds
> <=====
>
> Variable: thetao_regrid
> Type: float
> Total Size: 485222400 bytes
>             121305600 values
> Number of Dimensions: 3
> Dimensions and sizes: [time | 1872] x [lat | 180] x [lon | 360]
> Coordinates:
>             time: [15.5..56924.5]
>             lat: [89.5..-89.5]
>             lon: [-179.5..179.5]
> Number Of Attributes: 11
>   remap : remapped via ESMF_regrid_with_weights: Bilinear remapping
>   standard_name : sea_ice_area_fraction
>   long_name : Sea Ice Area Fraction
>   comment : fraction of grid cell covered by sea ice.
>   units : %
>   cell_methods : time: mean
>   cell_measures : area: areacello
>   history : 2012-04-01T10:38:11Z 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_BNU-ESM_
> historical_r0i0p0.nc areacello: areacello_fx_BNU-ESM_historical_r0i0p0.nc
> warning:lbLabelBrOn is not a resource in the given object
> warning:lbLabelBrOn is not a resource in the given object
>
> ; it’s ok for the curvilinear grid to rectilinear grid for Loop 4
>
>
> (0) 5.     /data1/linx/CMIP5_SIC/historical/CanCM4/sic_OImon_
> CanCM4_historical_r1i1p1_196101-200512.nc
>
>
> Variable: Opt
> Type: logical
> Total Size: 4 bytes
>             1 values
> Number of Dimensions: 1
> Dimensions and sizes: [1]
> Coordinates:
> Number Of Attributes: 9
>   Debug : True
>   PrintTimings : True
>   DstGridLon : <ARRAY of 360 elements>
>   DstGridLat : <ARRAY of 180 elements>
>   DstGridMask : <ARRAY of 64800 elements>
>   SrcGridMask : <ARRAY of 8192 elements>
>   ForceOverwrite : True
>   DstFileName : destination_grid_file.nc
>   SrcFileName : source_grid_file.nc
> (0) True
> (0) Generating interpolation weights from CMIP5 to
> (0) World 1 degree grid using the bilinear method.          ;
> ************************************************************
> (0) get_src_grid_info: source lat dims = (64)              ; the lat
> coordinate of source data is 1-dimension
> (0) get_src_grid_info: source lon dims = (128)
> (0) get_src_grid_info: source grid type is ‘curvilinear’    ; but
> recognized as “curvilinear” and report error as below
>                                                                 ;
> *************************************************
>
> fatal:Number of dimensions in parameter (1) of (curvilinear_to_SCRIP) is
> (1), (2) dimensions were expected
> fatal:["Execute.c":8567]:Execute: Error occurred at or near line 3320 in
> file $NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl
>
> fatal:["Execute.c":8567]:Execute: Error occurred at or near line 3427 in
> file $NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl
>
> fatal:["Execute.c":8567]:Execute: Error occurred at or near line 147 in
> file esmf_regrid_6_sic.ncl
>
>
>
> Thank!
>
>
> Lin
>
> <esmf_regrid_6_sic.ncl>
>
>
>
>
> _______________________________________________
> 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/20161219/9c651623/attachment.html 


More information about the ncl-talk mailing list