Skip to content
Snippets Groups Projects

Make sure RISK is never displayed as negative

Merged Tor-Einar Skog requested to merge debugNegativeRISK into main
3 files
+ 3561
20
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -28,8 +28,10 @@ import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import no.nibio.vips.i18n.I18nImpl;
import no.nibio.vips.entity.ModelConfiguration;
import no.nibio.vips.entity.WeatherObservation;
@@ -51,7 +53,7 @@ import no.nibio.vips.util.WeatherUtil;
* @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/
public class NaerstadModel extends I18nImpl implements Model{
private static Logger LOGGER = LoggerFactory.getLogger(NaerstadModel.class);
private boolean DEBUG = false;
private List<WeatherObservation> TM;
@@ -97,7 +99,10 @@ public class NaerstadModel extends I18nImpl implements Model{
*/
cal.add(Calendar.DATE, 1);
DecimalFormat dFormat = new DecimalFormat("###.##");
//System.out.println("RESULTS: " + this.backgroundData.toString());
if(DEBUG)
{
System.out.println("RESULTS: " + this.backgroundData.toString());
}
Date thePresent = cal.getTime();
while(thePresent.compareTo(calculationEnd) <= 0)
{
@@ -110,6 +115,10 @@ public class NaerstadModel extends I18nImpl implements Model{
{
break;
}
// The risk value should never be displayed as negative
RISK = Math.max(0.0, RISK);
if(this.DEBUG)
System.out.println("RISK(" + thePresent + ")=" + RISK);
@@ -147,7 +156,7 @@ public class NaerstadModel extends I18nImpl implements Model{
if(e instanceof ModelExcecutionException)
throw e;
// Log the error
Logger.getLogger(NaerstadModel.class.getName()).log(Level.SEVERE, null, e);
LOGGER.error(e.getMessage(), e);
throw new ModelExcecutionException("An exception occurred. Message is " + e.getMessage() + " See logs for details");
}
}
@@ -338,13 +347,23 @@ public class NaerstadModel extends I18nImpl implements Model{
* Sets up the collections
*/
private void initCollections(){
this.BT = new ArrayList();
this.Q0 = new ArrayList();
this.RR = new ArrayList();
this.TM = new ArrayList();
this.UM = new ArrayList();
this.BT = new ArrayList<>();
this.Q0 = new ArrayList<>();
this.RR = new ArrayList<>();
this.TM = new ArrayList<>();
this.UM = new ArrayList<>();
}
/**
* Survival factor of released spores
* @param Q0 Solar radiation value (Hourly w/sqm)
* @return
*/
public Double getSFRS(Double Q0)
{
return (1 - (Q0 - 270)/540)/1.5;
}
/**
* Calculates all background data for the model
* Depends on continuous weather data. This should be validated beforehand.
@@ -419,7 +438,7 @@ public class NaerstadModel extends I18nImpl implements Model{
Double VAS = ((VASLastHour * 0.95 * (1-((WVD-220)/6000))) + SPH) / (1 + (RRliste[i].getValue() * 0.3));
if(DEBUG)
{
//System.out.println(VAS + " = ((" + VASLastHour + " * 0.95 * (1-((" + WVD + "-220)/6000))) + " + SPH+ ") / (1 + (" + RRliste[i].getValue() + " * 0.3));");
System.out.println(VAS + " = ((" + VASLastHour + " * 0.95 * (1-((" + WVD + "-220)/6000))) + " + SPH+ ") / (1 + (" + RRliste[i].getValue() + " * 0.3));");
}
this.backgroundData.setParamDoubleValueForDate(TMliste[i].getTimeMeasured(), NaerstadModelBackgroundDataMatrix.VAS, VAS);
@@ -437,14 +456,16 @@ public class NaerstadModel extends I18nImpl implements Model{
// IRTA (Inhibition of Release To Air)
Double IRTA = 1-((double) BTliste[i].getValue() / 80);
// SFRS (Survival Factor of Released Spores)
Double SFRS = (1 - (Q0liste[i].getValue() - 270)/540)/1.5;
Double SFRS = this.getSFRS(Q0liste[i].getValue());
VRS = this.getVRS(VAS, RTA, IRTA, SFRS, VRSLastHour, (double) RRliste[i].getValue(), WHSLastHour);
if(DEBUG)
{
//System.out.println(TMliste[i].getTimeMeasured().toString() + ": SPH=" + SPH + ", RR[t]=" + RRliste[i].getValue() + ", WVD=" + WVD + ", VAS=" + VAS + ", RTA=" + RTA + ", IRTA=" + IRTA + ", SFRS=" + SFRS + ", VRSLastHour=" + VRSLastHour + ", WHSLastHour=" + WHSLastHour);
System.out.println(TMliste[i].getTimeMeasured().toString() + ": SPH=" + SPH + ", RR[t]=" + RRliste[i].getValue() + ", WVD=" + WVD + ", VAS=" + VAS + ", RTA=" + RTA + ", IRTA=" + IRTA + ", VRS = " + VRS + ", SFRS=" + SFRS + ", VRSLastHour=" + VRSLastHour + ", WHSLastHour=" + WHSLastHour);
}
VRS = this.getVRS(VAS, RTA, IRTA, SFRS, VRSLastHour, (double) RRliste[i].getValue(), WHSLastHour);
}
}
this.backgroundData.setParamDoubleValueForDate(TMliste[i].getTimeMeasured(), NaerstadModelBackgroundDataMatrix.VRS, VRS);
Loading