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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
esde
machine-learning
MLAir
Commits
f632ea35
Commit
f632ea35
authored
Mar 31, 2021
by
Felix Kleinert
Browse files
Options
Downloads
Patches
Plain Diff
prepare sector assingmnet
parent
0ebe5a99
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!259
Draft: Resolve "WRF-Datahandler should inherit from SingleStationDatahandler"
Pipeline
#64668
passed
Mar 31, 2021
Stage: test
Stage: docs
Stage: pages
Stage: deploy
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
mlair/data_handler/data_handler_wrf_chem.py
+62
-10
62 additions, 10 deletions
mlair/data_handler/data_handler_wrf_chem.py
with
62 additions
and
10 deletions
mlair/data_handler/data_handler_wrf_chem.py
+
62
−
10
View file @
f632ea35
...
...
@@ -548,16 +548,17 @@ class DataHandlerSingleGridColumn(DataHandlerSingleStation):
self
.
make_history_window
(
self
.
target_dim
,
self
.
window_history_size
,
self
.
time_dim
)
if
self
.
var_logical_z_coord_selector
is
not
None
:
self
.
history
=
self
.
history
.
sel
({
self
.
_logical_z_coord_name
:
self
.
var_logical_z_coord_selector
})
self
.
history
=
self
.
modify_history
()
self
.
make_labels
(
self
.
target_dim
,
self
.
target_var
,
self
.
time_dim
,
self
.
window_lead_time
)
self
.
make_observation
(
self
.
target_dim
,
self
.
target_var
,
self
.
time_dim
)
if
self
.
targetvar_logical_z_coord_selector
is
not
None
:
self
.
label
=
self
.
label
.
sel
({
self
.
_logical_z_coord_name
:
self
.
targetvar_logical_z_coord_selector
})
self
.
observation
=
self
.
observation
.
sel
(
{
self
.
_logical_z_coord_name
:
self
.
targetvar_logical_z_coord_selector
})
self
.
remove_nan
(
self
.
time_dim
)
self
.
history
=
self
.
modify_history
()
self
.
label
=
self
.
modify_label
()
self
.
observation
=
self
.
modify_observation
()
self
.
remove_nan
(
self
.
time_dim
)
# self.input_data = self.input_data.compute()
# self.label = self.label.compute()
...
...
@@ -686,11 +687,11 @@ class DataHandlerSectorGrid(DataHandlerSingleGridColumn):
trafo_opts
=
self
.
_transformation
[
pos_of_trafo
]
return
trafo_opts
def
apply_transformation_on_
wind_sector_edges
(
self
,
ws_edges
):
ws_
trafo_opts
=
self
.
get_transformation_opts
()
ws_
trafo
,
_
=
self
.
transform
(
ws_edges
,
dim
=
self
.
aggregation_dim
,
inverse
=
False
,
opts
=
ws_
trafo_opts
,
transformation_dim
=
self
.
target_dim
)
return
ws_
trafo
def
apply_transformation_on_
data
(
self
,
data
):
trafo_opts
=
self
.
get_transformation_opts
()
trafo
,
_
=
self
.
transform
(
data
,
dim
=
self
.
aggregation_dim
,
inverse
=
False
,
opts
=
trafo_opts
,
transformation_dim
=
self
.
target_dim
)
return
trafo
def
modify_history
(
self
):
if
self
.
transformation_is_applied
:
...
...
@@ -699,12 +700,63 @@ class DataHandlerSectorGrid(DataHandlerSingleGridColumn):
sector_allocation
=
self
.
windsector
.
get_sect_of_value
(
value
=
wind_dir_of_interest
,
external_edges
=
ws_edges
)
existing_sectors
=
np
.
unique
(
sector_allocation
.
data
)
with
self
.
loader
as
loader
:
pass
#circular_data = loader.data[self.variables].where(loader.geo_infos.dist.squeeze() <= self.radius)
# setup sector history
sector_history
=
xr
.
ones_like
(
self
.
history
)
sector_history_var_names
=
[
f
"
{
var
}
_sect
"
for
var
in
sector_history
.
coords
[
self
.
target_dim
].
values
]
# sector_history = sector_history.assign_coords({self.target_dim: sector_history_var_names})
grid_data
=
self
.
preselect_and_transform_neighbouring_data_based_on_radius
(
loader
)
for
sect
in
existing_sectors
:
# select data in wind sector
sec_data
=
self
.
get_section_data_from_circle
(
grid_data
,
loader
,
sect
)
sec_data
=
self
.
apply_aggregation_method_on_sector_data
(
sec_data
,
loader
)
# loader.data.T2.where(loader.geo_infos.dist.sel({'points': 0}).drop('points') <= self.radius).where(
# self.windsector.is_in_sector(sect, loader.geo_infos.bearing))
#
# loader.data[self.variables].sel(
# {self.time_dim: self.history.coords[self.time_dim].values}).where(
# loader.geo_infos.dist.sel({'points': 0}).drop('points') <= self.radius).where(
# self.windsector.is_in_sector(sect,
# loader.geo_infos.bearing.drop('points').squeeze()))
return
self
.
history
def
get_section_data_from_circle
(
self
,
grid_data
,
loader
,
sect
):
sec_data
=
grid_data
.
where
(
self
.
windsector
.
is_in_sector
(
sect
,
loader
.
geo_infos
.
bearing
.
drop
(
'
points
'
).
squeeze
()))
return
sec_data
def
preselect_and_transform_neighbouring_data_based_on_radius
(
self
,
loader
):
"""
Select neighbouring grid boxes which have a maximal distance of pre-selected radius from full model field
:param loader:
:type loader:
:return:
:rtype:
"""
# get data from loader
grid_data
=
loader
.
data
[
self
.
variables
]
# select correct time steps and vertical layers
grid_data
=
grid_data
.
sel
({
# self.time_dim: self.history.coords[self.time_dim].values, # get data which is used in history
self
.
time_dim
:
slice
(
self
.
start
,
self
.
end
),
# get data which is used in history
self
.
_logical_z_coord_name
:
self
.
var_logical_z_coord_selector
,
# get only used vertical layers
})
# select grid boxes which are closer than given radius
grid_data
=
grid_data
.
where
(
loader
.
geo_infos
.
dist
.
sel
({
"
points
"
:
0
}).
drop
(
"
points
"
)
<=
self
.
radius
)
# apply transformation on variables
grid_data
=
self
.
apply_transformation_on_data
(
grid_data
.
to_array
(
self
.
target_dim
)).
to_dataset
(
self
.
target_dim
)
return
grid_data
def
apply_aggregation_method_on_sector_data
(
self
,
data
,
loader
):
data
=
data
.
mean
(
dim
=
(
loader
.
logical_x_coord_name
,
loader
.
logical_y_coord_name
))
return
data
def
compute_wind_dir_of_interest
(
self
):
wind_dir_of_intrest
=
self
.
history
.
sel
({
self
.
target_dim
:
self
.
wind_dir_name
,
self
.
window_dim
:
0
})
return
wind_dir_of_intrest
...
...
@@ -712,7 +764,7 @@ class DataHandlerSectorGrid(DataHandlerSingleGridColumn):
@TimeTrackingWrapper
def
get_applied_transdormation_on_wind_sector_edges
(
self
):
ws_edges
=
self
.
_get_left_and_right_wind_sector_edges
(
return_as
=
'
xr.da
'
,
dim
=
self
.
wind_sector_edge_dim_name
)
ws_edges
=
self
.
apply_transformation_on_
wind_sector_edges
(
ws_edges
)
ws_edges
=
self
.
apply_transformation_on_
data
(
ws_edges
)
return
ws_edges
# def set_inputs_and_targets(self):
...
...
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
sign in
to comment