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

little tidying up

parent 1f44c386
No related branches found
No related tags found
No related merge requests found
...@@ -110,7 +110,7 @@ public class ModelMain { ...@@ -110,7 +110,7 @@ public class ModelMain {
LogWriter.println("Country " + ca.getCountry()); LogWriter.println("Country " + ca.getCountry());
Collection<RasterKey> countryKeys = countryBoundaryRaster.getKeysFor(ca.getCountry()); Collection<RasterKey> countryKeys = countryBoundaryRaster.getKeysFor(ca.getCountry());
YieldRaster countryYieldSurfaces = yieldSurfaces.getSubsetRasterForKeys(countryKeys); YieldRaster countryYieldSurfaces = yieldSurfaces.createSubsetForKeys(countryKeys);
GamsRasterOutput result = null; GamsRasterOutput result = null;
...@@ -305,8 +305,8 @@ public class ModelMain { ...@@ -305,8 +305,8 @@ public class ModelMain {
} }
List<RasterKey> keys = countryBoundaryRaster.getKeysFor(cc); List<RasterKey> keys = countryBoundaryRaster.getKeysFor(cc);
RasterSet<LandCoverItem> initCountryLC = initLC.popSubsetForKeys(new RasterSet<LandCoverItem>(initLC.getHeaderDetails()), keys); RasterSet<LandCoverItem> initCountryLC = initLC.createSubsetForKeys(keys);
RasterSet<IrrigationItem> irrigationCosts = allIrrigationCosts.popSubsetForKeys(new RasterSet<IrrigationItem>(allIrrigationCosts.getHeaderDetails()), keys); RasterSet<IrrigationItem> irrigationCosts = allIrrigationCosts.createSubsetForKeys(keys);
Map<CropType, CropUsageData> countryCommodityData = cropUsageDataMap.get(cc); Map<CropType, CropUsageData> countryCommodityData = cropUsageDataMap.get(cc);
if (countryCommodityData == null) { if (countryCommodityData == null) {
......
...@@ -145,7 +145,7 @@ public class GamsRasterOptimiser { ...@@ -145,7 +145,7 @@ public class GamsRasterOptimiser {
Set<RasterKey> keys = mapping.get(locId); Set<RasterKey> keys = mapping.get(locId);
if (DEBUG) if (DEBUG)
checkedTotalAreas(newLandUseRaster.popSubsetForKeys(new RasterSet<LandUseItem>(newLandUseRaster.getHeaderDetails()), keys), locId + " before"); checkedTotalAreas(newLandUseRaster.createSubsetForKeys(keys), locId + " before");
double pastureChange = newLandUseAggItem.getLandCoverArea(LandCoverType.PASTURE) - prevLandUseAggItem.getLandCoverArea(LandCoverType.PASTURE); double pastureChange = newLandUseAggItem.getLandCoverArea(LandCoverType.PASTURE) - prevLandUseAggItem.getLandCoverArea(LandCoverType.PASTURE);
double croplandChange = newLandUseAggItem.getLandCoverArea(LandCoverType.CROPLAND) - prevLandUseAggItem.getLandCoverArea(LandCoverType.CROPLAND); double croplandChange = newLandUseAggItem.getLandCoverArea(LandCoverType.CROPLAND) - prevLandUseAggItem.getLandCoverArea(LandCoverType.CROPLAND);
...@@ -187,7 +187,7 @@ public class GamsRasterOptimiser { ...@@ -187,7 +187,7 @@ public class GamsRasterOptimiser {
LogWriter.printlnError("This should never happen, due to GAMS constraint. Not able to incorporate all changes, as not enough forest or natural areas left: " + locId + ": " + shortfall); LogWriter.printlnError("This should never happen, due to GAMS constraint. Not able to incorporate all changes, as not enough forest or natural areas left: " + locId + ": " + shortfall);
if (DEBUG) if (DEBUG)
checkedTotalAreas(newLandUseRaster.popSubsetForKeys(new RasterSet<LandUseItem>(newLandUseRaster.getHeaderDetails()), keys), locId + " after"); checkedTotalAreas(newLandUseRaster.createSubsetForKeys(keys), locId + " after");
for (RasterKey key : keys) { for (RasterKey key : keys) {
LandUseItem newLandUseItem = newLandUseRaster.get(key); LandUseItem newLandUseItem = newLandUseRaster.get(key);
......
...@@ -19,8 +19,9 @@ public class YieldRaster extends RasterSet<YieldResponsesItem> { ...@@ -19,8 +19,9 @@ public class YieldRaster extends RasterSet<YieldResponsesItem> {
} }
// not very efficient, we could keep the mapping of country to area somewhere. // not very efficient, we could keep the mapping of country to area somewhere.
public YieldRaster getSubsetRasterForKeys(Collection<RasterKey> keys) { @Override
YieldRaster subsetYieldRaster = new YieldRaster(this.getHeaderDetails()); public YieldRaster createSubsetForKeys(Collection<RasterKey> keys) {
YieldRaster subsetYieldRaster = new YieldRaster(getHeaderDetails());
popSubsetForKeys(subsetYieldRaster, keys); popSubsetForKeys(subsetYieldRaster, keys);
return subsetYieldRaster; return subsetYieldRaster;
} }
......
...@@ -151,7 +151,11 @@ public class RasterSet<D extends RasterItem> extends HashMap<RasterKey, D> { ...@@ -151,7 +151,11 @@ public class RasterSet<D extends RasterItem> extends HashMap<RasterKey, D> {
return h.getXCellSize() == header.getXCellSize() && h.getYCellSize() == header.getYCellSize(); return h.getXCellSize() == header.getXCellSize() && h.getYCellSize() == header.getYCellSize();
} }
public RasterSet<D> popSubsetForKeys(RasterSet<D> subset, Collection<RasterKey> keys) { public RasterSet<D> createSubsetForKeys(Collection<RasterKey> keys) {
return popSubsetForKeys (new RasterSet<D>(getHeaderDetails()), keys);
}
protected RasterSet<D> popSubsetForKeys(RasterSet<D> subset, Collection<RasterKey> keys) {
for (RasterKey key : keys) { for (RasterKey key : keys) {
//LogWriter.println("popSubsetForKeys: " + key.getCol() + ", " + key.getRow() + ": " + getXCoordin(key) + ", " + getYCoordin(key)); //LogWriter.println("popSubsetForKeys: " + key.getCol() + ", " + key.getRow() + ": " + getXCoordin(key) + ", " + getYCoordin(key));
subset.put(key, get(key)); subset.put(key, get(key));
......
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