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
cd2d0cc7
Commit
cd2d0cc7
authored
3 years ago
by
Frisinghelli Daniel
Browse files
Options
Downloads
Patches
Plain Diff
Check if target file already exists.
parent
ec6d1af3
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
climax/main/downscale_infer.py
+17
-12
17 additions, 12 deletions
climax/main/downscale_infer.py
with
17 additions
and
12 deletions
climax/main/downscale_infer.py
+
17
−
12
View file @
cd2d0cc7
...
...
@@ -24,7 +24,7 @@ from climax.core.utils import split_date_range
from
climax.main.config
import
(
ERA5_PREDICTORS
,
ERA5_PLEVELS
,
PREDICTAND
,
NET
,
VALID_PERIOD
,
BATCH_SIZE
,
NORM
,
DOY
,
NYEARS
,
DEM
,
DEM_FEATURES
,
LOSS
,
ANOMALIES
,
OPTIM
,
OPTIM_PARAMS
,
CHUNKS
,
LR_SCHEDULER
)
OPTIM_PARAMS
,
CHUNKS
,
LR_SCHEDULER
,
OVERWRITE
)
from
climax.main.io
import
ERA5_PATH
,
DEM_PATH
,
MODEL_PATH
,
TARGET_PATH
# module level logger
...
...
@@ -46,6 +46,22 @@ if __name__ == '__main__':
# path to model state
state_file
=
MODEL_PATH
.
joinpath
(
PREDICTAND
,
state_file
)
# load pretrained model
if
state_file
.
exists
():
# load pretrained network
net
,
_
=
Network
.
load_pretrained_model
(
state_file
,
NET
)
else
:
# initialize OBS predictand dataset
LOGGER
.
info
(
'
{} does not exist.
'
.
format
(
state_file
))
sys
.
exit
()
# check if target dataset already exists
target
=
TARGET_PATH
.
joinpath
(
PREDICTAND
,
net
.
state_file
.
name
.
replace
(
net
.
state_file
.
suffix
,
'
.nc
'
))
if
target
.
exists
()
and
not
OVERWRITE
:
LogConfig
.
init_log
(
'
{} already exists.
'
.
format
(
target
))
sys
.
exit
()
# initialize logging
log_file
=
MODEL_PATH
.
joinpath
(
PREDICTAND
,
state_file
.
name
.
replace
(
'
.pt
'
,
'
_log.txt
'
))
...
...
@@ -78,15 +94,6 @@ if __name__ == '__main__':
# add dem to set of predictor variables
Era5_ds
=
xr
.
merge
([
Era5_ds
,
dem
]).
chunk
(
Era5_ds
.
chunks
)
# load pretrained model
if
state_file
.
exists
():
# load pretrained network
net
,
_
=
Network
.
load_pretrained_model
(
state_file
,
NET
)
else
:
# initialize OBS predictand dataset
LOGGER
.
info
(
'
{} does not exist.
'
.
format
(
state_file
))
sys
.
exit
()
# subset to reference period and predict in NYEAR intervals
trg_ds
=
[]
for
dates
in
split_date_range
(
VALID_PERIOD
[
0
],
VALID_PERIOD
[
-
1
],
...
...
@@ -103,8 +110,6 @@ if __name__ == '__main__':
trg_ds
=
xr
.
concat
(
trg_ds
,
dim
=
'
time
'
)
# save model predictions as NetCDF file
target
=
TARGET_PATH
.
joinpath
(
PREDICTAND
,
net
.
state_file
.
name
.
replace
(
net
.
state_file
.
suffix
,
'
.nc
'
))
if
not
target
.
parent
.
exists
():
target
.
parent
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
LOGGER
.
info
(
'
Saving network predictions: {}.
'
.
format
(
target
))
...
...
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