maccorcyclingdata package¶
Submodules¶
maccorcyclingdata.testdata module¶
-
maccorcyclingdata.testdata.clean_maccor_df(df)[source]¶ Given the testdata dataframe, this function will rename the headers and drop unnecessary columns. It will also change some of the units to match the column name and will remove all commas.
Parameters: df (pandas dataframe) – The testdata dataframe Returns: df – The cleaned pandas df of the testdata Return type: pandas dataframe Notes
If the following columns exist, the function will delete these:
ACR,DCIR,Watt-hr, andnnnamed.Examples
>>> import maccorcyclingdata.testdata as testdata >>> df = testdata.clean_maccor_df(df) >>> df.head(5)
-
maccorcyclingdata.testdata.delete_cycle_steps(df, steps_to_delete, decrement=False)[source]¶ Given the testdata dataframe (from the import_maccor_data or import_multiple_csv_data functions) and a list of integers (step numbers that you want to delete), this function will delete all rows from the dataframe that have a cycle step index that matches any in the list of integers
Parameters: - df (pandas dataframe) – The testdata dataframe
- steps_to_delete (array) – An array that has the step numbers you want to delete
- decrement (boolean) – If set to True, would shift cycle steps to adjust for the deleted steps
Returns: df – The dataframe with the corresponding steps deleted
Return type: pandas dataframe
Examples
>>> import maccorcyclingdata.testdata as testdata >>> del_df = testdata.delete_cycle_steps(df, [1], True) >>> del_df.head(5)
-
maccorcyclingdata.testdata.get_cycle_data(df, Headings, cyc_range, cycle_step_idx=[])[source]¶ Given the testdata df (from the import_maccor_data or import_multiple_csv_data functions), this function gets the data specified in the “Headings” for each sample within the specified cyc_range.
Parameters: - df (pandas dataframe) – The testdata dataframe
- Headings (array) – An array with the headers you want the data for
- cyc_range (array) – An array of the cycle numbers you want data for
- cycle_step_idx (array) – The step numbers within each cycle that you want the data for. Default value is all steps within each cycle.
Returns: data_df – A pandas dataframe that has the data for the specified headers at the specified cycles and steps.
Return type: pandas dataframe
Examples
>>> from maccorcyclingdata.testdata import get_cycle_data >>> data = testdata.get_cycle_data(df, ['current_ma', 'voltage_v'], [1, 3, 5], [12]) >>> print(data[:6])
-
maccorcyclingdata.testdata.get_index_range(df, cyc_range, cycle_step_idx=[])[source]¶ Given the testdata dataframe (from the import_maccor_data or import_multiple_csv_data functions), this function returns the index range for the specified cycle range, or if a cycle step index is passed, as subset of each cyle for only that specific cycle step.
Parameters: - df (pandas dataframe) – The testdata dataframe
- cyc_range (array) – An array of the cycles you want the indices for
- cycle_step_idx (array) – The step numbers that you want the indices of. Default value is all steps within each cycle.
Returns: index_range – A vector of the range of df indices for the specified cycle range
Return type: vector
Examples
>>> from maccorcyclingdata.testdata import get_index_range >>> ind = testdata.get_cycle_data(df, [1, 3, 5], [12]) >>> print(ind[:6])
-
maccorcyclingdata.testdata.get_num_cycles(df)[source]¶ Given the testdata dataframe (from the import_maccor_data or import_multiple_csv_data functions), this function will return the number of cycles.
Parameters: df (pandas dataframe) – The testdata dataframe Returns: number_of_cycles – An integer of the number of cycles in the dataframe Return type: integer Notes
This function assumes that the first cycle is cycle 0.
Examples
>>> from maccorcyclingdata.testdata import get_num_cycles >>> get_num_cycles(df)
-
maccorcyclingdata.testdata.import_maccor_data(file_path, file_name, header=0)[source]¶ Given the file path and file name of the testdata file, this function will import the csv file as a pandas df and clean it.
Parameters: - file_path (string) – File path
- file_name (string) – Filename
- header (integer) – Optional input that sets the header to a line number (default=2)
Returns: df – The cleaned testdata file as a pandas df
Return type: pandas dataframe
Examples
>>> import maccorcyclingdata.testdata as testdata >>> df = testdata.import_maccor_data('example_data/', 'testdata.csv') >>> df.head(5)
-
maccorcyclingdata.testdata.import_multiple_csv_data(file_path)[source]¶ Given the file path that holds multiple csv files (testdata files), this function will import and append all of the csv files to one another as one dataframe. Returns a cleaned version of that dataframe.
Parameters: file_path (string) – File path Returns: df – All of the cleaned csv files appended to one another as a pandas df Return type: pandas dataframe Notes
This function will append the csv files to one another depending on the order they appear in the directory.
Examples
>>> import maccorcyclingdata.testdata as testdata >>> mult_df = testdata.import_multiple_csv_data('example_data/multiple_csv/') >>> mult_df.head(5)
maccorcyclingdata.schedules module¶
-
maccorcyclingdata.schedules.import_schedules(file_path, file_name)[source]¶ Given the file path and file name (of the schedule file that is inputted into the Maccor Cycler), this function will import and clean the schedule file and return it as a df.
Parameters: - file_path (string) – File path
- file_name (string) – Filename
Returns: df – A cleaned schedule df
Return type: pandas dataframe
Notes
The schedule file should be input as a csv.
Examples
>>> import maccorcyclingdata.schedules as schedules >>> schedule_df = schedules.import_schedules('example_data/','schedule.csv') >>> schedule_df.head(5)
-
maccorcyclingdata.schedules.sort_scheduler_steps(schedule_df)[source]¶ Given the schedule_df (the df that was output by import_schedules function), this function will sort rest, charge, discharge, advance cycle, and end step numbers.
Parameters: schedule_df (pandas dataframe) – The cleaned dataframe of the schedule file Returns: - rest_steps (array) – An array of the steps from the schedule file that correlate to rest steps
- charge_steps (array) – An array of the steps from the schedule file that correlate to charging steps
- advance_steps (array) – An array of the steps from the schedule file that correlate to steps when the cycle is advanced
- discharge_steps (array) – An array of the steps from the schedule file that correlate to discharging steps
- end_steps (array) – An array of the steps from the schedule file that correlate to ending steps
- max_step (integer) – The last step from the schedule file
Examples
>>> import maccorcyclingdata.schedules as schedules >>> rest_steps, charge_steps, advance_steps, discharge_steps, end_steps, max_step = sort_scheduler_steps(schedule_df)
maccorcyclingdata.validate module¶
-
maccorcyclingdata.validate.validate_test_data(schedule_df, df, cell_id, time_interval, temp_interval, max_temp, discharge_neg, temp_tol=3, char_tol=2)[source]¶ This is a wrapper function that validates the testdata against the schedule file. The sub-modules that are validated are:
- validation_check_rest(validation_df, df, i, cell_id)
- validation_check_charging(validation_df, df, schedule_df, i, cell_id)
- validation_check_discharging(validation_df, df, schedule_df, i, cell_id, discharge_neg)
- validation_check_advanced_cycle(validation_df, df, i, cell_id)
- validation_check_max_step_num(validation_df, df, max_step, i, cell_id)
- validation_check_max_temp(validation_df, df, max_temp, i, cell_id, tol=3)
- validation_check_time_interval(validation_df, df, time_interval, i, cell_id)
- validation_check_temp_interval(validation_df, df, temp_interval, i, cell_id)
Parameters: - schedule_df (pandas dataframe) – The dataframe of the cleaned schedule file (from import_schedules function)
- df (pandas dataframe) – The testdata dataframe (from the import_maccor_data or import_multiple_csv_data functions)
- cell_id (integer) – The cell id of the testdata
- time_interval (integer) – The maximum interval of how often the cycler should be recording data
- temp_interval (integer) – The maximum interval of a temperature change
- max_temp (integer) – The threshold for the highest temperature allowed
- discharge_neg (boolean) – Set to True if the current was exported as negative during discharge steps.
- temp_tol (integer) – Sets the tolerance between warning, error, and ABORT messages. Default is 3 degrees.
- char_tol (integer) – Sets the tolerance between the current/discharging current values and the set value in the schedule file. Default is 2.
Returns: validation_df – The validation dataframe with any errors (if any) listed Headers of the validation_df:
- time (the current time of when the validation occurs)
- run (tells whether the validation function is in progress or complete)
- cell_num (the cell number of the testdata)
- row_number (the row number where the error occurs)
- error (what the error is)
Return type: pandas dataframe
Notes
Depending on the size of your testdata and schedules, this function may take much longer to run. For reference, the example in the jupyter notebook ran from 1:40pm-3:15pm for 901 cycles. Using timeit to time: 12min 3s ± 1min 56s per loop (mean ± std. dev. of 7 runs, 1 loop each)
There are 3 possibilities of error messages:
- warning - temperature approaching the max! (current temperature + temp_tol > max)
- error - temperature has surpassed the max! (current temperature >= max)
- ABORT - temperature is way too hot! (current temperature > max + temp_tol)
Examples
>>> import maccorcyclingdata.validate as validate >>> validation_df = validate.validate_test_data(schedule_df, df, 1, 10, 30, True, 5) >>> validation_df
-
maccorcyclingdata.validate.validation_check_advanced_cycle(validation_df, df, i, cell_id)[source]¶ This function will validate the testdata against the advance cycle steps by making sure the cycle advances
Parameters: - validation_df (pandas dataframe) – The validation dataframe where any errors will be recorded
- df (pandas dataframe) – The testdata dataframe (from the import_maccor_data or import_multiple_csv_data functions)
- i (integer) – An integer of the index where you want to validate
- cell_id (integer) – The cell id of the testdata
Returns: validation_df – The validation dataframe with any errors listed
Return type: pandas dataframe
Examples
>>> import maccorcyclingdata.validate as validate >>> validation_df = validate.validation_check_advanced_cycle(validation_df, df, i, 1) >>> validation_df
-
maccorcyclingdata.validate.validation_check_charging(validation_df, df, schedule_df, i, cell_id, char_tol=2)[source]¶ This function will validate the testdata against the charging steps by making sure the value of either the voltage or current matches with the value specfied in the scheduler.
Parameters: - validation_df (pandas dataframe) – The validation dataframe where any errors will be recorded
- df (pandas dataframe) – The testdata dataframe (from the import_maccor_data or import_multiple_csv_data functions)
- schedule_df (pandas dataframe) – The dataframe of the cleaned schedule file (from import_schedules function)
- i (integer) – An integer of the index where you want to validate
- cell_id (integer) – The cell id of the testdata
- char_tol (integer) – Sets the tolerance between the current/discharging current values and the set value in the schedule file. Default is 2.
Returns: validation_df – The validation dataframe with any errors listed
Return type: pandas dataframe
Examples
>>> import maccorcyclingdata.validate as validate >>> validation_df = validate.validation_check_charging(validation_df, df, schedule_df, i, 1) >>> validation_df
-
maccorcyclingdata.validate.validation_check_discharging(validation_df, df, schedule_df, i, cell_id, discharge_neg, char_tol=2)[source]¶ This function will validate the testdata against the discharging steps by making sure the value of either the voltage or current matches with the value specfied in the scheduler.
Parameters: - validation_df (pandas dataframe) – The validation dataframe where any errors will be recorded
- df (pandas dataframe) – The testdata dataframe (from the import_maccor_data or import_multiple_csv_data functions)
- schedule_df (pandas dataframe) – The dataframe of the cleaned schedule file (from the import_schedules function)
- i (integer) – An integer of the index where you want to validate
- cell_id (integer) – The cell id of the testdata
- discharge_neg (boolean) – Set to True if the current is exported as negative during discharge steps.
- char_tol (integer) – Sets the tolerance between the current/discharging current values and the set value in the schedule file. Default is 2.
Returns: validation_df – The validation dataframe with any errors listed
Return type: pandas dataframe
Examples
>>> import maccorcyclingdata.validate as validate >>> validation_df = validate.validation_check_discharging(validation_df, df, schedule_df, i, 1, True) >>> validation_df
-
maccorcyclingdata.validate.validation_check_max_step_num(validation_df, df, max_step, i, cell_id)[source]¶ This function will validate the testdata against the max step by making sure no steps surpass the max.
Parameters: - validation_df (pandas dataframe) – The validation dataframe where any errors will be recorded
- df (pandas dataframe) – The testdata dataframe (from the import_maccor_data or import_multiple_csv_data functions)
- max_step (integer) – The last step from the schedule file
- i (integer) – An integer of the index where you want to validate
- cell_id (integer) – The cell id of the testdata
Returns: validation_df – The validation dataframe with any errors listed
Return type: pandas dataframe
Examples
>>> import maccorcyclingdata.validate as validate >>> validation_df = validate.validation_check_max_step_num(validation_df, df, max_step, i, 1) >>> validation_df
-
maccorcyclingdata.validate.validation_check_max_temp(validation_df, df, max_temp, i, cell_id, temp_tol=3)[source]¶ This function will validate the testdata against the max temperature by making sure no steps surpass the max.
Parameters: - validation_df (pandas dataframe) – The validation dataframe where any errors will be recorded
- df (pandas dataframe) – The testdata dataframe (from the import_maccor_data or import_multiple_csv_data functions)
- max_temp (integer) – The threshold for the highest temperature allowed
- i (integer) – An integer of the index where you want to validate
- cell_id (integer) – The cell id of the testdata
Returns: validation_df – The validation dataframe with any errors listed
Return type: pandas dataframe
Notes
There are 3 possibilities of error messages:
- warning - temperature approaching the max! (current temperature + tol > max)
- error - temperature has surpassed the max! (current temperature >= max)
- ABORT - temperature is way too hot! (current temperature > max + tol)
Examples
>>> import maccorcyclingdata.validate as validate >>> validation_df = validate.validation_check_max_temp(validation_df, df, 30, i, 1, 3) >>> validation_df
-
maccorcyclingdata.validate.validation_check_rest(validation_df, df, i, cell_id)[source]¶ This function will validate the testdata against the rest steps by making sure the current is at 0 when resting.
Parameters: - validation_df (pandas dataframe) – The validation dataframe where any errors will be recorded
- df (pandas dataframe) – The testdata dataframe (from the import_maccor_data or import_multiple_csv_data functions)
- i (integer) – An integer of the index where you want to validate
- cell_id (integer) – The cell id of the testdata
Returns: validation_df – The validation dataframe with any errors listed
Return type: pandas dataframe
Examples
>>> import maccorcyclingdata.validate as validate >>> validation_df = validate.validation_check_rest_steps(validation_df, df, i, 1) >>> validation_df
-
maccorcyclingdata.validate.validation_check_temp_interval(validation_df, df, temp_interval, i, cell_id)[source]¶ This function will validate the testdata to make sure the temperature does not fluctuate suddenly.
Parameters: - validation_df (pandas dataframe) – The validation dataframe where any errors will be recorded
- df (pandas dataframe) – The testdata dataframe (from the import_maccor_data or import_multiple_csv_data functions)
- temp_interval (integer) – The maximum temperature change allowed between two data points.
- i (integer) – An integer of the index where you want to validate
- cell_id (integer) – The cell id of the testdata
Returns: validation_df – The validation dataframe with any errors listed
Return type: pandas dataframe
Examples
>>> import maccorcyclingdata.validate as validate >>> validation_df = validate.validation_check_temp_interval(validation_df, df, 10, i, 1) >>> validation_df
-
maccorcyclingdata.validate.validation_check_time_interval(validation_df, df, time_interval, i, cell_id)[source]¶ This function will validate the testdata to make sure data was collected regularly at the correct time interval.
Parameters: - validation_df (pandas dataframe) – The validation dataframe where any errors will be recorded
- df (pandas dataframe) – The testdata dataframe (from the import_maccor_data or import_multiple_csv_data functions)
- time_interval (integer) – The time interval between data point. How often data should be collected.
- i (integer) – An integer of the index where you want to validate
- cell_id (integer) – The cell id of the testdata
Returns: validation_df – The validation dataframe with any errors listed
Return type: pandas dataframe
Examples
>>> import maccorcyclingdata.validate as validate >>> validation_df = validate.validation_check_time_interval(validation_df, df, 10, i, 1) >>> validation_df