Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
MLAir
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
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
esde
machine-learning
MLAir
Commits
0682b903
Commit
0682b903
authored
4 years ago
by
leufen1
Browse files
Options
Downloads
Patches
Plain Diff
speed comparison
parent
4ab948e3
Branches
Branches containing commit
Tags
Tags containing commit
5 merge requests
!319
add all changes of dev into release v1.4.0 branch
,
!318
Resolve "release v1.4.0"
,
!317
enabled window_lead_time=1
,
!295
Resolve "data handler FIR filter"
,
!259
Draft: Resolve "WRF-Datahandler should inherit from SingleStationDatahandler"
Pipeline
#67280
passed
4 years ago
Stage: test
Stage: docs
Stage: pages
Stage: deploy
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
mlair/helpers/filter.py
+33
-13
33 additions, 13 deletions
mlair/helpers/filter.py
with
33 additions
and
13 deletions
mlair/helpers/filter.py
+
33
−
13
View file @
0682b903
...
@@ -265,13 +265,13 @@ class ClimateFIRFilter:
...
@@ -265,13 +265,13 @@ class ClimateFIRFilter:
time_axis
=
filter_input_data
.
coords
[
"
datetime
"
]
time_axis
=
filter_input_data
.
coords
[
"
datetime
"
]
# apply vectorized fir filter along the tmp dimension
# apply vectorized fir filter along the tmp dimension
kwargs
=
{
"
fs
"
:
fs
,
"
cutoff_high
"
:
cutoff_high
,
"
order
"
:
order
,
kwargs
=
{
"
fs
"
:
fs
,
"
cutoff_high
"
:
cutoff_high
,
"
order
"
:
order
,
"
causal
"
:
False
,
"
padlen
"
:
int
(
min
(
padlen_factor
,
1
)
*
length
)}
"
causal
"
:
False
,
"
padlen
"
:
int
(
min
(
padlen_factor
,
1
)
*
length
)
,
"
h
"
:
h
}
with
TimeTracking
():
with
TimeTracking
(
name
=
"
numpy_vec
"
):
filt
=
fir_filter_numpy_vectorized
(
filter_input_data
,
var_dim
,
new_dim
,
kwargs
)
filt
=
fir_filter_numpy_vectorized
(
filter_input_data
,
var_dim
,
new_dim
,
kwargs
)
#
with TimeTracking():
with
TimeTracking
(
name
=
"
xr_apply_ufunc
"
):
#
filt = xr.apply_ufunc(fir_filter_vectorized, filter_input_data, time_axis,
filt
=
xr
.
apply_ufunc
(
fir_filter_vectorized
,
filter_input_data
,
time_axis
,
#
input_core_dims=[[new_dim], []], output_core_dims=[[new_dim]], vectorize=True,
input_core_dims
=
[[
new_dim
],
[]],
output_core_dims
=
[[
new_dim
]],
vectorize
=
True
,
#
kwargs=kwargs)
kwargs
=
kwargs
)
# plot
# plot
if
self
.
plot_path
is
not
None
:
if
self
.
plot_path
is
not
None
:
...
@@ -413,8 +413,8 @@ def fir_filter_vectorized(data, time_stamp=None, fs=1, order=5, cutoff_low=None,
...
@@ -413,8 +413,8 @@ def fir_filter_vectorized(data, time_stamp=None, fs=1, order=5, cutoff_low=None,
pd_date
=
pd
.
to_datetime
(
time_stamp
)
pd_date
=
pd
.
to_datetime
(
time_stamp
)
if
pd_date
.
day
==
1
and
pd_date
.
month
in
[
1
,
7
]:
if
pd_date
.
day
==
1
and
pd_date
.
month
in
[
1
,
7
]:
logging
.
info
(
time_stamp
)
logging
.
info
(
time_stamp
)
sel
=
~
np
.
isnan
(
data
)
#
sel = ~np.isnan(data)
res
=
np
.
empty_like
(
data
)
#
res = np.empty_like(data)
if
h
is
None
:
if
h
is
None
:
cutoff
=
[]
cutoff
=
[]
if
cutoff_low
is
not
None
:
if
cutoff_low
is
not
None
:
...
@@ -431,9 +431,29 @@ def fir_filter_vectorized(data, time_stamp=None, fs=1, order=5, cutoff_low=None,
...
@@ -431,9 +431,29 @@ def fir_filter_vectorized(data, time_stamp=None, fs=1, order=5, cutoff_low=None,
raise
ValueError
(
"
Please provide either cutoff_low or cutoff_high.
"
)
raise
ValueError
(
"
Please provide either cutoff_low or cutoff_high.
"
)
h
=
signal
.
firwin
(
order
,
cutoff
,
pass_zero
=
filter_type
,
fs
=
fs
,
window
=
window
)
h
=
signal
.
firwin
(
order
,
cutoff
,
pass_zero
=
filter_type
,
fs
=
fs
,
window
=
window
)
if
causal
:
if
causal
:
y
=
signal
.
lfilter
(
h
,
1.
,
data
[
sel
])
# y = signal.lfilter(h, 1., data[sel])
y
=
signal
.
lfilter
(
h
,
1.
,
data
)
else
:
else
:
padlen
=
padlen
if
padlen
is
not
None
else
3
*
len
(
h
)
padlen
=
padlen
if
padlen
is
not
None
else
3
*
len
(
h
)
# if sum(sel) <= padlen:
# y = np.empty_like(data[sel])
# else:
# with TimeTracking():
# y = signal.filtfilt(h, 1., data[sel], padlen=padlen)
y
=
signal
.
filtfilt
(
h
,
1.
,
data
,
padlen
=
padlen
)
# res[sel] = y
# return res
return
y
def
fir_filter_vectorized_short
(
data
,
time_stamp
=
None
,
fs
=
1
,
order
=
5
,
cutoff_low
=
None
,
cutoff_high
=
None
,
window
=
"
hamming
"
,
h
=
None
,
causal
=
True
,
padlen
=
None
):
"""
Expects numpy array.
"""
sel
=
~
np
.
isnan
(
data
)
res
=
np
.
empty_like
(
data
)
if
sum
(
sel
)
<=
padlen
:
if
sum
(
sel
)
<=
padlen
:
y
=
np
.
empty_like
(
data
[
sel
])
y
=
np
.
empty_like
(
data
[
sel
])
else
:
else
:
...
...
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