Skip to content

Commit

Permalink
Merge branch 'master' of github.com:karanphil/scilpy into b1_correction
Browse files Browse the repository at this point in the history
  • Loading branch information
karanphil committed Feb 7, 2024
2 parents dad628a + d9736d9 commit 627f170
Show file tree
Hide file tree
Showing 13 changed files with 191 additions and 152 deletions.
28 changes: 0 additions & 28 deletions .github/workflows/build.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/freeze_requirements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
freeze_requirements:
runs-on: ubuntu-latest
runs-on: scilus-runners
steps:
-
name: Checkout scilpy
Expand Down
70 changes: 70 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Scilpy test suite

on:
push:
branches:
- master
pull_request_target:
branches:
- master

env:
MPLBACKEND: agg
OPENBLAS_NUM_THREADS: 1

jobs:
test:
runs-on: scilus-runners
steps:
- name: Checkout repository
uses: actions/[email protected]

- name: Fetch python version from repository
id: python-selector
run: echo "python-version=$(cat .python-version)" >> $GITHUB_OUTPUT

- name: Set up Python for Scilpy
uses: actions/[email protected]
with:
python-version: ${{ steps.python-selector.outputs.python-version }}
cache: 'pip'

- name: Install non-python dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
build-essential \
curl \
git \
libblas-dev \
liblapack-dev \
libfreetype6-dev
- name: Install Scilpy
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install -e .
- name: Run tests
run: |
export C_INCLUDE_PATH=$pythonLocation/include/python${{ steps.python-selector.outputs.python-version }}:$C_INCLUDE_PATH
pytest --cov-report term-missing:skip-covered
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
flags: unittests
name: scilpy-unittests-${{ github.run_id }}
verbose: true
directory: .test_reports/
fail_ci_if_error: true
root_dir: $GITHUB_WORKSPACE/scilpy/

- name: Upload test reports and coverage to artifacts
uses: actions/[email protected]
with:
name: test-reports
path: |
.test_reports/*
114 changes: 0 additions & 114 deletions Jenkinsfile

This file was deleted.

1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ include LICENSE
include requirements.txt
include .python-version

recursive-include data/LUT *
recursive-include scilpy *.c
recursive-include scilpy *.cpp
recursive-include scilpy *.pyx
34 changes: 34 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
codecov:
allow_coverage_offsets: True

coverage:
status:
project:
default:
target: 75%
threshold: 2%
branches:
- master
if_ci_failed: error
only_pulls: false
patch:
default:
target: 90%
branches:
- master
if_ci_failed: error
only_pulls: false

component_management:
individual_components:
- component_id: scilpy_scripts
name: Scripts
paths:
- scripts/
- component_id: scilpy_library
name: Library
paths:
- scilpy/

comment:
layout: "condensed_header, diff, components"
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ python-dateutil==2.8.*
pytz==2022.6.*
requests==2.28.*
scikit-learn==1.2.*
scikit-image==0.22.*
scipy==1.9.*
six==1.16.*
spams==2.6.*
Expand Down
32 changes: 32 additions & 0 deletions scilpy/image/tests/test_volume_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
cut_up_cube,
lower_threshold_eq, upper_threshold_eq,
lower_threshold, upper_threshold,
lower_threshold_otsu,
upper_threshold_otsu,
lower_clip, upper_clip,
absolute_value,
around, ceil, floor,
Expand Down Expand Up @@ -299,6 +301,36 @@ def test_upper_threshold():
assert_array_equal(output_data, expected_output)


def test_lower_threshold_otsu():
# Create a sample nib.Nifti1Image object
img_data = np.array([0, 1, 1, 50, 60, 60]).astype(float)
affine = np.eye(4)
img = nib.Nifti1Image(img_data, affine)

# Otsu is expected to separate foreground and background
expected_output = np.array([0, 0, 0, 1, 1, 1]).astype(float)

output_data = lower_threshold_otsu([img], img)

# compare output and expected arrays
assert_array_equal(output_data, expected_output)


def test_upper_threshold_otsu():
# Create a sample nib.Nifti1Image object
img_data = np.array([0, 1, 1, 50, 60, 60]).astype(float)
affine = np.eye(4)
img = nib.Nifti1Image(img_data, affine)

# Otsu is expected to separate foreground and background
expected_output = np.array([1, 1, 1, 0, 0, 0]).astype(float)

output_data = upper_threshold_otsu([img], img)

# compare output and expected arrays
assert_array_equal(output_data, expected_output)


def test_lower_clip():
img_data = np.array([-1, 0, 1, 2, 3, 4]).astype(float)
affine = np.eye(4)
Expand Down
42 changes: 42 additions & 0 deletions scilpy/image/volume_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from scipy.ndimage import (binary_closing, binary_dilation,
binary_erosion, binary_opening,
gaussian_filter)
from skimage.filters import threshold_otsu

from scilpy.utils.util import is_float

Expand All @@ -31,6 +32,8 @@ def get_array_ops():
('upper_threshold', upper_threshold),
('lower_threshold_eq', lower_threshold_eq),
('upper_threshold_eq', upper_threshold_eq),
('lower_threshold_otsu', lower_threshold_otsu),
('upper_threshold_otsu', upper_threshold_otsu),
('lower_clip', lower_clip),
('upper_clip', upper_clip),
('absolute_value', absolute_value),
Expand Down Expand Up @@ -146,6 +149,45 @@ def cut_up_cube(data, blck):
return data


def lower_threshold_otsu(input_list, ref_img):
"""
lower_threshold_otsu: IMG
All values below or equal to the Otsu threshold will be set to zero.
All values above the Otsu threshold will be set to one.
"""
_validate_length(input_list, 1)
_validate_type(input_list[0], nib.Nifti1Image)

output_data = np.zeros(ref_img.header.get_data_shape(), dtype=np.float64)
data = input_list[0].get_fdata(dtype=np.float64)
threshold = threshold_otsu(data)

output_data[data <= threshold] = 0
output_data[data > threshold] = 1

return output_data


def upper_threshold_otsu(input_list, ref_img):
"""
upper_threshold_otsu: IMG
All values below the Otsu threshold will be set to one.
All values above or equal to the Otsu threshold will be set to zero.
Equivalent to lower_threshold_otsu followed by an inversion.
"""
_validate_length(input_list, 1)
_validate_type(input_list[0], nib.Nifti1Image)

output_data = np.zeros(ref_img.header.get_data_shape(), dtype=np.float64)
data = input_list[0].get_fdata(dtype=np.float64)
threshold = threshold_otsu(data)

output_data[data < threshold] = 1
output_data[data >= threshold] = 0

return output_data


def lower_threshold_eq(input_list, ref_img):
"""
lower_threshold_eq: IMG THRESHOLD
Expand Down
4 changes: 3 additions & 1 deletion scripts/scil_tractogram_assign_custom_color.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ def main():
data = np.clip(data, np.quantile(data, 0.05),
np.quantile(data, 0.95))
elif args.use_dpp:
data = np.squeeze(sft.data_per_point[args.use_dpp]._data)
tmp = [np.squeeze(sft.data_per_point[args.use_dpp][s]) for s in
range(len(sft))]
data = np.hstack(tmp)
elif args.load_dps:
data = np.squeeze(load_matrix_in_any_format(args.load_dps))
if len(data) != len(sft):
Expand Down
Loading

0 comments on commit 627f170

Please sign in to comment.