Clean up Errors for CodeQL analyzer

CodeQL identified some errors and warnings, which this commit cleans up.
This commit is contained in:
Ogi Moore 2021-04-20 23:40:03 -07:00
parent 329423f525
commit 03ea368454
14 changed files with 17 additions and 41 deletions

View File

@ -8,7 +8,6 @@ This example uses the isosurface function to convert a scalar field
import initExample import initExample
import numpy as np import numpy as np
from pyqtgraph.Qt import QtCore, QtGui
import pyqtgraph as pg import pyqtgraph as pg
import pyqtgraph.opengl as gl import pyqtgraph.opengl as gl
@ -29,7 +28,6 @@ def psi(i, j, k, offset=(25, 25, 50)):
y = j-offset[1] y = j-offset[1]
z = k-offset[2] z = k-offset[2]
th = np.arctan2(z, np.hypot(x, y)) th = np.arctan2(z, np.hypot(x, y))
phi = np.arctan2(y, x)
r = np.sqrt(x**2 + y**2 + z **2) r = np.sqrt(x**2 + y**2 + z **2)
a0 = 1 a0 = 1
ps = (1./81.) * 1./(6.*np.pi)**0.5 * (1./a0)**(3/2) * (r/a0)**2 * np.exp(-r/(3*a0)) * (3 * np.cos(th)**2 - 1) ps = (1./81.) * 1./(6.*np.pi)**0.5 * (1./a0)**(3/2) * (r/a0)**2 * np.exp(-r/(3*a0)) * (3 * np.cos(th)**2 - 1)

View File

@ -9,7 +9,6 @@ import initExample
import numpy as np import numpy as np
import pyqtgraph as pg import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
import pyqtgraph.opengl as gl import pyqtgraph.opengl as gl
from pyqtgraph import functions as fn from pyqtgraph import functions as fn
@ -31,10 +30,8 @@ def psi(i, j, k, offset=(50,50,100)):
y = j-offset[1] y = j-offset[1]
z = k-offset[2] z = k-offset[2]
th = np.arctan2(z, np.hypot(x, y)) th = np.arctan2(z, np.hypot(x, y))
phi = np.arctan2(y, x)
r = np.sqrt(x**2 + y**2 + z **2) r = np.sqrt(x**2 + y**2 + z **2)
a0 = 2 a0 = 2
#ps = (1./81.) * (2./np.pi)**0.5 * (1./a0)**(3/2) * (6 - r/a0) * (r/a0) * np.exp(-r/(3*a0)) * np.cos(th)
ps = (1./81.) * 1./(6.*np.pi)**0.5 * (1./a0)**(3/2) * (r/a0)**2 * np.exp(-r/(3*a0)) * (3 * np.cos(th)**2 - 1) ps = (1./81.) * 1./(6.*np.pi)**0.5 * (1./a0)**(3/2) * (r/a0)**2 * np.exp(-r/(3*a0)) * (3 * np.cos(th)**2 - 1)
return ps return ps

View File

@ -8,6 +8,7 @@ Distributed under MIT/X11 license. See license.txt for more information.
from .Qt import QtCore from .Qt import QtCore
from math import atan2, hypot, degrees from math import atan2, hypot, degrees
class Point(QtCore.QPointF): class Point(QtCore.QPointF):
"""Extension of QPointF which adds a few missing methods.""" """Extension of QPointF which adds a few missing methods."""

View File

@ -7,7 +7,6 @@ Distributed under MIT/X11 license. See license.txt for more information.
from math import acos, degrees from math import acos, degrees
from .Qt import QtGui, QtCore, QT_LIB from .Qt import QtGui, QtCore, QT_LIB
from . import functions as fn from . import functions as fn
import numpy as np
class Vector(QtGui.QVector3D): class Vector(QtGui.QVector3D):
"""Extension of QVector3D which adds a few helpful methods.""" """Extension of QVector3D which adds a few helpful methods."""

View File

@ -1,6 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import numpy as np from ..Qt import QtGui, QtCore, QT_LIB
from ..Qt import QtGui, QtCore, QtSvg, QT_LIB
from .. import functions as fn from .. import functions as fn
from ..graphicsItems.ROI import ROI from ..graphicsItems.ROI import ROI
from .. import SRTTransform, ItemGroup from .. import SRTTransform, ItemGroup

View File

@ -67,10 +67,8 @@ def siScale(x, minVal=1e-25, allowUnicode=True):
raise raise
if abs(x) < minVal: if abs(x) < minVal:
m = 0 m = 0
x = 0
else: else:
m = int(clip_scalar(math.floor(math.log(abs(x))/math.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 = ''
elif m < -8 or m > 8: elif m < -8 or m > 8:
@ -82,7 +80,6 @@ def siScale(x, minVal=1e-25, allowUnicode=True):
pref = SI_PREFIXES_ASCII[m+8] pref = SI_PREFIXES_ASCII[m+8]
m1 = -3*m m1 = -3*m
p = 10.**m1 p = 10.**m1
return (p, pref) return (p, pref)

View File

@ -2,7 +2,6 @@ from math import atan2, degrees
from ..Qt import QtGui, QtCore from ..Qt import QtGui, QtCore
from . import ArrowItem from . import ArrowItem
from ..functions import clip_scalar from ..functions import clip_scalar
import numpy as np
from ..Point import Point from ..Point import Point
import weakref import weakref
from .GraphicsObject import GraphicsObject from .GraphicsObject import GraphicsObject

View File

@ -15,9 +15,9 @@ of how to build an ROI at the bottom of the file.
from ..Qt import QtCore, QtGui from ..Qt import QtCore, QtGui
import numpy as np import numpy as np
#from numpy.linalg import norm #from numpy.linalg import norm
from ..Point import * from ..Point import Point
from ..SRTTransform import SRTTransform from ..SRTTransform import SRTTransform
from math import atan2, cos, sin, hypot, radians, degrees from math import atan2, cos, sin, hypot, radians
from .. import functions as fn from .. import functions as fn
from .GraphicsObject import GraphicsObject from .GraphicsObject import GraphicsObject
from .UIGraphicsItem import UIGraphicsItem from .UIGraphicsItem import UIGraphicsItem
@ -141,12 +141,13 @@ class ROI(GraphicsObject):
maxBounds=None, snapSize=1.0, scaleSnap=False, maxBounds=None, snapSize=1.0, scaleSnap=False,
translateSnap=False, rotateSnap=False, parent=None, pen=None, translateSnap=False, rotateSnap=False, parent=None, pen=None,
hoverPen=None, handlePen=None, handleHoverPen=None, hoverPen=None, handlePen=None, handleHoverPen=None,
movable=True, rotatable=True, resizable=True, removable=False): movable=True, rotatable=True, resizable=True, removable=False,
aspectLocked=False):
GraphicsObject.__init__(self, parent) GraphicsObject.__init__(self, parent)
self.setAcceptedMouseButtons(QtCore.Qt.NoButton) self.setAcceptedMouseButtons(QtCore.Qt.NoButton)
pos = Point(pos) pos = Point(pos)
size = Point(size) size = Point(size)
self.aspectLocked = False self.aspectLocked = aspectLocked
self.translatable = movable self.translatable = movable
self.rotatable = rotatable self.rotatable = rotatable
self.resizable = resizable self.resizable = resizable
@ -678,7 +679,7 @@ class ROI(GraphicsObject):
The format returned is a list of (name, pos) tuples. The format returned is a list of (name, pos) tuples.
""" """
if index == None: if index is None:
positions = [] positions = []
for h in self.handles: for h in self.handles:
positions.append((h['name'], h['pos'])) positions.append((h['name'], h['pos']))
@ -691,7 +692,7 @@ class ROI(GraphicsObject):
The format returned is a list of (name, pos) tuples. The format returned is a list of (name, pos) tuples.
""" """
if index == None: if index is None:
positions = [] positions = []
for h in self.handles: for h in self.handles:
positions.append((h['name'], h['item'].scenePos())) positions.append((h['name'], h['item'].scenePos()))
@ -1298,7 +1299,7 @@ class ROI(GraphicsObject):
"""Return global transformation (rotation angle+translation) required to move """Return global transformation (rotation angle+translation) required to move
from relative state to current state. If relative state isn't specified, from relative state to current state. If relative state isn't specified,
then we use the state of the ROI when mouse is pressed.""" then we use the state of the ROI when mouse is pressed."""
if relativeTo == None: if relativeTo is None:
relativeTo = self.preMoveState relativeTo = self.preMoveState
st = self.getState() st = self.getState()
@ -1941,8 +1942,7 @@ class CircleROI(EllipseROI):
if radius is None: if radius is None:
raise TypeError("Must provide either size or radius.") raise TypeError("Must provide either size or radius.")
size = (radius*2, radius*2) size = (radius*2, radius*2)
EllipseROI.__init__(self, pos, size, **args) EllipseROI.__init__(self, pos, size, aspectLocked=True, **args)
self.aspectLocked = True
def _addHandles(self): def _addHandles(self):
self.addScaleHandle([0.5*2.**-0.5 + 0.5, 0.5*2.**-0.5 + 0.5], [0.5, 0.5]) self.addScaleHandle([0.5*2.**-0.5 + 0.5, 0.5*2.**-0.5 + 0.5], [0.5, 0.5])
@ -2307,16 +2307,15 @@ class CrosshairROI(ROI):
"""A crosshair ROI whose position is at the center of the crosshairs. By default, it is scalable, rotatable and translatable.""" """A crosshair ROI whose position is at the center of the crosshairs. By default, it is scalable, rotatable and translatable."""
def __init__(self, pos=None, size=None, **kargs): def __init__(self, pos=None, size=None, **kargs):
if size == None: if size is None:
size=[1,1] size=[1,1]
if pos == None: if pos is None:
pos = [0,0] pos = [0,0]
self._shape = None self._shape = None
ROI.__init__(self, pos, size, **kargs) ROI.__init__(self, pos, size, aspectLocked=True, **kargs)
self.sigRegionChanged.connect(self.invalidate) self.sigRegionChanged.connect(self.invalidate)
self.addScaleRotateHandle(Point(1, 0), Point(0, 0)) self.addScaleRotateHandle(Point(1, 0), Point(0, 0))
self.aspectLocked = True
def invalidate(self): def invalidate(self):
self._shape = None self._shape = None
@ -2391,9 +2390,6 @@ class TriangleROI(ROI):
""" """
def __init__(self, pos, size, **args): def __init__(self, pos, size, **args):
ROI.__init__(self, pos, [size, size], **args)
self.aspectLocked = True
angles = np.linspace(0, pi * 4 / 3, 3)
ROI.__init__(self, pos, [size, size], aspectLocked=True, **args) ROI.__init__(self, pos, [size, size], aspectLocked=True, **args)
angles = np.linspace(0, np.pi * 4 / 3, 3) angles = np.linspace(0, np.pi * 4 / 3, 3)
verticies = (np.array((np.sin(angles), np.cos(angles))).T + 1.0) / 2.0 verticies = (np.array((np.sin(angles), np.cos(angles))).T + 1.0) / 2.0

View File

@ -1,5 +1,4 @@
from math import atan2, pi, degrees from math import atan2
from ..Qt import QtGui, QtCore from ..Qt import QtGui, QtCore
from ..Point import Point from ..Point import Point
from .. import functions as fn from .. import functions as fn

View File

@ -550,7 +550,6 @@ class ViewBox(GraphicsWidget):
dy = 1 dy = 1
mn -= dy*0.5 mn -= dy*0.5
mx += dy*0.5 mx += dy*0.5
xpad = 0.0
# Make sure no nan/inf get through # Make sure no nan/inf get through
if not math.isfinite(mn) or not math.isfinite(mx): if not math.isfinite(mn) or not math.isfinite(mx):

View File

@ -12,7 +12,7 @@ Widget used for displaying 2D or 3D data. Features:
- ROI plotting - ROI plotting
- Image normalization through a variety of methods - Image normalization through a variety of methods
""" """
import os, sys import os
from math import log10 from math import log10
import numpy as np import numpy as np

View File

@ -5,7 +5,7 @@ import numpy as np
from .. import Vector from .. import Vector
from .. import functions as fn from .. import functions as fn
import warnings import warnings
from math import cos, sin, tan, degrees, radians from math import cos, sin, tan, radians
##Vector = QtGui.QVector3D ##Vector = QtGui.QVector3D
ShareWidget = None ShareWidget = None

View File

@ -398,9 +398,6 @@ if __name__ == '__main__':
# value at the same time. # value at the same time.
sh = (1./60.) sh = (1./60.)
raise raise
return ap return ap
def _balance(self): def _balance(self):
@ -408,8 +405,6 @@ if __name__ == '__main__':
light = self.lightMeter light = self.lightMeter
sh = self.shutter sh = self.shutter
ap = self.aperture ap = self.aperture
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 log2(bal) return log2(bal)

View File

@ -7,10 +7,7 @@ Distributed under MIT/X11 license. See license.txt for more information.
from ..Qt import QtCore, QtGui, QtWidgets, QT_LIB from ..Qt import QtCore, QtGui, QtWidgets, QT_LIB
from ..Point import Point from ..Point import Point
import sys, os
from .FileDialog import FileDialog
from ..GraphicsScene import GraphicsScene from ..GraphicsScene import GraphicsScene
import numpy as np
from .. import functions as fn from .. import functions as fn
from .. import debug as debug from .. import debug as debug
from .. import getConfigOption from .. import getConfigOption