diff --git a/src/ac/ed/lurg/ModelConfig.java b/src/ac/ed/lurg/ModelConfig.java index 6764036b3efc2257b34cf768ecc0b9e992d92351..db97a62320d9dc9b0e1d897b5a6c474997cf5e9b 100644 --- a/src/ac/ed/lurg/ModelConfig.java +++ b/src/ac/ed/lurg/ModelConfig.java @@ -119,7 +119,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 TIMESTEP_SIZE = getIntProperty("END_TIMESTEP", 35); + public static final int TIMESTEP_SIZE = getIntProperty("END_TIMESTEP", 40); public static final int BASE_YEAR = getIntProperty("BASE_YEAR", 2010); public static final double MAX_IMPORT_CHANGE = getDoubleProperty("MAX_IMPORT_CHANGE", 0.1); @@ -127,7 +127,7 @@ public class ModelConfig { public static final String SSP_SCENARIO = getProperty("SSP_SCENARIO", "SSP5_v9_130325"); // Output - public static final boolean WRITE_JPEG_IMAGES = getBooleanProperty("WRITE_JPEG_IMAGES", Boolean.TRUE); + public static final boolean WRITE_JPEG_IMAGES = getBooleanProperty("WRITE_JPEG_IMAGES", false); public static final int LPJG_MONITOR_TIMEOUT_SEC = getIntProperty("LPJG_MONITOR_TIMEOUT", 60*60*2); public static final String TOTAL_LAND_COVER_FILE = OUTPUT_DIR + File.separator + "total_lc.txt"; diff --git a/src/ac/ed/lurg/ModelMain.java b/src/ac/ed/lurg/ModelMain.java index ebad31c1720af200514094169c4c37928565dcb3..a6ff012425f7132975b7228fea76a1f18f9c8fc0 100644 --- a/src/ac/ed/lurg/ModelMain.java +++ b/src/ac/ed/lurg/ModelMain.java @@ -1,7 +1,6 @@ package ac.ed.lurg; import java.io.BufferedWriter; -import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; @@ -131,20 +130,23 @@ public class ModelMain { totalWorldInputCost.incrementValue(c, d.getProdCost()); } - /* after first timestep should look at trade balance and adjust appropriately - for (CropType crop : CropType.values()) { - CommodityData cd = result.getCommoditiesData().get(crop); - double netImport = cd.getNetImports(); - - if (netImport > 0) - totalImportCommodities.incrementValue(crop, netImport); - else - totalExportCommodities.incrementValue(crop, -netImport); - } */ } prevWorldInputCost = totalWorldInputCost.divideBy(totalQuantity); + // after first timestep should look at trade balance and adjust appropriately + /* for (CropType crop : CropType.values()) { + CommodityData cd = result.getCommoditiesData().get(crop); + double netImport = cd.getNetImports(); + + if (netImport > 0) + totalImportCommodities.incrementValue(crop, netImport); + else + totalExportCommodities.incrementValue(crop, -netImport); + } */ + + + // output results outputTimestepResults(timestep, globalIntensityRaster, globalCropAreaRaster, globalLocationIdRaster, yieldSurfaces); writeMarketFile(timestep, globalCropAreaRaster); @@ -240,19 +242,19 @@ public class ModelMain { }.writeOutput(ModelConfig.WRITE_JPEG_IMAGES); outputAreas(year, cropAreaRaster, CropType.MAIZE); */ - // outputAreas(timestep.getYear(), cropAreaRaster, CropType.WHEAT); - // outputAreas(timestep.getYear(), cropAreaRaster, CropType.PASTURE); + outputLandCover(timestep.getYear(), cropAreaRaster, LandCoverType.CROPLAND); + outputLandCover(timestep.getYear(), cropAreaRaster, LandCoverType.PASTURE); } - private void outputAreas(int year, RasterSet<AreasItem> cropAreaRaster, final CropType crop) { - new RasterOutputer<AreasItem>(cropAreaRaster, crop.getGamsName() + "Area" + year) { + private void outputLandCover(int year, RasterSet<AreasItem> cropAreaRaster, final LandCoverType lcType) { + new RasterOutputer<AreasItem>(cropAreaRaster, lcType.getName() + "Area" + year) { @Override public Double getValue(RasterKey location) { AreasItem area = results.get(location); if (area == null) return null; - return area.getCropArea(crop); + return area.getLandCoverArea(lcType); } @Override @@ -308,11 +310,11 @@ public class ModelMain { // DEBUG code - if (!(country.getCountryName().equals("United States of Americaxx") || country.getCountryName().equals("Russian Federationxx") || country.getCountryName().equals("China")) ) { //|| country.getCountryName().equals("China") - continue; - } + // if (!(country.getCountryName().equals("United States of Americaxx") || country.getCountryName().equals("Russian Federationxx") || country.getCountryName().equals("China")) ) { //|| 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; } diff --git a/src/ac/ed/lurg/country/Country.java b/src/ac/ed/lurg/country/Country.java index 36cddf6469219d85d7d0fa38466c96216801445b..d44edc77b146c4903aa23ab097e143ad3aacef9a 100644 --- a/src/ac/ed/lurg/country/Country.java +++ b/src/ac/ed/lurg/country/Country.java @@ -6,13 +6,14 @@ public class Country { private String countryName; private String iso3CharCode; private int iso3NumCode; - + private String region; - public Country(String countryName, String iso3CharCode, int iso3NumCode) { + public Country(String countryName, String iso3CharCode, int iso3NumCode, String region) { super(); this.countryName = countryName; this.iso3CharCode = iso3CharCode; this.iso3NumCode = iso3NumCode; + this.region = region; } public String getIso3CharCode() { diff --git a/src/ac/ed/lurg/country/CountryManager.java b/src/ac/ed/lurg/country/CountryManager.java index 7b75d35dd4fda47ecbc437e10c72a8c6e60bf00d..8f182320824d7ad2ae4008ac4fa20d59d5c1c3a2 100644 --- a/src/ac/ed/lurg/country/CountryManager.java +++ b/src/ac/ed/lurg/country/CountryManager.java @@ -12,6 +12,7 @@ import ac.ed.lurg.utils.LogWriter; public class CountryManager { private static final int NAME_COL = 0; private static final int CHAR_CODE_COL = 1; + private static final int REGION_COL = 2; private static final int NUM_CODE_COL = 4; private final Map<String, Country> nameMap = new HashMap<String, Country>(); @@ -30,7 +31,7 @@ public class CountryManager { String filename = ModelConfig.COUNTRY_CODES_FILE; try { BufferedReader fitReader = new BufferedReader(new FileReader(filename)); - String line, name, charCode; + String line, name, charCode, region; int numCode; fitReader.readLine(); // read header @@ -42,9 +43,10 @@ public class CountryManager { name = tokens[NAME_COL]; charCode = tokens[CHAR_CODE_COL]; + region = tokens[REGION_COL]; numCode = Integer.parseInt(tokens[NUM_CODE_COL]); - Country c = new Country(name, charCode, numCode); + Country c = new Country(name, charCode, numCode, region); nameMap.put(name, c); numCodeMap.put(numCode, c); } diff --git a/src/ac/ed/lurg/country/gams/GamsLocationTest.java b/src/ac/ed/lurg/country/gams/GamsLocationTest.java index b94d4e710fb4d7e384b48238bf5aa0ae767c83f2..1cdf9348aeecddd415091213f3fac02c47d72ac5 100644 --- a/src/ac/ed/lurg/country/gams/GamsLocationTest.java +++ b/src/ac/ed/lurg/country/gams/GamsLocationTest.java @@ -22,7 +22,7 @@ public class GamsLocationTest { } private void run() { - GamsCountryInput countryLevelInputs = GamsCountryInput.createInput(new Country("Test", "TES", 123), getProjectedDemand(), getWorldInputEnergy(), getBaseNetImport(), null, null, true); + GamsCountryInput countryLevelInputs = GamsCountryInput.createInput(new Country("Test", "TES", 123, "R1"), getProjectedDemand(), getWorldInputEnergy(), getBaseNetImport(), null, null, true); GamsLocationInput gamsInput = new GamsLocationInput(new Timestep(0), getYields(), getPreviousArea(), getIrrigationCosts(), countryLevelInputs); GamsLocationOptimiser opti = new GamsLocationOptimiser(gamsInput); diff --git a/src/ac/ed/lurg/country/gams/GamsRasterOptimiser.java b/src/ac/ed/lurg/country/gams/GamsRasterOptimiser.java index 86ca1873ee089b826c24841dd5d297fa9e82672d..fe5bafbf641656ca121b482c83cfcfab3493a7a4 100644 --- a/src/ac/ed/lurg/country/gams/GamsRasterOptimiser.java +++ b/src/ac/ed/lurg/country/gams/GamsRasterOptimiser.java @@ -71,7 +71,6 @@ public class GamsRasterOptimiser { return theCopy; } - @SuppressWarnings("unused") private void checkedTotalAreas(RasterSet<AreasItem> areaRaster, String comment) { for (LandCoverType l : LandCoverType.values()) { double total = 0; @@ -95,10 +94,8 @@ public class GamsRasterOptimiser { AreasItem prevAreaAggItem = prevAreasAgg.get(locId); Set<RasterKey> keys = mapping.get(locId); - checkedTotalAreas(newAreaRaster.popSubsetForKeys(new RasterSet<AreasItem>(newAreaRaster.getHeaderDetails()), keys), locId + " before"); - - - // if (DEBUG) LogWriter.println("Processing location id " + locId); + // if (DEBUG) + checkedTotalAreas(newAreaRaster.popSubsetForKeys(new RasterSet<AreasItem>(newAreaRaster.getHeaderDetails()), keys), locId + " before"); double pastureChange = newAreaAggItem.getLandCoverArea(LandCoverType.PASTURE) - prevAreaAggItem.getLandCoverArea(LandCoverType.PASTURE); double croplandChange = newAreaAggItem.getLandCoverArea(LandCoverType.CROPLAND) - prevAreaAggItem.getLandCoverArea(LandCoverType.CROPLAND); @@ -139,7 +136,8 @@ public class GamsRasterOptimiser { if (shortfall > 0.00001) LogWriter.printlnError("This should never happen, due to GAMS constraint. Not able to incorporate all changes, as not enough forest or natural areas left: " + locId + ": " + shortfall); - checkedTotalAreas(newAreaRaster.popSubsetForKeys(new RasterSet<AreasItem>(newAreaRaster.getHeaderDetails()), keys), locId + " after"); + // if (DEBUG) + checkedTotalAreas(newAreaRaster.popSubsetForKeys(new RasterSet<AreasItem>(newAreaRaster.getHeaderDetails()), keys), locId + " after"); for (RasterKey key : keys) { AreasItem newAreasRasterItem = newAreaRaster.get(key); diff --git a/src/ac/ed/lurg/country/gams/GamsRasterTest.java b/src/ac/ed/lurg/country/gams/GamsRasterTest.java index 71f0fb05276ed0d53c6076c0def8a571613f8382..40c65ac261e8c8843ad6786e10c92b60e2a964f0 100644 --- a/src/ac/ed/lurg/country/gams/GamsRasterTest.java +++ b/src/ac/ed/lurg/country/gams/GamsRasterTest.java @@ -18,7 +18,7 @@ public class GamsRasterTest extends GamsLocationTest { } private void run() { - GamsCountryInput countryLevelInputs = GamsCountryInput.createInput(new Country("Test", "TES", 123), getProjectedDemand(), getWorldInputEnergy(), getBaseNetImport(), null, null, true); + GamsCountryInput countryLevelInputs = GamsCountryInput.createInput(new Country("Test", "TES", 123, "R1"), getProjectedDemand(), getWorldInputEnergy(), getBaseNetImport(), null, null, true); GamsRasterInput input = new GamsRasterInput(new Timestep(0), getYieldRaster(), getPreviousAreaRaster(), getIrrigationCost(), countryLevelInputs); GamsRasterOptimiser opti = new GamsRasterOptimiser(input); diff --git a/src/ac/ed/lurg/types/CropType.java b/src/ac/ed/lurg/types/CropType.java index 7050dcf09130abf9f5e6a810032a48bf4759e201..efe7556ff390e9e6e408137de8b439af21d8fddb 100644 --- a/src/ac/ed/lurg/types/CropType.java +++ b/src/ac/ed/lurg/types/CropType.java @@ -19,7 +19,7 @@ public enum CropType { PULSES("Pulses + (Total)", "pulses"), STARCHY_ROOTS("Starchy Roots + (Total)", "starchyRoots"), MEAT("meatmilkeggs", "meat", true, true), - PASTURE("pasture", "pasture", false, false); + PASTURE("pasture", "pasture", false, false); // confusing having a land cover and a crop type. Needed here for yields (but not used for cropland area fractions). private String faoName; private String gamsName; diff --git a/src/ac/sac/raster/RasterOutputer.java b/src/ac/sac/raster/RasterOutputer.java index 8932b11bea10bcd2d115a8910952bee0ccfe0529..c9ddf3bbba6734b4dcea5f3e1108592876f74052 100644 --- a/src/ac/sac/raster/RasterOutputer.java +++ b/src/ac/sac/raster/RasterOutputer.java @@ -37,7 +37,7 @@ public abstract class RasterOutputer<D extends RasterItem> { BufferedWriter fileWriter = null; try { - String fullPathFileName = ModelConfig.OUTPUT_DIR + File.separator + fileName + ".txt"; + String fullPathFileName = ModelConfig.OUTPUT_DIR + File.separator + fileName + ".asc"; fileWriter = new BufferedWriter(new FileWriter(fullPathFileName,false)); String nullDataString = results.getHeaderDetails().getNodataString();