Skip to content
Snippets Groups Projects
Commit 3637f06b authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

Added fallback calculation of leaf wetness

parent 94e99a2a
Branches
Tags
No related merge requests found
......@@ -85,9 +85,12 @@ public class AppleScabModel extends I18nImpl implements Model{
private Date startDateAscosporeMaturity;
// Weather data collections
private List<WeatherObservation> TM;
private List<WeatherObservation> RR;
private List<WeatherObservation> BT;
private List<WeatherObservation> TM; // Mean temperature
private List<WeatherObservation> RR; // Rainfall
private List<WeatherObservation> BT; // Leaf wetness
// Helper for calculating if missing BT
private List<WeatherObservation> UM; // Relative humidity
// Helper class
private final WeatherUtil weatherUtil;
......@@ -315,20 +318,50 @@ public class AppleScabModel extends I18nImpl implements Model{
this.BT.add(o);
this.calculations.setParamDoubleValueForDate(o.getTimeMeasured(), AppleScabCalculations.BT, o.getValue());
break;
case WeatherElements.RELATIVE_HUMIDITY:
this.UM.add(o);
break;
default:
// TODO: Throw validation error?
// Let it pass in silence
break;
}
}
// TODO: Validate all input!!!!
// Problems with weather observations
// Unequal length of lists
if (
this.RR.size() != this.TM.size()
|| this.BT.size() != this.TM.size()
|| this.RR.size() != this.TM.size()
)
{
throw new ConfigValidationException("Incorrect number of weather data. TM.size() = " + this.TM.size() + ", BT.size()=" + this.BT.size() + ", RR.size()=" + this.RR.size() );
// Fallback if missing leaf wetness: If we have relative humidity. leaf wetness may be calculated
if(this.BT.size() != this.TM.size() && this.UM.size() == this.TM.size())
{
WeatherUtil wUtil = new WeatherUtil();
Collections.sort(this.TM);
Collections.sort(this.RR);
Collections.sort(this.UM);
this.BT = wUtil.calculateLeafWetnessHourSeriesSimple(this.TM, this.RR, this.UM);
if(this.BT.size() == this.TM.size())
{
// Need to set the values in result set
for(WeatherObservation o: this.BT)
{
this.calculations.setParamDoubleValueForDate(o.getTimeMeasured(), AppleScabCalculations.BT, o.getValue());
}
}
else
{
throw new ConfigValidationException("Missing leaf wetness data. Also, attempting to calculate leaf wetness from other weather parameters failed.");
}
}
else
{
throw new ConfigValidationException("Incorrect number of weather data. TM.size() = " + this.TM.size() + ", BT.size()=" + this.BT.size() + ", RR.size()=" + this.RR.size() );
}
}
......@@ -530,6 +563,7 @@ public class AppleScabModel extends I18nImpl implements Model{
this.BT = new ArrayList();
this.RR = new ArrayList();
this.TM = new ArrayList();
this.UM = new ArrayList();
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment