diff --git a/src/ac/ed/lurg/ModelConfig.java b/src/ac/ed/lurg/ModelConfig.java index c59ff35ceecd46c0c67351cc16651712452e20fa..aba91b802658e585e94442dd7e227ec8e86bcae5 100644 --- a/src/ac/ed/lurg/ModelConfig.java +++ b/src/ac/ed/lurg/ModelConfig.java @@ -113,8 +113,7 @@ public class ModelConfig { 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 String IRRIGATION_CONSTRAINT_FILE = SPATIAL_DATA_DIR + File.separator + "blue_water_available_pseudoCRU_rcp8p5_2004_2013_grid_allhdyro_mm_3deg.txt"; - public static final String IRRIG_MAX_WATER_FILENAME = getProperty("IRRIG_MAX_WATER_FILENAME", "max_irrig_water.out"); - public static final String IRRIG_MAX_WATER_FILE = YIELD_DIR + File.separator + IRRIG_MAX_WATER_FILENAME; + public static final String IRRIG_MAX_WATER_FILENAME = getProperty("IRRIG_MAX_WATER_FILENAME", "gsirr_1996_2005_100kgNha_3deg"); // Output public static final String LAND_COVER_OUTPUT_FILE = OUTPUT_DIR + File.separator + "lc.txt"; diff --git a/src/ac/ed/lurg/ModelMain.java b/src/ac/ed/lurg/ModelMain.java index 3ab05cdf84ca859ee5d491f7946372bbd880bbe3..90d2ce0d0bf1af1258cf4937cc44b025b0d187f4 100644 --- a/src/ac/ed/lurg/ModelMain.java +++ b/src/ac/ed/lurg/ModelMain.java @@ -1,6 +1,7 @@ package ac.ed.lurg; import java.io.BufferedWriter; +import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.Collection; @@ -55,6 +56,7 @@ public class ModelMain { private Map<CropType, GlobalPrice> prevWorldPrices; private RasterSet<LandUseItem> prevLandUseRaster; + private RasterSet<IrrigationItem> currentIrrigationData; public static void main(String[] args) { ModelMain theModel = new ModelMain(); @@ -69,7 +71,8 @@ public class ModelMain { BaseConsumpManager baseConsumpManager = new BaseConsumpManager(); compositeCountryManager = new CompositeCountryManager(baseConsumpManager); demandManager = new DemandManager(ModelFitType.LOGISTIC, ModelConfig.SSP_SCENARIO, baseConsumpManager, compositeCountryManager); - + currentIrrigationData = getFixedIrrigationData(); + countryBoundaryRaster = getCountryBoundaryRaster(); countryAgents = createCountryAgents(compositeCountryManager.getAll()); @@ -99,7 +102,7 @@ public class ModelMain { LogWriter.println(timestep.toString()); YieldRaster yieldSurfaces = getYieldSurfaces(timestep); // this will wait for the marker file from LPJ if configured to do so - RasterSet<IrrigationItem> allIrrigData = getIrrigationData(timestep, yieldSurfaces); + RasterSet<IrrigationItem> allIrrigData = getUpdateIrrigationData(timestep, yieldSurfaces); YieldResponsesItem yresp = yieldSurfaces.getFromCoordinates(-90.5, 45.5); LogWriter.printlnError("Test key: " + yresp.getYieldMax(CropType.MAIZE) + ", " + yresp.getYieldFertOnly(CropType.MAIZE) + ", " + yresp.getYieldIrrigOnly(CropType.MAIZE) + ", " + yresp.getYieldNone(CropType.MAIZE)); @@ -335,7 +338,7 @@ public class ModelMain { // DEBUG code if (ModelConfig.DEBUG_LIMIT_COUNTRIES) { - if (!(cc.getName().equals("United States of America") || cc.getName().equals("Chinaxx") || cc.getName().equals("Russian Federationxx") || cc.getName().equals("South Asia_otherxx")) ) { + if (!(cc.getName().equals("United States of Americaxx") || cc.getName().equals("China") || cc.getName().equals("Russian Federationxx") || cc.getName().equals("South Asia_otherxx")) ) { continue; } } @@ -370,22 +373,24 @@ public class ModelMain { LPJYieldResponseMapReader yieldReader = new LPJYieldResponseMapReader(desiredProjection); return yieldReader.getRasterData(timestep); } - - private RasterSet<IrrigationItem> getIrrigationData(Timestep timestep, YieldRaster yieldSurfaces) { - double needToUseTimeStepForMaxData; + /** Get irrigation data components that don't change over time */ + private RasterSet<IrrigationItem> getFixedIrrigationData() { RasterSet<IrrigationItem> irigData = new RasterSet<IrrigationItem>(desiredProjection) { private static final long serialVersionUID = 8393130687550888654L; - protected IrrigationItem createRasterData() { return new IrrigationItem(); } }; - new IrrigiationCostReader(irigData).getRasterDataFromFile(ModelConfig.IRRIGATION_COST_FILE); - new IrrigationConstraintReader(irigData).getRasterDataFromFile(ModelConfig.IRRIGATION_CONSTRAINT_FILE); - new IrrigationMaxAmountReader(irigData, yieldSurfaces).getRasterDataFromFile(ModelConfig.IRRIG_MAX_WATER_FILE); - + new IrrigiationCostReader(irigData).getRasterDataFromFile(ModelConfig.IRRIGATION_COST_FILE); + new IrrigationConstraintReader(irigData).getRasterDataFromFile(ModelConfig.IRRIGATION_CONSTRAINT_FILE); return irigData; } + + private RasterSet<IrrigationItem> getUpdateIrrigationData(Timestep timestep, YieldRaster yieldSurfaces) { + String rootDir = timestep.getYearSubDir(ModelConfig.YIELD_DIR); + new IrrigationMaxAmountReader(currentIrrigationData, yieldSurfaces).getRasterDataFromFile(rootDir + File.separator + ModelConfig.IRRIG_MAX_WATER_FILENAME); + return currentIrrigationData; + } } \ No newline at end of file diff --git a/src/ac/ed/lurg/Timestep.java b/src/ac/ed/lurg/Timestep.java index b72173612081137760cf74714fcb8cac3b321fbf..496697c7d9f04ce396c8151f7a1bb3eff9b55173 100644 --- a/src/ac/ed/lurg/Timestep.java +++ b/src/ac/ed/lurg/Timestep.java @@ -1,5 +1,6 @@ package ac.ed.lurg; +import java.io.File; import java.util.ArrayList; import java.util.Collection; @@ -82,4 +83,11 @@ public class Timestep { return years; } + + public String getYearSubDir(String rootDir) { + if (ModelConfig.CHANGE_YIELD_DATA_YEAR) + return rootDir + File.separator + getYieldYear(); + else + return rootDir; + } } diff --git a/src/ac/ed/lurg/yield/LPJYieldResponseMapReader.java b/src/ac/ed/lurg/yield/LPJYieldResponseMapReader.java index 311497164a15c6e1b4c80cdd93e343cce0b690ad..fcd5fc73d317847fe2698889d4a67237d86a967e 100644 --- a/src/ac/ed/lurg/yield/LPJYieldResponseMapReader.java +++ b/src/ac/ed/lurg/yield/LPJYieldResponseMapReader.java @@ -25,12 +25,7 @@ public class LPJYieldResponseMapReader extends AbstractTabularRasterReader<Yield } public YieldRaster getRasterData(Timestep timestep) { - String rootDir; - - if (ModelConfig.CHANGE_YIELD_DATA_YEAR) - rootDir = ModelConfig.YIELD_DIR + File.separator + timestep.getYieldYear(); - else - rootDir = ModelConfig.YIELD_DIR; + String rootDir = timestep.getYearSubDir(ModelConfig.YIELD_DIR); // wait for data to be available long startTime = System.currentTimeMillis();