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

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Tue Jan 21 2014 - 15:54:31 MST

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> 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
> Cell: (907) 750-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
Received on Tue Jan 21 15:54:38 2014

This archive was generated by hypermail 2.1.8 : Tue Jan 21 2014 - 15:57:30 MST