def test_calculate_pp_h2o_surf_500(self): try: calculate_pp_h2o_surf(500) except ValueError: pass else: self.fail('Should raise ValueError')
def __init__(self): """Init of Model class.""" # initiate class logger self.logger = logging.getLogger( "dipplanner.model.buhlmann.model.Model") self.logger.debug("creating an instance of Model") self.units = 'metric' self.tissues = [] self.ox_tox = OxTox() self.gradient = None self.init_gradient() # store water wapour pp self.pp_h2o = tools.calculate_pp_h2o_surf(settings.SURFACE_TEMP) for _ in range(self.COMPS): self.tissues.append(Compartment()) self.set_time_constants() for comp in self.tissues: comp.set_pp(pp_he=0.0, pp_n2=settings.DEFAULT_AIR_F_INNERT_GAS * (settings.AMBIANT_PRESSURE_SURFACE - self.pp_h2o)) self.metadata = "(none)"
def __init__(self): """Constructor for model class *Keyword arguments:* <none> *Returns:* <nothing> *Raise:* <nothing> """ #initiate class logger self.logger = logging.getLogger( "dipplanner.model.buhlmann.model.Model") self.logger.debug("creating an instance of Model") self.units = 'metric' self.tissues = [] self.ox_tox = OxTox() self.gradient = None self.init_gradient() for _ in range(0, self.COMPS): self.tissues.append(Compartment()) self.set_time_constants() for comp in self.tissues: comp.set_pp(0.0, 0.79 * (settings.AMBIANT_PRESSURE_SURFACE - tools.calculate_pp_h2o_surf(settings.SURFACE_TEMP))) #TODO: Check above : 0.79 or settings.DEFAULT_AIR_PPN2 (tdb) ? self.metadata = "(none)"
def full_desat_time(self): """Evaluate the full desat time. By doing deco at const depth of 0m until all compartement are (nearly) empty. Because of compartments halftimes, full desat is never really achieved. So we need to setup an arbitrary "margin": when sur-saturation falls below this margin, we consider that the compartment is not satured anymore. :returns: full desat time in seconds :rtype: int :raises InfiniteDeco: if the no flight time can not achieve enough decompression to be able to go to give altitude """ # TODO: DONE FOR TESTS HERE: return 0 full_desat_time = 0 margin = 0.01 + calculate_pp_h2o_surf(settings.SURFACE_TEMP) # bigger stop time to speed up calculation # (precision is not necesary here) stop_time = 60 # in second model_copy = copy.deepcopy(self.model) full_desat = False while not full_desat: # loop for "deco" calculation based on the new ceiling model_copy.const_depth(pressure=0.0, seg_time=stop_time, f_he=0.0, f_n2=settings.DEFAULT_AIR_FN2, pp_o2=0.0) full_desat_time += stop_time if full_desat_time > 300000: raise InfiniteDeco("Infinite deco error") full_desat = True for comp in model_copy.tissues: if (comp.pp_n2 > settings.DEFAULT_AIR_FN2 + margin or comp.pp_he > margin): full_desat = False break self.full_desat_time_value = full_desat_time return full_desat_time
def test_calculate_pp_h2o_surf_5(self): self.assertAlmostEqual(calculate_pp_h2o_surf(5), 0.00866264906268, 7, "Wrong ppH2O surf at 5° : %s" % calculate_pp_h2o_surf(5))
def test_calculate_pp_h2o_surf_1(self): self.assertAlmostEqual(calculate_pp_h2o_surf(1), 0.00651325686767, 7, "Wrong ppH2O surf at 1° : %s" % calculate_pp_h2o_surf(1))
def test_calculate_pp_h2o_surf_moins10(self): self.assertAlmostEqual(calculate_pp_h2o_surf(-10.0), 0.00651325686767, 7, "Wrong ppH2O surf at -10° : %s" % calculate_pp_h2o_surf(-10))
def test_calculate_pp_h2o_surf_10(self): self.assertAlmostEqual( calculate_pp_h2o_surf(10), 0.0122107541129, 7, "Wrong ppH2O surf at 10° : %s" % calculate_pp_h2o_surf(10))
def test_calculate_pp_h2o_surf_40(self): self.assertAlmostEqual(calculate_pp_h2o_surf(40), 0.0735844054898, 7, "Wrong ppH2O surf at 40° : %s" % calculate_pp_h2o_surf(40))
def test_calculate_pp_h2o_surf_30(self): self.assertAlmostEqual(calculate_pp_h2o_surf(30), 0.0423167530545, 7, "Wrong ppH2O surf at 30° : %s" % calculate_pp_h2o_surf(30))
def test_calculate_pp_h2o_surf_20(self): self.assertAlmostEqual(calculate_pp_h2o_surf(20), 0.0232957591939, 7, "Wrong ppH2O surf at 20° : %s" % calculate_pp_h2o_surf(20))
def test_calculate_pp_h2o_surf_40(self): self.assertAlmostEqual( calculate_pp_h2o_surf(40), 0.0735844054898, 7, "Wrong ppH2O surf at 40° : %s" % calculate_pp_h2o_surf(40))
def test_calculate_pp_h2o_surf_35(self): self.assertAlmostEqual( calculate_pp_h2o_surf(35), 0.0560901835181, 7, "Wrong ppH2O surf at 35° : %s" % calculate_pp_h2o_surf(35))
def test_calculate_pp_h2o_surf_30(self): self.assertAlmostEqual( calculate_pp_h2o_surf(30), 0.0423167530545, 7, "Wrong ppH2O surf at 30° : %s" % calculate_pp_h2o_surf(30))
def test_calculate_pp_h2o_surf_25(self): self.assertAlmostEqual( calculate_pp_h2o_surf(25), 0.0315792952353, 7, "Wrong ppH2O surf at 25° : %s" % calculate_pp_h2o_surf(25))
def test_calculate_pp_h2o_surf_20(self): self.assertAlmostEqual( calculate_pp_h2o_surf(20), 0.0232957591939, 7, "Wrong ppH2O surf at 20° : %s" % calculate_pp_h2o_surf(20))
def test_calculate_pp_h2o_surf_15(self): self.assertAlmostEqual( calculate_pp_h2o_surf(15), 0.0169758994956, 7, "Wrong ppH2O surf at 15° : %s" % calculate_pp_h2o_surf(15))
def test_calculate_pp_h2o_surf_10(self): self.assertAlmostEqual(calculate_pp_h2o_surf(10), 0.0122107541129, 7, "Wrong ppH2O surf at 10° : %s" % calculate_pp_h2o_surf(10))
def test_calculate_pp_h2o_surf_15(self): self.assertAlmostEqual(calculate_pp_h2o_surf(15), 0.0169758994956, 7, "Wrong ppH2O surf at 15° : %s" % calculate_pp_h2o_surf(15))
def asc_desc(self, start, finish, rate, f_he, f_n2, pp_o2): """Ascend/Descend profile. Calls Compartment.asc_desc to update compartments *Keyword arguments:* :start: (float) -- start pressure of this segment in bar (WARNING: not meter ! it's a pressure) :finish: (float) -- finish pressure of this segment in bar (WARNING: not meter ! it's a pressure) :rate: (float) -- rate of ascent or descent in m/s :f_he: (float) -- Fraction of inert gas Helium in inspired gas mix :f_n2: (float) -- Fraction of inert gas Nitrogen in inspired gas mix :pp_o2: (float) -- For CCR mode, partial pressure of oxygen in bar. If == 0.0, then open circuit *Returns:* <nothing> *Raise:* ModelStateException """ # rem: here we do not bother of PP_H2O like in constant_depth : WHY ? start_ambiant_pressure = start + settings.AMBIANT_PRESSURE_SURFACE finish_ambiant_pressure = finish + settings.AMBIANT_PRESSURE_SURFACE seg_time = abs(float(finish) - float(start)) / rate if pp_o2 > 0.0: # CCR mode # Calculate inert gas partial pressure == pAmb - pO2 - pH2O p_inert_start = start_ambiant_pressure - pp_o2 - \ tools.calculate_pp_h2o_surf(settings.SURFACE_TEMP) p_inert_finish = finish_ambiant_pressure - pp_o2 - \ tools.calculate_pp_h2o_surf(settings.SURFACE_TEMP) # Check that it doesn't go less than zero. # Could be due to shallow deco or starting on high setpoint if p_inert_start < 0.0: p_inert_start = 0.0 if p_inert_finish < 0.0: p_inert_finish = 0.0 # Separate into He and N2 components, checking that we are not # on pure O2 (or we get an arithmetic error) if f_he + f_n2 > 0.0: pp_he_inspired = (p_inert_start * f_he) / (f_he + f_n2) pp_n2_inspired = (p_inert_start * f_n2) / (f_he + f_n2) # calculate rate of change of each inert gas rate_he = ((p_inert_finish * f_he) / (f_he + f_n2) - pp_he_inspired) / (seg_time) rate_n2 = ((p_inert_finish * f_n2) / (f_he + f_n2) - pp_n2_inspired) / (seg_time) else: pp_he_inspired = 0.0 pp_n2_inspired = 0.0 rate_he = 0.0 rate_n2 = 0.0 # update ox_tox, constant pp_o2 # TODO - what if depth is less than pO2 in msw ? self.ox_tox.add_o2(seg_time, pp_o2) else: # OC mode # calculate He and N2 components pp_he_inspired = (start_ambiant_pressure - tools.calculate_pp_h2o_surf( settings.SURFACE_TEMP)) * f_he pp_n2_inspired = (start_ambiant_pressure - tools.calculate_pp_h2o_surf( settings.SURFACE_TEMP)) * f_n2 rate_he = rate * f_he rate_n2 = rate * f_n2 # update ox_tox, use average pp_o2 pp_o2_inspired_avg = ((start_ambiant_pressure - finish_ambiant_pressure) / 2 + finish_ambiant_pressure - tools.calculate_pp_h2o_surf( settings.SURFACE_TEMP)) \ * (1.0 - f_he - f_n2) self.ox_tox.add_o2(seg_time, pp_o2_inspired_avg) for comp in self.tissues: comp.asc_desc(pp_he_inspired, pp_n2_inspired, rate_he, rate_n2, seg_time)
def test_calculate_pp_h2o_surf_25(self): self.assertAlmostEqual(calculate_pp_h2o_surf(25), 0.0315792952353, 7, "Wrong ppH2O surf at 25° : %s" % calculate_pp_h2o_surf(25))
def test_calculate_pp_h2o_surf_1(self): self.assertAlmostEqual( calculate_pp_h2o_surf(1), 0.00651325686767, 7, "Wrong ppH2O surf at 1° : %s" % calculate_pp_h2o_surf(1))
def test_calculate_pp_h2o_surf_35(self): self.assertAlmostEqual(calculate_pp_h2o_surf(35), 0.0560901835181, 7, "Wrong ppH2O surf at 35° : %s" % calculate_pp_h2o_surf(35))
def test_calculate_pp_h2o_surf_moins10(self): self.assertAlmostEqual( calculate_pp_h2o_surf(-10.0), 0.00651325686767, 7, "Wrong ppH2O surf at -10° : %s" % calculate_pp_h2o_surf(-10))
def const_depth(self, pressure, seg_time, f_he, f_n2, pp_o2): """Constant depth profile. Calls Compartment.constDepth for each compartment to update the model. *Keyword arguments:* :pressure: (float)-- pressure of this depth of segment in bar :seg_time: (float) -- Time of segment in seconds :f_he: (float) -- fraction of inert gas Helium in inspired gas mix :f_n2: (float) -- fraction of inert gas Nitrogen in inspired gas mix :pp_o2: (float) -- For CCR mode, partial pressure of oxygen in bar. If == 0.0, then open circuit *Returns:* <nothing> *Raise:* ModelStateException """ ambiant_pressure = pressure + settings.AMBIANT_PRESSURE_SURFACE if pp_o2 > 0.0: # CCR mode #Determine pInert by subtracting absolute oxygen pressure and pH2O #Note that if f_he and f_n2 == 0.0 then need to force pp's to zero if f_he + f_n2 > 0.0: p_inert = ambiant_pressure - pp_o2 - \ tools.calculate_pp_h2o_surf(settings.SURFACE_TEMP) else: p_inert = 0.0 #Verify that pInert is positive. If the setpoint is close to or # less than the depth then there is no inert gas. if p_inert > 0.0: pp_he_inspired = (p_inert * f_he) / (f_he + f_n2) pp_n2_inspired = (p_inert * f_n2) / (f_he + f_n2) else: pp_he_inspired = 0.0 pp_n2_inspired = 0.0 # update OxTox object pp_o2_inspired = pp_o2 #Check that ppO2Inspired is not greater than the depth. #This occurs in shallow deco when the setpoint specified is > depth if pp_o2_inspired <= ambiant_pressure and p_inert > 0.0: # pp_o2 is the setpoint self.ox_tox.add_o2(seg_time, pp_o2) else: # pp_o2 is equal to the depth, also true is there is # no inert gaz self.ox_tox.add_o2(seg_time, ambiant_pressure - tools.calculate_pp_h2o_surf( settings.SURFACE_TEMP)) else: # OC mode pp_he_inspired = (ambiant_pressure - tools.calculate_pp_h2o_surf( settings.SURFACE_TEMP)) * f_he pp_n2_inspired = (ambiant_pressure - tools.calculate_pp_h2o_surf( settings.SURFACE_TEMP)) * f_n2 # update ox_tox if pressure == 0.0: # surface self.ox_tox.remove_o2(seg_time) else: self.ox_tox.add_o2( seg_time, (ambiant_pressure - tools.calculate_pp_h2o_surf(settings.SURFACE_TEMP)) * (1.0 - f_he - f_n2)) if seg_time > 0: for comp in self.tissues: comp.const_depth(pp_he_inspired, pp_n2_inspired, seg_time)
def test_calculate_pp_h2o_surf_5(self): self.assertAlmostEqual( calculate_pp_h2o_surf(5), 0.00866264906268, 7, "Wrong ppH2O surf at 5° : %s" % calculate_pp_h2o_surf(5))