diff --git a/SEPTREFHUM.cfg b/SEPTREFHUM.cfg new file mode 100644 index 0000000000000000000000000000000000000000..0d79cce3e3d2a47b358d6feab1fd4ee08a428bb4 --- /dev/null +++ b/SEPTREFHUM.cfg @@ -0,0 +1,17 @@ +[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 diff --git a/SEPTREFHUM.py b/SEPTREFHUM.py index 3be0c996a0527e0572e60f0326273d43518c8369..3021e9e12e40cedf2860f15c44d65151a8554153 100755 --- a/SEPTREFHUM.py +++ b/SEPTREFHUM.py @@ -29,10 +29,15 @@ from datetime import datetime, timezone, timedelta from jinja2 import Environment, FileSystemLoader import pytz import netCDF4 as nc +import configparser # Paths config # Create a .env file from dotenv-sample load_dotenv() +# Get language stuff +config = configparser.ConfigParser() +config.read("SEPTREFHUM.cfg") + # Path to weather data infile_path = os.getenv("WEATHER_DATA_DIR") # Path to store generated GeoTIFF files @@ -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'): continue - # 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) # Convert to GeoTIFF @@ -205,6 +209,16 @@ for timestep in timesteps: timestep_index = timestep_index + 1 # 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 env = Environment(loader=FileSystemLoader('.')) template = env.get_template("mapfile/template.j2") @@ -214,7 +228,9 @@ output = template.render({ "mapserver_mapfile_dir": os.getenv("MAPSERVER_MAPFILE_DIR"), "mapserver_log_file": os.getenv("MAPSERVER_LOG_FILE"), "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") with open(f"{mapfile_outdir}/SEPTREFHUM.map", 'w') as f: diff --git a/mapfile/template.j2 b/mapfile/template.j2 index 24e1a590e31c5ccddab8335b29a83b0e55ef1838..5d0f5436593e7d061161c3b0612187b17fcf534b 100644 --- a/mapfile/template.j2 +++ b/mapfile/template.j2 @@ -36,6 +36,10 @@ WEB # i18n support: https://mapserver.org/ogc/inspire.html#inspire-multi-language-support METADATA "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'> <p>The reference humidity model was developed as a supplement to the Humidity model. In this model 20 consecutive hours are @@ -71,12 +75,6 @@ WEB 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> - <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> <ul> <li>WHS = Wet hour sum</li> @@ -128,6 +126,35 @@ LAYER STATUS ON METADATA "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 CLASSITEM "[pixel]" @@ -176,6 +203,19 @@ LAYER STATUS ON METADATA "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 CLASSITEM "[pixel]" CLASS