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
6c3670ec
Commit
6c3670ec
authored
15 years ago
by
David Hoese
Browse files
Options
Downloads
Patches
Plain Diff
try it using mean
parent
3b38d844
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
metobs/data/filter.py
+15
-7
15 additions, 7 deletions
metobs/data/filter.py
with
15 additions
and
7 deletions
metobs/data/filter.py
+
15
−
7
View file @
6c3670ec
"""
Array filtering functions
"""
Array filtering functions
"""
"""
from
numpy
import
ndarray
,
array
,
diff
from
numpy
import
ndarray
,
array
,
diff
,
zeros
from
numpy.ma
import
MaskedArray
,
masked_array
,
masked_where
from
numpy.ma
import
MaskedArray
,
masked_array
,
masked_where
,
zeros
as
mzeros
__docformat__
=
'
Epytext
'
__docformat__
=
'
Epytext
'
__author__
=
'
David Hoese
'
__author__
=
'
David Hoese
'
...
@@ -19,15 +19,23 @@ def filter_arr(arr, threshold, fill_value=None):
...
@@ -19,15 +19,23 @@ def filter_arr(arr, threshold, fill_value=None):
@param fill_value: Value to replace the filtered values with (ex. NaN)
@param fill_value: Value to replace the filtered values with (ex. NaN)
@type fill_value: anything
@type fill_value: anything
"""
"""
if
type
.
arr
!=
ndarray
or
type
.
arr
!=
MaskedArray
:
if
type
(
arr
)
!=
ndarray
and
type
(
arr
)
!=
MaskedArray
:
if
fill_value
!=
None
:
arr
=
array
(
arr
)
if
fill_value
!=
None
:
arr
=
array
(
arr
)
if
fill_value
==
None
:
arr
=
masked_array
(
arr
)
if
fill_value
==
None
:
arr
=
masked_array
(
arr
)
if
fill_value
!=
None
:
diff_arr
=
zeros
(
arr
.
shape
[
0
])
step
=
10
if
fill_value
==
None
:
diff_arr
=
ma
.
zeros
(
arr
.
shape
[
0
])
m
=
zeros
(
arr
.
shape
[
0
])
diff_arr
[
1
:]
=
diff
(
arr
,
n
=
1
)
for
i
in
range
(
0
,
arr
.
shape
[
0
],
step
):
for
j
in
range
(
step
):
mean
=
(
arr
[
i
:(
i
+
step
)].
cumsum
()[
-
1
]
-
arr
[
i
+
j
])
/
(
step
-
1
)
df
=
abs
(
mean
-
arr
[
i
+
j
])
if
df
>
threshold
:
m
[
i
+
j
]
=
1
arr
=
masked_where
(
diff_arr
>=
threshold
,
arr
)
#if fill_value != None: diff_arr = zeros(arr.shape[0])
#if fill_value == None: diff_arr = mzeros(arr.shape[0])
#diff_arr[1:] = diff(arr, n=1)
arr
=
masked_array
(
data
=
arr
,
mask
=
m
)
if
fill_value
!=
None
:
if
fill_value
!=
None
:
arr
.
fill_value
=
fill_value
arr
.
fill_value
=
fill_value
arr
=
arr
.
filled
()
arr
=
arr
.
filled
()
...
...
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