From 2cd2d1ba131cf885e0534cec7f0504836f5b3d4b Mon Sep 17 00:00:00 2001 From: "Eugeniy E. Mikhailov" Date: Fri, 3 Dec 2021 13:14:48 -0500 Subject: redid Trace(s) infrastructure --- qolab/data/trace.py | 40 +++++++++++++++++----------------------- qolab/hardware/scope/sds1104x.py | 17 +++++++++-------- 2 files changed, 26 insertions(+), 31 deletions(-) (limited to 'qolab') diff --git a/qolab/data/trace.py b/qolab/data/trace.py index ef44041..871c8c2 100644 --- a/qolab/data/trace.py +++ b/qolab/data/trace.py @@ -1,51 +1,45 @@ -class TraceYonly: +class Trace: def __init__(self, descrStr): self.descr = descrStr - self.y = None - self.ylabel = None - self.yunit = None + self.values = None + self.label = None + self.unit = None def plot(self): import matplotlib.pyplot as plt - plt.plot(self.y, label=self.descr) + plt.plot(self.values, label=self.descr) plt.legend() -class Trace(TraceYonly): +class TraceXY: def __init__(self, descrStr): - super().__init__(descrStr) - self.x = None - self.xlabel = None - self.xunit = None + self.descr = descrStr + self.x = Trace('x_values') + self.y = Trace('y_values') def plot(self): import matplotlib.pyplot as plt - plt.plot(self.x, self.y, label=self.descr) + plt.plot(self.x.values, self.y.values, label=self.descr) plt.legend() + plt.xlabel(self.x.label) class TraceSetSameX: def __init__(self, descrStr): self.descr = descrStr - self.x = None - self.xlabel = None - self.xunit = None + self.x = Trace('x_values') self.traces={} def addTrace(self, tr): if len(self.traces) == 0: self.x = tr.x - self.xlabel = tr.xlabel - self.xunit = tr.xunit - trY = TraceYonly(tr.descr) - trY.y = tr.y - trY.ylabel = tr.ylabel - trY.yunit = tr.yunit - self.traces[trY.descr]=trY + trY = tr.y + self.traces[tr.descr]=trY def plot(self): import matplotlib.pyplot as plt - for k, v in self.traces.items(): - plt.plot(self.x, v.y, label=v.descr) + for k, tr in self.traces.items(): + tr.plot() + plt.xlabel(self.x.label) plt.legend() diff --git a/qolab/hardware/scope/sds1104x.py b/qolab/hardware/scope/sds1104x.py index f77883d..c310e51 100644 --- a/qolab/hardware/scope/sds1104x.py +++ b/qolab/hardware/scope/sds1104x.py @@ -4,7 +4,7 @@ Created by Eugeniy E. Mikhailov 2021/11/29 from qolab.hardware.scope import ScopeSCPI from qolab.hardware.scpi import response2numStr -from qolab.data.trace import Trace +from qolab.data.trace import TraceXY import numpy as np class SDS1104X(ScopeSCPI): @@ -140,13 +140,14 @@ class SDS1104X(ScopeSCPI): def getTrace(self, chNum, availableNpnts=None, maxRequiredPoints=None): wfVoltage, availableNpnts = self.getWaveform( chNum, availableNpnts=availableNpnts, maxRequiredPoints=maxRequiredPoints) t = self.getTimeTrace(availableNpnts=availableNpnts, maxRequiredPoints=maxRequiredPoints) - tr = Trace( f'Ch{chNum}' ) - tr.xlabel = 'Time' - tr.xunit = 'S' - tr.ylabel = 'Voltage' - tr.yunit = 'V' - tr.x = t - tr.y = wfVoltage + tr = TraceXY( f'Ch{chNum}' ) + tr.x.label = 'Time' + tr.x.unit = 'S' + tr.y.descr = f'Ch{chNum}' + tr.y.label = 'Voltage' + tr.y.unit = 'V' + tr.x.values = t + tr.y.values = wfVoltage return( tr ) -- cgit v1.2.3