Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AossTower
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MetObs
AossTower
Commits
1f1c03dc
Verified
Commit
1f1c03dc
authored
2 years ago
by
David Hoese
Browse files
Options
Downloads
Patches
Plain Diff
Fix a few style issues
parent
65ea217c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
aosstower/level_b1/calc.py
+38
-42
38 additions, 42 deletions
aosstower/level_b1/calc.py
with
38 additions
and
42 deletions
aosstower/level_b1/calc.py
+
38
−
42
View file @
1f1c03dc
...
@@ -21,58 +21,54 @@ def knots_to_mps(knots):
...
@@ -21,58 +21,54 @@ def knots_to_mps(knots):
return
knots
*
0.51444
return
knots
*
0.51444
def
dewpoint
(
tempC
,
relhum
):
def
dewpoint
(
temp_c
,
relhum
):
"""
Algorithm from Tom Whittaker tempC is the temperature in degrees Celsius,
"""
Convert air temperature and relative humidity to dewpoint.
relhum is the relative humidity as a percentage.
:param tempC: temperature in celsius
Algorithm from Tom Whittaker.
:param temp_c: temperature in celsius
:param relhum: relative humidity as a percentage
:param relhum: relative humidity as a percentage
"""
"""
if
temp
C
is
None
or
relhum
is
None
:
if
temp
_c
is
None
or
relhum
is
None
:
return
NaN
return
NaN
gasconst
=
461.5
gasconst
=
461.5
latheat
=
2500800.0
latheat
=
2500800.0
dp
=
1.0
/
(
1.0
/
(
273.15
+
temp
C
)
-
gasconst
*
np
.
log
((
0.0
+
relhum
)
/
100
)
/
(
latheat
-
temp
C
*
2397.5
))
dp
=
1.0
/
(
1.0
/
(
273.15
+
temp
_c
)
-
gasconst
*
np
.
log
((
0.0
+
relhum
)
/
100
)
/
(
latheat
-
temp
_c
*
2397.5
))
if
pd
is
not
None
and
isinstance
(
dp
,
pd
.
Series
):
if
pd
is
not
None
and
isinstance
(
dp
,
pd
.
Series
):
return
pd
.
concat
([
dp
-
273.15
,
temp
C
],
axis
=
1
).
min
(
axis
=
1
)
return
pd
.
concat
([
dp
-
273.15
,
temp
_c
],
axis
=
1
).
min
(
axis
=
1
)
return
np
.
min
(
dp
-
273.15
,
temp
C
)
return
np
.
min
(
dp
-
273.15
,
temp
_c
)
def
relhum
(
airTempK
,
dewpointTempK
):
def
relhum
(
air_temp_k
,
dewpoint_temp_k
):
"""
Algorithm derived by David Hoese from the above
"""
Calculate relative humidity from air temperature and dewpoint temperature.
dewpoint(tempC, relhum) function, both parameters are in Kelvin units.
:param air
T
emp
K
: air temperature in Kelvin
:param air
_t
emp
_k
: air temperature in Kelvin
:param dewpoint
T
emp
K
: dewpoint temp in Kelvin
:param dewpoint
_t
emp
_k
: dewpoint temp in Kelvin
"""
"""
if
air
T
emp
K
is
None
or
dewpoint
T
emp
K
is
None
:
if
air
_t
emp
_k
is
None
or
dewpoint
_t
emp
_k
is
None
:
return
NaN
return
NaN
gas_constant
=
461.5
gas_constant
=
461.5
latheat
=
2500800.0
latheat
=
2500800.0
# Only one section of the equation
# Only one section of the equation
latpart
=
latheat
-
(
airTempK
-
273.15
)
*
2397.5
latpart
=
latheat
-
(
air_temp_k
-
273.15
)
*
2397.5
relativehum
=
100
*
math
.
e
**
((
latpart
/
airTempK
-
latpart
/
dewpointTempK
)
/
gas_constant
)
return
100
*
math
.
e
**
((
latpart
/
air_temp_k
-
latpart
/
dewpoint_temp_k
)
/
gas_constant
)
return
relativehum
def
potentialtemp
(
air
T
emp
K
,
pressure
MB
):
def
potentialtemp
(
air
_t
emp
_k
,
pressure
_mb
):
"""
Algorithm from David Hoese to calculate potential temperature.
"""
Algorithm from David Hoese to calculate potential temperature.
:param air
T
emp
K
: air temperature in Kelvin
:param air
_t
emp
_k
: air temperature in Kelvin
:param pressure
MB
: air pressure in millibars
:param pressure
_mb
: air pressure in millibars
"""
"""
if
air
T
emp
K
is
None
or
pressure
MB
is
None
:
if
air
_t
emp
_k
is
None
or
pressure
_mb
is
None
:
return
NaN
return
NaN
pT
=
airTempK
*
(
pressureMB
.
max
()
/
pressureMB
)
**
0.286
return
air_temp_k
*
(
pressure_mb
.
max
()
/
pressure_mb
)
**
0.286
return
pT
def
altimeter
(
p
,
alt
):
def
altimeter
(
p
,
alt
):
...
@@ -108,44 +104,44 @@ def dir2txt(val):
...
@@ -108,44 +104,44 @@ def dir2txt(val):
>>>
dir2txt
(
359
)
>>>
dir2txt
(
359
)
'
N
'
'
N
'
"""
"""
assert
val
>=
0
and
val
<
360
,
"'
%s
'
out of range
"
%
val
if
not
(
val
>=
0
and
val
<
360
):
# noqa: PLR2004
dirs
=
(
"
NNE
"
,
"
NE
"
,
"
ENE
"
,
"
E
"
,
"
ESE
"
,
"
SE
"
,
"
SSE
"
,
"
S
"
,
"
SSW
"
,
"
SW
"
,
"
WSW
"
,
"
W
"
,
"
WNW
"
,
"
NW
"
,
"
NNW
"
)
msg
=
f
"'
{
val
}
'
out of range
"
raise
ValueError
(
msg
)
cardinal_dirs
=
(
"
NNE
"
,
"
NE
"
,
"
ENE
"
,
"
E
"
,
"
ESE
"
,
"
SE
"
,
"
SSE
"
,
"
S
"
,
"
SSW
"
,
"
SW
"
,
"
WSW
"
,
"
W
"
,
"
WNW
"
,
"
NW
"
,
"
NNW
"
)
if
(
val
>=
348.75
and
val
<=
360
)
or
val
>=
0
and
val
<
11.25
:
if
(
val
>=
348.75
and
val
<=
360
)
or
val
>=
0
and
val
<
11.25
:
# noqa: PLR2004
return
"
N
"
return
"
N
"
# 1/2 degree increment between the directions
# 1/2 degree increment between the directions
i
=
11.25
i
=
11.25
for
dir
in
dirs
:
for
card_
dir
in
cardinal_
dirs
:
if
val
>=
i
and
val
<
(
i
+
22.5
):
if
val
>=
i
and
val
<
(
i
+
22.5
):
return
dir
return
card_
dir
i
+=
22.5
i
+=
22.5
return
None
return
None
def
wind_vector_components
(
windspd
,
winddir
):
def
wind_vector_components
(
windspd
,
winddir
):
"""
Decompose scalar or list/array polar wind direction and speed data
"""
Decompose polar wind direction and speed into the horizontal and vertical vector components and speed vector.
into the horizontal and vertical vector components and speed vector.
Inputs can be scalar or arrays.
Inputs can be scalar or arrays.
"""
"""
dir_rad
=
np
.
deg2rad
(
winddir
)
dir_rad
=
np
.
deg2rad
(
winddir
)
spd_arr
=
np
.
array
(
windspd
)
spd_arr
=
np
.
array
(
windspd
)
V
_e
=
spd_arr
*
np
.
sin
(
dir_rad
)
v
_e
=
spd_arr
*
np
.
sin
(
dir_rad
)
V
_n
=
spd_arr
*
np
.
cos
(
dir_rad
)
v
_n
=
spd_arr
*
np
.
cos
(
dir_rad
)
U
_spd
=
np
.
sqrt
(
pow
(
V
_e
,
2
)
+
pow
(
V
_n
,
2
))
u
_spd
=
np
.
sqrt
(
pow
(
v
_e
,
2
)
+
pow
(
v
_n
,
2
))
return
V
_e
,
V
_n
,
U
_spd
return
v
_e
,
v
_n
,
u
_spd
def
wind_vector_degrees
(
vector_east
,
vector_north
):
def
wind_vector_degrees
(
vector_east
,
vector_north
):
"""
Re-compose horizontal (east/west) and vertical (north/south) vector
"""
Re-compose horizontal (east/west) and vertical (north/south) vector components into wind direction in degrees.
components into wind direction in degrees.
Inputs can be scalar or arrays.
Inputs can be scalar or arrays.
"""
"""
rads
=
np
.
arctan2
(
vector_east
,
vector_north
)
rads
=
np
.
arctan2
(
vector_east
,
vector_north
)
winddir
=
np
.
rad2deg
(
rads
)
winddir
=
np
.
rad2deg
(
rads
)
if
isinstance
(
winddir
,
(
np
.
ndarray
,
Series
)
)
:
if
isinstance
(
winddir
,
np
.
ndarray
|
Series
):
winddir
[
np
.
less
(
winddir
,
0
)]
+=
360
winddir
[
np
.
less
(
winddir
,
0
)]
+=
360
elif
winddir
<
0
:
elif
winddir
<
0
:
winddir
+=
360
winddir
+=
360
...
@@ -153,7 +149,7 @@ def wind_vector_degrees(vector_east, vector_north):
...
@@ -153,7 +149,7 @@ def wind_vector_degrees(vector_east, vector_north):
def
mean_wind_vector
(
windspd
,
winddir
):
def
mean_wind_vector
(
windspd
,
winddir
):
V
_e
,
V
_n
,
V
_spd
=
wind_vector_components
(
windspd
,
winddir
)
v
_e
,
v
_n
,
v
_spd
=
wind_vector_components
(
windspd
,
winddir
)
avg_dir
=
wind_vector_degrees
(
np
.
mean
(
V
_e
),
np
.
mean
(
V
_n
))
avg_dir
=
wind_vector_degrees
(
np
.
mean
(
v
_e
),
np
.
mean
(
v
_n
))
return
avg_dir
,
np
.
mean
(
V
_spd
)
return
avg_dir
,
np
.
mean
(
v
_spd
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment