Skip to content
Snippets Groups Projects
Commit 6ddb1e93 authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

Add i18n support for day degrees legend

parent 117f5994
No related branches found
No related tags found
No related merge requests found
......@@ -7,9 +7,11 @@ no_forecast = No forecast
no_risk = No risk
possible_risk = Possible risk
high_risk = High risk
day_degrees = Day degrees
[i18n.nb]
no_forecast = Varsel beregnes ikke
no_risk = Ingen infeksjonsrisikok
possible_risk = Mulig fare for angrep
high_risk = Høy fare for angrep
\ No newline at end of file
high_risk = Høy fare for angrep
day_degrees = Døgngrader
\ No newline at end of file
......@@ -38,7 +38,7 @@ out_path = os.getenv("DATA_DIR")
utc_offset = "+02:00"
local_timezone = pytz.timezone("Europe/Oslo")
"""
#"""
# Calculate cumulated degree days above 5 degrees after 1st of April
# Remove all values before April 1st
subprocess.run(f"cdo -selname,TM -seldate,2023-04-01T00:00:00,2023-12-31T00:00:00 {weatherdata_path}met_1_0km_nordic-2023.nc {tmp_path}TM_from_april.nc", shell=True)
......@@ -66,7 +66,7 @@ else:
# (A>0)*(A<=260)*2 + (A>260)*(A<=360)*3 + (A>360)*(A<=560)*4 + (A>560)*0
subprocess.run(f'cdo -aexpr,"WARNING_STATUS=(TM>0)*(TM<=260)*2 + (TM>260)*(TM<=360)*3 + (TM>360)*(TM<=560)*4 + (TM>560)*0" {tmp_path}DD.nc {tmp_path}result.nc', shell=True)
"""
#"""
# Split the combined file into daily .nc files again, with YYYY-MM-DD in the filename. Convert to corresponding GeoTIFF files
# Variables that needs discrete classification, must be integers in order for mapserver to work properly (Don't ask!)
......@@ -82,7 +82,7 @@ for timestep in timesteps:
#print(f"{timestep_index}: {file_date}")
timestep_dates.append(file_date)
# We must delete the GeoTIFF file before merging
"""
#"""
subprocess.run(f'rm {tmp_path}result_*{file_date}_lcc.tif', shell=True)
subprocess.run(f'rm {out_path}result_*{file_date}.tif', shell=True)
with open("/dev/null", "w") as devnull:
......@@ -91,7 +91,7 @@ for timestep in timesteps:
# Need to reproject the files, to ensure we have the projection given in the generted mapfile. We always use EPSG:4326 for this
subprocess.run(f'gdalwarp -t_srs EPSG:4326 {tmp_path}result_WARNING_STATUS_{file_date}_lcc.tif {out_path}result_WARNING_STATUS_{file_date}.tif', shell=True, stdout=devnull)
subprocess.run(f'gdalwarp -t_srs EPSG:4326 {tmp_path}result_{file_date}_lcc.tif {out_path}result_{file_date}.tif', shell=True, stdout=devnull)
"""
#"""
timestep_index = timestep_index + 1
if len(timestep_dates) != len(set(timestep_dates)):
......@@ -103,7 +103,8 @@ if len(timestep_dates) != len(set(timestep_dates)):
# Generate mapfile
# Building data sets for language specific legends
languages = []
for language_code in config["i18n"]["languages"].split(","):
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]:
......@@ -120,7 +121,8 @@ output = template.render({
"mapserver_log_file": os.getenv("MAPSERVER_LOG_FILE"),
"mapserver_image_path": os.getenv("MAPSERVER_IMAGE_PATH"),
"mapserver_extent": os.getenv("MAPSERVER_EXTENT"),
"languages": languages
"languages": languages,
"language_codes": language_codes
})
mapfile_outdir = os.getenv("MAPFILE_DIR")
with open(f"{mapfile_outdir}/PSILARTEMP.map", 'w') as f:
......
......@@ -35,9 +35,12 @@ WEB
# List of standard metadata: https://mapserver.org/ogc/wms_server.html#web-object-metadata
# i18n support: https://mapserver.org/ogc/inspire.html#inspire-multi-language-support
METADATA
"wms_inspire_capabilities" "embed"
"wms_languages" "en,nb" # The first is the default
"wms_keywordlist" "VIPS model Carrot Rust Fly (PSILARTEMP)"
{% if languages %}
"wms_inspire_capabilities" "embed"
"wms_languages" "{{ language_codes|join(",")}}" # The first is the default
{% endif %}
"wms_abstract.nb" "
<h2>Modellbeskrivelse</h2>
<p>Varslingsmodellen &laquo;Gulrotflue svermetidspunkt&raquo; er basert p&aring; en finsk, temperaturbasert modell (Markkula <em>et al</em>, 1998; Tiilikkala &amp; Ojanen, 1999; Markkula <em>et al</em>, 2000). Modellen beregner tidspunkt for sverming av 1. generasjon og 2. generasjon av gulrotflue basert p&aring; akkumulering av graddager (d&oslash;gngrader) over en basistemperatur p&aring; 5 &deg;C. I VIPS benyttes modellen kun for 1. generasjon.</p>
......@@ -182,19 +185,21 @@ LAYER
DATA "{{mapserver_data_dir}}result_{{ timestep_date }}.tif"
TEMPLATE "{{mapserver_mapfile_dir}}query_template_DD.xml" TOLERANCE 1 TOLERANCEUNITS PIXELS
TYPE RASTER
#PROCESSING "BANDS=1" # DD band on top (others invisible, but band values are available in the query template)
#PROCESSING "SCALE=AUTO"
#PROCESSING "NODATA=-1"
STATUS ON
METADATA
"wms_title" "Carrot rust fly (Psila rosae) temperature model Day Degrees {{ timestep_date }}"
{% for language in languages %}
"wms_abstract.{{language.language_code}}" "
<ul style=\"list-style: none; padding: 0;\">
<li style=\"margin-bottom: 5px;\"><span style=\"display: inline-block; width: 25px; background: linear-gradient(to right, #0000FF, #FF0000);\">&nbsp;</span> {{language.day_degrees}}</li>
</ul>
"
{% endfor %}
END
CLASSITEM "[pixel]"
CLASS
NAME "Day degrees"
#EXPRESSION ([pixel] >= 0 AND [pixel] <= 72)
STYLE
DATARANGE 0 1000
COLORRANGE 0 0 255 255 0 0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment