Skip to content

Commit

Permalink
Merge pull request #58 from MahdiAll99/dev
Browse files Browse the repository at this point in the history
Refactoring test script and updated requirements
  • Loading branch information
MahdiAll99 committed Apr 6, 2024
2 parents 14b0d61 + 156e6c5 commit b051677
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 52 deletions.
63 changes: 30 additions & 33 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,38 @@ channels:
- conda-forge
- defaults
dependencies:
- matplotlib==3.7.0
- nibabel==3.2.2
- pandas==1.5.3
- pillow==9.2.0
- pydicom=1.2.2
- pywavelets==1.1.1
- scikit-image==0.18.2
- scipy==1.7.0
- setuptools==62.2.0
- tqdm==4.65.0
- matplotlib
- nibabel
- pandas<2.0.0
- pillow
- pydicom
- pywavelets
- scikit-image
- scipy
- setuptools
- tqdm
- pip
- pip:
- numpy==1.22.4
- isort==5.10.1
- ipykernel==6.15.1
- ipywidgets==8.0.1
- jupyter==1.0.0
- networkx==2.8.5
- neuroCombat==0.2.12
- nilearn==0.10.1
- numpyencoder==0.3.0
- protobuf==3.20.*
- pycaret==3.0.4
- ray==2.5.1
- scikit_image==0.18.2
- SimpleITK==2.1.1.2
- scikit_learn==1.2.2
- seaborn==0.13.2
- Sphinx==7.2.6
- numpy
- isort
- ipykernel
- ipywidgets
- jupyter
- networkx
- neuroCombat
- nilearn
- numpyencoder
- protobuf
- pycaret
- ray
- scikit_image
- SimpleITK
- scikit_learn
- seaborn
- Sphinx
- sphinx-carousel==1.2.0
- sphinx-autodoc-typehints==1.19.2
- sphinx-jinja2-compat==0.1.2
- sphinx-jsonschema==1.19.1
- sphinx-rtd-dark-mode==1.2.4
- sphinx-rtd-theme==0.5.2
- wget==3.2
- tabulate==0.9.0
- xgboost==1.7.6
- wget
- tabulate
- xgboost
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ neuroCombat
nibabel
nilearn
numpyencoder
pandas
pandas<2.0.0
Pillow
protobuf
pycaret
Expand Down
103 changes: 85 additions & 18 deletions tests/test_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,105 @@


class TestExtraction:

def _get_phantom(self):
phantom = np.zeros((64,64,64))
phantom[32,32,32] = 255
"""
Test the extraction of morphological and statistical features.
Features are extracted from the IBSI phantom, and values are compared to the IBSI ones.
Phantom and reference values can be found in the IBSI manual: https://arxiv.org/pdf/1612.07003.pdf
"""
def __get_phantom(self):
phantom = np.array(
[[
[1, 1, 1, 1,],
[1, 1, 1, 1,],
[4, 1, 1, 1,],
[4, 4, 1, 1,]],

[[4, 4, 4, 4,],
[4, 1, 1, 1,],
[1, 1, 1, 1,],
[4, 4, 1, 1,]],

[[4, 4, 4, 4,],
[6, 6, 1, 1,],
[6, 3, 9, 1,],
[6, 6, 6, 6,]],

[[1, 1, 1, 1,],
[1, 1, 1, 1,],
[4, 1, 1, 1,],
[4, 1, 1, 1,]],

[[1, 1, 1, 1,],
[1, 1, 1, 1,],
[1, 1, 1, 1,],
[1, 1, 1, 1,]]], dtype=np.float32
)

return phantom

def _get_random_roi(self):
roi = np.zeros((64,64,64))
roi[
np.random.randint(0,64,5),
np.random.randint(0,64,5),
np.random.randint(0,64,5)] = 1
def __get_random_roi(self):
roi = np.array(
[[
[1, 1, 1, 1],
[1, 1, 1, 1],
[1, 0, 1, 1],
[1, 1, 1, 1]],

[[1, 1, 1, 1],
[1, 1, 1, 1],
[1, 1, 1, 1],
[1, 1, 1, 1]],

[[1, 1, 1, 1],
[1, 1, 1, 1],
[1, 1, 0, 1],
[1, 1, 1, 1]],

[[1, 1, 0, 0],
[1, 1, 1, 1],
[1, 1, 1, 1],
[1, 1, 1, 1]],

[[1, 1, 0, 0],
[1, 1, 1, 1],
[1, 1, 1, 1],
[1, 1, 1, 1]]], dtype=np.int16
)

return roi

def test_morph_features(self):
phantom = self._get_phantom()
roi = self._get_random_roi()
phantom = self.__get_phantom()
roi = self.__get_random_roi()
morph = MEDimage.biomarkers.morph.extract_all(
vol=phantom,
mask_int=roi,
mask_morph=roi,
res=[1,1,1],
res=[2, 2, 2],
intensity_type="arbitrary"
)
morph_vol = MEDimage.biomarkers.morph.vol(
vol=phantom,
mask_int=roi,
mask_morph=roi,
res=[1,1,1]
res=[2, 2, 2]
)
surface_area = MEDimage.biomarkers.morph.area(
vol=phantom,
mask_int=roi,
mask_morph=roi,
res=[2, 2, 2]
)
assert morph_vol == morph["Fmorph_vol"]
assert round(morph_vol, 2) == 0.83
assert abs(morph_vol - 556) < 1
assert surface_area == morph["Fmorph_area"]
assert abs(surface_area - 388) < 1

def test_stats_features(self):
phantom = self._get_phantom()
roi = self._get_random_roi()
phantom = self.__get_phantom()
roi = self.__get_random_roi()
vol_int_re = MEDimage.processing.roi_extract(
vol=phantom,
roi=roi
Expand All @@ -58,5 +120,10 @@ def test_stats_features(self):
kurt = MEDimage.biomarkers.stats.kurt(
vol=vol_int_re,
)
skewness = MEDimage.biomarkers.stats.skewness(
vol=vol_int_re,
)
assert kurt == stats["Fstat_kurt"]
assert round(kurt, 2) == -3.0
assert abs(kurt + 0.355) < 0.01
assert skewness == stats["Fstat_skew"]
assert abs(skewness - 1.08) < 0.01

0 comments on commit b051677

Please sign in to comment.