|build| |docs| |zenodo| 

Prepare Novonix Data
====================

This code handles common issues encountered in files generated with a
range of `Novonix`_ software versions and it can add extra information.
There is a master function *prepare_novonix* that can run at once
all the available features, providing also flexibility to only choose
some.

The code can be used to test if a file has the expected structure for a
`Novonix`_ file (*isnovoix* function) and to read a specific column
from a raw `Novonix`_ file (*read_column* function). Files can be
cleanned from empty lines and characters added after the ']' in the
header and failed tests are handled by modifying the capacity column to
start at the sum of the capacities from the failed tests, instead of 0
(*cleannovonix* function).

The extra information that can be created for **cleaned** files
(functions: *novonix_add_state* and *novonix_add_loopnr*) is:

-  A 'State' column with 0 for the first measurement of a particular
   step, 1 for regular data points, 2 to indicate the last measurement
   in that series and -1 for single measurements.
-  A reduced protocol with one command per numerated line.
-  A 'Protocol line' column that makes reference to the reduced protocol
   lines.
-  A 'Loop number' column with 0s when commands are not repeated and
   monotoncally increasing integers starting from 1, to indicate the
   repetition number.

Requirements and Installation
-----------------------------

This code has been developed in Python 3.7.1 and is compatible with Python above 3.4 versions. The code has been tested to run in both Windows and Linux OS. It has been tested to run within Matlab R2018a.

This code uses numpy and pathlib as specified in docs/requirements.txt.

The code can be run directly from a cloned repository or can also be installed as a python package through pip:


Example
-------

The **example.py** runs over the given example data. To run this
example, simply type: :code:`python example.py`.

Running this code from MatLab
-----------------------------

In your code add the 'pycode' folder to your search path:

.. code-block:: Matlab
		
   addpath(genpath('pycode'))

Try to run the code catching exceptions:

.. code-block:: Matlab
		
   try
	  py.pycode.novonix_add.prepare_novonix(file_to_open,pyargs('verbose','False','lprotocol','True'));
   catch e e.message if(isa(e,'matlab.exception.PyException'))
	  e.ExceptionObject
   end

Ensure that Matlab can see your installation of Python by running
`pyversion`_. If Matlab cannot see python, once you know where your
Python executable is (within a python terminal you can do this by
typing: :code:`import os, sys ; os.path.dirname(sys.executable)`), type
within your MatLab interpreter :code:`pyversion [path to python executable]`
and check that now the path to Python was recognised with
`pyversion`_.

Compatibility
-------------

This code has been tested with data generated by different versions of
the `Novonix`_ software. If you encounter issues running the code for
any version of Novonix software report an issue. Note that an example
file will be needed in order to improve the code. List of the `Novonix`_
software. If you encounter issues running the code for any version of Novonix software report an issue. Note that an example file will be needed in order to improve the code.
List of the `Novonix`_ software versions the code has been tested against:

-  3.0.2.3
-  3.0.2.1
-  TO
-  2.0.0.7
-  1.9.4.0

.. _Novonix: http://www.novonix.ca/
.. _pyversion: https://uk.mathworks.com/help/matlab/getting-started-with-python.html

.. |build| image:: https://travis-ci.org/BatLabLancaster/preparenovonix.svg?branch=master
    :target: https://travis-ci.org/BatLabLancaster/preparenovonix

.. |docs| image:: https://readthedocs.org/projects/prepare-novonix-data/badge/?version=latest
   :target: https://prepare-novonix-data.readthedocs.io/en/latest/?badge=latest
   :alt: Documentation Status

.. |zenodo| image:: https://zenodo.org/badge/186994865.svg
   :target: https://zenodo.org/badge/latestdoi/186994865
