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.
This commit is part of merge request !1. Comments created here will be created in the context of that merge request.
......@@ -23,6 +23,7 @@ import no.nibio.vips.model.ConfigValidationException;
import no.nibio.vips.model.Model;
import no.nibio.vips.model.ModelExcecutionException;
import no.nibio.vips.model.ModelId;
import no.nibio.vips.util.CommonNamespaces;
import no.nibio.vips.util.InvalidAggregationTypeException;
import no.nibio.vips.util.WeatherElements;
import no.nibio.vips.util.WeatherObservationListException;
......@@ -43,6 +44,7 @@ public class FinnCerealModels implements Model {
private DiseasePressureModel m;
private List<Result> results;
private Result parameters;
private List<WeatherObservation> dailyTemperature;
private List<WeatherObservation> dailyRainfall;
private Map<Date, List<Boolean>> leafWetness;
......@@ -118,16 +120,19 @@ public class FinnCerealModels implements Model {
List<Result> resultList = new ArrayList<>();
// reset model
Double accumulatedRisk = 0.0;
// add model parameters to results
resultList.add(parameters);
for(int i=0; i < dailyTemperature2.size(); i++) {
Date currentDate = dailyTemperature2.get(i).getTimeMeasured();
Result r = new ResultImpl();
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();
if(!currentDate.equals(test)) {
throw new ModelExcecutionException("Temperature and daily rainfall are from different dates!");
}
m.setPrecipitationRange(dailyRainfall2.get(i).getValue());
r.setValue(CommonNamespaces.NS_WEATHER, "Precipitation",""+dailyRainfall2.get(i).getValue());
List<Boolean> wetLeaves = leafWetness2.get(currentDate);
if(wetLeaves == null) {
throw new ModelExcecutionException("Leaf wetness data not found!");
......@@ -138,12 +143,14 @@ public class FinnCerealModels implements Model {
throw new ModelExcecutionException("Wind speed data not found!");
}
m.setWindSpeed(wind);
// XXX horrible hack here
r.setValue(CommonNamespaces.NS_WEATHER, "WindSpeed", wind.toString());
Double wetHours = leafWetnessHours2.get(currentDate);
if(wetHours == null) {
throw new ModelExcecutionException("Leaf wetness hours data not found!");
}
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!
r.setValue(pathogen, "BASE_RISK", "" + m.getBaseRisk());
r.setValue(pathogen, "DAILY_RISK", ""+ m.getDailyRisk());
......@@ -295,10 +302,13 @@ public class FinnCerealModels implements Model {
zone = TimeZone.getTimeZone(zoneString);
}
pathogen = (String)arg0.getConfigParameter("model");
m.setPathogen(pathogen);
m.setPrecedingCrop(((String)arg0.getConfigParameter("precedingCrop")));
parameters = new ResultImpl();
parameters.setValue(pathogen, "precedingCrop", (String)arg0.getConfigParameter("precedingCrop"));
m.setTillage(((String)arg0.getConfigParameter("tillageMethod")));
parameters.setValue(pathogen, "tillageMethod",(String)arg0.getConfigParameter("tillageMethod"));
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
Double d = (Double)arg0.getConfigParameter("accumulatedRisk");
......@@ -346,7 +356,8 @@ public class FinnCerealModels implements Model {
windSpeed = getWindSpeedByDay(windSpeedAll, wu);
// for some reason getAggregatedDailyValues returns the days in reverse order. This fixes that.
Collections.sort(dailyTemperature);
Collections.sort(dailyRainfall);
Collections.sort(dailyRainfall);
// weather parameters to Result
} catch(ClassCastException e) {
e.printStackTrace();
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