1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 """
21 Functions to calculate
22
23 - partial pressure
24 - equivalent air depth
25 - maximum operating depth
26 - respiratory minute volume
27 """
28
29 import functools
30
31 -def ppg(depth, ean, gas):
32 """
33 Calculate partial pressure of a gas.
34
35 :Parameters:
36 depth
37 Depth in meters.
38 ean
39 O2 percentage, i.e. 32, 34, 27.5.
40 gas
41 Gas name - O2 (oxygen) or N2 (nitrogen).
42 """
43 if gas not in ('O2', 'N2'):
44 raise ValueError('Invalid gas name: ' + gas)
45
46 p = 1.0 + depth / 10.0
47 fg = ean / 100.0 if gas == 'O2' else 1.0 - ean / 100.0
48
49 return p * fg
50
51
52 -def mod(ean, pp=1.4):
53 """
54 Calculate maximum operating depth for a gas and partial pressure.
55
56 :Parameters:
57 ean
58 O2 percentage, i.e. 32, 34, 27.5.
59 pp
60 Partial pressure value.
61 """
62 fg = ean / 100.0
63 p = pp / fg
64 return (p - 1) * 10
65
66
68 """
69 Calculate equivalent air depth for depth and a gas.
70
71 :Parameters:
72 depth
73 Depth in meters.
74 ean
75 O2 percentage, i.e. 32, 34, 27.5.
76 """
77 fN = (100.0 - ean) / 100.0
78 return (depth + 10.0) * fN / 0.79 - 10.0
79
80
81 -def rmv(tank, pressure, depth, duration):
82 """
83 Calculate respiratory minute volume (RMV).
84
85 :Parameters:
86 tank
87 Tank size in liters, i.e. 12l, 15l.
88 pressure
89 Difference in pressure of the tank at the end and start of a dive,
90 i.e. 170 (220 at start, 50 at end of a dive).
91 depth
92 The average depth of a dive.
93 duration
94 Duration of a dive in minutes.
95 """
96 return tank * pressure / (depth / 10.0 + 1) / duration
97
98
99 pp_n2 = functools.partial(ppg, gas='N2')
100 pp_n2.__doc__ = """
101 Calculate partial pressure of nitrogen.
102
103 :Parameters:
104 depth
105 Depth in meters.
106 ean
107 O2 percentage, i.e. 32, 34, 27.5.
108 """
109
110 pp_o2 = functools.partial(ppg, gas='O2')
111 pp_o2.__doc__ = """
112 Calculate partial pressure of oxygen.
113
114 :Parameters:
115 depth
116 Depth in meters.
117 ean
118 O2 percentage, i.e. 32, 34, 27.5.
119 """
120
121
122