-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindstress.py
359 lines (302 loc) · 10.8 KB
/
windstress.py
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
# -*- coding: utf-8 -*-
#
# windstress.py
#
# purpose:
# author: Filipe P. A. Fernandes
# e-mail: ocefpaf@gmail
# web: http://ocefpaf.github.io/
# created: 21-Aug-2013
# modified: Mon 21 Jul 2014 12:16:28 PM BRT
#
# obs:
#
import numpy as np
# ---- physical constants
g = 9.8 # 9.7803 in COARE FIXME: change to sw.grav
""" acceleration due to gravity [m s :sup:`-2`] """
# ---- meteorological constants
kappa = 0.4 # NOTE: 0.41
""" von Karman's constant """
Charnock_alpha = 0.011 # NOTE: 0.018
""" Charnock constant. For determining roughness length at sea given friction
velocity, used in Smith formulas for drag coefficient and also in Fairall and
Edson. Ese alpha = 0.011 for open-ocean and alpha = 0.018 for fetch-limited
(coastal) regions."""
R_roughness = 0.11
""" limiting roughness Reynolds for aerodynamically smooth flow """
def visc_air(Ta):
"""Computes the kinematic viscosity of dry air as a function of air
temperature
Parameters
----------
Ta : array_like
air temperature [:math:`^\\circ` C]
Returns
-------
visa : array_like
[m :sup:`2` s :sup:`-1`]
See Also
--------
hfbulktc, cdn
sw.visc
Notes
-----
sw.visc from python seawater package
Examples
--------
>>> from airsea import atmosphere as asea
>>> asea.visc_air([[0.1, 5., 15],[22.8, 28.9, 31.4]])
array([[ 1.32686758e-05, 1.36964784e-05, 1.45857532e-05],
[ 1.52942886e-05, 1.58573695e-05, 1.60903922e-05]])
References
----------
.. [1] Andreas (1989), CRREL Report 89-11.
Modifications: Original from COARE 3.0
11/26/2010: Filipe Fernandes, Python translation.
"""
# convert input to numpy array
Ta = np.asarray(Ta)
visa = 1.326e-5 * (1 + 6.542e-3 * Ta + 8.301e-6 * Ta ** 2 - 4.84e-9 *
Ta ** 3)
return visa
def cdn(sp, z, drag='largepond', Ta=10):
"""Computes neutral drag coefficient.
Methods available are: Large & Pond (1981), Vera (1983) or Smith (1988)
Parameters
----------
sp : array_like
wind speed [m s :sup:`-1`]
z : float, array_like
measurement height [m]
drag : str
neutral drag by:
'largepond' <-- default
'smith'
'vera'
Ta : array_like, optional for drag='smith'
air temperature [:math:`^\\circ` C]
Returns
-------
cd : float, array_like
neutral drag coefficient at 10 m
u10 : array_like
wind speed at 10 m [m s :sup:`-1`]
See Also
--------
stress, spshft, visc_air
Notes
-----
Vera (1983): range of fit to data is 1 to 25 [m s :sup:`-1`].
Examples
--------
>>> from airsea import windstress as ws
>>> ws.cdn([10., 0.2, 12., 20., 30., 50.], 10)
(array([ 0.00115, 0.00115, 0.00127, 0.00179, 0.00244, 0.00374]),
array([ 10. , 0.2, 12. , 20. , 30. , 50. ]))
>>> ws.cdn([10., 0.2, 12., 20., 30., 50.], 15, 'vera')
(array([ 0.00116157, 0.01545237, 0.00126151, 0.00174946, 0.00242021,
0.00379521]),
array([ 9.66606155, 0.17761896, 11.58297824, 19.18652915,
28.5750255 , 47.06117334]))
>>> ws.cdn([10., 0.2, 12., 20., 30., 50.], 20, 'smith', 20.)
(array([ 0.00126578, 0.00140818, 0.00136533, 0.00173801, 0.00217435,
0.00304636]),
array([ 9.41928554, 0.18778865, 11.27787697, 18.65250005,
27.75712916, 45.6352786 ]))
References
----------
.. [1] Large and Pond (1981), J. Phys. Oceanog., 11, 324-336.
.. [2] Smith (1988), J. Geophys. Res., 93, 311-326.
.. [3] E. Vera (1983) FIXME eqn. 8 in Large, Morzel, and Crawford (1995),
J. Phys. Oceanog., 25, 2959-2971.
Modifications: Original from AIR_SEA TOOLBOX, Version 2.0
03-08-1997: version 1.0
08-26-1998: version 1.1 (vectorized by RP)
08-05-1999: version 2.0
11-26-2010: Filipe Fernandes, Python translation.
"""
# convert input to numpy array
sp, z, Ta = np.asarray(sp), np.asarray(z), np.asarray(Ta)
tol = 0.00001 # Iteration end point.
if drag == 'largepond':
a = np.log(z / 10.) / kappa # Log-layer correction factor.
u10o = np.zeros(sp.shape)
cd = 1.15e-3 * np.ones(sp.shape)
u10 = sp / (1 + a * np.sqrt(cd))
ii = np.abs(u10 - u10o) > tol
while np.any(ii):
u10o = u10
cd = (4.9e-4 + 6.5e-5 * u10o) # Compute cd(u10).
cd[u10o < 10.15385] = 1.15e-3
u10 = sp / (1 + a * np.sqrt(cd)) # Next iteration.
# Keep going until iteration converges.
ii = np.abs(u10 - u10o) > tol
elif drag == 'smith':
visc = visc_air(Ta)
# Remove any sp==0 to prevent division by zero
# i = np.nonzero(sp == 0)
# sp[i] = 0.1 * np.ones(len(i)) FIXME
# initial guess
ustaro = np.zeros(sp.shape)
ustarn = 0.036 * sp
# iterate to find z0 and ustar
ii = np.abs(ustarn - ustaro) > tol
while np.any(ii):
ustaro = ustarn
z0 = Charnock_alpha * ustaro ** 2 / g + R_roughness * visc / ustaro
ustarn = sp * (kappa / np.log(z / z0))
ii = np.abs(ustarn - ustaro) > tol
sqrcd = kappa / np.log(10. / z0)
cd = sqrcd ** 2
u10 = ustarn / sqrcd
elif drag == 'vera':
# constants in fit for drag coefficient
A = 2.717e-3
B = 0.142e-3
C = 0.0764e-3
a = np.log(z / 10.) / kappa # Log-layer correction factor.
# Don't start iteration at 0 to prevent blowups.
u10o = np.zeros(sp.shape) + 0.1
cd = A / u10o + B + C * u10o
u10 = sp / (1 + a * np.sqrt(cd))
ii = np.abs(u10 - u10o) > tol
while np.any(ii):
u10o = u10
cd = A / u10o + B + C * u10o
u10 = sp / (1 + a * np.sqrt(cd)) # Next iteration.
# Keep going until iteration converges.
ii = np.abs(u10 - u10o) > tol
else:
print('Unknown method') # FIXME: raise a proper python error.
return cd, u10
def spshft(sp, z1, z2, drag='largepond', Ta=10.):
"""Adjusts wind speed from height z1 to z2. Methods available are: Large &
Pond (1981), Vera (1983) or Smith (1988).
Parameters
----------
sp : array_like
wind speed [m s :sup:`-1`]
z1 : float
measurement height [m]
z2 : float
desired height [m]
drag : str
neutral drag by:
'largepond' <-- default
'smith'
'vera'
Ta : array_like
air temperature [:math:`^\\circ` C]
Returns
-------
sp_adj : array_like
predicted wind speed [m s :sup:`-1`]
ustar : array_like
friction velocity [m s :sup:`-1`]
See Also
--------
cdn
Examples
--------
>>> from airsea import windstress as ws
>>> ws.spshft([10., 0.2, 12., 20., 30., 50.], 10, 10)[0]
array([ 10. , 0.2, 12. , 20. , 30. , 50. ])
>>> from airsea import windstress as ws
>>> ws.spshft([10., 0.2, 12., 20., 30., 50.], 10, 8, 'smith', 20)
(array([ 9.79908171, 0.19583568, 11.74922628, 19.52618419,
29.20068179, 48.40456082]), array([ 0.3601597 , 0.00746483, 0.44952896, 0.84934708, 1.43283229,
2.8599333 ]))
>>> ws.spshft([10., 0.2, 12., 20., 30., 50.], 15, 10, 'vera')
(array([ 9.66606155, 0.17761896, 11.58297824, 19.18652915,
28.5750255 , 47.06117334]), array([ 0.32943742, 0.02207938, 0.41140089, 0.80250639, 1.40576781,
2.89921535]))
References
----------
.. [1] Large and Pond (1981), J. Phys. Oceanog., 11, 324-336.
.. [2] Smith (1988), J. Geophys. Res., 93, 311-326.
.. [3] E. Vera (1983) FIXME eqn. 8 in Large, Morzel, and Crawford (1995),
J. Phys. Oceanog., 25, 2959-2971.
Modifications: Original from AIR_SEA TOOLBOX, Version 2.0
03-08-1997: version 1.0
08-27-1998: version 1.1 (revised to use cdn* efficiently by RP)
08-05-1999: version 2.0
11-26-2010: Filipe Fernandes, Python translation.
"""
z1, z2 = np.asarray(z1), np.asarray(z2)
sp, Ta = np.asarray(sp), np.asarray(Ta)
# Find cd and ustar.
if drag == 'largepond':
cd10, sp10 = cdn(sp, z1, 'largepond')
elif drag == 'smith':
cd10, sp10 = cdn(sp, z1, 'smith', Ta)
elif drag == 'vera':
cd10, sp10 = cdn(sp, z1, 'vera')
else:
print('Unknown method') # FIXME: raise a proper python error!
ustar = np.sqrt(cd10) * sp10
sp_adj = sp10 + ustar * np.log(z2 / 10.) / kappa
return sp_adj, ustar
def stress(sp, z=10., drag='largepond', rho_air=1.22, Ta=10.):
"""Computes the neutral wind stress.
Parameters
----------
sp : array_like
wind speed [m s :sup:`-1`]
z : float, array_like, optional
measurement height [m]
rho_air : array_like, optional
air density [kg m :sup:`-3`]
drag : str
neutral drag by:
'largepond' <-- default
'smith'
'vera'
Ta : array_like, optional
air temperature [:math:`^\\circ` C]
Returns
-------
tau : array_like
wind stress [N m :sup:`-2`]
See Also
--------
cdn
Examples
--------
>>> from airsea import windstress as ws
>>> ws.stress([10., 0.2, 12., 20., 30., 50.], 10)
array([ 1.40300000e-01, 5.61200000e-05, 2.23113600e-01,
8.73520000e-01, 2.67912000e+00, 1.14070000e+01])
>>> kw = dict(rho_air=1.02, Ta=23.)
>>> ws.stress([10., 0.2, 12., 20., 30., 50.], 15, 'smith', **kw)
array([ 1.21440074e-01, 5.32531576e-05, 1.88322389e-01,
6.62091968e-01, 1.85325310e+00, 7.15282267e+00])
>>> ws.stress([10., 0.2, 12., 20., 30., 50.], 8, 'vera')
array([ 1.50603698e-01, 7.16568379e-04, 2.37758830e-01,
9.42518454e-01, 3.01119044e+00, 1.36422742e+01])
References
----------
.. [1] Large and Pond (1981), J. Phys. Oceanog., 11, 324-336.
.. [2] Smith (1988), J. Geophys. Res., 93, 311-326.
.. [3] E. Vera (1983) FIXME eqn. 8 in Large, Morzel, and Crawford (1995),
J. Phys. Oceanog., 25, 2959-2971.
Modifications: Original from AIR_SEA TOOLBOX, Version 2.0
03-08-1997: version 1.0
08-26-1998: version 1.1 (revised by RP)
04-02-1999: versin 1.2 (air density option added by AA)
08-05-1999: version 2.0
11-26-2010: Filipe Fernandes, Python translation.
"""
z, sp = np.asarray(z), np.asarray(sp)
Ta, rho_air = np.asarray(Ta), np.asarray(rho_air)
# Find cd and ustar.
if drag == 'largepond':
cd, sp = cdn(sp, z, 'largepond')
elif drag == 'smith':
cd, sp = cdn(sp, z, 'smith', Ta)
elif drag == 'vera':
cd, sp = cdn(sp, z, 'vera')
else:
print('Unknown method') # FIXME: raise a proper python error
tau = rho_air * (cd * sp ** 2)
return tau