Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pytests for featurize_directory and featurize_files #191

Merged
merged 8 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build_and_test_mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
- name: Install Conda Dependencies
run: |
conda install mamba
mamba install compilers pytest --file ${{github.workspace}}/ci-utils/envs/conda_cpp.txt --file ${{github.workspace}}/ci-utils/envs/conda_py.txt
mamba install compilers pytest bfio --file ${{github.workspace}}/ci-utils/envs/conda_cpp.txt --file ${{github.workspace}}/ci-utils/envs/conda_py.txt

- name: Install Nyxus
working-directory: ${{github.workspace}}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_and_test_ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
- name: Install Conda Dependencies
run: |
conda install mamba
mamba install compilers=1.1.1 pytest --file ${{github.workspace}}/ci-utils/envs/conda_cpp.txt --file ${{github.workspace}}/ci-utils/envs/conda_py.txt
mamba install compilers=1.1.1 pytest bfio --file ${{github.workspace}}/ci-utils/envs/conda_cpp.txt --file ${{github.workspace}}/ci-utils/envs/conda_py.txt

- name: Install Nyxus
working-directory: ${{github.workspace}}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_and_test_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
working-directory: ${{github.workspace}}
run: |
conda install mamba
mamba install pytest --file ./ci-utils/envs/conda_cpp.txt --file ./ci-utils/envs/conda_py.txt
mamba install pytest bfio --file ./ci-utils/envs/conda_cpp.txt --file ./ci-utils/envs/conda_py.txt

- name: Install Nyxus
working-directory: ${{github.workspace}}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
CIBW_REPAIR_WHEEL_COMMAND_MACOS: DYLD_LIBRARY_PATH=$REPAIR_LIBRARY_PATH delocate-listdeps {wheel} && DYLD_LIBRARY_PATH=$REPAIR_LIBRARY_PATH delocate-wheel --require-archs {delocate_archs} -w {dest_dir} {wheel}
CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: "delvewheel repair -w {dest_dir} {wheel}"
CIBW_ARCHS: ${{ matrix.cibw_archs }}
CIBW_TEST_REQUIRES: numpy pandas pytest pyarrow
CIBW_TEST_REQUIRES: numpy pandas pyarrow pytest bfio
CIBW_TEST_COMMAND: pytest {project}/tests/python

- name: Upload Artifact
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
CIBW_REPAIR_WHEEL_COMMAND_MACOS: DYLD_LIBRARY_PATH=$REPAIR_LIBRARY_PATH delocate-listdeps {wheel} && DYLD_LIBRARY_PATH=$REPAIR_LIBRARY_PATH delocate-wheel --require-archs {delocate_archs} -w {dest_dir} {wheel}
CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: "delvewheel repair -w {dest_dir} {wheel}"
CIBW_ARCHS: ${{ matrix.cibw_archs }}
CIBW_TEST_REQUIRES: numpy pandas pytest pyarrow
CIBW_TEST_REQUIRES: numpy pandas pyarrow pytest bfio
CIBW_TEST_COMMAND: pytest {project}/tests/python

- name: Install Dependencies
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,5 @@ def build_extension(self, ext):
zip_safe=False,
python_requires=">=3.8",
install_requires=["numpy", "pandas"],
tests_require = ["pyarrow"]
tests_require = ["pyarrow", "bfio"]
)
Binary file added tests/python/data/int/p0_y1_r1_c0.ome.tif
Binary file not shown.
Binary file added tests/python/data/int/p0_y1_r1_c1.ome.tif
Binary file not shown.
Binary file added tests/python/data/seg/p0_y1_r1_c0.ome.tif
Binary file not shown.
Binary file added tests/python/data/seg/p0_y1_r1_c1.ome.tif
Binary file not shown.
75 changes: 74 additions & 1 deletion tests/python/test_nyxus.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
import pandas as pd
import math
from pathlib import Path
import pathlib
from test_data import intens, seg
import os
import shutil
import time

from test_tissuenet_data import tissuenet_int, tissuenet_seg

class TestImport():
def test_import(self):
assert nyxus.__name__ == "nyxus"
Expand All @@ -34,8 +37,77 @@ def teardown_class(cls):
os.remove('NyxusFeatures.parquet')
except:
print('No .parquet file to delete')

def test_featurize_all(self):
path = str(pathlib.Path(__file__).parent.resolve())

data_path = path + '/data/'

nyx = nyxus.Nyxus (["*ALL*"])
assert nyx is not None

directory_features = nyx.featurize_directory(data_path + 'int/', data_path + 'seg/')
directory_features.replace([np.inf, -np.inf, np.nan], 0, inplace=True)

files_features = nyx.featurize_files(
[data_path + 'int/p0_y1_r1_c0.ome.tif', data_path + 'int/p0_y1_r1_c1.ome.tif'],
[data_path + 'seg/p0_y1_r1_c0.ome.tif', data_path + 'seg/p0_y1_r1_c1.ome.tif'],
single_roi=False,
)

files_features.replace([np.inf, -np.inf, np.nan], 0, inplace=True)

directory_columns = directory_features.columns
files_columns = files_features.columns

assert len(directory_columns) == len(files_columns)

files_not_equal = []

for col in directory_columns:
directory_list = directory_features[col].tolist()
files_list = files_features[col].tolist()

for directory_val, files_val in zip(directory_list, files_list):
if not directory_val == pytest.approx(files_val, rel=1e-5, abs=1e-5):
files_not_equal.append(col)
break

assert len(files_not_equal) == 0

def test_featurize_montage(self):

path = str(pathlib.Path(__file__).parent.resolve())

data_path = path + '/data/'

nyx = nyxus.Nyxus (["*ALL_INTENSITY*"])
assert nyx is not None

montage_features = nyx.featurize(tissuenet_int, tissuenet_seg, intensity_names=['p0_y1_r1_c0.ome.tif', 'p0_y1_r1_c1.ome.tif'], label_names=['p0_y1_r1_c0.ome.tif', 'p0_y1_r1_c1.ome.tif'])
directory_features = nyx.featurize_directory(data_path + 'int/', data_path + 'seg/')

montage_features.replace([np.inf, -np.inf, np.nan], 0, inplace=True)
directory_features.replace([np.inf, -np.inf, np.nan], 0, inplace=True)

directory_columns = directory_features.columns
montage_columns = montage_features.columns

assert len(directory_columns) == len(montage_columns)

montage_not_equal = []

for col in directory_columns:
directory_list = directory_features[col].tolist()
montage_list = montage_features[col].tolist()

for directory_val, montage_val in zip(directory_list, montage_list):
if not directory_val == pytest.approx(montage_val, rel=1e-4, abs=1e-4): # higher error tolerance for COVERED_IMAGE_INTENSITY_RANGE
montage_not_equal.append(col)
break

assert len(montage_not_equal) == 0


def test_gabor_gpu(self):
# cpu gabor
cpu_nyx = nyxus.Nyxus(["GABOR"])
Expand Down Expand Up @@ -562,3 +634,4 @@ def test_arrow_ipc_path(self):
arrow_path = nyx.featurize(intens, seg, output_type="arrowipc")

assert arrow_path == 'NyxusFeatures.arrow'

20 changes: 20 additions & 0 deletions tests/python/test_tissuenet_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import numpy as np
from bfio import BioReader
from pathlib import Path

path = str(Path(__file__).parent.resolve())

with BioReader(path + '/data/int/p0_y1_r1_c0.ome.tif') as br:
int_p0_y1_r1_c0 = br.read()

with BioReader(path + '/data/int/p0_y1_r1_c1.ome.tif') as br:
int_p0_y1_r1_c1 = br.read()

with BioReader(path + '/data/seg/p0_y1_r1_c0.ome.tif') as br:
seg_p0_y1_r1_c0 = br.read()

with BioReader(path + '/data/seg/p0_y1_r1_c1.ome.tif') as br:
seg_p0_y1_r1_c1 = br.read()

tissuenet_int = np.array([int_p0_y1_r1_c0, int_p0_y1_r1_c1])
tissuenet_seg = np.array([seg_p0_y1_r1_c0, seg_p0_y1_r1_c1])