Skip to content

Commit feb7cd0

Browse files
authored
Merge pull request #44 from be-smith/bes/timestamp_bug_fix
Add try except around galvani timestamp. Not always present presumably due to the version of ec-lab used to write the file. Also minor bug fixes to the plotting library
2 parents 9f905b2 + 1a4ce08 commit feb7cd0

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/navani/echem.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ def echem_file_loader(filepath: Union[str, Path], mass: float = None, area: floa
7676
gal_file = MPRfile(f)
7777

7878
df = pd.DataFrame(data=gal_file.data)
79-
df["timestamp"] = gal_file.timestamp + pd.to_timedelta(df["time/s"], unit="s")
79+
try:
80+
df["timestamp"] = gal_file.timestamp + pd.to_timedelta(df["time/s"], unit="s")
81+
except AttributeError as e:
82+
print("No timestamp detected in galvani export")
8083
df = biologic_processing(df)
8184

8285
# arbin .res file - uses an sql server and requires mdbtools installed
@@ -909,7 +912,7 @@ def multi_cycle_plot(df: pd.DataFrame, cycles: ArrayLike, colormap: str = 'virid
909912
mask = df['half cycle'] == cycle
910913
ax.plot(df['Capacity'][mask], df['Voltage'][mask], color=cm(norm(np.ceil(cycle/2))))
911914

912-
cbar = fig.colorbar(sm)
915+
cbar = fig.colorbar(sm, ax=ax)
913916
cbar.set_label('Cycle', rotation=270, labelpad=10)
914917
ax.set_ylabel('Voltage / V')
915918
ax.set_xlabel('Capacity / mAh')
@@ -985,7 +988,7 @@ def multi_dqdv_plot(df: pd.DataFrame,
985988

986989
ax.plot(voltage, dqdv, color=cm(norm(np.ceil(cycle/2))))
987990

988-
cbar = fig.colorbar(sm)
991+
cbar = fig.colorbar(sm, ax=ax)
989992
cbar.set_label('Cycle', rotation=270, labelpad=10)
990993
ax.set_xlabel('Voltage / V')
991994
ax.set_ylabel('dQ/dV / $mAhV^{-1}$')

tests/test_echem.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def test_mpr_reader():
9797
df = ec.echem_file_loader(test_path)
9898
assert df.shape == (46102, 19)
9999

100-
cols = (
100+
required_cols = (
101101
"state",
102102
"Capacity",
103103
"dQ/mA.h",
@@ -116,10 +116,11 @@ def test_mpr_reader():
116116
"control/V/mA",
117117
"I Range",
118118
"flags",
119-
"timestamp",
120119
)
120+
optional_cols = ("timestamp",)
121121

122-
assert set(cols) == set(df)
122+
assert set(required_cols) <= set(df)
123+
assert set(df) <= set(required_cols) | set(optional_cols)
123124

124125
mask = df["half cycle"] == 1
125126
voltage, dqdv, capacity = ec.dqdv_single_cycle(

0 commit comments

Comments
 (0)