Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPOINTS for dynamic axes, to specify exact number of points #1157

Open
karlmsmith opened this issue Nov 23, 2017 · 3 comments
Open

NPOINTS for dynamic axes, to specify exact number of points #1157

karlmsmith opened this issue Nov 23, 2017 · 3 comments

Comments

@karlmsmith
Copy link
Contributor

karlmsmith commented Nov 23, 2017

Reported by @AndrewWittenberg on 25 Sep 2011 19:01 UTC
For static axis definitions, we have the NPOINTS qualifer to specify an exact number of points. It'd be nice to have the same ability for dynamic axis definitions, to prevent things like this:

atw:/home/atw> ferret
        NOAA/PMEL TMAP
        FERRET v6.71  
        Linux 2.6.18-274.el5PAE 32-bit - 08/05/11
        25-Sep-11 14:11     

yes? let n = 7; def ax/x=0:1/np=`n` xax; list/p=10 x[gx=xax]; list/p=10 x[gx=0:1:`1/(n-1),p=10`]
 !-> def ax/x=0:1/np=7 xax
             VARIABLE : X
                        axis XAX
             SUBSET   : 7 points (X)
 0    / 1:  0.000000000
 0.17 / 2:  0.166666672
 0.33 / 3:  0.333333343
 0.5  / 4:  0.500000000
 0.67 / 5:  0.666666687
 0.83 / 6:  0.833333313
 1    / 7:  1.000000000
 !-> list/p=10 x[gx=0:1:0.16666667]
             VARIABLE : X
                        axis (AX002)
             SUBSET   : 6 points (X)
 0    / 1:  0.0000000000
 0.17 / 2:  0.1666666716
 0.33 / 3:  0.3333333433
 0.5  / 4:  0.5000000000
 0.67 / 5:  0.6666666865
 0.83 / 6:  0.8333333731

I presume that the delta in the dynamic axis definition is being truncated to machine precision. And when that truncated value is used as a regular spacing, the accumulated sum then builds up an error such that the last coordinate no longer fits inside the desired range (0:1).

I'd suggest adding an optional fourth argument to the dynamic axis definition, e.g.

   x[gx=start:end:delta:npoints]

Then

   x[gx=0:100::7]

would specify that we want 7 points from 0 to 100, inclusive. If both DELTA and NPOINTS are given, Ferret could raise an error, or do what DEFINE AXIS does and just silently ignore DELTA and use NPOINTS.

Can dynamic axes have irregular spacing? If so, then the above dynamic definition should work just like the static one. If not, and if precision issues don't permit NPOINTS points to be spaced evenly over the interval, then perhaps expand the endpoint as needed until we do actually have NPOINTS points.

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

@karlmsmith
Copy link
Contributor Author

karlmsmith commented Nov 23, 2017

Comment by @AndrewWittenberg on 25 Sep 2011 19:37 UTC
Further refinement to afford more control -- especially if it turns out that dynamic axes have to be evenly spaced. The user would be required to specify at least 3 of the 4 arguments, and Ferret would fill in the missing argument with a reasonable choice.

   ! the following would produce {1,2,3,4,5}
   x[gx=1:5:1]
   x[gx=1:5::5]
   x[gx=1::1:5]
   x[gx=:5:1:5]

   ! more examples
   x[gx=0:10:3]   ! {0, 3, 6, 9}
   x[gx=0::3:4]   ! {0, 3, 6, 9}
   x[gx=:10:3:4]  ! {1, 4, 7, 10}
   x[gx=0:10::4]  ! {0, 3.333, 6.667, 10}

   ! and if dynamic axes had to be evenly spaced:
   x[gx=0:10::7]  ! {0, 1.666, 3.333, 5.000, 6.666, 8.333, 10.00000191}

@karlmsmith
Copy link
Contributor Author

karlmsmith commented Nov 23, 2017

Comment by @AnsleyManke on 27 Sep 2011 17:47 UTC
Of course all the DEFINE AXIS commands suffer from the inability to specify double precision values in the commands themselves. The start and end points of DEFINE AXIS/X=Lo:Hi, and DEFINE AXIS/FROM_DATA are other examples.

Dynamic axes are regularly spaced, but if we had the correct npoints, they wouldn't be any different from other regularly-spaced axes. The start, end, and delta (computed in double precision) are stored in double precision and the interior coordinate values are computed not by successive addition but by double-precision multiplication.

This means that the dynamic axis x[gx=0:10::7] would behave like DEFINE AXIS/x=0:10/npoints=7 and the coordinate values would be (from an ncdump of a variable saved on the axis),

XAXIS = 0, 1.66666666666667, 3.33333333333333, 5, 6.66666666666667,
8.33333333333333, 10

@karlmsmith
Copy link
Contributor Author

karlmsmith commented Nov 23, 2017

Comment by @AnsleyManke on 16 Jun 2015 19:18 UTC
With double-precision Ferret, the values in the command line are stored as double precision values. The proposals here would be useful additions, but we can make all(?) the right definitions for regularly-spaced axes with existing syntax.


yes? list/p=15 x[gx=0:1:`1./6,p=15`]
             VARIABLE : X
                        axis (AX005)
             SUBSET   : 7 points (X)
 0    / 1:  0.00000000000000
 0.17 / 2:  0.16666666666667
 0.33 / 3:  0.33333333333333
 0.5  / 4:  0.50000000000000
 0.67 / 5:  0.66666666666667
 0.83 / 6:  0.83333333333333
 1    / 7:  1.00000000000000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant