Skip to content
Snippets Groups Projects
Commit 20cd3a44 authored by Bhabesh Bhabani Mukhopadhyay's avatar Bhabesh Bhabani Mukhopadhyay
Browse files

Generic Phenology

Initiation of generic phenology
parent 1cfaf27e
No related branches found
No related tags found
No related merge requests found
......@@ -26,6 +26,7 @@ import no.nibio.vips.logic.entity.ForecastConfiguration;
import no.nibio.vips.logic.entity.PointOfInterestWeatherStation;
import no.nibio.vips.logic.scheduling.model.ModelRunPreprocessor;
import no.nibio.vips.logic.scheduling.model.PreprocessorException;
import no.nibio.vips.logic.util.Plant;
import no.nibio.vips.logic.util.Plantation;
import no.nibio.vips.logic.util.SessionControllerGetter;
import no.nibio.vips.logic.util.SystemTime;
......@@ -46,19 +47,19 @@ public class PhenologyModelPreprocessor extends ModelRunPreprocessor{
public final Logger LOGGER = Logger.getLogger(this.getClass().getName());
private final boolean DEBUG = false;
private final static String MODEL_ID = "PHENOLOGYM";
private final static String MAIZE_VARITY = "maizeVarity";
private final static String TYPE_NAME = "typeName";
private final static String SOWING_DATE = "sowingDate";
private final static String SOWING_DATA = "sowingData";
//private final static String SOWING_DATA = "sowingData";
private final static String PLANTATION_DATA = "plantationData";
private final static String FILE_PLANTATION = "/dataset/plantationData.json";
@Override
public ModelConfiguration getModelConfiguration(ForecastConfiguration configuration) throws PreprocessorException {
String PHENOLOGY_MAZE_VARIETY = SessionControllerGetter.getForecastBean().getDeCamelizedFieldName(MODEL_ID, MAIZE_VARITY);
String PHENOLOGY_TYPE_NAME = SessionControllerGetter.getForecastBean().getDeCamelizedFieldName(MODEL_ID, TYPE_NAME);
String PHENOLOGY_SOWING_DATE = SessionControllerGetter.getForecastBean().getDeCamelizedFieldName(MODEL_ID, SOWING_DATE);
String paramMazeVariety = null;
String paramPhenologyTypeName = null;
Date paramSowingDate = null;
......@@ -79,7 +80,7 @@ public class PhenologyModelPreprocessor extends ModelRunPreprocessor{
cal.set(Calendar.MONTH, Calendar.JANUARY);
cal.set(Calendar.DATE, 1);
Plantation sowdata = new Plantation();
Plant plant = new Plant();
try
{
......@@ -119,7 +120,7 @@ public class PhenologyModelPreprocessor extends ModelRunPreprocessor{
paramMazeVariety = configuration.getForecastModelConfigurationValue(PHENOLOGY_MAZE_VARIETY);
paramPhenologyTypeName = configuration.getForecastModelConfigurationValue(PHENOLOGY_TYPE_NAME);
Collections.sort(observations);
......@@ -156,14 +157,23 @@ public class PhenologyModelPreprocessor extends ModelRunPreprocessor{
LOGGER.log(Level.CONFIG, "Observations=" + observations.toString());
}
sowdata.setVarietyId(paramMazeVariety);
sowdata.setStartDate(paramSowingDate);
Plant plantDBData = getConfigurationPlantation(FILE_PLANTATION);
if(plantDBData.getTypeName().equals(paramPhenologyTypeName))
{
plant = plantDBData;
plant.setStartDate(paramSowingDate);
}
//plant.setTypeName(paramPhenologyTypeName);
//plant.setStartDate(paramSowingDate);
retVal.setModelId(this.getModelId());
retVal.setConfigParameter("timeZone", timeZone.getID());
retVal.setConfigParameter("observations", observations);
retVal.setConfigParameter(SOWING_DATA, sowdata);
retVal.setConfigParameter(PLANTATION_DATA, getConfigurationPlantation(FILE_PLANTATION));
//retVal.setConfigParameter(SOWING_DATA, plant);
retVal.setConfigParameter(PLANTATION_DATA, plant);
return retVal;
......@@ -271,6 +281,7 @@ public class PhenologyModelPreprocessor extends ModelRunPreprocessor{
// Fallback if missing leaf wetness: If we have relative humidity. leaf wetness may be calculated
/*
if((BT.size() != TM.size()) && (UM.size() == TM.size()))
{
BT = wUtil.calculateLeafWetnessHourSeriesBestEffort(BT,TM, RR, Q0, FM2, UM);
......@@ -285,16 +296,21 @@ public class PhenologyModelPreprocessor extends ModelRunPreprocessor{
LOGGER.log(Level.WARNING, "TM starts " + TM.get(0).getTimeMeasured() + ", ends " + TM.get(TM.size()-1).getTimeMeasured());
throw new ConfigValidationException("Incorrect number of weather data. TM.size() = " + TM.size() + ", BT.size()=" + BT.size() + ", RR.size()=" + RR.size() + ", UM.size()=" + UM.size() );
}
*/
}
List<WeatherObservation> retVal = new ArrayList<>();
retVal.addAll(TM);
retVal.addAll(RR);
retVal.addAll(BT);
// retVal.addAll(RR);
// retVal.addAll(BT);
Collections.sort(retVal);
return retVal;
}
private List<Plantation> getConfigurationPlantation(String fileName)
private Plant getConfigurationPlantation(String fileName)
{
Plant plant = new Plant();
List<Plantation> plantations = new ArrayList<Plantation>();
......@@ -304,6 +320,11 @@ public class PhenologyModelPreprocessor extends ModelRunPreprocessor{
JsonParser jp = f.createParser(inputStream);
JsonNode all = jp.readValueAsTree();
JsonNode nodePhaseInfo = all.path("phaseInfo");
plant.setSpeciesLatinName(all.get("speciesLatinName").asText());
plant.setTypeName(all.get("typeName").asText());
plant.setBaseTemp(all.get("baseTemp").asDouble());
if(nodePhaseInfo.isArray())
{
for(JsonNode node : nodePhaseInfo)
......@@ -317,32 +338,14 @@ public class PhenologyModelPreprocessor extends ModelRunPreprocessor{
}
}
/*
if(all.isArray())
{
for(JsonNode node : all)
{
Plantation plantation = new Plantation
(
node.get("maizeVarity").asText()
, node.get("phaseName").asText()
, node.get("baseTemp").asText()
, node.get("heatReq").asDouble()
);
plantations.add(plantation);
}
}
*/
plant.setPlantations(plantations);
} catch (IOException ex) {
Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
}
return plantations;
return plant;
}
}
package no.nibio.vips.logic.util;
import java.util.Date;
import java.util.List;
/**
*
* @author wildfly
*/
public class Plant {
private String speciesLatinName;
private String typeName;
private Double baseTemp;
private Date startDate;
private List<Plantation> plantations;
public String getSpeciesLatinName() {
return speciesLatinName;
}
public void setSpeciesLatinName(String speciesLatinName) {
this.speciesLatinName = speciesLatinName;
}
public String getTypeName() {
return typeName;
}
public void setTypeName(String typeName) {
this.typeName = typeName;
}
public Double getBaseTemp() {
return baseTemp;
}
public void setBaseTemp(Double baseTemp) {
this.baseTemp = baseTemp;
}
public Date getStartDate() {
return startDate;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
public List<Plantation> getPlantations() {
return plantations;
}
public void setPlantations(List<Plantation> plantations) {
this.plantations = plantations;
}
}
......@@ -10,26 +10,17 @@ import java.util.Date;
public class Plantation {
private String varietyId;
private String typeName;
private String phaseName;
private String baseTemp;
//private String baseTemp;
private Double heatReq;
private Date startDate;
//private Date startDate;
public Plantation() {
}
public Plantation(String varietyId, String phaseName, String baseTemp, Double heatReq) {
this.varietyId = varietyId;
this.phaseName = phaseName;
this.baseTemp = baseTemp;
this.heatReq = heatReq;
}
public Plantation(String varietyId, String phaseName, Double heatReq) {
this.varietyId = varietyId;
public Plantation(String typeName, String phaseName, Double heatReq) {
this.typeName = typeName;
this.phaseName = phaseName;
this.heatReq = heatReq;
}
......@@ -39,12 +30,12 @@ public class Plantation {
this.heatReq = heatReq;
}
public String getVarietyId() {
return varietyId;
public String getTypeName() {
return typeName;
}
public void setVarietyId(String varietyId) {
this.varietyId = varietyId;
public void setTypeName(String typeName) {
this.typeName = typeName;
}
public String getPhaseName() {
......@@ -55,14 +46,6 @@ public class Plantation {
this.phaseName = phaseName;
}
public String getBaseTemp() {
return baseTemp;
}
public void setBaseTemp(String baseTemp) {
this.baseTemp = baseTemp;
}
public Double getHeatReq() {
return heatReq;
}
......@@ -71,22 +54,9 @@ public class Plantation {
this.heatReq = heatReq;
}
public Date getStartDate() {
return startDate;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
@Override
public String toString() {
return "Plantation{" + "varietyId=" + varietyId + ", phaseName=" + phaseName + ", baseTemp=" + baseTemp + ", heatSum=" + heatReq + ", sowingDate=" + startDate + '}';
return "Plantation{" + "typeName=" + typeName + ", phaseName=" + phaseName + ", heatReq=" + heatReq + '}';
}
}
......@@ -19,7 +19,7 @@
"_comment" : "Structure of the specific fields for FAWPHENOLO",
"fields": [
{
"name" : "maizeVarity",
"name" : "typeName",
"dataType" : "STRING",
"fieldType" : "SELECT_SINGLE",
"required" : false,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment