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

nice_cntr_levels returns nsteps instead of step size #39

Open
brhillman opened this issue Oct 15, 2020 · 0 comments
Open

nice_cntr_levels returns nsteps instead of step size #39

brhillman opened this issue Oct 15, 2020 · 0 comments

Comments

@brhillman
Copy link

brhillman commented Oct 15, 2020

It appears as though the nice_cntr_levels function ultimately returns the number of steps, instead of the step size. Consequently, we get very misleading behavior when we pass the returnLevels argument. For example, if we pass lmin = 0, lmax = 457.8073, and specify a max step size of max_steps=15, we get back 41 levels:

>>> from ngl import nice_cntr_levels
>>> nice_min, nice_max, cint, levels = nice_cntr_levels(0.0, 457.8073, max_steps=15, returnLevels=True)
>>> print(levels)
[  0.  12.  24.  36.  48.  60.  72.  84.  96. 108. 120. 132. 144. 156.
 168. 180. 192. 204. 216. 228. 240. 252. 264. 276. 288. 300. 312. 324.
 336. 348. 360. 372. 384. 396. 408. 420. 432. 444. 456. 468. 480.]
>>> print(len(levels))
41

The reason for this is the following block of code in nice_cntr_levels:

        try:
            index = numpy.where(cints < max_steps)[0][0]
        except IndexError:
            return None

        if returnLevels:
            return am1[index], ax1[index], cints[index], numpy.arange(am1[index], ax1[index]+cints[index], cints[index])
        else:
            return am1[index], ax1[index], cints[index]

At this point in the code, cints is a list of candidate number of steps, while t is a list of candidate step sizes. Thus, the numpy.where call correctly finds the index we want. However, the return statements use cints, where they should be indexing into the t list, which represents the candidate list of step sizes. Replacing this block with the following gives me the expected behavior:

        try:
            index = numpy.where(cints < max_steps)[0][0]
        except IndexError:
            return None

        if returnLevels:
            return am1[index], ax1[index], t[index], numpy.arange(am1[index], ax1[index]+t[index], t[index])
        else:
            return am1[index], ax1[index], t[index]

And demonstrating the same example:

>>> from utils import nice_cntr_levels
>>> nice_min, nice_max, cint, levels = nice_cntr_levels(0.0, 457.8073, max_steps=15, returnLevels=True)
>>> print(levels)
[  0.  40.  80. 120. 160. 200. 240. 280. 320. 360. 400. 440. 480.]
>>> print(len(levels))
13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant