From d81fd3e43307a9545eee629febd1189dfaf72ddf Mon Sep 17 00:00:00 2001 From: Peter Alexander <peter@blackhillock.co.uk> Date: Thu, 17 Sep 2015 22:34:28 +0100 Subject: [PATCH] logging improvements --- .../country/gams/GamsRasterOptimiser.java | 34 +++++++++---------- src/ac/ed/lurg/landuse/IrrigationItem.java | 6 +++- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/ac/ed/lurg/country/gams/GamsRasterOptimiser.java b/src/ac/ed/lurg/country/gams/GamsRasterOptimiser.java index 9985cbe6..0cc19a4b 100644 --- a/src/ac/ed/lurg/country/gams/GamsRasterOptimiser.java +++ b/src/ac/ed/lurg/country/gams/GamsRasterOptimiser.java @@ -283,17 +283,14 @@ public class GamsRasterOptimiser { CropType crop = CropType.WHEAT; if (yresp != null && (yresp.getYieldMax(crop) < yresp.getYieldFertOnly(crop) || yresp.getYieldMax(crop) < yresp.getYieldIrrigOnly(crop))) { - LogWriter.printlnError(key.getCol() + ", " + key.getRow() + ": " + yieldRaster.getXCoordin(key) + ", " + yieldRaster.getYCoordin(key) + ": " + yresp.getYieldMax(crop) + ", " + yresp.getYieldFertOnly(crop) + ", " + yresp.getYieldIrrigOnly(crop)); + logErrorWithCoord("Inconsistency F only:" + yresp.getYieldFertOnly(crop) + ", I only" + yresp.getYieldIrrigOnly(crop) + ", max " + yresp.getYieldMax(crop) + " at ", key, yieldRaster); } - // else if (yresp != null) - // LogWriter.println(key.getCol() + ", " + key.getRow() + ": " + yieldRaster.getXCoordin(key) + ", " + yieldRaster.getYCoordin(key) + ": " + yresp.getYieldMax(CropType.CEREALS) + ", " + yresp.getYieldFertOnly(CropType.CEREALS) + ", " + yresp.getYieldIrrigOnly(CropType.CEREALS)); - } int numCerealCats = ModelConfig.NUM_CEREAL_CATEGORIES; int numPastureCats = ModelConfig.NUM_PASTURE_CATEGORIES; - int thisShouldLookAtCropsOtherThanJustWheat; // need to consider other crops, and perhaps other yieldTypes as well + int thisShouldLookAtCropsOtherThanJustWheat; // need to consider other crops, and perhaps other yieldTypes as well - particularly fert/irrig responses List<Double> wheatlDivisions = getDivisions(yieldRaster, CropType.WHEAT, numCerealCats); List<Double> pastureDivisions = getDivisions(yieldRaster, CropType.PASTURE, numPastureCats); @@ -320,11 +317,11 @@ public class GamsRasterOptimiser { if (yresp == null) { countMissing++; - LogWriter.printlnError("No YieldResponsesItem for " + key + ", x=" + yieldRaster.getXCoordin(key) + ", y=" + yieldRaster.getYCoordin(key)); + logErrorWithCoord("No YieldResponsesItem for ", key, yieldRaster); } else { countFound++; - //LogWriter.println("YieldResponsesItem found for " + key + ", x=" + yieldRaster.getXCoordin(key) + ", y=" + yieldRaster.getYCoordin(key)); + //logErrorWithCoord("YieldResponsesItem found for ", key, yieldRaster); LandUseItem landUseItem = landUseRaster.get(key); if (landUseItem == null) { @@ -357,15 +354,10 @@ public class GamsRasterOptimiser { if (irrigItem!= null) { double irrigMax = irrigItem.getMaxIrrigAmount(crop); - if (irrigMax == 0.0) { - if (CropType.PASTURE == crop) - irrigMax = ModelConfig.PASTURE_MAX_IRRIGATION_RATE; - else { - LogWriter.printlnError("Can't find irrig max amount for col:" + key.getCol() + ", row:" + key.getRow() + ", x:" + yieldRaster.getXCoordin(key) + ", y:" + yieldRaster.getYCoordin(key) + ", crop:" + crop); - } - } - - aggIrig.setMaxIrrigAmount(crop, aggregateMean(aggIrig.getMaxIrrigAmount(crop), suitableAreaSoFar, irrigMax, suitableAreaThisTime)); + if (Double.isNaN(irrigMax)) + logErrorWithCoord("Can't find irrig max amount for ", key, yieldRaster, crop); + else + aggIrig.setMaxIrrigAmount(crop, aggregateMean(aggIrig.getMaxIrrigAmount(crop), suitableAreaSoFar, irrigMax, suitableAreaThisTime)); } double areaSoFar = aggLandUse.getCropArea(crop); @@ -374,7 +366,7 @@ public class GamsRasterOptimiser { for (YieldType yieldType : YieldType.values()) { double y = yresp.getYield(yieldType, crop); if (Double.isNaN(y)) - LogWriter.printlnError("Problem getting yield at, col:" + key.getCol() + ", row:" + key.getRow() + ", x:" + yieldRaster.getXCoordin(key) + ", y:" + yieldRaster.getYCoordin(key) + ", type:" + yieldType + ", crop:" + crop); + logErrorWithCoord("Problem getting yield for type:" + yieldType + ", ", key, yieldRaster, crop); else aggYResp.setYield(yieldType, crop, aggregateMean(aggYResp.getYield(yieldType, crop), areaSoFar, y, areaThisTime)); } @@ -414,6 +406,14 @@ public class GamsRasterOptimiser { return new GamsLocationInput(rasterInputData.getTimestep(), aggregatedYields, aggregatedAreas, aggregatedIrrigCosts, rasterInputData.getCountryInput()); } + private void logErrorWithCoord(String message, RasterKey key, YieldRaster yieldRaster, CropType crop) { + logErrorWithCoord(message + "crop:" + crop + ", ", key, yieldRaster); + } + + private void logErrorWithCoord(String message, RasterKey key, YieldRaster yieldRaster) { + LogWriter.printlnError(message + key + ", x:" + yieldRaster.getXCoordin(key) + ", y:" + yieldRaster.getYCoordin(key)); + } + private double aggregateMean(double aggV, double aggArea, double newV, double newArea) { if (Double.isNaN(aggV)) return newV; diff --git a/src/ac/ed/lurg/landuse/IrrigationItem.java b/src/ac/ed/lurg/landuse/IrrigationItem.java index fa266640..a6d6d867 100644 --- a/src/ac/ed/lurg/landuse/IrrigationItem.java +++ b/src/ac/ed/lurg/landuse/IrrigationItem.java @@ -3,6 +3,7 @@ package ac.ed.lurg.landuse; import java.util.HashMap; import java.util.Map; +import ac.ed.lurg.ModelConfig; import ac.ed.lurg.types.CropType; import ac.sac.raster.RasterItem; @@ -24,8 +25,11 @@ public class IrrigationItem implements RasterItem { } public double getMaxIrrigAmount(CropType crop) { + if (CropType.PASTURE == crop) + return ModelConfig.PASTURE_MAX_IRRIGATION_RATE; + Double d = maxIrrigAmounts.get(crop); - return d==null ? 0.0 : d.doubleValue(); + return d==null ? Double.NaN : d.doubleValue(); } public void setMaxIrrigAmount(CropType crop, double maxIrrig) { -- GitLab