Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.plot3.getAxis("bottom").tickFont = font
self.plot3.getAxis("left").tickFont = font
# self.plot3.addLegend()
self.plot3.showGrid(x = True, y = True, alpha = 0.7)
self.USD_graph.show()
# ===============================================================
# Scroll range
# ===============================================================
self.data = {
"begin_datetime": None,
"end_datetime": None
}
self.begin_vLine = pg.InfiniteLine(angle=90, movable=False, pen=pg.mkPen('g', width=4, style=QtCore.Qt.SolidLine))
self.begin_vLine_USD = pg.InfiniteLine(angle=90, movable=False, pen=pg.mkPen('g', width=4, style=QtCore.Qt.SolidLine))
self.begin_vLine_BTC = pg.InfiniteLine(angle=90, movable=False, pen=pg.mkPen('g', width=4, style=QtCore.Qt.SolidLine))
self.top_midway_hLine = pg.InfiniteLine(angle=0, movable=False, pen=pg.mkPen('y', width=2, style=QtCore.Qt.DotLine))# DashLine))
self.bottom_midway_hLine = pg.InfiniteLine(angle=0, movable=False, pen=pg.mkPen('r', width=2, style=QtCore.Qt.DotLine))# DashLine))
self.end_vLine = pg.InfiniteLine(angle=90, movable=False, pen=pg.mkPen('m', width=4, style=QtCore.Qt.SolidLine))
self.plot1.addItem(self.begin_vLine, ignoreBounds=True)
self.plot2.addItem(self.begin_vLine_BTC, ignoreBounds=True)
self.plot3.addItem(self.begin_vLine_USD, ignoreBounds=True)
self.plot1.addItem(self.top_midway_hLine, ignoreBounds=True)
self.plot1.addItem(self.bottom_midway_hLine, ignoreBounds=True)
self.plot1.addItem(self.end_vLine, ignoreBounds=True)
self.end_vLine = pg.InfiniteLine(angle=90, movable=False, pen=pg.mkPen('m', width=4, style=QtCore.Qt.SolidLine))
self.plot1.addItem(self.begin_vLine, ignoreBounds=True)
self.plot1.addItem(self.end_vLine, ignoreBounds=True)
self.top_midway_hLine = pg.InfiniteLine(angle=0, movable=False, pen=pg.mkPen('y', width=2, style=QtCore.Qt.DotLine))# DashLine))
self.bottom_midway_hLine = pg.InfiniteLine(angle=0, movable=False, pen=pg.mkPen('r', width=2, style=QtCore.Qt.DotLine))# DashLine))
self.plot1.addItem(self.top_midway_hLine, ignoreBounds=True)
self.plot1.addItem(self.bottom_midway_hLine, ignoreBounds=True)
if "strategy" in parts:
self.plot2.clear()
self.plot3.clear()
self.begin_vLine_BTC = pg.InfiniteLine(angle=90, movable=False, pen=pg.mkPen('g', width=4, style=QtCore.Qt.SolidLine))
self.begin_vLine_USD = pg.InfiniteLine(angle=90, movable=False, pen=pg.mkPen('g', width=4, style=QtCore.Qt.SolidLine))
self.plot2.addItem(self.begin_vLine_BTC, ignoreBounds=True)
self.plot3.addItem(self.begin_vLine_USD, ignoreBounds=True)
# self.win_pg_left.scene().removeItem(self.plot2.legend)
# self.win_pg_right.scene().removeItem(self.plot3.legend)
# self.plot2.addLegend()
# self.plot3.addLegend()
for item in self.plot1_sell_buy:
self.plot1.removeItem(item)
self.plot1_sell_buy = []
super(PuffAnalyzer,self).__init__(parent) ## Create window with ImageView widget
self.puffs=puffs
self.setWindowTitle('Puff Analyzer')
self.setGeometry(QtCore.QRect(360, 368, 1552, 351))
self.l = QtGui.QVBoxLayout()
self.l_mid=QtGui.QGridLayout()
self.threeD_Holder=QtGui.QHBoxLayout()
self.l_bottom=QtGui.QGridLayout()
self.p1=pg.PlotWidget()
self.p4=pg.PlotWidget()
self.p1.setMaximumWidth(600)
#self.p1.setAutoVisible(y=True)
self.p2=Puff3d(self.puffs)
self.p3=Puff3d_fit(self.puffs)
self.show()
self.vLine = pg.InfiniteLine(angle=90, movable=True)
self.vLine.setPos(self.puffs[0].position[0])
self.startLine = pg.InfiniteLine(pen=QPen(Qt.green),angle=90, movable=True)
self.startLine.setPos(self.puffs[0].position[0])
self.endLine = pg.InfiniteLine(pen=QPen(Qt.cyan),angle=90, movable=True)
self.endLine.setPos(self.puffs[0].position[0])
self.proxy = pg.SignalProxy(self.vLine.sigDragged, rateLimit=60, slot=self.lineDragged)
self.proxy2 = pg.SignalProxy(self.startLine.sigDragged, rateLimit=60, slot=self.startlineDragged)
self.proxy3 = pg.SignalProxy(self.endLine.sigDragged, rateLimit=60, slot=self.endlineDragged)
self.prevButton=QtGui.QPushButton('Previous')
self.currentPuff_spinbox=QtGui.QSpinBox()
self.currentPuff_spinbox.setMaximum(len(self.puffs.puffs)-1)
self.nextButton=QtGui.QPushButton('Next')
self.nextButton.pressed.connect(self.increment)
self.currentPuff_spinbox.valueChanged.connect(self.setCurrPuff)
def genLine(self, time, movable=False):
line = pg.InfiniteLine(time,
angle=90,
pen=self.pen,
movable=movable)
line.parent = self
return line
if self.binsx is None:
self.binsx, self.binsy = mta.plot.get_bins_from_backgroundimage(self.backgroundimg_filename)
self.backgroundimg = cv2.imread(self.backgroundimg_filename, cv2.CV_8UC1)
img = copy.copy(self.backgroundimg)
# plot a heatmap of the trajectories, for error checking
h = mta.plot.get_heatmap(pd_subset, self.binsy, self.binsx, position_x='position_y', position_y='position_x', position_z='position_z', position_z_slice=None)
indices = np.where(h != 0)
img[indices] = 0
self.img = pg.ImageItem(img)
self.p2.addItem(self.img)
self.img.setZValue(-200) # make sure image is behind other data
# cross hair mouse stuff
self.p2.scene().sigMouseMoved.connect(self.mouse_moved)
self.crosshair_vLine = pg.InfiniteLine(angle=90, movable=False)
self.crosshair_hLine = pg.InfiniteLine(angle=0, movable=False)
self.p2.addItem(self.crosshair_vLine, ignoreBounds=True)
self.p2.addItem(self.crosshair_hLine, ignoreBounds=True)
keys = np.unique(pd_subset.objid.values)
self.plotted_traces_keys = []
self.plotted_traces = []
if len(keys) < 100:
for key in keys:
trajec = self.dataset.trajec(key)
first_time = np.max([self.troi[0], trajec.time_epoch[0]])
first_time_index = np.argmin( np.abs(trajec.time_epoch-first_time) )
last_time = np.min([self.troi[-1], trajec.time_epoch[-1]])
last_time_index = np.argmin( np.abs(trajec.time_epoch-last_time) )
#if trajec.length > 5:
if key not in self.trajec_to_color_dict.keys():
if is_an_array(self.slicedArray.mask):
connected = np.logical_and(connected, ~self.slicedArray.mask[:, col])
else:
connected = (np.zeros_like(colData)
if self.slicedArray.mask else connected)
# Replace infinite value with nans because PyQtGraph can't handle them
colData = replaceMaskedValueWithFloat(colData, np.isinf(colData),
np.nan, copyOnReplace=True)
verPlotDataItem = self.config.crossPenCti.createPlotDataItem()
verPlotDataItem.setData(colData, np.arange(nRows), connect=connected)
self.verCrossPlotItem.addItem(verPlotDataItem)
# Horizontal line in ver-cross plot
crossLineShadow0 = pg.InfiniteLine(angle=0, movable=False,
pen=self.crossShadowPen)
crossLineShadow0.setPos(row)
self.verCrossPlotItem.addItem(crossLineShadow0, ignoreBounds=True)
crossLine0 = pg.InfiniteLine(angle=0, movable=False, pen=self.crossPen)
crossLine0.setPos(row)
self.verCrossPlotItem.addItem(crossLine0, ignoreBounds=True)
if show_data_point:
crossPoint0 = pg.PlotDataItem(symbolPen=self.crossPen)
crossPoint0.setSymbolBrush(QtGui.QBrush(self.config.crossPenCti.penColor))
crossPoint0.setSymbolSize(10)
crossPoint0.setData((colData[row],), (row,))
self.verCrossPlotItem.addItem(crossPoint0, ignoreBounds=True)
self.config.verCrossPlotRangeCti.updateTarget() # update auto range
del colData # defensive programming
return
if silhouette_values.shape != self.controller.spike_label.shape:
return
silhouette_avg = np.mean(silhouette_values)
silhouette_by_labels = {}
labels = self.controller.spike_label
labels_list = np.unique(labels)
for k in labels_list:
v = silhouette_values[k==labels]
v.sort()
silhouette_by_labels[k] = v
self.vline = pg.InfiniteLine(pos=silhouette_avg, angle = 90, movable = False, pen = '#FF0000')
self.plot.addItem(self.vline)
y_lower = 10
cluster_visible = self.controller.cluster_visible
visibles = [c for c, v in self.controller.cluster_visible.items() if v and c>=0]
for k in visibles:
if k not in silhouette_by_labels:
continue
v = silhouette_by_labels[k]
color = self.controller.qcolors[k]
color2 = QT.QColor(color)
color2.setAlpha(self.alpha)
y_upper = y_lower + v.size
if self.slicedArray.mask else connected)
# Replace infinite value with nans because PyQtGraph can't handle them
colData = replaceMaskedValueWithFloat(colData, np.isinf(colData),
np.nan, copyOnReplace=True)
verPlotDataItem = self.config.crossPenCti.createPlotDataItem()
verPlotDataItem.setData(colData, np.arange(nRows), connect=connected)
self.verCrossPlotItem.addItem(verPlotDataItem)
# Horizontal line in ver-cross plot
crossLineShadow0 = pg.InfiniteLine(angle=0, movable=False,
pen=self.crossShadowPen)
crossLineShadow0.setPos(row)
self.verCrossPlotItem.addItem(crossLineShadow0, ignoreBounds=True)
crossLine0 = pg.InfiniteLine(angle=0, movable=False, pen=self.crossPen)
crossLine0.setPos(row)
self.verCrossPlotItem.addItem(crossLine0, ignoreBounds=True)
if show_data_point:
crossPoint0 = pg.PlotDataItem(symbolPen=self.crossPen)
crossPoint0.setSymbolBrush(QtGui.QBrush(self.config.crossPenCti.penColor))
crossPoint0.setSymbolSize(10)
crossPoint0.setData((colData[row],), (row,))
self.verCrossPlotItem.addItem(crossPoint0, ignoreBounds=True)
self.config.verCrossPlotRangeCti.updateTarget() # update auto range
del colData # defensive programming
except Exception as ex:
# In contrast to _drawContents, this function is a slot and thus must not throw
# exceptions. The exception is logged. Perhaps we should clear the cross plots, but
def _orthonormal_line(x, y, color, width):
# https://en.wikipedia.org/wiki/Deming_regression, with δ=0.
pen = pg.mkPen(color=color, width=width)
xm = np.mean(x)
ym = np.mean(y)
sxx, sxy, _, syy = np.cov(x, y, ddof=1).flatten()
if sxy != 0: # also covers sxx != 0 and syy != 0
slope = (syy - sxx + np.sqrt((syy - sxx) ** 2 + 4 * sxy ** 2)) \
/ (2 * sxy)
intercept = ym - slope * xm
xmin = x.min()
return pg.InfiniteLine(
QPointF(xmin, xmin * slope + intercept),
np.degrees(np.arctan(slope)),
pen)
elif (sxx == 0) == (syy == 0): # both zero or non-zero -> can't draw
return None
elif sxx != 0:
return pg.InfiniteLine(QPointF(x.min(), ym), 0, pen)
else:
return pg.InfiniteLine(QPointF(xm, y.min()), 90, pen)
self.plot.setLabel("bottom", "Frequency", units="Hz")
self.plot.setLimits(xMin=0)
self.plot.showButtons()
#self.plot.setDownsampling(mode="peak")
#self.plot.setClipToView(True)
self.create_baseline_curve()
self.create_persistence_curves()
self.create_average_curve()
self.create_peak_hold_min_curve()
self.create_peak_hold_max_curve()
self.create_main_curve()
# Create crosshair
self.vLine = pg.InfiniteLine(angle=90, movable=False)
self.vLine.setZValue(1000)
self.hLine = pg.InfiniteLine(angle=0, movable=False)
self.vLine.setZValue(1000)
self.plot.addItem(self.vLine, ignoreBounds=True)
self.plot.addItem(self.hLine, ignoreBounds=True)
self.mouseProxy = pg.SignalProxy(self.plot.scene().sigMouseMoved,
rateLimit=60, slot=self.mouse_moved)