Mix intervals and ints in update_cycles
This commit is contained in:
parent
9ebab7d6ee
commit
0699399d1a
1 changed files with 55 additions and 35 deletions
|
|
@ -19,10 +19,11 @@ def plot_gc(data, options=None):
|
||||||
|
|
||||||
|
|
||||||
# Update options
|
# Update options
|
||||||
required_options = ['x_vals', 'y_vals', 'which_cycles', 'charge', 'discharge', 'colours', 'differentiate_charge_discharge', 'gradient', 'interactive', 'interactive_session_active', 'rc_params', 'format_params']
|
required_options = ['x_vals', 'y_vals', 'which_cycles', 'exclude_cycles', 'charge', 'discharge', 'colours', 'differentiate_charge_discharge', 'gradient', 'interactive', 'interactive_session_active', 'rc_params', 'format_params']
|
||||||
default_options = {
|
default_options = {
|
||||||
'x_vals': 'capacity', 'y_vals': 'voltage',
|
'x_vals': 'capacity', 'y_vals': 'voltage',
|
||||||
'which_cycles': 'all',
|
'which_cycles': 'all',
|
||||||
|
'exclude_cycles': [],
|
||||||
'charge': True, 'discharge': True,
|
'charge': True, 'discharge': True,
|
||||||
'colours': None,
|
'colours': None,
|
||||||
'differentiate_charge_discharge': True,
|
'differentiate_charge_discharge': True,
|
||||||
|
|
@ -35,43 +36,45 @@ def plot_gc(data, options=None):
|
||||||
options = aux.update_options(options=options, required_options=required_options, default_options=default_options)
|
options = aux.update_options(options=options, required_options=required_options, default_options=default_options)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if not 'cycles' in data.keys():
|
if not 'cycles' in data.keys():
|
||||||
data['cycles'] = ec.io.read_data(data=data, options=options)
|
data['cycles'] = ec.io.read_data(data=data, options=options)
|
||||||
|
|
||||||
# Update list of cycles to correct indices
|
|
||||||
update_cycles_list(cycles=data['cycles'], options=options)
|
|
||||||
|
|
||||||
colours = generate_colours(cycles=data['cycles'], options=options)
|
|
||||||
|
|
||||||
if options['interactive']:
|
|
||||||
options['interactive'], options['interactive_session_active'] = False, True
|
|
||||||
plot_gc_interactive(data=data, options=options)
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
# Prepare plot, and read and process data
|
|
||||||
|
|
||||||
fig, ax = btp.prepare_plot(options=options)
|
if not options['summary']:
|
||||||
|
# Update list of cycles to correct indices
|
||||||
|
update_cycles_list(data=data, options=options)
|
||||||
|
|
||||||
for i, cycle in enumerate(data['cycles']):
|
colours = generate_colours(cycles=data['cycles'], options=options)
|
||||||
if i in options['which_cycles']:
|
|
||||||
if options['charge']:
|
|
||||||
cycle[0].plot(x=options['x_vals'], y=options['y_vals'], ax=ax, c=colours[i][0])
|
|
||||||
|
|
||||||
if options['discharge']:
|
if options['interactive']:
|
||||||
cycle[1].plot(x=options['x_vals'], y=options['y_vals'], ax=ax, c=colours[i][1])
|
options['interactive'], options['interactive_session_active'] = False, True
|
||||||
|
plot_gc_interactive(data=data, options=options)
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
if options['interactive_session_active']:
|
# Prepare plot, and read and process data
|
||||||
update_labels(options, force=True)
|
|
||||||
else:
|
fig, ax = btp.prepare_plot(options=options)
|
||||||
update_labels(options)
|
|
||||||
|
|
||||||
fig, ax = btp.adjust_plot(fig=fig, ax=ax, options=options)
|
for i, cycle in enumerate(data['cycles']):
|
||||||
|
if i in options['which_cycles']:
|
||||||
|
if options['charge']:
|
||||||
|
cycle[0].plot(x=options['x_vals'], y=options['y_vals'], ax=ax, c=colours[i][0])
|
||||||
|
|
||||||
#if options['interactive_session_active']:
|
if options['discharge']:
|
||||||
|
cycle[1].plot(x=options['x_vals'], y=options['y_vals'], ax=ax, c=colours[i][1])
|
||||||
|
|
||||||
|
|
||||||
|
if options['interactive_session_active']:
|
||||||
|
update_labels(options, force=True)
|
||||||
|
else:
|
||||||
|
update_labels(options)
|
||||||
|
|
||||||
|
fig, ax = btp.adjust_plot(fig=fig, ax=ax, options=options)
|
||||||
|
|
||||||
|
elif options['summary']:
|
||||||
|
|
||||||
|
fig, ax = 0, 0
|
||||||
|
|
||||||
|
|
||||||
return data['cycles'], fig, ax
|
return data['cycles'], fig, ax
|
||||||
|
|
@ -118,29 +121,46 @@ def update_labels(options, force=False):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def update_cycles_list(cycles, options: dict) -> None:
|
def update_cycles_list(data, options: dict) -> None:
|
||||||
|
|
||||||
if options['which_cycles'] == 'all':
|
if options['which_cycles'] == 'all':
|
||||||
options['which_cycles'] = [i for i in range(len(cycles))]
|
options['which_cycles'] = [i for i in range(len(data['cycles']))]
|
||||||
|
|
||||||
|
|
||||||
elif type(options['which_cycles']) == list:
|
elif isinstance(options['which_cycles'], list):
|
||||||
options['which_cycles'] = [i-1 for i in options['which_cycles']]
|
|
||||||
|
cycles =[]
|
||||||
|
|
||||||
|
for cycle in options['which_cycles']:
|
||||||
|
if isinstance(cycle, int):
|
||||||
|
cycles.append(cycle-1)
|
||||||
|
|
||||||
|
elif isinstance(cycle, tuple):
|
||||||
|
interval = [i-1 for i in range(cycle[0], cycle[1]+1)]
|
||||||
|
cycles.extend(interval)
|
||||||
|
|
||||||
|
|
||||||
|
options['which_cycles'] = cycles
|
||||||
|
|
||||||
|
|
||||||
# Tuple is used to define an interval - as elements tuples can't be assigned, I convert it to a list here.
|
# Tuple is used to define an interval - as elements tuples can't be assigned, I convert it to a list here.
|
||||||
elif type(options['which_cycles']) == tuple:
|
elif isinstance(options['which_cycles'], tuple):
|
||||||
which_cycles = list(options['which_cycles'])
|
which_cycles = list(options['which_cycles'])
|
||||||
|
|
||||||
if which_cycles[0] <= 0:
|
if which_cycles[0] <= 0:
|
||||||
which_cycles[0] = 1
|
which_cycles[0] = 1
|
||||||
|
|
||||||
elif which_cycles[1] < 0:
|
elif which_cycles[1] < 0:
|
||||||
which_cycles[1] = len(cycles)
|
which_cycles[1] = len(options['which_cycles'])
|
||||||
|
|
||||||
|
|
||||||
options['which_cycles'] = [i-1 for i in range(which_cycles[0], which_cycles[1]+1)]
|
options['which_cycles'] = [i-1 for i in range(which_cycles[0], which_cycles[1]+1)]
|
||||||
|
|
||||||
|
|
||||||
|
for i, cycle in enumerate(options['which_cycles']):
|
||||||
|
if cycle in options['exclude_cycles']:
|
||||||
|
del options['which_cycles'][i]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue