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

Moved weather treatment stuff to VIPSCOmmon/weatherutil

parent 1b19dcc4
Branches
Tags
No related merge requests found
...@@ -295,9 +295,11 @@ public class AppleScabModel extends I18nImpl implements Model{ ...@@ -295,9 +295,11 @@ public class AppleScabModel extends I18nImpl implements Model{
throw new ConfigValidationException("Illegal date format for startDateAscosporeMaturity: " + config.getConfigParameter("startDateAscosporeMaturity")); throw new ConfigValidationException("Illegal date format for startDateAscosporeMaturity: " + config.getConfigParameter("startDateAscosporeMaturity"));
} }
// Weather data are OK, let's add them to calculations matrix // ############ Weather data ##############
// Getting weather data, validating
this.calculations = new AppleScabCalculations(); this.calculations = new AppleScabCalculations();
List<WeatherObservation> observations = mapper.convertValue(config.getConfigParameter("observations"), new TypeReference<List<WeatherObservation>>(){}); List<WeatherObservation> observations = mapper.convertValue(config.getConfigParameter("observations"), new TypeReference<List<WeatherObservation>>(){});
for(WeatherObservation o:observations) for(WeatherObservation o:observations)
{ {
switch(o.getElementMeasurementTypeId()) switch(o.getElementMeasurementTypeId())
...@@ -311,70 +313,69 @@ public class AppleScabModel extends I18nImpl implements Model{ ...@@ -311,70 +313,69 @@ public class AppleScabModel extends I18nImpl implements Model{
case WeatherElements.LEAF_WETNESS: case WeatherElements.LEAF_WETNESS:
this.BT.add(o); this.BT.add(o);
break; break;
case WeatherElements.RELATIVE_HUMIDITY:
this.UM.add(o);
break;
case WeatherElements.GLOBAL_RADIATION:
this.Q0.add(o);
break;
case WeatherElements.WIND_SPEED_2M:
this.FM2.add(o);
break;
default: default:
// Let it pass in silence // Let it pass in silence
break; break;
} }
} }
//mapper.convertValue(config.getConfigParameter("timeZone"), new TypeReference<java.util.TimeZone>(){});
WeatherUtil wUtil = new WeatherUtil(); WeatherUtil wUtil = new WeatherUtil();
// Problems with weather observations
// Unequal length of lists // Must be of same length,
if ( if(this.TM.size() != this.RR.size() || this.TM.size() != BT.size())
this.RR.size() != this.TM.size()
|| this.BT.size() != this.TM.size()
|| this.RR.size() != this.TM.size()
)
{ {
// Fallback if missing leaf wetness: If we have relative humidity. leaf wetness may be calculated throw new ConfigValidationException("Unequal length of weather parameter lists. "
if(this.BT.size() != this.TM.size() && this.UM.size() == this.TM.size()) + "Temperature list size = " + this.TM.size()
{ + ", precipitation list size = " + this.RR.size()
+ ", leaf wetness list size = " + this.BT.size()
Collections.sort(this.TM); );
Collections.sort(this.RR);
Collections.sort(this.UM);
Collections.sort(this.Q0);
this.BT = wUtil.calculateLeafWetnessHourSeriesBestEffort(this.BT,this.TM, this.RR, this.Q0, this.FM2, this.UM);
if(this.BT.size() != this.TM.size())
{
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() );
}
} }
// Must be starting at same time
if(
this.TM.get(0).getTimeMeasured().compareTo(this.RR.get(0).getTimeMeasured()) != 0
|| this.TM.get(0).getTimeMeasured().compareTo(this.BT.get(0).getTimeMeasured()) != 0
)
{
throw new ConfigValidationException("Weather parameter lists do not start at same time "
+ "Temperature list starts at = " + this.TM.get(0).getTimeMeasured()
+ ", precipitation list starts at = " + this.RR.get(0).getTimeMeasured()
+ ", leaf wetness list starts at = " + this.BT.get(0).getTimeMeasured()
);
}
int minimumNumberOfWeatherData = 24; // Must be ending at same time
if((this.TM.size() + this.RR.size() + this.BT.size()) / 3 < minimumNumberOfWeatherData) int lastIndex = this.TM.size() -1;
if(
this.TM.get(lastIndex).getTimeMeasured().compareTo(this.RR.get(lastIndex).getTimeMeasured()) != 0
|| this.TM.get(lastIndex).getTimeMeasured().compareTo(this.BT.get(lastIndex).getTimeMeasured()) != 0
)
{ {
throw new ConfigValidationException("Minimum number of weather data = " + minimumNumberOfWeatherData); throw new ConfigValidationException("Weather parameter lists do not end at same time "
+ "Temperature list ends at = " + this.TM.get(lastIndex).getTimeMeasured()
+ ", precipitation list ends at = " + this.RR.get(lastIndex).getTimeMeasured()
+ ", leaf wetness list ends at = " + this.BT.get(lastIndex).getTimeMeasured()
);
} }
// If all that's OK, chop of all hour values exceeding the last full day // If all that's OK, chop of all hour values exceeding the last full day
// of hourly data // of hourly data
this.TM = wUtil.cutTrailingHourlyValues(this.TM, timeZone); this.TM = wUtil.cutTrailingHourlyValues(this.TM, timeZone);
this.BT = wUtil.cutTrailingHourlyValues(this.BT, timeZone); this.BT = wUtil.cutTrailingHourlyValues(this.BT, timeZone);
this.RR = wUtil.cutTrailingHourlyValues(this.RR, timeZone); this.RR = wUtil.cutTrailingHourlyValues(this.RR, timeZone);
// Must be minimum 24 hours
int minimumNumberOfWeatherData = 24;
if((this.TM.size() + this.RR.size() + this.BT.size()) / 3 < minimumNumberOfWeatherData)
{
throw new ConfigValidationException("Minimum number of weather data = " + minimumNumberOfWeatherData);
}
// Then, at last, add to calculations // Then, at last, add to calculations
// Weather data are OK, let's add them to calculations matrix
this.calculations = new AppleScabCalculations();
for(WeatherObservation o: this.TM) for(WeatherObservation o: this.TM)
{ {
this.calculations.setParamDoubleValueForDate(o.getTimeMeasured(), AppleScabCalculations.TM, o.getValue()); this.calculations.setParamDoubleValueForDate(o.getTimeMeasured(), AppleScabCalculations.TM, o.getValue());
...@@ -430,7 +431,7 @@ public class AppleScabModel extends I18nImpl implements Model{ ...@@ -430,7 +431,7 @@ public class AppleScabModel extends I18nImpl implements Model{
} }
// We accumulate Mills only when there are humid conditions // We accumulate Mills only when there are humid conditions
if(this.getLeafWetness(currentTimeStamp) < LEAF_WETNESS_THRESHOLD) if(this.getLeafWetness(currentTimeStamp) != null && this.getLeafWetness(currentTimeStamp) < LEAF_WETNESS_THRESHOLD)
{ {
hoursSinceLeafWetness++; hoursSinceLeafWetness++;
// If dry for long enough, reset accumulated Mills // If dry for long enough, reset accumulated Mills
...@@ -442,7 +443,10 @@ public class AppleScabModel extends I18nImpl implements Model{ ...@@ -442,7 +443,10 @@ public class AppleScabModel extends I18nImpl implements Model{
else else
{ {
hoursSinceLeafWetness = 0; hoursSinceLeafWetness = 0;
accumulatedMills += millsTable.getMillsValue(this.getTemperature(currentTimeStamp), currentAppleScabStadium); if(this.getTemperature(currentTimeStamp) != null)
{
accumulatedMills += millsTable.getMillsValue(this.getTemperature(currentTimeStamp), currentAppleScabStadium);
}
} }
this.calculations.setParamDoubleValueForDate(currentTimeStamp, AppleScabCalculations.ACCUMULATED_MILLS, accumulatedMills); this.calculations.setParamDoubleValueForDate(currentTimeStamp, AppleScabCalculations.ACCUMULATED_MILLS, accumulatedMills);
...@@ -616,7 +620,7 @@ public class AppleScabModel extends I18nImpl implements Model{ ...@@ -616,7 +620,7 @@ public class AppleScabModel extends I18nImpl implements Model{
WeatherUtil wUtil = new WeatherUtil(); WeatherUtil wUtil = new WeatherUtil();
List<WeatherObservation> dailyAggregate = new ArrayList<>(); List<WeatherObservation> dailyAggregate = new ArrayList<>();
try { try {
dailyAggregate = wUtil.getAggregatedDailyValues(hourlyValues, this.timeZone, 23, aggregationType); dailyAggregate = wUtil.getAggregatedDailyValues(hourlyValues, this.timeZone, 21, aggregationType);
} }
catch (InvalidAggregationTypeException ex) { catch (InvalidAggregationTypeException ex) {
// TODO // TODO
......
...@@ -143,7 +143,10 @@ public class AppleScabModelTest extends TestCase { ...@@ -143,7 +143,10 @@ public class AppleScabModelTest extends TestCase {
} }
} }
public void testAcceptanceWithLeafWetnessFallback() /**
* NOT IN USE. Fallback responsibility has been passed on to data provider
*/
public void notinuseTestAcceptanceWithLeafWetnessFallback()
{ {
System.out.println("testAcceptanceWithLeafWetnessFallback"); System.out.println("testAcceptanceWithLeafWetnessFallback");
try try
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment