From 2ead7aa6793d24fa925d3d6d6afe65f29549c526 Mon Sep 17 00:00:00 2001
From: Peter Alexander <peter@blackhillock.co.uk>
Date: Fri, 18 Nov 2016 13:01:28 +0000
Subject: [PATCH] Add technology change to yields from LPJ, and some other
 tweaks

---
 src/ac/ed/lurg/ModelConfig.java               |  5 ++-
 .../lurg/country/gams/GamsLocationTest.java   |  1 -
 src/ac/ed/lurg/landuse/LandUseItem.java       |  2 +-
 src/ac/ed/lurg/types/CommodityType.java       |  1 -
 .../lurg/yield/LPJYieldResponseMapReader.java | 15 +++++++--
 .../ed/lurg/yield/YieldResponseMapReader.java | 33 -------------------
 6 files changed, 17 insertions(+), 40 deletions(-)
 delete mode 100644 src/ac/ed/lurg/yield/YieldResponseMapReader.java

diff --git a/src/ac/ed/lurg/ModelConfig.java b/src/ac/ed/lurg/ModelConfig.java
index f7fae185..7acc7e54 100644
--- a/src/ac/ed/lurg/ModelConfig.java
+++ b/src/ac/ed/lurg/ModelConfig.java
@@ -157,6 +157,9 @@ public class ModelConfig {
 	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.15);  
 
+	public static final double TECHNOLOGY_CHANGE_ANNUAL_RATE = getDoubleProperty("TECHNOLOGY_CHANGE_ANNUAL_RATE", 0.0);
+	public static final int TECHNOLOGY_CHANGE_START_STEP = getIntProperty("TECHNOLOGY_CHANGE_START_STEP", 0);
+	
 	public static final double MARKET_LAMBA = getDoubleProperty("MARKET_LAMBA", 0.5); // controls international market price adjustment rate
 	public static final double POPULATION_AGGREG_LIMIT = getDoubleProperty("POPULATION_AGGREG_LIMIT", 40.0);  // in millions, smaller countries are aggregated on a regional basis
 	
@@ -171,7 +174,7 @@ public class ModelConfig {
 	
 	public static final double DOMESTIC_PRICE_MARKUP = getDoubleProperty("DOMESTIC_PRICE_MARKUP", 1.0);
 	public static final double TRANSPORT_LOSSES = getDoubleProperty("TRANSPORT_LOSSES", 0.1);  // in international trade
-	public static final double TRADE_BARRIER_FACTOR_DEFAULT = getDoubleProperty("TRADE_BARRIER_FACTOR", 0.2);  // price factor in international trade, transport cost and real trade barriers
+	public static final double TRADE_BARRIER_FACTOR_DEFAULT = getDoubleProperty("TRADE_BARRIER_FACTOR_DEFAULT", 0.2);  // price factor in international trade, transport cost and real trade barriers
 	public static final boolean ACTIVE_TRADE_BARRIERS = getBooleanProperty("ACTIVE_TRADE_BARRIERS", false);  // if set to true read in barrier information from file, otherwise use default as above
 
 	public static final boolean PROTECTED_AREAS_ENABLED = getBooleanProperty("PROTECTED_AREAS_ENABLED", true);
diff --git a/src/ac/ed/lurg/country/gams/GamsLocationTest.java b/src/ac/ed/lurg/country/gams/GamsLocationTest.java
index f66d29ce..eb35c147 100644
--- a/src/ac/ed/lurg/country/gams/GamsLocationTest.java
+++ b/src/ac/ed/lurg/country/gams/GamsLocationTest.java
@@ -33,7 +33,6 @@ public class GamsLocationTest {
 	Map<CommodityType, Double> getProjectedDemand() {
 		Map<CommodityType, Double> dummyMap = new HashMap<CommodityType, Double>();
 		dummyMap.put(CommodityType.CEREALS, 300.0);
-		dummyMap.put(CommodityType.SOYBEAN, 50.0);
 		dummyMap.put(CommodityType.OILCROPS, 50.0);
 		dummyMap.put(CommodityType.PULSES, 60.0);
 		dummyMap.put(CommodityType.STARCHY_ROOTS, 150.0);
diff --git a/src/ac/ed/lurg/landuse/LandUseItem.java b/src/ac/ed/lurg/landuse/LandUseItem.java
index 9b16b040..c710d1bd 100644
--- a/src/ac/ed/lurg/landuse/LandUseItem.java
+++ b/src/ac/ed/lurg/landuse/LandUseItem.java
@@ -57,7 +57,7 @@ public class LandUseItem implements InterpolatingRasterItem<LandUseItem> {
 		
 		for (CropType c : crops) {
 			fertTotal += getFertiliserAmount(c);
-			areaTotal = getCropArea(c);
+			areaTotal += getCropArea(c);
 		}
 		
 		return areaTotal > 0 ? fertTotal / areaTotal : 0;
diff --git a/src/ac/ed/lurg/types/CommodityType.java b/src/ac/ed/lurg/types/CommodityType.java
index ae9090a9..cf7d27a0 100644
--- a/src/ac/ed/lurg/types/CommodityType.java
+++ b/src/ac/ed/lurg/types/CommodityType.java
@@ -9,7 +9,6 @@ public enum CommodityType {
 	CEREALS("Cereals - Excluding Beer + (Total)", "cereals"),
 	OILCROPS("Oilcrops + (Total)", "oilcrops"),
 	PULSES("Pulses + (Total)", "pulses"),
-	SOYBEAN("Soyabeans", "soybean"),
 	STARCHY_ROOTS("Starchy Roots + (Total)", "starchyRoots"),
 	MEAT("meatmilkeggs", "meat");
 
diff --git a/src/ac/ed/lurg/yield/LPJYieldResponseMapReader.java b/src/ac/ed/lurg/yield/LPJYieldResponseMapReader.java
index 63f14050..c2f003ba 100644
--- a/src/ac/ed/lurg/yield/LPJYieldResponseMapReader.java
+++ b/src/ac/ed/lurg/yield/LPJYieldResponseMapReader.java
@@ -18,7 +18,8 @@ import ac.sac.raster.RasterKey;
 public class LPJYieldResponseMapReader {	
 
 	private RasterHeaderDetails rasterProj;
-	
+	private double techYieldAdj;
+
 	public LPJYieldResponseMapReader(RasterHeaderDetails rasterProj) {
 		this.rasterProj = rasterProj; 
 	}
@@ -36,6 +37,11 @@ public class LPJYieldResponseMapReader {
 		}
 		LogWriter.println("Found marker file in " + (System.currentTimeMillis() - startTime) + " ms");
 
+		// arithmetic adjustment of yield for tech change  
+		int yearsOfTech = (timestep.getTimestep() - ModelConfig.TECHNOLOGY_CHANGE_START_STEP) * ModelConfig.TIMESTEP_SIZE;
+		techYieldAdj = yearsOfTech > 0 ?  (1.0 +  yearsOfTech * ModelConfig.TECHNOLOGY_CHANGE_ANNUAL_RATE) : 1.0 ;
+		LogWriter.println("Yield adjustment for technology for " + timestep + " is " + techYieldAdj);
+		
 		YieldRaster yieldRaster = new YieldRaster(rasterProj);
 		readNppFile(yieldRaster, rootDir+File.separator+ModelConfig.ANPP_FILENAME);
 		readYieldFile(yieldRaster, rootDir+File.separator+ModelConfig.YIELD_FILENAME);
@@ -103,7 +109,10 @@ public class LPJYieldResponseMapReader {
 		yieldReader.getRasterDataFromFile(fileToRead);
 	}
 	
-	private void setCalibratedYield(YieldResponsesItem item, YieldType yieldType, CropType crop, double yield) {
-		item.setYield(yieldType, crop, yield * crop.getCalibrationFactor());  // applying the calibration factor can't go in YieldResponsesItem.setYield as this is also called from elsewhere
+	private void setCalibratedYield(YieldResponsesItem item, YieldType yieldType, CropType crop, double yieldFromFile) {
+		double yieldCalib = yieldFromFile * crop.getCalibrationFactor();
+		double yieldAdj = yieldCalib * techYieldAdj;
+		
+		item.setYield(yieldType, crop, yieldAdj);  // applying the calibration factor can't go in YieldResponsesItem.setYield as this is also called from elsewhere
 	}
 }
\ No newline at end of file
diff --git a/src/ac/ed/lurg/yield/YieldResponseMapReader.java b/src/ac/ed/lurg/yield/YieldResponseMapReader.java
deleted file mode 100644
index 94177331..00000000
--- a/src/ac/ed/lurg/yield/YieldResponseMapReader.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package ac.ed.lurg.yield;
-
-import ac.ed.lurg.types.CropType;
-import ac.ed.lurg.types.YieldType;
-import ac.ed.lurg.utils.LogWriter;
-import ac.sac.raster.AbstractRasterReader;
-import ac.sac.raster.RasterHeaderDetails;
-
-public class YieldResponseMapReader extends AbstractRasterReader<YieldResponsesItem> {	
-
-	private YieldType yieldType;
-	private CropType cropType;
-	
-	public YieldResponseMapReader (YieldRaster dataset, YieldType yieldType, CropType cropType) {
-		super(dataset);
-		this.yieldType = yieldType;
-		this.cropType = cropType;
-	}
-
-	protected void createDataSet(RasterHeaderDetails header) {
-		if (DEBUG) LogWriter.println("Creating RasterDataset col:"+header.getNcolumns() + ", rows:" + header.getNrows());
-
-		if (dataset == null) {
-			dataset = new YieldRaster(header);
-		}
-	}
-
-	@Override
-	public void setData(YieldResponsesItem item, String token) {
-		double d = Double.parseDouble(token);
-		item.setYield(yieldType, cropType, d);
-	}
-}
\ No newline at end of file
-- 
GitLab