Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Series handling #11

Merged
merged 51 commits into from
Nov 12, 2021
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
a424abf
ECMeasurement properties: potential and current
ScottSoren Jan 26, 2021
2947325
first working EC plotter
ScottSoren Jan 26, 2021
b9f5ae2
current=0 during OCP periods
ScottSoren Jan 26, 2021
23ae425
file_number and selector in ECMeasurement
ScottSoren Jan 27, 2021
01eff7a
Merge branch 'ec_tools' into ec_features
ScottSoren Jan 27, 2021
48381a4
tspan cutting and selection in Measurement
ScottSoren Jan 27, 2021
550ef7f
ohmic drop correction, debug save&load
ScottSoren Jan 27, 2021
b0c185e
colored axes and plot_vs_potential for ec!
ScottSoren Jan 27, 2021
0f8dffa
first use of (id, backend_name) combo in Measurement
ScottSoren Jan 27, 2021
1ff49ba
start CyclicVoltammagram technique
ScottSoren Jan 27, 2021
1953d9c
CyclicVoltammagram cycle indexing and slicing
ScottSoren Jan 27, 2021
da0df21
working exporter for EC data
ScottSoren Jan 27, 2021
af60510
docstrings for cv.py, plotters and exporters
ScottSoren Jan 28, 2021
ad2b64f
docstrings in ec and new Measurement methods; debug time zero-ing
ScottSoren Jan 28, 2021
430d2b3
debugging for ipython notebook tutorial
ScottSoren Jan 29, 2021
953d577
add TODOs from design WS3 and 1st rev of PR #6
ScottSoren Feb 5, 2021
20a7966
update tools.rst
ScottSoren Jun 23, 2021
9a05ab0
update tools
ScottSoren Jun 24, 2021
6443968
write test for coming fixes
ScottSoren Jun 25, 2021
6db74c8
THE CORRECT __getitem__. MEASUREMENT BROKEN.
ScottSoren Jun 25, 2021
451fb33
move build functions to data_series, add new meas attributes
ScottSoren Jun 26, 2021
33a13b1
refactoring in prep for EC series handling
ScottSoren Jun 26, 2021
a5f130b
aliases in ec measurements
ScottSoren Jun 27, 2021
e3b5a8e
recursive lookup in __getitem__ for alias->calibration->alias
ScottSoren Jun 27, 2021
50b9ac2
Systematic series constructors. No ECMeasurement__getitem__. Working!
ScottSoren Jun 27, 2021
cb82ae9
fix selector and sel_str handling
ScottSoren Jun 27, 2021
3132636
ec calibration working with new __getitem__
ScottSoren Jun 27, 2021
4d903c5
debug tox
ScottSoren Jun 28, 2021
8fb8997
clean up after debugging tox
ScottSoren Jun 28, 2021
cce47c6
debug to run ec_tools_dev.py
ScottSoren Jun 28, 2021
b693d5f
new zero constant value essential series
ScottSoren Jun 29, 2021
d0bc4be
differentiate between BackendBase and MemoryBackend
ScottSoren Jun 29, 2021
9e87e57
object identity, less re-saving
ScottSoren Jun 29, 2021
494a937
start switching uid=197609(scott) gid=197609 groups=197609 for
ScottSoren Jun 29, 2021
5bcadfd
a ValueSeries is a Field!
ScottSoren Jun 29, 2021
2c4fbf0
vseries saves child tseries, ec_toos_dev passes
ScottSoren Jun 29, 2021
839d508
problematic attempt to use memory backend
ScottSoren Jun 29, 2021
bcd4840
better memory backend use via Saveable.as_dict()
ScottSoren Jun 30, 2021
a17b388
Merge branch 'master' into series_handling
ScottSoren Jun 30, 2021
0796611
write test for save-load cycle and write comments
ScottSoren Jun 30, 2021
47036bf
minor cleanup docu and comments in backends and db
ScottSoren Jun 30, 2021
d8e25b2
minor cleanup docu and comments in measurement and ec
ScottSoren Jun 30, 2021
cab5a65
preparing for implementation of Kenneth's review
ScottSoren Nov 9, 2021
8f06e28
rewrite __getitem__
ScottSoren Nov 9, 2021
d0f8f43
implement Kenneth's review comments: backends
ScottSoren Nov 9, 2021
3ba19a7
implement kni's comments to #11: db
ScottSoren Nov 10, 2021
4ec3209
differing returns back in Savable.short_identity
Nov 10, 2021
2a2266e
implementation of #11 review: measurement
Nov 10, 2021
399290e
continue implementation of #11 review: ec
ScottSoren Nov 11, 2021
878b578
finish implementation of review to #11
ScottSoren Nov 11, 2021
f16247d
t_zero in cut, add TODO comments, black format
Nov 12, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@

# Big files from tests and docs prep
development_scripts/*/*.png
development_scripts/*/*.svg
development_scripts/*/*.csv
docs/source/figures/big_src/*



# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down Expand Up @@ -133,4 +142,4 @@ dmypy.json

# More temporary files
\#*\#
*~
*~
71 changes: 62 additions & 9 deletions TOOLS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Tools used
The following is a list of specific tools used during ixdat
development:

* **black** is used for formatting code
* **pytest** is used for running tests
* **flake8** is used for linting
* **sphinx** is used to build documentation
Expand All @@ -20,7 +21,7 @@ The following is a list of "tool and commands runners":
before push or by continuous integration (CI) tools

Install instructions
--------------------
====================

Install all development tools by executing::

Expand Down Expand Up @@ -53,20 +54,25 @@ it is (see Windows instructions below under git hooks).
https://flake8.pycqa.org/en/latest/
This includes
syntax errors, but also programming errors like using a variable which
has not been defined, and style errors. flake8 can be a bit over-zeleous
and even a bit stupid, so even perfectly formatted (i.e. black-formatted)
code can sometimes
has not been defined, and style errors. flake8 can be a bit over-zeleous,
so even perfectly formatted (i.e. black-formatted) code can sometimes
trigger it. An example is unused import statements in __init__.py, which
are fine practice to make it quicker to import the most important parts of
a package. To allow these, we have added to the project's setup.cfg, the line
`--per-file-ignores = src/*/__init__.py:F401`
Additional allowances may need to be added there.
flake8 also enforces a maximum line length of 89, chosen by Soren to match the
flake8 also enforces a maximum line length of 89, chosen to match the
default setting of black (+/- 1 char).

**pytest** is a suite of stuff used to write and run software tests.
https://docs.pytest.org/en/stable/

**sphinx** is a tool for building the documentation into html and other
formats from restructured text (.rst). It also enables automatic documentation
generation from the doc-strings in the code. Read The Docs uses sphinx to compile
the documentation (ixdat/docs/source/index.rst) to make the will-be-beautiful
ixdat documentation at https://ixdat.readthedocs.io/

Tool runners
------------

Expand Down Expand Up @@ -129,10 +135,16 @@ Git hooks

The version control system ``git`` has the option of having check done
before certain important actions, like a commit or a push. These are
referred to as ``hooks``. For xidat a pre-push is recommended (as
referred to as ``hooks``. For ixdat, a pre-push is recommended (as
opposed to a pre-commit hook, which take time to run the tests on
every commit). The pre-push hooks are located in ``tools/hooks``.

While the pre-push hook is optional for developers, we will require
that any pull request to a branch supported for users passes linting
and pytesting. If you are using a pre-push hook, you enforce with
yourself that your work passes these checks the whole time, avoiding
extra work later.

Git hooks cannot be distributed automatically, so it will need to be
"installed".

Expand Down Expand Up @@ -164,20 +176,23 @@ Windows version of the hook, is the line at the top that indicates the
executable that should run the program).

Then there is a bit of difference depending on how git is used. If the
main interface to git is via powershell (or mayby Command Prompt) and
main interface to git is via powershell (or maybe Command Prompt) and
a virtual environment is being used and is active, then the commit
hook will just work.

If the development is done elsewhere, but still somehow relies on a
virtual environment (either a separate virtual environment or an
anaconda environment), and git is used via the Git Bash program that
is installed along with Git for Windows, then a bit more work is
required. The problem is that Git Bash does not know about the path of
required. This can be buggy.

The problem is that Git Bash does not know about the path of
the development tools, so that will have to be set manually.

First we should locate the path of the tools. In case a separate
virtual environment is used, located e.g. in ``c:\venv\ixdat``, then
``c:\venv\ixdat\Scripts`` will be the path of tools. TODO anaconda.
``c:\venv\ixdat\Scripts`` will be the path of tools. If you are
using conda, look below.

Having found the path of the tools it needs to be added to the Bash
configuration file like so::
Expand Down Expand Up @@ -210,6 +225,44 @@ Bash shell, navigation to the git archive and executing the command::
flake8: commands succeeded
congratulations :)

Anaconda Instructions
---------------------

If you are using Conda (Anaconda/Minicond) with Windows, you will need to
add two directories either to your system PATH variable (se explanation
`here <https://superuser.com/questions/284342/what-are-path-and-other-environment-variables-and-how-can-i-set-or-use-them>`_
) or to your ``.bash_profile`` or ``.bashrc`` (see explanation
`here <https://stackoverflow.com/questions/6883760/git-for-windows-bashrc-or-equivalent-configuration-files-for-git-bash-shell>`_
).

For a full Anaconda installation with the default location for User "scott",
the two paths to add are::

- ``C:\Users\scott\Anaconda3\Scripts``
- ``C:\Users\scott\Anaconda3``

And the two corresponding lines to add to ``~/.bash_profile``, using any text editor, are::

export PATH="$PATH:/c/ProgramData/Anaconda3/Scripts/"
export PATH="$PATH:/c/ProgramData/Anaconda3/"

Note that ``C:\`` becomes ``/c/``.

After adding these to your PATH variable, they should appear in $PATH in git bash.
To check, type::

echo $PATH

in git bash and see if they appear in the output. Once that is there you should
be able to run tox and the other tools and tool runners from git bash just by e.g.::

$ tox

, and it should work in a pre-push hook.

NOTE: There can still be bugs. See https://github.com/ixdat/ixdat/issues/10


Command quick tips
==================

Expand Down
30 changes: 30 additions & 0 deletions development_scripts/cv_tools_dev.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
"""
Created on Mon Jan 25 22:02:57 2021

@author: scott
"""
from pathlib import Path
from matplotlib import pyplot as plt

from ixdat import Measurement

plt.close("all")

my_id = 5
loaded_meas = Measurement.get(my_id)

cv = loaded_meas.as_cv()
cv.plot_measurement(j_name="cycle")
cv_selection = cv[10:16]

cv_selection.plot_measurement(j_name="cycle")
cv_selection.redefine_cycle(start_potential=0.4, redox=1)
cv_selection.plot_measurement(j_name="cycle")

ax = cv_selection[1].plot(label="cycle 1")
cv_selection[2].plot(ax=ax, linestyle="--", label="cycle 2")
ax.legend()


cv_selection.export(path_to_file=Path.home() / "test.csv")
5 changes: 1 addition & 4 deletions development_scripts/ec_tools.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from ixdat.techniques import ECMeasurement

path_to_file = (
"../test_data/biologic_mpt_and_zilien_tsv/"
"2020-07-29 10_30_39 Pt_poly_cv_01_02_CVA_C01.mpt"
)
path_to_file = "../test_data/biologic/Pt_poly_cv.mpt"

m = ECMeasurement.read(
path_to_file,
Expand Down
67 changes: 67 additions & 0 deletions development_scripts/ec_tools_dev.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# -*- coding: utf-8 -*-
"""
Created on Mon Jan 25 22:02:57 2021

@author: scott
"""
from pathlib import Path
from matplotlib import pyplot as plt

from ixdat import Measurement

plt.close("all")

if True:
data_dir = Path.home() / (
"Dropbox/ixdat_resources/tutorials_data/extended_platinum_ec/"
)

ocp_file = data_dir / "01_demo_02_OCV_C01.mpt"
cv_file = data_dir / "01_demo_03_CVA_C01.mpt"
cp_file = data_dir / "01_demo_04_CP_C01.mpt"

ocp_meas = Measurement.read(ocp_file, reader="biologic", name="Pt_demo_ocp")
print("read ocp file!")
cv_meas = Measurement.read(cv_file, reader="biologic", name="Pt_demo_cv")
print("read cv file!")
cp_meas = Measurement.read(cp_file, reader="biologic", name="Pt_demo_cp")
print("read cp file!")

ocp_id = ocp_meas.save()
cv_id = cv_meas.save()
cp_id = cp_meas.save()
else:
ocp_meas = Measurement.get(1)
cv_meas = Measurement.get(2)
cp_meas = Measurement.get(3)

combined_meas = ocp_meas + cv_meas + cp_meas

t_start = 13700
tspan = [0, 5000]

combined_meas.calibrate(RE_vs_RHE=0.715, A_el=0.196)

combined_meas.tstamp += t_start

combined_meas.plot(tspan=tspan)

cut_meas = combined_meas.cut(tspan=tspan)
cut_meas.plot(j_name="selector")

select_meas = cut_meas.select_values(selector=range(4, 8))
select_meas.correct_ohmic_drop(R_Ohm=200)
select_meas.plot_vs_potential()
if True:
select_meas.name = "selected_measurement"
select_meas.save() # this changes its ID!
my_id = select_meas.id
else:
my_id = 4

# select_meas

loaded_meas = Measurement.get(my_id)

loaded_meas.plot_vs_potential()
loaded_meas.plot(J_str="selector")
47 changes: 0 additions & 47 deletions development_scripts/ec_tools_development_pyCOox_data.py

This file was deleted.

2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ exclude =
# Likewise for all files in the .tox directory, which includes all
# the python source file of all dependencies etc.
.tox
# and any build
build
5 changes: 4 additions & 1 deletion src/ixdat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
__license__ = "MIT"

from .measurements import Measurement

from . import db
from . import techniques
from . import plotters
from . import exporters

# I like this to be sure I'm importing from where I think I am:
print(f"importing ixdat v{__version__} from {__file__}")
13 changes: 10 additions & 3 deletions src/ixdat/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@
is the backend class (inheriting from Backend) for saving and loading things.
"""

from .memory_backend import BackendBase, MemoryBackend
from .backend_base import BackendBase
from .memory_backend import MemoryBackend
from .directory_backend import DirBackend


DATABASE_BACKENDS = {
"None": BackendBase,
BACKEND_CLASSES = {
"none": BackendBase,
"memory": MemoryBackend,
"directory": DirBackend,
}
# FIXME: should automate that all initiated backends get added to database_backends?
database_backends = {
"none": BackendBase(), # Just assigns id's but doesn't keep track.
"memory": MemoryBackend(), # Keeps track so child objects can be passed around
"directory": DirBackend(), # Saves json files, stand-in for SQL, mainly for testing
ScottSoren marked this conversation as resolved.
Show resolved Hide resolved
}