Commit 9c875f8e authored by Gabriel Couture's avatar Gabriel Couture

Adding dosctring in the project

parent 232ed683
Pipeline #178 passed with stage
in 4 seconds
......@@ -9,10 +9,26 @@ class PrescriptionDoseIsMissingException(Exception):
def is_dvh_has_a_prescription_dose(dvh: DVH) -> bool:
"""Check if DVH has a prescription dose.
Args:
dvh: An DVH object.
Returns:
True if dvh has a prescription dose, else False.
"""
return False if dvh.get_prescription_dose() is None else True
def convert_dvh_doses_to_relative(dvh: DVH) -> DVH:
"""Convert a DVH with absolute doses to a DVH with relative doses.
Args:
dvh: An DVH object.
Returns:
A DVH object with relative doses.
"""
if dvh.get_dose_unit() == '%':
return dvh
......@@ -28,6 +44,14 @@ def convert_dvh_doses_to_relative(dvh: DVH) -> DVH:
def convert_dvh_doses_to_absolute(dvh: DVH) -> DVH:
"""Convert a DVH with relative doses to a DVH with absolute doses.
Args:
dvh: An DVH object.
Returns:
A DVH object with absolute doses.
"""
if dvh.get_dose_unit() == 'GY':
return dvh
......@@ -40,5 +64,3 @@ def convert_dvh_doses_to_absolute(dvh: DVH) -> DVH:
dvh.dose_unit = 'GY'
return dvh
......@@ -4,8 +4,7 @@ from typing import List
class DVH:
"""
This class is the representation of a DVH.
"""Object representing a DVH.
"""
VALID_DOSE_UNITS = ['GY', '%']
VALID_VOLUME_UNITS = ['CM3', '%']
......@@ -16,6 +15,17 @@ class DVH:
volume_unit: str,
structure_name: str = None,
prescription_dose: float = None):
"""Constructor of a DVH object.
Args:
doses: Doses list.
volumes: Volumes list.
dose_unit: Dose units, only 'GY' and '%' or supported.
volume_unit: Volume units, only 'CM3' and '%' or supported.
structure_name: The Structure name (i.e. prostate).
prescription_dose: The prescription doses, which is needed for the
conversion from absolute to relative dose values.
"""
self.doses = doses
self.volumes = volumes
......
......@@ -8,27 +8,28 @@ from dvh import conversion
from dvh.dvh import DVH
ABSOLUTE_DOSE_UNIT = 'GY'
RELATIVE_DOSE_UNIT = '%'
class TestConversion(unittest.TestCase):
ABSOLUTE_DOSE_UNIT = 'GY'
RELATIVE_DOSE_UNIT = '%'
A_PRESCRIPTION_DOSE = 15
AN_ABSOLUTE_DOSE_ARRAY = list(range(0, 16))
A_RELATIVE_DOSE_ARRAY = [dose / A_PRESCRIPTION_DOSE for dose in AN_ABSOLUTE_DOSE_ARRAY]
A_PRESCRIPTION_DOSE = 15
AN_ABSOLUTE_DOSE_ARRAY = list(range(0, 16))
A_RELATIVE_DOSE_ARRAY = [dose / 15 for dose in range(0, 16)]
class TestConversion(unittest.TestCase):
def setUp(self) -> None:
self.a_dvh_with_absolute_doses = self._setup_dvh_with_absolute_doses()
self.a_dvh_with_relative_doses = self._setup_dvh_with_relative_doses()
def test_givenADVHWithAbsoluteDosesAndPrescriptionDose_whenConvertingDVHDoseToRelative_thenResultIsADVHWithRelativeDoses(self):
self.a_dvh_with_absolute_doses.get_prescription_dose.return_value = TestConversion.A_PRESCRIPTION_DOSE
self.a_dvh_with_absolute_doses.get_prescription_dose.return_value = A_PRESCRIPTION_DOSE
result = conversion.convert_dvh_doses_to_relative(self.a_dvh_with_absolute_doses)
self.assertEqual(result.dose_unit, TestConversion.RELATIVE_DOSE_UNIT)
self.assertEqual(result.doses, TestConversion.A_RELATIVE_DOSE_ARRAY)
self.assertEqual(result.dose_unit, RELATIVE_DOSE_UNIT)
self.assertEqual(result.doses, A_RELATIVE_DOSE_ARRAY)
def test_givenADVHWithAbsoluteDosesAndNoPrescriptionDose_whenConvertingDVHDoseToRelative_thenRaisePrescriptionDoseIsMissingException(self):
self.assertRaises(
......@@ -39,16 +40,16 @@ class TestConversion(unittest.TestCase):
def test_givenADVHWithRelativeDoses_whenConvertingDVHDoseToRelative_thenResultHasTheSameDosesAndThePrescriptionDoseWasNeverUsed(self):
result = conversion.convert_dvh_doses_to_relative(self.a_dvh_with_relative_doses)
self.assertEqual(result.doses, TestConversion.A_RELATIVE_DOSE_ARRAY)
self.assertEqual(result.doses, A_RELATIVE_DOSE_ARRAY)
self.a_dvh_with_relative_doses.get_prescription_dose.assert_not_called()
def test_givenADVHWithRelativeDosesAndPrescriptionDose_whenConvertingDVHDoseToAbsolute_thenResultIsADVHWithAbsoluteDoses(self):
self.a_dvh_with_relative_doses.get_prescription_dose.return_value = TestConversion.A_PRESCRIPTION_DOSE
self.a_dvh_with_relative_doses.get_prescription_dose.return_value = A_PRESCRIPTION_DOSE
result = conversion.convert_dvh_doses_to_absolute(self.a_dvh_with_relative_doses)
self.assertEqual(result.dose_unit, TestConversion.ABSOLUTE_DOSE_UNIT)
self.assertEqual(result.doses, TestConversion.AN_ABSOLUTE_DOSE_ARRAY)
self.assertEqual(result.dose_unit, ABSOLUTE_DOSE_UNIT)
self.assertEqual(result.doses, AN_ABSOLUTE_DOSE_ARRAY)
def test_givenADVHWithRelativeDosesAndNoPrescriptionDose_whenConvertingDVHDoseToAbsolute_thenRaisePrescriptionDoseIsMissingException(self):
self.assertRaises(
......@@ -67,23 +68,23 @@ class TestConversion(unittest.TestCase):
def _setup_dvh_with_absolute_doses(self) -> DVH:
dvh = Mock()
dvh.doses = TestConversion.AN_ABSOLUTE_DOSE_ARRAY
dvh.dose_unit = TestConversion.ABSOLUTE_DOSE_UNIT
dvh.doses = AN_ABSOLUTE_DOSE_ARRAY
dvh.dose_unit = ABSOLUTE_DOSE_UNIT
dvh.get_prescription_dose.return_value = None
dvh.get_dose_unit.return_value = TestConversion.ABSOLUTE_DOSE_UNIT
dvh.get_doses.return_value = TestConversion.AN_ABSOLUTE_DOSE_ARRAY
dvh.get_dose_unit.return_value = ABSOLUTE_DOSE_UNIT
dvh.get_doses.return_value = AN_ABSOLUTE_DOSE_ARRAY
return dvh
def _setup_dvh_with_relative_doses(self) -> DVH:
dvh = Mock()
dvh.doses = TestConversion.A_RELATIVE_DOSE_ARRAY
dvh.dose_unit = TestConversion.RELATIVE_DOSE_UNIT
dvh.doses = A_RELATIVE_DOSE_ARRAY
dvh.dose_unit = RELATIVE_DOSE_UNIT
dvh.get_prescription_dose.return_value = None
dvh.get_dose_unit.return_value = TestConversion.RELATIVE_DOSE_UNIT
dvh.get_doses.return_value = TestConversion.A_RELATIVE_DOSE_ARRAY
dvh.get_dose_unit.return_value = RELATIVE_DOSE_UNIT
dvh.get_doses.return_value = A_RELATIVE_DOSE_ARRAY
return dvh
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment