From 56f9baab55e9796d8f08ba610cb628cde9b0e212 Mon Sep 17 00:00:00 2001
From: lewa <lene.wasskog@nibio.no>
Date: Fri, 26 Apr 2024 12:49:37 +0200
Subject: [PATCH] feat: Add warning status medium risk

IDEC-461
---
 ADASMELIAE.py       | 17 +++++++++--------
 mapfile/template.j2 | 20 ++++++++++++++++----
 2 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/ADASMELIAE.py b/ADASMELIAE.py
index 8abd804..4894b41 100755
--- a/ADASMELIAE.py
+++ b/ADASMELIAE.py
@@ -73,7 +73,9 @@ logging.basicConfig(
 )
 
 tm_max = "air_temperature_2m_max"
-THRESHOLD = 15
+
+THRESHOLD_HIGH = 15
+THRESHOLD_MEDIUM = 12
 
 
 # Run given command using subprocess.run. Handle logging.
@@ -188,13 +190,12 @@ if __name__ == "__main__":
     )
 
     # Classifying warning status for the model
-    # temperature < 15     --> 2 (Yellow)
-    # temperature >= 15    --> 4 (Red)
-    logging.info(
-        f"Calculate warning status by checking if {tm_max} is below or above {THRESHOLD}"
-    )
+    # temperature < 12       --> 2 (Yellow)
+    # 12 <= temperature < 15 --> 3 (Orange)
+    # temperature >= 15      --> 4 (Red)
+    logging.info(f"Calculate warning status by checking {tm_max}")
     run_command(
-        command=f"cdo -s -aexpr,'WARNING_STATUS = {tm_max} < {THRESHOLD} ? 2 : 4' {max_temp_in_period_file} {unmasked_result_file}",
+        command=f"cdo -s -aexpr,'WARNING_STATUS = {tm_max} < {THRESHOLD_MEDIUM} ? 2 : -1; WARNING_STATUS = {tm_max} < {THRESHOLD_HIGH} && WARNING_STATUS == -1 ? 3 : WARNING_STATUS ; WARNING_STATUS = {tm_max} >= {THRESHOLD_HIGH} && WARNING_STATUS == -1 ? 4 : WARNING_STATUS' {max_temp_in_period_file} {unmasked_result_file}",
     )
 
     # Mask results using a CSV file with polygons. Env variable MASK_FILE must be set, or else we use the file as it is.
@@ -286,7 +287,7 @@ if __name__ == "__main__":
     )
     with open(f"{result_mapfile_dir}/{model_id}.map", "w") as f:
         f.write(output)
-    remove_temporary_files()
+    # remove_temporary_files()
 
     end_time = time.time()
     logging.info(
diff --git a/mapfile/template.j2 b/mapfile/template.j2
index 4810f29..1b49d66 100644
--- a/mapfile/template.j2
+++ b/mapfile/template.j2
@@ -128,6 +128,11 @@ LAYER
             \"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 }}\",
@@ -143,15 +148,22 @@ LAYER
     # class using simple string comparison, equivalent to ([pixel] = 0)
   
     CLASS
-      NAME "Low migration risk"
-      EXPRESSION ([pixel] >= 0 AND [pixel] < 3) 
+      NAME "Low infection risk"
+      EXPRESSION ([pixel] >= 0 AND [pixel] <= 2) 
       STYLE
           COLOR 255 204 0
       END
     END
     CLASS
-      NAME "High migration risk"
-      EXPRESSION ([pixel] >= 3) 
+      NAME "Medium infection risk"
+      EXPRESSION ([pixel] > 2 AND [pixel] <= 3) 
+      STYLE
+          COLOR 255 153 0
+      END
+    END
+    CLASS
+      NAME "High infection risk"
+      EXPRESSION ([pixel] > 3) 
       STYLE
           COLOR  255 0 0
       END
-- 
GitLab