Skip to content

Commit

Permalink
Merge pull request #103 from BruisVanVlijmen2020/update_DiagnosticPro…
Browse files Browse the repository at this point in the history
…perties_nx

Initial commit to discharge throughput normalization
  • Loading branch information
chirranjeevigopal-TRI authored Sep 24, 2020
2 parents b6388ec + e70c55d commit 517e131
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 5 deletions.
57 changes: 57 additions & 0 deletions beep/features/featurizer_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,7 @@ def get_fractional_quantity_remaining(
"""
Determine relative loss of <metric> in diagnostic_cycles of type <diagnostic_cycle_type> after 100 regular cycles
Args:
processed_cycler_run (beep.structure.ProcessedCyclerRun): information about cycler run
metric (str): column name to use for measuring degradation
Expand All @@ -886,3 +887,59 @@ def get_fractional_quantity_remaining(
)
summary_diag_cycle_type.columns = ["cycle_index", "fractional_metric"]
return summary_diag_cycle_type


def get_fractional_quantity_remaining_nx(
processed_cycler_run, metric="discharge_energy", diagnostic_cycle_type="rpt_0.2C"
):
"""
Similar to get_fractional_quantity_remaining()
Determine relative loss of <metric> in diagnostic_cycles of type <diagnostic_cycle_type>
Also returns value of 'x', the discharge throughput passed by the first diagnostic
and the value 'n' at each diagnostic
Args:
processed_cycler_run (beep.structure.ProcessedCyclerRun): information about cycler run
metric (str): column name to use for measuring degradation
diagnostic_cycle_type (str): the diagnostic cycle to use for computing the amount of degradation
Returns:
a dataframe with cycle_index, corresponding degradation relative to the first measured value, 'x',
i.e. the discharge throughput passed by the first diagnostic
and the value 'n' at each diagnostic, i.e. the equivalent scaling factor for lifetime using n*x
"""
summary_diag_cycle_type = processed_cycler_run.diagnostic_summary[
(processed_cycler_run.diagnostic_summary.cycle_type == diagnostic_cycle_type)
].reset_index()
summary_diag_cycle_type = summary_diag_cycle_type[["cycle_index", metric]]

# For the nx addition
if 'energy' in metric:
normalize_qty = 'discharge' + '_energy'
else:
normalize_qty = 'discharge' + '_capacity'

normalize_qty_throughput = normalize_qty + '_throughput'
regular_summary = processed_cycler_run.summary.copy()
regular_summary[normalize_qty_throughput] = regular_summary[normalize_qty].cumsum()
indices = summary_diag_cycle_type.cycle_index
initial_throughput = regular_summary.loc[
regular_summary.cycle_index == indices.iloc[0]
][normalize_qty_throughput].iloc[0]
x = regular_summary.loc[
regular_summary.cycle_index == indices.iloc[1]
][normalize_qty_throughput].iloc[0] - initial_throughput

summary_diag_cycle_type['x'] = x
summary_diag_cycle_type['n'] = (
(1/x) * regular_summary[regular_summary.cycle_index.isin(indices)][normalize_qty_throughput]
).values

# end of nx addition
summary_diag_cycle_type[metric] = (
summary_diag_cycle_type[metric]
/ processed_cycler_run.diagnostic_summary[metric].iloc[0]
)

summary_diag_cycle_type.columns = ["cycle_index", "fractional_metric", "x", "n"]
return summary_diag_cycle_type
7 changes: 5 additions & 2 deletions beep/featurize.py
Original file line number Diff line number Diff line change
Expand Up @@ -1099,12 +1099,14 @@ def validate_data(cls, processed_cycler_run, params_dict=None):
@classmethod
def features_from_processed_cycler_run(cls, processed_cycler_run, params_dict=None):
"""
Generates diagnostic-property features from processed cycler run, including values for n*x method
Args:
processed_cycler_run (beep.structure.ProcessedCyclerRun): data from cycler run
params_dict (dict): dictionary of parameters governing how the ProcessedCyclerRun object
gets featurized. These could be filters for column or row operations
Returns:
pd.DataFrame: cycles at which capacity/energy degradation exceeds thresholds
pd.DataFrame: with "cycle_index", "fractional_metric", "x", "n", "cycle_type" and "metric" columns, rows
for each diagnostic cycle of the cell
"""
if params_dict is None:
params_dict = FEATURE_HYPERPARAMS[cls.class_feature_name]
Expand All @@ -1113,9 +1115,10 @@ def features_from_processed_cycler_run(cls, processed_cycler_run, params_dict=No
X = pd.DataFrame()
for quantity in params_dict["quantities"]:
for cycle_type in cycle_types:
summary_diag_cycle_type = featurizer_helpers.get_fractional_quantity_remaining(
summary_diag_cycle_type = featurizer_helpers.get_fractional_quantity_remaining_nx(
processed_cycler_run, quantity, cycle_type
)

summary_diag_cycle_type["cycle_type"] = cycle_type
summary_diag_cycle_type["metric"] = quantity
X = X.append(summary_diag_cycle_type)
Expand Down
6 changes: 3 additions & 3 deletions beep/tests/test_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def test_feature_generation_list_to_json(self):
self.assertIsInstance(features_reloaded, DiagnosticProperties)
self.assertListEqual(
list(features_reloaded.X.iloc[2, :]),
[143, 0.9753520623934744, "rpt_0.2C", "discharge_energy"],
[141,0.9859837086597274,91.17758004259996,2.578137278917377,'reset','discharge_energy'],
)

# Workflow output
Expand Down Expand Up @@ -357,8 +357,8 @@ def test_DiagnosticProperties_class(self):
folder = os.path.split(path)[-1]
dumpfn(featurizer, featurizer.name)
self.assertEqual(folder, "DiagnosticProperties")
self.assertEqual(featurizer.X.shape, (10, 4))
self.assertEqual(featurizer.X.shape, (30, 6))
self.assertListEqual(
list(featurizer.X.iloc[2, :]),
[143, 0.9753520623934744, "rpt_0.2C", "discharge_energy"],
[141,0.9859837086597274,91.17758004259996,2.578137278917377,'reset','discharge_energy']
)

0 comments on commit 517e131

Please sign in to comment.