Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Climax
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
earth_observation_public
Climax
Commits
53d94223
Commit
53d94223
authored
3 years ago
by
Frisinghelli Daniel
Browse files
Options
Downloads
Patches
Plain Diff
Initial implementation of downscaling script.
parent
fef4fa2b
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
climax/core/constants.py
+6
-6
6 additions, 6 deletions
climax/core/constants.py
climax/main/config.py
+64
-5
64 additions, 5 deletions
climax/main/config.py
climax/main/downscale.py
+53
-0
53 additions, 0 deletions
climax/main/downscale.py
with
123 additions
and
11 deletions
climax/core/constants.py
+
6
−
6
View file @
53d94223
...
...
@@ -31,18 +31,18 @@ EUROCORDEX_RCMS = ['SMHI-RCA4', 'CLMcom-CCLM4-8-17',
# climate data operator (cdo) resampling modes
CDO_RESAMPLING_MODES
=
[
'
bilinear
'
,
'
conservative
'
]
# ERA5 variables on pressure levels
# ERA5
predictor
variables on pressure levels
ERA5_P_VARIABLES
=
[
'
geopotential
'
,
'
temperature
'
,
'
u_component_of_wind
'
,
'
v_component_of_wind
'
,
'
specific_humidity
'
]
# ERA5 variables on single levels
# ERA5
predictor
variables on single levels
ERA5_S_VARIABLES
=
[
'
mean_sea_level_pressure
'
]
# ERA5 variables
# ERA5
predictor
variables
ERA5_VARIABLES
=
ERA5_P_VARIABLES
+
ERA5_S_VARIABLES
# ERA5 pressure levels
ERA5_PLEVELS
=
[
500
,
850
]
# name of target projection
PROJECTION
=
'
lambert_azimuthal_equal_area
'
# predictand variables: covered by observations
PREDICTANDS
=
[
'
tasmin
'
,
'
tasmax
'
,
'
pr
'
]
This diff is collapsed.
Click to expand it.
climax/main/config.py
+
64
−
5
View file @
53d94223
...
...
@@ -7,12 +7,71 @@
import
pathlib
import
datetime
# externals
import
numpy
as
np
# locals
from
climax.core.constants
import
PREDICTANDS
# -----------------------------------------------------------------------------
# Paths to input data ---------------------------------------------------------
# -----------------------------------------------------------------------------
# project root path
ROOT
=
pathlib
.
Path
(
'
/mnt/CEPH_PROJECTS/FACT_CLIMAX/
'
)
# path to this file
HERE
=
pathlib
.
Path
(
__file__
).
parent
# calibration period
P_CAL
=
(
datetime
.
datetime
.
strptime
(
'
1981-01-01
'
,
'
%Y-%m-%d
'
).
date
(),
datetime
.
datetime
.
strptime
(
'
2011-01-01
'
,
'
%Y-%m-%d
'
).
date
())
# path to ERA5 reanalysis data
ERA5_PATH
=
pathlib
.
Path
(
'
/mnt/CEPH_PROJECTS/FACT_CLIMAX/REANALYSIS/
'
)
ERA5_PATH
=
ROOT
.
joinpath
(
'
REANALYSIS
'
)
# path to OBServation data
OBS_PATH
=
ROOT
.
joinpath
(
'
OBSERVATION
'
)
# path to save trained models
MODEL_PATH
=
ROOT
.
joinpath
(
'
Models
'
)
# -----------------------------------------------------------------------------
# ERA5 downscaling configuration ----------------------------------------------
# -----------------------------------------------------------------------------
# ERA5 predictor variables on pressure levels
# ERA5_P_PREDICTORS = ERA5_P_VARIABLES
# # ERA5 predictor variables on single levels
# ERA5_S_PREDICTORS = ERA5_S_VARIABLES
# # ERA5 predictor variables
# ERA5_PREDICTORS = ERA5_VARIABLES
# ERA5 pressure levels
ERA5_PLEVELS
=
[
500
,
850
]
# -----------------------------------------------------------------------------
# Observations ----------------------------------------------------------------
# -----------------------------------------------------------------------------
# target variable: check if target variable is valid
PREDICTAND
=
'
tasmin
'
assert
PREDICTAND
in
PREDICTANDS
# -----------------------------------------------------------------------------
# Calibration period ---------------------------------------------------------
# -----------------------------------------------------------------------------
# calibration period: training and validation
CALIB_PERIOD
=
np
.
arange
(
datetime
.
datetime
.
strptime
(
'
1981-01-01
'
,
'
%Y-%m-%d
'
).
date
(),
datetime
.
datetime
.
strptime
(
'
2011-01-01
'
,
'
%Y-%m-%d
'
).
date
())
# -----------------------------------------------------------------------------
# Model training configuration ------------------------------------------------
# -----------------------------------------------------------------------------
# whether to randomly shuffle time steps or to conserve time series for model
# training
SHUFFLE
=
False
# batch size: number of time steps processed by the net in each iteration
BATCH_SIZE
=
64
This diff is collapsed.
Click to expand it.
climax/main/downscale.py
0 → 100644
+
53
−
0
View file @
53d94223
"""
Dynamical climate downscaling using deep convolutional neural networks.
"""
# !/usr/bin/env python
# -*- coding: utf-8 -*-
# externals
import
xarray
as
xr
from
sklearn.model_selection
import
train_test_split
from
torch.utils.data
import
DataLoader
# locals
from
pysegcnn.core.utils
import
search_files
from
pysegcnn.core.models
import
SegNet
from
climax.core.dataset
import
ERA5Dataset
,
NetCDFDataset
from
climax.core.constants
import
(
ERA5_P_VARIABLES
,
ERA5_S_VARIABLES
,
ERA5_VARIABLES
)
from
climax.main.config
import
(
ERA5_PATH
,
ERA5_PLEVELS
,
OBS_PATH
,
PREDICTAND
,
CALIB_PERIOD
,
MODEL_PATH
,
SHUFFLE
,
BATCH_SIZE
)
if
__name__
==
'
__main__
'
:
# initialize ERA5 predictor dataset
Era5
=
ERA5Dataset
(
ERA5_PATH
,
ERA5_VARIABLES
,
plevels
=
ERA5_PLEVELS
)
Era5_ds
=
Era5
.
merge
()
# initialize OBS predictand dataset
Obs_ds
=
search_files
(
OBS_PATH
.
joinpath
(
PREDICTAND
),
'
.nc$
'
).
pop
()
Obs_ds
=
xr
.
open_dataset
(
Obs_ds
)
# split calibration period into training and validation period
train
,
valid
=
train_test_split
(
CALIB_PERIOD
,
shuffle
=
SHUFFLE
)
# training and validation dataset
Era5_train
,
Obs_train
=
Era5_ds
.
sel
(
time
=
train
),
Obs_ds
.
sel
(
time
=
train
)
Era5_valid
,
Obs_valid
=
Era5_ds
.
sel
(
time
=
valid
),
Obs_ds
.
sel
(
time
=
valid
)
# create PyTorch compliant dataset and dataloader instances for model
# training
train_ds
=
NetCDFDataset
(
Era5_train
,
Obs_train
,
dim
=
'
time
'
)
valid_ds
=
NetCDFDataset
(
Era5_valid
,
Obs_valid
,
dim
=
'
time
'
)
train_dl
=
DataLoader
(
train_ds
,
batch_size
=
BATCH_SIZE
,
shuffle
=
SHUFFLE
,
drop_last
=
False
)
valid_dl
=
DataLoader
(
valid_ds
,
batch_size
=
BATCH_SIZE
,
shuffle
=
SHUFFLE
,
drop_last
=
False
)
# initialize network: calculate number of input variables
in_channels
=
int
(
len
(
ERA5_P_VARIABLES
)
*
len
(
ERA5_PLEVELS
)
+
len
(
ERA5_S_VARIABLES
))
net
=
SegNet
(
MODEL_PATH
.
joinpath
(
PREDICTAND
+
'
.pt
'
),
in_channels
,
1
)
# initialize network training
# TODO: Extend ClassificationNetworkTrainer -> RegressionNetworkTrainer
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