ScubaMath.psm1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285

<#
        .Synopsis
        Math is hard!
 
        .DESCRIPTION
        Functions for planning your dive. Returns exact numbers, so you can do your own rounding, unlike tables,
        which do the rounding for you.
         
        .NOTES
        Yes. You can dive without a computer, even with Nitrox...
         
        .COMPONENT
        Scuba diving
         
        .ROLE
        Gas @ pressure math
         
        .FUNCTIONALITY
        Saftey calculations, and dive planning
#>



#region NITROX


Function Get-NitroxMOD
{
    <#
            .SYNOPSIS
            Gets the maximum operating depth in feet, based on F02, and desired P02
 
            .DESCRIPTION
            Calculations based on the magic circle method
 
            .PARAMETER P02
            Desired partial pressure for your dive. Warmer water, you can max out @ 1.6... colder water, suggest 1.4
 
            .PARAMETER F02
            Oxygen percentage your tank is filled with, in decimal form
 
            .EXAMPLE
            Get-NitroxMOD -P02 1.4 -F02 .36
            Returns the maximum depth for your dive.
 
            .LINK
            Watch the video https://www.youtube.com/watch?v=Ho3erOkNEXQ
 
            .INPUTS
            Double
 
            .OUTPUTS
            PSObject
    #>



    Param
    (
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [Double] $P02 = 1.4,
        
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [Alias('EAN','AirMix')]
        [Double] $F02 = .32
    )
    
    # We need to get our absolute atmospheric pressure, then convert it to depth
    $Atmosphere = $P02 / $F02 - 1
    
    $MOD = $Atmosphere * 33
    
    $EAD = Get-EquivalentAirDepth -Depth $MOD -F02 $F02
    
    $properties = [Ordered] @{

        #'MOD' = '{0:N1}' -f $MOD
        'MOD' = $MOD
        'P02' = $P02
        'F02' = $F02
        'EAD' = $EAD
        'Atmospheric_Pressure' = $Atmosphere
    }
    
    $retVal = New-Object -TypeName PSObject -Property $properties
    
    $retVal
}


Function Get-NitroxF02
{
    <#
            .SYNOPSIS
            Gets the fraction of oxygen, based on p02, and planned depth
 
            .DESCRIPTION
            Calculations based on the magic circle method. This method of finding the best EAN mix, is good for
            planning to dive a destination i.e. wreck dive.
 
            .PARAMETER P02
            Desired partial pressure for your dive. Warmer water, you can max out @ 1.6... colder water, suggest 1.4
 
            .PARAMETER MOD
            Maximum Operating Depth at which you plan to dive.
 
            .EXAMPLE
            Get-NitroxMOD -P02 1.6 -Depth 100
            If you planned to dive 100 ft, and your desired partial pressure is 1.6, this would return the optimal
            F02, to fill your tank with
 
            .LINK
            Watch the video https://www.youtube.com/watch?v=Ho3erOkNEXQ
 
            .INPUTS
            Double
 
            .OUTPUTS
            PSObject
    #>

    
    Param
    (
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [Double] $P02 = 1.4,
        
        [Parameter( Mandatory = $true, 
                    Position = 1,
                    HelpMessage = 'Max depth you plan to dive',
                    ValueFromPipelineByPropertyName = $true
        )] [Double] $MOD
    )
    
    # We need to get our absolute atmospheric pressure from the depth
    $Atmosphere = $MOD / 33 + 1
    
    $F02 = $P02 / $Atmosphere
    
    $EAD = Get-EquivalentAirDepth -Depth $MOD -F02 $F02
    
    $properties = [Ordered] @{

        #'MOD' = '{0:N1}' -f $MOD
        'MOD' = $MOD
        'P02' = $P02
        'F02' = $F02
        'EAD' = $EAD
        'Atmospheric_Pressure' = $Atmosphere
    }
    
    $retVal = New-Object -TypeName PSObject -Property $properties
    
    $retVal
}


Function Get-NitroxP02
{    
        <#
            .SYNOPSIS
            Gets the partial pressure based on depth and gas mix
 
            .DESCRIPTION
            Calculations based on the magic circle method. Use to double check your P02 based on your tank fill,
            and dive plan. Always ensure you'll be safe... check it twice!
 
            .PARAMETER F02
            Oxygen percentage your tank is filled with, in decimal form
 
            .PARAMETER MOD
            Maximum Operating Depth at which you plan to dive.
 
            .EXAMPLE
            Get-NitroxMOD -F02 .40 -Depth 100
            If you planned to dive 100 ft, and your tank is filled with EAN40, this would return the P02 which you
            would experience at the MOD
 
            .LINK
            Watch the video https://www.youtube.com/watch?v=Ho3erOkNEXQ
 
            .INPUTS
            Double
 
            .OUTPUTS
            PSObject
    #>

    
    Param
    (
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [Alias('EAN','AirMix')]
        [Double] $F02 = .32,
        
        [Parameter( Mandatory = $true, 
                    Position = 1,
                    HelpMessage = 'Max depth you plan to dive',
                    ValueFromPipelineByPropertyName = $true
        )] [Double] $MOD
    )
    
    # We need to get our absolute atmospheric pressure from the depth
    $Atmosphere = $MOD / 33 + 1
    
    $P02 = $F02 * $Atmosphere
    
    $EAD = Get-EquivalentAirDepth -Depth $MOD -F02 $F02
    
    $properties = [Ordered] @{

        #'MOD' = '{0:N1}' -f $MOD
        'MOD' = $MOD
        'P02' = $P02
        'F02' = $F02
        'EAD' = $EAD
        'Atmospheric_Pressure' = $Atmosphere
    }
    
    $retVal = New-Object -TypeName PSObject -Property $properties
    
    $retVal
}


Function Script:Get-EquivalentAirDepth
{    
        <#
            .SYNOPSIS
            Helper function. Gets the EAD, based on depth and oxygen levels in your air tank
 
            .DESCRIPTION
            Calculations in feet. Used to plan your decompression stops based on your dive plan.
            Always ensure you'll be safe... check it twice!
 
            .PARAMETER F02
            Oxygen percentage your tank is filled with, in decimal form
 
            .PARAMETER Depth
            Maximum depth at which you plan to dive.
 
            .EXAMPLE
            Get-NitroxMOD -F02 .40 -Depth 100
            If you planned to dive 100 ft, and your tank is filled with EAN40, this would return the P02 which you
            would experience at the MOD
 
            .LINK
            https://en.wikipedia.org/wiki/Equivalent_air_depth
 
            .INPUTS
            Double
 
            .OUTPUTS
            Double
    #>

    
    Param
    (
        [Alias('EAN','AirMix')]
        [Double] $F02 = .32,
        
        [Alias('MOD')]
        [Parameter( Mandatory = $true, 
                    Position = 1,
                    HelpMessage = 'Max depth you plan to dive',
                    ValueFromPipelineByPropertyName = $true
        )] [Double] $Depth
    )
    
    # Get the fraction of nitrogen (N2)
    $FN2 = 1 - $F02
    
    # First Atmosphere, in feet
    [Int] $A1 = 33
    
    # Ambient level of nitrogen in air
    [Double] $N2 = .791
    
    # Calc it up
    [Double] $EAD = ($Depth + $A1) * $FN2 / $N2 - $A1
    
    $EAD
}


#endregion