-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwx_utilities.py
More file actions
66 lines (49 loc) · 1.44 KB
/
Copy pathwx_utilities.py
File metadata and controls
66 lines (49 loc) · 1.44 KB
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
import numpy as np
import math
import datetime
#### Knots to MPH ####
def knot2mph(knots):
return knots * 1.15078
def mph2knot(mph):
return mph / 1.15078
def ms2knot(ms):
return ms / 0.5144447
def knot2ms(knot):
return knot * 0.5144447
def mph2ms(mph):
return mph * 0.44704
def ms2mph(ms):
return ms / 0.44704
def C2F(C):
return (C * (9.0/5.0)) + 32.0
def F2C(F):
return (F - 32.0) * (5.0/9.0)
def C2K(C):
return C + 273.15
def K2C(K):
return K - 273.15
def F2K(F):
C = F2C(F)
return C2K(C)
def K2F(K):
C = K2C(K)
return C2F(C)
def ClausClap(T):
# use the empirical version of the Clausius-Clapeyron equation
# as described in A First Course in Atmospheric Thermodynamics (Petty)
# Input: T (float or int) Temperature in C (NOT KELVIN)
return 611.2 * math.exp( (17.67*T) / (T+243.5) )
def RH(T,Td):
es = ClausClap(T)
ev = ClausClap(Td)
return (ev/es) * 100.0
def roundTime(dt=None, roundTo=60):
"""Round a datetime object to any time lapse in seconds
dt : datetime.datetime object, default now.
roundTo : Closest number of seconds to round to, default 1 minute.
Author: Thierry Husson 2012 - Use it as you want but don't blame me.
"""
if dt == None : dt = datetime.datetime.now()
seconds = (dt.replace(tzinfo=None) - dt.min).seconds
rounding = (seconds+roundTo/2) // roundTo * roundTo
return dt + datetime.timedelta(0,rounding-seconds,-dt.microsecond)