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

Custom growth start calc date [GROVFOR-10]

parent 681a67f2
Branches
Tags
No related merge requests found
......@@ -73,6 +73,7 @@ public class RoughageNutritionModel implements Model {
private Date firstHarvest;
private Date secondHarvest;
private Date firstPossibleGrowthStartDate;
private Integer soilType;
private Integer cloverShare;
private List<OptimizationObservation> optimizationObservations;
......@@ -90,6 +91,7 @@ public class RoughageNutritionModel implements Model {
Q0D,
firstHarvest,
secondHarvest,
firstPossibleGrowthStartDate,
soilType,
cloverShare,
optimizationObservations,
......@@ -246,7 +248,7 @@ public class RoughageNutritionModel implements Model {
List<WeatherObservation> globalStraaling, Q0
Date foersteslaatt,
Date andreslaatt,
Date tidligsteVekststart,
Date tidligsteVekststart, // Default: 1. mars
int jordtype,
int kloeverandel,
List<OptimizationObservation> observasjoner
......@@ -289,6 +291,20 @@ public class RoughageNutritionModel implements Model {
{
this.secondHarvest = mapper.convertValue(config.getConfigParameter("secondHarvest"), Date.class);
}
if(config.getConfigParameter("firstPossibleGrowthStartDate") != null)
{
this.firstPossibleGrowthStartDate = mapper.convertValue(config.getConfigParameter("firstPossibleGrowthStartDate"), Date.class);
}
else
{
Calendar cal = Calendar.getInstance();
cal.setTime(firstHarvest);
cal.set(Calendar.MONTH, Calendar.MARCH);
cal.set(Calendar.DATE, 1);
this.firstPossibleGrowthStartDate = cal.getTime();
}
if(config.getConfigParameter("soilType") != null)
{
this.soilType = mapper.convertValue(config.getConfigParameter("soilType"), Integer.class);
......@@ -309,6 +325,8 @@ public class RoughageNutritionModel implements Model {
List<WeatherObservation> observations = mapper.convertValue(config.getConfigParameter("observations"), new TypeReference<List<WeatherObservation>>(){});
for(WeatherObservation o:observations)
......
......@@ -33,6 +33,7 @@ import java.util.TimeZone;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import no.nibio.vips.entity.WeatherObservation;
import no.nibio.vips.model.ModelExcecutionException;
......@@ -43,12 +44,15 @@ import org.apache.commons.math.optimization.CostException;
import org.apache.commons.math.optimization.CostFunction;
import org.apache.commons.math.optimization.NelderMead;
import org.apache.commons.math.optimization.PointCostPair;
import org.slf4j.LoggerFactory;
/**
* @copyright 2018 <a href="http://www.nibio.no/">NIBIO</a>
* @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/
public class RoughageNutritionModelImpl implements CostFunction {
private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(RoughageNutritionModelImpl.class);
// Globale variable som må nullstilles for hver beregning av modellen
private List<WeatherObservation> nedboerVerdier;
......@@ -67,6 +71,7 @@ public class RoughageNutritionModelImpl implements CostFunction {
private Date datoFoersteSlaatt;
private Date datoAndreSlaatt;
private Date foersteMuligeVekststartdato;
private Integer jordtype;
private Integer kloeverandel;
......@@ -135,6 +140,7 @@ public class RoughageNutritionModelImpl implements CostFunction {
List<WeatherObservation> dailyGlobalRadiation,
Date firstHarvest,
Date secondHarvest,
Date firstPossibleGrowthStartDate,
int soilType,
int cloverShare,
List<OptimizationObservation> optimizationObservations,
......@@ -150,6 +156,7 @@ public class RoughageNutritionModelImpl implements CostFunction {
this.datoAndreSlaatt = secondHarvest;
this.jordtype = soilType;
this.kloeverandel = cloverShare;
this.foersteMuligeVekststartdato = firstPossibleGrowthStartDate;
this.calculatedDateOfGrowthStart = null;
this.timeZone = timeZone;
......@@ -456,6 +463,8 @@ public class RoughageNutritionModelImpl implements CostFunction {
Integer dagNummer = 1;
for (Iterator<WeatherObservation> tempI = this.luftTemperaturVerdier.iterator(); tempI.hasNext();) {
temperatur = tempI.next();
// Beregner TS1
double TS1;
......@@ -1221,17 +1230,30 @@ public class RoughageNutritionModelImpl implements CostFunction {
/**
*
* @return @throws com.ac.march.ModelExcecutionException
* @return
* @throws no.nibio.vips.model.ModelExcecutionException
*/
protected Date getVekstStart() throws ModelExcecutionException {
if (this.calculatedDateOfGrowthStart == null) {
this.calculatedDateOfGrowthStart = this.getVekstStart(this.luftTemperaturVerdier, this.jordTemperaturVerdier);
// Filtrer bort datoer før første mulige vekststartdato
if(this.foersteMuligeVekststartdato != null)
{
List<WeatherObservation> TMFiltrert = this.luftTemperaturVerdier.stream()
.filter(wo->wo.getTimeMeasured().compareTo(this.foersteMuligeVekststartdato) >=0 )
.collect(Collectors.toList());
List<WeatherObservation> TJMFiltrert = this.jordTemperaturVerdier.stream()
.filter(wo->wo.getTimeMeasured().compareTo(this.foersteMuligeVekststartdato) >=0 )
.collect(Collectors.toList());
this.calculatedDateOfGrowthStart = this.getVekstStart(TMFiltrert, TJMFiltrert);
LOGGER.debug("calculatedDateOfGrowthStart=" + this.calculatedDateOfGrowthStart);
}
}
return this.calculatedDateOfGrowthStart;
}
/**
* Beregner datoen hvor vekststart antas å inntreffe. Vekststart antas å
* Beregner datoen hvor vekststart antas å inntreffe.Vekststart antas å
* inntreffe etter tre påfølgende femdøgnsmiddel av temperatur > 5 grader
* Celcius. Dvs. datoen blir den tredje av disse påfølgende femdøgnsmiddel.
* Endring 2013-10-06: Hvis vi har jordtemperatur tilgjengelig, så må det
......@@ -1242,6 +1264,7 @@ public class RoughageNutritionModelImpl implements CostFunction {
* @param jordTemperatur
* @return Dato for vekststart, eller null hvis ikke betingelsene for
* vekstart er oppfylt i de gitte klimadata
* @throws no.nibio.vips.model.ModelExcecutionException
*/
protected Date getVekstStart(Collection dognMiddelLuftTemperatur, Collection jordTemperatur) throws ModelExcecutionException {
double lufttempTerskel = 5.0;
......
......@@ -49,7 +49,7 @@ import static org.junit.Assert.*;
/**
*
* @author treinar
* @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/
public class RoughageNutritionModelTest {
......@@ -86,6 +86,9 @@ public class RoughageNutritionModelTest {
cal.set(Calendar.MILLISECOND,0);
config.setConfigParameter("timeZone","Europe/Oslo");
config.setConfigParameter("firstHarvest", cal.getTime());
cal.set(Calendar.MONTH, Calendar.APRIL);
cal.set(Calendar.DATE, 15);
config.setConfigParameter("firstPossibleGrowthStartDate", cal.getTime());
config.setConfigParameter("soilType", RoughageNutritionModel.JORDTYPE_SAND);
config.setConfigParameter("cloverShare", RoughageNutritionModel.ENGSAMMENSETNING_KLOEVERANDEL_LITEN);
String[] optimizationInfoLines = {"2016-06-02,2,3,,,,"};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment