From 45a3b179d41040ff5b7ccfdfd3be4b4824eeeea0 Mon Sep 17 00:00:00 2001
From: Tor-Einar Skog <tor-einar.skog@nibio.no>
Date: Tue, 22 Jan 2019 12:30:06 +0100
Subject: [PATCH] Weather parameter refactoring

---
 .../ZymoseptoriaSimpleRiskGridModelPreprocessor.java   |  2 +-
 .../model/preprocessor/AppleScabModelPreprocessor.java |  4 ++--
 .../preprocessor/BremiaLactucaeModelPreprocessor.java  | 10 +++++-----
 .../model/preprocessor/DOWNCASTModelPreprocessor.java  | 10 +++++-----
 .../model/preprocessor/NaerstadModelPreprocessor.java  |  4 ++--
 .../SeptoriaApiicolaModelPreprocessor.java             |  4 ++--
 .../no/nibio/vips/logic/service/ModelFormService.java  |  2 +-
 .../no/nibio/vips/util/weather/MetosAPIDataParser.java |  2 +-
 .../weather/dnmipointweb/DMIPointWebDataParser.java    |  4 ++--
 .../java/no/nibio/vips/logic/test/mock/MockModel.java  |  2 +-
 10 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/src/main/java/no/nibio/vips/logic/scheduling/model/grid/preprocessor/ZymoseptoriaSimpleRiskGridModelPreprocessor.java b/src/main/java/no/nibio/vips/logic/scheduling/model/grid/preprocessor/ZymoseptoriaSimpleRiskGridModelPreprocessor.java
index 2abdd427..6b4d3b28 100644
--- a/src/main/java/no/nibio/vips/logic/scheduling/model/grid/preprocessor/ZymoseptoriaSimpleRiskGridModelPreprocessor.java
+++ b/src/main/java/no/nibio/vips/logic/scheduling/model/grid/preprocessor/ZymoseptoriaSimpleRiskGridModelPreprocessor.java
@@ -120,7 +120,7 @@ public class ZymoseptoriaSimpleRiskGridModelPreprocessor extends ModelRunPreproc
                     station, 
                     WeatherObservation.LOG_INTERVAL_ID_1H, 
                     new String[]{
-                        WeatherElements.LEAF_WETNESS,
+                        WeatherElements.LEAF_WETNESS_DURATION,
                         WeatherElements.RELATIVE_HUMIDITY_MEAN,
                         WeatherElements.PRECIPITATION, 
                         WeatherElements.TEMPERATURE_MEAN
diff --git a/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/AppleScabModelPreprocessor.java b/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/AppleScabModelPreprocessor.java
index 4de8ad02..c86453bc 100755
--- a/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/AppleScabModelPreprocessor.java
+++ b/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/AppleScabModelPreprocessor.java
@@ -106,7 +106,7 @@ public class AppleScabModelPreprocessor extends ModelRunPreprocessor{
                     new String[]{
                         WeatherElements.TEMPERATURE_MEAN,
                         WeatherElements.PRECIPITATION,
-                        WeatherElements.LEAF_WETNESS,
+                        WeatherElements.LEAF_WETNESS_DURATION,
                         WeatherElements.RELATIVE_HUMIDITY_MEAN
                     },
                     startDateAscosporeMaturity,
@@ -222,7 +222,7 @@ public class AppleScabModelPreprocessor extends ModelRunPreprocessor{
         {
             switch(o.getElementMeasurementTypeId())
             {
-                case WeatherElements.LEAF_WETNESS:
+                case WeatherElements.LEAF_WETNESS_DURATION:
                     BT.add(o); 
                     break;
                 case WeatherElements.RELATIVE_HUMIDITY_MEAN:
diff --git a/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/BremiaLactucaeModelPreprocessor.java b/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/BremiaLactucaeModelPreprocessor.java
index e65356dd..55fdb4cc 100755
--- a/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/BremiaLactucaeModelPreprocessor.java
+++ b/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/BremiaLactucaeModelPreprocessor.java
@@ -57,8 +57,8 @@ public class BremiaLactucaeModelPreprocessor extends ModelRunPreprocessor {
                     weatherStation,
                     WeatherObservation.LOG_INTERVAL_ID_1H,
                     new String[]{
-                        WeatherElements.LEAF_WETNESS,
-                        WeatherElements.LEAF_WETNESS_GROUND_LEVEL,
+                        WeatherElements.LEAF_WETNESS_DURATION,
+                        WeatherElements.LEAF_WETNESS_DURATION_GROUND_LEVEL,
                         WeatherElements.TEMPERATURE_MAXIMUM,
                         WeatherElements.GLOBAL_RADIATION,
                         WeatherElements.RELATIVE_HUMIDITY_MEAN,
@@ -68,8 +68,8 @@ public class BremiaLactucaeModelPreprocessor extends ModelRunPreprocessor {
                     configuration.getDateStartInTimeZone(),
                     configuration.getDateEndInTimeZone());
             observations = wUtil.checkForAndFixHourlyTimeSeriesHoles(observations);
-            List<WeatherObservation> BTg = wUtil.filterWeatherObservationsByParameter(observations, new HashSet(Arrays.asList(WeatherElements.LEAF_WETNESS_GROUND_LEVEL)));
-            List<WeatherObservation> BT = wUtil.filterWeatherObservationsByParameter(observations, new HashSet(Arrays.asList(WeatherElements.LEAF_WETNESS)));
+            List<WeatherObservation> BTg = wUtil.filterWeatherObservationsByParameter(observations, new HashSet(Arrays.asList(WeatherElements.LEAF_WETNESS_DURATION_GROUND_LEVEL)));
+            List<WeatherObservation> BT = wUtil.filterWeatherObservationsByParameter(observations, new HashSet(Arrays.asList(WeatherElements.LEAF_WETNESS_DURATION)));
             List<WeatherObservation> TX = wUtil.filterWeatherObservationsByParameter(observations, new HashSet(Arrays.asList(WeatherElements.TEMPERATURE_MAXIMUM)));
             List<WeatherObservation> Q0 = wUtil.filterWeatherObservationsByParameter(observations, new HashSet(Arrays.asList(WeatherElements.GLOBAL_RADIATION)));
             List<WeatherObservation> UM = wUtil.filterWeatherObservationsByParameter(observations, new HashSet(Arrays.asList(WeatherElements.RELATIVE_HUMIDITY_MEAN)));
@@ -83,7 +83,7 @@ public class BremiaLactucaeModelPreprocessor extends ModelRunPreprocessor {
             {
                 BTg = wUtil.calculateLeafWetnessHourSeriesBestEffort(BTg,TM, RR, null,null, UM);
             }
-            wUtil.renameParameter(BTg, WeatherElements.LEAF_WETNESS, WeatherElements.LEAF_WETNESS_GROUND_LEVEL);
+            wUtil.renameParameter(BTg, WeatherElements.LEAF_WETNESS_DURATION, WeatherElements.LEAF_WETNESS_DURATION_GROUND_LEVEL);
             
             observations = new ArrayList<>();
             observations.addAll(BTg);
diff --git a/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/DOWNCASTModelPreprocessor.java b/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/DOWNCASTModelPreprocessor.java
index 33d3332b..e5d12c74 100755
--- a/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/DOWNCASTModelPreprocessor.java
+++ b/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/DOWNCASTModelPreprocessor.java
@@ -56,8 +56,8 @@ public class DOWNCASTModelPreprocessor extends ModelRunPreprocessor{
                     weatherStation,
                     WeatherObservation.LOG_INTERVAL_ID_1H,
                     new String[]{
-                        WeatherElements.LEAF_WETNESS,
-                        WeatherElements.LEAF_WETNESS_GROUND_LEVEL,
+                        WeatherElements.LEAF_WETNESS_DURATION,
+                        WeatherElements.LEAF_WETNESS_DURATION_GROUND_LEVEL,
                         WeatherElements.RELATIVE_HUMIDITY_MEAN,
                         WeatherElements.PRECIPITATION, 
                         WeatherElements.TEMPERATURE_MEAN 
@@ -65,8 +65,8 @@ public class DOWNCASTModelPreprocessor extends ModelRunPreprocessor{
                     configuration.getDateStartInTimeZone(),
                     configuration.getDateEndInTimeZone());
             observations = wUtil.checkForAndFixHourlyTimeSeriesHoles(observations);
-            List<WeatherObservation> BTg = wUtil.filterWeatherObservationsByParameter(observations, new HashSet(Arrays.asList(WeatherElements.LEAF_WETNESS_GROUND_LEVEL)));
-            List<WeatherObservation> BT = wUtil.filterWeatherObservationsByParameter(observations, new HashSet(Arrays.asList(WeatherElements.LEAF_WETNESS)));
+            List<WeatherObservation> BTg = wUtil.filterWeatherObservationsByParameter(observations, new HashSet(Arrays.asList(WeatherElements.LEAF_WETNESS_DURATION_GROUND_LEVEL)));
+            List<WeatherObservation> BT = wUtil.filterWeatherObservationsByParameter(observations, new HashSet(Arrays.asList(WeatherElements.LEAF_WETNESS_DURATION)));
             List<WeatherObservation> UM = wUtil.filterWeatherObservationsByParameter(observations, new HashSet(Arrays.asList(WeatherElements.RELATIVE_HUMIDITY_MEAN)));
             List<WeatherObservation> RR = wUtil.filterWeatherObservationsByParameter(observations, new HashSet(Arrays.asList(WeatherElements.PRECIPITATION)));
             List<WeatherObservation> TM = wUtil.filterWeatherObservationsByParameter(observations, new HashSet(Arrays.asList(WeatherElements.TEMPERATURE_MEAN)));
@@ -78,7 +78,7 @@ public class DOWNCASTModelPreprocessor extends ModelRunPreprocessor{
             {
                 BTg = wUtil.calculateLeafWetnessHourSeriesBestEffort(BTg,TM, RR, null,null, UM);
             }
-            wUtil.renameParameter(BTg, WeatherElements.LEAF_WETNESS, WeatherElements.LEAF_WETNESS_GROUND_LEVEL);
+            wUtil.renameParameter(BTg, WeatherElements.LEAF_WETNESS_DURATION, WeatherElements.LEAF_WETNESS_DURATION_GROUND_LEVEL);
             
             observations = new ArrayList<>();
             observations.addAll(BTg);
diff --git a/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/NaerstadModelPreprocessor.java b/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/NaerstadModelPreprocessor.java
index ce971de0..7fbed9f1 100755
--- a/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/NaerstadModelPreprocessor.java
+++ b/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/NaerstadModelPreprocessor.java
@@ -89,7 +89,7 @@ public class NaerstadModelPreprocessor extends ModelRunPreprocessor{
                         new String[]{
                             WeatherElements.TEMPERATURE_MEAN,
                             WeatherElements.PRECIPITATION,
-                            WeatherElements.LEAF_WETNESS,
+                            WeatherElements.LEAF_WETNESS_DURATION,
                             WeatherElements.RELATIVE_HUMIDITY_MEAN,
                             WeatherElements.GLOBAL_RADIATION,
                             WeatherElements.WIND_SPEED_2M
@@ -194,7 +194,7 @@ public class NaerstadModelPreprocessor extends ModelRunPreprocessor{
             {
                 switch(o.getElementMeasurementTypeId())
                 {
-                    case WeatherElements.LEAF_WETNESS:
+                    case WeatherElements.LEAF_WETNESS_DURATION:
                         BT.add(o); 
                         break;
 
diff --git a/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/SeptoriaApiicolaModelPreprocessor.java b/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/SeptoriaApiicolaModelPreprocessor.java
index 6fcab9c6..8186262e 100755
--- a/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/SeptoriaApiicolaModelPreprocessor.java
+++ b/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/SeptoriaApiicolaModelPreprocessor.java
@@ -70,7 +70,7 @@ public class SeptoriaApiicolaModelPreprocessor extends ModelRunPreprocessor {
                     weatherStation,
                     WeatherObservation.LOG_INTERVAL_ID_1H,
                     new String[]{
-                        WeatherElements.LEAF_WETNESS,
+                        WeatherElements.LEAF_WETNESS_DURATION,
                         WeatherElements.TEMPERATURE_MEAN,
                         WeatherElements.PRECIPITATION,
                         WeatherElements.RELATIVE_HUMIDITY_MEAN
@@ -78,7 +78,7 @@ public class SeptoriaApiicolaModelPreprocessor extends ModelRunPreprocessor {
                     configuration.getDateStartInTimeZone(),
                     configuration.getDateEndInTimeZone());
             observations = wUtil.checkForAndFixHourlyTimeSeriesHoles(observations);
-            List<WeatherObservation> BT = wUtil.filterWeatherObservationsByParameter(observations, new HashSet(Arrays.asList(WeatherElements.LEAF_WETNESS)));
+            List<WeatherObservation> BT = wUtil.filterWeatherObservationsByParameter(observations, new HashSet(Arrays.asList(WeatherElements.LEAF_WETNESS_DURATION)));
             List<WeatherObservation> TM = wUtil.filterWeatherObservationsByParameter(observations, new HashSet(Arrays.asList(WeatherElements.TEMPERATURE_MEAN)));
             List<WeatherObservation> RR = wUtil.filterWeatherObservationsByParameter(observations, new HashSet(Arrays.asList(WeatherElements.PRECIPITATION)));
             List<WeatherObservation> UM = wUtil.filterWeatherObservationsByParameter(observations, new HashSet(Arrays.asList(WeatherElements.RELATIVE_HUMIDITY_MEAN)));
diff --git a/src/main/java/no/nibio/vips/logic/service/ModelFormService.java b/src/main/java/no/nibio/vips/logic/service/ModelFormService.java
index 3a00a583..56ddefe8 100644
--- a/src/main/java/no/nibio/vips/logic/service/ModelFormService.java
+++ b/src/main/java/no/nibio/vips/logic/service/ModelFormService.java
@@ -150,7 +150,7 @@ public class ModelFormService {
                             WeatherElements.TEMPERATURE_MEAN,
                             WeatherElements.PRECIPITATION,
                             WeatherElements.RELATIVE_HUMIDITY_MEAN,
-                            WeatherElements.LEAF_WETNESS
+                            WeatherElements.LEAF_WETNESS_DURATION
                         }, 
                         startTime, 
                         endTime
diff --git a/src/main/java/no/nibio/vips/util/weather/MetosAPIDataParser.java b/src/main/java/no/nibio/vips/util/weather/MetosAPIDataParser.java
index 0a11e35f..14a64364 100644
--- a/src/main/java/no/nibio/vips/util/weather/MetosAPIDataParser.java
+++ b/src/main/java/no/nibio/vips/util/weather/MetosAPIDataParser.java
@@ -78,7 +78,7 @@ public class MetosAPIDataParser {
     // TODO; Separate parameter: Soil temperature. Search for name "Soil temperature", higher channel number = deeper sensor
     private final ParamInfo[] PARAM_MAP = {
         new ParamInfo(WeatherElements.PRECIPITATION,            new Integer[] {6},          "sum"),
-        new ParamInfo(WeatherElements.LEAF_WETNESS,             new Integer[] {4},          "time"),
+        new ParamInfo(WeatherElements.LEAF_WETNESS_DURATION,             new Integer[] {4},          "time"),
         new ParamInfo(WeatherElements.GLOBAL_RADIATION,         new Integer[] {600},        "avg"),
         new ParamInfo(WeatherElements.WIND_SPEED_2M,            new Integer[] {5},          "avg"),
         new ParamInfo(WeatherElements.TEMPERATURE_MEAN,         new Integer[] {0,16385},      "avg"),
diff --git a/src/main/java/no/nibio/vips/util/weather/dnmipointweb/DMIPointWebDataParser.java b/src/main/java/no/nibio/vips/util/weather/dnmipointweb/DMIPointWebDataParser.java
index cff4c3f0..57f45b59 100644
--- a/src/main/java/no/nibio/vips/util/weather/dnmipointweb/DMIPointWebDataParser.java
+++ b/src/main/java/no/nibio/vips/util/weather/dnmipointweb/DMIPointWebDataParser.java
@@ -56,7 +56,7 @@ public class DMIPointWebDataParser {
         PARAM_MAP.put(WeatherElements.RELATIVE_HUMIDITY_MEAN, WeatherDataParameter.AIRRH);
         PARAM_MAP.put(WeatherElements.WIND_SPEED_2M, WeatherDataParameter.WINDSPEED);
         PARAM_MAP.put(WeatherElements.SOIL_TEMPERATURE_10CM_MEAN, WeatherDataParameter.SOILTEMP);
-        PARAM_MAP.put(WeatherElements.LEAF_WETNESS, WeatherDataParameter.LEAFWET);
+        PARAM_MAP.put(WeatherElements.LEAF_WETNESS_DURATION, WeatherDataParameter.LEAFWET);
     }
     
     
@@ -174,7 +174,7 @@ public class DMIPointWebDataParser {
                     obs.setValue(wDataModel.getSoiltemp().getValue());     break;// Not sure if it's 10 or 5 cm depth yet
                 case WeatherElements.SOIL_TEMPERATURE_5CM_MEAN:
                     obs.setValue(wDataModel.getSoiltemp().getValue());     break;
-                case WeatherElements.LEAF_WETNESS:
+                case WeatherElements.LEAF_WETNESS_DURATION:
                     obs.setValue(wDataModel.getLeafwet().getValue());      break;
                 default: return null;
             }
diff --git a/src/test/java/no/nibio/vips/logic/test/mock/MockModel.java b/src/test/java/no/nibio/vips/logic/test/mock/MockModel.java
index 140a7d04..022dab95 100644
--- a/src/test/java/no/nibio/vips/logic/test/mock/MockModel.java
+++ b/src/test/java/no/nibio/vips/logic/test/mock/MockModel.java
@@ -102,7 +102,7 @@ public class MockModel implements Model{
                 {
                     wetHoursForDay[0]++; // We add up the number of hours we actually have weather data for
                 }
-                Double BT = pointMatrix.getParamDoubleValueForDate(timestamp, WeatherElements.LEAF_WETNESS);
+                Double BT = pointMatrix.getParamDoubleValueForDate(timestamp, WeatherElements.LEAF_WETNESS_DURATION);
                 Double RR = pointMatrix.getParamDoubleValueForDate(timestamp, WeatherElements.PRECIPITATION);
                 if(TM >= 10.0)
                 {
-- 
GitLab