From cd0eaff25b851b8242a164d3b2bef301f58e546e Mon Sep 17 00:00:00 2001 From: rasmusvt Date: Mon, 15 Aug 2022 17:35:01 +0200 Subject: [PATCH] Make BATSMALL-read more general and import decimal = , --- nafuma/electrochemistry/io.py | 28 ++++++++++++++++++++++------ nafuma/electrochemistry/plot.py | 3 ++- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/nafuma/electrochemistry/io.py b/nafuma/electrochemistry/io.py index 7ad764d..296bd4f 100644 --- a/nafuma/electrochemistry/io.py +++ b/nafuma/electrochemistry/io.py @@ -70,7 +70,9 @@ def read_batsmall(path): Output: df: pandas DataFrame containing the data as-is, but without additional NaN-columns.''' - df = pd.read_csv(path, skiprows=2, sep='\t') + + # FIXME Now it is hardcoded that the decimal is a comma. It should do a check, as datasets can vary depending on the system settings of the machine that does the data conversion + df = pd.read_csv(path, skiprows=2, sep='\t', decimal=',') df = df.loc[:, ~df.columns.str.contains('^Unnamed')] return df @@ -133,9 +135,11 @@ def process_batsmall_data(df, options=None): df = unit_conversion(df=df, options=options) + if options['splice_cycles']: df = splice_cycles(df=df, options=options) + # Replace NaN with empty string in the Comment-column and then remove all steps where the program changes - this is due to inconsistent values for current df[["comment"]] = df[["comment"]].fillna(value={'comment': ''}) df = df[df["comment"].str.contains("program")==False] @@ -694,11 +698,23 @@ def get_old_units(df: pd.DataFrame, options: dict) -> dict: if options['kind'] == 'batsmall': - time = df.columns[0].split()[-1].strip('[]') - voltage = df.columns[1].split()[-1].strip('[]') - current = df.columns[2].split()[-1].strip('[]') - capacity, mass = df.columns[4].split()[-1].strip('[]').split('/') - old_units = {'time': time, 'current': current, 'voltage': voltage, 'capacity': capacity, 'mass': mass} + old_units = {} + + for column in df.columns: + if 'TT [' in column: + old_units['time'] = column.split()[-1].strip('[]') + elif 'U [' in column: + old_units['voltage'] = column.split()[-1].strip('[]') + elif 'I [' in column: + old_units['current'] = column.split()[-1].strip('[]') + elif 'C [' in column: + old_units['capacity'], old_units['mass'] = column.split()[-1].strip('[]').split('/') + + # time = df.columns[0].split()[-1].strip('[]') + # voltage = df.columns[1].split()[-1].strip('[]') + # current = df.columns[2].split()[-1].strip('[]') + # capacity, mass = df.columns[4].split()[-1].strip('[]').split('/') + # old_units = {'time': time, 'current': current, 'voltage': voltage, 'capacity': capacity, 'mass': mass} if options['kind']=='neware': diff --git a/nafuma/electrochemistry/plot.py b/nafuma/electrochemistry/plot.py index 7a0246c..8fbee49 100644 --- a/nafuma/electrochemistry/plot.py +++ b/nafuma/electrochemistry/plot.py @@ -23,7 +23,7 @@ def plot_gc(data, options=None): # Update options - required_options = ['force_reload', 'x_vals', 'y_vals', 'which_cycles', 'limit', 'exclude_cycles', 'show_plot', 'charge', 'discharge', 'colours', 'differentiate_charge_discharge', 'gradient', 'interactive', 'interactive_session_active', 'rc_params', 'format_params', 'save_gif', 'save_path', 'fps'] + required_options = ['force_reload', 'x_vals', 'y_vals', 'which_cycles', 'limit', 'exclude_cycles', 'show_plot', 'summary', 'charge', 'discharge', 'colours', 'differentiate_charge_discharge', 'gradient', 'interactive', 'interactive_session_active', 'rc_params', 'format_params', 'save_gif', 'save_path', 'fps'] default_options = { 'force_reload': False, 'x_vals': 'capacity', 'y_vals': 'voltage', @@ -31,6 +31,7 @@ def plot_gc(data, options=None): 'limit': None, # Limit line to be drawn 'exclude_cycles': [], 'show_plot': True, + 'summary': False, 'charge': True, 'discharge': True, 'colours': None, 'differentiate_charge_discharge': True,