Skip to content

Commit

Permalink
Merge pull request #67 from neuro-ml/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
maxme1 authored Jan 20, 2023
2 parents c6786f8 + 9534551 commit 85f70e8
Show file tree
Hide file tree
Showing 35 changed files with 159 additions and 432 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Test

on: [ pull_request ]

env:
MODULE_NAME: dpipe

jobs:
test:
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: [ 3.6, 3.7, 3.8, 3.9, '3.10' ]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Check the version and build the package
run: |
VERSION=$(python -c "from pathlib import Path; import runpy; folder, = {d.parent for d in Path().resolve().glob('*/__init__.py') if d.parent.is_dir() and (d.parent / '__version__.py').exists()}; print(runpy.run_path(folder / '__version__.py')['__version__'])")
MATCH=$(pip index versions deep-pipe | grep "Available versions:" | grep $VERSION) || echo
echo $MATCH
if [ "$GITHUB_BASE_REF" = "master" ] && [ "$MATCH" != "" ]; then exit 1; fi
python setup.py sdist
- name: Install
run: |
pip install dist/*
pip install -r tests/requirements.txt
cd tests
export MODULE_PARENT=$(python -c "import $MODULE_NAME, os; print(os.path.dirname($MODULE_NAME.__path__[0]))")
export MODULE_PARENT=${MODULE_PARENT%"/"}
cd ..
echo $MODULE_PARENT
echo "MODULE_PARENT=$(echo $MODULE_PARENT)" >> $GITHUB_ENV
- name: Test with pytest
run: |
pytest tests -m "not integration and not cuda" --junitxml=reports/junit-${{ matrix.python-version }}.xml --cov="$MODULE_PARENT/$MODULE_NAME" --cov-report=xml --cov-branch
- name: Generate coverage report
run: |
coverage xml -o reports/coverage-${{ matrix.python-version }}.xml
sed -i -e "s|$MODULE_PARENT/||g" reports/coverage-${{ matrix.python-version }}.xml
sed -i -e "s|$(echo $MODULE_PARENT/ | tr "/" .)||g" reports/coverage-${{ matrix.python-version }}.xml
- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: reports-${{ matrix.python-version }}
path: reports/*-${{ matrix.python-version }}.xml
if: ${{ always() }}

- name: Upload coverage results
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: true
files: reports/coverage-${{ matrix.python-version }}.xml
verbose: true
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include *.md
include README.md
include requirements.txt
include LICENSE
recursive-include dpipe *.py
Expand Down
2 changes: 1 addition & 1 deletion dpipe/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.1.2'
from .__version__ import __version__
1 change: 1 addition & 0 deletions dpipe/__version__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = '0.2.0'
16 changes: 9 additions & 7 deletions dpipe/im/preprocessing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np
from skimage.measure import label
from imops.measure import label

from dpipe.itertools import negate_indices
from .axes import AxesLike, check_axes, AxesParams
Expand Down Expand Up @@ -99,14 +99,16 @@ def describe_connected_components(mask: np.ndarray, background: int = 0, drop_ba
volumes
a list of corresponding labels' volumes.
"""
label_map = label(mask, background=background)
labels, volumes = np.unique(label_map, return_counts=True)
label_map, labels, volumes = label(mask, background=background, return_labels=True, return_sizes=True)

if not drop_background:
# background's label is always 0
labels = np.append(labels, 0)
volumes = np.append(volumes, label_map.size - volumes.sum(dtype=int))

idx = volumes.argsort()[::-1]
labels, volumes = labels[idx], volumes[idx]
if drop_background:
# background's label is always 0
foreground = labels != 0
labels, volumes = labels[foreground], volumes[foreground]

return label_map, labels, volumes


Expand Down
Loading

0 comments on commit 85f70e8

Please sign in to comment.