aboutsummaryrefslogtreecommitdiff
path: root/qolab
diff options
context:
space:
mode:
Diffstat (limited to 'qolab')
-rw-r--r--qolab/data/trace.py34
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")