Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Grid SEPTREFHUM
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
VIPS
Models
GRID
Grid SEPTREFHUM
Commits
9231833a
Commit
9231833a
authored
1 year ago
by
Tor-Einar Skog
Browse files
Options
Downloads
Patches
Plain Diff
Add i18n and Json based legends
parent
acc9d2b6
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
SEPTREFHUM.cfg
+17
-0
17 additions, 0 deletions
SEPTREFHUM.cfg
SEPTREFHUM.py
+18
-2
18 additions, 2 deletions
SEPTREFHUM.py
mapfile/template.j2
+46
-6
46 additions, 6 deletions
mapfile/template.j2
with
81 additions
and
8 deletions
SEPTREFHUM.cfg
0 → 100644
+
17
−
0
View file @
9231833a
[i18n]
# 1st is the default language
languages
=
en,nb
[i18n.en]
no_risk
=
No infection risk
low_risk
=
Low infection risk
medium_risk
=
Medium infection risk
high_risk
=
High infection risk
whs
=
Wet Hour Sum (0-72)
[i18n.nb]
no_risk
=
Ingen infeksjonsrisiko
low_risk
=
Lav infeksjonsrisiko
medium_risk
=
Middels infeksjonsrisiko
high_risk
=
Høy infeksjonsrisiko
whs
=
Sum fuktige timer (0-72)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
SEPTREFHUM.py
+
18
−
2
View file @
9231833a
...
@@ -29,10 +29,15 @@ from datetime import datetime, timezone, timedelta
...
@@ -29,10 +29,15 @@ from datetime import datetime, timezone, timedelta
from
jinja2
import
Environment
,
FileSystemLoader
from
jinja2
import
Environment
,
FileSystemLoader
import
pytz
import
pytz
import
netCDF4
as
nc
import
netCDF4
as
nc
import
configparser
# Paths config
# Paths config
# Create a .env file from dotenv-sample
# Create a .env file from dotenv-sample
load_dotenv
()
load_dotenv
()
# Get language stuff
config
=
configparser
.
ConfigParser
()
config
.
read
(
"
SEPTREFHUM.cfg
"
)
# Path to weather data
# Path to weather data
infile_path
=
os
.
getenv
(
"
WEATHER_DATA_DIR
"
)
infile_path
=
os
.
getenv
(
"
WEATHER_DATA_DIR
"
)
# Path to store generated GeoTIFF files
# Path to store generated GeoTIFF files
...
@@ -186,7 +191,6 @@ for timestep in timesteps:
...
@@ -186,7 +191,6 @@ for timestep in timesteps:
if
os
.
path
.
isfile
(
f
'
{
outfile_path
}
result_WARNING_STATUS_
{
file_date
}
.tif
'
)
and
os
.
path
.
isfile
(
f
'
{
outfile_path
}
result_
{
file_date
}
.tif
'
):
if
os
.
path
.
isfile
(
f
'
{
outfile_path
}
result_WARNING_STATUS_
{
file_date
}
.tif
'
)
and
os
.
path
.
isfile
(
f
'
{
outfile_path
}
result_
{
file_date
}
.tif
'
):
continue
continue
# Create NetCDF result file
# Create NetCDF result file
subprocess
.
run
(
f
'
cdo -s -seltimestep,
{
timestep_index
}
/
{
timestep_index
}
{
tmpfile_path
}
result.nc
{
tmpfile_path
}
result_
{
file_date
}
.nc
'
,
shell
=
True
)
subprocess
.
run
(
f
'
cdo -s -seltimestep,
{
timestep_index
}
/
{
timestep_index
}
{
tmpfile_path
}
result.nc
{
tmpfile_path
}
result_
{
file_date
}
.nc
'
,
shell
=
True
)
# Convert to GeoTIFF
# Convert to GeoTIFF
...
@@ -205,6 +209,16 @@ for timestep in timesteps:
...
@@ -205,6 +209,16 @@ for timestep in timesteps:
timestep_index
=
timestep_index
+
1
timestep_index
=
timestep_index
+
1
# Generate mapfile
# Generate mapfile
# Building data sets for language specific legends
languages
=
[]
language_codes
=
config
[
"
i18n
"
][
"
languages
"
].
split
(
"
,
"
);
for
language_code
in
language_codes
:
language
=
{
"
language_code
"
:
language_code
}
if
(
"
i18n.%s
"
%
language_code
)
in
config
:
for
keyword
in
config
[
"
i18n.%s
"
%
language_code
]:
language
[
keyword
]
=
config
[
"
i18n.%s
"
%
language_code
][
keyword
]
languages
.
append
(
language
)
# The paths should be set in a .env file
# The paths should be set in a .env file
env
=
Environment
(
loader
=
FileSystemLoader
(
'
.
'
))
env
=
Environment
(
loader
=
FileSystemLoader
(
'
.
'
))
template
=
env
.
get_template
(
"
mapfile/template.j2
"
)
template
=
env
.
get_template
(
"
mapfile/template.j2
"
)
...
@@ -214,7 +228,9 @@ output = template.render({
...
@@ -214,7 +228,9 @@ output = template.render({
"
mapserver_mapfile_dir
"
:
os
.
getenv
(
"
MAPSERVER_MAPFILE_DIR
"
),
"
mapserver_mapfile_dir
"
:
os
.
getenv
(
"
MAPSERVER_MAPFILE_DIR
"
),
"
mapserver_log_file
"
:
os
.
getenv
(
"
MAPSERVER_LOG_FILE
"
),
"
mapserver_log_file
"
:
os
.
getenv
(
"
MAPSERVER_LOG_FILE
"
),
"
mapserver_image_path
"
:
os
.
getenv
(
"
MAPSERVER_IMAGE_PATH
"
),
"
mapserver_image_path
"
:
os
.
getenv
(
"
MAPSERVER_IMAGE_PATH
"
),
"
mapserver_extent
"
:
os
.
getenv
(
"
MAPSERVER_EXTENT
"
)
"
mapserver_extent
"
:
os
.
getenv
(
"
MAPSERVER_EXTENT
"
),
"
languages
"
:
languages
,
"
language_codes
"
:
language_codes
})
})
mapfile_outdir
=
os
.
getenv
(
"
MAPFILE_DIR
"
)
mapfile_outdir
=
os
.
getenv
(
"
MAPFILE_DIR
"
)
with
open
(
f
"
{
mapfile_outdir
}
/SEPTREFHUM.map
"
,
'
w
'
)
as
f
:
with
open
(
f
"
{
mapfile_outdir
}
/SEPTREFHUM.map
"
,
'
w
'
)
as
f
:
...
...
This diff is collapsed.
Click to expand it.
mapfile/template.j2
+
46
−
6
View file @
9231833a
...
@@ -36,6 +36,10 @@ WEB
...
@@ -36,6 +36,10 @@ WEB
# i18n support: https://mapserver.org/ogc/inspire.html#inspire-multi-language-support
# i18n support: https://mapserver.org/ogc/inspire.html#inspire-multi-language-support
METADATA
METADATA
"wms_keywordlist" "VIPS model Septoria Reference Humidity Model (SEPTREFHUM)"
"wms_keywordlist" "VIPS model Septoria Reference Humidity Model (SEPTREFHUM)"
{% if languages %}
"wms_inspire_capabilities" "embed"
"wms_languages" "{{ language_codes|join(",")}}" # The first is the default
{% endif %}
"wms_abstract" "<div id='preamble'>
"wms_abstract" "<div id='preamble'>
<p>The reference humidity model was developed as a supplement to
<p>The reference humidity model was developed as a supplement to
the Humidity model. In this model 20 consecutive hours are
the Humidity model. In this model 20 consecutive hours are
...
@@ -71,12 +75,6 @@ WEB
...
@@ -71,12 +75,6 @@ WEB
The reference humidity model is considered as a weather based submodel
The reference humidity model is considered as a weather based submodel
for the risk of Septoria, Easy to map and calculate based on weather data alone.</p>
for the risk of Septoria, Easy to map and calculate based on weather data alone.</p>
<h3>How to interpret the warning status</h3>
<ul>
<li>Green: High risk of infection</li>
<li>Yellow: Medium risk of infection</li>
<li>Red: Medium risk of infection</li>
</ul>
<h3>Explanation of parameters</h3>
<h3>Explanation of parameters</h3>
<ul>
<ul>
<li>WHS = Wet hour sum</li>
<li>WHS = Wet hour sum</li>
...
@@ -128,6 +126,35 @@ LAYER
...
@@ -128,6 +126,35 @@ LAYER
STATUS ON
STATUS ON
METADATA
METADATA
"wms_title" "Reference humidity model {{ timestep_date }}"
"wms_title" "Reference humidity model {{ timestep_date }}"
{% for language in languages %}
"wms_abstract.{{language.language_code}}" "
{
\"isWarningStatus\": true,
\"legendItems\": [
{
\"classification\": 0,
\"legendLabel\": \"{{ language.no_risk }}\",
\"legendIconCSS\": \"width: 25px; background-color: #707070;\"
},
{
\"classification\": 2,
\"legendLabel\": \"{{ language.low_risk }}\",
\"legendIconCSS\": \"width: 25px; background-color: #FFCC00;\"
},
{
\"classification\": 3,
\"legendLabel\": \"{{ language.medium_risk }}\",
\"legendIconCSS\": \"width: 25px; background-color: #FFCC99;\"
},
{
\"classification\": 4,
\"legendLabel\": \"{{ language.high_risk }}\",
\"legendIconCSS\": \"width: 25px; background-color: #FF0000;\"
}
]
}
"
{% endfor %}
END
END
CLASSITEM "[pixel]"
CLASSITEM "[pixel]"
...
@@ -176,6 +203,19 @@ LAYER
...
@@ -176,6 +203,19 @@ LAYER
STATUS ON
STATUS ON
METADATA
METADATA
"wms_title" "Reference humidity model WHS {{ timestep_date }}"
"wms_title" "Reference humidity model WHS {{ timestep_date }}"
{% for language in languages %}
"wms_abstract.{{language.language_code}}" "
{
\"isWarningStatus\": false,
\"legendItems\": [
{
\"legendLabel\": \"{{ language.whs }}\",
\"legendIconCSS\": \"width: 25px; background: linear-gradient(to right, #FFFF00, #0000FF);\"
}
]
}
"
{% endfor %}
END
END
CLASSITEM "[pixel]"
CLASSITEM "[pixel]"
CLASS
CLASS
...
...
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