diff options
author | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2021-12-14 00:18:06 -0500 |
---|---|---|
committer | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2021-12-14 00:18:06 -0500 |
commit | d6ab6f0f86d6c6a76adf166aa79deb649dd0384a (patch) | |
tree | e2ce9434937d364bb287561c67bee70a26aacccb | |
parent | 4b4e198d337216e1bcfffb07b6618d9c9ef0f9a7 (diff) | |
download | qolab-d6ab6f0f86d6c6a76adf166aa79deb649dd0384a.tar.gz qolab-d6ab6f0f86d6c6a76adf166aa79deb649dd0384a.zip |
traces can add points now
-rw-r--r-- | qolab/data/trace.py | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/qolab/data/trace.py b/qolab/data/trace.py index 65373e5..7154896 100644 --- a/qolab/data/trace.py +++ b/qolab/data/trace.py @@ -16,7 +16,7 @@ class Trace: self.config['label'] = label self.config['unit'] = None self.config['tags'] = {} - self.values = None + self.values = np.empty(0) def plot(self): import matplotlib.pyplot as plt @@ -38,6 +38,9 @@ class Trace: def save(self, fname, item_format='e', **kwargs): save_table_with_header(fname, self.getData(), self.getHeader(), item_format=item_format, **kwargs) + def addPoint(self, val): + self.values = np.append(self.values, val) + class TraceXY(Trace): def __init__(self, label): @@ -64,8 +67,19 @@ class TraceXY(Trace): return( config ) def getData(self): - data=np.concatenate((self.x.values, self.y.values), 1) + data=self.x.values + if data.ndim == 1: + data = data[:, np.newaxis] + vals = self.y.values + if vals.ndim == 1: + vals = vals[:, np.newaxis] + data=np.concatenate((data, vals), 1) return( data ) + + def addPoint(self, valX, valY): + self.x.values = np.append(self.x.values, valX) + self.y.values = np.append(self.y.values, valY) + class TraceSetSameX(Trace): def __init__(self, label): @@ -120,10 +134,24 @@ class TraceSetSameX(Trace): def getData(self): data=self.x.values + if data.ndim == 1: + data = data[:, np.newaxis] for k,v in self.traces.items(): - data=np.concatenate((data, v.values), 1) + vals = v.values + if vals.ndim == 1: + vals = vals[:, np.newaxis] + data=np.concatenate((data, vals), 1) return( data ) + def addPointToTrace(self, val, name=None): + if name is None: + self.x.values = np.append(self.x.values, val) + else: + a = self.traces[name].values + a = np.append(a, val) + self.traces[name].values = a + + if __name__ == '__main__': print("Testing trace") |