diff --git a/GAMS/IntExtOpt.gms b/GAMS/IntExtOpt.gms index 8fab4b934c862eb0ca9a68058fc4fff259ace797..2b08fc4b4c3d04b12b76469c2367670dcf3e95b9 100644 --- a/GAMS/IntExtOpt.gms +++ b/GAMS/IntExtOpt.gms @@ -113,9 +113,9 @@ $gdxin PASTURE_DECREASE_CONV_CALC(location) ENERGY_EQ total energy objective function; - UNIT_ENERGY_EQ(crop, location) .. unitEnergy(crop, location) =E= ( baseCost(crop) * power(cropAdj(crop), 1) + - (fertiliserUnitCost * fertI(crop, location)) + - (irrigCost(location) * irrigI(crop, location)) ) ; + UNIT_ENERGY_EQ(crop, location) .. unitEnergy(crop, location) =E= ( baseCost(crop) * cropAdj(crop) + + fertiliserUnitCost * fertI(crop, location) + + irrigCost(location) * irrigI(crop, location) ) ; YIELD_EQ(crop, location) .. yield(crop, location) =E= ( yieldNone(crop, location) + diff --git a/src/ac/ed/lurg/ModelConfig.java b/src/ac/ed/lurg/ModelConfig.java index f0b75b426840edd619856041307721a44068475a..2f5e043ea678b05e7dd8b15c6f1b8ee26194119c 100644 --- a/src/ac/ed/lurg/ModelConfig.java +++ b/src/ac/ed/lurg/ModelConfig.java @@ -96,7 +96,7 @@ public class ModelConfig { public static final String COMMODITY_DATA_FILE = DATA_DIR + File.separator + "con_prod_c_and_m.csv"; // yield data - public static final String YIELD_DIR = "/Users/peteralexander/Documents/LURG/LPJ/tom-April2015"; + public static final String YIELD_DIR = "/Users/peteralexander/Documents/LURG/LPJ/tom-July2015"; // Spatial (gridded) data public static final String SPATIAL_DATA_DIR = DATA_DIR; // + File.separator + "tinyTest"; diff --git a/src/ac/ed/lurg/ModelMain.java b/src/ac/ed/lurg/ModelMain.java index 53fbd1f63fd670466089f97e4e3f1e01a953e9ad..90fbf0a41302507480d5308d558f1e2291486f9b 100644 --- a/src/ac/ed/lurg/ModelMain.java +++ b/src/ac/ed/lurg/ModelMain.java @@ -24,7 +24,6 @@ import ac.ed.lurg.landuse.IrrigationCostItem; import ac.ed.lurg.landuse.IrrigiationCostReader; import ac.ed.lurg.landuse.LandCoverItem; import ac.ed.lurg.landuse.LandCoverReader; -import ac.ed.lurg.output.RasterOutputer; import ac.ed.lurg.types.CropToDoubleMap; import ac.ed.lurg.types.CropType; import ac.ed.lurg.types.FertiliserRate; @@ -36,6 +35,7 @@ import ac.ed.lurg.yield.YieldRaster; import ac.sac.raster.IntegerRasterItem; import ac.sac.raster.RasterHeaderDetails; import ac.sac.raster.RasterKey; +import ac.sac.raster.RasterOutputer; import ac.sac.raster.RasterSet; public class ModelMain { @@ -241,7 +241,7 @@ public class ModelMain { // DEBUG code - if (!(country.getCountryName().equals("United States of Americaxx") || country.getCountryName().equals("Russian Federation"))) { //|| country.getCountryName().equals("China") + if (!(country.getCountryName().equals("United States of America") || country.getCountryName().equals("Russian Federationxx"))) { //|| country.getCountryName().equals("China") continue; } diff --git a/src/ac/ed/lurg/output/LpjgOutputer.java b/src/ac/ed/lurg/output/LpjgOutputer.java new file mode 100644 index 0000000000000000000000000000000000000000..5a3c890832a876249582b2053d4584bb39536fc8 --- /dev/null +++ b/src/ac/ed/lurg/output/LpjgOutputer.java @@ -0,0 +1,69 @@ +package ac.ed.lurg.output; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Map.Entry; + +import ac.ed.lurg.ModelConfig; +import ac.ed.lurg.landuse.AreasItem; +import ac.ed.lurg.landuse.IntensitiesItem; +import ac.sac.raster.RasterKey; +import ac.sac.raster.RasterSet; + +public class LpjgOutputer { + + private RasterSet<IntensitiesItem> intensityRaster; + private RasterSet<AreasItem> cropAreaRaster; + private int timestep; + + public LpjgOutputer(int timestep, RasterSet<IntensitiesItem> intensityRaster, RasterSet<AreasItem> cropAreaRaster) { + this.intensityRaster = intensityRaster; + this.cropAreaRaster = cropAreaRaster; + } + + + public void writeOutput(boolean writeImage) { + BufferedWriter fileWriter = null; + + try { + String areaFileName = ModelConfig.OUTPUT_DIR + File.separator + "Areas" + timestep + ".txt"; + fileWriter = new BufferedWriter(new FileWriter(areaFileName,false)); + + writeHeader(fileWriter); + + for (Entry<RasterKey, AreasItem> entry : cropAreaRaster.entrySet()) { + RasterKey location = entry.getKey(); + AreasItem item = entry.getValue(); + + /* Double d = getValue(location); + + if (d == null) + fileWriter.write(nullDataString + " "); + else + fileWriter.write(d + " ");*/ + + fileWriter.newLine(); + } + } + catch (IOException e) { + e.printStackTrace(); + } + finally { + if (fileWriter != null) { + try { + fileWriter.close(); + } + catch (IOException e) { + e.printStackTrace(); + } + } + } + } + + private void writeHeader(BufferedWriter outputFile) throws IOException { + outputFile.write("h1,h2,... ,hn"); + outputFile.newLine(); + } +} diff --git a/src/ac/ed/lurg/types/FertiliserRate.java b/src/ac/ed/lurg/types/FertiliserRate.java index 704ca4908ebd755854ae91947368e56e69443d16..e1e6ae7b0753eaab8c9bb40bbf8e819909005cde 100644 --- a/src/ac/ed/lurg/types/FertiliserRate.java +++ b/src/ac/ed/lurg/types/FertiliserRate.java @@ -1,10 +1,16 @@ package ac.ed.lurg.types; +import java.io.File; + public enum FertiliserRate { - NO_FERT("yield_1996_2005_minfert_CRU.out"), - MID_FERT("yield_1996_2005_middlefert_CRU.out"), - MAX_FERT("yield_1996_2005_highfert_CRU.out"); + // NO_FERT("yield_1996_2005_minfert_CRU.out"), + // MID_FERT("yield_1996_2005_middlefert_CRU.out"), + // MAX_FERT("yield_1996_2005_highfert_CRU.out"); + NO_FERT("minfert" + File.separator + "yield_1996_2005"), + MID_FERT("middlefert" + File.separator + "yield_1996_2005"), + MAX_FERT("highfert" + File.separator + "yield_1996_2005"); + private String fileName; FertiliserRate(String fileName) { diff --git a/src/ac/ed/lurg/yield/LPJYieldResponseMapReader.java b/src/ac/ed/lurg/yield/LPJYieldResponseMapReader.java index efb48f754314254356875bc36908fe31ab675355..2cde5a8b250f7d859d57c9e14906ffed87407955 100644 --- a/src/ac/ed/lurg/yield/LPJYieldResponseMapReader.java +++ b/src/ac/ed/lurg/yield/LPJYieldResponseMapReader.java @@ -56,27 +56,33 @@ public class LPJYieldResponseMapReader { break; case 2: //YieldRecord values in kg DM / m2, we want t/ha, so 10 times larger - record.teSW = d * 10; + record.c3Pasture = d * 10; break; case 3: - record.teSWirr = d * 10; + record.c4Pasture = d * 10; break; case 4: record.teWW = d * 10; break; case 5: - record.teWWirr = d * 10; + record.teSW = d * 10; break; case 6: record.teCo = d * 10; break; case 7: - record.teCoirr = d * 10; + record.trRi = d * 10; break; case 8: - record.trRi = d * 10; + record.teWWirr = d * 10; break; case 9: + record.teSWirr = d * 10; + break; + case 10: + record.teCoirr = d * 10; + break; + case 11: record.trRiirr = d * 10; break; } @@ -124,19 +130,15 @@ public class LPJYieldResponseMapReader { item.setYield(noIrrigYieldType, CropType.STARCHY_ROOTS, record.teSW * 1.1); item.setYield(maxIrrigYieldType, CropType.STARCHY_ROOTS, record.teSWirr * 1.1); - if (noIrrigYieldType.getFertiliserRate() == FertiliserRate.MAX_FERT) { - item.setYield(noIrrigYieldType, CropType.PASTURE, record.teSW*1.2); - item.setYield(maxIrrigYieldType, CropType.PASTURE, record.teSWirr*1.2); - } - else { - item.setYield(noIrrigYieldType, CropType.PASTURE, record.teSW*0.6); - item.setYield(maxIrrigYieldType, CropType.PASTURE, record.teSWirr*0.7); - } + item.setYield(noIrrigYieldType, CropType.PASTURE, Math.max(record.c3Pasture, record.c4Pasture)); + item.setYield(maxIrrigYieldType, CropType.PASTURE, Math.max(record.c3Pasture, record.c4Pasture)*1.2); } class YieldRecord { double x; double y; + double c3Pasture; + double c4Pasture; double teSW; double teSWirr; double teWW; diff --git a/src/ac/ed/lurg/output/RasterOutputer.java b/src/ac/sac/raster/RasterOutputer.java similarity index 97% rename from src/ac/ed/lurg/output/RasterOutputer.java rename to src/ac/sac/raster/RasterOutputer.java index acc511de85b094fbf6779f4aac06e09b98a293c8..ff4c3b7f06de9b6577ee6218599b2af65ceda2a2 100644 --- a/src/ac/ed/lurg/output/RasterOutputer.java +++ b/src/ac/sac/raster/RasterOutputer.java @@ -1,4 +1,4 @@ -package ac.ed.lurg.output; +package ac.sac.raster; import java.awt.Image; import java.awt.image.BufferedImage; @@ -19,13 +19,10 @@ import java.io.IOException; import javax.imageio.ImageIO; import ac.ed.lurg.ModelConfig; -import ac.sac.raster.RasterItem; -import ac.sac.raster.RasterKey; -import ac.sac.raster.RasterSet; public abstract class RasterOutputer<D extends RasterItem> { protected RasterSet<D> results; - String fileName; + private String fileName; public RasterOutputer(RasterSet<D> results, String fileName) { this.results = results;