Skip to content

Commit

Permalink
Merge pull request #118 from patrickherring-TRI/MAT-1993_featurizatio…
Browse files Browse the repository at this point in the history
…n_failure_get_v_diff

Create test and test file to resolve error
  • Loading branch information
patrickherring-TRI authored Oct 12, 2020
2 parents 3939daa + c4161ce commit 730c89d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
18 changes: 14 additions & 4 deletions beep/features/featurizer_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ def get_V_I(df):
return result


def get_v_diff(processed_cycler_run, diag_pos, soc_window):
def get_v_diff(processed_cycler_run, diag_pos, soc_window, baseline_step_index=15, measured_step_index=47):
"""
This method calculates the variance of voltage difference between a specified hppc cycle and the first
one during a specified state of charge window.
Expand All @@ -600,6 +600,8 @@ def get_v_diff(processed_cycler_run, diag_pos, soc_window):
diag_pos (int): diagnostic cycle occurence for a specific <diagnostic_cycle_type>. e.g.
if rpt_0.2C, occurs at cycle_index = [2, 37, 142, 244 ...], <diag_pos>=0 would correspond to cycle_index 2
soc_window (int): step index counter corresponding to the soc window of interest.
baseline_step_index (int): step index of the initial hppc cycle (TODO automatically get value in the method)
measured_step_index (int): step index of the comparison hppc cycle (TODO automatically get value in the method)
Returns:
a dataframe that contains the variance of the voltage differences
Expand All @@ -618,8 +620,8 @@ def get_v_diff(processed_cycler_run, diag_pos, soc_window):

# the discharge steps in later hppc cycles has a step number of 47
# but that in the initial hppc cycle has a step number of 15
hppc_data_2_d = hppc_data_2.loc[hppc_data_2.step_index == 47]
hppc_data_1_d = hppc_data_1.loc[hppc_data_1.step_index == 15]
hppc_data_2_d = hppc_data_2.loc[hppc_data_2.step_index == measured_step_index]
hppc_data_1_d = hppc_data_1.loc[hppc_data_1.step_index == baseline_step_index]
step_counters_1 = hppc_data_1_d.step_index_counter.unique()
step_counters_2 = hppc_data_2_d.step_index_counter.unique()
chosen_1 = hppc_data_1_d.loc[
Expand All @@ -633,7 +635,15 @@ def get_v_diff(processed_cycler_run, diag_pos, soc_window):

V = chosen_1.voltage.values
Q = chosen_1.discharge_capacity.values
f = interp1d(Q, V, kind="cubic", fill_value="extrapolate")

# Round values so that non-strictly monotonic values are removed
np.around(Q, decimals=6, out=Q)
np.around(V, decimals=6, out=V)
if not np.all(np.diff(Q) > 0):
index_of_repeated = np.where(np.abs(np.diff(Q)) == 0)[0]
Q = np.delete(Q, index_of_repeated, axis=0)
V = np.delete(V, index_of_repeated, axis=0)
f = interp1d(Q, V, kind="cubic", fill_value="extrapolate", assume_sorted=False)

v_2 = chosen_2.voltage.tolist()
v_1 = f(chosen_2.discharge_capacity).tolist()
Expand Down
21 changes: 21 additions & 0 deletions beep/tests/test_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,24 @@ def test_generate_dQdV_peak_fits(self):
['m0_Amp_rpt_0.2C_1', 'm0_Mu_rpt_0.2C_1', 'm1_Amp_rpt_0.2C_1',
'm1_Mu_rpt_0.2C_1', 'm2_Amp_rpt_0.2C_1', 'm2_Mu_rpt_0.2C_1',
'trough_height_0_rpt_0.2C_1', 'trough_height_1_rpt_0.2C_1'])

def test_get_v_diff(self):
processed_cycler_run_path_1 = os.path.join(
TEST_FILE_DIR, "Talos_001383_NCR18650618001_CH31_truncated_structure.json"
)
processed_cycler_run_path_2 = os.path.join(
TEST_FILE_DIR, "PreDiag_000304_000153_truncated_structure.json"
)
with ScratchDir("."):
os.environ["BEEP_PROCESSING_DIR"] = TEST_FILE_DIR
pcycler_run = loadfn(processed_cycler_run_path_1)
v_vars_df = featurizer_helpers.get_v_diff(pcycler_run, 1, 8)
print(v_vars_df)
self.assertEqual(np.round(v_vars_df.iloc[0]['var(v_diff)'], decimals=8),
np.round(0.00850563, decimals=8))

pcycler_run = loadfn(processed_cycler_run_path_2)
v_vars_df = featurizer_helpers.get_v_diff(pcycler_run, 1, 8)
print(v_vars_df)
self.assertEqual(np.round(v_vars_df.iloc[0]['var(v_diff)'], decimals=8),
np.round(2.664685514952474e-05, decimals=8))

Large diffs are not rendered by default.

0 comments on commit 730c89d

Please sign in to comment.