Skip to content

Commit

Permalink
Merge branch 'ghactions'
Browse files Browse the repository at this point in the history
  • Loading branch information
CCampJr committed Mar 11, 2022
2 parents 4144cbb + f25cd64 commit 1190bc8
Show file tree
Hide file tree
Showing 130 changed files with 663 additions and 376 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Upload Python Package

on:
release:
types: [published]

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
46 changes: 46 additions & 0 deletions .github/workflows/python-testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: pytest

on: [push, pull_request]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pip install pytest
pip install pytest-cov
pytest --cov=./ --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
token: ${{ secrets.CODECOV_TOKEN }}
directory: ./coverage/reports/
env_vars: runs-on,python-version
fail_ci_if_error: true
files: ./coverage.xml
flags: unittests
name: codecov-umbrella
path_to_write_report: ./coverage/codecov_report.txt
verbose: true
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ This document records all notable changes to
This project adheres to `PEP 440 -- Version Identification
and Dependency Specification <https://www.python.org/dev/peps/pep-0440/>`_.

0.4 (22-03-11)
---------------
- **Important**: PhaseErrCorrectALS now has parameter for whether wavenumber is increasing left-to-right. This is important to set correctly. This should match the `conjugate` parameter in the KramersKronig.

0.3.1 (21-11-29)
-----------------
- Updated h5py deprecated syntax from .value to [:] (@XavierAutier)
Expand Down
10 changes: 8 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
.. -*- mode: rst -*-
.. image:: https://github.com/CCampJr/CRIkit2/actions/workflows/python-testing.yml/badge.svg
:alt: pytest
:target: https://github.com/CCampJr/CRIkit2/actions/workflows/python-testing.yml

.. image:: https://codecov.io/gh/CCampJr/CRIkit2/branch/master/graph/badge.svg
:alt: Codecov
:target: https://codecov.io/gh/CCampJr/CRIkit2

.. image:: https://img.shields.io/pypi/pyversions/CRIkit2.svg
:alt: PyPI - Python Version
:target: https://pypi.org/project/CRIkit2/
Expand Down Expand Up @@ -58,8 +66,6 @@ Note: These are the developmental system specs. Older versions of certain
packages may work.

- python >= 3.4
- Tested with 3.4.4, 3.5.2, 3.6.1, 3.7.2

- NumPy
- SciPy
- matplotlib (1.*, 2.*, 3.*)
Expand Down
2 changes: 1 addition & 1 deletion crikit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
* Charles H. Camp Jr. <[email protected]>
"""

__version__ = '0.3.1'
__version__ = '0.4.0'
86 changes: 80 additions & 6 deletions crikit/cri/error_correction.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,83 @@

class PhaseErrCorrectALS:
"""
Phase error correction using alternating least squares (ALS)
Phase error correction (PEC) using asymmetric least squares (ALS).
Parameters
----------
wavenumber_increasing : bool, optional (default=True)
Are the wavenumbers increasing from left-to-right? This setting should
match the conjugate setting of the previously performed KramersKronig.
smoothness_param : float, optional (default=1.0)
ALS smoothness parameter. See Ref [2].
asym_param : float, optional (default=1e-2)
ALS asymmetry parameter. See Ref [2].
redux : int, optional (default=10)
Factor to sub-sample each spectrum. This reduces computational burnden.
Sub-sample phase error is then interpolated to match input signal
length.
order : int, optional (default=2)
ALS derivative order number. See Ref [2].
rng : array-like, optional (default=None)
Only perform PEC on specific pixel range.
fix_end_points : bool, optional (default=False)
Phase error at extrema points is equal to input phase extrema points.
fix_rng : array-like, optional (default=None)
Phase error over given range is pushed to be equal to input phase. To
prevent discontinuities, it is not enforced in an exact manner, but
rather the algorithm is weighted to try to match.
fix_const : float, optional (default=1.)
For fix_rng, this is the weighting term. Higher value will force the
phase error to be more equal to the input.
max_iter : int, optional (default=100)
Maximum number of ALS iterations
min_diff : float, optional (default=1e-5)
Minimum difference between ALS phase error values. If difference is
less than min_diff, considered static and iterations are ceased.
verbose : bool, optional (default=True)
Verbose PEC output
Returns
-------
ndarray
Phase-error corrected signal from CARS.
Notes
-----
- This module assumes the spectra are oriented as such that the frequency
(wavenumber) increases with increasing index. If this is not the case for
your spectra(um), set wavenumber_increasing=False.
- The wavenumber_increasing setting should match that of the conjugate
setting for the previously-performed KramersKronig.
References
-----------
* C H Camp Jr, Y J Lee, and M T Cicerone, JRS (2016).
----------
[1] C. H. Camp Jr, Y. J. Lee, and M. T. Cicerone, "Quantitative, \
Comparable Coherent Anti-Stokes Raman Scattering (CARS) \
Spectroscopy: Correcting Errors in Phase Retrieval," Journal of Raman \
Spectroscopy 47, 408-415 (2016). arXiv:1507.06543.
[2] P. H. C. Eilers and H. F. M. Boelens, "Baseline Correction with \
Asymmetric Least Squares Smoothing," (2005).
"""
def __init__(self, smoothness_param=1, asym_param=1e-2,
def __init__(self, wavenumber_increasing=True,
smoothness_param=1, asym_param=1e-2,
redux=10, order=2, rng=None, fix_end_points=False,
fix_rng=None, fix_const=1, max_iter=100, min_diff=1e-5,
verbose=True, **kwargs):
Expand All @@ -33,7 +103,8 @@ def __init__(self, smoothness_param=1, asym_param=1e-2,
self.rng = _rng_is_pix_vec(rng)
self._k = kwargs

self._k.update({'smoothness_param' : smoothness_param,
self._k.update({'wavenumber_increasing' : wavenumber_increasing,
'smoothness_param' : smoothness_param,
'asym_param' : asym_param,
'redux' : redux,
'order' : order,
Expand Down Expand Up @@ -73,7 +144,10 @@ def _calc(self, data, ret_obj, **kwargs):
h = _np.zeros(err_phase[..., self.rng].shape)
h += _hilbert(err_phase[..., self.rng])

correction_factor = _np.exp(h) * _np.exp(-1j*err_phase[...,self.rng])
if self._k['wavenumber_increasing']:
correction_factor = _np.exp(h) * _np.exp(-1j*err_phase[...,self.rng])
else:
correction_factor = _np.exp(-h) * _np.exp(-1j*err_phase[...,self.rng])

# if self.rng is None:
# ret_obj[idx] *= correction_factor
Expand Down
11 changes: 6 additions & 5 deletions crikit/io/meta_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def meta_process(rosetta, output_cls_instance):
output_cls_instance.freq.calib_fcn = _calib_pix_wl

output_cls_instance.freq.update()

# See if an original calibration is found
try:
calib_orig_dict = {}
Expand All @@ -130,7 +130,7 @@ def meta_process(rosetta, output_cls_instance):
calib_orig_dict['ctr_wl0'] = rosetta_query('OrigColorCalibWL',rosetta, output_cls_instance)[0]
if calib_orig_dict['ctr_wl0'] is None:
raise ValueError

# Probe and Units are not necessary for calibration
# Probe is only needed for wavelength-to-wavenumber conversion
calib_orig_dict['probe'] = rosetta_query('OrigColorProbe',rosetta, output_cls_instance)[0]
Expand All @@ -141,7 +141,7 @@ def meta_process(rosetta, output_cls_instance):
else:
print('Original calibration found.')
output_cls_instance.freq.calib_orig = calib_orig_dict

# Spatial for HSI
if type(output_cls_instance) == _Hsi:
print('Type Hsi')
Expand Down Expand Up @@ -268,18 +268,19 @@ def meta_process(rosetta, output_cls_instance):
as _snb)

from crikit.io.hdf5 import hdf_import_data as _hdf_import_data
import os as _os
rosetta = _snb()

filename = _os.path.abspath('../../../mP2_w_small.h5')

spect_dark = _Spectra()
_hdf_import_data(filename,'/Spectra/Dark_3_5ms_2',spect_dark)
_hdf_import_data(filename, '/Spectra/Dark_3_5ms_2',spect_dark)
meta_process(rosetta, spect_dark)
print(spect_dark.reps)

print('')
img = _Hsi()
_hdf_import_data(filename,'/BCARSImage/mP2_3_5ms_Pos_2_0/mP2_3_5ms_Pos_2_0_small',img)
_hdf_import_data(filename, '/BCARSImage/mP2_3_5ms_Pos_2_0/mP2_3_5ms_Pos_2_0_small',img)
meta_process(rosetta, img)
print(img.freq.__dict__)

Expand Down
Binary file modified docs/build/doctrees/api.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/crikit.cri.doctree
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/build/html/.buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: ab213400e0c5b629c3fbbc81887e1f87
config: 680b288bd642a5606b1d094f16f72345
tags: 645f666f9bcd5a90fca523b33c5a78b7
6 changes: 3 additions & 3 deletions docs/build/html/_modules/crikit/CRIkitUI.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>crikit.CRIkitUI &#8212; CRIKit2 0.3.1 documentation</title>
<title>crikit.CRIkitUI &#8212; CRIKit2 0.4.0 documentation</title>
<link rel="stylesheet" href="../../_static/nature.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
Expand All @@ -26,7 +26,7 @@ <h3>Navigation</h3>
<li class="right" >
<a href="../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../index.html">CRIKit2 0.3.1 documentation</a> &#187;</li>
<li class="nav-item nav-item-0"><a href="../../index.html">CRIKit2 0.4.0 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">crikit.CRIkitUI</a></li>
</ul>
Expand Down Expand Up @@ -3864,7 +3864,7 @@ <h3>Navigation</h3>
<li class="right" >
<a href="../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../index.html">CRIKit2 0.3.1 documentation</a> &#187;</li>
<li class="nav-item nav-item-0"><a href="../../index.html">CRIKit2 0.4.0 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">crikit.CRIkitUI</a></li>
</ul>
Expand Down
6 changes: 3 additions & 3 deletions docs/build/html/_modules/crikit/cri/algorithms/kk.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>crikit.cri.algorithms.kk &#8212; CRIKit2 0.3.1 documentation</title>
<title>crikit.cri.algorithms.kk &#8212; CRIKit2 0.4.0 documentation</title>
<link rel="stylesheet" href="../../../../_static/nature.css" type="text/css" />
<link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
Expand All @@ -26,7 +26,7 @@ <h3>Navigation</h3>
<li class="right" >
<a href="../../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../../index.html">CRIKit2 0.3.1 documentation</a> &#187;</li>
<li class="nav-item nav-item-0"><a href="../../../../index.html">CRIKit2 0.4.0 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">crikit.cri.algorithms.kk</a></li>
</ul>
Expand Down Expand Up @@ -276,7 +276,7 @@ <h3>Navigation</h3>
<li class="right" >
<a href="../../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../../index.html">CRIKit2 0.3.1 documentation</a> &#187;</li>
<li class="nav-item nav-item-0"><a href="../../../../index.html">CRIKit2 0.4.0 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">crikit.cri.algorithms.kk</a></li>
</ul>
Expand Down
Loading

0 comments on commit 1190bc8

Please sign in to comment.