# Coverage for rocketcea\biprop_utils\calc_plot_range.py : 10%

## 40 statements 4 run 36 missing 0 excluded

Hot-keys on this page

r m x p toggle line displays

j k next/prev highlighted chunk

0 (zero) top of page

1 (one) first highlighted chunk

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | from __future__ import print_function from math import log10, floor def calcMinMaxRange(vmin, vmax, num_ticks=10): try: if vmin>vmax: vmin,vmax = vmax,vmin diff = vmax - vmin elif vmin==vmax: vmin = 0.0 diff = vmax else: diff = vmax - vmin ldiff = log10( diff ) n = int( str(ldiff)[0] ) # first digit of log10 of diff tenN = 10.0**n msd = int(diff / tenN) # most significant decimal digit of diff r = (msd+1)*10.0**n # slightly larger than diff, but even number of msd values t = 10.0**( int(log10(r)) ) # diff in form 1.0Enn rmin = int(vmin/t) * t rmax = int(vmax/t) * t while rmax < vmax: rmax += t while rmin > vmin: rmin -= t # Now calc a reasonable step size tempStep = (rmax-rmin) / num_ticks mag = floor( log10(tempStep) ) magPow = 10.0**mag magMSD = int( 0.5 + tempStep/magPow ) step = magMSD * magPow return rmin, rmax, step except: return vmin, vmax, (vmax-vmin)/10.0 if __name__ == "__main__": def test( vmin, vmax): print( 'for vmin, vmax=',vmin, vmax, end='') rmin,rmax,step = calcMinMaxRange(vmin, vmax) print( ' (rmin,rmax)=(%g,%g)'%(rmin, rmax),' step=%g'%step ) test(4233.0, 4610.0) test(4610.0, 4233.0) test( 255.0, 255.0) test( -255.0, 255.0)