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

T115 include bvf #182

Merged
merged 17 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
test bvf
- test calculation
- test comparison against lit values

ToDo:
- Consider cases with volume_fraction>1
- Add literature values for bvf
  • Loading branch information
jnoelke committed Aug 17, 2022
commit 2c0e891cdd605bf13de4517e49207c603966d20b
58 changes: 56 additions & 2 deletions simpa_tests/automatic_tests/test_calculation_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import unittest
from simpa.utils import SegmentationClasses, MolecularCompositionGenerator
from simpa.utils.libraries.molecule_library import MOLECULE_LIBRARY
from simpa.utils.calculate import calculate_oxygenation
from simpa.utils.calculate import calculate_oxygenation, calculate_bvf
from simpa.utils.calculate import randomize_uniform
from simpa.utils.calculate import calculate_gruneisen_parameter_from_temperature
from simpa.utils.calculate import positive_gauss
Expand Down Expand Up @@ -65,6 +65,56 @@ def test_oxygenation_calculation(self):

assert abs(sO2_value - (oxy / (oxy + deoxy))) < 1e-10

def test_bvf_calculation(self):

# Neither oxy nor deoxy:
mcg = MolecularCompositionGenerator()
mcg.append(MOLECULE_LIBRARY.fat(1.0))
bvf_value = calculate_bvf(mcg.get_molecular_composition(segmentation_type=SegmentationClasses.GENERIC))
assert bvf_value == 0

mcg = MolecularCompositionGenerator()
mcg.append(MOLECULE_LIBRARY.fat(1.0))
mcg.append(MOLECULE_LIBRARY.oxyhemoglobin(0.0))
bvf_value = calculate_bvf(mcg.get_molecular_composition(segmentation_type=SegmentationClasses.GENERIC))
assert bvf_value == 0

# Just oxyhemoglobin CASES:
mcg = MolecularCompositionGenerator()
mcg.append(MOLECULE_LIBRARY.oxyhemoglobin(1.0))
oxy_hemo = mcg.get_molecular_composition(segmentation_type=SegmentationClasses.GENERIC)
bvf_value = calculate_bvf(oxy_hemo)
assert bvf_value == 1.0
mcg.append(MOLECULE_LIBRARY.deoxyhemoglobin(0.0))
oxy_hemo = mcg.get_molecular_composition(segmentation_type=SegmentationClasses.GENERIC)
bvf_value = calculate_bvf(oxy_hemo)
assert bvf_value == 1.0

# Just deoxyhemoglobin CASES:
mcg = MolecularCompositionGenerator()
mcg.append(MOLECULE_LIBRARY.deoxyhemoglobin(1.0))
deoxy_hemo = mcg.get_molecular_composition(segmentation_type=SegmentationClasses.GENERIC)
bvf_value = calculate_bvf(deoxy_hemo)
assert bvf_value == 1.0
mcg.append(MOLECULE_LIBRARY.oxyhemoglobin(0.0))
deoxy_hemo = mcg.get_molecular_composition(segmentation_type=SegmentationClasses.GENERIC)
bvf_value = calculate_bvf(deoxy_hemo)
assert bvf_value == 1.0

# RANDOM CASES
for i in range(100):
oxy = np.random.random()
deoxy = np.random.random()
fat = np.random.random()

sum_oxy_deoxy_fat = oxy + deoxy + fat
mcg = MolecularCompositionGenerator()
mcg.append(MOLECULE_LIBRARY.fat(fat/sum_oxy_deoxy_fat))
mcg.append(MOLECULE_LIBRARY.deoxyhemoglobin(deoxy/sum_oxy_deoxy_fat))
mcg.append(MOLECULE_LIBRARY.oxyhemoglobin(oxy/sum_oxy_deoxy_fat))
bvf_value = calculate_bvf(mcg.get_molecular_composition(segmentation_type=SegmentationClasses.GENERIC))
assert abs(bvf_value - (oxy+deoxy)/sum_oxy_deoxy_fat) < 1e-10

def test_randomize(self):
for _ in range(1000):
lower = np.random.randint(0, 10000000)
Expand All @@ -79,10 +129,14 @@ def test_gruneisen_parameter_calculation(self):
assert isinstance(gruneisen, float), "Gruneisenparameter was not a float"
assert gruneisen > 0, "Gruneisenparameter was negative"
assert gruneisen < 1, "Gruneisenparameter was way too large"

def test_positive_Gauss(self):
for _ in range(1000):
mean = np.random.rand(1)[0]
std = np.random.rand(1)[0]
random_value = positive_gauss(mean, std)
assert random_value > float(0), "positive Gauss value outside the desired range and negative"


# test = TestCalculationUtils()
# test.test_bvf_calculation()
Loading