Re: Regridding from low to high resolution ?

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Thu Jun 14 2012 - 07:48:38 MDT

Hi Madeleine,

When people post to ncl-talk, we ask that they don't also CC other NCL developers. This may cause multiple people to work on your problem.

We do appreciate that you posted to ncl-talk, and not to an NCL developer only.

You are missing a "begin" after the "function" declaration.

In general, I would recommend not putting a function declaration right in the middle of your main program. It's cleaner to do it like this:

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"

undef("regrid_cat")
function regrid_cat(clat[*],clon[*],pctpft[*][*],tlat[*],tlon[*]) ; categorical grid and target grid
begin
testd=grid2triple(clon,clat,pctpft) ; testd(3,ld)
pctpftnew = triple2grid(testd(0,:),testd(1,:),testd(2,:),tlon,tlat,False)

copy_VarAtts(pctpft,pctpftnew) ;contributed.ncl
cnew!0 = "lat"
cnew!1 = "lon"
cnew&lat =tlat
cnew&lon =tlon

return(pctpftnew)
end

begin

setfileoption("nc","SuppressClose",False)

in1 = addfile("pft_file1.nc","r")

pctpft = in1->PCT_PFT

clat=90
clon=144
tlat=360
tlon=720
. . .

end

--Mary

On Jun 13, 2012, at 2:56 PM, Madeleine Patterson wrote:

> Hi Dennis,
>
> I am trying to implement your regridding script that you suggested a while ago but am having trouble -could I get some advice? I get an error message 'syntax error before or near testd...possibly expecting a begin or local'. My script is below.
>
> Thanks,
> Madeleine.
>
> ************************************************
>
> begin
>
> 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"
>
> setfileoption("nc","SuppressClose",False)
>
> in1 = addfile("pft_file1.nc","r")
>
> pctpft = in1->PCT_PFT
>
> clat=90
> clon=144
> tlat=360
> tlon=720
>
> undef("regrid_cat")
> function regrid_cat(clat[*],clon[*],pctpft[*][*],tlat[*],tlon[*]) ; categorical grid and target grid
>
> testd=grid2triple(clon,clat,pctpft) ; testd(3,ld)
> pctpftnew = triple2grid(testd(0,:),testd(1,:),testd(2,:),tlon,tlat,False)
>
> copy_VarAtts(pctpft,pctpftnew) ;contributed.ncl
> cnew!0 = "lat"
> cnew!1 = "lon"
> cnew&lat =tlat
> cnew&lon =tlon
>
> return(pctpftnew)
> end
>
> ************************************************
>
>
> On Thu, Apr 19, 2012 at 3:21 AM, Dennis Shea <shea@ucar.edu> wrote:
> For categorical data, bilinear interpolation is likely not
> appropriate. Consider vegland_1 at
>
> http://www.ncl.ucar.edu/Applications/classification.shtml
>
> If the target grid point is in the middle of 4 points with
> categories 16, 10, 1, 2 then bilinear interpolation would
> yield 29/4 -> 7.25 -> 7. It is highly unlikely that this
> would be the case.
>
> Though slow, I would suggest a 2-step procedure
>
> [1] http://www.ncl.ucar.edu/Document/Functions/Built-in/grid2triple.shtml
>
> to convert the source grid to a triplet.
>
> [2] then
>
> http://www.ncl.ucar.edu/Document/Functions/Built-in/triple2grid.shtml
>
>
> ===
> untested ...
>
>
> undef("regrid_cat")
> function regrid_cat (clat[*], clon[*], cgrid[*][*] \ ; categorical grid
> ,tlat[*], tlon[*]) ; target grid
>
> begin
> d = grid2triple (clon,clat,cgrid) ; d(3,ld)
> cnew = triple2grid(d(0,:), d(1,:), d(2,:), tlon, tlat, False)
>
> copy_VarAtts(cgrid, cnew) ; contributed.ncl
> cnew!0 = "lat"
> cnew!1 = "lon"
> cnew&lat = tlat
> cnew&lon = tlon
>
> return( cnew )
> end
>
>
>
> On 4/18/12 9:17 AM, Noel Aloysius wrote:
> You can use CDO tools to do this, somthing like
>
> cdo remapbil,1x1grid_target.txt infile.nc <http://infile.nc>
> outfile.nc <http://outfile.nc>
>
>
> where remapbil does bilinear interpolation (and remapbic is for
> bicubic), 1x1grid_target.txt is the user input file with grid size
> information.
>
> Noel
>
>
> On Wed, Apr 18, 2012 at 11:08 AM, Madeleine Patterson
> <madeleine.patterson77@gmail.com
> <mailto:madeleine.patterson77@gmail.com>> wrote:
>
> Hi All,
>
> I was wondering if there is a low-to-high-resolution function for
> regridding a global map of a categorical variable?
>
> I found all the regridding scripts but they all employ
> interpolation, whereas I just want to 'pixelate' a 2x2.5 deg map to
> a 0.5 x 0.5 degree map...
>
> Does NCL have a function which will do this?
>
> Thanks
>
> M
>
> _______________________________________________
> 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

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu Jun 14 07:49:02 2012

This archive was generated by hypermail 2.1.8 : Fri Jun 15 2012 - 14:51:31 MDT