From 6e3b9ceebd0ee6b6a0c27e3af983969799068e5e Mon Sep 17 00:00:00 2001 From: CPD Date: Mon, 10 Mar 2025 12:20:13 +0100 Subject: [PATCH] Add logging --- cpdctrl/utility/data.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cpdctrl/utility/data.py b/cpdctrl/utility/data.py index 2815cc2..cc690b0 100644 --- a/cpdctrl/utility/data.py +++ b/cpdctrl/utility/data.py @@ -4,11 +4,14 @@ import os import matplotlib.pyplot as plt import datetime import pickle +import logging +log = logging.getLogger(__name__) from cpdctrl.utility.file_io import get_next_filename, sanitize_filename FLUSH_TYPE = "pickle-ndarray" METADATA_FILENAME = "_measurement_metadata.pkl" + class DataCollector: columns = ["idx", "t [s]", "V [V]", "LED [%]"] def __init__(self, @@ -56,6 +59,7 @@ class DataCollector: None. """ filepath = os.path.join(self.dirpath, METADATA_FILENAME) + log.debug(f"Writing metadata to {filepath}") with open(filepath, "wb") as file: pickle.dump(self.metadata, file) @@ -85,11 +89,13 @@ class DataCollector: if FLUSH_TYPE == "csv": filename = self._get_filename() + ".csv" filepath = os.path.join(self.dirpath, filename) + log.info(f"Flushing data to {filepath}") if verbose: print(f"Flushing data to {filepath}") self.to_dataframe().to_csv(filepath, sep=",", index=False, metadata=True) elif FLUSH_TYPE == "pickle-ndarray": filename = self._get_filename() + ".ndarray.pkl" filepath = os.path.join(self.dirpath, filename) + log.info(f"Flushing data to {filepath}") if verbose: print(f"Flushing data to {filepath}") with open(filepath, "wb") as file: pickle.dump(np.array(self.data), file) @@ -117,7 +123,8 @@ class DataCollector: def save_csv(self, sep=",", verbose=False): filepath = os.path.join(self.path, self.dirname + ".csv") - if verbose: print(f"Writing data to {filepath}") + if verbose: print(f"Writing csv to {filepath}") + log.info(f"Writing csv to {filepath}") with open(filepath, "w") as file: file.write(self.to_csv(sep=sep))