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

Refactor code architecture #27

Merged
merged 91 commits into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
8223e53
chore: refactor config
MyPyDavid Oct 29, 2023
0d3d051
chore: refactor models
MyPyDavid Oct 29, 2023
5957e79
build: rm py3.7
MyPyDavid Oct 29, 2023
aaecf0a
test: mv example files to test_fixtures
MyPyDavid Oct 29, 2023
3b11df1
style: fix type checking
MyPyDavid Oct 29, 2023
fae205d
chore: add config file option
MyPyDavid Oct 29, 2023
257164c
chore: refactor file parsers and validation
MyPyDavid Oct 29, 2023
0dfb6ab
tests: fix test empty file
MyPyDavid Oct 29, 2023
899b4be
chore: refactor post process methods
MyPyDavid Oct 29, 2023
e07436c
test: fix test imports
MyPyDavid Oct 29, 2023
81c90b7
cli: update arg
MyPyDavid Oct 29, 2023
5c5f359
build: support only python 3.11 and higher
MyPyDavid Oct 29, 2023
77d7bfe
fix arg run_mode debug
MyPyDavid Oct 29, 2023
b59126f
fix func arg
MyPyDavid Oct 29, 2023
6bd98a2
ci: run only py 3.11
MyPyDavid Oct 29, 2023
2ea7cac
chore: refactor default models, add pydantic, mv to toml config
MyPyDavid Nov 11, 2023
25838dc
build: refactor build in toml and add dependencies
MyPyDavid Nov 11, 2023
a317656
tests: update tests
MyPyDavid Nov 25, 2023
ef4c9b4
chore: update config and default settings
MyPyDavid Nov 25, 2023
092fe98
feat: convert model to pydantic
MyPyDavid Nov 25, 2023
744082f
feat: use tablib for data parsing
MyPyDavid Nov 25, 2023
08114f2
chore: style and clean up
MyPyDavid Nov 25, 2023
57ac29a
chore: fix imports
MyPyDavid Nov 26, 2023
b7ebd00
ci: fix install
MyPyDavid Nov 26, 2023
55cc5dd
style: make ruff
MyPyDavid Dec 8, 2023
9c193ff
test: update imports
MyPyDavid Dec 10, 2023
d33eae3
chore: refactor processing
MyPyDavid Dec 10, 2023
47cee8a
chore: refactor subpackages, imports, exports
MyPyDavid Dec 10, 2023
b7808db
chore: refactor deconvolution models
MyPyDavid Dec 10, 2023
6dc5254
syle: make ruff
MyPyDavid Dec 10, 2023
79af303
chore: fix test and processing
MyPyDavid Dec 10, 2023
f44c759
chore: fix bugs
MyPyDavid Dec 10, 2023
3354a85
build: update pre-commit add ruff
MyPyDavid Jan 14, 2024
cf6a9ad
tests: refactor test fixtures
MyPyDavid Jan 14, 2024
4b4cf9a
refactor: default models to config
MyPyDavid Jan 14, 2024
fba0683
refactor: config settings
MyPyDavid Jan 14, 2024
f016991
refactor and convert models to pydantic
MyPyDavid Jan 14, 2024
f6b23ed
refactor and update file imports, add pydantic models
MyPyDavid Jan 14, 2024
87a1970
refactor delegating
MyPyDavid Jan 14, 2024
99dd668
refactor processing use pydantic and protocol
MyPyDavid Jan 14, 2024
e0041c8
chore: style
MyPyDavid Jan 14, 2024
26a3199
tests: update and fix tests
MyPyDavid Jan 14, 2024
c56464e
build: update deps, add pydantic-settings
MyPyDavid Jan 14, 2024
1f16b2d
chore: rename variables and imports
MyPyDavid Feb 11, 2024
e179df0
chore: add timer to run fit
MyPyDavid Feb 11, 2024
bc17053
refactor: refactor functions and update code style
MyPyDavid Feb 11, 2024
5ae1ef0
chore: update delegating functions
MyPyDavid Feb 11, 2024
300ac55
build: add loguru
MyPyDavid Feb 11, 2024
ea208ed
chore: refactor exports plots and tables
MyPyDavid Feb 11, 2024
4a498b3
chore: refactor files index functions
MyPyDavid Feb 11, 2024
9b6f35e
chore: refactor fit run
MyPyDavid Feb 11, 2024
cfd8cee
chore: refactor fit_spectrum_plot
MyPyDavid Feb 12, 2024
3a151e1
chore: refactor RunModePaths
MyPyDavid Feb 12, 2024
b5ae145
chore: fix style
MyPyDavid Feb 12, 2024
dc2d35c
test: update test paths
MyPyDavid Feb 12, 2024
4ef01f4
chore: add export paths to ExportManager
MyPyDavid Feb 12, 2024
06a2dff
refactor calculate params post fit
MyPyDavid Feb 17, 2024
68c3cc7
fix tests and rename
MyPyDavid Feb 17, 2024
1737f95
refactor despiker
MyPyDavid Feb 17, 2024
7cc06fe
feat add normalization fit
MyPyDavid Feb 17, 2024
149ce5b
chore add get_window func
MyPyDavid Feb 17, 2024
3d4493b
refactor and rename funcs and vars
MyPyDavid Feb 17, 2024
5d669be
chore: fix main user package home setting for export
MyPyDavid Feb 18, 2024
43d9e18
tests: fix plot formatting tests
MyPyDavid Feb 18, 2024
b836bd9
chore: clean up
MyPyDavid Feb 18, 2024
a589d63
refactor fit spectrum plot
MyPyDavid Feb 18, 2024
ae29087
chore: fix load from index
MyPyDavid Feb 19, 2024
bc2f15f
refactor config settings
Mar 6, 2024
e03e136
style fix typing
Mar 6, 2024
df2ecb2
refactor windows into spectrum_regions.py from config
Mar 6, 2024
a955ee2
tests: migrate to pytest, add fixtures
Mar 9, 2024
a3dd01a
chore: update config
Mar 9, 2024
56ac76b
build: autoupdate pre-commit
Mar 9, 2024
3ac5be0
feat: add typer cli
Mar 9, 2024
9fea399
chore: use loguru as logger
Mar 9, 2024
9b3884a
chore: rename to region and minor changes
Mar 9, 2024
bafa2a7
Bump version: 0.7.0 → 0.8.0
Mar 9, 2024
23dd2fe
feat: add decorator_with_kwargs by @ramonrosa
Mar 9, 2024
fcafab7
feat: add required params to calculate_ratio funcs
Mar 9, 2024
aadf5fd
cli: fix and add make cmd
Mar 9, 2024
bd66d1a
chore: resolve all sonar issues and rename windows into regions
Mar 9, 2024
656c8f7
chore: resolve sonar issue
Mar 9, 2024
0e003e4
feat: add support for multiprocessing
Mar 10, 2024
6b42cf8
chore: clean up preprocessing
Mar 10, 2024
6d4ad0b
chore: add many minor changes
Mar 10, 2024
ea8aa59
tests: add param ratio and fit model tests
Mar 10, 2024
0e59e15
feat: add calculate params
Mar 10, 2024
68eeb62
cli: update make index
Mar 10, 2024
f7ed461
chore: export fix plots
Mar 10, 2024
b5f97ab
chore: add minor changes and fixes
Mar 10, 2024
5af8dc2
tests: add test for base peak
Mar 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions .github/workflows/build-test-codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
fail-fast: true
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
python-version: [3.8, 3.9, "3.10", 3.11]
python-version: [3.11]


steps:
Expand All @@ -32,8 +32,7 @@ jobs:
run: |
python3 -m pip install -U pip
python3 -m pip install -U build
python3 -m pip install flake8 pytest
python3 -m pip install -r requirements.txt
python3 -m pip install flake8

- name: Lint with flake8
run: |
Expand All @@ -46,18 +45,16 @@ jobs:
run: |
python3 -m build
# install the package in editable mode for the coverage report
python3 -m pip install -e .

- name: Install dependencies for coverage report
run: |
python3 -m pip install pytest pytest-cov coverage
python3 -m pip install -e .["pytest"]

- name: Generate coverage report
run: |
pytest --cov --cov-report=xml --cov-report=term-missing
- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v1

- name: raman_fitting -M make_examples
- name: raman_fitting run examples


run: |
raman_fitting -M make_examples
raman_fitting run examples
7 changes: 2 additions & 5 deletions .github/workflows/test-release-candidate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
# windows-latest !=> gives error in 'if' statetement
python-version: ["3.9", "3.10", "3.11"]
python-version: ["3.11"]
env:
OS: ${{ matrix.os }}
PYTHON: ${{ matrix.python-version }}
Expand All @@ -71,10 +70,8 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install flake8
python -m pip install pytest pytest-cov coverage
python -m pip install -U build
python -m pip install -r requirements.txt
python -m pip install --editable .[test]
python -m pip install --editable .["pytest"]

- name: Sanity check with flake8
run: |
Expand Down
27 changes: 10 additions & 17 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Temporary disabling hooks: SKIP=flake8 git commit -m "foo"
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-added-large-files
name: Check for files larger than 5 MB
Expand All @@ -13,23 +13,16 @@ repos:
exclude: '\.Rd'
- id: trailing-whitespace
name: Check for trailing whitespaces (auto-fixes)
# - repo: https://github.com/pycqa/isort # raises an error disabled for now
# rev: 5.11.2
# hooks:
# - id: isort
# name: isort (python)
- repo: https://github.com/psf/black
rev: 23.3.0 # Replace by any tag/version: https://github.com/psf/black/tags
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.3.2
hooks:
- id: black
name: black - consistent Python code formatting (auto-fixes)
language_version: python # Should be a command that runs python3.6+
# - repo: https://github.com/pycqa/flake8
# rev: 6.0.0
# hooks:
# - id: flake8
# name: flake8 - Python linting
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format
- repo: https://github.com/gitleaks/gitleaks
rev: v8.16.1
rev: v8.18.2
hooks:
- id: gitleaks
10 changes: 7 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
# set base image (host OS)
FROM python:3.11

RUN addgroup -S nonroot \
&& adduser -S nonroot -G nonroot

USER nonroot

# set the working directory in the container
WORKDIR /code

# copy the dependencies file to the working directory
COPY . .
COPY ./raman-fitting ./raman-fitting

# copy setup.cfg to work dir
# COPY setup.cfg .
Expand All @@ -25,5 +30,4 @@ RUN pip install -e ./
#COPY src/ .

# command to run on container start
CMD [ "raman_fitting -M make_examples" ]
# CMD [ "python", "./raman_fitting/docker/run_make_examples.py" ]
CMD [ "raman_fitting run examples" ]
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

In batch processing mode this package will index the raman data files in a chosen folder.
First, it will try to extract a sample ID and position number from the filenames and create an index of the files in a dataframe. Over this index a preprocessing, fitting and exporting loop will start.
There are several models, each with a different combination of typical peaks, used for fitting. Each individual typical peak is defined as a class in the deconvolution/default_peaks folder with some added literature reference in the docstring. Here, the individual peak parameter settings can also be easily adjusted for initial values, limits, shape (eg. Lorentzian, Gaussian and Voigt) or be fixed at certain initial values.
There are several models, each with a different combination of typical peaks, used for fitting. Each individual typical peak is defined as a class in the deconvolution/default_models folder with some added literature reference in the docstring. Here, the individual peak parameter settings can also be easily adjusted for initial values, limits, shape (eg. Lorentzian, Gaussian and Voigt) or be fixed at certain initial values.
Export is done with plots and excel files for the spectral data and fitting parameters for further analysis.


Expand Down Expand Up @@ -57,7 +57,7 @@ python -m pip install -e raman-fitting/

In order to test the package after installation, please try the following command in a terminal CLI.
``` bash
raman_fitting -M make_examples
raman_fitting run examples
```
or these commands in the Python interpreter or in a Jupyter Notebook.
``` python
Expand Down Expand Up @@ -86,7 +86,7 @@ raman_fitting

# If you add a lot of files, try to check if the index is properly constructed
# before fitting them.
raman_fitting -M make_index
raman_fitting make index

# Location of index
home/.raman_fitting/datafiles/results/raman_fitting_index.csv
Expand All @@ -106,7 +106,7 @@ sample2-100_3.txt => sampleID = 'sample2-100', position = 3
```
### Version

The current version is v0.7.0
The current version is v0.8.0

### Dependencies

Expand Down
95 changes: 73 additions & 22 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,62 @@ authors = [
]
description = "Python framework for the batch processing and deconvolution of raman spectra."
readme = {file = "README.md", content-type = "text/markdown"}
long_description = {file = "README.md", content-type = "text/markdown"}
keywords = ["spectroscopy", "Raman", "fitting", "deconvolution", "batch processing", "carbonaceous materials"]
classifiers = [
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Programming Language :: Python",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Intended Audience :: Science/Research",
"Topic :: Scientific/Engineering :: Physics",
"Topic :: Scientific/Engineering :: Chemistry",
]
dynamic = ["version", "long_description"]
dynamic = ["version"]
dependencies = [
"pandas~=2.1.2",
"scipy~=1.11.3",
"lmfit~=1.2.2",
"matplotlib~=3.8.0",
"numpy~=1.26.1",
"tablib~=3.5.0",
"pydantic>=2.5",
"pydantic-settings>=2.1",
"pydantic_numpy>=4.1",
"loguru>=0.7",
"typer[all]",
"mpire[dill]~=2.10.0",
]

[project.optional-dependencies]
pytest = [
"pytest",
"pytest-cov",
"pytest-flake8",
"mock",
"wheel"
]
dev = [
"isort",
"pylint",
"flake8",
"autopep8",
"pydocstyle",
"black",
"bump2version",
"raman_fitting[pytest]"
]

[project.urls]
homepage = "https://pypi.org/project/raman-fitting/"
repository = "https://github.com/MyPyDavid/raman-fitting.git"
# documentation = "https://raman-fitting.readthedocs.io/en/latest/"

[project.scripts]
raman_fitting = "raman_fitting.interfaces:main"
raman_fitting = "raman_fitting.interfaces.typer_cli:app"


[tool.hatch.version]
source = "vcs"
Expand All @@ -53,7 +82,7 @@ sources = ["src"]

# testing
[tool.pytest.ini_options]
minversion = "6.0"
minversion = "7.0"
pythonpath = "src"
addopts = [
"--import-mode=importlib",
Expand All @@ -65,36 +94,58 @@ testpaths = [
"tests",
]

[tool.coverage.run]
source = ["src"]
omit = [
"*/example_fixtures/*",
]

[tool.coverage.report]
# Regexes for lines to exclude from consideration
exclude_also = [
# Don't complain about missing debug-only code:
"def __repr__",
"if self\\.debug",

# Don't complain if tests don't hit defensive assertion code:
"raise AssertionError",
"raise NotImplementedError",

# Don't complain if non-runnable code isn't run:
"if 0:",
"if __name__ == .__main__.:",

# Don't complain about abstract methods, they aren't run:
"@(abc\\.)?abstractmethod",
]

ignore_errors = true

[tool.coverage.html]
directory = "coverage_html_report"


[tool.bumpversion]
current_version = "0.7.0"
current_version = "0.8.0"
commit = true
commit_args = "--no-verify"
message = "Bump version: {current_version} → {new_version}"
tag = true
allow_dirty = true
tag_name = "{new_version}"
tag_message = "Bump version: {current_version} → {new_version}"
parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)(\\.dev(?P<dev>\\d+))?"
serialize =[
"{major}.{minor}.{patch}.dev{dev}",
"{major}.{minor}.{patch}"
]
message = "Version updated from {current_version} to {new_version}"

[[bumpversion.files]]
[[tool.bumpversion.files]]
filename= "README.md"
search = "The current version is v{current_version}"
replace = "The current version is v{new_version}"

# [[bumpversion.files]]
# filename= "src/raman_fitting/__init__.py"
# search = "__version__ = '{current_version}'"
# replace = "__version__ = '{new_version}'"

# [[bumpversion.files]]
# filename= "src/raman_fitting/_version.py"
# search = "version = '{current_version}'"
# replace = "version = '{new_version}'"

[[bumpversion.files]]
[[tool.bumpversion.files]]
filename= "pyproject.toml"
search = "current_version = '{current_version}'"
replace = "current_version = '{new_version}'"
6 changes: 0 additions & 6 deletions requirements.txt

This file was deleted.

Loading
Loading