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
aef6282a
Commit
aef6282a
authored
4 years ago
by
Felix Kleinert
Browse files
Options
Downloads
Patches
Plain Diff
integrate WRF for datahandler
parent
48a1b6ef
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!259
Draft: Resolve "WRF-Datahandler should inherit from SingleStationDatahandler"
Pipeline
#61995
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/data_handler/data_handler_wrf_chem.py
+26
-8
26 additions, 8 deletions
mlair/data_handler/data_handler_wrf_chem.py
with
26 additions
and
8 deletions
mlair/data_handler/data_handler_wrf_chem.py
+
26
−
8
View file @
aef6282a
...
@@ -12,10 +12,12 @@ import os
...
@@ -12,10 +12,12 @@ import os
from
mlair.helpers.geofunctions
import
haversine_dist
from
mlair.helpers.geofunctions
import
haversine_dist
from
mlair.helpers.helpers
import
convert2xrda
,
remove_items
from
mlair.helpers.helpers
import
convert2xrda
,
remove_items
from
mlair.helpers
import
TimeTrackingWrapper
from
mlair.helpers
import
TimeTrackingWrapper
from
typing
import
Tuple
,
Union
,
List
,
Dict
from
mlair.data_handler.abstract_data_handler
import
AbstractDataHandler
from
mlair.data_handler.data_handler_single_station
import
DataHandlerSingleStation
from
mlair.data_handler.data_handler_single_station
import
DataHandlerSingleStation
from
mlair.data_handler
import
DefaultDataHandler
from
typing
import
Tuple
,
Union
,
List
,
Dict
import
logging
import
logging
import
cartopy.crs
as
ccrs
import
cartopy.crs
as
ccrs
...
@@ -170,6 +172,8 @@ class SingleGridColumnWrfChemDataLoader(BaseWrfChemDataLoader):
...
@@ -170,6 +172,8 @@ class SingleGridColumnWrfChemDataLoader(BaseWrfChemDataLoader):
self
.
external_coords_file
=
external_coords_file
self
.
external_coords_file
=
external_coords_file
self
.
open_data
()
self
.
open_data
()
if
self
.
physical_t_coord_name
!=
self
.
time_dim_name
:
self
.
assign_coords
(
self
.
assign_coords
(
{
self
.
physical_t_coord_name
:
(
self
.
time_dim_name
,
self
.
_data
[
self
.
physical_t_coord_name
].
values
)})
{
self
.
physical_t_coord_name
:
(
self
.
time_dim_name
,
self
.
_data
[
self
.
physical_t_coord_name
].
values
)})
...
@@ -194,7 +198,7 @@ class SingleGridColumnWrfChemDataLoader(BaseWrfChemDataLoader):
...
@@ -194,7 +198,7 @@ class SingleGridColumnWrfChemDataLoader(BaseWrfChemDataLoader):
raise
SyntaxError
(
f
"
`coords
'
must have length=2 (lat, lon), but has length=
{
len
(
coords
)
}
"
)
raise
SyntaxError
(
f
"
`coords
'
must have length=2 (lat, lon), but has length=
{
len
(
coords
)
}
"
)
if
isinstance
(
coords
,
tuple
):
if
isinstance
(
coords
,
tuple
):
self
.
__coords
=
dict
(
lat
=
coords
[
0
],
lon
=
coords
[
1
])
self
.
__coords
=
dict
(
lat
=
coords
[
0
],
lon
=
coords
[
1
])
print
(
f
"
self.__c
oords=
{
self
.
__coords
}
"
)
logging
.
debug
(
f
"
{
self
.
__c
lass__
.
__name__
}
.__coords is set to
{
self
.
__coords
}
"
)
elif
isinstance
(
coords
,
dict
):
elif
isinstance
(
coords
,
dict
):
if
(
coords
.
keys
()
==
__set_coords
.
keys
()):
if
(
coords
.
keys
()
==
__set_coords
.
keys
()):
self
.
__coords
=
coords
self
.
__coords
=
coords
...
@@ -263,13 +267,19 @@ class DataHandlerSingleGridColumn2(DataHandlerSingleStation):
...
@@ -263,13 +267,19 @@ class DataHandlerSingleGridColumn2(DataHandlerSingleStation):
lat
,
lon
=
self
.
str2coords
(
station
)
lat
,
lon
=
self
.
str2coords
(
station
)
sgc_loader
=
SingleGridColumnWrfChemDataLoader
((
lat
,
lon
),
sgc_loader
=
SingleGridColumnWrfChemDataLoader
((
lat
,
lon
),
data_path
=
path
,
data_path
=
path
,
rechunk_values
=
{
'
Time
'
:
1
,
'
bottom_top
'
:
2
},
external_coords_file
=
self
.
external_coords_file
,
external_coords_file
=
self
.
external_coords_file
,
time_dim_name
=
self
.
time_dim
)
)
# select defined variables at grid box or grid coloumn based on nearest icoords
data
=
sgc_loader
.
data
.
isel
(
sgc_loader
.
get_nearest_icoords
()).
squeeze
()[
self
.
variables
]
data
=
sgc_loader
.
data
.
isel
(
sgc_loader
.
get_nearest_icoords
()).
squeeze
()[
self
.
variables
]
data
=
data
.
expand_dims
({
self
.
iter_dim
:
station
}).
to_array
()
# expand dimesion for iterdim
data
=
data
.
transpose
(
self
.
iter_dim
,
self
.
time_dim
,
'
variable
'
,
sgc_loader
.
logical_z_coord_name
)
data
=
data
.
expand_dims
({
self
.
iter_dim
:
station
}).
to_array
(
self
.
target_dim
)
# transpose dataarray: set first three fixed and keep remaining as is
data
=
data
.
transpose
(
self
.
iter_dim
,
self
.
time_dim
,
self
.
target_dim
,
...)
data
=
self
.
_slice_prep
(
data
,
start
=
start
,
end
=
end
)
# data = self.check_for_negative_concentrations(data)
# ToDo
# ToDo
# data should somehow look like this:
# data should somehow look like this:
# < xarray.DataArray(Stations: 1, datetime: 7670, variables: 9) (From DataHandlerSingleStation)
# < xarray.DataArray(Stations: 1, datetime: 7670, variables: 9) (From DataHandlerSingleStation)
...
@@ -311,6 +321,14 @@ class DataHandlerSingleGridColumn2(DataHandlerSingleStation):
...
@@ -311,6 +321,14 @@ class DataHandlerSingleGridColumn2(DataHandlerSingleStation):
# raise NotImplementedError
# raise NotImplementedError
class
DataHandlerWRF
(
DefaultDataHandler
):
"""
Data handler using CDC.
"""
data_handler
=
DataHandlerSingleGridColumn2
data_handler_transformation
=
DataHandlerSingleGridColumn2
_requirements
=
data_handler
.
requirements
()
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
def
plot_map_proj
(
data
,
xlim
=
None
,
ylim
=
None
,
filename
=
None
,
point
=
None
):
def
plot_map_proj
(
data
,
xlim
=
None
,
ylim
=
None
,
filename
=
None
,
point
=
None
):
...
...
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