-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconversions.py
95 lines (79 loc) · 1.48 KB
/
conversions.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
# -*- coding: utf-8 -*-
"""
Sopan Kurkute
University of Saskatchewan
conversions.py
Conversions of variables for plotting wrf netcdf package
"""
import numpy as np
import constants as const
#convert geopotential height to height in m
def gphgt_to_hgt(totalgp):
"""
Parameters
Geopotential (m^2/s^2)
Returns
Geopotential Height (m)
"""
hgt = (totalgp / const.g)
return hgt
#convert pa to hPa
def pa_to_hpa(pres):
"""
Parameters
Pressure (Pa)
Returns
Pressure (hPa)
"""
pres_hpa = pres * 0.01
return pres_hpa
#convert kelvin to celcius
def k_to_c(tempk):
"""
Parameters
Temp (K)
Returns
Temp(C)
"""
tempc = tempk - 273.15
return tempc
#convert kelvin to fahreinheit
def k_to_f(tempk):
"""
Parameters
Temp (K)
Returns
Temp (F)
"""
tempc = k_to_c(tempk)
tempf = tempc * (9./5.) + 32.
return tempf
# convert c to f
def c_to_f(tempc):
"""
Parameters
Temp (C)
Returns
Temp (F)
"""
tempf = tempc * (9./5.) + 32.
return tempf
# ms^-1 to knots
def ms_to_kts(spd):
"""
Parameters
Speed (ms^-1)
Returns
Speed (knots)
"""
spdkts = spd * 1.94384449
return spdkts
def mm_to_in(ppn):
"""
Parameters
Precipitation (mm)
Returns
Precipitation (inches)
"""
ppnin = ppn * 0.0393701
return ppnin