From 9ebab7d6ee979a7bf61dbdd8e3602d8d70c014c1 Mon Sep 17 00:00:00 2001 From: rasmusvt Date: Mon, 1 Aug 2022 15:47:46 +0200 Subject: [PATCH] Add splice cycles for Neware (summary + cycles) --- nafuma/electrochemistry/io.py | 47 +++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/nafuma/electrochemistry/io.py b/nafuma/electrochemistry/io.py index 108c5eb..71fa93b 100644 --- a/nafuma/electrochemistry/io.py +++ b/nafuma/electrochemistry/io.py @@ -206,6 +206,47 @@ def splice_cycles(df, options: dict) -> pd.DataFrame: add = df['specific_capacity'].iloc[i-1] df['specific_capacity'].iloc[i:last_chg] = df['specific_capacity'].iloc[i:last_chg] + add + + if options['kind'] == 'neware': + + if options['summary']: + for i in range(df['cycle'].max()): + sub_df = df.loc[df['cycle'] == i+1].copy() + + if sub_df['status'].loc[sub_df['status'] == 'CC Chg'].count() > 1: + indices = sub_df.index[sub_df['status'] == 'CC Chg'] + + add_columns = ['capacity', 'specific_capacity', 'ions', 'energy', 'cycle_time'] + + for column in add_columns: + if column in df.columns: + df[column].iloc[indices[-1]] = df[column].iloc[indices[-1]] + df[column].iloc[indices[0]] + + df.drop(index=indices[0], inplace=True) + df.reset_index(inplace=True, drop=True) + + else: + for i in range(df['cycle'].max()): + sub_df = df.loc[df['cycle'] == i+1].copy() + sub_chg_df = sub_df.loc[sub_df['status'] == 'CC Chg'].copy() + + steps_indices = sub_chg_df['steps'].unique() + + if len(steps_indices) > 1: + + add_columns = ['capacity', 'specific_capacity', 'ions', 'energy', 'cycle_time'] + + for column in add_columns: + if column in df.columns: + # Extract the maximum value from the first of the two cycles by accessing the column value of the highest index of the first cycle + add = df[column].iloc[df.loc[df['steps'] == steps_indices[0]].index.max()] + + df[column].loc[df['steps'] == steps_indices[1]] += add + + + + + return df @@ -245,6 +286,9 @@ def process_neware_data(df, options={}): df = unit_conversion(df=df, options=options) # converts all units from the old units to the desired units + if options['splice_cycles']: + df = splice_cycles(df=df, options=options) + # Creates masks for charge and discharge curves chg_mask = df['status'] == 'CC Chg' @@ -294,6 +338,9 @@ def process_neware_data(df, options={}): df = add_columns(df=df, options=options) df = unit_conversion(df=df, options=options) + if options['splice_cycles']: + df = splice_cycles(df=df, options=options) + return df