diff --git a/README.rst b/README.rst index e2a8831..c7a13a0 100644 --- a/README.rst +++ b/README.rst @@ -5,15 +5,13 @@ Preparing Novonix Data ====================== -**preparenovonix** is a Python package that handles common issues encountered in files generated with a range of software versions from the `Novonix`_ -battery-testers. The code can also add extra information that makes -easier coulombic counting and relating a measurement to the experimental -protocol. The code provides a master function, *prepare_novonix*, that can run at once all the available features, providing also flexibility to choose only some. +**preparenovonix** is a Python package that handles common issues encountered in data files generated with a range of software versions from the `Novonix`_ battery-testers. This package can also add extra information that makes easier coulombic counting and relating a measurement to the experimental protocol. The package provides a master function, *prepare_novonix*, that can run at once the cleaning and adding derived information, with flexibility to choose only some features. There is a separate function to simply read a column by its given name. + Example ------- -The **example.py** runs over the given example data. To run this +The **example.py** runs over the given example data, producing a new file and a plot that compares the original and the prepared data. To run this example, simply type: :code:`python example.py`. Requirements and Installation @@ -21,7 +19,7 @@ Requirements and Installation This code has been developed in Python 3.7.1 and it is compatible with Python above 3.5 versions. The code has been tested to run in Windows, OSX and Linux operating systems. -This code uses numpy and pathlib as specified in docs/requirements.txt. +This code uses numpy as specified in docs/requirements.txt. The ploting routine from the *example.py* also requires the use of matplotlib. The code can be run directly from a cloned GitHub `repository`_ or it can also be installed as a python `package`_ through pip: @@ -47,7 +45,7 @@ In your code you can add the following lines that will call the master function .. code-block:: Matlab try - py.preparenovonix.novonix_add.prepare_novonix(file_to_open,... + py.preparenovonix.novonix_prep.prepare_novonix(file_to_open,... pyargs('addstate','True',... 'lprotocol','True',... 'overwrite','True',... @@ -59,6 +57,9 @@ In your code you can add the following lines that will call the master function end end + +.. _compability: + Compatibility ------------- @@ -86,7 +87,7 @@ List of the `Novonix`_ software versions the code has been tested against: .. |build| image:: https://travis-ci.org/BatLabLancaster/preparenovonix.svg?branch=master :target: https://travis-ci.org/BatLabLancaster/preparenovonix -.. |coverage| image:: https://codecov.io/gh/codecov/preparenovonix/branch/master/graph/badge.svg +.. |coverage| image:: https://codecov.io/gh/BatLabLancaster/preparenovonix/branch/master/graph/badge.svg :target: https://codecov.io/gh/BatLabLancaster/preparenovonix .. |docs| image:: https://readthedocs.org/projects/prepare-novonix-data/badge/?version=latest diff --git a/docs/features.rst b/docs/features.rst index f3e0e74..f53cdb8 100644 --- a/docs/features.rst +++ b/docs/features.rst @@ -2,62 +2,44 @@ Code Features ============= -The `preparenovonix`_ package prepares exported files produced by -`Novonix`_ battery-testers (or ’Novonix files’) by (i) cleaning them and (ii) adding -derived information to the file. The package also allows reading a -column given its name. The list of functions available in the package -can be found below in alphabetical order. This functions are presented -with the expected input parameters in brackets and further details are -given here for some of them and otherwise go to the `module index`_ for full details and examples of usage. - -- ``cleannovonix(infile)``: Given a ’Novonix file’ clean it as it is - described below. - -- ``isnovonix(infile)``: Given a file, check if it is or not a ’Novonix - file’. - -- ``icolumn(infile,column_name)``: Given the name of a column, find the - position of this column within a cleaned ’Novonix file’. - -- ``novonix_add_loopnr(infile,verbose=False)``: Given a cleaned - ’Novonix file’, add a reduced protocol to the header and the columns - ’Protocol line’ and ’Loop number’. - -- ``novonix_add_state(infile,verbose=False)``: Given a cleaned ’Novonix - file’, add the ’State’. - -- ``prepare_novonix(infile,addstate=False,lprotocol=False,``\ ``overwrite=False,verbose=False)``: - Master function of the package that can call the cleaning and adding - derived information functions directly. This function follows the - flow chart presented in the :ref:`chart`. Running all the - available features from the `preparenovonix`_ package can take form +The main functions available in the `preparenovonix`_ package are +listed below in alphabetical order. The list contains the module name +followed by the function name with the expected input parameters in +brackets. + +- ``novonix_add.create_reduced_protocol(infile,verbose=False)``: Given + a cleaned Novonix data file, ``infile``, generate a reduced protocol. + +- ``novonix_add.novonix_add_loopnr(infile,verbose=False)``: Given a + cleaned Novonix data file, ``infile``, add a reduced protocol to the + header and the columns Protocol line and Loop number. + +- ``novonix_add.novonix_add_state(infile,verbose=False)``: Given a + cleaned Novonix data file, ``infile``, add the State column. + +- ``novonix_clean.cleannovonix(infile)``: Given a Novonix data file, + ``infile``, clean it as it is described below. + +- ``novonix_io.isnovonix(infile)``: Given a file, ``infile``, check if + it is or not a Novonix data file. + +- ``novonix_io.read_column(infile,column_name,outtype=’float’)``: Given + a column name, ``column_name``, read it from a cleaned Novonix data + file, ``infile``, as a numpy array of the type given in ``outtype``. + +- ``novonix_prep.prepare_novonix(infile,addstate=False,lprotocol=False,``\ ``overwrite=False,verbose=False)``: + Master function of the ``preparenovonix`` package that prepares a + Novonix data file by cleaning it and adding to it derived + information. This function follows the flow chart presented in + :ref:`chart`. Running all the available features from + the `preparenovonix`_ package through this function can take form few seconds to up to few minutes depending on the size of the input file. -- ``read_column(infile,column_name,outtype=’float’)``: Given a column - name, read it from a cleaned ’Novonix file’ as a numpy array of the - type given in ``outtype``. - -- ``reduced_protocol(infile,verbose=False)``: Given a cleaned ’Novonix - file’, generate a reduced protocol. - -- ``select_com_val(index)``: Auxiliary function of - ``novonix_add_loopnr``. - -As it is shown in the :ref:`chart`, the derived information -is only added on ’cleaned’ files and only files that the code considers -as ’Novonix files’ can be cleaned. The master function -``prepare_novonix`` allows the user to call either the cleaning process -or the addition of extra columns ensuring that the dependencies -previously defined are taken into account. This function requires as -input parameters: the path to a file and four boolean optional -parameters. These boolean parameters are: ``addstate``, ``lprotocol``, -``overwrite`` and ``verbose``. The last parameter provides the option to -output more information about the run. If the ``overwrite`` parameter is -set to False, a new file will be generated with a name similar to the -input one, except for the addition of ``_prep`` before the extension of -the file. +In what follows, the above functions will be referred by simply their +name, without stating the modules they belong to. + .. _chart: Flow chart @@ -67,40 +49,66 @@ Flow chart :align: center :alt: Flow chart - Flow chart for the ``prepare_novonix`` function. Besides the name of the input file, this function has four optional boolean input parameters: ``addstate``, ``lprotocol``, ``overwrite`` and ``verbose``. The last two parameters are not included in the flow chart, but they are described in the text. In this chart rectangle shapes indicate a process, rounder rectangles the end of a process and diamonds a decision. Note that for simplicity not all the decisions made in the code are shown here. +Flow chart for the ``prepare_novonix`` function (within the +``novonix_prep`` module) which contains all the functionality of the +`preparenovonix`_ package presented here. Besides the name of the input +file, this function has four optional boolean input parameters: +``addstate``, ``lprotocol``, ``overwrite`` and ``verbose``. The last two +parameters are not included in the flow chart, but they are described in +the text. In this chart rectangle shapes indicate processes, rounder +rectangles end of processes and diamonds decisions. Note that for +simplicity not all the decisions made in the code are shown here. + +.. _prepare_novonix: + +The ``prepare_novonix`` function +-------------------------------- +As it is shown in :ref:`chart`, the `preparenovonix`_ package only cleans data files that are consider to +be exported from the Novonix battery-testers and it only derives +information for cleaned Novonix files. The master function ``prepare_novonix`` allows the user to +call either the cleaning process or the addition of extra columns +ensuring that these dependencies are taken into account. The input +parameters for this function are the path to a file and four boolean +optional parameters: ``addstate``, ``lprotocol``, ``overwrite`` and +``verbose``. The last parameter provides the option to output more +information about the run. If the ``overwrite`` parameter is set to +``False``, a new file will be generated with a name similar to the input +one, except for the addition of ``_prep`` before the extension of the +file. The ``isnovonix`` function -------------------------- -The function ``isnovonix`` decides if a file has the expected structure -(including a full header) for an exported file produced by the Novonix -battery-testers (or ’Novonix files’). If the file is lacking the header -or if it has not been exported with a Novonix battery-tester using the -covered software (see section ’Quality control’), the code will exit -with an error message and without generating a new file. +The function ``isnovonix`` decides if a file has the expected structure (including a full header) +for an exported file produced by the Novonix battery-testers. If the +file is lacking the header or if it has not been exported with a Novonix +battery-tester using the covered software (see the section :ref:`compability`), the code will exit with +an error message and without generating a new file. + The ``cleannovonix`` function ----------------------------- -The function ``cleannovonix`` produces a new ’Novonix type’ file after -performing the following tasks: +The function ``cleannovonix`` produces a new Novonix type file after performing the following tasks: + +- Delete failed tests within a single file, adding the final capacity + of all failed tests to the capacity column of the finished test. -- Delete failed tests within one file, adding the final capacity of all - failed tests to the capacity column of the finished test. +- Remove individual measurements for which the run time goes backwards. - Remove blank lines from the header. -- Remove eventual trailing characters from the header produced when the - file was previously open with certain programs, such as Excel. +- Remove any trailing characters from the header produced when the file + has been previously open with certain programs, such as Excel. - Add a dummy header name (``dum[number]``) for each data column lacking a header name. -The ’State’ column ------------------- -A ’State’ column can be added to a cleaned Novonix file by calling the -function ``novonix_add_state`` or setting to True the parameter -``addstate`` when calling the function ``prepare_novonix``. This ’State’ -column can have the following values: +The ``State`` column +-------------------- +A ``State`` column can be added to a cleaned Novonix file by calling the function +``novonix_add_state`` or setting to ``True`` the parameter ``addstate`` +when calling the function ``prepare_novonix``. This State column can +have the following values: - 0 for the first measurement of a given type (for example, a constant current charge). @@ -110,29 +118,29 @@ column can have the following values: - 2 for the last measurement of a given type. - -1 for single measurements. This can happen under different - conditions. A type of measurement can end after a single measurement - when some conditions are met (this usually happens while the time - resolution is coarse). At times, the current can overshoot from - negative to positive values at the beginning of a measurement. A bug - in the Novonix software that locks certain values, etc. If two single - measurements happen together, the two lines are discarded in the new - file containing the additional ’State’ column. - -The ’State’ column is generated based on the quantities provided in -’Novonix files’: ’Step’ (integer indicating the type of measurement) and -’Step time’ (time that resets to 0 each time a new type of measurement -starts). + circumstances. A type of measurement can end after a single + measurement when some experimental conditions are met, this usually + happens while the time resolution is coarse. At times, the current + can overshoot from negative to positive values at the beginning of a + measurement. A bug in the Novonix software that locks certain values, + etc. If two single measurements happen together, the two lines are + discarded in the new file containing the additional State column. + +The State column is generated based on the following quantities provided +in the raw Novonix data files: Step number (integer indicating the type +of measurement) and Step time (this time is assumed to reset to 0 each +time a new type of measurement starts). The ``reduced_protocol`` function --------------------------------- -The ``reduced_protocol`` function reads the complete header from the -input file and generates (or reads) the reduced protocol. This function -returns the reduce protocol itself and a boolean flag, ``viable_prot``. -The reduced protocol consist of an array of strings. Each string -contains a line of the experimental protocol with a structure as -follows: line number,’:’,command,’:’,trip conditions. An example: -``[4 : Repeat 49 times :]``. Only commands referring to the following -processes will appear in the reduced protocol (note that commands that do not produce measurements are ignored here): +The ``reduced_protocol`` function reads the complete header from the input file and generates (or reads) +the reduced protocol. This function returns the reduce protocol itself +and a boolean flag, ``viable_prot``. The reduced protocol consist of an +array of strings. Each string contains a line number, a command from the +experimental protocol and the corresponding experimental conditions (if +aplicable); for example: ``[4 : Repeat 49 times :]``. Only commands +referring to the following processes will appear in the reduced +protocol (note that the commands corresponding to incrementing the cycle counter and global emergency limits are ignored in the reduced protocol as there are no measurements associated with those): - Open circuit storage (or rest) @@ -143,25 +151,25 @@ processes will appear in the reduced protocol (note that commands that do not pr - (End) Repeat The reduced protocol is tested against the number of unique measurements -in the file, determined using the column ’State’. If the number of +in the file, determined using the column State. If the number of measurements expected from the protocol is less than the actual number -of measurements, the flag ``viable_prot`` is set to false, indicating -that the construction of the reduced protocol was not viable. - -The ’Protocol line’ and ’Loop number’ columns ---------------------------------------------- -The ’Protocol line’ and ’Loop number’ columns can be generated by either -calling directly the function ``novonix_add_loopnr`` or by setting to -True the parameter ``lprotocol`` when calling the function -``prepare_novonix``. The column ’Protocol line’ associates a measurment -with the its corresponding line in the reduced protocol previously -produced. The ’Loop number’ column has a value of 0 if a measurement -does not correspond to any repetition statement in the protocol and -otherwise it grows monotonically with each repetition. - -If the flag ``viable_prot`` was set to false by the ``reduced_protocol`` -function, the ’Protocol line’ and ’Loop number’ columns are populated -with the value -999. +of measurements, the flag ``viable_prot`` is set to ``False``, +indicating that the construction of the reduced protocol was not viable. + +The ``Protocol line`` and ``Loop number`` columns +------------------------------------------------- +The ``Protocol line`` and ``Loop number`` columns can be generated by either calling directly the function +``novonix_add_loopnr`` or by setting to ``True`` the parameter +``lprotocol`` when calling the function ``prepare_novonix``. The column +Protocol line associates a measurment with its corresponding line in the +reduced protocol. The Loop number column has a value of 0 if a +measurement does not correspond to any repetition statement in the +protocol and otherwise it grows monotonically with each repetition (see +:ref:`chart`). + +If the flag ``viable_prot`` was set to ``False`` by the +``reduced_protocol`` function, the Protocol line and Loop number columns +are populated with the value -999. .. _preparenovonix: https://github.com/BatLabLancaster/preparenovonix diff --git a/docs/index.rst b/docs/index.rst index 5b36706..4acf3ac 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -15,6 +15,7 @@ Documentation for ``preparenovonix`` :maxdepth: 2 readme_include.rst + overview.rst features.rst source/modules.rst diff --git a/docs/overview.rst b/docs/overview.rst new file mode 100644 index 0000000..356d9a0 --- /dev/null +++ b/docs/overview.rst @@ -0,0 +1,75 @@ +.. _overview: + +Code overview +============= + +The `preparenovonix`_ package prepares exported data files produced by `Novonix`_ battery-testers by (i) cleaning them and (ii) adding derived information to the file. The package also allows reading an individual column given its name. The derived information includes: + +#. A State column with explicit information of the start and end of a + given type of measurement. Novonix provides a Step number with a + different value for each type of measurement, for example, 0 + corresponds to an open circuit. However, it is possible to have two + consecutive measurements of the same type but with different + experimental conditions, for example charging at different currents. + These can now be set appart using the State value. + +#. A reduced protocol summarising the experimental protocol into having + each command and corresponding experimental conditions in a single + line. This is needed to directly relate a measurement with the + experimental protocol. The reduced protocol is output as a string of + arrays and it is stored as part of the header when using the + :ref:`prepare_novonix` function. + +#. A Protocol line column with values that assign a measurement to a + particular line of the reduced protocol. + +#. A Loop number column with a counter of the repetitions of a given + measurement within a loop in the experimental protocol. + +Combining the state and step number values makes it possible to select +the capacities from a charge or discharge experimental step. These are +needed for estimating the coulombic efficiency. This combination of +state with step number also allows the computation of resistances based +on current experimental steps or pulses. Specific cycles or individual +sections of the experiment can be selected combining the loop number +with either the state and step number values or the protocol line +values. + +The example data provided within the repository for this code is shown +in the figure below :ref:`comparison`. This figure compares the raw +Novonix data with the data after being processed by the +`preparenovonix`_ package. The example raw data contains individual +measurements for which the experimental run time decreases. As it can be +seen in the :ref:`comparison`, these measurements are +removed by the `preparenovonix`_ package. The example raw data file +also includes a failed test. The `preparenovonix`_ package takes the +capacity from the failed test and adds it to the capacities from the +completed experiment. This shifts the result capacity curve by a +constant value, as it can be seen in the :ref:`comparison`. This figure also shows the +increasing loop number when the measurements are within a repeat loop +and the protocol line each measurement corresponds to. + +.. _comparison: comparison figure + +Plot comparing the raw and processed data +----------------------------------------- + +.. figure:: ../example_data/compare_vct.png + :align: center + :alt: Data comparison + +Comparison of the raw battery testing data (thin dashed lines) and the +data after being processed by the `preparenovonix`_ package (thick +solid lines), as a function of the experimental run time. The top panel +shows the potential and capacity of the battery. The middle panel shows +the step number, which indicates the type of measurement being done. The +bottom panel shows the loop number and protocol line, which are only +available after processing the raw data with the +`preparenovonix`_ package. + + +.. _preparenovonix: https://github.com/BatLabLancaster/preparenovonix + +.. _Novonix: http://www.novonix.ca/ + +.. _module index: https://prepare-novonix-data.readthedocs.io/en/latest/py-modindex.html diff --git a/docs/source/preparenovonix.rst b/docs/source/preparenovonix.rst index db3c138..f612da1 100644 --- a/docs/source/preparenovonix.rst +++ b/docs/source/preparenovonix.rst @@ -4,6 +4,15 @@ preparenovonix package Submodules ---------- +preparenovonix.compare module +----------------------------- + +.. automodule:: preparenovonix.compare + :members: + :undoc-members: + :show-inheritance: + + preparenovonix.novonix\_add module ---------------------------------- @@ -13,6 +22,42 @@ preparenovonix.novonix\_add module :show-inheritance: +preparenovonix.novonix\_clean module +------------------------------------ + +.. automodule:: preparenovonix.novonix_clean + :members: + :undoc-members: + :show-inheritance: + + +preparenovonix.novonix\_io module +---------------------------------- + +.. automodule:: preparenovonix.novonix_io + :members: + :undoc-members: + :show-inheritance: + + +preparenovonix.novonix\_prep module +----------------------------------- + +.. automodule:: preparenovonix.novonix_prep + :members: + :undoc-members: + :show-inheritance: + + +preparenovonix.novonix\_variables module +---------------------------------------- + +.. automodule:: preparenovonix.novonix_variables + :members: + :undoc-members: + :show-inheritance: + + Module contents --------------- diff --git a/example.py b/example.py index 00e86cb..5f55a61 100644 --- a/example.py +++ b/example.py @@ -10,4 +10,4 @@ overwrite=False, verbose=True) # Compare the prepared file with the original one -plot_vct(infile, first_loop=0, plot_type='pdf', plot_show=True) +plot_vct(infile, first_loop=0, plot_type='png', plot_show=True) diff --git a/example_data/compare_vct.png b/example_data/compare_vct.png new file mode 100644 index 0000000..48d0b8b Binary files /dev/null and b/example_data/compare_vct.png differ diff --git a/preparenovonix/compare.py b/preparenovonix/compare.py index d5f71c8..1c9592c 100644 --- a/preparenovonix/compare.py +++ b/preparenovonix/compare.py @@ -34,9 +34,8 @@ def plot_vct(before_file, first_loop=0, plot_type="pdf", plot_show=False): 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) + >>> 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) """ after_file = after_file_name(before_file) diff --git a/preparenovonix/novonix_add.py b/preparenovonix/novonix_add.py index 0b23cb0..7d24343 100644 --- a/preparenovonix/novonix_add.py +++ b/preparenovonix/novonix_add.py @@ -31,11 +31,9 @@ def column_check(infile, col_name, verbose=False): 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) + >>> 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 """ @@ -67,8 +65,8 @@ def state_check(state): Examples --------- - >>>> import preparenovonix.novonix_add as prep - >>>> prep.state_check([0,1,2]) + >>> import preparenovonix.novonix_add as prep + >>> prep.state_check([0,1,2]) True """ @@ -119,9 +117,8 @@ def novonix_add_state(infile, verbose=False): Examples --------- - >>>> import preparenovonix.novonix_add as prep - - >>>> prep.novonix_add_state('example_data/example_data_prep.csv',verbose=True) + >>> 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 """ @@ -258,9 +255,8 @@ def select_com_val(index): Examples --------- - >>>> import preparenovonix.novonix_add as prep - - >>>> prep.select_com_val(2) + >>> import preparenovonix.novonix_add as prep + >>> prep.select_com_val(2) 'np.logical_or(step == com_val1[index], step == nv.com_val2[index])' """ if nv.com_val2[index] is None: @@ -293,12 +289,10 @@ def read_reduced_protocol(infile, verbose=False): Examples --------- - >>>> import preparenovonix.novonix_add as prep - - >>>> protocol, continue_reading = prep.read_reduced_protocol( + >>> import preparenovonix.novonix_add as prep + >>> protocol, continue_reading = prep.read_reduced_protocol( 'example_data/example_data_prep.csv',verbose=True) - - >>>> print(continue_reading) + >>> print(continue_reading) False """ @@ -354,9 +348,8 @@ def protocol_check(infile, istate, verbose=False): Examples --------- - >>>> import preparenovonix.novonix_add as prep - - >>>> prep.protocol_check('example_data/example_data_prep.csv',103) + >>> import preparenovonix.novonix_add as prep + >>> prep.protocol_check('example_data/example_data_prep.csv',103) True """ @@ -441,9 +434,9 @@ def rep_info_not_fmtspace(line, fmt_space): 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) + >>> 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 """ @@ -495,9 +488,9 @@ def create_end_repeat(nstep, iline, protocol, inrepeat): Examples --------- - >>>> import preparenovonix.novonix_add as prep - >>>> protocol, inrepeat = prep.create_end_repeat(34,1,['Example'],True) - >>>> print(protocol[-1],inrepeat) + >>> 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 """ @@ -533,14 +526,11 @@ def create_reduced_protocol(infile, verbose=False): 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) + >>> 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]) + >>> print(protocol[0],protocol[-1]) [Reduced Protocol] [End Reduced Protocol] """ @@ -757,9 +747,8 @@ def novonix_add_loopnr(infile, verbose=False): Examples --------- - >>>> import preparenovonix.novonix_add as prep - - >>>> prep.novonix_add_loopnr('example_data/example_data_prep.csv',verbose=True) + >>> 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 """ diff --git a/preparenovonix/novonix_clean.py b/preparenovonix/novonix_clean.py index a10f20c..c0526f8 100644 --- a/preparenovonix/novonix_clean.py +++ b/preparenovonix/novonix_clean.py @@ -25,9 +25,8 @@ def count_tests(infile): Examples --------- - >>>> from preparenovonix.novonix_clean import count_tests - - >>>> count_tests('example_data/example_data.csv') + >>> from preparenovonix.novonix_clean import count_tests + >>> count_tests('example_data/example_data.csv') 2 """ @@ -63,13 +62,10 @@ def header_data_columns(head_line, data_cols, header): Examples --------- - >>>> from preparenovonix.novonix_clean import header_data_columns - - >>>> header = ['# Example header'] - - >>>> header_data_columns("a,b",[1,2,3],header) - - >>>> print(header[-1]) + >>> 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 """ @@ -127,9 +123,8 @@ def capacity_failed_tests(icapacity, ntests, infile): Examples --------- - >>>> from preparenovonix.novonix_clean import capacity_failed_tests - - >>>> capacity_failed_tests(2,"example_data/example_data.csv") + >>> from preparenovonix.novonix_clean import capacity_failed_tests + >>> capacity_failed_tests(2,"example_data/example_data.csv") 0.4956497995 """ @@ -171,9 +166,8 @@ def cleannovonix(infile): Examples --------- - >>>> from preparenovonix.novonix_clean import cleannovonix - - >>>> cleannovonix('example_data/example_data.csv') + >>> from preparenovonix.novonix_clean import cleannovonix + >>> cleannovonix('example_data/example_data.csv') """ # Count the number of tests diff --git a/preparenovonix/novonix_io.py b/preparenovonix/novonix_io.py index 2c595f3..7905c30 100644 --- a/preparenovonix/novonix_io.py +++ b/preparenovonix/novonix_io.py @@ -22,8 +22,7 @@ def after_file_name(file_to_open): Examples --------- >>> from preparenovonix.novonix_io import after_file_name - - >>>> after_file_name('example_data/example_data.csv') + >>> after_file_name('example_data/example_data.csv') """ # Extract the path and file name @@ -64,8 +63,7 @@ def get_infile(file_to_open, overwrite=False): Examples --------- >>> from preparenovonix.novonix_io import get_infile - - >>>> get_infile('example_data/example_data.csv',overwrite=False) + >>> get_infile('example_data/example_data.csv',overwrite=False) """ # Extract the path and file name @@ -99,9 +97,8 @@ def isnovonix(infile): Examples --------- - >>>> from preparenovonix.novonix_io import isnovonix - - >>>> isnovonix('example_data/example_data.csv') + >>> from preparenovonix.novonix_io import isnovonix + >>> isnovonix('example_data/example_data.csv') True """ @@ -210,9 +207,8 @@ def icolumn(infile, column_name): Examples --------- - >>>> from preparenovonix.novonix_io import icolumn - - >>>> icolumn('example_data/example_data.csv','Step Number') + >>> from preparenovonix.novonix_io import icolumn + >>> icolumn('example_data/example_data.csv','Step Number') 2 """ @@ -268,12 +264,10 @@ def read_column(infile, column_name, outtype="float"): Examples --------- - >>>> from preparenovonix.novonix_io import read_column - - >>>> col = read_column('example_data/example_data_prep.csv', + >>> from preparenovonix.novonix_io import read_column + >>> col = read_column('example_data/example_data_prep.csv', 'Step Number',outtype='int') - - >>>> print(col[0]) + >>> print(col[0]) 0 """ @@ -340,8 +334,7 @@ def replace_file(newfile, infile, newbigger=False): Examples --------- >>> from preparenovonix.novonix_io import replace_file - - >>>> replace_file("example_data/example_data_prep.csv","example_data/example_data.csv") + >>> replace_file("example_data/example_data_prep.csv","example_data/example_data.csv") """ if newbigger: @@ -384,9 +377,8 @@ def get_format(line): Examples --------- - >>>> import preparenovonix.novonix_io as prep - - >>>> fmt_space, commands = prep.get_format('[0: Open_circuit_storage:]') + >>> import preparenovonix.novonix_io as prep + >>> fmt_space, commands = prep.get_format('[0: Open_circuit_storage:]') False """ @@ -422,9 +414,8 @@ def get_command(line, fmt_space): Examples --------- - >>>> import preparenovonix.novonix_io as prep - - >>>> command = prep.get_command('[Open circuit storage]',fmt_space=True) + >>> import preparenovonix.novonix_io as prep + >>> command = prep.get_command('[Open circuit storage]',fmt_space=True) Open circuit storage """ diff --git a/preparenovonix/novonix_prep.py b/preparenovonix/novonix_prep.py index 3e45999..fa66941 100644 --- a/preparenovonix/novonix_prep.py +++ b/preparenovonix/novonix_prep.py @@ -43,9 +43,8 @@ def prepare_novonix( Examples --------- - >>>> import preparenovonix.novonix_prep as prep - - >>>> prep.prepare_novonix('example_data/example_data.csv',addstate=True,lprotocol=True,overwrite=False,verbose= False) + >>> 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. """ diff --git a/preparenovonix/test_prep.py b/preparenovonix/test_prep.py new file mode 100644 index 0000000..8a16d2a --- /dev/null +++ b/preparenovonix/test_prep.py @@ -0,0 +1,18 @@ +import os +from shutil import copy +import preparenovonix.novonix_prep as prep + +exfile = "example_data/example_data.csv" + + +def test_prepare_novonix(): + ff = "dumfile.csv" + ffout = "dumfile_prep.csv" + copy(exfile, ff) + assert os.path.isfile(ff) is True + prep.prepare_novonix( + ff, addstate=True, lprotocol=True, overwrite=False, verbose=True + ) + assert os.stat(ff).st_size > os.stat(ffout).st_size + os.remove(ff) + os.remove(ffout)