-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
205 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ name: gpu-tests | |
on: | ||
pull_request: | ||
push: | ||
branches: main | ||
branches: [dev, main] | ||
|
||
jobs: | ||
test-linux: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
icon_registration>=1.1.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import itk | ||
import numpy as np | ||
import unittest | ||
import icon_registration.test_utils | ||
|
||
import subprocess | ||
import os | ||
import torch | ||
|
||
|
||
class TestCommandInterface(unittest.TestCase): | ||
def __init__(self, methodName: str = "runTest") -> None: | ||
super().__init__(methodName) | ||
icon_registration.test_utils.download_test_data() | ||
self.test_data_dir = icon_registration.test_utils.TEST_DATA_DIR | ||
self.test_temp_dir = f"{self.test_data_dir}/temp" | ||
os.makedirs(self.test_temp_dir, exist_ok=True) | ||
self.device = torch.cuda.current_device() | ||
|
||
def test_register_unigradicon_inference(self): | ||
subprocess.run([ | ||
"unigradicon-register", | ||
"--fixed", f"{self.test_data_dir}/lung_test_data/copd1_highres_EXP_STD_COPD_img.nii.gz", | ||
"--fixed_modality", "ct", | ||
"--fixed_segmentation", f"{self.test_data_dir}/lung_test_data/copd1_highres_EXP_STD_COPD_label.nii.gz", | ||
"--moving", f"{self.test_data_dir}/lung_test_data/copd1_highres_INSP_STD_COPD_img.nii.gz", | ||
"--moving_modality", "ct", | ||
"--moving_segmentation", f"{self.test_data_dir}/lung_test_data/copd1_highres_INSP_STD_COPD_label.nii.gz", | ||
"--transform_out", f"{self.test_temp_dir}/transform.hdf5", | ||
"--io_iterations", "None" | ||
]) | ||
|
||
# load transform | ||
phi_AB = itk.transformread(f"{self.test_temp_dir}/transform.hdf5")[0] | ||
|
||
assert isinstance(phi_AB, itk.CompositeTransform) | ||
|
||
insp_points = icon_registration.test_utils.read_copd_pointset( | ||
str( | ||
icon_registration.test_utils.TEST_DATA_DIR | ||
/ "lung_test_data/copd1_300_iBH_xyz_r1.txt" | ||
) | ||
) | ||
exp_points = icon_registration.test_utils.read_copd_pointset( | ||
str( | ||
icon_registration.test_utils.TEST_DATA_DIR | ||
/ "lung_test_data/copd1_300_eBH_xyz_r1.txt" | ||
) | ||
) | ||
|
||
dists = [] | ||
for i in range(len(insp_points)): | ||
px, py = ( | ||
insp_points[i], | ||
np.array(phi_AB.TransformPoint(tuple(exp_points[i]))), | ||
) | ||
dists.append(np.sqrt(np.sum((px - py) ** 2))) | ||
print(np.mean(dists)) | ||
self.assertLess(np.mean(dists), 2.1) | ||
|
||
# remove temp file | ||
os.remove(f"{self.test_temp_dir}/transform.hdf5") | ||
|
||
def test_register_multigradicon_inference(self): | ||
subprocess.run([ | ||
"unigradicon-register", | ||
"--fixed", f"{self.test_data_dir}/lung_test_data/copd1_highres_EXP_STD_COPD_img.nii.gz", | ||
"--fixed_modality", "ct", | ||
"--fixed_segmentation", f"{self.test_data_dir}/lung_test_data/copd1_highres_EXP_STD_COPD_label.nii.gz", | ||
"--moving", f"{self.test_data_dir}/lung_test_data/copd1_highres_INSP_STD_COPD_img.nii.gz", | ||
"--moving_modality", "ct", | ||
"--moving_segmentation", f"{self.test_data_dir}/lung_test_data/copd1_highres_INSP_STD_COPD_label.nii.gz", | ||
"--transform_out", f"{self.test_temp_dir}/transform.hdf5", | ||
"--io_iterations", "None", | ||
"--model", "multigradicon" | ||
]) | ||
|
||
# load transform | ||
phi_AB = itk.transformread(f"{self.test_temp_dir}/transform.hdf5")[0] | ||
|
||
assert isinstance(phi_AB, itk.CompositeTransform) | ||
|
||
insp_points = icon_registration.test_utils.read_copd_pointset( | ||
str( | ||
icon_registration.test_utils.TEST_DATA_DIR | ||
/ "lung_test_data/copd1_300_iBH_xyz_r1.txt" | ||
) | ||
) | ||
exp_points = icon_registration.test_utils.read_copd_pointset( | ||
str( | ||
icon_registration.test_utils.TEST_DATA_DIR | ||
/ "lung_test_data/copd1_300_eBH_xyz_r1.txt" | ||
) | ||
) | ||
|
||
dists = [] | ||
for i in range(len(insp_points)): | ||
px, py = ( | ||
insp_points[i], | ||
np.array(phi_AB.TransformPoint(tuple(exp_points[i]))), | ||
) | ||
dists.append(np.sqrt(np.sum((px - py) ** 2))) | ||
print(np.mean(dists)) | ||
self.assertLess(np.mean(dists), 3.8) | ||
|
||
# remove temp file | ||
os.remove(f"{self.test_temp_dir}/transform.hdf5") | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import unittest | ||
|
||
|
||
class TestImports(unittest.TestCase): | ||
|
||
def test_requirements_match_cfg(self): | ||
from inspect import getsourcefile | ||
import os.path as path, sys | ||
import configparser | ||
|
||
current_dir = path.dirname(path.abspath(getsourcefile(lambda: 0))) | ||
parent_dir = current_dir[: current_dir.rfind(path.sep)] | ||
|
||
with open(parent_dir + "/requirements.txt") as f: | ||
requirements_txt = "\n" + f.read() | ||
requirements_cfg = configparser.ConfigParser() | ||
requirements_cfg.read(parent_dir + "/setup.cfg") | ||
requirements_cfg = requirements_cfg["options"]["install_requires"] | ||
self.assertEqual(requirements_txt, requirements_cfg) |