Skip to content
Snippets Groups Projects
Commit 50906f96 authored by Bart Arendarczyk's avatar Bart Arendarczyk
Browse files

Added carbon demand from external file.

parent bf4b2c82
No related branches found
No related tags found
No related merge requests found
......@@ -424,8 +424,10 @@ public class ModelConfig {
public static final String TARGET_DIET_FILE = getProperty("TARGET_DIET_FILE", DATA_DIR + File.separator + "TargetDiet.txt");
// Forestry parameters
public static final String CONVERSION_COST_FILE = DATA_DIR + File.separator + "conversion_costs.csv";
public static final String CONVERSION_COST_FILE = DATA_DIR + File.separator + "conversion_costs.csv"; // cost of converting from one land cover to another, $1000/ha
public static final String SERIALIZED_CARBON_MARKET_FILE = CALIB_DIR + File.separator + "CarbonMarket.ser";
public static final String CARBON_DEMAND_FILENAME = getProperty("CARBON_DEMAND_FILENAME", "carbon_demand.csv");
public static final String CARBON_DEMAND_FILE = getProperty("CARBON_DEMAND_FILE", DATA_DIR + File.separator + CARBON_DEMAND_FILENAME);
public static final double CARBON_PRICE = getDoubleProperty("CARBON_PRICE", 0.02); // $1000/tC-eq
public static final double WOOD_PRICE = getDoubleProperty("WOOD_PRICE", 0.05); // $1000/tC-eq
public static final int FOREST_LOCKIN_PERIOD = getIntProperty("FOREST_LOCKIN_PERIOD", 30); // cannot convert forest after planting for this many years
......
......@@ -143,13 +143,12 @@ public class ModelMain {
double previousGen2EcDDemand = (timestep.isInitialTimestep() || ModelConfig.IS_CALIBRATION_RUN ) ? 0: demandManager.getSecondGenBioenergyDemand(timestep.getPreviousTimestep());
double gen2EcDDemand = demandManager.getSecondGenBioenergyDemand(ModelConfig.IS_CALIBRATION_RUN ? new Timestep(1) : timestep);
double gen2Increase = (gen2EcDDemand>previousGen2EcDDemand) ? gen2EcDDemand - previousGen2EcDDemand : 0.0;
double previousCarbonDemand = (timestep.isInitialTimestep() || ModelConfig.IS_CALIBRATION_RUN ) ? 0: 0.0;
double carbonDemand = 1000; //TODO read from file
double carbonDemandIncrease = (carbonDemand > previousCarbonDemand) ? carbonDemand - previousCarbonDemand: 0;
double previousCarbonDemand = (timestep.isInitialTimestep() || ModelConfig.IS_CALIBRATION_RUN ) ? 0: demandManager.getCarbonDemand(timestep.getPreviousTimestep());
double carbonDemand = demandManager.getCarbonDemand(ModelConfig.IS_CALIBRATION_RUN ? new Timestep(1) : timestep);
double carbonDemandIncrease = (carbonDemand > previousCarbonDemand) ? carbonDemand - previousCarbonDemand: 0;
CarbonFluxRasterSet currentCarbonFluxData = getCarbonFluxData(timestep);
WoodYieldRasterSet currentWoodYieldData = getWoodYieldData(timestep);
DoubleMap<LandCoverType, LandCoverType, Double> conversionCosts = new ConversionCostReader().read();
......
......@@ -219,7 +219,7 @@ public class CountryAgent extends AbstractCountryAgent {
importConstraints.put(crop, new TradeConstraint(baseTrade - changeDown, baseTrade + changeUp));
}
// Carbon import/export constraints
// Carbon import/export constraints TODO not used
double baseTrade = getNetCarbonFlux();
double countryArea = LandUseItem.getTotalLandArea(previousGamsRasterOutput.getLandUses().values());
double changeUp = 0.0;
......
......@@ -137,7 +137,7 @@ public class CountryAgentManager {
}
if (craftyCountryAgents.size() > 0) {
craftyManager.updateWithCraftyData(craftyCountryAgents, timestep, internationalMarket.getWorldPrices()); // this will wait for the marker file from CRAFTY
craftyManager.updateWithCraftyData(craftyCountryAgents, timestep, internationalMarket.getWorldPrices(), internationalMarket.getCarbonPrice()); // this will wait for the marker file from CRAFTY
}
}
......
......@@ -28,8 +28,8 @@ public class CraftyCountryAgent extends AbstractCountryAgent {
return cropUsageData;
}
public void updateProduction(Map<CropType, Double> cropProduction, Map<CropType, GlobalPrice> worldPrices) {
calculateCountryPricesAndDemand(worldPrices, false);
public void updateProduction(Map<CropType, Double> cropProduction, Map<CropType, GlobalPrice> worldPrices, GlobalPrice carbonPrice) {
calculateCountryPricesAndDemand(worldPrices, carbonPrice, false);
cropUsageData = new HashMap<CropType, CropUsageData>();
for (Entry<CropType, Double> entry : cropProduction.entrySet()) {
......@@ -50,4 +50,8 @@ public class CraftyCountryAgent extends AbstractCountryAgent {
}
return commPricePlum;
}
public double getNetCarbonFlux() {
return 0;
}
}
\ No newline at end of file
......@@ -32,7 +32,7 @@ public class CraftyProdManager {
return craftyCountries;
}
public void updateWithCraftyData(Collection<CraftyCountryAgent> craftyCountryAgents, Timestep timestep, Map<CropType, GlobalPrice> worldPrices) {
public void updateWithCraftyData(Collection<CraftyCountryAgent> craftyCountryAgents, Timestep timestep, Map<CropType, GlobalPrice> worldPrices, GlobalPrice carbonPrice) {
String rootDir = ModelConfig.CRAFTY_PRODUCTION_DIR + File.separator + timestep.getYear();
long startTime = System.currentTimeMillis();
......@@ -66,7 +66,7 @@ public class CraftyProdManager {
if (cropProduction.size() < CropType.getImportedTypes().size()) { // Don't need setaside or pasture, which aren't imported either
LogWriter.printlnError("Not all crops present in Crafty production for country: " + cca.getCountry() + " only " + cropProduction.size());
}
cca.updateProduction(cropProduction, worldPrices);
cca.updateProduction(cropProduction, worldPrices, carbonPrice);
}
catch (Exception e) {
LogWriter.println("Problem getting Crafty data for: " + cca.getCountry());
......
......@@ -19,12 +19,14 @@ public abstract class AbstractDemandManager {
protected CalorieManager calorieManager;
protected BioenergyDemandManager bioenergyDemandManager;
protected CerealFractionsManager cerealFractionsManager;
protected CarbonDemandManager carbonDemandManager;
public AbstractDemandManager(CompositeCountryManager compositeCountryManager, CalorieManager calorieManager) {
this.compositeCountryManager = compositeCountryManager;
this.calorieManager = calorieManager;
bioenergyDemandManager = new BioenergyDemandManager();
cerealFractionsManager = new CerealFractionsManager(compositeCountryManager);
carbonDemandManager = new CarbonDemandManager();
}
public Map<CommodityType, Double> getDemand(CompositeCountry cc, int year, Map<CommodityType, Double> prices, boolean outputGamsDemand) {
......@@ -130,5 +132,9 @@ public abstract class AbstractDemandManager {
// LogWriter.println("updated map " + updatedFoodDemandMap);
return updatedFoodDemandMap;
}
public double getCarbonDemand(Timestep timestep) {
return carbonDemandManager.getGlobalCarbonDemand(timestep.getYear());
}
}
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.utils.Interpolator;
import ac.ed.lurg.utils.LogWriter;
public class CarbonDemandManager {
private Map<Integer, Double> globalCarbonDemand; // global demand for carbon sequestration
private static final int YEAR_COL = 0;
private static final int DEMAND_COL = 1;
public CarbonDemandManager() {
readCarbonDemandData();
}
public void readCarbonDemandData() {
Map<Integer, Double> data = new HashMap<Integer, Double>();
String filename = ModelConfig.CARBON_DEMAND_FILE;
try {
BufferedReader reader = new BufferedReader(new FileReader(filename));
String line;
Integer year;
Double demand;
reader.readLine(); // read header
while ((line=reader.readLine()) != null) {
String[] tokens = line.split(",");
if (tokens.length < 2)
LogWriter.printlnError("Too few columns in " + filename + ", " + line);
year = Integer.valueOf(tokens[YEAR_COL]);
demand = Double.valueOf(tokens[DEMAND_COL]);
data.put(year, demand);
}
reader.close();
} catch (IOException e) {
LogWriter.printlnError("Failed in reading carbon demand data");
LogWriter.print(e);
}
globalCarbonDemand = data;
LogWriter.println("Processed " + filename);
}
public double getGlobalCarbonDemand(int year) {
int downYear = (year/5) * 5;
int upYear = downYear + 5;
Double lowerD = globalCarbonDemand.get(downYear);
Double upperD = globalCarbonDemand.get(upYear);
double factor = ((double)(year - downYear)) / (upYear - downYear);
Double d = Interpolator.interpolate(lowerD, upperD, factor);
return d;
}
}
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