NOAA-PMEL / Ferret

The Ferret program from NOAA/PMEL
https://ferret.pmel.noaa.gov/Ferret/
The Unlicense
55 stars 20 forks source link

applying context to arguments of external functions #546

Closed karlmsmith closed 6 years ago

karlmsmith commented 6 years ago

Reported by @AnsleyManke on 4 Mar 2005 22:47 UTC from LAS bug 1053- give it a Ferret bug number so we can find in the future!

The regridding mechanism for curvilinear data has brought to light a bug in the behavior of grid-changing functions in Ferret that prevents them from behaving as they are designed to. This bug seems to be a blocker for support of curvilinear grids in LAS and FDS -- it needs to be resolved before curvilinear support can move forward."

This has had an impact on the way regions as session context, as command qualifiers, and as explicit\

! cf_var is the name of the original variable on a curvlilinear grid ! cf_map_file is the name of the netCDF file containing a variable ! called map which has been pre-generated for the curv_to_rect function

use curvilinear_data use cf_map_file let regridded_data = curv_to_rect(cf_var[d=1],map[d=2])

The map variable has data on all 4 dimensions, using K and L for data at the corners of grid cells, where are the nearest neighbors, etc. If the data being regridded depends on Z or T then this meant we could not select a single time and make a plot, for instance.

set region/L=5 shade regridded_data **ERROR: illegal limits: (c027,V001) is not in the range L=5 Axis extremes are L=1:3

Migrated-From: http://dunkel.pmel.noaa.gov/trac/ferret/ticket/1187

karlmsmith commented 6 years ago

Comment by @AnsleyManke on 4 Mar 2005 23:01 UTC See /home/ja8/ansley/FERRET/external_functions/hinterp/hycom/bug1187.jnl and in the same directory joe_examples.jnl

Bug was in fer/utl/gcf_get_arg_lims, where the axis information was obtained for all arguments as if it was coming from argument number 1.

There are implications for some of the grid-changing functions, e.g. the scat2grid functions have arguments xpts, ypts, fpts (scattered data triples) then an xaxis and a yaxis. The xaxis and yaxis previously had no region information applied to them, so the scat_to_grid operation was done on the entire output axes. With the fix, xaxis and yaxis are constrained by any region that is in place. LIST/X=30/Y=-24 SCAT2GRIDGAUSS_XY(...) needs to do computation on more than a single output grid cell at x=30 and y=-24. Additions were needed to the ef_set_axis_extend capablity.

karlmsmith commented 6 years ago

Comment by @AnsleyManke on 7 Mar 2005 17:16 UTC There is also a change in the behavior of the SAPMLE functions. This sequence is from benchmark scripts bench_sorti.jnl. The error message occurs after having made the fix.

yes? use coads_climatology yes? set region/x=141:151/y=39/z=0/l=2 yes? list sst

yes? let tsorted_indices = sorti( sst[i=61:66]) yes? let tsorted_sst = samplei(sst, tsorted_indices)

yes? list tsorted_indices, tsorted_sst **ERROR: invalid command: list of indices supplied to SAMPLEI must be 1D

The region information for y, z, and t does not get applied to argument 2 of SAMPLEJ. The function inherits these axes from argument 1, and we previously accidentally also applied argument 1's context to all the arguments. Now that that's fixed, the documented behavior occurs. In the Users Guide, under "grid-changing functions". It's the last paragraph of this that comes into play.

----------From Chapter 3 Sec 2.3---------------------------------------- If in the result of a grid-changing function, an axis (X, Y, Z, or T) has been replaced relative to some argument, then region information which applies to the result of the function on that axis will NOT be passed to that argument.

So, when you issue commands like

SET REGION/X=20E:30E/Y=0N:20N/L=1 LIST XSEQUENCE(sst)

the X axis region ("20E:30E") applies to the result ABSTRACT axis -- it is not passed along to the argument, SST. The Y axis region is, in fact, ignored altogether, since it is not relevant to the result of XSEQUENCE, and is not passed along to the argument.