aboutsummaryrefslogtreecommitdiff
path: root/qolab/data
diff options
context:
space:
mode:
authorEugeniy E. Mikhailov <evgmik@gmail.com>2024-06-25 23:49:52 -0400
committerEugeniy E. Mikhailov <evgmik@gmail.com>2024-06-25 23:49:52 -0400
commit4951d890ad4ae3422a7ba717cb1c55ae7a891df5 (patch)
tree728129a50f68a03c5f79057c203164ee5b662d3a /qolab/data
parentda84938d06877f860e03831f6f8a3d8e6140235e (diff)
downloadqolab-4951d890ad4ae3422a7ba717cb1c55ae7a891df5.tar.gz
qolab-4951d890ad4ae3422a7ba717cb1c55ae7a891df5.zip
Added documentation to trace module
Diffstat (limited to 'qolab/data')
-rw-r--r--qolab/data/trace.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/qolab/data/trace.py b/qolab/data/trace.py
index 843d48e..87e0b4e 100644
--- a/qolab/data/trace.py
+++ b/qolab/data/trace.py
@@ -6,6 +6,7 @@ import pandas
import os
def headerFromDictionary(d, prefix=''):
+ """Converts dictionary to YAML format with optional prefix for every line."""
header = []
tail = yaml.dump(d, default_flow_style=False, sort_keys=False)
tail = tail.split('\n')
@@ -14,14 +15,17 @@ def headerFromDictionary(d, prefix=''):
return prefixed_header
def from_timestamps_to_dates(timestamps):
+ """Formats timestamps to datetime format"""
dates = [datetime.datetime.fromtimestamp(float(ts)) for ts in timestamps]
return(dates)
def loadTraceRawHeaderAndData(fname, tryCompressedIfMissing=True):
- # Attempts to load a compressed file if the main is missing
- # and `tryCompressedIfMissing` is set to `True`.
- # E.g. if we try to load 'data.dat' file and it is missing, attempt to load 'data.dat.gz'
- # this option is mainly for compatibility with old scripts which are not aware of compressed files
+ """Load trace file and return header and data.
+ Attempts to load a compressed file if the main is missing
+ and `tryCompressedIfMissing` is set to `True`.
+ E.g. if we try to load 'data.dat' file and it is missing, attempt to load 'data.dat.gz'
+ this option is mainly for compatibility with old scripts which are not aware of compressed files
+ """
headerstr=[]
data = None
if (not os.path.exists(fname)) and tryCompressedIfMissing:
@@ -62,10 +66,12 @@ def loadTraceRawHeaderAndData(fname, tryCompressedIfMissing=True):
return(header, data)
def loadTrace(fname, tryCompressedIfMissing=True):
+ """Load trace file."""
(header, data) = loadTraceRawHeaderAndData(fname, tryCompressedIfMissing=tryCompressedIfMissing)
return traceFromHeaderAndData(header, data)
def traceFromHeaderAndData(header, data=None):
+ """Generate trace class from it description (header) and data."""
label = None
model = None
tr = None
@@ -117,6 +123,7 @@ def traceFromHeaderAndData(header, data=None):
return tr
class Trace:
+ """Base Trace class, which holds only one variable"""
def __init__(self, label):
self.config = {}
self.config['label'] = label
@@ -189,6 +196,7 @@ class Trace:
class TraceXY(Trace):
+ """Data structure to handle two variables X and Y, handy for Y vs X data arrangements."""
def __init__(self, label):
super().__init__(label)
self.config['model'] = 'TraceXY'
@@ -249,6 +257,7 @@ class TraceXY(Trace):
class TraceSetSameX(Trace):
+ """Data structure to handle multiple Ys vs X dependencies, handy for scope traces."""
def __init__(self, label):
super().__init__(label)
self.config['model'] = 'TraceSetSameX'