[Thread Prev][Thread Next][Index]

Re: [ferret_users] undesirable missing_value



Hi David & Martin,

The short answer is simply to add explicit limits to your average:

let newtemp = IF z[g=temp] LE 1000 THEN temp \
   ELSE temp[x=130e:70w@ave,y=23.5s:23.5n@ave]+0*temp

---

Now the long answer (Ansley or Steve, please correct me if I'm wrong).
As the indefinite average

   let avg = temp[x=@ave,y=@ave]

has no explicit x/y limits, these must be determined by Ferret based on
the "context" at evaluation (PLOT, SHADE, FILL, SAVE, LIST).  This context
is determined from the domain specified with square brackets

   list avg[x=140w,y=0]

or if those are absent, the "command qualifiers"

   list/x=140w/y=0 avg

or if those are absent, the current region (imposed with SET REGION); or
if that is absent, the entire data domain.

In David's example, those final command qualifiers override everything
else, and so the horizontal average is performed only over the single
point x=140w, y=0, which is a region of zero volume.

Ferret returns the "missing value" for such averages -- perhaps based on
the argument that a domain with zero volume contains no data, and thus can
have no average.  The Ferret developers might otherwise have chosen to
return the interpolated value instead of the missing value, but in some
cases (like this one) users might have been misled into thinking that they
had a domain-average value, when they really had only a point-value.  The
current behavior prevents such potentially scientifically-disastrous
mistakes by requiring users to understand what Ferret is actually doing.

To insulate your average from the current data context and the vagaries of
Ferret, simply define it with explicit limits:

   let avg = temp[x=130e:70w@ave,y=23.5s:23.5n@ave]

In David's case he could do:

use levitus_climatology.cdf
set region/@T
let newtemp = IF z[g=temp] LE 1000 THEN temp ELSE 0*temp + \
   temp[x=`temp,r=xstart`:`temp,r=xend`@ave, \
        y=`temp,r=ystart`:`temp,r=yend`@ave]
list/x=140w/y=0 temp, newtemp ! testing
shade/z=2000 newtemp ! testing

Here we are using the `return=...` (abbreviated as `r=...`) to
"immediately" get the current start/end values for the current domain,
which has been limited to the tropical Pacific by the "SET REGION T".  To
see that NEWTEMP is now defined with those explicit limits:

yes? list newtemp
NEWTEMP = IF Z[G=TEMP] LE 1000 THEN TEMP ELSE
   0*TEMP + TEMP[X=130.5E:70.5W@AVE,Y=23.5S:23.5N@AVE]


See also the user's guide:

   http://ferret.wrc.noaa.gov/Ferret/Documentation/Users_Guide/current/Chapter3_Variables_and_Expressions.htm#_VPINDEXENTRY_404

Cheers,

Andrew


On Fri, 10 Feb 2006, Martin Schmidt wrote:

> Hi David,
>
> the operation
>
> list/x=140w/y=0 temp, newtemp
>
> limits the region of temp and newtemp. Hence temp[x=@ave,y=@ave]
> gets a different meaning. This is often not taken into account.
> Please note also, that temp is defined at x=140.5 and x=139.5. So some
> interpolation is done here.
>
> What helps.
>
> - save newtemp to a new file.
>
> save/clobber/file=newtemp.nc newtemp
>
> - delete the variable newtemp
>
> cancel var newtemp
>
> - get the complete set newtemp from newtemp.nc
>
> use newtemp.nc
> list/x=140w/y=0 temp[d=1], newtemp   ! testing
>
> It should be now, what you expect.
>
> My experience with ferret is the following: Doing things with
> averaging, filling or shift operation and applying some
> regional limits later gives unexpected results. These are not
> errors but is a "misunderstanding" between user and ferret.
> Ferret executes commands, when output is required. When you
> define newtemp about nothing happens. In matlab the field would
> be generated, ferret says "yessir - understood" and waits what
> really is to do and is so much faster in many cases. If you list
> newtemp at x=140w and y=0 ferret executes the commands defined
> previously only for a small region around x=140w. If you
> really want the average over all x and y you have to tell ferret
> to execute this. Saving to a file does exactly this. Making
> a figure with "shade" also. However, issuing the list command later,
> ferret gets "oops, the same again, but now only for x=140w and y=0."
>
> One could try to "think like ferret". However, a saver way is to save complete
> intermediate variables to intermediate files, remove the variable definition
> and to read data from file. This "stores" the ferret results.
> This seems to  be slower and expensive in compute power but is save and there is no need
> for error search. Finally one gets the desired result much faster.
>
> Regards,
> Martin Schmidt
>
>



[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement