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
23c8ade0
Commit
23c8ade0
authored
4 years ago
by
leufen1
Browse files
Options
Downloads
Patches
Plain Diff
extra loop for each year to prevent memory issues
parent
df510cdb
No related branches found
No related tags found
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
#68275
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
+85
-57
85 additions, 57 deletions
mlair/helpers/filter.py
with
85 additions
and
57 deletions
mlair/helpers/filter.py
+
85
−
57
View file @
23c8ade0
...
...
@@ -531,12 +531,23 @@ class ClimateFIRFilter:
for
var
in
reversed
(
data
.
coords
[
var_dim
].
values
):
# self._tmp_analysis(data, apriori, var, var_dim, length, time_dim, new_dim, h)
logging
.
info
(
f
"
{
data
.
coords
[
'
Stations
'
].
values
[
0
]
}
(
{
var
}
): sel data
"
)
d
=
data
.
sel
({
var_dim
:
[
var
]})
a
=
apriori
.
sel
({
var_dim
:
[
var
]})
_start
=
pd
.
to_datetime
(
data
.
coords
[
time_dim
].
min
().
values
).
year
_end
=
pd
.
to_datetime
(
data
.
coords
[
time_dim
].
max
().
values
).
year
filt_coll
=
[]
for
_year
in
range
(
_start
,
_end
+
1
):
logging
.
info
(
f
"
{
data
.
coords
[
'
Stations
'
].
values
[
0
]
}
(
{
var
}
): year=
{
_year
}
"
)
extend_length
=
length
if
minimum_length
is
None
else
max
(
length
,
minimum_length
+
int
((
length
+
1
)
/
2
))
time_slice
=
self
.
_create_time_range_extend
(
_year
,
sampling
,
extend_length
)
d
=
data
.
sel
({
var_dim
:
[
var
],
time_dim
:
time_slice
})
a
=
apriori
.
sel
({
var_dim
:
[
var
],
time_dim
:
time_slice
})
if
len
(
d
.
coords
[
time_dim
])
==
0
:
# no data at all for this year
continue
# combine historical data / observation [t0-length,t0] and climatological statistics [t0+1,t0+length]
logging
.
info
(
f
"
{
data
.
coords
[
'
Stations
'
].
values
[
0
]
}
(
{
var
}
): history
"
)
extend_length
=
length
if
minimum_length
is
None
else
max
(
length
,
minimum_length
+
int
((
length
+
1
)
/
2
))
if
new_dim
not
in
d
.
coords
:
history
=
self
.
_shift_data
(
d
,
range
(
int
(
-
extend_length
),
1
),
time_dim
,
var_dim
,
new_dim
)
gc
.
collect
()
...
...
@@ -553,6 +564,12 @@ class ClimateFIRFilter:
logging
.
info
(
f
"
{
data
.
coords
[
'
Stations
'
].
values
[
0
]
}
(
{
var
}
): concat to filter input
"
)
filter_input_data
=
xr
.
concat
([
history
.
dropna
(
time_dim
),
future
],
dim
=
new_dim
,
join
=
"
left
"
)
try
:
filter_input_data
=
filter_input_data
.
sel
({
time_dim
:
str
(
_year
)})
except
KeyError
:
# no valid data for this year
continue
if
len
(
filter_input_data
.
coords
[
time_dim
])
==
0
:
# no valid data for this year
continue
# filter_input_data = history.combine_first(future)
# history.sel(datetime=slice("2010-11-01", "2011-04-01"),variables="o3").plot()
# filter_input_data.sel(datetime=slice("2009-11-01", "2011-04-01"),variables="temp").plot()
...
...
@@ -576,24 +593,27 @@ class ClimateFIRFilter:
vectorize
=
True
,
kwargs
=
{
"
h
"
:
h
})
filt_coll
.
append
(
filt
.
sel
({
new_dim
:
slice
(
-
extend_length
,
0
)},
drop
=
True
))
# plot
# ToDo: enable plotting again
if
self
.
plot_path
is
not
None
:
for
i
,
time_pos
in
enumerate
([
0.25
,
1.5
,
2.75
,
4
]):
# [0.25, 1.5, 2.75, 4] x 365 days
try
:
pos
=
int
(
time_pos
*
365
*
fs
)
filter_example
=
filter_input_data
.
isel
({
time_dim
:
pos
})
t0
=
filter_example
.
coords
[
time_dim
].
values
t_slice
=
filter_input_data
.
isel
(
{
time_dim
:
slice
(
pos
-
int
((
length
-
1
)
/
2
),
pos
+
int
((
length
-
1
)
/
2
)
+
1
)}).
coords
[
time_dim
].
values
# self.plot(d, filter_example, var_dim, time_dim, t_slice, t0, f"{plot_index}_{i}")
except
IndexError
:
pass
#
if self.plot_path is not None:
#
for i, time_pos in enumerate([0.25, 1.5, 2.75, 4]): # [0.25, 1.5, 2.75, 4] x 365 days
#
try:
#
pos = int(time_pos * 365 * fs)
#
filter_example = filter_input_data.isel({time_dim: pos})
#
t0 = filter_example.coords[time_dim].values
#
t_slice = filter_input_data.isel(
#
{time_dim: slice(pos - int((length - 1) / 2), pos + int((length - 1) / 2) + 1)}).coords[
#
time_dim].values
#
# self.plot(d, filter_example, var_dim, time_dim, t_slice, t0, f"{plot_index}_{i}")
#
except IndexError:
#
pass
# select only values at tmp dimension 0 at each point in time
# coll.append(filt.sel({new_dim: 0}, drop=True))
coll
.
append
(
filt
.
sel
({
new_dim
:
slice
(
-
extend_length
,
0
)},
drop
=
True
))
# coll.append(filt.sel({new_dim: slice(-extend_length, 0)}, drop=True))
coll
.
append
(
xr
.
concat
(
filt_coll
,
time_dim
))
gc
.
collect
()
logging
.
info
(
f
"
{
data
.
coords
[
'
Stations
'
].
values
[
0
]
}
: concat all variables
"
)
...
...
@@ -607,6 +627,14 @@ class ClimateFIRFilter:
res_full
.
loc
[
res
.
coords
]
=
res
.
transpose
(
*
dims
)
return
res_full
,
h
,
apriori
@staticmethod
def
_create_time_range_extend
(
year
,
sampling
,
extend_length
):
td_type
=
{
"
1d
"
:
"
D
"
,
"
1H
"
:
"
h
"
}.
get
(
sampling
)
delta
=
np
.
timedelta64
(
extend_length
+
1
,
td_type
)
start
=
np
.
datetime64
(
f
"
{
year
}
-01-01
"
)
-
delta
end
=
np
.
datetime64
(
f
"
{
year
}
-12-31
"
)
+
delta
return
slice
(
start
,
end
)
@staticmethod
def
_create_tmp_dimension
(
data
):
new_dim
=
"
window
"
...
...
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