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

Change handling of year/timesteps

parent d5d0ab47
No related branches found
No related tags found
No related merge requests found
Showing
with 1627 additions and 1599 deletions
source diff could not be displayed: it is too large. Options to address this: view the blob.
......@@ -112,7 +112,7 @@ public class ModelConfig {
public static final int START_TIMESTEP = getIntProperty("START_TIMESTEP", 0);
public static final int END_TIMESTEP = getIntProperty("END_TIMESTEP", 1);
public static final int END_TIMESTEP = getIntProperty("END_TIMESTEP", 0);
public static final int TIMESTEP_SIZE = getIntProperty("END_TIMESTEP", 5);
public static final int BASE_YEAR = getIntProperty("BASE_YEAR", 2010);
......@@ -129,4 +129,5 @@ public class ModelConfig {
public static final double MEAT_EFFICIENCY = getDoubleProperty("MEAT_EFFICIENCY", 0.5);
public static final double LAND_CHANGE_COST = getDoubleProperty("LAND_CHANGE_COST", 2.0);
public static final double MIN_FEED_RATE = getDoubleProperty("MIN_FEED_RATE", 0.15);
public static final double SEED_AND_WASTE_FRACTION = getDoubleProperty("SEED_AND_WASTE_FRACTION", 0.1);
}
\ No newline at end of file
......@@ -243,7 +243,7 @@ public class ModelMain {
RasterSet<IrrigationCostItem> allIrrigationCosts = getIrrigationCosts();
Map<Country, Map<CropType, CropUsageData>> cropUsageDataMap = CropUsageData.readCommodityData();
HashSet<String> countryExclusionList = new HashSet<String>(Arrays.asList("Bangladesh", "Indonesia", "Sierra Leone", "Togo", "United Arab Emirates")); //"French Polynesia", "Cabo Verde", "Samoa", "Saint Vincent and the Grenadines"));
HashSet<String> countryExclusionList = new HashSet<String>(Arrays.asList("Bangladesh", "Portugal", "Haiti")); //"French Polynesia", "Cabo Verde", "Samoa", "Saint Vincent and the Grenadines"));
for (Map.Entry<Country, List<RasterKey>> entry : countryToKeysMap.entrySet()) {
Country country = entry.getKey();
......@@ -251,11 +251,11 @@ public class ModelMain {
// DEBUG code
// if (!(country.getCountryName().equals("United States of Americaxx") || country.getCountryName().equals("Russian Federationxx") || country.getCountryName().equals("Indonesia")) ) { //|| country.getCountryName().equals("China")
// continue;
// }
if (!(country.getCountryName().equals("United States of America") || country.getCountryName().equals("Russian Federationxx") || country.getCountryName().equals("Indonesiaxx")) ) { //|| country.getCountryName().equals("China")
continue;
}
if (demandManager.getPopulation(country, 2010) < 50 || countryExclusionList.contains(country.getCountryName())) {
if (demandManager.getPopulation(country, 2010) < 8 || countryExclusionList.contains(country.getCountryName())) {
LogWriter.printlnError("Skipping " + country);
continue;
}
......
......@@ -119,7 +119,7 @@ public class CountryAgent {
}
GamsCountryInput countryLevelInputs = GamsCountryInput.createInput(country, projectedDemand, worldInputEnergy, baseNetImport, maxOfProdOrSupply, cropAdjs, calibrate);
GamsRasterInput input = new GamsRasterInput(countryYieldSurfaces, prevOutput.getCropAreaRaster(), irrigationCostRaster, countryLevelInputs);
GamsRasterInput input = new GamsRasterInput(currentTimestep, countryYieldSurfaces, prevOutput.getCropAreaRaster(), irrigationCostRaster, countryLevelInputs);
return input;
}
......
......@@ -2,20 +2,23 @@ package ac.ed.lurg.country.gams;
import java.util.Map;
import ac.ed.lurg.Timestep;
import ac.ed.lurg.landuse.AreasItem;
import ac.ed.lurg.landuse.IrrigationCostItem;
import ac.ed.lurg.yield.YieldResponsesItem;
public class GamsLocationInput {
private Timestep timestep;
private Map<Integer, ? extends YieldResponsesItem> yields;
private Map<Integer, ? extends AreasItem> previousAreas;
private Map<Integer, ? extends IrrigationCostItem> irrigationCosts;
private GamsCountryInput countryInput;
public GamsLocationInput(Map<Integer, ? extends YieldResponsesItem> yields, Map<Integer, ? extends AreasItem> previousAreas,
public GamsLocationInput(Timestep timestep, Map<Integer, ? extends YieldResponsesItem> yields, Map<Integer, ? extends AreasItem> previousAreas,
Map<Integer, ? extends IrrigationCostItem> irrigationCosts, GamsCountryInput countryInput) {
super();
this.timestep = timestep;
this.yields = yields;
this.previousAreas = previousAreas;
this.irrigationCosts = irrigationCosts;
......@@ -37,4 +40,8 @@ public class GamsLocationInput {
public GamsCountryInput getCountryInput() {
return countryInput;
}
public Timestep getTimestep() {
return timestep;
}
}
......@@ -193,9 +193,11 @@ public class GamsLocationOptimiser {
@SuppressWarnings("serial")
private GamsLocationOutput handleResults(GAMSDatabase outDB) {
int modelStatus = (int) outDB.getParameter("ms").findRecord().getValue();
System.out.println(
"\nModelstatus: " + GAMSGlobals.ModelStat.lookup( modelStatus ) +
", Solvestatus: " + GAMSGlobals.SolveStat.lookup((int) outDB.getParameter("ss").findRecord().getValue()) );
LogWriter.println(String.format("\n%s %s: Modelstatus %s, Solvestatus %s",
inputData.getCountryInput().getCountry(),
inputData.getTimestep().getYear(),
GAMSGlobals.ModelStat.lookup( modelStatus ),
GAMSGlobals.SolveStat.lookup((int) outDB.getParameter("ss").findRecord().getValue()) ));
GAMSVariable varAreas = outDB.getVariable("area");
GAMSVariable varFertIntensities = outDB.getVariable("fertI");
......@@ -243,7 +245,7 @@ public class GamsLocationOptimiser {
prod = getParmValue(parmProd, itemName);
prodCost = getParmValue(parmProdCost, itemName);
cropUsageData.put(cropType, new CropUsageData(feedAmount, netImport, prod, prodCost));
cropUsageData.put(cropType, new CropUsageData(feedAmount, netImport, prod, prodCost, Double.NaN));
cropAdjs.put(cropType, cropAdj);
if (DEBUG) LogWriter.println(String.format("\n%s:\tfeedAmount= %.1f,\tnetImports= %.3f,\tprod= %.3f,\tprodCost= %.3f,\tcropAdj= %.3f", itemName, feedAmount, netImport, prod, prodCost, cropAdj));
}
......@@ -268,7 +270,7 @@ public class GamsLocationOptimiser {
netImport = varNetImports.findRecord(CropType.MEAT.getGamsName()).getLevel();
prod = parmProd.findRecord(CropType.MEAT.getGamsName()).getValue();
prodCost = parmProdCost.findRecord(CropType.MEAT.getGamsName()).getValue();
cropUsageData.put(CropType.MEAT, new CropUsageData(0.0, netImport, prod, prodCost));
cropUsageData.put(CropType.MEAT, new CropUsageData(0.0, netImport, prod, prodCost, 0));
if (DEBUG) {
LogWriter.println(String.format("\n%s:\t\t\t\t\tnetImports= %.3f,\tprod= %.3f,\tprodCost= %.3f", CropType.MEAT.getGamsName(), netImport, prod, prodCost));
LogWriter.println(String.format("\nTotal area= %.1f", totalArea));
......
......@@ -3,6 +3,7 @@ package ac.ed.lurg.country.gams;
import java.util.HashMap;
import java.util.Map;
import ac.ed.lurg.Timestep;
import ac.ed.lurg.country.Country;
import ac.ed.lurg.landuse.AreasItem;
import ac.ed.lurg.landuse.IrrigationCostItem;
......@@ -22,7 +23,7 @@ public class GamsLocationTest {
private void run() {
GamsCountryInput countryLevelInputs = GamsCountryInput.createInput(new Country("Test", "TES", 123), getProjectedDemand(), getWorldInputEnergy(), getBaseNetImport(), null, null, true);
GamsLocationInput gamsInput = new GamsLocationInput(getYields(), getPreviousArea(), getIrrigationCosts(), countryLevelInputs);
GamsLocationInput gamsInput = new GamsLocationInput(new Timestep(0), getYields(), getPreviousArea(), getIrrigationCosts(), countryLevelInputs);
GamsLocationOptimiser opti = new GamsLocationOptimiser(gamsInput);
opti.run();
......
package ac.ed.lurg.country.gams;
import ac.ed.lurg.Timestep;
import ac.ed.lurg.landuse.AreasItem;
import ac.ed.lurg.landuse.IrrigationCostItem;
import ac.ed.lurg.yield.YieldRaster;
......@@ -7,14 +8,16 @@ import ac.sac.raster.RasterSet;
public class GamsRasterInput {
private Timestep timestep;
private YieldRaster yields;
private RasterSet<AreasItem> previousAreas;
private RasterSet<IrrigationCostItem> irrigationCost;
private GamsCountryInput countryInput;
public GamsRasterInput(YieldRaster yields, RasterSet<AreasItem> previousAreas,
public GamsRasterInput(Timestep timestep, YieldRaster yields, RasterSet<AreasItem> previousAreas,
RasterSet<IrrigationCostItem> irrigationCost, GamsCountryInput countryInput) {
super();
this.timestep = timestep;
this.yields = yields;
this.previousAreas = previousAreas;
this.irrigationCost = irrigationCost;
......@@ -36,4 +39,8 @@ public class GamsRasterInput {
public GamsCountryInput getCountryInput() {
return countryInput;
}
public Timestep getTimestep() {
return timestep;
}
}
......@@ -344,7 +344,7 @@ public class GamsRasterOptimiser {
}
}
return new GamsLocationInput(aggregatedYields, aggregatedAreas, aggregatedIrrigCosts, rasterInputData.getCountryInput());
return new GamsLocationInput(rasterInputData.getTimestep(), aggregatedYields, aggregatedAreas, aggregatedIrrigCosts, rasterInputData.getCountryInput());
}
private int findCategory(List<Double> divisions, double yield) {
......
package ac.ed.lurg.country.gams;
import ac.ed.lurg.Timestep;
import ac.ed.lurg.country.Country;
import ac.ed.lurg.landuse.AreasItem;
import ac.ed.lurg.landuse.IrrigationCostItem;
......@@ -18,7 +19,7 @@ public class GamsRasterTest extends GamsLocationTest {
private void run() {
GamsCountryInput countryLevelInputs = GamsCountryInput.createInput(new Country("Test", "TES", 123), getProjectedDemand(), getWorldInputEnergy(), getBaseNetImport(), null, null, true);
GamsRasterInput input = new GamsRasterInput(getYieldRaster(), getPreviousAreaRaster(), getIrrigationCost(), countryLevelInputs);
GamsRasterInput input = new GamsRasterInput(new Timestep(0), getYieldRaster(), getPreviousAreaRaster(), getIrrigationCost(), countryLevelInputs);
GamsRasterOptimiser opti = new GamsRasterOptimiser(input);
GamsRasterOutput output = opti.run();
......
......@@ -18,18 +18,21 @@ public class CropUsageData {
private static final int FEED_COL = 4;
private static final int NET_IMPORT_COL = 5;
private static final int PROD_COL = 6;
private static final int OTHER_COL = 7;
private double feedAmount;
private double netImports;
private double prod;
private double prodCost;
public CropUsageData(double feedAmount, double netImports, double prod, double prodCost) {
private double bioenergyAmount;
public CropUsageData(double feedAmount, double netImports, double prod, double prodCost, double bioenergyAmount) {
super();
this.feedAmount = feedAmount;
this.netImports = netImports;
this.prod = prod;
this.prodCost = prodCost;
this.bioenergyAmount = bioenergyAmount;
}
public double getFeedAmount() {
......@@ -47,7 +50,10 @@ public class CropUsageData {
public double getProdCost() {
return prodCost;
}
public double getBioenergyAmount() {
return bioenergyAmount;
}
public static Map<Country, Map<CropType, CropUsageData>> readCommodityData() {
Map<Country, Map<CropType, CropUsageData>> commodityMap = new HashMap<Country, Map<CropType, CropUsageData>>();
......@@ -55,7 +61,7 @@ public class CropUsageData {
try {
BufferedReader fitReader = new BufferedReader(new FileReader(filename));
String line, countryName, commodityName;
double feedAmount, netImports, prod;
double feedAmount, netImports, prod, other;
fitReader.readLine(); // read header
while ((line=fitReader.readLine()) != null) {
......@@ -69,10 +75,11 @@ public class CropUsageData {
feedAmount = Double.parseDouble(tokens[FEED_COL]);
netImports = Double.parseDouble(tokens[NET_IMPORT_COL]);
prod = Double.parseDouble(tokens[PROD_COL]);
other = Double.parseDouble(tokens[OTHER_COL]);
Country country = CountryManager.getForName(countryName);
CropUsageData data = new CropUsageData(feedAmount, netImports, prod, Double.NaN);
CropUsageData data = new CropUsageData(feedAmount, netImports, prod, Double.NaN, other);
Map<CropType, CropUsageData> countryData = commodityMap.get(country);
if (countryData == null) {
countryData = new HashMap<CropType, CropUsageData>();
......
......@@ -64,7 +64,7 @@ public class LPJYieldResponseMapReader extends AbstractTabularRasterReader<Yield
}
else {
// TeWWhi TeWWme TeWWlo TeSWhi TeSWme TeSWlo TeCohi TeCome TeColo TrRihi TrRime TrRilo
double adjFactor = 10; // 10 for kg/m2 to t/ha
double adjFactor = 10 * (1 - ModelConfig.SEED_AND_WASTE_FRACTION) ; // 10 for kg/m2 to t/ha
boolean isSpringWheat = (getValueForCol(rowValues, "teSWhi") > getValueForCol(rowValues, "TeWWhi"));
item.setIsSpringWheat(isSpringWheat);
......@@ -84,7 +84,7 @@ public class LPJYieldResponseMapReader extends AbstractTabularRasterReader<Yield
item.setYield(yieldType, CropType.RICE, ri);
item.setYield(yieldType, CropType.TROPICAL_CEREALS, co);
item.setYield(yieldType, CropType.OILCROPS, ww);
item.setYield(yieldType, CropType.OILCROPS, isSpringWheat ? sw : ww);
item.setYield(yieldType, CropType.SOYBEAN, sw);
item.setYield(yieldType, CropType.PULSES, sw);
item.setYield(yieldType, CropType.STARCHY_ROOTS, sw);
......
......@@ -4,6 +4,7 @@ import java.util.HashMap;
import java.util.Map;
import ac.ed.lurg.types.YieldType;
import ac.ed.lurg.utils.LogWriter;
public class YieldResponse {
Map<YieldType, Double> yields = new HashMap<YieldType, Double>();
......@@ -28,22 +29,23 @@ public class YieldResponse {
}
public double getFertParam() {
if (fertParm == 0)
fertParm = calcParam (0, 0.7, 1); // we do have MID fert data, but looks wrong calcParam(getYield(YieldType.NO_FERT_NO_IRRIG), getYield(YieldType.FERT_MID_NO_IRRIG), getYield(YieldType.FERT_MAX_NO_IRRIG));
if (fertParm == 0) {
// fertParm = calcParam (0, 0.7, 1); // we do have MID fert data, but looks wrong
fertParm = calcParam(getYield(YieldType.NO_FERT_NO_IRRIG), getYield(YieldType.FERT_MID_NO_IRRIG), getYield(YieldType.FERT_MAX_NO_IRRIG), 5.0/200, 50.0/200, 200.0/200);
if (fertParm > 1)
LogWriter.println(String.format("%s %s %s", getYield(YieldType.NO_FERT_NO_IRRIG), getYield(YieldType.FERT_MID_NO_IRRIG), getYield(YieldType.FERT_MAX_NO_IRRIG)));
}
return fertParm;
}
public double getIrrigParam() {
if (irrigParm == 0)
irrigParm = calcParam (0, 0.8, 1); // we don't have a mid irrigation figure, so lets assume 60% at mid point
if (irrigParm == 0) {
irrigParm = calcParam (0, 0.6, 1, 0, 0.5, 1.0); // we don't have a mid irrigation figure, so lets assume 60% at mid point
}
return irrigParm;
}
private double calcParam(double yMin, double yMid, double yMax) {
double xMin = 0, xMid = 0.5, xMax = 1;
private double calcParam(double yMin, double yMid, double yMax, double xMin, double xMid, double xMax) {
if (yMid <= yMin || yMax <= yMid)
return 1; // default to linear
......
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