From 85c726e49a484c014a9c9848bb4b8540015322f7 Mon Sep 17 00:00:00 2001 From: Ogi Moore Date: Sun, 18 Apr 2021 23:16:45 -0700 Subject: [PATCH] Replace uses of np.log on scalers with math.log --- pyqtgraph/functions.py | 2 +- pyqtgraph/graphicsItems/AxisItem.py | 15 ++++++++------- pyqtgraph/graphicsItems/GridItem.py | 8 +------- pyqtgraph/imageview/ImageView.py | 3 ++- pyqtgraph/parametertree/SystemSolver.py | 3 ++- 5 files changed, 14 insertions(+), 17 deletions(-) diff --git a/pyqtgraph/functions.py b/pyqtgraph/functions.py index 6b9916c1..2a4ef281 100644 --- a/pyqtgraph/functions.py +++ b/pyqtgraph/functions.py @@ -71,7 +71,7 @@ def siScale(x, minVal=1e-25, allowUnicode=True): m = 0 x = 0 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: pref = '' diff --git a/pyqtgraph/graphicsItems/AxisItem.py b/pyqtgraph/graphicsItems/AxisItem.py index 37490d9d..d907558a 100644 --- a/pyqtgraph/graphicsItems/AxisItem.py +++ b/pyqtgraph/graphicsItems/AxisItem.py @@ -4,6 +4,7 @@ from ..python2_3 import asUnicode import numpy as np from ..Point import Point from .. import debug as debug +from math import ceil, floor, log, log10 import sys import weakref from .. import functions as fn @@ -680,13 +681,13 @@ class AxisItem(GraphicsWidget): return [] ## 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 optimalSpacing = dif / optimalTickCount ## 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. intervals = np.array([1., 2., 10., 20., 100.]) * p10unit @@ -758,7 +759,7 @@ class AxisItem(GraphicsWidget): spacing, offset = tickLevels[i] ## determine starting tick - start = (np.ceil((minVal-offset) / spacing) * spacing) + offset + start = (ceil((minVal-offset) / spacing) * spacing) + offset ## determine number of ticks num = int((maxVal-start) / spacing) + 1 @@ -795,8 +796,8 @@ class AxisItem(GraphicsWidget): ticks.append((spacing, t)) if len(ticks) < 3: - v1 = int(np.floor(minVal)) - v2 = int(np.ceil(maxVal)) + v1 = int(floor(minVal)) + v2 = int(ceil(maxVal)) #major = list(range(v1+1, v2)) minor = [] @@ -822,7 +823,7 @@ class AxisItem(GraphicsWidget): if self.logMode: return self.logTickStrings(values, scale, spacing) - places = max(0, np.ceil(-np.log10(spacing*scale))) + places = max(0, ceil(-log10(spacing*scale))) strings = [] for v in values: vs = v * scale @@ -969,7 +970,7 @@ class AxisItem(GraphicsWidget): if lineAlpha is None: lineAlpha = 255 / (i+1) 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): lineAlpha *= 255 lineAlpha = max(0, int(round(lineAlpha))) diff --git a/pyqtgraph/graphicsItems/GridItem.py b/pyqtgraph/graphicsItems/GridItem.py index 4cb30bf8..9004ac94 100644 --- a/pyqtgraph/graphicsItems/GridItem.py +++ b/pyqtgraph/graphicsItems/GridItem.py @@ -126,8 +126,7 @@ class GridItem(UIGraphicsItem): for i in range(self.grid_depth - 1, -1, -1): dist = br-ul nlTarget = 10.**i - - d = 10. ** np.floor(np.log10(abs(dist/nlTarget))+0.5) + d = 10. ** np.floor(np.log10(np.abs(dist/nlTarget))+0.5) for ax in range(0,2): ts = self.opts['tickSpacing'][ax] try: @@ -141,11 +140,6 @@ class GridItem(UIGraphicsItem): br1 = np.ceil(br / d) * d dist = br1-ul1 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 if i >= len(self.opts['tickSpacing'][ax]): continue diff --git a/pyqtgraph/imageview/ImageView.py b/pyqtgraph/imageview/ImageView.py index 62c030a4..3e0cb39b 100644 --- a/pyqtgraph/imageview/ImageView.py +++ b/pyqtgraph/imageview/ImageView.py @@ -13,6 +13,7 @@ Widget used for displaying 2D or 3D data. Features: - Image normalization through a variety of methods """ import os, sys +from math import log10 import numpy as np from ..Qt import QtCore, QtGui, QT_LIB @@ -807,7 +808,7 @@ class ImageView(QtGui.QWidget): img = self.getProcessedImage() if self.hasTimeAxis(): 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]): self.imageItem.setImage(img[i], autoLevels=False) self.imageItem.save(fmt % (base, i, ext)) diff --git a/pyqtgraph/parametertree/SystemSolver.py b/pyqtgraph/parametertree/SystemSolver.py index cac42483..71f051e6 100644 --- a/pyqtgraph/parametertree/SystemSolver.py +++ b/pyqtgraph/parametertree/SystemSolver.py @@ -1,6 +1,7 @@ from collections import OrderedDict import numpy as np import copy +from math import log2 class SystemSolver(object): @@ -409,7 +410,7 @@ if __name__ == '__main__': fl = self.flash bal = (4.0 / ap) * (sh / (1./60.)) * (iso / 100.) * (2 ** light) - return np.log2(bal) + return log2(bal) camera = Camera()