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

Fixing relation to new weather service

parent 30fc38e8
Branches
Tags
No related merge requests found
Pipeline #18 failed
...@@ -167,6 +167,7 @@ public class RoughageService { ...@@ -167,6 +167,7 @@ public class RoughageService {
// We must do some special adjustmens to get weather forecasts from 3-9 days in // We must do some special adjustmens to get weather forecasts from 3-9 days in
// the future // the future
// For EPP and Q0 we simply add the last value // For EPP and Q0 we simply add the last value
//System.out.println("observations.size=" + observations.size());
WeatherObservation lastEPP = wUtil.getLastObservations(observations, "EPP", 1).get(0); WeatherObservation lastEPP = wUtil.getLastObservations(observations, "EPP", 1).get(0);
Date lastEPPDate = lastEPP.getTimeMeasured(); Date lastEPPDate = lastEPP.getTimeMeasured();
while(lastEPPDate.before(dateOfLastWeatherData)) while(lastEPPDate.before(dateOfLastWeatherData))
...@@ -192,7 +193,7 @@ public class RoughageService { ...@@ -192,7 +193,7 @@ public class RoughageService {
// For TM and RR we get long time forecasts from LMT (Norwegian service only) // For TM and RR we get long time forecasts from LMT (Norwegian service only)
try { try {
//System.out.println("Last TM dated " + wUtil.getLastObservations(observations, "TM", 1).get(0).getTimeMeasured()); //System.out.println("dateOfLastWeatherData=" + dateOfLastWeatherData + ", last TM dated " + wUtil.getLastObservations(observations, "TM", 1).get(0).getTimeMeasured());
cal.setTime(wUtil.getLastObservations(observations, "TM", 1).get(0).getTimeMeasured()); cal.setTime(wUtil.getLastObservations(observations, "TM", 1).get(0).getTimeMeasured());
cal.add(Calendar.DATE, 1); cal.add(Calendar.DATE, 1);
Date firstLongTermForecastTime = cal.getTime(); Date firstLongTermForecastTime = cal.getTime();
...@@ -222,7 +223,10 @@ public class RoughageService { ...@@ -222,7 +223,10 @@ public class RoughageService {
}*/ }*/
List<WeatherObservation> TMDLongTime = wUtil.getAggregatedDailyValues(TMLongTime, timeZone, 15, WeatherUtil.AGGREGATION_TYPE_AVERAGE); List<WeatherObservation> TMDLongTime = wUtil.getAggregatedDailyValues(TMLongTime, timeZone, 15, WeatherUtil.AGGREGATION_TYPE_AVERAGE);
observations.addAll(TMDLongTime); if(TMDLongTime != null)
{
observations.addAll(TMDLongTime);
}
...@@ -240,7 +244,10 @@ public class RoughageService { ...@@ -240,7 +244,10 @@ public class RoughageService {
RRLongTime = wUtil.fillHourlyHolesBruteForce(RRLongTime, WeatherUtil.AGGREGATION_TYPE_SUM, firstLongTermForecastTime, dateOfLastWeatherData); RRLongTime = wUtil.fillHourlyHolesBruteForce(RRLongTime, WeatherUtil.AGGREGATION_TYPE_SUM, firstLongTermForecastTime, dateOfLastWeatherData);
List<WeatherObservation> RRDLongTime = wUtil.getAggregatedDailyValues(RRLongTime, timeZone, 15, WeatherUtil.AGGREGATION_TYPE_SUM); List<WeatherObservation> RRDLongTime = wUtil.getAggregatedDailyValues(RRLongTime, timeZone, 15, WeatherUtil.AGGREGATION_TYPE_SUM);
observations.addAll(RRDLongTime); if(RRDLongTime != null)
{
observations.addAll(RRDLongTime);
}
} }
} }
catch(WeatherDataSourceException | InvalidAggregationTypeException | WeatherObservationListException ex) catch(WeatherDataSourceException | InvalidAggregationTypeException | WeatherObservationListException ex)
...@@ -394,15 +401,18 @@ public class RoughageService { ...@@ -394,15 +401,18 @@ public class RoughageService {
// Last date to fetch data // Last date to fetch data
Date latestObsDate = wUtil.getLastObservations(observations, "TM", 1).get(0).getTimeMeasured(); Date latestObsDate = wUtil.getLastObservations(observations, "TM", 1).get(0).getTimeMeasured();
weatherStation = em.find(PointOfInterestWeatherStation.class, normalDataWeatherStationId); weatherStation = em.find(PointOfInterestWeatherStation.class, normalDataWeatherStationId);
weatherStation.getWeatherStationDataSourceId().setDatafetchUriExpression(
weatherStation.getWeatherStationDataSourceId().getDatafetchUriExpression().replaceFirst("forecastfallback", "grovfornormal")
);
observations = wsdUtil.getWeatherObservations( observations = wsdUtil.getWeatherObservations(
weatherStation, weatherStation,
WeatherObservation.LOG_INTERVAL_ID_1D, WeatherObservation.LOG_INTERVAL_ID_1D,
new String[]{ new String[]{
WeatherElements.getNormalDataParameter(WeatherElements.TEMPERATURE_MEAN), WeatherElements.TEMPERATURE_MEAN,
WeatherElements.getNormalDataParameter(WeatherElements.PRECIPITATION), WeatherElements.PRECIPITATION,
WeatherElements.getNormalDataParameter(WeatherElements.GLOBAL_RADIATION), WeatherElements.GLOBAL_RADIATION,
WeatherElements.getNormalDataParameter(WeatherElements.SOIL_TEMPERATURE_10CM_MEAN), WeatherElements.SOIL_TEMPERATURE_10CM_MEAN,
WeatherElements.getNormalDataParameter(WeatherElements.POTENTIAL_EVAPORATION) WeatherElements.POTENTIAL_EVAPORATION
}, },
aprilFirst, aprilFirst,
//dateOfLastWeatherData //dateOfLastWeatherData
...@@ -411,7 +421,7 @@ public class RoughageService { ...@@ -411,7 +421,7 @@ public class RoughageService {
// The observations are tainted with the _NORMAL prefix, must clean up // The observations are tainted with the _NORMAL prefix, must clean up
// before sending to model // before sending to model
observations.stream().forEach(obs->obs.setElementMeasurementTypeId(obs.getElementMeasurementTypeId().substring(0, obs.getElementMeasurementTypeId().indexOf("_NORMAL")))); //observations.stream().forEach(obs->obs.setElementMeasurementTypeId(obs.getElementMeasurementTypeId().substring(0, obs.getElementMeasurementTypeId().indexOf("_NORMAL"))));
// Add waterings to normal data precipitation? // Add waterings to normal data precipitation?
if( if(
......
...@@ -70,7 +70,9 @@ public class ZymoseptoriaSimpleRiskGridModelPreprocessor extends ModelRunPreproc ...@@ -70,7 +70,9 @@ public class ZymoseptoriaSimpleRiskGridModelPreprocessor extends ModelRunPreproc
} }
catch(WeatherObservationListException ex) catch(WeatherObservationListException ex)
{ {
throw new PreprocessorException("Problem with station #" + station.getPointOfInterestId() + ": " + ex.getMessage()); //throw new PreprocessorException();
System.out.println("Problem with station " + station.getPointOfInterest().getName() + " (#" + station.getPointOfInterestId() + "): " + ex.getMessage());
continue;
} }
// Checking for BT // Checking for BT
try try
......
...@@ -47,6 +47,8 @@ import org.apache.commons.io.IOUtils; ...@@ -47,6 +47,8 @@ import org.apache.commons.io.IOUtils;
* @author Tor-Einar Skog <tor-einar.skog@nibio.no> * @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/ */
public class WeatherDataSourceUtil { public class WeatherDataSourceUtil {
private final boolean DEBUG = false;
/** /**
* Fetches measured data from the stations weather data source, and optionally * Fetches measured data from the stations weather data source, and optionally
...@@ -186,7 +188,7 @@ public class WeatherDataSourceUtil { ...@@ -186,7 +188,7 @@ public class WeatherDataSourceUtil {
int readTimeout = 120; int readTimeout = 120;
try { try {
URL weatherURL = new URL(URL.toString()); URL weatherURL = new URL(URL.toString());
//System.out.println("URL=" + weatherURL); if(this.DEBUG) { System.out.println("URL=" + weatherURL); }
URLConn = weatherURL.openConnection(); URLConn = weatherURL.openConnection();
URLConn.setConnectTimeout(1000 * connectTimeout); // If weather data server does not reply in 30 seconds, abort URLConn.setConnectTimeout(1000 * connectTimeout); // If weather data server does not reply in 30 seconds, abort
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment