[Thread Prev][Thread Next][Index]

Re: [ferret_users] indefinite integral, axis, regrid and context

Hi Billy,

Thanks you! This is a nice workaround.

I was aware of the way Ferret realizes an _expression_. But I don't understand, as you pointed out, the latest grid at the point of _expression_ (re-)evaluation is that of "basin". Haven't I regridded this variable basin onto the wind grid in the if-then masking command defining the variable psi_pac?


On Sat, Jan 17, 2009 at 6:55 PM, William.S.Kessler <William.S.Kessler@xxxxxxxx> wrote:
I'm not sure if this is the real answer, but one of Ferret's strengths/weaknesses is that definitions are evaluated when a variable is used. Thus when you define the masked variable curl_pac, and then plot it, the @iin in the definition of psi is reevaluated on its latest grid (which is that of the masking variable basin).

A klugey way to get around this is to SAVE the intermediate variable to freeze the evaluation of @iin:

yes? let savepsi=psi          ! define this dummy to avoid having to CAN VAR PSI when it is read back in
yes? save/file=junk.cdf savepsi
LISTing to file junk.cdf
yes? can var savepsi       ! remove the dummy definition
yes? use junk.cdf
yes? let savepsi0=if basin[d=2,gxy=psi@nrst,k=1] eq 2 then savepsi
yes? shade/x=100e:290e savepsi0     ! note specification of x-limits

This produces the plot you want. That fact that this works makes me thinks the problem is the reevaluation of @iin. I agree that this is inelegant, but sometimes intermediate saves are the easiest way to get a result.

Billy K

On 17/01/2009, at 9:34 AM, David Wang wrote:

Hi Ferreters,

I've run into trouble with @iin indefinite integral but wasn't able to pin down the source of error. I wrote a script meant to give me a quick look at the Sverdrup streamfunction in the tropical Pacific from a given wind stress curl. My basic idea is to first mask out the wind stress curl outside the Pacific basin with zero, do the zonal indefinite integration westward, then mask out the resulting streamfunction in all basins except the Pacific. Here is the code using the publicly available wind data (Trenberth et al. 1990) and mask:

\can mode verify

can data/a
can region

! Load annual wind stress curl and basin mask files
use "http://iridl.ldeo.columbia.edu/SOURCES/.TRENBERTH/.Annual/dods"
use "http://iridl.ldeo.columbia.edu/SOURCES/.NOAA/.NODC/.WOA05/.Masks/.basin/dods"

! Mask out all basins but the Pacific
let curl_pac = if basin[d=2,gxy=curl[d=1]@nrst,k=1] eq 2 then curl[d=1]/1e8 else 0

! Calculate Rossby parameter \beta
let f = (2*7.29212e-5) * sin(y[gy=curl_pac]*(4*atan(1.)/180))
let beta = f[y=@ddc]

! Calculate Sverdrup streamfunction (in Sv)
let psi = (-1)*(curl_pac[x=0:360@din]-curl_pac[x=0:360@iin])/beta/1027/1e6

! Mask out all basin but the Pacific
let psi_pac = if basin[d=2,gxy=psi@nrst,k=1] eq 2 then psi

! Show me the result
sha/line/key/@t psi_pac

Things are still OK after psi is defined (try sha psi). However the masked variable psi_pac has become erroneous (try sha psi_pac). And the last command, with a specified context (@t), issues an error msg complaining inconsistent sizes. I found it tricky to figure out what goes wrong in such a script with indefinite integral, regridding between different axes (the x axis starts at 180E (-180) in curl[d=1] while 0.5E in basin[d=2]) and the interplay between indefinite integral and context. Does anyone has a clue please?

life grows, death doesn't.

[Thread Prev][Thread Next][Index]

Contact Us
Dept of Commerce / NOAA / OAR / PMEL / TMAP

Privacy Policy | Disclaimer | Accessibility Statement