Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MetObsData
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
MetObsData
Commits
d39d2777
Commit
d39d2777
authored
15 years ago
by
David Hoese
Browse files
Options
Downloads
Patches
Plain Diff
averaging intervals work with masked arrays
parent
30507bb2
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
metobs/data/__init__.py
+17
-5
17 additions, 5 deletions
metobs/data/__init__.py
with
17 additions
and
5 deletions
metobs/data/__init__.py
+
17
−
5
View file @
d39d2777
...
...
@@ -8,7 +8,8 @@ import math
from
datetime
import
timedelta
import
fpconst
from
numpy
import
array
,
average
,
zeros
,
radians
,
degrees
,
arctan2
,
sin
,
cos
from
numpy
import
array
,
average
,
zeros
,
radians
,
degrees
,
arctan2
,
sin
,
cos
,
ndarray
from
numpy.ma
import
masked_array
,
average
as
masked_average
,
MaskedArray
,
masked_where
,
column_stack
from
pydap.client
import
open_url
as
dapopen
from
metobs
import
mytime
...
...
@@ -32,6 +33,12 @@ def average_for_interval(basetime, arr, interval):
:type arr: ``numpy.array``
:param interval: the averaging interval in seconds
"""
if
type
(
arr
)
==
ndarray
:
avg_func
=
average
array_func
=
array
elif
type
(
arr
)
==
MaskedArray
:
avg_func
=
masked_average
array_func
=
masked_array
arr_out
=
[]
stop_dt
=
basetime
+
timedelta
(
seconds
=
interval
)
stop_idx
=
1
...
...
@@ -55,12 +62,13 @@ def average_for_interval(basetime, arr, interval):
# matrix of data to be averaged
avg_input
=
arr
[
start_idx
:
stop_idx
,
1
:]
avg_out
=
array
(
zeros
(
arr
[
0
].
shape
[
0
]))
avg_out
.
fill
(
NaN
)
if
type
(
arr
)
==
ndarray
:
avg_out
.
fill
(
NaN
)
elif
type
(
arr
)
==
MaskedArray
:
masked_where
(
avg_out
==
0
,
avg_out
)
# timestamp for center of averaging interval
int_dt
=
stop_dt
-
timedelta
(
seconds
=
(
interval
/
2
))
avg_out
[
0
]
=
mytime
.
datetime_to_epoch
(
int_dt
)
avg_out
[
1
:]
=
av
erage
(
avg_input
,
axis
=
0
)
avg_out
[
1
:]
=
av
g_func
(
avg_input
,
axis
=
0
)
arr_out
.
append
(
avg_out
)
# adjust conditions for next average
...
...
@@ -69,8 +77,12 @@ def average_for_interval(basetime, arr, interval):
stop_dt
+=
timedelta
(
seconds
=
interval
)
avg_arr
=
arr
[
start_idx
:,:]
arr_out
.
append
(
average
(
avg_arr
,
axis
=
0
))
return
array
(
arr_out
)
avg_arr
=
avg_func
(
avg_arr
,
axis
=
0
)
arr_out
.
append
(
avg_arr
)
if
type
(
arr
)
==
ndarray
:
arr_out
=
array_func
(
arr_out
)
elif
type
(
arr
)
==
MaskedArray
:
arr_out
=
column_stack
(
arr_out
).
transpose
()
return
arr_out
def
average_for_interval_degree
(
basetime
,
arr
,
interval
):
"""
Generate averages for timestamped data at a particular interval.
...
...
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