diff options
author | Daniel Friesel <daniel.friesel@uos.de> | 2021-03-09 16:04:19 +0100 |
---|---|---|
committer | Daniel Friesel <daniel.friesel@uos.de> | 2021-03-09 16:04:19 +0100 |
commit | 396bc7fa899be4c1dc95a32476922c9a488cded2 (patch) | |
tree | 7cbec75549fe637b63d2f38a964db5408502d05b /lib/loader/keysight.py | |
parent | 3a06a2ea959e184760c174f73fbee2c358b1a585 (diff) |
Refactor loader into separate ET / MIMOSA modules
Diffstat (limited to 'lib/loader/keysight.py')
-rw-r--r-- | lib/loader/keysight.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/loader/keysight.py b/lib/loader/keysight.py new file mode 100644 index 0000000..b9b298d --- /dev/null +++ b/lib/loader/keysight.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 + +import csv +import logging +import numpy as np + +logger = logging.getLogger(__name__) + + +class KeysightCSV: + """Simple loader for Keysight CSV data, as exported by the windows software.""" + + def __init__(self): + """Create a new KeysightCSV object.""" + pass + + def load_data(self, filename: str): + """ + Load log data from filename, return timestamps and currents. + + Returns two one-dimensional NumPy arrays: timestamps and corresponding currents. + """ + with open(filename) as f: + for i, _ in enumerate(f): + pass + timestamps = np.ndarray((i - 3), dtype=float) + currents = np.ndarray((i - 3), dtype=float) + # basically seek back to start + with open(filename) as f: + for _ in range(4): + next(f) + reader = csv.reader(f, delimiter=",") + for i, row in enumerate(reader): + timestamps[i] = float(row[0]) + currents[i] = float(row[2]) * -1 + return timestamps, currents |