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

Added bioenergy demand

parent 2ba3a0e9
No related branches found
No related tags found
No related merge requests found
......@@ -63,7 +63,7 @@ $gdxin
starchyRoots 4.0
pasture 0.1 / ;
SCALAR fertiliserUnitCost / 1.5 /
SCALAR fertiliserUnitCost / 1.0 /
PARAMETER previousCropTotalAreas(location);
previousCropTotalAreas(location) = sum(crop_less_pasture, previousArea(crop_less_pasture, location));
......@@ -169,6 +169,8 @@ $gdxin
scalar count / 1 /;
scalar newPasture / 0 /;
scalar newCropland / 0 /;
scalar cropAdjSingle / 0 /;
scalar pastureAdjSingle / 0 /;
parameter temp(location);
......@@ -191,11 +193,15 @@ $gdxin
newPasture = sum(location, area.l("pasture", location));
newCropland = sum((location, crop_less_pasture), area.l(crop_less_pasture, location));
cropAdj(crop_less_pasture) = cropAdj(crop_less_pasture) * newCropland / baseCropland;
cropAdj("pasture") = cropAdj("pasture") * newPasture / basePasture;
cropAdjSingle = newCropland / baseCropland;
cropAdjSingle = min(max(cropAdjSingle, 0.5), 2);
cropAdj(crop_less_pasture) = cropAdj(crop_less_pasture) * cropAdjSingle;
pastureAdjSingle = newPasture / basePasture;
pastureAdjSingle = min(max(pastureAdjSingle, 0.5), 2);
cropAdj("pasture") = cropAdj("pasture") * pastureAdjSingle;
cropAdj(crop) = max(cropAdj(crop), 0.2);
cropAdj(crop) = min(cropAdj(crop), 5);
cropAdj(crop) = min(max(cropAdj(crop), 0.2), 5);
display area.l, count, basePasture, baseCropland, newPasture, newCropland, cropAdj;
count = count+1 ;
......
This diff is collapsed.
......@@ -94,9 +94,13 @@ public class ModelConfig {
public static final String COUNTRY_CODES_FILE = DATA_DIR + File.separator + "country_codes3.csv";
public static final String COUNTRY_DATA_FILE = DATA_DIR + File.separator + "country_data.csv";
public static final String COMMODITY_DATA_FILE = DATA_DIR + File.separator + "con_prod_c_and_m.csv";
public static final String BIOENERGY_DEMAND_FILE = DATA_DIR + File.separator + "bio_demand.csv";
// yield data
public static final String YIELD_DIR = getProperty("YIELD_DIR");
public static final String ANPP_FILENAME = getProperty("ANPP_FILENAME", "anpp_plum.out");
public static final String YIELD_FILENAME = getProperty("YIELD_FILENAME", "yield_plum.out");
// Spatial (gridded) data
public static final double CELL_SIZE_X = getDoubleProperty("CELL_SIZE_X", 3.0);
......
......@@ -18,6 +18,7 @@ import ac.ed.lurg.country.gams.GamsRasterOutput;
import ac.ed.lurg.demand.DemandManager;
import ac.ed.lurg.landuse.AreasItem;
import ac.ed.lurg.landuse.CropUsageData;
import ac.ed.lurg.landuse.CropUsageReader;
import ac.ed.lurg.landuse.IntensitiesItem;
import ac.ed.lurg.landuse.IrrigationCostItem;
import ac.ed.lurg.landuse.IrrigiationCostReader;
......@@ -241,7 +242,8 @@ public class ModelMain {
RasterSet<LandCoverItem> initLC = getInitialLandCover();
RasterSet<IrrigationCostItem> allIrrigationCosts = getIrrigationCosts();
Map<Country, Map<CropType, CropUsageData>> cropUsageDataMap = CropUsageData.readCommodityData();
Map<Country, Map<CropType, CropUsageData>> cropUsageDataMap = new CropUsageReader().getCommodityData();
HashSet<String> countryExclusionList = new HashSet<String>(Arrays.asList("Bangladesh", "Portugal", "Haiti")); //"French Polynesia", "Cabo Verde", "Samoa", "Saint Vincent and the Grenadines"));
......@@ -251,7 +253,7 @@ public class ModelMain {
// DEBUG code
if (!(country.getCountryName().equals("United States of America") || country.getCountryName().equals("Russian Federationxx") || country.getCountryName().equals("Indonesiaxx")) ) { //|| country.getCountryName().equals("China")
if (!(country.getCountryName().equals("United States of America") || country.getCountryName().equals("Russian Federationxx") || country.getCountryName().equals("Brazilxx")) ) { //|| country.getCountryName().equals("China")
continue;
}
......
......@@ -3,7 +3,6 @@ package ac.ed.lurg.country;
import java.util.HashMap;
import java.util.Map;
import ac.ed.lurg.ModelConfig;
import ac.ed.lurg.Timestep;
import ac.ed.lurg.country.gams.GamsCountryInput;
import ac.ed.lurg.country.gams.GamsRasterInput;
......@@ -41,7 +40,6 @@ public class CountryAgent {
this.irrigationCostRaster = irrigationCostRaster;
GamsRasterOutput initialData = new GamsRasterOutput(cropAreaRaster, cropUsageData);
resultsTimeseries.put(new Timestep(0), initialData);
}
......
......@@ -245,7 +245,7 @@ public class GamsLocationOptimiser {
prod = getParmValue(parmProd, itemName);
prodCost = getParmValue(parmProdCost, itemName);
cropUsageData.put(cropType, new CropUsageData(feedAmount, netImport, prod, prodCost, Double.NaN));
cropUsageData.put(cropType, new CropUsageData(feedAmount, netImport, prod, prodCost));
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));
}
......@@ -270,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, 0));
cropUsageData.put(CropType.MEAT, new CropUsageData(0.0, netImport, prod, prodCost));
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));
......
package ac.ed.lurg.demand;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import ac.ed.lurg.ModelConfig;
import ac.ed.lurg.country.Country;
import ac.ed.lurg.country.CountryManager;
import ac.ed.lurg.types.CommodityType;
import ac.ed.lurg.utils.LazyHashMap;
import ac.ed.lurg.utils.LogWriter;
public class BioenergyDemand {
private static final int COUNTRY_COL = 0;
private static final int COMMODITY_COL = 2;
private static final int OTHER_COL = 3;
@SuppressWarnings("serial")
public Map<Country, Map<CommodityType, Double>> getBioenergyData() {
LazyHashMap<Country, Map<CommodityType, Double>> bioenergyMap = new LazyHashMap<Country, Map<CommodityType, Double>>() {
protected Map<CommodityType, Double> createValue() { return new HashMap<CommodityType, Double>(); }
};
String filename = ModelConfig.BIOENERGY_DEMAND_FILE;
try {
BufferedReader fitReader = new BufferedReader(new FileReader(filename));
String line, countryName, commodityName;
double other;
fitReader.readLine(); // read header
while ((line=fitReader.readLine()) != null) {
String[] tokens = line.split(",");
if (tokens.length < 4)
LogWriter.printlnError("Too few columns in " + filename + ", " + line);
countryName = tokens[COUNTRY_COL];
commodityName = tokens[COMMODITY_COL];
other = Double.parseDouble(tokens[OTHER_COL]);
Country country = CountryManager.getForName(countryName);
CommodityType crop = CommodityType.getForFaoName(commodityName);
Map<CommodityType, Double> countryData = bioenergyMap.lazyGet(country);
countryData.put(crop, other);
}
fitReader.close();
} catch (IOException e) {
LogWriter.printlnError("Failed in reading commodity demand fits");
e.printStackTrace();
}
LogWriter.println("Processed " + filename + ", create " + bioenergyMap.size() + " country commodity maps values");
return bioenergyMap;
}
}
......@@ -14,6 +14,7 @@ public class DemandManager {
private DemandCurveManager demandCurveManager;
private SspManager sspManager;
private BaseConsumpManager baseConsumpManager;
private Map<Country, Map<CommodityType, Double>> bioenergyBaseDemand;
private ModelFitType fitType; // these could be mutable
private String ssp_scenario;
......@@ -24,6 +25,7 @@ public class DemandManager {
demandCurveManager = new DemandCurveManager();
sspManager = new SspManager();
baseConsumpManager = new BaseConsumpManager();
bioenergyBaseDemand = new BioenergyDemand().getBioenergyData();
}
public Map<CommodityType, Double> getDemand(Country country, int year) {
......@@ -43,11 +45,22 @@ public class DemandManager {
double cpc = dc.getConsumptionPc(baseSspData.getGdpPc(), baseConsumpManager.get(country, dc.getCommodityType()), sd.getGdpPc());
double d = cpc * sd.getPopulation();
demandMap.put(dc.getCommodityType(), d);
double bioenergy = getBioenergyDemand(country, year, dc.getCommodityType());
// LogWriter.println(String.format("Country %s comm %s: %f", country, dc.getCommodityType(), bioenergy));
demandMap.put(dc.getCommodityType(), d + bioenergy);
}
return demandMap;
}
private double getBioenergyDemand(Country country, int year, CommodityType commodity) {
// could adjust for year somehow, but not doing this yet
if (bioenergyBaseDemand != null && bioenergyBaseDemand.containsKey(country)) {
Double d = bioenergyBaseDemand.get(country).get(commodity);
return d == null ? 0 : d.doubleValue();
}
return 0.0;
}
public double getPopulation (Country country, int year) {
SspData sd = sspManager.get(ssp_scenario, year, country);
if (sd == null) {
......
package ac.ed.lurg.landuse;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import ac.ed.lurg.ModelConfig;
import ac.ed.lurg.country.Country;
import ac.ed.lurg.country.CountryManager;
import ac.ed.lurg.types.CropType;
import ac.ed.lurg.utils.LogWriter;
public class CropUsageData {
private static final int COUNTRY_COL = 0;
private static final int COMMODITY_COL = 2;
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;
private double bioenergyAmount;
public CropUsageData(double feedAmount, double netImports, double prod, double prodCost, double bioenergyAmount) {
public CropUsageData(double feedAmount, double netImports, double prod, double prodCost) {
super();
this.feedAmount = feedAmount;
this.netImports = netImports;
this.prod = prod;
this.prodCost = prodCost;
this.bioenergyAmount = bioenergyAmount;
}
public double getFeedAmount() {
......@@ -50,52 +30,4 @@ 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>>();
String filename = ModelConfig.COMMODITY_DATA_FILE;
try {
BufferedReader fitReader = new BufferedReader(new FileReader(filename));
String line, countryName, commodityName;
double feedAmount, netImports, prod, other;
fitReader.readLine(); // read header
while ((line=fitReader.readLine()) != null) {
String[] tokens = line.split(",");
if (tokens.length < 6)
LogWriter.printlnError("Too few columns in " + filename + ", " + line);
countryName = tokens[COUNTRY_COL];
commodityName = tokens[COMMODITY_COL];
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, other);
Map<CropType, CropUsageData> countryData = commodityMap.get(country);
if (countryData == null) {
countryData = new HashMap<CropType, CropUsageData>();
commodityMap.put(country, countryData);
}
countryData.put(CropType.getForFaoName(commodityName), data);
}
fitReader.close();
} catch (IOException e) {
LogWriter.printlnError("Failed in reading commodity demand fits");
e.printStackTrace();
}
LogWriter.println("Processed " + filename + ", create " + commodityMap.size() + " country commodity maps values");
return commodityMap;
}
}
package ac.ed.lurg.landuse;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import ac.ed.lurg.ModelConfig;
import ac.ed.lurg.country.Country;
import ac.ed.lurg.country.CountryManager;
import ac.ed.lurg.types.CropType;
import ac.ed.lurg.utils.LazyHashMap;
import ac.ed.lurg.utils.LogWriter;
public class CropUsageReader {
private static final int COUNTRY_COL = 0;
private static final int COMMODITY_COL = 2;
private static final int FEED_COL = 4;
private static final int NET_IMPORT_COL = 5;
private static final int PROD_COL = 6;
@SuppressWarnings("serial")
public Map<Country, Map<CropType, CropUsageData>> getCommodityData() {
LazyHashMap<Country, Map<CropType, CropUsageData>> commodityMap = new LazyHashMap<Country, Map<CropType, CropUsageData>>() {
protected Map<CropType, CropUsageData> createValue() { return new HashMap<CropType, CropUsageData>(); }
};
String filename = ModelConfig.COMMODITY_DATA_FILE;
try {
BufferedReader fitReader = new BufferedReader(new FileReader(filename));
String line, countryName, commodityName;
double feedAmount, netImports, prod;
fitReader.readLine(); // read header
while ((line=fitReader.readLine()) != null) {
String[] tokens = line.split(",");
if (tokens.length < 6)
LogWriter.printlnError("Too few columns in " + filename + ", " + line);
countryName = tokens[COUNTRY_COL];
commodityName = tokens[COMMODITY_COL];
feedAmount = Double.parseDouble(tokens[FEED_COL]);
netImports = Double.parseDouble(tokens[NET_IMPORT_COL]);
prod = Double.parseDouble(tokens[PROD_COL]);
Country country = CountryManager.getForName(countryName);
CropType crop = CropType.getForFaoName(commodityName);
CropUsageData data = new CropUsageData(feedAmount, netImports, prod, Double.NaN);
Map<CropType, CropUsageData> countryData = commodityMap.lazyGet(country);
countryData.put(crop, data);
}
fitReader.close();
} catch (IOException e) {
LogWriter.printlnError("Failed in reading commodity demand fits");
e.printStackTrace();
}
LogWriter.println("Processed " + filename + ", create " + commodityMap.size() + " country commodity maps values");
return commodityMap;
}
}
......@@ -37,10 +37,10 @@ public class LPJYieldResponseMapReader extends AbstractTabularRasterReader<Yield
YieldRaster yieldRaster = new YieldRaster(rasterProj);
dataset = yieldRaster;
String nppFilename = rootDir + File.separator + "anpp.out";
String nppFilename = rootDir + File.separator + ModelConfig.ANPP_FILENAME;
getRasterDataFromFile(nppFilename);
String yieldFilename = rootDir + File.separator + "yield.out";
String yieldFilename = rootDir + File.separator + ModelConfig.YIELD_FILENAME;
getRasterDataFromFile(yieldFilename);
return yieldRaster;
......
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