From 96b859fd94a5b0f1343cd2360117ea00cda26686 Mon Sep 17 00:00:00 2001 From: Samuel Rowlinson <16781733+sjrowlinson@users.noreply.github.com> Date: Thu, 20 Apr 2023 14:10:08 +0100 Subject: [PATCH] #64 --- implementing Experiment format for .mpr --- harvester/harvester/harvest.py | 1 + .../harvester/parse/biologic_input_file.py | 37 +++++++++++++++---- harvester/harvester/parse/input_file.py | 8 ++-- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/harvester/harvester/harvest.py b/harvester/harvester/harvest.py index 070812f3..7e664ba6 100644 --- a/harvester/harvester/harvest.py +++ b/harvester/harvester/harvest.py @@ -224,6 +224,7 @@ def import_file(core_path: str, file_path: str) -> bool: 'task': 'import', 'status': 'in_progress', 'data': [v for v in column_data.values()], + 'labels': tuple(input_file.get_data_labels()), 'test_date': serialize_datetime(core_metadata['Date of Test']) }) if report is None: diff --git a/harvester/harvester/parse/biologic_input_file.py b/harvester/harvester/parse/biologic_input_file.py index 2ef5424a..7461ae3f 100644 --- a/harvester/harvester/parse/biologic_input_file.py +++ b/harvester/harvester/parse/biologic_input_file.py @@ -61,23 +61,46 @@ def get_data_labels(self): 3: 'Rest', } last_Ns_change = 1 + + column_names = self.mpr_file.data.dtype.names + time_col = next((i for i, c in enumerate(column_names) if c.startswith("time")), 3) + cont_col = next((i for i, c in enumerate(column_names) if c.startswith("control")), 4) + prev_time = 0 + for i in range(len(self.mpr_file.data)): last_mode = modes[i-1] last_Ns = self.mpr_file.data[i-1][Ns_index] Ns_change = Ns_changes[i] if Ns_change: + time = self.mpr_file.data[i][time_col] + mode_label = mode_labels.get(last_mode) + if mode_label.casefold() == "rest": + experiment_label = "Rest " + else: + control = self.mpr_file.data[i - 1][cont_col] + if control > 0: + experiment_label = "Charge " + else: + experiment_label = "Discharge " + + is_const_curr = mode_label.casefold() == "cc" + experiment_label += f"at {control} {'mA' if is_const_curr else 'V'} " + experiment_label += f"for {time - prev_time} seconds" + if last_mode in mode_labels: - yield ( - 'Ns_{}_{}'.format(last_Ns, - mode_labels[last_mode]), - (last_Ns_change, i-1) + data_label = ( + f"Ns_{last_Ns}_{mode_label}", (last_Ns_change, i - 1), experiment_label ) else: - yield ( - 'Ns_{}'.format(last_Ns), - (last_Ns_change, i-1) + data_label = ( + f"Ns_{last_Ns}", (last_Ns_change, i - 1), experiment_label ) + last_Ns_change = i + prev_time = time + + yield data_label + def load_metadata(self): file_path = self.file_path diff --git a/harvester/harvester/parse/input_file.py b/harvester/harvester/parse/input_file.py index e4fb0b7b..4718d015 100644 --- a/harvester/harvester/parse/input_file.py +++ b/harvester/harvester/parse/input_file.py @@ -128,16 +128,16 @@ def tsv_format(value): raise def load_data(self, file_path, available_desired_columns): - raise UnsupportedFileTypeError + raise UnsupportedFileTypeError() def get_data_labels(self): - raise UnsupportedFileTypeError + raise UnsupportedFileTypeError() def get_file_column_to_standard_column_mapping(self): """ returns map of file column name strings to column id numbers """ - raise UnsupportedFileTypeError + raise UnsupportedFileTypeError() def load_metadata(self): - raise UnsupportedFileTypeError + raise UnsupportedFileTypeError()