Re: Regridding from low to high resolution ?

From: Hobbs, Will R (3244-Affiliate) <William.R.Hobbs_at_nyahnyahspammersnyahnyah>
Date: Fri Jul 06 2012 - 13:46:25 MDT

Madeleine

In your argument for the function regrid_cat(), you specify the input variable pctpftN as having two dimensions (i.e. pctpftN[*][*]).

Hope that helps

Will

**********************************************************
Will Hobbs, Ph.D. William.R.Hobbs@jpl.nasa.gov
Jet Propulsion Laboratory
4800 Oak Grove Dr. office: 300-324a
M/S 300-323 phone: (818) 354-0466
Pasadena, CA 91109 fax: (818) 354-0966
**********************************************************

From: Madeleine Patterson <madeleine.patterson77@gmail.com<mailto:madeleine.patterson77@gmail.com>>
Date: Sat, 7 Jul 2012 05:40:57 +1000
To: ncl-talk <ncl-talk@ucar.edu<mailto:ncl-talk@ucar.edu>>
Subject: Re: Regridding from low to high resolution ?

Hi,
I am still trying to implement some script ideas that Mary Haley suggested I try in order to regrid categorical data from low to high resolution, but I cannot get the grid2triple() function -which I'm using to create a regrid function, let alone the actual regrid function - to work with 3 dimensions of data -even with do loops... I keep getting error messages telling me it's expecting 2 dims when I'm giving it 3:

fatal:Number of subscripts do not match number of dimensions of variable,(3) Subscripts used, (2) Subscripts expected
fatal:Execute: Error occurred at or near line 23 in file changedims.ncl
fatal:Execute: Error occurred at or near line 75 in file changedims.ncl

I am wondering if I am implementing the do loop with the wrong syntax, or if there is something else wrong with my script (below)?
Can anyone suggest a way to get grid2triple to work with a 3D input dataset?

Thanks for your advice...

MP

********************************************************************************
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[*],pctpftN[*][*],tlat[*],tlon[*]) ; categorical grid and target grid
local testd, pctpftNnew

begin

do i=1,10
testd=grid2triple(clon,clat,pctpftN(i,:,:)) ; testd(3,ld)
end do

pctpftNnew = triple2grid(testd(0,:),testd(1,:),testd(2,:),tlon,tlat,False)
copy_VarAtts(pctpftN,pctpftNnew) ;contributed.ncl
return(pctpftNnew)

end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; main code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
begin

in1 = addfile("pctpft.nc<http://pctpft.nc>","r")
pctpft = in1->PCTPFT
pctpftN = pctpft(0,:,:,:)

printVarSummary(pctpftN)

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

ntim =dimsizes(pctpftN(:,0,0))
nlat =dimsizes(tlat)
nlon = dimsizes(tlon)

pctpftNnew=new((/ntim,nlat,nlon/),typeof(pctpftN))
;pctpft_regrid=new((/ntim,nlat,nlon/),typeof(pctpftN))

do i=0,ntim-1

pctpftNnew(i,:,:) = regrid_cat(clat,clon,pctpftN(i,:,:),tlat,tlon) ; categorical grid and target grid

end do

end
********************************************************************************

On Tue, Jun 19, 2012 at 2:33 AM, Mary Haley <haley@ucar.edu<mailto:haley@ucar.edu>> wrote:
Hi Madeleine,

You will need to add a "do" loop and call grid2triple for each element of that third dimension. I'm not sure why grid2triple doesn't allow for multiple leftmost dimensions. I'll look into this.

Meanwhile, maybe something like this:

  ntim = dimsizes(pctpft(:,0,0))
  nlat = dimsizes(tlat)
  nlon = dimsizes(tlon)

  xregrid = new( (/ntim,nlat,nlon/), typeof(pctpft))

  do i=0,ntim-1
    xregrid(i,:,:) = regrid_cat(clon,clat,pctpft(i,:,:),tlat,tlon)
  end do

I don't know what "regrid_cat" looks like, so I'm not sure this is the correct syntax. Perhaps the creation of "xregrid" and the "do" loop should be moved into "regrid_cat".

--Mary

On Jun 15, 2012, at 10:23 AM, Madeleine Patterson wrote:

> Hi Mary,
>
> Thanks for your response - I am trying to get the regridding function I created to work; I've tried your code but I get an error message:
>
> fatal: number of dimensions in parameter (2) or (regrid_cat) is (3), (2) dimensions were expected
>
> So I tried putting the regrid function into a do loop so I can loop over all 10 pfts...
>
> do i=1,10
> xregrid = regrid_cat(clon,clat,pctpft(i,:,:),tlat,tlon) ;;;; (this may well be incorrect syntax)
> end do
>
> but then I get the error message :
>
> fatal: grid2triple : the last input array must be dimensioned ny x mx where ny is the length of y and mx is the length of x
>
> - so in my function definition testd=grid2triple(clon,clat,pctpft), it's saying pctpft must be 2 dimensional, not 3 dimensional (which it is).
>
> How to get around this? Would I have to read in each pft as one 2d variable, perform the regridding then reconstruct the 3d netcdf file, or is there an easier solution?
>
> thanks,
>
> M.P.

_______________________________________________ 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 Fri Jul 6 13:47:08 2012

This archive was generated by hypermail 2.1.8 : Thu Jul 12 2012 - 10:16:50 MDT