Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Structuring 3 #760

Open
wants to merge 46 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
8a8274c
initial draft for structure v3
ardunn Mar 2, 2023
69090d3
adding some bugfixes and nice-to-haves in early draft of structuringv3
ardunn Mar 2, 2023
054130a
various basic improvements to __repr__s and functionality
ardunn Mar 2, 2023
66b13c8
double structure
ardunn Mar 2, 2023
f498f77
allow for single items to be returned thru DFSelectorAggregator so at…
ardunn Apr 22, 2023
8e8f0ba
allow for single items to be returned thru DFSelectorAggregator so at…
ardunn Apr 22, 2023
55094cb
update structuring config to be more sane
ardunn Apr 22, 2023
148f413
update config setting for cycles
ardunn Apr 22, 2023
b3d811e
update config setting for cycles
ardunn Apr 22, 2023
a89bff8
[skip ci]
ardunn Apr 22, 2023
21868fb
renmove multiple ways of setting configs, separate configs into Step-…
ardunn Apr 22, 2023
ea3c42e
working but untested sane methods for both paradigms of interpolation
ardunn Apr 23, 2023
97d320e
removal of update_nested as it is no longer needed
ardunn Apr 23, 2023
759bf35
add a basic assignment for DiagnosticConfig in Run, untested
ardunn Apr 23, 2023
7230de8
remove unneeded kwargs from Diagnostic config [skip ci]
ardunn Apr 23, 2023
06497f2
fix problem with empty multistep dataframes
ardunn Apr 23, 2023
6c024f2
[skip ci]
ardunn Apr 23, 2023
2edf0e8
enable dask bag for all cyclecontainers
ardunn May 11, 2023
8e785a6
update Run to include dask bags inside cyclecontainers
ardunn May 11, 2023
fe1bc3e
[skip ci]
ardunn May 11, 2023
327e09a
separate modules
ardunn May 11, 2023
4776a19
[skip ci]
ardunn May 11, 2023
6cc0c49
creating as_dict/from_dict for Monty compatibility
ardunn May 12, 2023
c963f90
[skip ci]
ardunn May 12, 2023
95390bb
move validate
ardunn May 16, 2023
34eb25a
working diagnostic setting and usage via cycle_label
ardunn May 16, 2023
2eeac32
update diagnostic and convert Maccor to Run
ardunn May 17, 2023
57c3424
working basic validation and diagnostic w/o tests
ardunn May 17, 2023
1fc80f5
clean up maccor
ardunn May 17, 2023
36a9f73
implementing basic tests
ardunn May 17, 2023
8394f8c
memory friendly summary method for run
ardunn May 18, 2023
dd2408d
include diagnostic summary in run
ardunn May 18, 2023
437399d
slight refactoring, fixing by_raw_index
ardunn May 18, 2023
a7161f3
[skip ci] fix iterable indexing field
ardunn May 18, 2023
2ed43fe
[skip ci] working serialization with diagnostic
ardunn May 18, 2023
82fbc95
add cycles_to_capacities (and inverse), with better presentation and …
ardunn May 18, 2023
4df5a7d
update run as_dict
ardunn May 19, 2023
07ca92d
make DFSelectorAggregator more idiomatic behavior
ardunn May 19, 2023
182d455
Fix some bugs with cycles_container, move configs to constants, and a…
ardunn May 19, 2023
9e215ae
various bugfizxes
ardunn May 19, 2023
60800e3
update constants
ardunn May 19, 2023
333ca88
update util
ardunn May 19, 2023
a616b6c
refactor step_index -> step_code, which is more reflective of what th…
ardunn May 19, 2023
b919b14
add step test files
ardunn May 19, 2023
c51f7cd
update test_step, add new multistep file
ardunn May 19, 2023
6a28ff2
[skip ci] complete test_step, move .uniques to class attributes for S…
ardunn May 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions beep/conversion_schemas/arbin_conversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ data_columns:
test_time: test_time
datetime: date_time
step_time: step_time
step_index: step_index
step_code: step_code
cycle_index: cycle_index
current: current
voltage: voltage
Expand All @@ -41,7 +41,7 @@ data_types:
test_time: 'float64'
datetime: 'float32'
step_time: 'float32'
step_index: 'int16'
step_code: 'int16'
cycle_index: 'int32'
current: 'float32'
voltage: 'float32'
Expand Down
2 changes: 1 addition & 1 deletion beep/conversion_schemas/biologic_conversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ data_columns:
beep_name: cycle_index
data_type: int
Ns:
beep_name: step_index
beep_name: step_code
data_type: int
Ecell/V:
beep_name: voltage
Expand Down
2 changes: 1 addition & 1 deletion beep/conversion_schemas/indigo_conversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ metadata_fields:
data_columns:
test_time: test_time
date_time_iso: date_time_iso
half_cycle_count: step_index
half_cycle_count: step_code
cycle_count: cycle_index
cell_current_a: current
cell_voltage_v: voltage
Expand Down
2 changes: 1 addition & 1 deletion beep/conversion_schemas/maccor_conversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ metadata_fields:
data_columns:
rec#: data_point
cyc#: cycle_index
step: step_index
step: step_code
test (sec): test_time
step (sec): step_time
# amp-hr and watt-hr are a bit ambiguous
Expand Down
2 changes: 1 addition & 1 deletion beep/conversion_schemas/neware_conversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ data_columns:
test_time: test_time
Realtime: date_time
Time(h:min:s.ms): step_time
Step ID: step_index
Step ID: step_code
Cycle ID: cycle_index
Current(mA): current
Voltage(V): voltage
Expand Down
2 changes: 1 addition & 1 deletion beep/conversion_schemas/novonix_conversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ data_columns:
beep_name: cycle_index
data_type: int
Step Type:
beep_name: step_index
beep_name: step_code
data_type: int
Run Time (h):
beep_name: test_time
Expand Down
6 changes: 3 additions & 3 deletions beep/conversion_schemas/structured_dtypes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cycles_interpolated:
charge_energy: 'float32'
discharge_energy: 'float32'
step_type: 'category'
step_index: 'int16'
step_code: 'int16'

summary:
cycle_index: 'int32'
Expand Down Expand Up @@ -62,8 +62,8 @@ diagnostic_interpolated:
test_time: 'float64'
cycle_index: 'int32'
cycle_type: 'category'
step_index: 'int16'
step_index_counter: 'int16'
step_code: 'int16'
step_code_counter: 'int16'
step_type: 'category'
discharge_dQdV: 'float32'
charge_dQdV: 'float32'
Expand Down
16 changes: 8 additions & 8 deletions beep/structure/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from beep.structure.base import BEEPDatapath
from beep.structure.arbin import ArbinDatapath
from beep.structure.indigo import IndigoDatapath
from beep.structure.maccor import MaccorDatapath
from beep.structure.neware import NewareDatapath
from beep.structure.biologic import BiologicDatapath
from beep.structure.battery_archive import BatteryArchiveDatapath
from beep.structure.novonix import NovonixDatapath
# from beep.structure.base import BEEPDatapath
# from beep.structure.arbin import ArbinDatapath
# from beep.structure.indigo import IndigoDatapath
# from beep.structure.maccor import MaccorDatapath
# from beep.structure.neware import NewareDatapath
# from beep.structure.biologic import BiologicDatapath
# from beep.structure.battery_archive import BatteryArchiveDatapath
# from beep.structure.novonix import NovonixDatapath
54 changes: 27 additions & 27 deletions beep/structure/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,10 +649,10 @@ def interpolate_step(
else:
raise ValueError(f"Axis {axis} not a valid step interpolation axis.")

if len(step_df.step_index.unique()) > 1:
if len(step_df.step_code.unique()) > 1:
raise ValueError("Step DF has multiple step indices present!")

step_index = step_df.step_index.iloc[0]
step_code = step_df.step_code.iloc[0]

step_df = interpolate_df(
step_df,
Expand All @@ -664,9 +664,9 @@ def interpolate_step(

step_df["cycle_index"] = cycle_index
step_df["step_type"] = step_type
step_df["step_index"] = step_index
step_df["step_code"] = step_code

for c in ("step_type", "step_index"):
for c in ("step_type", "step_code"):
step_df[c] = step_df[c].astype("category")

all_dfs.append(step_df)
Expand Down Expand Up @@ -717,12 +717,12 @@ def interpolate_cycles(

# If any regular cycle contains a waveform step, interpolate on test_time.
if self.raw_data[reg_mask]. \
groupby(["cycle_index", "step_index"]). \
groupby(["cycle_index", "step_code"]). \
apply(step_is_waveform_dchg).any():
discharge_axis = 'test_time'

if self.raw_data[reg_mask]. \
groupby(["cycle_index", "step_index"]). \
groupby(["cycle_index", "step_code"]). \
apply(step_is_waveform_chg).any():
charge_axis = 'test_time'

Expand Down Expand Up @@ -930,17 +930,17 @@ def interpolate_diagnostic_cycles(
diag_data = self.raw_data.loc[self.raw_data["cycle_index"].isin(self.diagnostic.all_ix)]
# diag_types = [self.diagnostic.cycle_to_type[cix] for cix in diag_data.cycle_index.unique()]

# Counter to ensure non-contiguous repeats of step_index
# Counter to ensure non-contiguous repeats of step_code
# within same cycle_index are grouped separately
diag_data.loc[:, "step_index_counter"] = 0
diag_data.loc[:, "step_code_counter"] = 0

for cycle_index in self.diagnostic.all_ix:
indices = diag_data.loc[diag_data.cycle_index == cycle_index].index
step_index_list = diag_data.step_index.loc[indices]
shifted = step_index_list.ne(step_index_list.shift()).cumsum()
diag_data.loc[indices, "step_index_counter"] = shifted
step_code_list = diag_data.step_code.loc[indices]
shifted = step_code_list.ne(step_code_list.shift()).cumsum()
diag_data.loc[indices, "step_code_counter"] = shifted

group = diag_data.groupby(["cycle_index", "step_index", "step_index_counter"])
group = diag_data.groupby(["cycle_index", "step_code", "step_code_counter"])
incl_columns = [
"current",
"voltage",
Expand All @@ -957,14 +957,14 @@ def interpolate_diagnostic_cycles(
diag_dict = {}
for cycle in diag_data.cycle_index.unique():
diag_dict.update({cycle: None})
steps = diag_data[diag_data.cycle_index == cycle].step_index.unique()
steps = diag_data[diag_data.cycle_index == cycle].step_code.unique()
diag_dict[cycle] = list(steps)

all_dfs = []
for (cycle_index, step_index, step_index_counter), df in tqdm(group, desc="Interpolating diagnostic by step"):
for (cycle_index, step_code, step_code_counter), df in tqdm(group, desc="Interpolating diagnostic by step"):
if len(df.index) < 2:
logger.debug(f"Skipping cycle: {cycle_index}, step: {step_index_counter} with step "
f"type: {step_index} as there were < 2 data points.")
logger.debug(f"Skipping cycle: {cycle_index}, step: {step_code_counter} with step "
f"type: {step_code} as there were < 2 data points.")
step_dv = df.voltage.max() - df.voltage.min()
dv = [df.voltage.min(), df.voltage.max()]
if cycle_index in self.diagnostic.hppc_ix and step_dv >= v_delta_min:
Expand Down Expand Up @@ -1002,15 +1002,15 @@ def interpolate_diagnostic_cycles(
)
new_df["cycle_index"] = cycle_index
new_df["cycle_type"] = self.diagnostic.type_by_ix[cycle_index]
new_df["step_index"] = step_index
new_df["step_index_counter"] = step_index_counter
new_df["step_type"] = diag_dict[cycle_index].index(step_index)
new_df["step_code"] = step_code
new_df["step_code_counter"] = step_code_counter
new_df["step_type"] = diag_dict[cycle_index].index(step_code)
new_df.astype(
{
"cycle_index": "int32",
"cycle_type": "category",
"step_index": "uint8",
"step_index_counter": "int16",
"step_code": "uint8",
"step_code_counter": "int16",
"step_type": "uint8",
}
)
Expand All @@ -1021,15 +1021,15 @@ def interpolate_diagnostic_cycles(
new_df.charge_capacity.diff() / new_df.voltage.diff()
)
if new_df.shape[0] < 2:
logger.debug(f"Step number {step_index_counter} with step type {step_index} has less than "
logger.debug(f"Step number {step_code_counter} with step type {step_code} has less than "
f"2 interpolated points; refusing to append to interpolated data.")
else:
all_dfs.append(new_df)

# Ignore the index to avoid issues with overlapping voltages
result = pd.concat(all_dfs, ignore_index=True)
result.sort_values(
by=["cycle_index", "step_index_counter", "test_time"],
by=["cycle_index", "step_code_counter", "test_time"],
axis=0,
inplace=True
)
Expand Down Expand Up @@ -1074,8 +1074,8 @@ def summarize_diagnostic(self):
for cycle in diag_summary.cycle_index:
raw_cycle = self.raw_data.loc[self.raw_data.cycle_index == cycle]

# Charge is the very first step_index
CCCV = raw_cycle.loc[raw_cycle.step_index == raw_cycle.step_index.min()]
# Charge is the very first step_code
CCCV = raw_cycle.loc[raw_cycle.step_code == raw_cycle.step_code.min()]
CV = get_CV_segment_from_charge(CCCV)
if CV.empty:
logger.debug(f"Failed to extract CV segment for diagnostic cycle {cycle}!")
Expand Down Expand Up @@ -1116,13 +1116,13 @@ def iterate_steps_in_cycle(self, cycle_df, step_type):
step_filter = step_is_chg
else:
raise ValueError(f"'{step_type}' is not a recognized step type")
dfs_chgstate = cycle_df.groupby("step_index").filter(
dfs_chgstate = cycle_df.groupby("step_code").filter(
lambda ldf: step_filter(
ldf,
indeterminate_step_charge=self.indeterminate_step_default_charge
)
)
for _, step_df in dfs_chgstate.groupby("step_index"):
for _, step_df in dfs_chgstate.groupby("step_code"):
yield step_df

@StructuringDecorators.must_be_structured
Expand Down
8 changes: 4 additions & 4 deletions beep/structure/battery_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ def from_file(cls, path):
df = pd.read_csv(path)
df.rename(str.lower, axis="columns", inplace=True)
df.drop(columns=[c for c in cls.COLUMNS_IGNORE if c in df.columns], inplace=True)
df["step_index"] = 0
df["step_code"] = 0

df["step_index"] = df["current (a)"].apply(decide_step_index)
df["step_code"] = df["current (a)"].apply(decide_step_code)

step_change_ix = np.where(np.diff(df["step_index"], prepend=np.nan))[0]
step_change_ix = np.where(np.diff(df["step_code"], prepend=np.nan))[0]

# get list of start times to subtract
start_times = df["test_time (s)"].loc[step_change_ix]
Expand Down Expand Up @@ -123,7 +123,7 @@ def from_file(cls, path):
return cls(df, metadata, paths)


def decide_step_index(i):
def decide_step_code(i):
"""
Decide a step index based on current values.
Args:
Expand Down
Empty file added beep/structure/core/__init__.py
Empty file.
Loading