Skip to content
Snippets Groups Projects
Commit fec57148 authored by Peter Alexander's avatar Peter Alexander
Browse files

Further changes to PA and clustering

parent 4aa3993d
No related branches found
No related tags found
No related merge requests found
...@@ -75,7 +75,10 @@ public class CountryAgent { ...@@ -75,7 +75,10 @@ public class CountryAgent {
if (yieldresp != null) { if (yieldresp != null) {
RasterKey key = entry.getKey(); RasterKey key = entry.getKey();
IrrigationItem irrigItem = irrigData.get(key); IrrigationItem irrigItem = irrigData.get(key);
clusteringPoints.add(new YieldClusterPoint(key, yieldresp, irrigItem));
LandUseItem luItem = previousGamsRasterOutput.getLandUses().get(key);
double protectedArea = luItem.getProtectedArea();
clusteringPoints.add(new YieldClusterPoint(key, yieldresp, irrigItem, protectedArea));
} }
} }
......
...@@ -76,18 +76,18 @@ public class GamsRasterOptimiser { ...@@ -76,18 +76,18 @@ public class GamsRasterOptimiser {
LogWriter.printlnError("Total Area " + comment + ": " + l.getName() + ": " + total); LogWriter.printlnError("Total Area " + comment + ": " + l.getName() + ": " + total);
} }
double protectedAreaIncMinNatural=0, suitableArea=0, protectedArea=0, unprotectedArea=0; double unprotectedNatural=0, suitableArea=0, protectedArea=0, unprotectedArea=0;
for (LandUseItem a : areaRaster.values()) { for (LandUseItem a : areaRaster.values()) {
if (a != null) { if (a != null) {
protectedArea += a.getProtectedArea(); protectedArea += a.getProtectedArea();
unprotectedArea += a.getUnprotectedArea(); unprotectedArea += a.getUnprotectedArea();
protectedAreaIncMinNatural += a.getProtectedAreaIncMinNatural(); unprotectedNatural += a.getUnprotectedNatural();
suitableArea += a.getSuitableLand(); suitableArea += a.getSuitableLand();
} }
} }
LogWriter.println("Total protectedArea " + comment + ": " + protectedArea); LogWriter.println("Total protectedArea " + comment + ": " + protectedArea);
LogWriter.println("Total unprotectedArea " + comment + ": " + unprotectedArea); LogWriter.println("Total unprotectedArea " + comment + ": " + unprotectedArea);
LogWriter.println("Total protectedAreaIncMinNatural " + comment + ": " + protectedAreaIncMinNatural); LogWriter.println("Total unprotectedNatural " + comment + ": " + unprotectedNatural);
LogWriter.println("Total suitableArea " + comment + ": " + suitableArea); LogWriter.println("Total suitableArea " + comment + ": " + suitableArea);
} }
......
...@@ -54,15 +54,6 @@ public class LandUseItem implements InterpolatingRasterItem<LandUseItem>, Serial ...@@ -54,15 +54,6 @@ public class LandUseItem implements InterpolatingRasterItem<LandUseItem>, Serial
return getTotalLandCoverArea()-getProtectedArea(); return getTotalLandCoverArea()-getProtectedArea();
} }
public double getProtectedAreaIncMinNatural() {
double protectedLand = getProtectedArea();
double unprotectedLand = getUnprotectedArea();
double unsuitableLand = Math.max(unprotectedLand * ModelConfig.MIN_NATURAL_RATE, unprotectedLand*unavailableFract);
double minOrProtectedA = protectedLand + unsuitableLand;
return minOrProtectedA;
}
public Intensity getIntensity(CropType crop) { public Intensity getIntensity(CropType crop) {
return intensityMap.get(crop); return intensityMap.get(crop);
} }
...@@ -273,9 +264,13 @@ public class LandUseItem implements InterpolatingRasterItem<LandUseItem>, Serial ...@@ -273,9 +264,13 @@ public class LandUseItem implements InterpolatingRasterItem<LandUseItem>, Serial
} }
public double getUnprotectedNatural() { public double getUnprotectedNatural() {
double totalLand = getTotalLandCoverArea();
double totalNatural = getLandCoverArea(LandCoverType.OTHER_NATURAL) + getLandCoverArea(LandCoverType.MANAGED_FOREST) + getLandCoverArea(LandCoverType.UNMANAGED_FOREST); double totalNatural = getLandCoverArea(LandCoverType.OTHER_NATURAL) + getLandCoverArea(LandCoverType.MANAGED_FOREST) + getLandCoverArea(LandCoverType.UNMANAGED_FOREST);
double minOrProtectedA = getProtectedAreaIncMinNatural();
double unprotectedNat = Math.max(0, totalNatural - minOrProtectedA); // if we are already using more than is protected then the unprotectedArea is 0 double protectedFract = getProtectedArea() / totalLand;
double minAndProtectedA = totalLand * (1 - (1-protectedFract) * (1-unavailableFract) * (1-ModelConfig.MIN_NATURAL_RATE));
double unprotectedNat = Math.max(0, totalNatural - minAndProtectedA); // if we are already using more than is protected then the unprotectedArea is 0
return unprotectedNat; return unprotectedNat;
} }
......
...@@ -29,7 +29,7 @@ public class LandUseOutputer extends AbstractLandUseOutputer { ...@@ -29,7 +29,7 @@ public class LandUseOutputer extends AbstractLandUseOutputer {
String landCoverFileName = outputDir.getPath() + File.separator + "LandUse.txt"; String landCoverFileName = outputDir.getPath() + File.separator + "LandUse.txt";
fertWriter = new BufferedWriter(new FileWriter(landCoverFileName, false)); fertWriter = new BufferedWriter(new FileWriter(landCoverFileName, false));
StringBuffer sbHeader = new StringBuffer("Lon Lat area protected"); StringBuffer sbHeader = new StringBuffer("Lon Lat area suitable");
for (LandCoverType cover : LandCoverType.values()) { for (LandCoverType cover : LandCoverType.values()) {
sbHeader.append(" " + cover.getName()); sbHeader.append(" " + cover.getName());
...@@ -57,7 +57,7 @@ public class LandUseOutputer extends AbstractLandUseOutputer { ...@@ -57,7 +57,7 @@ public class LandUseOutputer extends AbstractLandUseOutputer {
StringBuffer sbData = new StringBuffer(String.format("%.2f %.2f", lat, lon)); StringBuffer sbData = new StringBuffer(String.format("%.2f %.2f", lat, lon));
sbData.append(String.format(" %.8f", item.getTotalLandCoverArea())); sbData.append(String.format(" %.8f", item.getTotalLandCoverArea()));
sbData.append(String.format(" %.8f", item.getProtectedAreaIncMinNatural())); sbData.append(String.format(" %.8f", item.getSuitableLand()));
for (LandCoverType cover : LandCoverType.values()) { for (LandCoverType cover : LandCoverType.values()) {
sbData.append(String.format(" %.8f", item.getLandCoverArea(cover))); sbData.append(String.format(" %.8f", item.getLandCoverArea(cover)));
......
...@@ -17,8 +17,8 @@ public class YieldClusterPoint implements ClusteringPoint<String> { ...@@ -17,8 +17,8 @@ public class YieldClusterPoint implements ClusteringPoint<String> {
private final static String RICE_MAX = "riceMin"; private final static String RICE_MAX = "riceMin";
private final static String MAIZE_MIN = "maizeMin"; private final static String MAIZE_MIN = "maizeMin";
private final static String MAIZE_MAX = "maizeMax"; private final static String MAIZE_MAX = "maizeMax";
private final static String ROOTS_MIN = "rootsMin";
private final static String IRRIG_WATER_AVAL = "irrigWaterAval"; private final static String IRRIG_WATER_AVAL = "irrigWaterAval";
private final static String PROTECTED_AREA = "protectedArea";
private RasterKey rasterKey; private RasterKey rasterKey;
private double wheatMin; private double wheatMin;
...@@ -26,22 +26,22 @@ public class YieldClusterPoint implements ClusteringPoint<String> { ...@@ -26,22 +26,22 @@ public class YieldClusterPoint implements ClusteringPoint<String> {
private double riceMax; private double riceMax;
private double maizeMin; private double maizeMin;
private double maizeMax; private double maizeMax;
private double rootsMin;
private double pasture; private double pasture;
private double irrigWaterAval; private double irrigWaterAval;
private double protectedArea;
public YieldClusterPoint(RasterKey rasterKey, YieldResponsesItem yields, IrrigationItem irrigItem) { public YieldClusterPoint(RasterKey rasterKey, YieldResponsesItem yields, IrrigationItem irrigItem, double protectedArea) {
this.rasterKey = rasterKey; this.rasterKey = rasterKey;
// not sure if we be better to get a reference to the YieldResponsesItem, rather than caching these values? // not sure if we be better to get a reference to the YieldResponsesItem, rather than caching these values?
this.wheatMin = yields.getYieldNone(CropType.WHEAT); this.wheatMin = yields.getYieldNone(CropType.WHEAT);
this.riceMax = yields.getYieldMax(CropType.RICE); this.riceMax = yields.getYieldMax(CropType.RICE);
this.maizeMin = yields.getYieldNone(CropType.MAIZE); this.maizeMin = yields.getYieldNone(CropType.MAIZE);
this.rootsMin = yields.getYieldNone(CropType.STARCHY_ROOTS);
this.pasture = yields.getYieldNone(CropType.PASTURE); this.pasture = yields.getYieldNone(CropType.PASTURE);
this.wheatMax = yields.getYieldMax(CropType.WHEAT); this.wheatMax = yields.getYieldMax(CropType.WHEAT);
this.maizeMax = yields.getYieldMax(CropType.MAIZE); this.maizeMax = yields.getYieldMax(CropType.MAIZE);
this.irrigWaterAval = irrigItem.getIrrigConstraint(); this.irrigWaterAval = irrigItem.getIrrigConstraint();
this.protectedArea = protectedArea;
} }
public RasterKey getRasterKey() { public RasterKey getRasterKey() {
...@@ -58,8 +58,8 @@ public class YieldClusterPoint implements ClusteringPoint<String> { ...@@ -58,8 +58,8 @@ public class YieldClusterPoint implements ClusteringPoint<String> {
case RICE_MAX: return riceMax; case RICE_MAX: return riceMax;
case MAIZE_MIN: return maizeMin; case MAIZE_MIN: return maizeMin;
case MAIZE_MAX: return maizeMax; case MAIZE_MAX: return maizeMax;
case ROOTS_MIN: return rootsMin;
case IRRIG_WATER_AVAL: return irrigWaterAval; case IRRIG_WATER_AVAL: return irrigWaterAval;
case PROTECTED_AREA: return protectedArea;
} }
LogWriter.printlnError("YieldClusterPoint.getClusteringValue: got unknown value " + key); LogWriter.printlnError("YieldClusterPoint.getClusteringValue: got unknown value " + key);
return Double.NaN; return Double.NaN;
...@@ -67,7 +67,7 @@ public class YieldClusterPoint implements ClusteringPoint<String> { ...@@ -67,7 +67,7 @@ public class YieldClusterPoint implements ClusteringPoint<String> {
@Override @Override
public Collection<String> getAllClusteringKeys() { public Collection<String> getAllClusteringKeys() {
return Arrays.asList(PASTURE, WHEAT_MIN, WHEAT_MAX, MAIZE_MIN, MAIZE_MAX, RICE_MAX, IRRIG_WATER_AVAL); return Arrays.asList(PASTURE, WHEAT_MIN, WHEAT_MAX, MAIZE_MIN, MAIZE_MAX, IRRIG_WATER_AVAL, PROTECTED_AREA);
} }
public String toString() { public String toString() {
......
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