Skip to content
Snippets Groups Projects
Commit 258d1230 authored by Peter Alexander's avatar Peter Alexander
Browse files

Changes to LPJG column names

parent 6ef910e8
No related branches found
No related tags found
No related merge requests found
package ac.ed.lurg.types; package ac.ed.lurg.types;
import ac.ed.lurg.ModelConfig;
public enum FertiliserRate { public enum FertiliserRate {
NO_FERT("lo"), NO_FERT(String.format("%03.0f", ModelConfig.MIN_FERT_AMOUNT)),
MID_FERT("me"), MID_FERT(String.format("%03.0f", ModelConfig.MID_FERT_AMOUNT)),
MAX_FERT("hi"); MAX_FERT(String.format("%03.0f", ModelConfig.MAX_FERT_AMOUNT));
private String fertId; private String fertId;
......
...@@ -43,4 +43,8 @@ public enum YieldType { ...@@ -43,4 +43,8 @@ public enum YieldType {
public IrrigationRate getIrrigationRate() { public IrrigationRate getIrrigationRate() {
return irrigationRate; return irrigationRate;
} }
public String getFertIrrigString() {
return irrigationRate.getId() + fertiliserRate.getId();
}
} }
...@@ -15,12 +15,11 @@ import ac.sac.raster.AbstractTabularRasterReader; ...@@ -15,12 +15,11 @@ import ac.sac.raster.AbstractTabularRasterReader;
import ac.sac.raster.RasterHeaderDetails; import ac.sac.raster.RasterHeaderDetails;
import ac.sac.raster.RasterKey; import ac.sac.raster.RasterKey;
public class LPJYieldResponseMapReader extends AbstractTabularRasterReader<YieldResponsesItem> { public class LPJYieldResponseMapReader {
private RasterHeaderDetails rasterProj; private RasterHeaderDetails rasterProj;
public LPJYieldResponseMapReader(RasterHeaderDetails rasterProj) { public LPJYieldResponseMapReader(RasterHeaderDetails rasterProj) {
super(" +", 10);
this.rasterProj = rasterProj; this.rasterProj = rasterProj;
} }
...@@ -38,68 +37,65 @@ public class LPJYieldResponseMapReader extends AbstractTabularRasterReader<Yield ...@@ -38,68 +37,65 @@ public class LPJYieldResponseMapReader extends AbstractTabularRasterReader<Yield
LogWriter.println("Found marker file in " + (System.currentTimeMillis() - startTime) + " ms"); LogWriter.println("Found marker file in " + (System.currentTimeMillis() - startTime) + " ms");
YieldRaster yieldRaster = new YieldRaster(rasterProj); YieldRaster yieldRaster = new YieldRaster(rasterProj);
dataset = yieldRaster; readNppFile(yieldRaster, rootDir+File.separator+ModelConfig.ANPP_FILENAME);
readYieldFile(yieldRaster, rootDir+File.separator+ModelConfig.YIELD_FILENAME);
String nppFilename = rootDir + File.separator + ModelConfig.ANPP_FILENAME;
getRasterDataFromFile(nppFilename);
String yieldFilename = rootDir + File.separator + ModelConfig.YIELD_FILENAME;
getRasterDataFromFile(yieldFilename);
return yieldRaster; return yieldRaster;
} }
private void readNppFile(YieldRaster yieldRaster, String fileToRead) { // Passed in YieldRaster is updated
@Override AbstractTabularRasterReader<YieldResponsesItem> nppReader = new AbstractTabularRasterReader<YieldResponsesItem>(" +", 10, yieldRaster) {
protected void setData(RasterKey key, YieldResponsesItem item, Map<String, Double> rowValues) { protected void setData(RasterKey key, YieldResponsesItem item, Map<String, Double> rowValues) {
double adjFactor = 2 * 10 * ModelConfig.PASTURE_HARVEST_FRACTION; // 2 for carbon units, 10 for kg/m2 to t/ha, and 0.5 for half grazed
boolean isC3 = (getValueForCol(rowValues, "PC3GN005") > getValueForCol(rowValues, "PC4GN005"));
for (FertiliserRate fert : FertiliserRate.values()) {
double pastureYield = (isC3 ? getValueForCol(rowValues, "PC3GN" + fert.getId()) : getValueForCol(rowValues, "PC4GN" + fert.getId())) * adjFactor;
item.setYield(YieldType.getYieldType(fert, IrrigationRate.NO_IRRIG), CropType.PASTURE, pastureYield);
item.setYield(YieldType.getYieldType(fert, IrrigationRate.MAX_IRRIG), CropType.PASTURE, pastureYield);
}
}
};
if (rowValues.containsKey("C4G_pas".toLowerCase())) { // need to work out if it's the yield.out or the anpp.out file, this isn't very nice, but should work ok nppReader.getRasterDataFromFile(fileToRead);
}
// C3G_pas C4G_pas TeWWhi TeWWme TeWWlo TeSWhi TeSWme TeSWlo TeCohi TeCome TeColo TrRihi TrRime TrRilo Total Crop_sum Pasture_sum
double adjFactor = 2 * 10 * ModelConfig.PASTURE_HARVEST_FRACTION; // 2 for carbon units, 10 for kg/m2 to t/ha, and 0.5 for half grazed
double pastureYield = Math.max(getValueForCol(rowValues, "C3G_pas") + getValueForCol(rowValues, "C4G_pas"), 0) * adjFactor;
item.setYield(YieldType.NO_FERT_NO_IRRIG, CropType.PASTURE, pastureYield);
item.setYield(YieldType.NO_FERT_IRRIG_MAX, CropType.PASTURE, pastureYield*1.2);
item.setYield(YieldType.FERT_MID_NO_IRRIG, CropType.PASTURE, pastureYield*1.1);
item.setYield(YieldType.FERT_MID_IRRIG_MAX, CropType.PASTURE, pastureYield*1.3);
item.setYield(YieldType.FERT_MAX_NO_IRRIG, CropType.PASTURE, pastureYield*1.3);
item.setYield(YieldType.FERT_MAX_IRRIG_MAX, CropType.PASTURE, pastureYield*1.4);
}
else {
double adjFactor;
boolean isSpringWheat = (getValueForCol(rowValues, "teSWhi") > getValueForCol(rowValues, "TeWWhi")); private void readYieldFile(YieldRaster yieldRaster, String fileToRead) { // Passed in YieldRaster is updated
item.setIsSpringWheat(isSpringWheat);
AbstractTabularRasterReader<YieldResponsesItem> yieldReader = new AbstractTabularRasterReader<YieldResponsesItem>(" +", 10, yieldRaster) {
protected void setData(RasterKey key, YieldResponsesItem item, Map<String, Double> rowValues) {
double adjFactor = 10; // 10 for kg/m2 to t/ha
String highFertString = YieldType.getYieldType(FertiliserRate.MAX_FERT, IrrigationRate.NO_IRRIG).getFertIrrigString();
boolean isSpringWheat = (getValueForCol(rowValues, "teSW" + highFertString) > getValueForCol(rowValues, "TeWW" + highFertString));
item.setIsSpringWheat(isSpringWheat);
for (FertiliserRate fert : FertiliserRate.values()) {
for (IrrigationRate irrig : IrrigationRate.values()) {
YieldType yieldType = YieldType.getYieldType(fert, irrig);
String fertIrrigString = yieldType.getFertIrrigString();
for (FertiliserRate fert : FertiliserRate.values()) { /*
for (IrrigationRate irrig : IrrigationRate.values()) { * WARNING: if you change mapping below you also need to change LpjgOutputer and IrrigationMaxAmountReader to match
YieldType yieldType = YieldType.getYieldType(fert, irrig); */
double ww = getValueForCol(rowValues, "TeWW" + fertIrrigString) * adjFactor;
// if (fert.equals(FertiliserRate.NO_FERT)) double sw = getValueForCol(rowValues, "TeSW" + fertIrrigString) * adjFactor;
// adjFactor = 10 * 0.4; // adjust no fert yield to 40% of figure double co = getValueForCol(rowValues, "TeCo" + fertIrrigString) * adjFactor;
// else if (fert.equals(FertiliserRate.MID_FERT)) double ri = getValueForCol(rowValues, "TrRi" + fertIrrigString) * adjFactor;
// adjFactor = 10 * 0.9; // adjust mid fert yield to 90% of figure
// else item.setYield(yieldType, CropType.WHEAT, isSpringWheat ? sw : ww);
adjFactor = 10; // 10 for kg/m2 to t/ha item.setYield(yieldType, CropType.MAIZE, co);
item.setYield(yieldType, CropType.RICE, ri);
String fertIrrigString = irrig.getId() + fert.getId(); item.setYield(yieldType, CropType.OILCROPS, isSpringWheat ? sw : ww);
item.setYield(yieldType, CropType.PULSES, sw);
/* item.setYield(yieldType, CropType.STARCHY_ROOTS, sw);
* WARNING: if you can mapping below you also need to change LpjgOutputer and IrrigationMaxAmountReader to match }
*/
double ww = getValueForCol(rowValues, "TeWW" + fertIrrigString) * adjFactor;
double sw = getValueForCol(rowValues, "TeSW" + fertIrrigString) * adjFactor;
double co = getValueForCol(rowValues, "TeCo" + fertIrrigString) * adjFactor;
double ri = getValueForCol(rowValues, "TrRi" + fertIrrigString) * adjFactor;
item.setYield(yieldType, CropType.WHEAT, isSpringWheat ? sw : ww);
item.setYield(yieldType, CropType.MAIZE, co);
item.setYield(yieldType, CropType.RICE, ri);
item.setYield(yieldType, CropType.OILCROPS, isSpringWheat ? sw : ww);
item.setYield(yieldType, CropType.PULSES, sw);
item.setYield(yieldType, CropType.STARCHY_ROOTS, sw);
} }
} }
} };
yieldReader.getRasterDataFromFile(fileToRead);
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment