Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Grid NAERSTADMO
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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
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
VIPS
Models
GRID
Grid NAERSTADMO
Commits
6f1681b1
Commit
6f1681b1
authored
1 year ago
by
Brita Linnestad
Browse files
Options
Downloads
Patches
Plain Diff
Change logic when counting tif-files for mapfile creation
parent
9591fc27
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
NAERSTADMO.py
+14
-8
14 additions, 8 deletions
NAERSTADMO.py
with
14 additions
and
8 deletions
NAERSTADMO.py
+
14
−
8
View file @
6f1681b1
...
...
@@ -39,13 +39,13 @@ def create_dataset():
# Find the latest file from previous run to create a start date
last_final_date
=
None
list_of_files
=
glob
.
glob
(
f
"
{
outtmp_path
}
final_2[0-9][0-9][0-9]-[01][0-9]-[0123][0-9].nc
"
,
recursive
=
True
)
print
(
list_of_files
)
if
list_of_files
:
latest_file
=
max
(
list_of_files
,
key
=
os
.
path
.
getctime
)
file_name
=
os
.
path
.
basename
(
latest_file
)
file_date
=
file_name
[
file_name
.
index
(
"
final_
"
)
+
6
:
file_name
.
index
(
"
final_
"
)
+
16
]
last_final_date
=
file_date
print
(
last_final_date
)
if
last_final_date
is
None
or
last_final_date
<
file_date
:
start_date
=
datetime
.
strptime
(
os
.
getenv
(
"
START_DATE
"
),
'
%Y-%m-%d
'
)
...
...
@@ -82,9 +82,10 @@ def create_dataset():
create_matrix
()
create_warning_status
(
start_date
)
def
create_warning_status
(
start_date
):
risk
_files
=
glob
.
glob
(
f
"
{
out
file
_path
}
/
RISK
_*.nc
"
)
final
_files
=
glob
.
glob
(
f
"
{
out
tmp
_path
}
/
final
_*.nc
"
)
# Classifying warning status for the WHS model
# 0 == RISK --> Grey
...
...
@@ -92,15 +93,12 @@ def create_warning_status(start_date):
# 1 <= RISK < 2.5 --> Orange
# 2.5 <= RISK --> Red
timestep_dates
=
[]
# Used in the mapfile template
for
file
in
risk_files
:
for
file
in
final_files
:
subprocess
.
run
(
f
'
cdo -aexpr,
"
WARNING_STATUS = RISK < 0 ? 0 : -1; WARNING_STATUS = RISK <= 1 && WARNING_STATUS == -1 ? 2 : WARNING_STATUS; WARNING_STATUS = RISK <= 2.5 && WARNING_STATUS == -1 ? 3 : WARNING_STATUS;WARNING_STATUS = RISK >= 2.5 && WARNING_STATUS == -1 ? 4 : WARNING_STATUS
"
-timmax
{
file
}
{
tmpfile_path
}
result_unmasked.nc
'
,
shell
=
True
)
file_name
=
os
.
path
.
basename
(
file
)
file_date
=
file_name
[
file_name
.
index
(
"
RISK_result
_
"
)
+
12
:
file_name
.
index
(
"
RISK_result
_
"
)
+
22
]
file_date
=
file_name
[
file_name
.
index
(
"
final
_
"
)
+
6
:
file_name
.
index
(
"
final
_
"
)
+
16
]
timestep_dates
.
append
(
file_date
)
# Mask results using a CSV file with polygons
# Env variable MASK_FILE must be set
if
os
.
getenv
(
"
MASK_FILE
"
)
is
not
None
:
...
...
@@ -122,6 +120,14 @@ def create_warning_status(start_date):
subprocess
.
run
(
f
'
gdalwarp -t_srs EPSG:4326
{
tmpfile_path
}
RISK_result_
{
file_date
}
.tif
{
outfile_path
}
RISK_result_
{
file_date
}
.tif
'
,
shell
=
True
,
stdout
=
devnull
)
subprocess
.
run
(
f
'
gdalwarp -t_srs EPSG:4326
{
tmpfile_path
}
IR_result_
{
file_date
}
.tif
{
outfile_path
}
IR_result_
{
file_date
}
.tif
'
,
shell
=
True
,
stdout
=
devnull
)
#Count tif-files to add to mapfile
risk_files
=
glob
.
glob
(
f
"
{
outfile_path
}
/RISK_*.tif
"
)
timestep_dates
=
[]
# Used in the mapfile template
for
file
in
risk_files
:
file_name
=
os
.
path
.
basename
(
file
)
file_date
=
file_name
[
file_name
.
index
(
"
RISK_result_
"
)
+
12
:
file_name
.
index
(
"
RISK_result_
"
)
+
22
]
timestep_dates
.
append
(
file_date
)
# Generate mapfile
# Building data sets for language specific legends
...
...
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