Re: Regridding 2-D lat/lons with the linint2 function

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Tue Feb 04 2014 - 15:05:15 MST

I ran the attached script and had no problems.

Weight file is at:

ftp ftp.cgd.ucar.edu
anonymous
email
cd pub/shea/ESMF
get hycom-cice_ARCu0.bilinear.nc
quit

Good luck

On 02/03/2014 11:17 PM, Gregory Deemer wrote:
> Hi Mary or others,
>
> Thanks for guiding me towards these regridding methods. I did have
> success with one of my datasets using rcm2rgridWrap, but my data on an
> EASE grid has proven to be too curvy for that function. I have followed
> the ESMF_regrid_8.ncl example in formulating my own regridding routine.
>
> I am getting a couple of odd errors referring to "malloc", which I've
> read is related to insufficient memory, but I am on a 64-bit system and
> my input files are not that large. Please have a look at the debug
> output below:
>
> Copyright (C) 1995-2013 - All Rights Reserved
>
> University Corporation for Atmospheric Research
>
> NCAR Command Language Version 6.1.2
>
> The use of this software is governed by a License Agreement.
>
> See http://www.ncl.ucar.edu/ for more details.
>
> (0)write_grid_description: source lat dims = (448,304)
>
> (0)write_grid_description: source lon dims = (448,304)
>
> (0)write_grid_description: 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: 31.1027/89.8368
>
> (0) min/max original lon: 0.192267/360
>
> (0)calc_SCRIP_corners_noboundaries
>
> (0) min/max Extlat2d: 30.8581/89.8368
>
> (0) min/max Extlon2d: -359.615/360.192
>
> (0)calc_SCRIP_corners_noboundaries
>
> (0) min/max ExtGridCenter_lat: 30.9805/89.8368
>
> (0) min/max ExtGridCenter_lon: -89.6148/360.001
>
> (0)write_grid_description: destination lat dims = (876)
>
> (0)write_grid_description: destination lon dims = (751)
>
> (0)write_grid_description: destination grid type is 'rectilinear'
>
> (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: 40/75
>
> (0) min/max original lon: 160/220
>
> (0)calc_SCRIP_corners_noboundaries
>
> (0) min/max Extlat2d: 39.96/75.04
>
> (0) min/max Extlon2d: 159.92/220.08
>
> (0)calc_SCRIP_corners_noboundaries
>
> (0) min/max ExtGridCenter_lat: 39.98/75.02
>
> (0) min/max ExtGridCenter_lon: 159.96/220.04
>
> (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
> <http://source_grid_file.nc> --destination destination_grid_file.nc
> <http://destination_grid_file.nc> --weight weights_file.nc
> <http://weights_file.nc> --method bilinear --src_regional --dst_regional
> -i --64bit_offset'
>
> (0)--------------------------------------------------
>
> ESMF_RegridWeightGen(3987,0x7fff7ad36310) malloc: *** error for object
> 0x10116c6a0: pointer being freed was not allocated
>
> *** set a breakpoint in malloc_error_break to debug
>
> (0)ESMF_regrid_gen_weights: output from 'ESMF_RegridWeightGen':
>
> (0) missing
>
> (0)--------------------------------------------------
>
> fatal:The result of the conditional expression yields a missing value.
> NCL can not determine branch, see ismissing function
>
> fatal:["Execute.c":8128]:Execute: Error occurred at or near line 2291 in
> file $NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl
>
>
> fatal:["Execute.c":8128]:Execute: Error occurred at or near line 3166 in
> file $NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl
>
>
> fatal:["Execute.c":8128]:Execute: Error occurred at or near line 54 in
> file GodMerg_ESMF_Regrid_v04.ncl
>
>
> I have also attached my script, in case that is helpful in solving the
> issue.
>
> Thank you,
> Greg
>
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> - - - - - - - - - -
>
> Gregory J. Deemer
> Graduate Research Assistant
> Department of Atmospheric Sciences
> University of Alaska Fairbanks
> IARC 338K
> Office: (907) 474-5430 <tel:%28907%29%20474-5430>
> Cell: (907) 750-1063 <tel:%28907%29%20750-1063>
>
>
>
> On Tue, Jan 21, 2014 at 1:54 PM, Mary Haley <haley@ucar.edu
> <mailto:haley@ucar.edu>> wrote:
>
> Hi Greg,
>
> You have a curvilinear grid (2D lat/lon grid) and the "linint2"
> function only works on rectilinear grids (those with 1D coordinate
> arrays). This is why you are getting an error about xi being the
> wrong size. It's expecting a 1D array for xi (longitude).
>
> If your curvilinear grid is not too "curvy", then may want to look
> at rcm2rgrid_Wrap", which goes from a curvilinear grid to a
> rectilinear grid.
>
> http://www.ncl.ucar.edu/Document/Functions/Contributed/rcm2rgrid_Wrap.shtml
>
> If rcm2rgrid_Wrap doesn't work for you, then you may want to look at
> ESMF_regrid, which is a little more complicated, but gives you more
> flexibility with grid types and interpolation methods.
>
> We have a whole page of ESMF regridding examples:
>
> http://www.ncl.ucar.edu/Applications/ESMF.shtml
>
> My suggestion is to look at examples that are going from curvilinear
> grids to rectilinear grids, like:
>
> ESMF_regrid_6.ncl
> ESMF_regrid_7.ncl
> ESMF_regrid_8.ncl
> ESMF_regrid_24.ncl
>
> I think that ESMF_regrid_8.ncl might be your best bet, because it's
> one of the few where the rectilinear grid being regridded to is read
> off a file. The others tend to just regrid to a predefined grid,
> like "0.5 deg" or "1x1".
>
> --Mary
>
> On Jan 18, 2014, at 6:48 PM, Gregory Deemer <gjdeemer@alaska.edu
> <mailto:gjdeemer@alaska.edu>> wrote:
>
> > Hello,
> >
> > I have two sea - ice models with limited domains and differing
> grids that I will be using in a validation analysis. The model with
> the coarser grid is an arctic cap model over the circumpolar region
> from 90 degrees_north down to a latitude of 49 degrees_north. The
> dimensions of this arctic cap grid are: [ lat | 120] x [ lon | 360].
> Each latitude and longitude value per grid cell is unique, in
> generalized curvilinear coordinates. This results in a 2-D latitude
> array and a 2-D longitude array.
> >
> > I'm wishing to regrid the aforementioned arctic cap model in a
> region that overlaps with a higher-resolution model enveloping the
> Bering, Chukchi, and Beaufort Seas. The regional model domain spans
> 45 to 75 degrees_north latitude and 160 to 220 degrees_east
> longitude. The dimensions of the regional grid over the region are:
> [lat | 876] x [lon | 751]. This grid is rectangular and can be
> represented by 1-D latitude and longitudes arrays.
> >
> > From reading over the various regridding routines available
> through NCL, I've determined that the linint2 function is
> appropriate and can handle this transformation.
> >
> > The code that I have started putting together for this task is as
> follows:
> >
> >
> ;**********************************************************************
> > ; PIOMAS regridding script.
> > ; - Regrid PIOMAS down to the ACNFS resolution.
> > ;
> > ; Created 01/17/2014
> >
> ;**********************************************************************
> >
> > 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/csm/shea_util.ncl"
> >
> > begin
> > ; - - - Read in PIOMAS ice thickness climatology
> > ClimateFile = "1979-2000_PIOMAS_Climatology_.nc"
> > ClimatePath = "/Volumes/OLD_GREG/Research/Validation
> Data/PIOMAS/Climatology/"
> > PIOMAS = addfile(ClimatePath + ClimateFile, "r")
> >
> > ; - - - Assign variables to file objects
> > hi = PIOMAS->hi(0,:,:)
> > lat = PIOMAS->lat(:,:)
> > lon = PIOMAS->lon(:,:)
> >
> > printVarSummary(hi)
> > printVarSummary(lat)
> > printVarSummary(lon)
> >
> > ; - - - Create new grid dimensions to match ACNFS
> > minlon = 160
> > maxlon = 220
> > lonnum = 751
> > minlat = 40
> > maxlat = 75
> > latnum = 876
> >
> > newlat = fspan(minlat, maxlat, latnum)
> > newlon = fspan(minlon, maxlon, lonnum)
> >
> > ; - - - Regrid with linint2 function
> > new_hi = linint2(lon,lat, hi, False, newlon, newlat,0)
> >
> > end
> >
> > The variable summaries and error message that I receive from this
> code is this:
> >
> > Variable: hi
> > Type: double
> > Total Size: 345600 bytes
> > 43200 values
> > Number of Dimensions: 2
> > Dimensions and sizes: [lat | 120] x [lon | 360]
> > Coordinates:
> > Number Of Attributes: 5
> > time : 0
> > standard_name : sea_ice_thickness
> > units : m
> > _FillValue : -9999
> > missing_value : -9999
> >
> > Variable: lat
> > Type: double
> > Total Size: 345600 bytes
> > 43200 values
> > Number of Dimensions: 2
> > Dimensions and sizes: [lat | 120] x [lon | 360]
> > Coordinates:
> > Number Of Attributes: 3
> > standard_name : latitude
> > units : degrees_north
> > axis : Y
> >
> > Variable: lon
> > Type: double
> > Total Size: 345600 bytes
> > 43200 values
> > Number of Dimensions: 2
> > Dimensions and sizes: [lat | 120] x [lon | 360]
> > Coordinates:
> > Number Of Attributes: 3
> > standard_name : longitude
> > units : degrees_east
> > axis : X
> > fatal:linint2: If xi is not one-dimensional, then it must have
> one less dimension than fi
> >
> > Two questions here:
> > 1) Why is there no list of coordinate variables and values after
> "Coordinates:"? - Does this have something to do with the 2-D
> latitude and longitude arrays?
> >
> > 2) How do I address the fatal error here? My first guess was to
> change dimension of my ice thickness variable, hi, to [time | 366] x
> [lat | 120] x [lon | 360] instead of bringing in one slice along the
> time dimension. I did this by changing the line of code that
> assigned my ice thickness data.
> >
> > old: hi = PIOMAS->hi(0,:,:)
> > new: hi = PIOMAS->hi
> >
> > This then resulted in a new fatal error stating:
> >
> > fatal:linint2: If xi is not one-dimensional, then its leftmost
> dimensions must be the same as the leftmost dimensions of fi
> >
> > This error I am not quite able to interoperate. It seems that I
> need to switch the ordering of my array to lon x time x lat, which
> sounds unreasonable.
> >
> > Thank you for the help,
> > Greg
> >
> > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> - - - - - - - - - - - - -
> >
> > Gregory J. Deemer
> > Graduate Research Assistant
> > Department of Atmospheric Sciences
> > University of Alaska Fairbanks
> > IARC 338K
> > Office: (907) 474-5430 <tel:%28907%29%20474-5430>
> > Cell: (907) 750-1063 <tel:%28907%29%20750-1063>
> >
> > _______________________________________________
> > ncl-talk mailing list
> > List instructions, subscriber options, unsubscribe:
> > http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
>
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk

Received on Tue Feb 4 15:05:37 2014

This archive was generated by hypermail 2.1.8 : Mon Mar 03 2014 - 14:26:18 MST