diff --git a/src/ac/ed/lurg/ModelConfig.java b/src/ac/ed/lurg/ModelConfig.java index 594d9e2d60262b943b92efce30c9fa9e6b37dbce..a96c2bae71e551a26ef2e9380e9b55bbebce2106 100644 --- a/src/ac/ed/lurg/ModelConfig.java +++ b/src/ac/ed/lurg/ModelConfig.java @@ -80,8 +80,8 @@ public class ModelConfig { public static final boolean SUPPRESS_STD_OUTPUT = getBooleanProperty("SUPPRESS_STD_OUTPUT", Boolean.FALSE); + // Directory information public static final String BASE_DIR = getProperty("BASE_DIR"); // this must to be set in config file - public static final String TEMP_DIR = getProperty("TEMP_DIR", BASE_DIR + File.separator + "temp"); public static final String OUTPUT_DIR = getProperty("OUTPUT_DIR", BASE_DIR + File.separator + "output"); public static final String DATA_DIR = getProperty("DATA_DIR", BASE_DIR + File.separator + "data"); @@ -100,39 +100,34 @@ public class ModelConfig { // yield data public static final String YIELD_DIR = getProperty("YIELD_DIR"); public static final boolean CHANGE_YIELD_DATA_YEAR = getBooleanProperty("CHANGE_YIELD_DATA_YEAR", true); - + public static final int LPJG_MONITOR_TIMEOUT_SEC = getIntProperty("LPJG_MONITOR_TIMEOUT", 60*60*2); 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); public static final double CELL_SIZE_Y = getDoubleProperty("CELL_SIZE_Y", CELL_SIZE_X); - public static final String SPATIAL_DIR_NAME = getProperty("SPATIAL_DIR_NAME", "3deg"); - public static final String SPATIAL_DATA_DIR = getProperty("SPATIAL_DATA_DIR", DATA_DIR + File.separator + SPATIAL_DIR_NAME); public static final String INITAL_LAND_COVER_FILE = SPATIAL_DATA_DIR + File.separator + "netfract_hurtt_2000.txt"; public static final String COUNTRY_BOUNDARY_FILE = SPATIAL_DATA_DIR + File.separator + "country_boundaries.asc"; public static final String IRRIGATION_COST_FILE = SPATIAL_DATA_DIR + File.separator + "irrigation_cost.asc";; public static final double IRRIG_COST_SCALE_FACTOR = 0.0003; // something wrong with the 3 deg irrigation cost file (figures are v large) - + // Output + public static final String TOTAL_LAND_COVER_FILE = OUTPUT_DIR + File.separator + "total_lc.txt"; + public static final boolean OUTPUT_FOR_LPJG = getBooleanProperty("OUTPUT_FOR_LPJG", true); + + // Temporal configuration public static final int START_TIMESTEP = getIntProperty("START_TIMESTEP", 0); - public static final int END_TIMESTEP = getIntProperty("END_TIMESTEP", 4); - public static final int TIMESTEP_SIZE = getIntProperty("TIMESTEP_SIZE", 10); + public static final int END_TIMESTEP = getIntProperty("END_TIMESTEP", 18); + public static final int TIMESTEP_SIZE = getIntProperty("TIMESTEP_SIZE", 5); public static final int BASE_YEAR = getIntProperty("BASE_YEAR", 2010); - - public static final double MAX_IMPORT_CHANGE = getDoubleProperty("MAX_IMPORT_CHANGE", 0.1); - + + // Other model parameters public static final String SSP_SCENARIO = getProperty("SSP_SCENARIO", "SSP5_v9_130325"); - - // Output - 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"; + public static final double MAX_IMPORT_CHANGE = getDoubleProperty("MAX_IMPORT_CHANGE", 0.1); - // public static final double PASTURE_HARVEST_FRACTION = getDoubleProperty("PASTURE_HARVEST_FRACTION", 0.5); public static final double MEAT_EFFICIENCY = getDoubleProperty("MEAT_EFFICIENCY", 0.5); public static final double LAND_CHANGE_COST = getDoubleProperty("LAND_CHANGE_COST", 2.0); @@ -140,5 +135,4 @@ public class ModelConfig { public static final double SEED_AND_WASTE_FRACTION = getDoubleProperty("SEED_AND_WASTE_FRACTION", 0.1); public static final double MARKET_LAMBA = getDoubleProperty("MARKET_LAMBA", 0.3); // controls market price adjustment rate - } \ No newline at end of file diff --git a/src/ac/ed/lurg/ModelMain.java b/src/ac/ed/lurg/ModelMain.java index 546584a243cf5a8635d276f76c568e94990f9787..48d078bc15487b2ad0a081b783502cbfcfe3cda6 100644 --- a/src/ac/ed/lurg/ModelMain.java +++ b/src/ac/ed/lurg/ModelMain.java @@ -142,11 +142,9 @@ public class ModelMain { // output results outputTimestepResults(timestep, globalIntensityRaster, globalCropAreaRaster, globalLocationIdRaster, yieldSurfaces); - writeMarketFile(timestep, globalCropAreaRaster); } public double updateMarketPrices(double previousPrice, double demand, double supply) { - if (demand > 0 || supply > 0) { double ratio; @@ -188,7 +186,7 @@ public class ModelMain { private void writeMarketFile(Timestep timestep, RasterSet<AreasItem> cropAreaRaster) { try { StringBuffer sbHeadings = new StringBuffer("Year, Cropland (Mha), Pasture (Mha), Natural (Mha)"); - for (CropType crop : CropType.getImportedTypes() ) + for (CropType crop : CropType.getImportedTypes()) sbHeadings.append(",Px_" + crop.getGamsName()); BufferedWriter outputFile = getFileWriter(timestep, ModelConfig.TOTAL_LAND_COVER_FILE, sbHeadings.toString()); @@ -199,7 +197,7 @@ public class ModelMain { for (CropType crop : CropType.getImportedTypes() ) sbData.append(String.format(",%.3f", prevWorldPrices.get(crop))); - + outputFile.write(sbData.toString()); outputFile.newLine(); outputFile.close(); @@ -209,49 +207,16 @@ public class ModelMain { } } - private void outputTimestepResults(Timestep timestep, RasterSet<IntensitiesItem> intensityRaster, RasterSet<AreasItem> cropAreaRaster, RasterSet<IntegerRasterItem> locationIdRaster, YieldRaster yieldSurfaces) { - - - - LpjgOutputer lpjOutputer = new LpjgOutputer(timestep, intensityRaster, cropAreaRaster, yieldSurfaces); - lpjOutputer.writeOutput(); + private void outputTimestepResults(Timestep timestep, RasterSet<IntensitiesItem> intensityRaster, RasterSet<AreasItem> cropAreaRaster, + RasterSet<IntegerRasterItem> locationIdRaster, YieldRaster yieldSurfaces) { - /* new RasterOutputer<IntegerRasterItem>(locationIdRaster, "locId" + year) { - @Override - public Double getValue(RasterKey location) { - IntegerRasterItem locItem = results.get(location); - if (locItem == null) - return null; - - return (double)locItem.getInt(); - } - - @Override - public int convertToPixelValue(double value) { - return (int) (value * 3 + 1); - } - }.writeOutput(ModelConfig.WRITE_JPEG_IMAGES); + writeMarketFile(timestep, cropAreaRaster); - - new RasterOutputer<IntensitiesItem>(intensityRaster, "wheatIntensity" + year) { - @Override - public Double getValue(RasterKey location) { - IntensitiesItem intensityItem = results.get(location); - if (intensityItem == null) - return null; - - Intensity cropIntensity = intensityItem.getIntensity(CropType.WHEAT); - - return cropIntensity == null ? 0 : cropIntensity.getFertiliserIntensity(); - } - - @Override - public int convertToPixelValue(double value) { - return (int) (value * 20) + 1; - } - }.writeOutput(ModelConfig.WRITE_JPEG_IMAGES); - - outputAreas(year, cropAreaRaster, CropType.MAIZE); */ + if (ModelConfig.OUTPUT_FOR_LPJG) { + LpjgOutputer lpjOutputer = new LpjgOutputer(timestep, intensityRaster, cropAreaRaster, yieldSurfaces); + lpjOutputer.writeOutput(); + } + outputLandCover(timestep.getYear(), cropAreaRaster, LandCoverType.CROPLAND); outputLandCover(timestep.getYear(), cropAreaRaster, LandCoverType.PASTURE); } @@ -266,12 +231,7 @@ public class ModelMain { return area.getLandCoverArea(lcType); } - - @Override - public int convertToPixelValue(double value) { - return value > 0 ? 10 : 1; - } - }.writeOutput(ModelConfig.WRITE_JPEG_IMAGES); + }.writeOutput(); } public Map<Country, List<RasterKey>> createCountryToKeysMap() { @@ -324,7 +284,7 @@ public class ModelMain { // continue; // } - if (demandManager.getPopulation(country, 2010) < 80 || 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/gams/GamsLocationOptimiser.java b/src/ac/ed/lurg/country/gams/GamsLocationOptimiser.java index ce2060a8a7bff9291ec7f6bfd37f185edaaca57d..a099c6520126d38f813c6e3599e586eb32b17643 100644 --- a/src/ac/ed/lurg/country/gams/GamsLocationOptimiser.java +++ b/src/ac/ed/lurg/country/gams/GamsLocationOptimiser.java @@ -271,8 +271,9 @@ public class GamsLocationOptimiser { } netImport = varNetImports.findRecord(CropType.MEAT.getGamsName()).getLevel(); - prod = parmProd.findRecord(CropType.MEAT.getGamsName()).getValue(); - prodCost = parmProdCost.findRecord(CropType.MEAT.getGamsName()).getValue(); + prod = getParmValue(parmProd, CropType.MEAT.getGamsName()); + prodCost = getParmValue(parmProdCost, CropType.MEAT.getGamsName()); + 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)); diff --git a/src/ac/sac/raster/RasterOutputer.java b/src/ac/sac/raster/RasterOutputer.java index c9ddf3bbba6734b4dcea5f3e1108592876f74052..523183450fa1955ac3221b9c45920625228ca8e8 100644 --- a/src/ac/sac/raster/RasterOutputer.java +++ b/src/ac/sac/raster/RasterOutputer.java @@ -31,8 +31,16 @@ public abstract class RasterOutputer<D extends RasterItem> { } abstract public Double getValue(RasterKey location); - abstract public int convertToPixelValue(double value); + + public int convertToPixelValue(double value) { + throw new RuntimeException("RasterOutputer: if outputing image, need to override this method. "); + } + /** write raster output, but no image */ + public void writeOutput() { + writeOutput(false); + } + public void writeOutput(boolean writeImage) { BufferedWriter fileWriter = null;