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
fcabd10f
Commit
fcabd10f
authored
11 years ago
by
Bruce Flynn
Browse files
Options
Downloads
Patches
Plain Diff
Add tests for and fix winds.
parent
c7094fc0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
aosstower/model.py
+1
-0
1 addition, 0 deletions
aosstower/model.py
aosstower/tests/test_wind.py
+26
-18
26 additions, 18 deletions
aosstower/tests/test_wind.py
aosstower/wind.py
+17
-13
17 additions, 13 deletions
aosstower/wind.py
with
44 additions
and
31 deletions
aosstower/model.py
+
1
−
0
View file @
fcabd10f
...
...
@@ -7,6 +7,7 @@ import numpy as np
from
.time
import
to_unix_timestamp
from
.wind
import
mean_wind_vector_degrees
def
dewpoint
(
tempC
,
relhum
):
"""
Algorithm from Tom Whittaker tempC is the temperature in degrees Celsius,
...
...
This diff is collapsed.
Click to expand it.
aosstower/tests/test_wind.py
+
26
−
18
View file @
fcabd10f
import
unittest
class
MeanVector
Average
Tests
(
unittest
.
TestCase
):
class
Mean
Wind
VectorTests
(
unittest
.
TestCase
):
def
_fut
(
self
,
input_windspd
,
input_winddir
):
def
_fut
(
self
,
winddir
,
windspd
=
None
):
from
aosstower.wind
import
mean_wind_vector
return
mean_wind_vector
(
input_windspd
,
input_winddir
)
def
test_scalar_input
(
self
):
for
wdir
,
wspd
in
[(
0
,
20
),
(
90
,
20
),
(
180
,
20
),
(
270
,
20
)]:
output_speed
,
output_dir
=
self
.
_fut
(
wspd
,
wdir
)
self
.
assertEqual
(
wdir
,
output_dir
)
self
.
assertEqual
(
wspd
,
20
)
def
test_array_input
(
self
):
for
wdir
,
wspd
in
[([
0
,
90
,
180
,
270
],[
10
,
10
,
10
,
10
])]:
output_speed
,
output_winddir
=
self
.
_fut
(
wspd
,
wdir
)
self
.
assertEqual
(
wdir
,
output_winddir
.
tolist
())
self
.
assertEqual
(
wspd
,
output_speed
.
tolist
())
windspd
=
windspd
or
[
1
]
*
len
(
winddir
)
return
mean_wind_vector
(
windspd
,
winddir
)[
0
]
def
test_spanning_0_degrees
(
self
):
winddir
=
self
.
_fut
([
315
,
45
])
self
.
assertAlmostEqual
(
winddir
,
0
)
def
test_spanning_cardinal_directions
(
self
):
self
.
assertAlmostEqual
(
self
.
_fut
([
45
,
135
]),
90
)
self
.
assertAlmostEqual
(
self
.
_fut
([
135
,
225
]),
180
)
self
.
assertAlmostEqual
(
self
.
_fut
([
225
,
315
]),
270
)
self
.
assertAlmostEqual
(
self
.
_fut
([
315
,
45
]),
0
)
def
test_all_zeros
(
self
):
self
.
assertAlmostEqual
(
self
.
_fut
([
0
,
0
]),
0
)
def
test_zero_windspd
(
self
):
self
.
assertAlmostEqual
(
self
.
_fut
([
0
,
0
],
windspd
=
[
0
,
0
]),
0
)
def
test_45s
(
self
):
self
.
assertAlmostEqual
(
self
.
_fut
([
0
,
90
]),
45
)
self
.
assertAlmostEqual
(
self
.
_fut
([
90
,
180
]),
135
)
self
.
assertAlmostEqual
(
self
.
_fut
([
180
,
270
]),
225
)
self
.
assertAlmostEqual
(
self
.
_fut
([
270
,
0
]),
315
)
This diff is collapsed.
Click to expand it.
aosstower/wind.py
+
17
−
13
View file @
fcabd10f
"""
See: Campbell Scientific CR1000 Manual Section 7.8.5.2.2.
"""
import
numpy
as
np
def
mean_
wind_vector_components
(
windspd
,
winddir
):
def
wind_vector_components
(
windspd
,
winddir
):
"""
Decompose scalar or list/array wind direction and speed data into the
corresponding horizontal and vertical direction components and speed
vector.
Inputs can be scalar or arrays.
"""
dir_rad
=
np
.
deg2rad
(
winddir
)
V_e
=
windspd
*
np
.
sin
(
dir_rad
)
V_n
=
windspd
*
np
.
cos
(
dir_rad
)
U_spd
=
(
V_e
**
2
+
V_n
**
2
)
**
0.5
spd_arr
=
np
.
array
(
windspd
)
V_e
=
spd_arr
*
np
.
sin
(
dir_rad
)
V_n
=
spd_arr
*
np
.
cos
(
dir_rad
)
U_spd
=
np
.
sqrt
(
pow
(
V_e
,
2
)
+
pow
(
V_n
,
2
))
return
V_e
,
V_n
,
U_spd
def
mean_
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
components into wind direction in degrees.
Inputs can be scalar or arrays.
"""
rads
=
np
.
arctan2
(
vector_east
,
vector_north
)
winddir
=
np
.
rad2deg
(
rads
)
...
...
@@ -24,14 +31,11 @@ def mean_wind_vector_degrees(vector_east, vector_north):
winddir
[
np
.
less
(
winddir
,
0
)]
+=
360
elif
winddir
<
0
:
winddir
+=
360
return
winddir
return
winddir
%
360
def
mean_wind_vector
(
windspd
,
winddir
):
"""
Compute the mean wind vector.
V_e
,
V_n
,
V_spd
=
wind_vector_components
(
windspd
,
winddir
)
avg_dir
=
wind_vector_degrees
(
np
.
mean
(
V_e
),
np
.
mean
(
V_n
))
See: Campbell Scientific CR1000 Manual Section 7.8.5.2.2.
"""
vector_east
,
vector_north
,
vector_speed
=
\
mean_wind_vector_components
(
windspd
,
winddir
)
return
vector_speed
,
mean_wind_vector_degrees
(
vector_east
,
vector_north
)
\ No newline at end of file
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