Skip to content
Snippets Groups Projects
Commit fccbbaa0 authored by Bart Arendarczyk's avatar Bart Arendarczyk
Browse files

Fixed issue with new forest area additions.

parent a7fd4a7c
No related branches found
No related tags found
No related merge requests found
......@@ -67,6 +67,7 @@ public class ForestManager {
//LogWriter.println(key.toString());
WoodYieldItem wYItem = initWoodYieldData.get(key);
double timberYieldThisTime;
// TODO Assuming forest was pasture before
timberYieldThisTime = (wYItem != null) ? initWoodYieldData.get(key).getWoodYield(LandCoverType.PASTURE, LandCoverType.TIMBER_FOREST) : 0.0;
unmanagedForestArea.put(clusterId, unmanagedForestAreaSoFar + luItem.getInitialForestedNaturalArea());
......@@ -89,21 +90,33 @@ public class ForestManager {
int forestPseudoYear = ModelConfig.BASE_YEAR - ModelConfig.FOREST_LOCKIN_PERIOD;
for (Entry<Integer, Double> entry : unmanagedForestArea.entrySet()) {
addForestRecord(new ForestRecord(forestPseudoYear, entry.getKey(), LandCoverType.NATURAL, entry.getValue(), 0));
if (entry.getValue() > 0)
addForestRecord(new ForestRecord(forestPseudoYear, entry.getKey(), LandCoverType.NATURAL, entry.getValue(), 0));
}
for (Entry<Integer, Double> entry : otherNaturalArea.entrySet()) {
addForestRecord(new ForestRecord(otherNaturalPseudoYear, entry.getKey(), LandCoverType.NATURAL, entry.getValue(), 0));
if (entry.getValue() > 0)
addForestRecord(new ForestRecord(otherNaturalPseudoYear, entry.getKey(), LandCoverType.NATURAL, entry.getValue(), 0));
}
for (Entry<Integer, Double> entry : timberForestArea.entrySet()) {
int clusterId = entry.getKey();
double area = entry.getValue();
double timberYield = (area > 0) ? timberYieldTimesArea.get(clusterId) / area : 0.0;
addForestRecord(new ForestRecord(forestPseudoYear, entry.getKey(), LandCoverType.TIMBER_FOREST, area, timberYield));
if (area > 0) {
double timberYield = timberYieldTimesArea.get(clusterId) / area;
addForestRecord(new ForestRecord(forestPseudoYear, clusterId, LandCoverType.TIMBER_FOREST, area, timberYield));
}
}
/*
for (ForestRecord record: forestHistory) {
LogWriter.println(""+record.getLocation()+","+record.getYearPlanted()+","+record.getForestType()+","+record.getArea());
}
LogWriter.print("foo");
*/
}
// Area of forest not fully grown
public DoubleMap<Integer, LandCoverType, Double> getReservedAreaForTimestep(Timestep timestep) {
DoubleMap<Integer, LandCoverType, Double> minimumLandCoverForTimestep = new DoubleMap<Integer, LandCoverType, Double>();
double minYear = timestep.getYear() - ModelConfig.FOREST_LOCKIN_PERIOD;
......@@ -225,6 +238,13 @@ public class ForestManager {
for (ForestRecord item : newForest) {
forestHistory.add(new ForestRecord(yearPlanted, item));
}
/*
for (ForestRecord record: forestHistory) {
LogWriter.println(""+record.getLocation()+","+record.getYearPlanted()+","+record.getForestType()+","+record.getArea()+","+record.getPotentialYield());
}
LogWriter.print("foo");
*/
// Remove deforested area from minimum area requirement
if (reservedDeforested.getMap().isEmpty())
......
......@@ -603,9 +603,11 @@ public class GamsLocationOptimiser {
// Minimum land cover additions. Need to keep track of new forest areas to restrict conversion
// Also keep track of natural areas
List<ForestRecord> newForest = new ArrayList<ForestRecord>();
DoubleMap<Integer, LandCoverType, Double> totalArea = new DoubleMap<Integer, LandCoverType, Double>();
DoubleMap<Integer, LandCoverType, Double> areaTimesYield = new DoubleMap<Integer, LandCoverType, Double>();
for (Entry<Integer, DoubleMap<LandCoverType, LandCoverType, Double>> locMap : landCoverChanges.getMap().entrySet()) {
Integer locId = locMap.getKey();
int locId = locMap.getKey();
DoubleMap<LandCoverType, LandCoverType, Double> changeMap = locMap.getValue();
for (Entry<LandCoverType, Map<LandCoverType, Double>> fromMap : changeMap.getMap().entrySet()) {
LandCoverType fromLC = fromMap.getKey();
......@@ -616,12 +618,26 @@ public class GamsLocationOptimiser {
continue;
Double minArea = inputData.getMinimumLandCover().get(locId, fromLC);
minArea = (minArea == null) ? 0.0 : minArea;
double newForestArea = newArea - minArea;
double newForestArea = newArea - minArea; // subtract unchanged forest area
double woodYield = (toLC.equals(LandCoverType.TIMBER_FOREST)) ? inputData.getWoodYields().get(locId).getWoodYield(fromLC, toLC) : 0.0;
newForest.add(new ForestRecord(locId, toLC, newForestArea, woodYield));
totalArea.addTo(locId, toLC, newForestArea);
areaTimesYield.addTo(locId, toLC, woodYield * newForestArea);
}
}
}
// Calculate weighted average yield
for (Entry<Integer, Map<LandCoverType, Double>> locMap : totalArea.getMap().entrySet()) {
Integer locId = locMap.getKey();
for (Entry<LandCoverType, Double> lcMap : locMap.getValue().entrySet()) {
LandCoverType lcType = lcMap.getKey();
double a = lcMap.getValue();
double ya = areaTimesYield.get(locId, lcType);
double y = ya / a;
newForest.add(new ForestRecord(locId, lcType, a, y));
}
}
// reserved Forest which was deforested
GAMSVariable varReservedDeforested = outDB.getVariable("reservedAreaDeforested");
......
......@@ -188,13 +188,13 @@ public class LpjgOutputer extends AbstractLandUseOutputer {
LogWriter.printlnError("Land cover areas look strange " + key + ": expected=" + expectedArea + ", actual=" + area);
}
double crop = item.getLandCoverFract(LandCoverType.CROPLAND);
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 barren = item.getLandCoverFract(LandCoverType.BARREN);
double urban = item.getLandCoverFract(LandCoverType.URBAN);
double crop = item.getLandCoverArea(LandCoverType.CROPLAND);
double pasture = item.getLandCoverArea(LandCoverType.PASTURE);
double timberForest = item.getLandCoverArea(LandCoverType.TIMBER_FOREST);
double carbonForest = item.getLandCoverArea(LandCoverType.CARBON_FOREST);
double natural = item.getLandCoverArea(LandCoverType.NATURAL);
double barren = item.getLandCoverArea(LandCoverType.BARREN);
double urban = item.getLandCoverArea(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.newLine();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment