Skip to content

Commit

Permalink
python: update package metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Mar 25, 2024
1 parent 655fb22 commit 57f53c0
Show file tree
Hide file tree
Showing 27 changed files with 91 additions and 161 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 0 additions & 20 deletions .coveragerc

This file was deleted.

2 changes: 0 additions & 2 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@
max-line-length = 132
ignore = E203
exclude = .git,__pycache__,.eggs/,doc/,docs/,build/,dist/,archive/
per-file-ignores =
__init__.py:F401
20 changes: 0 additions & 20 deletions .gitattributes

This file was deleted.

47 changes: 19 additions & 28 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,15 @@ on:
paths:
- "**/*.py"
- "**/*.f90"
pull_request:
paths:
- "**/*.py"
- "**/*.f90"


jobs:

fortran:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'

Expand All @@ -25,36 +22,30 @@ jobs:
- run: meson setup build
- run: meson test -C build

linux:
runs-on: ubuntu-latest
python:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [windows-latest, macos-latest, ubuntu-latest]

steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'

- run: |
sudo apt update
sudo apt install --no-install-recommends octave
- name: Install GNU Octave
if: runner.os == 'Linux'
run: sudo apt install --no-install-recommends octave

- name: Install Oct2Py
if: runner.os == 'Linux'
run: pip install oct2py

- run: pip install oct2py
- run: pip install .[tests,lint]

- run: flake8
- run: mypy

- run: pytest

integration:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, macos-latest]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.x'

- run: pip install .[tests]
- run: pytest
5 changes: 0 additions & 5 deletions .mypy.ini

This file was deleted.

4 changes: 2 additions & 2 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2014, Michael Hirsch
Copyright (c) 2014, SciVision
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand All @@ -24,4 +24,4 @@ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 changes: 8 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
# AIRtools


[![Actions Status](https://github.com/scivision/airtools/workflows/ci/badge.svg)](https://github.com/scivision/airtools/actions)

[![PyPi versions](https://img.shields.io/pypi/pyversions/airtools.svg)](https://pypi.python.org/pypi/airtools)
[![PyPi Download stats](http://pepy.tech/badge/airtools)](http://pepy.tech/project/airtools)
[![Actions Status](https://github.com/geospace-code/airtools/workflows/ci/badge.svg)](https://github.com/geospace-code/airtools/actions)
[![PyPI Download stats](http://pepy.tech/badge/airtools)](http://pepy.tech/project/airtools)



Limited subset of P.C. Hansen and J. S. Jørgensen
[AIRtools 1.0](http://www2.compute.dtu.dk/~pcha/AIRtoolsII/)
[AIRtools](http://www2.compute.dtu.dk/~pcha/AIRtoolsII/)
Matlab suite of inversion / regularization tools, along with some ReguTools functions.
Also includes linear constrained least squares solver using cvxopt in `lsqlin.py`

More function are available in Matlab from
[AIRtools 2](https://github.com/jakobsj/AIRToolsII).

## Install

```sh
python -m pip install -e .
```

## Usage

Just paste the code from each test into your console for the function
you're interested in. Would you like to submit a pull request for an
inversion example making a cool plot?

* logmart.py: log-MART
* picard.py: Picard Plot
* kaczmarz.py Kaczmarz ART
* maxent.py: Maximum Entropy Regularization (from ReguTools)
Expand All @@ -36,16 +28,15 @@ inversion example making a cool plot?
* matlab/logmart.m: Implementation of log-MART
* fortran/logmart.f90: log-MART in Fortran


### Examples

[tests/test_all.py](./tests/test_all.py)
Examples: [tests/test_all.py](./tests/test_all.py)

### Tests

Run a comparison of the Python code with the Matlab code in the [matlab](./matlab) directory by:

python airtools/tests/test_octave.py
```sh
python airtools/tests/test_octave.py
```

which runs the Matlab version via
[Oct2Py](https://blink1073.github.io/oct2py/).
4 changes: 2 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
project('airtools', 'fortran',
default_options : ['default_library=static', 'buildtype=release'])
default_options : ['buildtype=release'])


art = library('art', 'fortran/logmart.f90')
Expand All @@ -8,4 +8,4 @@ test_exe = executable('test_logmart',
sources: ['fortran/test_logmart.f90', 'fortran/random_utils.f90'],
link_with : art)

test('logmart', test_exe)
test('logmart', test_exe)
34 changes: 33 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
[build-system]
requires = ["setuptools", "wheel"]
requires = ["setuptools>=61.0.0", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "airtools"
description = "Python port of Matlab AIRtools and ReguTools regularization toolbox"
keywords = [ "regularization", "linear algebra" ]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Intended Audience :: End Users/Desktop",
"Intended Audience :: Science/Research",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Topic :: Scientific/Engineering",
"Topic :: Utilities"
]
dependencies = ["scipy", "numpy"]
requires-python = ">=3.8"
dynamic = ["version", "readme"]

[tool.setuptools.dynamic]
readme = {file = ["README.md"], content-type = "text/markdown"}
version = {attr = "airtools.__version__"}

[project.optional-dependencies]
tests = ["pytest"]
lint = ["flake8", "flake8-bugbear", "flake8-builtins", "flake8-blind-except", "mypy",
"types-python-dateutil", "types-requests"]

[tool.mypy]
files = ["src"]
ignore_missing_imports = true

[tool.black]
line-length = 99
40 changes: 0 additions & 40 deletions setup.cfg

This file was deleted.

4 changes: 0 additions & 4 deletions setup.py

This file was deleted.

4 changes: 4 additions & 0 deletions airtools/__init__.py → src/airtools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
from .picard import picard
from .logmart import logmart
from .rzr import rzr

__all__ = ["kaczmarz", "maxent", "picard", "logmart", "rzr"]

__version__ = "1.3.0"
13 changes: 7 additions & 6 deletions airtools/kaczmarz.py → src/airtools/kaczmarz.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
from __future__ import annotations
import logging

import numpy as np
from numpy.linalg import norm
import scipy.sparse as sp


def kaczmarz(
A: np.ndarray | sp.spmatrix,
b: np.ndarray,
A,
b,
*,
max_iter: int = 8,
x0: np.ndarray = None,
x0=None,
lamb: float = 1.0,
stop_mdp: bool = False,
taudelta: float = 0,
nonneg: bool = True
) -> tuple[np.ndarray, np.ndarray]:
nonneg: bool = True,
) -> tuple:
"""
Michael Hirsch May 2014
Expand Down Expand Up @@ -104,6 +105,6 @@ def kaczmarz(
break
if i % 200 == 0:
residualNorm = norm(b - A @ x, 2)
print("Iteration {}, ||residual|| = {:.2f}".format(i, residualNorm))
print(f"Iteration {i}, ||residual|| = {residualNorm:.2f}")

return x, residual
12 changes: 6 additions & 6 deletions airtools/logmart.py → src/airtools/logmart.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@


def logmart(
A: np.ndarray,
b: np.ndarray,
A,
b,
*,
relax: float = 1.0,
x0: float = None,
x0: float | None = None,
sigma: float = 1.0,
max_iter: int = 20
) -> tuple[np.ndarray, float, int]:
max_iter: int = 20,
) -> tuple:
"""
estimation halted based on chi**2 value
A and b must be all NON-NEGATIVE!
Expand Down Expand Up @@ -95,5 +95,5 @@ def logmart(
return x_prev, chi2, i


def chi_squared(A: np.ndarray, b: np.ndarray, x: np.ndarray, sigma: float) -> float:
def chi_squared(A, b, x, sigma: float) -> float:
return math.sqrt((((A @ x - b) / sigma) ** 2).sum())
1 change: 1 addition & 0 deletions airtools/lsqlin.py → src/airtools/lsqlin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
See http://maggotroot.blogspot.ch/2013/11/constrained-linear-least-squares-in.html for more info
"""

__author__ = "Valeriy Vishnevskiy", "Michael Hirsch"
__email__ = "[email protected]"
__version__ = "1.0"
Expand Down
Loading

0 comments on commit 57f53c0

Please sign in to comment.