Skip to content
Snippets Groups Projects
Commit 088cb993 authored by Jussi Nikander's avatar Jussi Nikander
Browse files

Added weather data to the results.

parent 49fe5de8
No related branches found
No related tags found
1 merge request!1Added weather data to the results.
...@@ -23,6 +23,7 @@ import no.nibio.vips.model.ConfigValidationException; ...@@ -23,6 +23,7 @@ import no.nibio.vips.model.ConfigValidationException;
import no.nibio.vips.model.Model; import no.nibio.vips.model.Model;
import no.nibio.vips.model.ModelExcecutionException; import no.nibio.vips.model.ModelExcecutionException;
import no.nibio.vips.model.ModelId; import no.nibio.vips.model.ModelId;
import no.nibio.vips.util.CommonNamespaces;
import no.nibio.vips.util.InvalidAggregationTypeException; import no.nibio.vips.util.InvalidAggregationTypeException;
import no.nibio.vips.util.WeatherElements; import no.nibio.vips.util.WeatherElements;
import no.nibio.vips.util.WeatherObservationListException; import no.nibio.vips.util.WeatherObservationListException;
...@@ -43,6 +44,7 @@ public class FinnCerealModels implements Model { ...@@ -43,6 +44,7 @@ public class FinnCerealModels implements Model {
private DiseasePressureModel m; private DiseasePressureModel m;
private List<Result> results; private List<Result> results;
private Result parameters;
private List<WeatherObservation> dailyTemperature; private List<WeatherObservation> dailyTemperature;
private List<WeatherObservation> dailyRainfall; private List<WeatherObservation> dailyRainfall;
private Map<Date, List<Boolean>> leafWetness; private Map<Date, List<Boolean>> leafWetness;
...@@ -118,16 +120,19 @@ public class FinnCerealModels implements Model { ...@@ -118,16 +120,19 @@ public class FinnCerealModels implements Model {
List<Result> resultList = new ArrayList<>(); List<Result> resultList = new ArrayList<>();
// reset model // reset model
Double accumulatedRisk = 0.0; Double accumulatedRisk = 0.0;
// add model parameters to results
resultList.add(parameters);
for(int i=0; i < dailyTemperature2.size(); i++) { for(int i=0; i < dailyTemperature2.size(); i++) {
Date currentDate = dailyTemperature2.get(i).getTimeMeasured(); Date currentDate = dailyTemperature2.get(i).getTimeMeasured();
Result r = new ResultImpl(); Result r = new ResultImpl();
m.setTemperature(dailyTemperature2.get(i).getValue()); m.setTemperature(dailyTemperature2.get(i).getValue());
r.setValue(pathogen, "ATemp", ""+dailyTemperature2.get(i).getValue()); r.setValue(CommonNamespaces.NS_WEATHER, "ATemp", ""+dailyTemperature2.get(i).getValue());
Date test = dailyRainfall2.get(i).getTimeMeasured(); Date test = dailyRainfall2.get(i).getTimeMeasured();
if(!currentDate.equals(test)) { if(!currentDate.equals(test)) {
throw new ModelExcecutionException("Temperature and daily rainfall are from different dates!"); throw new ModelExcecutionException("Temperature and daily rainfall are from different dates!");
} }
m.setPrecipitationRange(dailyRainfall2.get(i).getValue()); m.setPrecipitationRange(dailyRainfall2.get(i).getValue());
r.setValue(CommonNamespaces.NS_WEATHER, "Precipitation",""+dailyRainfall2.get(i).getValue());
List<Boolean> wetLeaves = leafWetness2.get(currentDate); List<Boolean> wetLeaves = leafWetness2.get(currentDate);
if(wetLeaves == null) { if(wetLeaves == null) {
throw new ModelExcecutionException("Leaf wetness data not found!"); throw new ModelExcecutionException("Leaf wetness data not found!");
...@@ -138,12 +143,14 @@ public class FinnCerealModels implements Model { ...@@ -138,12 +143,14 @@ public class FinnCerealModels implements Model {
throw new ModelExcecutionException("Wind speed data not found!"); throw new ModelExcecutionException("Wind speed data not found!");
} }
m.setWindSpeed(wind); m.setWindSpeed(wind);
// XXX horrible hack here
r.setValue(CommonNamespaces.NS_WEATHER, "WindSpeed", wind.toString());
Double wetHours = leafWetnessHours2.get(currentDate); Double wetHours = leafWetnessHours2.get(currentDate);
if(wetHours == null) { if(wetHours == null) {
throw new ModelExcecutionException("Leaf wetness hours data not found!"); throw new ModelExcecutionException("Leaf wetness hours data not found!");
} }
m.setDailyLeafWetnessDuration(wetHours); m.setDailyLeafWetnessDuration(wetHours);
r.setValue(pathogen, "LeafWet", "" + wetHours); r.setValue(CommonNamespaces.NS_WEATHER, "LeafWet", "" + wetHours);
// TODO does not take into account the disease progress at the moment! // TODO does not take into account the disease progress at the moment!
r.setValue(pathogen, "BASE_RISK", "" + m.getBaseRisk()); r.setValue(pathogen, "BASE_RISK", "" + m.getBaseRisk());
r.setValue(pathogen, "DAILY_RISK", ""+ m.getDailyRisk()); r.setValue(pathogen, "DAILY_RISK", ""+ m.getDailyRisk());
...@@ -295,10 +302,13 @@ public class FinnCerealModels implements Model { ...@@ -295,10 +302,13 @@ public class FinnCerealModels implements Model {
zone = TimeZone.getTimeZone(zoneString); zone = TimeZone.getTimeZone(zoneString);
} }
pathogen = (String)arg0.getConfigParameter("model"); pathogen = (String)arg0.getConfigParameter("model");
m.setPathogen(pathogen);
m.setPrecedingCrop(((String)arg0.getConfigParameter("precedingCrop"))); m.setPrecedingCrop(((String)arg0.getConfigParameter("precedingCrop")));
parameters = new ResultImpl();
parameters.setValue(pathogen, "precedingCrop", (String)arg0.getConfigParameter("precedingCrop"));
m.setTillage(((String)arg0.getConfigParameter("tillageMethod"))); m.setTillage(((String)arg0.getConfigParameter("tillageMethod")));
parameters.setValue(pathogen, "tillageMethod",(String)arg0.getConfigParameter("tillageMethod"));
m.setCropSusceptibility(((String)arg0.getConfigParameter("diseaseSusceptibility"))); m.setCropSusceptibility(((String)arg0.getConfigParameter("diseaseSusceptibility")));
parameters.setValue(pathogen, "diseaseSusceptibility", (String)arg0.getConfigParameter("diseaseSusceptibility"));
// Optional parameters, will be given default values if not included in the ModelConfiguration // Optional parameters, will be given default values if not included in the ModelConfiguration
Double d = (Double)arg0.getConfigParameter("accumulatedRisk"); Double d = (Double)arg0.getConfigParameter("accumulatedRisk");
...@@ -346,7 +356,8 @@ public class FinnCerealModels implements Model { ...@@ -346,7 +356,8 @@ public class FinnCerealModels implements Model {
windSpeed = getWindSpeedByDay(windSpeedAll, wu); windSpeed = getWindSpeedByDay(windSpeedAll, wu);
// for some reason getAggregatedDailyValues returns the days in reverse order. This fixes that. // for some reason getAggregatedDailyValues returns the days in reverse order. This fixes that.
Collections.sort(dailyTemperature); Collections.sort(dailyTemperature);
Collections.sort(dailyRainfall); Collections.sort(dailyRainfall);
// weather parameters to Result
} catch(ClassCastException e) { } catch(ClassCastException e) {
e.printStackTrace(); e.printStackTrace();
throw new ConfigValidationException("incorrect input"); throw new ConfigValidationException("incorrect input");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment