Replace uses of np.log on scalers with math.log

This commit is contained in:
Ogi Moore 2021-04-18 23:16:45 -07:00
parent b01e0e0895
commit 85c726e49a
5 changed files with 14 additions and 17 deletions

View File

@ -71,7 +71,7 @@ def siScale(x, minVal=1e-25, allowUnicode=True):
m = 0 m = 0
x = 0 x = 0
else: else:
m = int(np.clip(np.floor(np.log(abs(x))/np.log(1000)), -9.0, 9.0)) m = int(clip_scalar(math.floor(math.log(abs(x))/math.log(1000)), -9.0, 9.0))
if m == 0: if m == 0:
pref = '' pref = ''

View File

@ -4,6 +4,7 @@ from ..python2_3 import asUnicode
import numpy as np import numpy as np
from ..Point import Point from ..Point import Point
from .. import debug as debug from .. import debug as debug
from math import ceil, floor, log, log10
import sys import sys
import weakref import weakref
from .. import functions as fn from .. import functions as fn
@ -680,13 +681,13 @@ class AxisItem(GraphicsWidget):
return [] return []
## decide optimal minor tick spacing in pixels (this is just aesthetics) ## decide optimal minor tick spacing in pixels (this is just aesthetics)
optimalTickCount = max(2., np.log(size)) optimalTickCount = max(2., log(size))
## optimal minor tick spacing ## optimal minor tick spacing
optimalSpacing = dif / optimalTickCount optimalSpacing = dif / optimalTickCount
## the largest power-of-10 spacing which is smaller than optimal ## the largest power-of-10 spacing which is smaller than optimal
p10unit = 10 ** np.floor(np.log10(optimalSpacing)) p10unit = 10 ** floor(log10(optimalSpacing))
## Determine major/minor tick spacings which flank the optimal spacing. ## Determine major/minor tick spacings which flank the optimal spacing.
intervals = np.array([1., 2., 10., 20., 100.]) * p10unit intervals = np.array([1., 2., 10., 20., 100.]) * p10unit
@ -758,7 +759,7 @@ class AxisItem(GraphicsWidget):
spacing, offset = tickLevels[i] spacing, offset = tickLevels[i]
## determine starting tick ## determine starting tick
start = (np.ceil((minVal-offset) / spacing) * spacing) + offset start = (ceil((minVal-offset) / spacing) * spacing) + offset
## determine number of ticks ## determine number of ticks
num = int((maxVal-start) / spacing) + 1 num = int((maxVal-start) / spacing) + 1
@ -795,8 +796,8 @@ class AxisItem(GraphicsWidget):
ticks.append((spacing, t)) ticks.append((spacing, t))
if len(ticks) < 3: if len(ticks) < 3:
v1 = int(np.floor(minVal)) v1 = int(floor(minVal))
v2 = int(np.ceil(maxVal)) v2 = int(ceil(maxVal))
#major = list(range(v1+1, v2)) #major = list(range(v1+1, v2))
minor = [] minor = []
@ -822,7 +823,7 @@ class AxisItem(GraphicsWidget):
if self.logMode: if self.logMode:
return self.logTickStrings(values, scale, spacing) return self.logTickStrings(values, scale, spacing)
places = max(0, np.ceil(-np.log10(spacing*scale))) places = max(0, ceil(-log10(spacing*scale)))
strings = [] strings = []
for v in values: for v in values:
vs = v * scale vs = v * scale
@ -969,7 +970,7 @@ class AxisItem(GraphicsWidget):
if lineAlpha is None: if lineAlpha is None:
lineAlpha = 255 / (i+1) lineAlpha = 255 / (i+1)
if self.grid is not False: if self.grid is not False:
lineAlpha *= self.grid/255. * np.clip((0.05 * lengthInPixels / (len(ticks)+1)), 0., 1.) lineAlpha *= self.grid/255. * fn.clip_scalar((0.05 * lengthInPixels / (len(ticks)+1)), 0., 1.)
elif isinstance(lineAlpha, float): elif isinstance(lineAlpha, float):
lineAlpha *= 255 lineAlpha *= 255
lineAlpha = max(0, int(round(lineAlpha))) lineAlpha = max(0, int(round(lineAlpha)))

View File

@ -126,8 +126,7 @@ class GridItem(UIGraphicsItem):
for i in range(self.grid_depth - 1, -1, -1): for i in range(self.grid_depth - 1, -1, -1):
dist = br-ul dist = br-ul
nlTarget = 10.**i nlTarget = 10.**i
d = 10. ** np.floor(np.log10(np.abs(dist/nlTarget))+0.5)
d = 10. ** np.floor(np.log10(abs(dist/nlTarget))+0.5)
for ax in range(0,2): for ax in range(0,2):
ts = self.opts['tickSpacing'][ax] ts = self.opts['tickSpacing'][ax]
try: try:
@ -141,11 +140,6 @@ class GridItem(UIGraphicsItem):
br1 = np.ceil(br / d) * d br1 = np.ceil(br / d) * d
dist = br1-ul1 dist = br1-ul1
nl = (dist / d) + 0.5 nl = (dist / d) + 0.5
#print "level", i
#print " dim", dim
#print " dist", dist
#print " d", d
#print " nl", nl
for ax in range(0,2): ## Draw grid for both axes for ax in range(0,2): ## Draw grid for both axes
if i >= len(self.opts['tickSpacing'][ax]): if i >= len(self.opts['tickSpacing'][ax]):
continue continue

View File

@ -13,6 +13,7 @@ Widget used for displaying 2D or 3D data. Features:
- Image normalization through a variety of methods - Image normalization through a variety of methods
""" """
import os, sys import os, sys
from math import log10
import numpy as np import numpy as np
from ..Qt import QtCore, QtGui, QT_LIB from ..Qt import QtCore, QtGui, QT_LIB
@ -807,7 +808,7 @@ class ImageView(QtGui.QWidget):
img = self.getProcessedImage() img = self.getProcessedImage()
if self.hasTimeAxis(): if self.hasTimeAxis():
base, ext = os.path.splitext(fileName) base, ext = os.path.splitext(fileName)
fmt = "%%s%%0%dd%%s" % int(np.log10(img.shape[0])+1) fmt = "%%s%%0%dd%%s" % int(log10(img.shape[0])+1)
for i in range(img.shape[0]): for i in range(img.shape[0]):
self.imageItem.setImage(img[i], autoLevels=False) self.imageItem.setImage(img[i], autoLevels=False)
self.imageItem.save(fmt % (base, i, ext)) self.imageItem.save(fmt % (base, i, ext))

View File

@ -1,6 +1,7 @@
from collections import OrderedDict from collections import OrderedDict
import numpy as np import numpy as np
import copy import copy
from math import log2
class SystemSolver(object): class SystemSolver(object):
@ -409,7 +410,7 @@ if __name__ == '__main__':
fl = self.flash fl = self.flash
bal = (4.0 / ap) * (sh / (1./60.)) * (iso / 100.) * (2 ** light) bal = (4.0 / ap) * (sh / (1./60.)) * (iso / 100.) * (2 ** light)
return np.log2(bal) return log2(bal)
camera = Camera() camera = Camera()