-
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
8 changed files
with
205 additions
and
7 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
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,5 @@ | ||
keV omega | ||
30 10000 | ||
31 15000 | ||
32 20000 | ||
33 -1 |
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 @@ | ||
import numpy as np |
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,43 @@ | ||
import os | ||
import pytest | ||
import numpy as np | ||
from crip.physics import * | ||
from crip.utils import CripException | ||
|
||
|
||
def test_getCommonDensity(): | ||
assert getCommonDensity('H2O') == 1.0 | ||
assert getCommonDensity('Water') == 1.0 | ||
|
||
with pytest.raises(CripException): | ||
getCommonDensity('h2o') | ||
|
||
|
||
class Test_Spectrum: | ||
|
||
def test_init(self): | ||
s = Spectrum(omega=[0, 10, 20, 0, *[0] * (151 - 4)]) | ||
assert s.omega[1] == 10 | ||
assert s.omega[2] == 20 | ||
assert s.omega[3] == 0 | ||
assert s.omega[4:].sum() == 0 | ||
assert s.sumOmega == 30 | ||
|
||
def test_isMonochromatic(self): | ||
omega = [0.0] * 151 | ||
omega[50] = 1.0 | ||
is_mono, energy = Spectrum(omega).isMonochromatic() | ||
assert is_mono == True | ||
assert energy == 50 | ||
|
||
def test_fromText(self): | ||
spec = Spectrum.fromText('50 1\n51 2\n52 3\n53 4\n54 5\n55 -1\n') | ||
assert list(spec.omega[50:56]) == [1, 2, 3, 4, 5, 0] | ||
|
||
def test_fromFile(self): | ||
spec = Spectrum.fromFile(os.path.join(os.path.dirname(__file__), '_asset/spectrum.txt')) | ||
assert list(spec.omega[30:34]) == [10000, 15000, 20000, 0] | ||
|
||
def test_monochromatic(self): | ||
spec = Spectrum.monochromatic(100) | ||
assert [spec.omega[100], spec.omega[101]] == [10**5, 0] |
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,43 @@ | ||
import pytest | ||
import numpy as np | ||
from crip.postprocess import * | ||
|
||
|
||
def test_fovCropRadius(): | ||
assert fovCropRadius(1000, 1000, 1000, 1) == 447 | ||
|
||
|
||
class test_fovCrop(): | ||
twoD = np.ones((16, 16)) | ||
threeD = np.ones((2, 16, 16)) | ||
|
||
def test_twoD(self): | ||
cropped = fovCrop(self.twoD, radius=8) | ||
assert cropped[0, 0] == 0 | ||
assert cropped[8, 8] == 1 | ||
|
||
def test_threeD(self): | ||
cropped = fovCrop(self.threeD, radius=8, fill=10) | ||
assert np.all(cropped[:, 0, 0] == 10) | ||
assert np.all(cropped[:, 8, 8] == 1) | ||
|
||
|
||
def test_muToHU(): | ||
image = np.array([[1, 2], [3, 4]]) | ||
assert np.allclose(muToHU(image, 1), [[0, 1000], [2000, 3000]]) | ||
|
||
|
||
def test_huToMu(): | ||
image = np.array([[0, 1000], [2000, 3000]]) | ||
assert np.allclose(huToMu(image, 1), [[1, 2], [3, 4]]) | ||
|
||
|
||
def test_huNoRescale(): | ||
image = np.array([[-1000, 0], [1000, 2000]]) | ||
assert np.allclose(huNoRescale(image), [[0, 1000], [2000, 3000]]) | ||
|
||
|
||
def test_postlogsToRaws(): | ||
postlogs = np.array([[0, 1]]) | ||
flat = 1000 | ||
assert np.allclose(postlogsToRaws(postlogs, flat), [[flat, flat * np.exp(-1)]]) |
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,96 @@ | ||
import pytest | ||
import numpy as np | ||
from crip.shared import * | ||
|
||
|
||
class Test_rotate(): | ||
twoD = np.array([[1, 2], [3, 4]]) | ||
threeD = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]) | ||
|
||
def test_twoD(self): | ||
img = self.twoD | ||
assert np.array_equal(rotate(img, 90), np.array([[3, 1], [4, 2]])) | ||
assert np.array_equal(rotate(img, 180), np.array([[4, 3], [2, 1]])) | ||
assert np.array_equal(rotate(img, 270), np.array([[2, 4], [1, 3]])) | ||
assert np.array_equal(rotate(img, 360), img) | ||
assert np.array_equal(rotate(img, 0), img) | ||
|
||
with pytest.raises(CripException): | ||
rotate(img, 45) | ||
|
||
def test_threeD(self): | ||
img = self.threeD | ||
assert np.array_equal(rotate(img, 90), np.array([[[3, 1], [4, 2]], [[7, 5], [8, 6]]])) | ||
assert np.array_equal(rotate(img, 180), np.array([[[4, 3], [2, 1]], [[8, 7], [6, 5]]])) | ||
assert np.array_equal(rotate(img, 270), np.array([[[2, 4], [1, 3]], [[6, 8], [5, 7]]])) | ||
assert np.array_equal(rotate(img, 360), img) | ||
assert np.array_equal(rotate(img, 0), img) | ||
|
||
with pytest.raises(CripException): | ||
rotate(img, 45) | ||
|
||
|
||
class Test_verticalFlip(): | ||
twoD = np.array([[1, 2], [3, 4]]) | ||
threeD = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]) | ||
|
||
def test_twoD(self): | ||
img = self.twoD | ||
assert np.array_equal(verticalFlip(img), np.array([[3, 4], [1, 2]])) | ||
|
||
def test_threeD(self): | ||
img = self.threeD | ||
assert np.array_equal(verticalFlip(img), np.array([[[3, 4], [1, 2]], [[7, 8], [5, 6]]])) | ||
|
||
|
||
class Test_horizontalFlip(): | ||
twoD = np.array([[1, 2], [3, 4]]) | ||
threeD = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]) | ||
|
||
def test_twoD(self): | ||
img = self.twoD | ||
assert np.array_equal(horizontalFlip(img), np.array([[2, 1], [4, 3]])) | ||
|
||
def test_threeD(self): | ||
img = self.threeD | ||
assert np.array_equal(horizontalFlip(img), np.array([[[2, 1], [4, 3]], [[6, 5], [8, 7]]])) | ||
|
||
|
||
class Test_stackFlip(): | ||
twoD = np.array([[1, 2], [3, 4]]) | ||
threeD = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]) | ||
|
||
def test_twoD(self): | ||
img = self.twoD | ||
with pytest.raises(CripException): | ||
stackFlip(img) | ||
|
||
def test_threeD(self): | ||
img = self.threeD | ||
assert np.array_equal(stackFlip(img), np.array([[[5, 6], [7, 8]], [[1, 2], [3, 4]]])) | ||
|
||
|
||
class Test_resizeTo(): | ||
pass | ||
|
||
|
||
class Test_resizeBy(): | ||
pass | ||
|
||
|
||
class Test_resize3D(): | ||
pass | ||
|
||
|
||
def test_permute(): | ||
top = np.array([[1, 2], [3, 4]]) | ||
bottom = np.array([[5, 6], [7, 8]]) | ||
threeD = np.stack([top, bottom]) | ||
|
||
|
||
def test_fitPolyV2D2(): | ||
pass | ||
|
||
|
||
def test_applyPolyV2D2(): | ||
pass |
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,12 @@ | ||
import pytest | ||
import numpy as np | ||
|
||
from crip.spec import * | ||
|
||
|
||
# def test_decompMaterial(): | ||
# src = Atten([1, 2]) | ||
# base1 = Atten([3, 4]) | ||
# base2 = Atten([5, 6]) | ||
# res = decompMaterial(src, base1, base2, mode='coeff') | ||
# assert np.allclose(res, [0.2, 0.4]) |