diff --git a/GAMS/IntExtOpt.gms b/GAMS/IntExtOpt.gms index 66115fcbe8f6b23038aba9ccf55c34d6efc315df..5b1afba8e6e4934fdf665400f145627b629e0dce 100644 --- a/GAMS/IntExtOpt.gms +++ b/GAMS/IntExtOpt.gms @@ -66,7 +66,7 @@ SCALAR carbonPrice price of carbon; SCALAR woodPrice price of wood and timber; -*$gdxin "/Users/peteralexander/Documents/R_Workspace/UNPLUM/temp/GamsTmp/t1.gdx" +*$gdxin "C:\Users\Bart\Documents\PhD\GAMS testing area\_gams_java_gdb1.gdx" $gdxin %gdxincname% $load location, suitableLandArea, demand, agriExpansionCost, cropIncCost, pastureIncCost, cropDecCost, pastureDecCost $load previousCropArea, previousFertIntensity, previousIrrigIntensity, previousOtherIntensity, previousRuminantFeed, previousMonogastricFeed, previousImportAmount, previousExportAmount @@ -77,6 +77,10 @@ $load previousLandCoverArea, carbonFluxRate, woodYield, carbonPrice, woodPrice *$load minimumLandCoverArea $gdxin +* need to convert from $/kg to $/Mt + carbonPrice = carbonPrice * 0.01; + woodPrice = woodPrice * 0.01; + SCALAR delta use to smooth power function see 7.5 www.gams.com dd docs solversconopt.pdf / 0.00000000001 /; demand(cereal_crop) = demand('cereals') * minDemandPerCereal(cereal_crop); @@ -177,6 +181,7 @@ $gdxin * TOTAL_LAND_COVER_CONSTRAINT(location) total land cover equals suitable area LAND_COVER_CHANGE_CALC(land_cover, location) LAND_COVER_CHANGE_CONSTRAINT(land_cover, location) + LAND_COVER_SELF_CHANGE_CONSTRAINT(land_cover, location) WOOD_HARVEST_CALC(location) calc wood harvested CARBON_FLUX_CALC(location) calc carbon flux COST_EQ total cost objective function; @@ -244,6 +249,8 @@ $gdxin LAND_COVER_CHANGE_CONSTRAINT(land_cover, location) .. sum(land_cover_after, landCoverChange(land_cover, land_cover_after, location)) =L= previousLandCoverArea(land_cover, location); + LAND_COVER_SELF_CHANGE_CONSTRAINT(land_cover, location) .. landCoverChange(land_cover, land_cover, location) =E= 0; + * TOTAL_LAND_COVER_CONSTRAINT(location) .. sum(land_cover, landCoverArea(land_cover, location)) =E= suitableLandArea(location); WOOD_HARVEST_CALC(location) .. woodHarvest(location) =E= sum((land_cover_before, land_cover_after), landCoverChange(land_cover_before, land_cover_after, location) * woodYield(land_cover_before, land_cover_after, location)); diff --git a/src/ac/ed/lurg/ModelConfig.java b/src/ac/ed/lurg/ModelConfig.java index 8703013576acb0a8e3fe121ed5e10e19c2710b55..d8f42418536952d2ca5aa3093940e213cb134257 100755 --- a/src/ac/ed/lurg/ModelConfig.java +++ b/src/ac/ed/lurg/ModelConfig.java @@ -423,7 +423,7 @@ public class ModelConfig { public static final String TARGET_DIET_FILE = getProperty("TARGET_DIET_FILE", DATA_DIR + File.separator + "TargetDiet.txt"); // Forestry parameters - public static final double CARBON_PRICE = getDoubleProperty("CARBON_PRICE", 20.0); - public static final double WOOD_PRICE = getDoubleProperty("WOOD_PRICE", 0.175); + public static final double CARBON_PRICE = getDoubleProperty("CARBON_PRICE", 20.0); // $/tC + public static final double WOOD_PRICE = getDoubleProperty("WOOD_PRICE", 0.175); // $/tC } diff --git a/src/ac/ed/lurg/ModelMain.java b/src/ac/ed/lurg/ModelMain.java index 0ae21ecd9aa272646cfa9533a2a4374b68c5f2bb..66294c60fb6d6349cbb1b27c0a073bb1dee8805e 100644 --- a/src/ac/ed/lurg/ModelMain.java +++ b/src/ac/ed/lurg/ModelMain.java @@ -142,7 +142,7 @@ public class ModelMain { CarbonFluxRasterSet currentCarbonFluxData = getCarbonFluxData(timestep); LogWriter.println("Carbon flux data read"); - LogWriter.println("Data: " + currentCarbonFluxData.get(1, 1).getCarbonFluxes()); + LogWriter.println("First line: " + currentCarbonFluxData.get(1, 1).getCarbonFluxes()); WoodYieldRasterSet currentWoodYieldData = getWoodYieldData(timestep); countryAgents.determineProductionForAll(timestep, yieldSurfaces, currentIrrigationData, gen2Increase, currentCarbonFluxData, currentWoodYieldData); @@ -170,7 +170,7 @@ public class ModelMain { sbData.append(String.format("%d,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f", timestep.getYear(), LandUseItem.getTotalLandCover(landUseRaster.values(), LandCoverType.CROPLAND), LandUseItem.getTotalLandCover(landUseRaster.values(), LandCoverType.PASTURE), - LandUseItem.getTotalLandCover(landUseRaster.values(), LandCoverType.MANAGED_FOREST), + LandUseItem.getTotalLandCover(landUseRaster.values(), LandCoverType.TIMBER_FOREST) + LandUseItem.getTotalLandCover(landUseRaster.values(), LandCoverType.CARBON_FOREST), LandUseItem.getTotalLandCover(landUseRaster.values(), LandCoverType.UNMANAGED_FOREST), LandUseItem.getTotalLandCover(landUseRaster.values(), LandCoverType.OTHER_NATURAL), LandUseItem.getAbandonedPasture(landUseRaster.values()), @@ -626,7 +626,7 @@ public class ModelMain { }; new MaxCropAreaReader(initialLC).getRasterDataFromFile(ModelConfig.HIGH_SLOPE_AREAS_FILE); - new LandCoverReader(initialLC).getRasterDataFromFile(ModelConfig.INITAL_LAND_COVER_FILE); + new LandCoverReader(initialLC).getRasterDataFromFile(ModelConfig.INITAL_LAND_COVER_FILE); // Land cover fractions RasterSet<LandUseItem> landUseRaster = new RasterSet<LandUseItem>(initialLC.getHeaderDetails()); diff --git a/src/ac/ed/lurg/country/gams/GamsLocationOptimiser.java b/src/ac/ed/lurg/country/gams/GamsLocationOptimiser.java index c8278cd1edb441c57b019633487e6b0ade414875..9f1d7b93f060c0ddef00a0288a924e1a1d5f27f6 100644 --- a/src/ac/ed/lurg/country/gams/GamsLocationOptimiser.java +++ b/src/ac/ed/lurg/country/gams/GamsLocationOptimiser.java @@ -27,10 +27,12 @@ import ac.ed.lurg.landuse.CarbonFluxItem; import ac.ed.lurg.landuse.CropUsageData; import ac.ed.lurg.landuse.Intensity; import ac.ed.lurg.landuse.IrrigationItem; +import ac.ed.lurg.landuse.LandCoverChangeItem; import ac.ed.lurg.landuse.LandUseItem; import ac.ed.lurg.landuse.WoodYieldItem; import ac.ed.lurg.types.CommodityType; import ac.ed.lurg.types.CropType; +import ac.ed.lurg.types.GamsLandCoverType; import ac.ed.lurg.types.LandCoverType; import ac.ed.lurg.types.Parameter; import ac.ed.lurg.types.YieldType; @@ -169,13 +171,25 @@ public class GamsLocationOptimiser { } // Previous land covers - for (LandCoverType lc : LandCoverType.getGamsTypes()) { - Vector<String> v = new Vector<String>(); - v.add(lc.getName()); - v.add(locString); - setGamsParamValue(prevLandCoverP.addRecord(v), landUseItem.getUnprotectedLandCoverArea(lc), 3); - } - + Vector<String> v = new Vector<String>(); + + // TODO Increase number of decimal places? + v.add("cropland"); + v.add(locString); + setGamsParamValueTruncate(prevLandCoverP.addRecord(v), landUseItem.getUnprotectedLandCoverArea(LandCoverType.CROPLAND), 3); + + v.set(0, "pasture"); + setGamsParamValueTruncate(prevLandCoverP.addRecord(v), landUseItem.getUnprotectedLandCoverArea(LandCoverType.PASTURE), 3); + + v.set(0, "timberForest"); + setGamsParamValueTruncate(prevLandCoverP.addRecord(v), landUseItem.getUnprotectedLandCoverArea(LandCoverType.TIMBER_FOREST), 3); + + v.set(0, "carbonForest"); + setGamsParamValueTruncate(prevLandCoverP.addRecord(v), landUseItem.getUnprotectedLandCoverArea(LandCoverType.CARBON_FOREST), 3); + + v.set(0, "natural"); + setGamsParamValueTruncate(prevLandCoverP.addRecord(v), landUseItem.getUnprotectedLandCoverArea(LandCoverType.OTHER_NATURAL) + landUseItem.getUnprotectedLandCoverArea(LandCoverType.UNMANAGED_FOREST), 3); + } if (DEBUG) LogWriter.println(String.format(" Total agricultural %.1f,\t suitable %.1f", totalAgriLand, totalSuitable)); @@ -349,8 +363,8 @@ public class GamsLocationOptimiser { String locString = Integer.toString(locationId); CarbonFluxItem cFlux = entry.getValue(); - for (LandCoverType prevLC : LandCoverType.getGamsTypes()) { - for (LandCoverType newLC : LandCoverType.getGamsTypes()) { + for (GamsLandCoverType prevLC : GamsLandCoverType.values()) { + for (GamsLandCoverType newLC : GamsLandCoverType.values()) { Vector<String> v = new Vector<String>(); v.add(prevLC.getName()); v.add(newLC.getName()); @@ -369,8 +383,8 @@ public class GamsLocationOptimiser { String locString = Integer.toString(locationId); WoodYieldItem wYield = entry.getValue(); - for (LandCoverType prevLC : LandCoverType.getGamsTypes()) { - for (LandCoverType newLC : LandCoverType.getGamsTypes()) { + for (GamsLandCoverType prevLC : GamsLandCoverType.values()) { + for (GamsLandCoverType newLC : GamsLandCoverType.values()) { Vector<String> v = new Vector<String>(); v.add(prevLC.getName()); v.add(newLC.getName()); @@ -509,6 +523,7 @@ public class GamsLocationOptimiser { totalCropArea+totalPastureArea, totalCropArea, totalPastureArea)); +/* // Land cover areas (exc. cropland and pasture) GAMSVariable varLandCoverArea = outDB.getVariable("landCoverArea"); double landCoverArea; @@ -530,16 +545,23 @@ public class GamsLocationOptimiser { landUseItem.setLandCoverArea(LandCoverType.CARBON_FOREST, landCoverArea); break; case "natural": - landUseItem.setLandCoverArea(LandCoverType.NATURAL, landCoverArea); + + double prevOtherNaturalArea = inputData.getPreviousLandUse().get(locId).getLandCoverArea(LandCoverType.OTHER_NATURAL); + double prevUnmanagedForestArea = inputData.getPreviousLandUse().get(locId).getLandCoverArea(LandCoverType.UNMANAGED_FOREST); + double prevUnmanagedForestProp = (prevOtherNaturalArea + prevUnmanagedForestArea) != 0 ? prevUnmanagedForestArea / (prevUnmanagedForestArea + prevOtherNaturalArea) : 0; + + landUseItem.setLandCoverArea(LandCoverType.UNMANAGED_FOREST, landCoverArea * prevUnmanagedForestProp); // TODO Split into unmanaged forest and other natural + landUseItem.setLandCoverArea(LandCoverType.OTHER_NATURAL, landCoverArea * (1 - prevUnmanagedForestProp)); // TODO Split into unmanaged forest and other natural break; } } - +*/ // Land cover change GAMSVariable varLandCoverChange = outDB.getVariable("landCoverChange"); - Map<Integer, Map<LandCoverType, Map<LandCoverType, Double>>> landCoverChange = new HashMap<Integer, Map<LandCoverType, Map<LandCoverType, Double>>>(); + LandCoverChangeItem landCoverChange = new LandCoverChangeItem(); + for (GAMSVariableRecord rec : varLandCoverChange) { String fromLC = rec.getKeys()[0]; @@ -549,46 +571,35 @@ public class GamsLocationOptimiser { double change = rec.getLevel(); - if (landCoverChange.containsKey(locId)) { - Map<LandCoverType, Map<LandCoverType, Double>> locMap = landCoverChange.get(locId); - - if (locMap.containsKey(LandCoverType.getForName(fromLC))) { - locMap.get(LandCoverType.getForName(fromLC)).put(LandCoverType.getForName(toLC), change); - } - else { - Map<LandCoverType, Double> toMap = new HashMap<LandCoverType, Double>(); - toMap.put(LandCoverType.getForName(toLC), change); - - //Map<LandCoverType, Map<LandCoverType, Double>> fromMap = new HashMap<LandCoverType, Map<LandCoverType, Double>>(); - //fromMap.put(LandCoverType.getForName(fromLC), toMap); - - landCoverChange.get(locId).put(LandCoverType.getForName(fromLC), toMap); - } - } - else { - Map<LandCoverType, Double> toMap = new HashMap<LandCoverType, Double>(); - toMap.put(LandCoverType.getForName(toLC), change); - - Map<LandCoverType, Map<LandCoverType, Double>> fromMap = new HashMap<LandCoverType, Map<LandCoverType, Double>>(); - fromMap.put(LandCoverType.getForName(fromLC), toMap); - - landCoverChange.put(locId, fromMap); - } + if (change == 0.0) { + continue; + } - /* - Map<LandCoverType, Double> toMap = new HashMap<LandCoverType, Double>(); - toMap.put(LandCoverType.getForName(toLC), change); - - Map<LandCoverType, Map<LandCoverType, Double>> fromMap = new HashMap<LandCoverType, Map<LandCoverType, Double>>(); - fromMap.put(LandCoverType.getForName(fromLC), toMap); - - landCoverChange.put(locId, fromMap); - */ + if (fromLC.equals("natural")) { + double prevUnmanagedForestProp = getPrevUnmanagedForestProp(locId); + landCoverChange.setLandCoverChange(LandCoverType.UNMANAGED_FOREST, LandCoverType.getForName(toLC), locId, change * prevUnmanagedForestProp); + landCoverChange.setLandCoverChange(LandCoverType.OTHER_NATURAL, LandCoverType.getForName(toLC), locId, change * (1 - prevUnmanagedForestProp)); + } else if (toLC.equals("natural")) { + double prevUnmanagedForestProp = getPrevUnmanagedForestProp(locId); + landCoverChange.setLandCoverChange(LandCoverType.getForName(fromLC), LandCoverType.UNMANAGED_FOREST, locId, change * prevUnmanagedForestProp); + landCoverChange.setLandCoverChange(LandCoverType.getForName(fromLC), LandCoverType.OTHER_NATURAL, locId, change * (1 - prevUnmanagedForestProp)); + } else { + landCoverChange.setLandCoverChange(LandCoverType.getForName(fromLC), LandCoverType.getForName(toLC), locId, change); + } + } GamsLocationOutput results = new GamsLocationOutput(modelStatus, landUses, cropUsageData, landCoverChange); return results; } + + private double getPrevUnmanagedForestProp(Integer locId) { + double prevOtherNaturalArea = inputData.getPreviousLandUse().get(locId).getUnprotectedLandCoverArea(LandCoverType.OTHER_NATURAL); + double prevUnmanagedForestArea = inputData.getPreviousLandUse().get(locId).getUnprotectedLandCoverArea(LandCoverType.UNMANAGED_FOREST); + double prevUnmanagedForestProp = (prevOtherNaturalArea + prevUnmanagedForestArea) != 0 ? prevUnmanagedForestArea / (prevUnmanagedForestArea + prevOtherNaturalArea) : 0; + return prevUnmanagedForestProp; + } + private double getParmValue(GAMSParameter aParm, String itemName) { try { diff --git a/src/ac/ed/lurg/country/gams/GamsLocationOutput.java b/src/ac/ed/lurg/country/gams/GamsLocationOutput.java index f750626770b92f66dbe035c9fafb10ca21429431..b64a6d6ddb97826f6f64313cd44e042fe22a8f8b 100644 --- a/src/ac/ed/lurg/country/gams/GamsLocationOutput.java +++ b/src/ac/ed/lurg/country/gams/GamsLocationOutput.java @@ -1,26 +1,25 @@ package ac.ed.lurg.country.gams; -import java.util.HashMap; import java.util.Map; import com.gams.api.GAMSGlobals.ModelStat; import ac.ed.lurg.landuse.CropUsageData; +import ac.ed.lurg.landuse.LandCoverChangeItem; import ac.ed.lurg.landuse.LandUseItem; import ac.ed.lurg.types.CropType; -import ac.ed.lurg.types.LandCoverType; public class GamsLocationOutput { ModelStat status; Map<Integer, LandUseItem> landUses; // data mapped from id (not raster) private Map<CropType, CropUsageData> cropUsageData; - Map<Integer, Map<LandCoverType, Map<LandCoverType, Double>>> landCoverChange = new HashMap<Integer, Map<LandCoverType, Map<LandCoverType, Double>>>(); + LandCoverChangeItem landCoverChange = new LandCoverChangeItem(); public GamsLocationOutput(ModelStat status, Map<Integer, LandUseItem> landUses, Map<CropType, CropUsageData> cropUsageData, - Map<Integer, Map<LandCoverType, Map<LandCoverType, Double>>> landCoverChange) { + LandCoverChangeItem landCoverChange) { super(); this.status = status; this.landUses = landUses; @@ -39,7 +38,7 @@ public class GamsLocationOutput { return cropUsageData; } - public Map<Integer, Map<LandCoverType, Map<LandCoverType, Double>>> getLandCoverChange() { + public LandCoverChangeItem getLandCoverChange() { return landCoverChange; } } diff --git a/src/ac/ed/lurg/country/gams/GamsRasterOptimiser.java b/src/ac/ed/lurg/country/gams/GamsRasterOptimiser.java index a0b8df7d3f78d165b961506af9828c66dc1f4ff9..d4b6b9394d6222385dbc8c83945017bfb9454968 100644 --- a/src/ac/ed/lurg/country/gams/GamsRasterOptimiser.java +++ b/src/ac/ed/lurg/country/gams/GamsRasterOptimiser.java @@ -8,9 +8,11 @@ import java.util.Set; import ac.ed.lurg.landuse.CarbonFluxItem; import ac.ed.lurg.landuse.Intensity; import ac.ed.lurg.landuse.IrrigationItem; +import ac.ed.lurg.landuse.LandCoverChangeItem; import ac.ed.lurg.landuse.LandUseItem; import ac.ed.lurg.landuse.WoodYieldItem; import ac.ed.lurg.types.CropType; +import ac.ed.lurg.types.GamsLandCoverType; import ac.ed.lurg.types.LandCoverType; import ac.ed.lurg.types.YieldType; import ac.ed.lurg.utils.LazyTreeMap; @@ -70,12 +72,16 @@ public class GamsRasterOptimiser { private void checkedTotalAreas(Map<? extends Object, LandUseItem> areaRaster, String comment) { for (LandCoverType l : LandCoverType.values()) { double total = 0; + double unprotected = 0; for (LandUseItem a : areaRaster.values()) { - if (a != null) + if (a != null) { total += a.getLandCoverArea(l); + unprotected += a.getUnprotectedLandCoverArea(l); + } + } - LogWriter.println("Total Area " + comment + ": " + l.getName() + ": " + total); + LogWriter.println("Total Area " + comment + ": " + l.getName() + ": total = " + total + ", unprotected = " + unprotected); } double suitableArea=0, protectedArea=0; @@ -94,6 +100,8 @@ public class GamsRasterOptimiser { //checkedTotalAreas(rasterInputData.getPreviousAreas(), "old"); //checkedTotalAreas(newAreaRaster, "new"); + + LandCoverChangeItem landCoverChangeSet = gamsOutput.getLandCoverChange(); for (Map.Entry<Integer, LandUseItem> entry : gamsOutput.getLandUses().entrySet()) { Integer locId = entry.getKey(); @@ -109,33 +117,28 @@ public class GamsRasterOptimiser { } // Allocate land cover change to grid cells - // pasture, cropland, carbonForest, timberForest, natural - Map<Integer, Map<LandCoverType, Map<LandCoverType, Double>>> landCoverChange = gamsOutput.getLandCoverChange(); - - for (LandCoverType fromLC : LandCoverType.getGamsTypes()) { - for (LandCoverType toLC : LandCoverType.getGamsTypes()) { - double change = landCoverChange.get(locId).get(fromLC).get(toLC); + + Map<LandCoverType, Map<LandCoverType, Double>> landCoverChange = landCoverChangeSet.getLandCoverChangeForLocation(locId); + + /* + for (LandCoverType fromLC : LandCoverType.getConvertibleTypes()) { + for (LandCoverType toLC : LandCoverType.getConvertibleTypes()) { + double change = landCoverChange.getLandCoverChange(fromLC, toLC, locId); allocAllLandCropsTop(newLandUseRaster, keys, toLC, fromLC, change, locId); } } + */ - // Allocate derived land cover areas - // managedForest, unmanagedForest, otherNatural - for (RasterKey key : keys) { - LandUseItem newLandUseItem = newLandUseRaster.get(key); - LandUseItem prevLandUseItem = rasterInputData.getPreviousLandUses().get(key); - - if (newLandUseItem != null) { - newLandUseItem.setLandCoverArea(LandCoverType.MANAGED_FOREST, newLandUseItem.getLandCoverArea(LandCoverType.TIMBER_FOREST) + newLandUseItem.getLandCoverArea(LandCoverType.CARBON_FOREST)); - - double prevUnmanagedForest = prevLandUseItem.getLandCoverArea(LandCoverType.UNMANAGED_FOREST); - double prevOtherNatural = prevLandUseItem.getLandCoverArea(LandCoverType.OTHER_NATURAL); - double prevUnmanagedForestToNaturalProp = (prevOtherNatural > 0 || prevUnmanagedForest > 0) ? prevUnmanagedForest / (prevOtherNatural + prevUnmanagedForest) : 0.5; - newLandUseItem.setLandCoverArea(LandCoverType.UNMANAGED_FOREST, newLandUseItem.getLandCoverArea(LandCoverType.NATURAL) * prevUnmanagedForestToNaturalProp); - newLandUseItem.setLandCoverArea(LandCoverType.OTHER_NATURAL, newLandUseItem.getLandCoverArea(LandCoverType.NATURAL) * (1 - prevUnmanagedForestToNaturalProp)); - + for (Entry<LandCoverType, Map<LandCoverType, Double>> fromMap: landCoverChange.entrySet()) { + LandCoverType fromLC = fromMap.getKey(); + for (Entry<LandCoverType, Double> toMap: fromMap.getValue().entrySet()) { + LandCoverType toLC = toMap.getKey(); + double change = toMap.getValue(); + allocAllLandCropsTop(newLandUseRaster, keys, toLC, fromLC, change, locId); } } + + /* double gamsPastureChange = newLandUseAggItem.getLandCoverArea(LandCoverType.PASTURE) - prevLandUseAggItem.getLandCoverArea(LandCoverType.PASTURE); double gamsCroplandChange = newLandUseAggItem.getLandCoverArea(LandCoverType.CROPLAND) - prevLandUseAggItem.getLandCoverArea(LandCoverType.CROPLAND); @@ -451,9 +454,10 @@ public class GamsRasterOptimiser { } // Aggregate carbon fluxes and wood yields - for (LandCoverType prevLC : LandCoverType.getGamsTypes()) { - for (LandCoverType newLC : LandCoverType.getGamsTypes()) { + for (GamsLandCoverType prevLC : GamsLandCoverType.values()) { + for (GamsLandCoverType newLC : GamsLandCoverType.values()) { + // Carbon flux if (!aggCFlux.checkForKeys(prevLC, newLC)) { // if not seen yet //LogWriter.println("prevLC: " + prevLC + ", newLC: " + newLC); //LogWriter.println("Data: " + carbonFluxItem.getCarbonFluxes()); @@ -463,7 +467,8 @@ public class GamsRasterOptimiser { carbonFluxItem.getCarbonFlux(prevLC, newLC), suitableAreaThisTime)); } - if (!aggWYield.checkForKeys(prevLC, newLC)) { + // Wood yield + if (!aggWYield.checkForKeys(prevLC, newLC)) { // if not seen yet aggWYield.setWoodYield(prevLC, newLC, woodYieldItem.getWoodYield(prevLC, newLC)); } else { aggWYield.setWoodYield(prevLC, newLC, aggregateMean(aggWYield.getWoodYield(prevLC, newLC), suitableAreaSoFar, @@ -532,17 +537,18 @@ public class GamsRasterOptimiser { // Land covers areas for (LandCoverType landType : LandCoverType.values()) { - double areaThisTime = landUseItem.getUnprotectedLandCoverArea(landType); - double areaSoFar = aggLandUse.getUnprotectedLandCoverArea(landType); - - aggLandUse.setUnprotectedLandCoverArea(landType, areaSoFar + areaThisTime); - } - - + double unprotectedAreaThisTime = landUseItem.getUnprotectedLandCoverArea(landType); + double unprotectedAreaSoFar = aggLandUse.getUnprotectedLandCoverArea(landType); + aggLandUse.setUnprotectedLandCoverArea(landType, unprotectedAreaSoFar + unprotectedAreaThisTime); + + double totalAreaThisTime = landUseItem.getLandCoverArea(landType); + double totalAreaSoFar = aggLandUse.getLandCoverArea(landType); + aggLandUse.setLandCoverArea(landType, totalAreaSoFar + totalAreaThisTime); + } } } - /* +/* for (Entry<RasterKey, LandUseItem> entry : rasterInputData.getPreviousLandUses().entrySet()) { LandUseItem landUseItem = entry.getValue(); RasterKey key = entry.getKey(); @@ -557,9 +563,8 @@ public class GamsRasterOptimiser { aggLandUse.setLandCoverArea(landType, areaSoFar + areaThisTime); } } - */ +*/ /* - LogWriter.println("potato" + rasterInputData.getCountryInput().getCountry().getName()); if (rasterInputData.getCountryInput().getCountry().getName().equals("Central America")) { LogWriter.println("foo"); } diff --git a/src/ac/ed/lurg/landuse/CarbonFluxItem.java b/src/ac/ed/lurg/landuse/CarbonFluxItem.java index ce7452d61ef1f98bdc2219cbe10043514e9e9eef..7c471ae3ecca85cbb977e7f67e20274123812692 100644 --- a/src/ac/ed/lurg/landuse/CarbonFluxItem.java +++ b/src/ac/ed/lurg/landuse/CarbonFluxItem.java @@ -4,27 +4,27 @@ import ac.sac.raster.RasterItem; import java.util.HashMap; import java.util.Map; -import ac.ed.lurg.types.LandCoverType; +import ac.ed.lurg.types.GamsLandCoverType; public class CarbonFluxItem implements RasterItem { - Map<LandCoverType, Map<LandCoverType, Double>> carbonFluxes = new HashMap<LandCoverType, Map<LandCoverType, Double>>(); + Map<GamsLandCoverType, Map<GamsLandCoverType, Double>> carbonFluxes = new HashMap<GamsLandCoverType, Map<GamsLandCoverType, Double>>(); - public void setCarbonFlux(LandCoverType previousLandCover, LandCoverType newLandCover, double carbonFlux) { + public void setCarbonFlux(GamsLandCoverType previousLandCover, GamsLandCoverType newLandCover, double carbonFlux) { if (carbonFluxes.containsKey(previousLandCover)) { carbonFluxes.get(previousLandCover).put(newLandCover, carbonFlux); } else { - Map<LandCoverType, Double> cfMap = new HashMap<LandCoverType, Double>(); + Map<GamsLandCoverType, Double> cfMap = new HashMap<GamsLandCoverType, Double>(); cfMap.put(newLandCover, carbonFlux); carbonFluxes.put(previousLandCover, cfMap); } } - public double getCarbonFlux(LandCoverType previousLandCover, LandCoverType newLandCover) { + public double getCarbonFlux(GamsLandCoverType previousLandCover, GamsLandCoverType newLandCover) { return carbonFluxes.get(previousLandCover).get(newLandCover); } - public boolean checkForKeys(LandCoverType previousLandCover, LandCoverType newLandCover) { + public boolean checkForKeys(GamsLandCoverType previousLandCover, GamsLandCoverType newLandCover) { if (carbonFluxes.containsKey(previousLandCover)) { if (carbonFluxes.get(previousLandCover).containsKey(newLandCover)) { return true; @@ -36,7 +36,7 @@ public class CarbonFluxItem implements RasterItem { } } - public Map<LandCoverType, Map<LandCoverType, Double>> getCarbonFluxes() { + public Map<GamsLandCoverType, Map<GamsLandCoverType, Double>> getCarbonFluxes() { return carbonFluxes; } diff --git a/src/ac/ed/lurg/landuse/CarbonFluxReader.java b/src/ac/ed/lurg/landuse/CarbonFluxReader.java index b79d5e933bca64cd0d6c20ff0ee6d02b12f17ce8..b07f14a376d0f88f0da259f6083dbff5e3bb5dbd 100644 --- a/src/ac/ed/lurg/landuse/CarbonFluxReader.java +++ b/src/ac/ed/lurg/landuse/CarbonFluxReader.java @@ -2,7 +2,7 @@ package ac.ed.lurg.landuse; import java.util.Map; -import ac.ed.lurg.types.LandCoverType; +import ac.ed.lurg.types.GamsLandCoverType; import ac.sac.raster.AbstractTabularRasterReader; import ac.sac.raster.RasterKey; import ac.sac.raster.RasterSet; @@ -10,6 +10,7 @@ import ac.sac.raster.RasterSet; public class CarbonFluxReader extends AbstractTabularRasterReader<CarbonFluxItem> { private static final int MIN_COLS = 27; + private static final double conversionFactor = 10; // convert kgC/m2 to MtC/Mha public CarbonFluxReader(RasterSet<CarbonFluxItem> carbonFluxes) { super("[ |\t]+", MIN_COLS, carbonFluxes); @@ -17,35 +18,35 @@ public class CarbonFluxReader extends AbstractTabularRasterReader<CarbonFluxItem @Override protected void setData(RasterKey key, CarbonFluxItem item, Map<String, Double> rowValues) { - item.setCarbonFlux(LandCoverType.CROPLAND, LandCoverType.NATURAL, getValueForCol(rowValues, "crop_to_ntrl")); - item.setCarbonFlux(LandCoverType.CROPLAND, LandCoverType.TIMBER_FOREST, getValueForCol(rowValues, "crop_to_forT")); - item.setCarbonFlux(LandCoverType.CROPLAND, LandCoverType.CARBON_FOREST, getValueForCol(rowValues, "crop_to_forC")); - item.setCarbonFlux(LandCoverType.CROPLAND, LandCoverType.PASTURE, getValueForCol(rowValues, "crop_to_past")); - item.setCarbonFlux(LandCoverType.CROPLAND, LandCoverType.CROPLAND, getValueForCol(rowValues, "crop_to_crop")); + item.setCarbonFlux(GamsLandCoverType.CROPLAND, GamsLandCoverType.NATURAL, getValueForCol(rowValues, "crop_to_ntrl") * conversionFactor); + item.setCarbonFlux(GamsLandCoverType.CROPLAND, GamsLandCoverType.TIMBER_FOREST, getValueForCol(rowValues, "crop_to_forT") * conversionFactor); + item.setCarbonFlux(GamsLandCoverType.CROPLAND, GamsLandCoverType.CARBON_FOREST, getValueForCol(rowValues, "crop_to_forC") * conversionFactor); + item.setCarbonFlux(GamsLandCoverType.CROPLAND, GamsLandCoverType.PASTURE, getValueForCol(rowValues, "crop_to_past") * conversionFactor); + item.setCarbonFlux(GamsLandCoverType.CROPLAND, GamsLandCoverType.CROPLAND, getValueForCol(rowValues, "crop_to_crop") * conversionFactor); + + item.setCarbonFlux(GamsLandCoverType.PASTURE, GamsLandCoverType.NATURAL, getValueForCol(rowValues, "past_to_ntrl") * conversionFactor); + item.setCarbonFlux(GamsLandCoverType.PASTURE, GamsLandCoverType.TIMBER_FOREST, getValueForCol(rowValues, "past_to_forT") * conversionFactor); + item.setCarbonFlux(GamsLandCoverType.PASTURE, GamsLandCoverType.CARBON_FOREST, getValueForCol(rowValues, "past_to_forC") * conversionFactor); + item.setCarbonFlux(GamsLandCoverType.PASTURE, GamsLandCoverType.CROPLAND, getValueForCol(rowValues, "past_to_crop") * conversionFactor); + item.setCarbonFlux(GamsLandCoverType.PASTURE, GamsLandCoverType.PASTURE, getValueForCol(rowValues, "past_to_past") * conversionFactor); - item.setCarbonFlux(LandCoverType.PASTURE, LandCoverType.NATURAL, getValueForCol(rowValues, "past_to_ntrl")); - item.setCarbonFlux(LandCoverType.PASTURE, LandCoverType.TIMBER_FOREST, getValueForCol(rowValues, "past_to_forT")); - item.setCarbonFlux(LandCoverType.PASTURE, LandCoverType.CARBON_FOREST, getValueForCol(rowValues, "past_to_forC")); - item.setCarbonFlux(LandCoverType.PASTURE, LandCoverType.CROPLAND, getValueForCol(rowValues, "past_to_crop")); - item.setCarbonFlux(LandCoverType.PASTURE, LandCoverType.PASTURE, getValueForCol(rowValues, "past_to_past")); + item.setCarbonFlux(GamsLandCoverType.NATURAL, GamsLandCoverType.PASTURE, getValueForCol(rowValues, "ntrl_to_past") * conversionFactor); + item.setCarbonFlux(GamsLandCoverType.NATURAL, GamsLandCoverType.TIMBER_FOREST, getValueForCol(rowValues, "ntrl_to_forT") * conversionFactor); + item.setCarbonFlux(GamsLandCoverType.NATURAL, GamsLandCoverType.CARBON_FOREST, getValueForCol(rowValues, "ntrl_to_forC") * conversionFactor); + item.setCarbonFlux(GamsLandCoverType.NATURAL, GamsLandCoverType.CROPLAND, getValueForCol(rowValues, "ntrl_to_crop") * conversionFactor); + item.setCarbonFlux(GamsLandCoverType.NATURAL, GamsLandCoverType.NATURAL, getValueForCol(rowValues, "ntrl_to_ntrl") * conversionFactor); - item.setCarbonFlux(LandCoverType.NATURAL, LandCoverType.PASTURE, getValueForCol(rowValues, "ntrl_to_past")); - item.setCarbonFlux(LandCoverType.NATURAL, LandCoverType.TIMBER_FOREST, getValueForCol(rowValues, "ntrl_to_forT")); - item.setCarbonFlux(LandCoverType.NATURAL, LandCoverType.CARBON_FOREST, getValueForCol(rowValues, "ntrl_to_forC")); - item.setCarbonFlux(LandCoverType.NATURAL, LandCoverType.CROPLAND, getValueForCol(rowValues, "ntrl_to_crop")); - item.setCarbonFlux(LandCoverType.NATURAL, LandCoverType.NATURAL, getValueForCol(rowValues, "ntrl_to_ntrl")); - - item.setCarbonFlux(LandCoverType.TIMBER_FOREST, LandCoverType.PASTURE, getValueForCol(rowValues, "forT_to_past")); - item.setCarbonFlux(LandCoverType.TIMBER_FOREST, LandCoverType.NATURAL, getValueForCol(rowValues, "forT_to_ntrl")); - item.setCarbonFlux(LandCoverType.TIMBER_FOREST, LandCoverType.CARBON_FOREST, getValueForCol(rowValues, "forT_to_forC")); - item.setCarbonFlux(LandCoverType.TIMBER_FOREST, LandCoverType.CROPLAND, getValueForCol(rowValues, "forT_to_crop")); - item.setCarbonFlux(LandCoverType.TIMBER_FOREST, LandCoverType.TIMBER_FOREST, getValueForCol(rowValues, "forT_to_forT")); - - item.setCarbonFlux(LandCoverType.CARBON_FOREST, LandCoverType.PASTURE, getValueForCol(rowValues, "forC_to_past")); - item.setCarbonFlux(LandCoverType.CARBON_FOREST, LandCoverType.NATURAL, getValueForCol(rowValues, "forC_to_ntrl")); - item.setCarbonFlux(LandCoverType.CARBON_FOREST, LandCoverType.TIMBER_FOREST, getValueForCol(rowValues, "forC_to_forT")); - item.setCarbonFlux(LandCoverType.CARBON_FOREST, LandCoverType.CROPLAND, getValueForCol(rowValues, "forC_to_crop")); - item.setCarbonFlux(LandCoverType.CARBON_FOREST, LandCoverType.CARBON_FOREST, getValueForCol(rowValues, "forC_to_forC")); + item.setCarbonFlux(GamsLandCoverType.TIMBER_FOREST, GamsLandCoverType.PASTURE, getValueForCol(rowValues, "forT_to_past") * conversionFactor); + item.setCarbonFlux(GamsLandCoverType.TIMBER_FOREST, GamsLandCoverType.NATURAL, getValueForCol(rowValues, "forT_to_ntrl") * conversionFactor); + item.setCarbonFlux(GamsLandCoverType.TIMBER_FOREST, GamsLandCoverType.CARBON_FOREST, getValueForCol(rowValues, "forT_to_forC") * conversionFactor); + item.setCarbonFlux(GamsLandCoverType.TIMBER_FOREST, GamsLandCoverType.CROPLAND, getValueForCol(rowValues, "forT_to_crop") * conversionFactor); + item.setCarbonFlux(GamsLandCoverType.TIMBER_FOREST, GamsLandCoverType.TIMBER_FOREST, getValueForCol(rowValues, "forT_to_forT") * conversionFactor); + + item.setCarbonFlux(GamsLandCoverType.CARBON_FOREST, GamsLandCoverType.PASTURE, getValueForCol(rowValues, "forC_to_past") * conversionFactor); + item.setCarbonFlux(GamsLandCoverType.CARBON_FOREST, GamsLandCoverType.NATURAL, getValueForCol(rowValues, "forC_to_ntrl") * conversionFactor); + item.setCarbonFlux(GamsLandCoverType.CARBON_FOREST, GamsLandCoverType.TIMBER_FOREST, getValueForCol(rowValues, "forC_to_forT") * conversionFactor); + item.setCarbonFlux(GamsLandCoverType.CARBON_FOREST, GamsLandCoverType.CROPLAND, getValueForCol(rowValues, "forC_to_crop") * conversionFactor); + item.setCarbonFlux(GamsLandCoverType.CARBON_FOREST, GamsLandCoverType.CARBON_FOREST, getValueForCol(rowValues, "forC_to_forC") * conversionFactor); } diff --git a/src/ac/ed/lurg/landuse/LandCoverChangeItem.java b/src/ac/ed/lurg/landuse/LandCoverChangeItem.java new file mode 100644 index 0000000000000000000000000000000000000000..cdde2f6e8e10c07cd7fb32c030f30a1fd430848d --- /dev/null +++ b/src/ac/ed/lurg/landuse/LandCoverChangeItem.java @@ -0,0 +1,46 @@ +package ac.ed.lurg.landuse; + +import java.util.HashMap; +import java.util.Map; + +import ac.ed.lurg.types.LandCoverType; + +public class LandCoverChangeItem { + private Map<Integer, Map<LandCoverType, Map<LandCoverType, Double>>> landCoverChange = new HashMap<Integer, Map<LandCoverType, Map<LandCoverType, Double>>>(); + + public LandCoverChangeItem() {} + + public void setLandCoverChange(LandCoverType fromLC, LandCoverType toLC, Integer locId, double change) { + + if (landCoverChange.containsKey(locId)) { + Map<LandCoverType, Map<LandCoverType, Double>> locMap = landCoverChange.get(locId); + + if (locMap.containsKey(fromLC)) { + locMap.get(fromLC).put(toLC, change); + } + else { + Map<LandCoverType, Double> toMap = new HashMap<LandCoverType, Double>(); + toMap.put(toLC, change); + + landCoverChange.get(locId).put(fromLC, toMap); + } + } + else { + Map<LandCoverType, Double> toMap = new HashMap<LandCoverType, Double>(); + toMap.put(toLC, change); + + Map<LandCoverType, Map<LandCoverType, Double>> fromMap = new HashMap<LandCoverType, Map<LandCoverType, Double>>(); + fromMap.put(fromLC, toMap); + + landCoverChange.put(locId, fromMap); + } + } + + public double getLandCoverChange(LandCoverType fromLC, LandCoverType toLC, Integer locId) { + return landCoverChange.get(locId).get(fromLC).get(toLC); + } + + public Map<LandCoverType, Map<LandCoverType, Double>> getLandCoverChangeForLocation(Integer locId) { + return landCoverChange.get(locId); + } +} diff --git a/src/ac/ed/lurg/landuse/LandCoverReader.java b/src/ac/ed/lurg/landuse/LandCoverReader.java index 520dff75b5fb5c21e9f1eda933e8d3249e4c936a..66bbfc5ca0483478ee77fb56f6d377d4effb58f3 100644 --- a/src/ac/ed/lurg/landuse/LandCoverReader.java +++ b/src/ac/ed/lurg/landuse/LandCoverReader.java @@ -23,7 +23,8 @@ public class LandCoverReader extends AbstractTabularRasterReader<LandCoverItem> lcData.setLandCoverFract(LandCoverType.CROPLAND, getValueForCol(rowValues, "cropland")); lcData.setLandCoverFract(LandCoverType.PASTURE, getValueForCol(rowValues, "pasture")); lcData.setLandCoverFract(LandCoverType.OTHER_NATURAL, getValueForCol(rowValues, "natural")); - lcData.setLandCoverFract(LandCoverType.MANAGED_FOREST, getValueForCol(rowValues, "managed_forest")); + lcData.setLandCoverFract(LandCoverType.TIMBER_FOREST, getValueForCol(rowValues, "managed_forest")); + lcData.setLandCoverFract(LandCoverType.CARBON_FOREST, 0.0); // TODO custom initial timber/carbon forest allocation lcData.setLandCoverFract(LandCoverType.UNMANAGED_FOREST, getValueForCol(rowValues, "unmanaged_forest")); lcData.setLandCoverFract(LandCoverType.BARREN, getValueForCol(rowValues, "barren")); lcData.setLandCoverFract(LandCoverType.URBAN, getValueForCol(rowValues, "urban")); diff --git a/src/ac/ed/lurg/landuse/LandUseItem.java b/src/ac/ed/lurg/landuse/LandUseItem.java index ad974d34bde721d509f180667b5580c2a7e97c47..f6774523f6f5c2082b5512e23dae52df8e5fab92 100644 --- a/src/ac/ed/lurg/landuse/LandUseItem.java +++ b/src/ac/ed/lurg/landuse/LandUseItem.java @@ -30,11 +30,7 @@ public class LandUseItem implements InterpolatingRasterItem<LandUseItem>, Serial this(); if (landCover != null) { for (LandCoverType lcType : LandCoverType.values()) - landCoverAreas.put(lcType, landCover.getLandCoverArea(lcType)); - - landCoverAreas.put(LandCoverType.TIMBER_FOREST, landCover.getLandCoverArea(LandCoverType.MANAGED_FOREST)); - landCoverAreas.put(LandCoverType.CARBON_FOREST, 0.0); - landCoverAreas.put(LandCoverType.NATURAL, landCover.getLandCoverArea(LandCoverType.OTHER_NATURAL) + landCover.getLandCoverArea(LandCoverType.UNMANAGED_FOREST)); + landCoverAreas.put(lcType, landCover.getLandCoverArea(lcType)); // Converts land cover fractions to areas setCropFraction(CropType.WHEAT, 0.5); // random start as don't have better data setCropFraction(CropType.MAIZE, 0.5); @@ -254,7 +250,7 @@ public class LandUseItem implements InterpolatingRasterItem<LandUseItem>, Serial public double getTotalLandCoverArea() { double d = 0; - for (LandCoverType l : LandCoverType.getLuhTypes()) + for (LandCoverType l : LandCoverType.values()) d += getLandCoverArea(l); return d; @@ -285,13 +281,13 @@ public class LandUseItem implements InterpolatingRasterItem<LandUseItem>, Serial } public double getTotalNatural() { - double totalNatural = getLandCoverArea(LandCoverType.OTHER_NATURAL) + getLandCoverArea(LandCoverType.MANAGED_FOREST) + getLandCoverArea(LandCoverType.UNMANAGED_FOREST); + double totalNatural = getLandCoverArea(LandCoverType.OTHER_NATURAL) + getLandCoverArea(LandCoverType.TIMBER_FOREST) + getLandCoverArea(LandCoverType.CARBON_FOREST) + getLandCoverArea(LandCoverType.UNMANAGED_FOREST); return totalNatural; } public double getTotalUnprotectedNatural() { double unprotectedNatural = 0; - for (LandCoverType landType : LandCoverType.getLuhTypes()) { + for (LandCoverType landType : LandCoverType.values()) { if (landType.isProtectable()) { unprotectedNatural += unprotectedAreas.get(landType); } @@ -352,7 +348,7 @@ public class LandUseItem implements InterpolatingRasterItem<LandUseItem>, Serial } public double getForestManagedFraction() { - double managed = getLandCoverArea(LandCoverType.MANAGED_FOREST); + double managed = getLandCoverArea(LandCoverType.TIMBER_FOREST) + getLandCoverArea(LandCoverType.CARBON_FOREST); double unmanaged = getLandCoverArea(LandCoverType.UNMANAGED_FOREST); double d = managed / (managed + unmanaged); return (Double.isNaN(d) || Double.isInfinite(d)) ? 1.0 : d; diff --git a/src/ac/ed/lurg/landuse/WoodYieldItem.java b/src/ac/ed/lurg/landuse/WoodYieldItem.java index 3da2875900ce54598fe1ee17c7d82b09491d24e9..6c5f9473ff527a298f173274c35a4ec6c760cbcf 100644 --- a/src/ac/ed/lurg/landuse/WoodYieldItem.java +++ b/src/ac/ed/lurg/landuse/WoodYieldItem.java @@ -3,27 +3,27 @@ package ac.ed.lurg.landuse; import java.util.HashMap; import java.util.Map; -import ac.ed.lurg.types.LandCoverType; +import ac.ed.lurg.types.GamsLandCoverType; import ac.sac.raster.RasterItem; public class WoodYieldItem implements RasterItem { - Map<LandCoverType, Map<LandCoverType, Double>> woodYields = new HashMap<LandCoverType, Map<LandCoverType, Double>>(); + Map<GamsLandCoverType, Map<GamsLandCoverType, Double>> woodYields = new HashMap<GamsLandCoverType, Map<GamsLandCoverType, Double>>(); - public void setWoodYield(LandCoverType previousLandCover, LandCoverType newLandCover, double woodYield) { + public void setWoodYield(GamsLandCoverType previousLandCover, GamsLandCoverType newLandCover, double woodYield) { if (woodYields.containsKey(previousLandCover)) { woodYields.get(previousLandCover).put(newLandCover, woodYield); } else { - Map<LandCoverType, Double> cfMap = new HashMap<LandCoverType, Double>(); + Map<GamsLandCoverType, Double> cfMap = new HashMap<GamsLandCoverType, Double>(); cfMap.put(newLandCover, woodYield); woodYields.put(previousLandCover, cfMap); } } - public double getWoodYield(LandCoverType previousLandCover, LandCoverType newLandCover) { + public double getWoodYield(GamsLandCoverType previousLandCover, GamsLandCoverType newLandCover) { return woodYields.get(previousLandCover).get(newLandCover); } - public boolean checkForKeys(LandCoverType previousLandCover, LandCoverType newLandCover) { + public boolean checkForKeys(GamsLandCoverType previousLandCover, GamsLandCoverType newLandCover) { if (woodYields.containsKey(previousLandCover)) { if (woodYields.get(previousLandCover).containsKey(newLandCover)) { return true; diff --git a/src/ac/ed/lurg/landuse/WoodYieldReader.java b/src/ac/ed/lurg/landuse/WoodYieldReader.java index 7c693c54036a4cfaf3dcece71f3f9bbe0068f360..eb8c5aee67e6efdb2fef71714e188f1d3f70179d 100644 --- a/src/ac/ed/lurg/landuse/WoodYieldReader.java +++ b/src/ac/ed/lurg/landuse/WoodYieldReader.java @@ -2,7 +2,7 @@ package ac.ed.lurg.landuse; import java.util.Map; -import ac.ed.lurg.types.LandCoverType; +import ac.ed.lurg.types.GamsLandCoverType; import ac.sac.raster.AbstractTabularRasterReader; import ac.sac.raster.RasterKey; import ac.sac.raster.RasterSet; @@ -10,41 +10,42 @@ import ac.sac.raster.RasterSet; public class WoodYieldReader extends AbstractTabularRasterReader<WoodYieldItem> { private static final int MIN_COLS = 27; + private static final double conversionFactor = 10.0; // convert kgC/m2 to MtC/Mha public WoodYieldReader(RasterSet<WoodYieldItem> woodYield) { super("[ |\t]+", MIN_COLS, woodYield); } protected void setData(RasterKey key, WoodYieldItem item, Map<String, Double> rowValues) { - item.setWoodYield(LandCoverType.CROPLAND, LandCoverType.NATURAL, getValueForCol(rowValues, "crop_to_ntrl")); - item.setWoodYield(LandCoverType.CROPLAND, LandCoverType.TIMBER_FOREST, getValueForCol(rowValues, "crop_to_forT")); - item.setWoodYield(LandCoverType.CROPLAND, LandCoverType.CARBON_FOREST, getValueForCol(rowValues, "crop_to_forC")); - item.setWoodYield(LandCoverType.CROPLAND, LandCoverType.PASTURE, getValueForCol(rowValues, "crop_to_past")); - item.setWoodYield(LandCoverType.CROPLAND, LandCoverType.CROPLAND, getValueForCol(rowValues, "crop_to_crop")); + item.setWoodYield(GamsLandCoverType.CROPLAND, GamsLandCoverType.NATURAL, getValueForCol(rowValues, "crop_to_ntrl") * conversionFactor); + item.setWoodYield(GamsLandCoverType.CROPLAND, GamsLandCoverType.TIMBER_FOREST, getValueForCol(rowValues, "crop_to_forT") * conversionFactor); + item.setWoodYield(GamsLandCoverType.CROPLAND, GamsLandCoverType.CARBON_FOREST, getValueForCol(rowValues, "crop_to_forC") * conversionFactor); + item.setWoodYield(GamsLandCoverType.CROPLAND, GamsLandCoverType.PASTURE, getValueForCol(rowValues, "crop_to_past") * conversionFactor); + item.setWoodYield(GamsLandCoverType.CROPLAND, GamsLandCoverType.CROPLAND, getValueForCol(rowValues, "crop_to_crop") * conversionFactor); - item.setWoodYield(LandCoverType.PASTURE, LandCoverType.NATURAL, getValueForCol(rowValues, "past_to_ntrl")); - item.setWoodYield(LandCoverType.PASTURE, LandCoverType.TIMBER_FOREST, getValueForCol(rowValues, "past_to_forT")); - item.setWoodYield(LandCoverType.PASTURE, LandCoverType.CARBON_FOREST, getValueForCol(rowValues, "past_to_forC")); - item.setWoodYield(LandCoverType.PASTURE, LandCoverType.CROPLAND, getValueForCol(rowValues, "past_to_crop")); - item.setWoodYield(LandCoverType.PASTURE, LandCoverType.PASTURE, getValueForCol(rowValues, "past_to_past")); + item.setWoodYield(GamsLandCoverType.PASTURE, GamsLandCoverType.NATURAL, getValueForCol(rowValues, "past_to_ntrl") * conversionFactor); + item.setWoodYield(GamsLandCoverType.PASTURE, GamsLandCoverType.TIMBER_FOREST, getValueForCol(rowValues, "past_to_forT") * conversionFactor); + item.setWoodYield(GamsLandCoverType.PASTURE, GamsLandCoverType.CARBON_FOREST, getValueForCol(rowValues, "past_to_forC") * conversionFactor); + item.setWoodYield(GamsLandCoverType.PASTURE, GamsLandCoverType.CROPLAND, getValueForCol(rowValues, "past_to_crop") * conversionFactor); + item.setWoodYield(GamsLandCoverType.PASTURE, GamsLandCoverType.PASTURE, getValueForCol(rowValues, "past_to_past") * conversionFactor); - item.setWoodYield(LandCoverType.NATURAL, LandCoverType.PASTURE, getValueForCol(rowValues, "ntrl_to_past")); - item.setWoodYield(LandCoverType.NATURAL, LandCoverType.TIMBER_FOREST, getValueForCol(rowValues, "ntrl_to_forT")); - item.setWoodYield(LandCoverType.NATURAL, LandCoverType.CARBON_FOREST, getValueForCol(rowValues, "ntrl_to_forC")); - item.setWoodYield(LandCoverType.NATURAL, LandCoverType.CROPLAND, getValueForCol(rowValues, "ntrl_to_crop")); - item.setWoodYield(LandCoverType.NATURAL, LandCoverType.NATURAL, getValueForCol(rowValues, "ntrl_to_ntrl")); + item.setWoodYield(GamsLandCoverType.NATURAL, GamsLandCoverType.PASTURE, getValueForCol(rowValues, "ntrl_to_past") * conversionFactor); + item.setWoodYield(GamsLandCoverType.NATURAL, GamsLandCoverType.TIMBER_FOREST, getValueForCol(rowValues, "ntrl_to_forT") * conversionFactor); + item.setWoodYield(GamsLandCoverType.NATURAL, GamsLandCoverType.CARBON_FOREST, getValueForCol(rowValues, "ntrl_to_forC") * conversionFactor); + item.setWoodYield(GamsLandCoverType.NATURAL, GamsLandCoverType.CROPLAND, getValueForCol(rowValues, "ntrl_to_crop") * conversionFactor); + item.setWoodYield(GamsLandCoverType.NATURAL, GamsLandCoverType.NATURAL, getValueForCol(rowValues, "ntrl_to_ntrl") * conversionFactor); - item.setWoodYield(LandCoverType.TIMBER_FOREST, LandCoverType.PASTURE, getValueForCol(rowValues, "forT_to_past")); - item.setWoodYield(LandCoverType.TIMBER_FOREST, LandCoverType.NATURAL, getValueForCol(rowValues, "forT_to_ntrl")); - item.setWoodYield(LandCoverType.TIMBER_FOREST, LandCoverType.CARBON_FOREST, getValueForCol(rowValues, "forT_to_forC")); - item.setWoodYield(LandCoverType.TIMBER_FOREST, LandCoverType.CROPLAND, getValueForCol(rowValues, "forT_to_crop")); - item.setWoodYield(LandCoverType.TIMBER_FOREST, LandCoverType.TIMBER_FOREST, getValueForCol(rowValues, "forT_to_forT")); + item.setWoodYield(GamsLandCoverType.TIMBER_FOREST, GamsLandCoverType.PASTURE, getValueForCol(rowValues, "forT_to_past") * conversionFactor); + item.setWoodYield(GamsLandCoverType.TIMBER_FOREST, GamsLandCoverType.NATURAL, getValueForCol(rowValues, "forT_to_ntrl") * conversionFactor); + item.setWoodYield(GamsLandCoverType.TIMBER_FOREST, GamsLandCoverType.CARBON_FOREST, getValueForCol(rowValues, "forT_to_forC") * conversionFactor); + item.setWoodYield(GamsLandCoverType.TIMBER_FOREST, GamsLandCoverType.CROPLAND, getValueForCol(rowValues, "forT_to_crop") * conversionFactor); + item.setWoodYield(GamsLandCoverType.TIMBER_FOREST, GamsLandCoverType.TIMBER_FOREST, getValueForCol(rowValues, "forT_to_forT") * conversionFactor); - item.setWoodYield(LandCoverType.CARBON_FOREST, LandCoverType.PASTURE, getValueForCol(rowValues, "forC_to_past")); - item.setWoodYield(LandCoverType.CARBON_FOREST, LandCoverType.NATURAL, getValueForCol(rowValues, "forC_to_ntrl")); - item.setWoodYield(LandCoverType.CARBON_FOREST, LandCoverType.TIMBER_FOREST, getValueForCol(rowValues, "forC_to_forT")); - item.setWoodYield(LandCoverType.CARBON_FOREST, LandCoverType.CROPLAND, getValueForCol(rowValues, "forC_to_crop")); - item.setWoodYield(LandCoverType.CARBON_FOREST, LandCoverType.CARBON_FOREST, getValueForCol(rowValues, "forC_to_forC")); + item.setWoodYield(GamsLandCoverType.CARBON_FOREST, GamsLandCoverType.PASTURE, getValueForCol(rowValues, "forC_to_past") * conversionFactor); + item.setWoodYield(GamsLandCoverType.CARBON_FOREST, GamsLandCoverType.NATURAL, getValueForCol(rowValues, "forC_to_ntrl") * conversionFactor); + item.setWoodYield(GamsLandCoverType.CARBON_FOREST, GamsLandCoverType.TIMBER_FOREST, getValueForCol(rowValues, "forC_to_forT") * conversionFactor); + item.setWoodYield(GamsLandCoverType.CARBON_FOREST, GamsLandCoverType.CROPLAND, getValueForCol(rowValues, "forC_to_crop") * conversionFactor); + item.setWoodYield(GamsLandCoverType.CARBON_FOREST, GamsLandCoverType.CARBON_FOREST, getValueForCol(rowValues, "forC_to_forC") * conversionFactor); } } diff --git a/src/ac/ed/lurg/output/LpjgOutputer.java b/src/ac/ed/lurg/output/LpjgOutputer.java index 35e23308e4572b31481471ce44fec3c49f9f0e7f..5ba5f785f1d232c49ebfad835ff38d3565f6bfeb 100644 --- a/src/ac/ed/lurg/output/LpjgOutputer.java +++ b/src/ac/ed/lurg/output/LpjgOutputer.java @@ -143,7 +143,7 @@ public class LpjgOutputer extends AbstractLandUseOutputer { double crop = item.getLandCoverFract(LandCoverType.CROPLAND); double pasture = item.getLandCoverFract(LandCoverType.PASTURE); - double forest = item.getLandCoverFract(LandCoverType.MANAGED_FOREST) + item.getLandCoverFract(LandCoverType.UNMANAGED_FOREST); + double forest = item.getLandCoverFract(LandCoverType.TIMBER_FOREST) + item.getLandCoverFract(LandCoverType.CARBON_FOREST) + item.getLandCoverFract(LandCoverType.UNMANAGED_FOREST); double otherNatural = item.getLandCoverFract(LandCoverType.OTHER_NATURAL); double barren = item.getLandCoverFract(LandCoverType.BARREN); double urban = item.getLandCoverFract(LandCoverType.URBAN); @@ -192,10 +192,11 @@ public class LpjgOutputer extends AbstractLandUseOutputer { double pasture = item.getLandCoverFract(LandCoverType.PASTURE); double timberForest = item.getLandCoverFract(LandCoverType.TIMBER_FOREST); double carbonForest = item.getLandCoverFract(LandCoverType.CARBON_FOREST); - double natural = item.getLandCoverFract(LandCoverType.NATURAL); + double unmanagedForest = item.getLandCoverFract(LandCoverType.UNMANAGED_FOREST); + double natural = item.getLandCoverFract(LandCoverType.OTHER_NATURAL); double barren = item.getLandCoverFract(LandCoverType.BARREN); double urban = item.getLandCoverFract(LandCoverType.URBAN); - landCoverWriter.write(String.format("%.2f %.2f %d %.14f %.14f %.14f %.14f %.14f %.14f %.14f", lat, lon, year, crop, pasture, timberForest, carbonForest, natural, barren, urban)); + landCoverWriter.write(String.format("%.2f %.2f %d %.14f %.14f %.14f %.14f %.14f %.14f %.14f %.14f", lat, lon, year, crop, pasture, timberForest, carbonForest, unmanagedForest, natural, barren, urban)); landCoverWriter.newLine(); } } diff --git a/src/ac/ed/lurg/types/GamsLandCoverType.java b/src/ac/ed/lurg/types/GamsLandCoverType.java index a986955b476df342b49c309a6c038ecde67caf66..d656e10b2d8087b137e1ecf2063c29afaf46c8b2 100644 --- a/src/ac/ed/lurg/types/GamsLandCoverType.java +++ b/src/ac/ed/lurg/types/GamsLandCoverType.java @@ -8,7 +8,7 @@ import ac.ed.lurg.utils.LogWriter; public enum GamsLandCoverType { TIMBER_FOREST("timberForest"), CARBON_FOREST("carbonForest"), - OTHER_NATURAL("otherNatural"), + NATURAL("natural"), PASTURE("pasture"), CROPLAND("cropland"); diff --git a/src/ac/ed/lurg/types/LandCoverType.java b/src/ac/ed/lurg/types/LandCoverType.java index 64eb252de701ce00bbe7607430bc0b3ba295449b..47c1563360ac3c5321c0bccbc8f9f70169da7a81 100644 --- a/src/ac/ed/lurg/types/LandCoverType.java +++ b/src/ac/ed/lurg/types/LandCoverType.java @@ -9,25 +9,23 @@ import ac.ed.lurg.utils.LogWriter; public enum LandCoverType { - MANAGED_FOREST ("managedForest", true, false), // This is TIMBER_FOREST + CARBON_FOREST - UNMANAGED_FOREST ("unmanagedForest", true, false), - OTHER_NATURAL ("otherNatural", true, false), + TIMBER_FOREST("timberForest", true, true), + CARBON_FOREST("carbonForest", true, true), + UNMANAGED_FOREST ("unmanagedForest", true, true), + OTHER_NATURAL ("otherNatural", true, true), CROPLAND ("cropland", false, true), PASTURE ("pasture", false, true), BARREN ("barren", false, false), - URBAN("urban", false, false), - TIMBER_FOREST("timberForest", true, true), - CARBON_FOREST("carbonForest", true, true), - NATURAL("natural", true, true); // This is OTHER_NATURAL + UNMANAGED_FOREST + URBAN("urban", false, false); private String name; private boolean isProtectable; - private boolean isGamsType; + private boolean isConvertible; - LandCoverType(String name, boolean isProtectable, boolean isGamsType) { + LandCoverType(String name, boolean isProtectable, boolean isConvertible) { this.name = name; this.isProtectable = isProtectable; - this.isGamsType = isGamsType; + this.isConvertible = isConvertible; } public String getName() { @@ -55,27 +53,16 @@ public enum LandCoverType { return type; } - public static Collection<LandCoverType> getLuhTypes() { - - Collection<LandCoverType> luhTypes = new HashSet<LandCoverType>(); - - for (LandCoverType c : values()) - if (!c.isGamsType) - luhTypes.add(c); - - return luhTypes; - - } - public static Collection<LandCoverType> getGamsTypes() { + public static Collection<LandCoverType> getConvertibleTypes() { - Collection<LandCoverType> gamsTypes = new HashSet<LandCoverType>(); + Collection<LandCoverType> convertibleTypes = new HashSet<LandCoverType>(); for (LandCoverType c : values()) - if (c.isGamsType) - gamsTypes.add(c); + if (c.isConvertible) + convertibleTypes.add(c); - return gamsTypes; + return convertibleTypes; } }