Skip to content

Commit ad85042

Browse files
authored
Merge pull request #61 from ImperialCollegeLondon/60-fix-biologic-MB-rest
Patch Biologic MB rest bug
2 parents 2844b2c + e4e0692 commit ad85042

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

pyprobe/cyclers/biologic.py

+23-9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import glob
55
import re
6+
import warnings
67
from datetime import datetime
78
from typing import List
89

@@ -51,14 +52,16 @@ def read_file(filepath: str) -> pl.DataFrame:
5152
_, value = start_time_line.split(" : ")
5253
start_time = datetime.strptime(value.strip(), "%m/%d/%Y %H:%M:%S.%f")
5354

54-
columns_to_read = ["time", "Ns", "I", "Ecell", "Q charge", "Q discharge"]
55+
columns_to_read = ["time/", "Ns", "I/", "Ecell/", "Q charge/", "Q discharge/"]
5556

5657
all_columns = pl.scan_csv(
5758
filepath, skip_rows=n_header_lines - 1, separator="\t"
5859
).columns
59-
selected_columns = [
60-
col for col in all_columns if any(sub in col for sub in columns_to_read)
61-
]
60+
selected_columns = []
61+
for substring in columns_to_read:
62+
found_columns = [col for col in all_columns if substring in col]
63+
selected_columns.extend(found_columns)
64+
6265
dataframe = pl.read_csv(
6366
filepath,
6467
skip_rows=n_header_lines - 1,
@@ -107,11 +110,22 @@ def raw_dataframe(self) -> pl.DataFrame:
107110
files = glob.glob(self.input_data_path)
108111
files = self.sort_files(files)
109112
dataframes = [self.read_file(file) for file in files]
110-
111-
for i in range(1, len(dataframes)):
112-
dataframes[i] = dataframes[i].with_columns(
113-
pl.col("Ns") + dataframes[i - 1]["Ns"].max() + 1
114-
)
113+
all_columns = set([col for df in dataframes for col in df.columns])
114+
indices_to_remove = []
115+
for i in range(len(dataframes)):
116+
if len(dataframes[i].columns) < len(all_columns):
117+
indices_to_remove.append(i)
118+
warnings.warn(
119+
f"File {files[i]} has missing columns, it has not been read."
120+
)
121+
continue
122+
if i > 0:
123+
dataframes[i] = dataframes[i].with_columns(
124+
pl.col("Ns") + dataframes[i - 1]["Ns"].max() + 1
125+
)
126+
dataframes = [
127+
df for i, df in enumerate(dataframes) if i not in indices_to_remove
128+
]
115129
return pl.concat(dataframes, how="vertical")
116130

117131
@property

0 commit comments

Comments
 (0)