Package kenozooid :: Module calc

Source Code for Module kenozooid.calc

  1  # 
  2  # Kenozooid - dive planning and analysis toolbox. 
  3  # 
  4  # Copyright (C) 2009-2019 by Artur Wroblewski <wrobell@riseup.net> 
  5  # 
  6  # This program is free software: you can redistribute it and/or modify 
  7  # it under the terms of the GNU General Public License as published by 
  8  # the Free Software Foundation, either version 3 of the License, or 
  9  # (at your option) any later version. 
 10  # 
 11  # This program is distributed in the hope that it will be useful, 
 12  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 13  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 14  # GNU General Public License for more details. 
 15  # 
 16  # You should have received a copy of the GNU General Public License 
 17  # along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 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 # absolute pressure 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
67 -def ead(depth, ean):
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 # vim: sw=4:et:ai 122