preparenovonix package¶
Submodules¶
preparenovonix.compare module¶
-
preparenovonix.compare.
plot_vct
(before_file, first_loop=0, plot_type='pdf', plot_show=False)[source]¶ Given two Novonix data files, pre and post-processing with preparenovonix, plot toghether their Voltage, Capacity, Step Number and Loop number versus time
Parameters: - before_file (string) – Name of the pre-processed file
- first_loop (int) – Value for the Loop Number to start showing data
- plot_type (string) – ‘pdf’, ‘png’, ‘jpg’ for the format of the saved file
- plot_show (boolean) – True to show the plot.
Notes
This code returns a plot.
Examples
>>> from preparenovonix.compare import plot_vct >>> plot_vct('example_data/example_data.csv','example_data/example_data_prep.csv',first_loop=0,plot_type='pdf',plot_show=True)
preparenovonix.novonix_add module¶
-
preparenovonix.novonix_add.
column_check
(infile, col_name, verbose=False)[source]¶ Given a cleaned Novonix data file, check if the col_name column exists.
Parameters: - infile (string) – Name of the input Novonix file
- col_name (string) – Name of the column
- verbose (boolean) – True to print information out.
Returns: column_exists – True when the column name has been found in the header
Return type: boolean
Examples
>>> import preparenovonix.novonix_variables as nv >>> import preparenovonix.novonix_add as prep >>> prep.column_check('example_data/example_data_prep.csv',nv.col_step) True
-
preparenovonix.novonix_add.
create_end_repeat
(nstep, iline, protocol, inrepeat)[source]¶ Given a line from a file with format: add to the protocol an [# : End repeat nstep steps :] line
Parameters: - nstep (int) – Number of steps in a loop
- iline (int) – Counter for protocol lines
- protocol (array of strings) – Array with the reduced protocol
- inrepeat (boolean) – True if inside a loop
Returns: - protocol (array of strings) – Array with the reduced protocol, with the added new line
- inrepeat (boolean) – Set to False by this function
Examples
>>> import preparenovonix.novonix_add as prep >>> protocol, inrepeat = prep.create_end_repeat(34,1,['Example'],True) >>> print(protocol[-1],inrepeat) [0 : End Repeat 34 steps :] False
-
preparenovonix.novonix_add.
create_reduced_protocol
(infile, verbose=False)[source]¶ Given a Novonix data file, get a reduced protocol with one command per line.
Parameters: - infile (string) – Name of the input Novonix file
- verbose (boolean) – Yes = print out some informative statements
Returns: - protocol (list) – List with the reduced protocol
- viable_prot (bool) – False if there was a problem creating the reduced protocol.
Examples
>>> import preparenovonix.novonix_add as prep >>> protocol, viable_prot = prep.create_reduced_protocol('example_data/example_data_prep.csv',verbose=True) >>> print(viable_prot) True >>> print(protocol[0],protocol[-1]) [Reduced Protocol] [End Reduced Protocol]
-
preparenovonix.novonix_add.
novonix_add_loopnr
(infile, verbose=False)[source]¶ Given a cleaned Novonix data file, it adds a ‘Loop number’ column, with monotonically increasing numbers and the protocol line corresponding to a given measurement.
Measurements that are not being repeated are assinged: Loop number=0.
This values are determined by the change in the ‘State’ and the protocol description in the header
Parameters: - infile (string) – Name of the input Novonix file
- verbose (boolean) – Yes = print out some informative statements
Notes
This code returns a Novonix file with two extra columns.
Examples
>>> import preparenovonix.novonix_add as prep >>> prep.novonix_add_loopnr('example_data/example_data_prep.csv',verbose=True) The file already has the column Loop number
-
preparenovonix.novonix_add.
novonix_add_state
(infile, verbose=False)[source]¶ Given a cleaned Novonix data file, it adds a ‘State’ column, which mimimcs Basytec format with:
0 = Start of a measurement type (charge/discharge, etc) 1 = Regular data point (measuring, no mode change) 2 = End of cycle (last point of the measurement)
This values are determined by the change in the ‘Step Number’ from Novonix and the ‘Step time’, which goes to 0 with each new ‘Step’.
Parameters: - infile (string) – Name of the input Novonix file
- verbose (boolean) – Yes : print out some informative statements
Notes
This code returns a Novonix file with an extra ‘State’ column.
Examples
>>> import preparenovonix.novonix_add as prep >>> prep.novonix_add_state('example_data/example_data_prep.csv',verbose=True) The file example_data/example_data_prep.csv already has a State column
-
preparenovonix.novonix_add.
protocol_check
(infile, istate, verbose=False)[source]¶ Given a cleaned Novonix data file and the expected number of different measurements from the header, check if the obtained protocol is reasonable given the data.
Parameters: - infile (string) – Name of the input Novonix file
- istate (int) – Number of measurements derived from reading the protocol
- verbose (boolean) – True to print information statements
Returns: viable_prot – True when the reduced protocol is adequate given the data
Return type: boolean
Examples
>>> import preparenovonix.novonix_add as prep >>> prep.protocol_check('example_data/example_data_prep.csv',103) True
-
preparenovonix.novonix_add.
read_reduced_protocol
(infile, verbose=False)[source]¶ Given a cleaned Novonix data file, read the reduced protocol if it exists.
Parameters: - infile (string) – Name of the input Novonix file
- verbose (boolean) – Yes = print out some informative statements
Returns: - protocol (list) – List with the reduced protocol.
- protocol_exists (bool) – False if there is no reduced protocol.
Examples
>>> import preparenovonix.novonix_add as prep >>> protocol, continue_reading = prep.read_reduced_protocol( 'example_data/example_data_prep.csv',verbose=True) >>> print(continue_reading) False
-
preparenovonix.novonix_add.
rep_info_not_fmtspace
(line, fmt_space)[source]¶ Given a line from a file with format: fmt_space=False, get the number or repetitions and the number of steps that are being repeated
Parameters: - line (string) – Line with data from a Novonix data file
- fmt_space (boolean) – This function only works if this variable is False
Returns: - ncount (int) – Number of repetitions in a loop
- nstep (int) – Number or steps in a loop
- unexpected (boolean) – Flag to state if an unexpected syntax has been encountered
Examples
>>> import preparenovonix.novonix_add as prep >>> ncount, nstep, unexpected = prep.rep_info_not_fmtspace('[5: Repeat: 24 time(s) Node count: 4]',False) >>> print(ncount, nstep, unexpected) 24 4 False
-
preparenovonix.novonix_add.
select_com_val
(index)[source]¶ Establish the selection statement for the one or two possible command values (com_val#)
Parameters: index (integer) – Index within the above arrays com_val1, nv.com_val2 Returns: sel – String with the selection using either one or two values Return type: string Examples
>>> import preparenovonix.novonix_add as prep >>> prep.select_com_val(2) 'np.logical_or(step == com_val1[index], step == nv.com_val2[index])'
-
preparenovonix.novonix_add.
state_check
(state)[source]¶ Perform tests on the State array
Parameters: - state (array of integers) – State array
- col_name (string) – Name of the column
Returns: answer – True when the tests went fine
Return type: boolean
Examples
>>> import preparenovonix.novonix_add as prep >>> prep.state_check([0,1,2]) True
preparenovonix.novonix_clean module¶
-
preparenovonix.novonix_clean.
capacity_failed_tests
(icapacity, ntests, infile)[source]¶ Given a Novonix data file, add up the last capacity measurement of each failed test in the file.
Parameters: - icapacity (int) – Column position for the capacity
- ntests (int) – Number of tests in the file
- infile (string) – Input file
Returns: last_capacity – Sum of the last capacity measurements for each test before the last one in the file.
Return type: float
Examples
>>> from preparenovonix.novonix_clean import capacity_failed_tests >>> capacity_failed_tests(2,"example_data/example_data.csv") 0.4956497995
-
preparenovonix.novonix_clean.
cleannovonix
(infile)[source]¶ Given a Novonix file remove blank lines, correct the header, remove failed tests if needed.
Parameters: infile (string) – Name of the input Novonix file Notes
This code returns a cleaned Novonix file
Examples
>>> from preparenovonix.novonix_clean import cleannovonix >>> cleannovonix('example_data/example_data.csv')
-
preparenovonix.novonix_clean.
count_tests
(infile)[source]¶ Given a Novonix data file, count the number of tests it contains, by looking for the “[Summary]” line that starts all Novonix data files.
Parameters: infile (string) – Name of the input Novonix file Returns: ntests – Number of tests found in the file Return type: int Examples
>>> from preparenovonix.novonix_clean import count_tests >>> count_tests('example_data/example_data.csv') 2
-
preparenovonix.novonix_clean.
header_data_columns
(head_line, data_cols, header)[source]¶ Given a Novonix data file, compare the columns according to the data and the header. If there are more data columns than implied in the header, dummy colum names are added (dum#). If there are less data columns than implied in the header, the program stops.
Parameters: - head_line (string) – Header line with column names.
- data_cols (array of floats) – First line with data
- header (array of strings) – Header. If needed, this header will be modified.
Examples
>>> from preparenovonix.novonix_clean import header_data_columns >>> header = ['# Example header'] >>> header_data_columns("a,b",[1,2,3],header) >>> print(header[-1]) a,b,dum0
preparenovonix.novonix_io module¶
-
preparenovonix.novonix_io.
after_file_name
(file_to_open)[source]¶ Given a file name return as: [file_to_open root]_prep.[file-to_open_ending]
Parameters: file_to_open (string) – Name of the input file. Returns: after_file – Full path to the (new) file. Return type: string Examples
>>> from preparenovonix.novonix_io import after_file_name >>> after_file_name('example_data/example_data.csv')
-
preparenovonix.novonix_io.
get_command
(line, fmt_space)[source]¶ Given a header line, get the possible command
Parameters: - line (string) – Line of the header
- fmt_space (boolean) – Yes = Novonix format with spaces in the commands
Returns: command – Instruction in the header line
Return type: string
Examples
>>> import preparenovonix.novonix_io as prep >>> command = prep.get_command('[Open circuit storage]',fmt_space=True) Open circuit storage
-
preparenovonix.novonix_io.
get_format
(line)[source]¶ Given a file line, establish the format
Parameters: line (string) – Line of the header Returns: - fmt_space (boolean) – True indicates the main protocol commands have words separated by spaces, which it is assumed to be connected with the presence of a semi-colons in the header lines.
- commands (array of string) – Main protocol commands in the adequate format
Examples
>>> import preparenovonix.novonix_io as prep >>> fmt_space, commands = prep.get_format('[0: Open_circuit_storage:]') False
-
preparenovonix.novonix_io.
get_infile
(file_to_open, overwrite=False)[source]¶ Given a file name return it after dealing with possible issues with the path and copy it if the overwrite flag is set to True.
Parameters: - infile_name (string) – Name of the input file.
- overwrite (boolean) –
Yes : overwrite the input file No : a new file will be created, appending ‘_prep’ at the end of the
original file file
Returns: - infile (string) – Path to the (new) file.
- fname (string) – File name withouth the path.
Examples
>>> from preparenovonix.novonix_io import get_infile >>> get_infile('example_data/example_data.csv',overwrite=False)
-
preparenovonix.novonix_io.
icolumn
(infile, column_name)[source]¶ Given a Novonix data file, find the column position of the given column_name
Parameters: - infile (string) – Name of the input Novonix data file
- column_name (string) – Name of the column name to find
- icolumn (integer) – icolumn = -1 : the column has not been found. If icolumn > -1: icolumn is the index of the column.
Returns: icol – Position of the column with name ‘column_name’, in the range form 0 to the number of columns - 1
Return type: integer
Examples
>>> from preparenovonix.novonix_io import icolumn >>> icolumn('example_data/example_data.csv','Step Number') 2
-
preparenovonix.novonix_io.
isnovonix
(infile)[source]¶ Given a data file, check if it exists and if looks like a Novonix data file, allowing for blank lines and commas after the commands due to having open the file in Excel
Parameters: infile (string) – Name of the input Novonix data file Returns: answer – Yes=the file seems to be a Novonix data file Return type: boolean Examples
>>> from preparenovonix.novonix_io import isnovonix >>> isnovonix('example_data/example_data.csv') True
-
preparenovonix.novonix_io.
read_column
(infile, column_name, outtype='float')[source]¶ Given a Novonix data file, read a column as an array of the type given in the variable astype.
Parameters: - infile (string) – Name of the input Novonix data file
- column_name (string) – Name of the column to be read
- outtype (string) – Type of data of the column to be read
Returns: column_data – Column of interest read as a str
Return type: numpy array of the given type
Examples
>>> from preparenovonix.novonix_io import read_column >>> col = read_column('example_data/example_data_prep.csv', 'Step Number',outtype='int') >>> print(col[0]) 0
-
preparenovonix.novonix_io.
replace_file
(newfile, infile, newbigger=False)[source]¶ Replace infile by newfile, testing, if adequate, if the new file is larger than the older.
Parameters: - newfile (string) – Name of the new file
- infile (string) – Name of the file to be replaced.
- newbigger (boolean) – Yes : test if the newfile is larger than infile. No : simply move the files
Examples
>>> from preparenovonix.novonix_io import replace_file >>> replace_file("example_data/example_data_prep.csv","example_data/example_data.csv")
preparenovonix.novonix_prep module¶
-
preparenovonix.novonix_prep.
prepare_novonix
(file_to_open, addstate=False, lprotocol=False, overwrite=False, verbose=False)[source]¶ Given a Novonix data file, it prepare it to be handled.
Parameters: - infile (string) – Name of the input Novonix file
- addstate (boolean) – Yes = add a State column
- lprotocol (boolean) – Yes = add to the initial header a ‘reduced’ protocol with a step per line and add lines with the loop number and protocol lines
- overwrite (boolean) –
Yes : overwrite the input file No : a new file will be created, appending ‘_prep’ at the end of the
original file file - verbose (boolean) – Yes = print out some informative statements
Notes
This function returns a clean Novonix file with, possibly, 3 extra columns.
Examples
>>> import preparenovonix.novonix_prep as prep >>> prep.prepare_novonix('example_data/example_data.csv',addstate=True,lprotocol=True,overwrite=False,verbose= False) File example_data_prep.csv has been prepared.