Skip to content

Commit

Permalink
Merge pull request #4 from lowe-lab-ucl/refactor
Browse files Browse the repository at this point in the history
Refactor
  • Loading branch information
quantumjot authored Nov 21, 2023
2 parents a16667a + df94c1a commit b58cdd3
Show file tree
Hide file tree
Showing 19 changed files with 1,162 additions and 635 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Linting

on:
push:
branches:
- main
pull_request:

jobs:
linting:
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v3

- name: Cache pre-commit
uses: actions/cache@v3
with:
path: ~/.cache/pre-commit
key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}

- name: Set up python
uses: actions/setup-python@v4
with:
python-version: "3.x"
cache: "pip"
cache-dependency-path: "pyproject.toml"

- name: Install dependencies
run: |-
python -m pip install pre-commit
pre-commit install
- name: Run pre-commit
run: pre-commit run --all-files --color always
36 changes: 36 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Test

on:
push:
branches:
- main
pull_request:
paths-ignore:
- "**.md"
- "**.rst"

jobs:
tests:
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v3

- name: Set up python
uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: "pip"
cache-dependency-path: "pyproject.toml"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install pytest
- name: Install umetrics
run: |
pip install -e .
- name: Run tests
run: |
pytest
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
*.ipynb_checkpoints
*.egg-info/
.DS_Store
umetrics/__pycache__
notebooks/.ipynb_checkpoints
__pycache__
notebooks/
_version.py
26 changes: 26 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.262
hooks:
- id: ruff
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-case-conflict
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-merge-conflict
- id: check-toml
- id: end-of-file-fixer
- id: mixed-line-ending
args: [--fix=lf]
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
- repo: https://github.com/pappasam/toml-sort
rev: v0.23.0
hooks:
- id: toml-sort-fix
25 changes: 16 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ TODO:
### Single image usage

```python
import umetrics
import umetrix
from skimage.io import imread

y_true = imread('true.tif')
Expand All @@ -29,7 +29,12 @@ y_pred = imread('pred.tif')

# can now make the calculation strict, by only considering objects that have
# an IoU above a theshold as being true positives
result = umetrics.calculate(y_true, y_pred, strict=True, iou_threshold=0.5)
result = umetrix.calculate(
y_true,
y_pred,
strict=True,
iou_threshold=0.5
)

print(result.results)
```
Expand All @@ -56,14 +61,16 @@ localization_error: 0.010
### Batch processing

```python
import umetrics
import umetrix

# provide a list of file pairs ('true', 'prediction')
files = [('true0.tif', 'pred0.tif'),
('true1.tif', 'pred1.tif'),
('true2.tif', 'pred2.tif')]
files = [
('true0.tif', 'pred0.tif'),
('true1.tif', 'pred1.tif'),
('true2.tif', 'pred2.tif')
]

batch_result = umetrics.batch(files)
batch_result = umetrix.batch(files)
```

Returns aggregate statistics over the batch. Jaccard index is calculated over
Expand All @@ -79,8 +86,8 @@ $ git clone https://github.com/quantumjot/unet_segmentation_metrics.git

2. (Optional, but advised) Create a conda environment:
```sh
$ conda create -n umetrics python=3.7
$ conda activate umetrics
$ conda create -n umetrix python=3.9
$ conda activate umetrix
```

3. Install the package
Expand Down
99 changes: 53 additions & 46 deletions notebooks/unet_segmentation_metrics-napari.ipynb

Large diffs are not rendered by default.

179 changes: 111 additions & 68 deletions notebooks/unet_segmentation_metrics.ipynb

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[build-system]
requires = ["setuptools", "setuptools-scm"]
build-backend = "setuptools.build_meta"

[project]
name = "umetrix"
authors = [
{name = "Alan R. Lowe", email = "[email protected]"}
]
description = "UNet Segmentation Metrics"
readme = "README.md"
requires-python = ">=3.8"
keywords = ["image analysis"]
license = {text = "BSD-3-Clause"}
classifiers = [
"Programming Language :: Python :: 3"
]
dependencies = [
"matplotlib",
"numpy",
"pandas",
"scikit-learn",
"scikit-image>=0.20.0" # to include the spacing argument in regionprops
]
dynamic = ["version"]

[tool.setuptools.packages.find]
where = ["src"]
include = ["umetrix*"]

[tool.setuptools_scm]
local_scheme = "no-local-version"
write_to = "src/umetrix/_version.py"
13 changes: 0 additions & 13 deletions setup.py

This file was deleted.

1 change: 1 addition & 0 deletions src/umetrix/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .core import calculate, batch # NOQA: F401
Loading

0 comments on commit b58cdd3

Please sign in to comment.