GithubHelp home page GithubHelp logo

bcliang / gamry-parser Goto Github PK

View Code? Open in Web Editor NEW
6.0 0.0 8.0 147 KB

Package for parsing the contents of Gamry EXPLAIN data (DTA) files

License: MIT License

Python 100.00%
gamry explain parser python electrochemistry cyclic-voltammetry eis chronoamperometry

gamry-parser's People

Contributors

agualdron avatar bcliang avatar p2jones avatar thatch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

gamry-parser's Issues

Missing files in sdist

It appears that the manifest is missing at least one file necessary to build
from the sdist for version 0.4.1. You're in good company, about 5% of other
projects updated in the last year are also missing files.

+ /tmp/venv/bin/pip3 wheel --no-binary gamry-parser -w /tmp/ext gamry-parser==0.4.1
Looking in indexes: http://10.10.0.139:9191/root/pypi/+simple/
Collecting gamry-parser==0.4.1
  Downloading http://10.10.0.139:9191/root/pypi/%2Bf/598/4cf3a2950d58a/gamry_parser-0.4.1.tar.gz (10 kB)
    ERROR: Command errored out with exit status 1:
     command: /tmp/venv/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-wheel-4es5ic97/gamry-parser/setup.py'"'"'; __file__='"'"'/tmp/pip-wheel-4es5ic97/gamry-parser/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-wheel-4es5ic97/gamry-parser/pip-egg-info
         cwd: /tmp/pip-wheel-4es5ic97/gamry-parser/
    Complete output (7 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-wheel-4es5ic97/gamry-parser/setup.py", line 23, in <module>
        install_requires=get_requirements(),
      File "/tmp/pip-wheel-4es5ic97/gamry-parser/setup.py", line 5, in get_requirements
        requirements = open("requirements.txt", "r").read()
    FileNotFoundError: [Errno 2] No such file or directory: 'requirements.txt'
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

ChronoAmperometry.load() bug

ChronoAmperometry is a subclass of GamryParser. It overloads the GamryParser.load() function improperly (does not support filename input).

Need to fix to support specifying ChronoAmperometry.load(filename)

Package should use pd.read_csv

We should migrate to using pandas read_csv rather than maintaining a custom parser.

See gamryparser.GamryParser.read_curves.read_curve_data

bug: CyclicVoltammetry get_v_range()

CyclicVoltammetry.get_v_range() only looks up the results from the first curve. Usually, this should match the entire set of curves, but it is possible to set up the initial potential to skip some of the range in the first curve. I suspect it's also possible to miss on other curves if the experiment is aborted before completion.

Instead, we should be looking the range up from the header:

  • VINIT: starting potential
  • VLIMIT1: minimum voltage range
  • VLIMIT2: maximum voltage range
  • VFINAL: ending potential

Fix:

  1. Change the behavior to return a tuple of (VLIMIT1, VLIMIT2)
  2. Raise an assertion error if the header did not contain those keys.

Load OCV Curve Data

Currently, OCVCURVE data is ignored by the parser (#13).

Instead, (if it exists) the OCV data should be kept and made accessible to the user.

Currently:

  • bool self.ocv_curve indicates if the DTA file contained an OCV curve in the header.

Fix:

  • persist OCVCURVE data. The curve table is expected to take the form:
OCVCURVE	TABLE	[__a_number__]
	Pt	T	Vf	Vm	Ach	Over
	#	s	V vs. Ref.	V	V	bits
  • provide a function to retrieve the time-series OCV data, if it exists
  • provide a function to indicate whether OCV data has been loaded

handling string during file loading

Hello everyone,

sorry if this is a newbie question, but upon loading the file, I run into a 'could not convert string to float: '0,00000E+000' error.
My Gamry outpul .DATA files contain scientific notation of numbers and apparently the loading of the file and conversion to pd.dataframe has an issue with that.
What were your solutions/what am I doing wrong?

Thanks for any advice

Support for VFP600

VFP600 is a LabView frontend distributed by Gamry alongside the Gamry Framework. VFP600 generates a simple EXPLAIN-formatted data file.

Notable differences from typical explain files:

  • The header contains minimal information (just control mode and acq. frequency)
  • Tables of type VFPCURVE only have 2 columns [Voltage, Current] and do not contain index information.

Fails for files encoded with a different locale

Gamry files are created with local number formatting. For example, in Germany and much of the world, the comma is used a decimal separator. So a value would be 8,47309E-004 in the DTA file.

This can be partly solved with import locale in the header and replacing float with locale.atof in read_header. Then any file using gamry-parser can set the locale:

import gamry_parser as parser
import locale
locale.setlocale(locale.LC_ALL, 'de_DE')

file = 'CV.DTA'
gp = parser.GamryParser()
gp.load(filename=file)

However, a problem remains. read_curves uses the following line:

temp = temp.apply(pd.to_numeric, errors='ignore')

This doesn't use the locale. It doesn't give an error, but numbers with a comma decimal remain as strings. I'm not sure what the best way to solve this is.

Fix pycodestyle errors

  1. Fix errors
  2. Remove --exit-zero flag from flake8 CI workflow to generate errors rather than warnings.

List of errors generated:

 ./gamry_parser/vfp600.py:42:17: E226 missing whitespace around arithmetic operator
./gamry_parser/vfp600.py:67:1: W293 blank line contains whitespace
./gamry_parser/vfp600.py:88:1: W391 blank line at end of file
./gamry_parser/__init__.py:7:27: W292 no newline at end of file
./gamry_parser/gamryparser.py:185:1: W293 blank line contains whitespace
./tests/test_vfp600.py:17:49: E226 missing whitespace around arithmetic operator
./tests/test_vfp600.py:17:53: E261 at least two spaces before inline comment
./tests/test_vfp600.py:21:1: W293 blank line contains whitespace
./tests/test_vfp600.py:25:1: W293 blank line contains whitespace
./tests/test_vfp600.py:28:1: W293 blank line contains whitespace
./tests/test_vfp600.py:30:51: E226 missing whitespace around arithmetic operator
./tests/test_vfp600.py:32:57: E226 missing whitespace around arithmetic operator
./tests/test_vfp600.py:32:70: W292 no newline at end of file
4     E226 missing whitespace around arithmetic operator
1     E261 at least two spaces before inline comment
2     W292 no newline at end of file

Improper date handling for Gamry Framework 7.07

Recently installed new gamry framework software. Looks like the EXPLAIN label for DATE is now presented in D-M-YYYY format. Previously, the date label was provided as MM/DD/YYYY (EN_US format).

This breaks assumptions using timestamp-aware experiments (CHRONOA, CORPOT), in which we rely exclusively on pandas.to_datetime().

Solution:

  • For any pandas.to_datetime calls, add the parameter datefirst=True when necessary.

Open Circuit Potential Files

Package should properly parse CORPOT explain files.

  • Single curve data
  • data to keep: T, Vf
  • self.curves[0] should be the same as self.ocv

CV add-ons: peak finding, plotting

In my fork, I've added functionality to cv.py:

  • get_peaks(): returns a DataFrame of peak positions and heights, and other info from scipy find_peaks. The function also finds a peak at the upper voltage limit. I'm not sure how to best solve this.
  • plot(): plots the CV, including peaks, arrows showing scan direction. It can convert units as well, and includes correct units in the axis labels.

Inconsistency in `to_timestamp` argument

The load() method of the GamryParser class and subclasses process raw DTA data. An alternative is to specify the file to be processed during class initialization.

For the OpenCircuitPotential subclass, an additional parameter was introduced allowing users to define whether the resulting dataframe samples should be listed in time elapsed (seconds) or as a pandas.Timestamp (param: to_timestamp).

  1. Should this be extended to other classes? Maybe it should be part of the parent GamryParser class.
  2. Within OpenCircuitPotential, the load() method doesn't respect the to_timestamp parameter specified in init.
  3. Within OpenCircuitPotential, the load() method should accept another optional input (to_timestamp) allowing the user to specify on a per-load basis.

Change: Impl class properties

Replace class getter methods with @property decorators.

  • get_curve_count
  • get_curve_indices
  • get_curve_numbers
  • get_curves
  • get_header
  • get_experiment_type
  • get_ocv_curve
  • get_ocv_value

Note: this will be a breaking change.

Subclass GamryParser for specific experiment types

EXPLAIN data format may be used to record many different types of experiments (including custom-generated ones). In fact, all experiments run by the Gamry Framework software will save results to an EXPLAIN-compatible file.

For different experiment types (e.g. cyclic voltammetry and potentiostatic EIS have different inputs and outputs), the generic parser class may result in a lot of overhead for end users.

Example Use case

For cyclic voltammetry experiments, the Gamry Framework is configured to perform N cycles of voltage cycling between A and B potentials at a rate of +/- C mV/s and sampling every D seconds.

  • The end user may want all cycles, but more likely only needs a subset of them (e.g. curve 10 out of 10). Supported by GamryParser
  • The end user may only care about specific data (columns), rather than the entire TABLE output (e.g. ignore T, keep Vf and Im). Not supported
  • The end user may need to perform basic routine analysis associated with an experiment type that is not common with others (e.g. peak detection, or integration over a range). Not supported

In the not supported cases, it make sense to extend the GamryParser class with experiment-specific classes, overloading and adding methods as necessary.

Proposal

An initial set of subclasses should be created. My immediate needs are to do this for Cyclic Voltammetry (CV) and Chronoamperometry (CHRONOA) experiments, though online the most common usage appears to be for Potentiostatic Impedance (EISPOT) experiments (often associated with battery simulation).

Github Action should automatically publish releases

Currently, github actions are used as CI to run linting and unit tests. It would be nice to automate publishing a new release to pypi through similar triggers.

  • mirror current build process using setuptools
  • build artifacts for each environment that's tested (currently, python 3.5, 3.6, 3.7, 3.8, and 3.9)
  • publish sdist and eggs to pypi

Parser fails on Aborted Experiments

Latest Gamry Framework will append the following line for experiments that are aborted (including in the middle of a curve).

EXPERIMENTABORTED	TOGGLE	T	Experiment Aborted

Current behavior:
This currently causes the parser to raise an exception (can't convert string to int when trying to add the row into the current curve's dataframe).

Expected behavior:
Curve should load all collected data leading up to the EXPERIMENTABORTED label

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.