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
dd95488c
Unverified
Commit
dd95488c
authored
8 years ago
by
David Hoese
Browse files
Options
Downloads
Patches
Plain Diff
Finalize behavior of averaging wind properties in summary file
parent
5a00ce2e
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/nc.py
+10
-15
10 additions, 15 deletions
aosstower/level_b1/nc.py
with
10 additions
and
15 deletions
aosstower/level_b1/nc.py
+
10
−
15
View file @
dd95488c
...
...
@@ -207,7 +207,7 @@ def calculate_wind_gust(wind_speed_5s, wind_speed_2m):
"""
# 1 minute rolling peaks
wind_peak_1m
=
wind_speed_5s
.
rolling
(
window
=
12
,
center
=
False
).
max
()
wind_peak_1m
=
wind_speed_5s
.
rolling
(
window
=
'
1T
'
,
center
=
False
).
max
()
# criteria for a fast wind to be considered a wind gust
gust_mask
=
(
wind_speed_2m
>=
KNOTS_9
)
&
\
(
wind_peak_1m
>=
wind_speed_2m
+
KNOTS_5
)
...
...
@@ -215,9 +215,9 @@ def calculate_wind_gust(wind_speed_5s, wind_speed_2m):
# determine highest gust in the last 10 minutes
# 5 seconds * 120 = 10 minutes
max_10m_gusts
=
gusts
.
rolling
(
window
=
120
,
center
=
False
).
max
()
max_10m_gusts
=
gusts
.
rolling
(
window
=
'
10T
'
,
center
=
False
).
max
()
# Minimum 5-second average in the past 10 minutes
min_10m_5avg
=
wind_speed_5s
.
rolling
(
window
=
120
,
center
=
False
).
min
()
min_10m_5avg
=
wind_speed_5s
.
rolling
(
window
=
'
10T
'
,
center
=
False
).
min
()
# criteria for a wind gust to be reportable
reportable_mask
=
(
max_10m_gusts
>=
wind_speed_2m
+
KNOTS_3
)
&
\
(
wind_speed_2m
>
KNOTS_2
)
&
\
...
...
@@ -264,7 +264,7 @@ def summary_over_interval(frame, interval_width):
# the value at time X is for the data X - interval_width minutes
exclude
=
[
'
gust
'
,
'
wind_east
'
,
'
wind_north
'
]
include
=
[
c
for
c
in
frame
.
columns
if
c
not
in
exclude
]
gb
=
frame
[
include
].
resample
(
interval_width
,
closed
=
'
right
'
,
loffset
=
interval_width
)
gb
=
frame
[
include
].
resample
(
interval_width
,
closed
=
'
left
'
)
low
=
gb
.
min
()
low
.
rename
(
columns
=
lambda
x
:
x
+
"
_min
"
,
inplace
=
True
)
...
...
@@ -276,8 +276,8 @@ def summary_over_interval(frame, interval_width):
out_frames
=
pd
.
concat
((
low
,
high
,
mean
),
axis
=
1
)
# wind fields need to be handled specially
ws_min_idx
=
frame
[
'
wind_speed
'
].
resample
(
interval_width
,
closed
=
'
right
'
,
loffset
=
interval_width
).
apply
(
lambda
arr_like
:
arr_like
.
argmin
())
ws_max_idx
=
frame
[
'
wind_speed
'
].
resample
(
interval_width
,
closed
=
'
right
'
,
loffset
=
interval_width
).
apply
(
lambda
arr_like
:
arr_like
.
argmax
())
ws_min_idx
=
frame
[
'
wind_speed
'
].
resample
(
interval_width
,
closed
=
'
left
'
).
apply
(
lambda
arr_like
:
arr_like
.
argmin
())
ws_max_idx
=
frame
[
'
wind_speed
'
].
resample
(
interval_width
,
closed
=
'
left
'
).
apply
(
lambda
arr_like
:
arr_like
.
argmax
())
# probably redundant but need to make sure the direction indexes are
# the same as those used in the wind speed values
# must use .values so we don't take data at out_frames index, but rather
...
...
@@ -286,11 +286,11 @@ def summary_over_interval(frame, interval_width):
out_frames
[
'
wind_speed_max
'
]
=
frame
[
'
wind_speed
'
][
ws_max_idx
].
values
out_frames
[
'
wind_speed_min_dir
'
]
=
calc
.
wind_vector_degrees
(
frame
[
'
wind_east
'
][
ws_min_idx
],
frame
[
'
wind_north
'
][
ws_min_idx
]).
values
out_frames
[
'
wind_speed_max_dir
'
]
=
calc
.
wind_vector_degrees
(
frame
[
'
wind_east
'
][
ws_max_idx
],
frame
[
'
wind_north
'
][
ws_max_idx
]).
values
we
=
frame
[
'
wind_east
'
].
resample
(
interval_width
,
closed
=
'
right
'
,
loffset
=
interval_width
).
mean
()
wn
=
frame
[
'
wind_north
'
].
resample
(
interval_width
,
closed
=
'
right
'
,
loffset
=
interval_width
).
mean
()
we
=
frame
[
'
wind_east
'
].
resample
(
interval_width
,
closed
=
'
left
'
).
mean
()
wn
=
frame
[
'
wind_north
'
].
resample
(
interval_width
,
closed
=
'
left
'
).
mean
()
out_frames
[
'
wind_speed_mean_dir
'
]
=
calc
.
wind_vector_degrees
(
we
,
wn
).
values
gust_idx
=
frame
[
'
gust
'
].
resample
(
interval_width
,
closed
=
'
right
'
,
loffset
=
interval_width
).
apply
(
lambda
arr_like
:
arr_like
.
argmax
())
gust_idx
=
frame
[
'
gust
'
].
resample
(
interval_width
,
closed
=
'
left
'
).
apply
(
lambda
arr_like
:
arr_like
.
argmax
())
# gusts may be NaN so this argmax will be NaN indexes which don't work great
gust_idx
=
gust_idx
.
astype
(
'
datetime64[ns]
'
,
copy
=
False
)
peak_gust
=
frame
[
'
gust
'
][
gust_idx
]
...
...
@@ -397,13 +397,11 @@ def create_giant_netcdf(input_files, output_fn, zlib, chunk_size,
frame
[
'
wind_east
'
],
frame
[
'
wind_north
'
],
_
=
calc
.
wind_vector_components
(
frame
[
'
wind_speed
'
],
frame
[
'
wind_dir
'
])
# round up each 1 minute group so data at time T is the average of data
# from T - 1 (exclusive) to T (inclusive).
# new_frame = frame.resample('1T', closed='right', loffset='1T').mean()
new_frame
=
frame
.
resample
(
'
5S
'
,
closed
=
'
right
'
,
loffset
=
'
5S
'
).
mean
()
# 2 minute rolling average of 5 second data (5 seconds * 24 = 120 seconds = 2 minutes)
winds_frame_5s
=
new_frame
[[
'
wind_speed
'
,
'
wind_east
'
,
'
wind_north
'
]]
# winds_frame_5s = winds_frame_5s.resample('5S', closed='right', loffset='5S').mean()
winds_frame_2m
=
winds_frame_5s
.
rolling
(
24
,
win_type
=
'
boxcar
'
).
mean
()
winds_frame_2m
=
winds_frame_5s
.
rolling
(
'
2T
'
).
mean
()
winds_frame_2m
[
'
gust
'
]
=
calculate_wind_gust
(
winds_frame_5s
[
'
wind_speed
'
],
winds_frame_2m
[
'
wind_speed
'
])
# rolling average is used for mean output
...
...
@@ -415,9 +413,6 @@ def create_giant_netcdf(input_files, output_fn, zlib, chunk_size,
frame
=
summary_over_interval
(
new_frame
,
interval_width
)
else
:
frame
=
new_frame
.
resample
(
interval_width
,
closed
=
'
right
'
,
loffset
=
interval_width
).
mean
()
# gust_idx = new_frame['gust'].resample(interval_width, closed='right', loffset=interval_width).apply(lambda arr_like: arr_like.argmax())
# frame['gust'][:] = new_frame['gust'][gust_idx.values]
# frame['wind_dir'] = calc.wind_vector_degrees(frame['wind_east'][gust_idx.values], frame['wind_north'][gust_idx.values])
frame
[
'
wind_dir
'
]
=
calc
.
wind_vector_degrees
(
frame
[
'
wind_east
'
],
frame
[
'
wind_north
'
])
frame
[
'
gust
'
]
=
new_frame
[
'
gust
'
].
resample
(
interval_width
,
closed
=
'
right
'
,
loffset
=
interval_width
).
max
()
frame
.
fillna
(
np
.
nan
,
inplace
=
True
)
...
...
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