/* * GridStatistics1_0.java * * Created on 18 February 2002, 14:22 */ package uk.ac.leeds.ccg.cluster.grids; /** * * @author andyt * * Description: * This class is for updating grid stats when the underlying data is changed. * If grid stats are often wanted then this is probably the fastest. */ public class GridStatistics1_0 extends AbstractGridStatistics { /** * Indicates if the min needs recalulating. * The min would need recalculating if the only min value in the grid was * replaced by a larger value. */ protected boolean recalculateMin=false; /** * Indicates if the max needs recalulating. * The max would need recalculating if the only max value in the grid was * replaced by a larger value. */ protected boolean recalculateMax=false; /** Creates a new instance of GridStatistics1_0 */ public GridStatistics1_0(AbstractGrid2DSquareCellDouble grid) { int nrows=grid.getNrows(); int ncols=grid.getNcols(); // Set defaults this.max=Double.NEGATIVE_INFINITY; this.maxCount=nrows*ncols; this.min=Double.POSITIVE_INFINITY; this.minCount=nrows*ncols; this.sum=0.0d; this.sparseness=1.0d; setGrid(grid); } /** * Returns a description. */ public String toString() {return "GridStatistics1_0(sparseness("+getSparseness()+"),sum("+getSum()+"),min("+getMin()+"),minCount("+getMinCount()+"),max("+getMax()+"),maxCount("+getMaxCount()+"))";} /** * Returns sparseness. */ public double getSparseness() {return this.sparseness;} /** * Sets sparseness. */ public void setSparseness(double sparseness) {this.sparseness=sparseness;} /** * Returns sum. */ public double getSum() {return this.sum;} /** * Sets sum. */ public void setSum(double sum) {this.sum=sum;} /** * Sets min. */ public void setMin(double min) {this.min=min;} /** * Sets min to the minimum of it and d1 and corrects minCount. */ public void doMin(double d1) { AbstractGrid2DSquareCellDouble grid = getGrid(); double noDataValue=grid.getNoDataValue(); if (d1!=noDataValue) { double min=getMin(); if (d1max) {setMaxCount(1);setMax(d1);setRecalculateMax(false);} if (d1==max) {setMaxCount(getMaxCount()+1);} } } /** * Returns the maximum value in the Grid. */ public double getMax() { AbstractGrid2DSquareCellDouble grid = getGrid(); int nrows=grid.getNrows(); int ncols=grid.getNcols(); double noDataValue=grid.getNoDataValue(); if (getRecalculateMax()) { setRecalculateMax(false); setRecalculateMin(false); setMax(Double.NEGATIVE_INFINITY); setMin(Double.POSITIVE_INFINITY); double d1; for (int i=0;i max) {maxCount = 1; max = d1;} if (d1 == max) {maxCount ++;} if (d1 < min) {minCount = 1;min = d1;} if (d1 == min) {minCount ++;} } } } setSparseness(sparseness); setSum(sum); setMin(min); setMinCount(minCount); setRecalculateMin(false); setMax(max); setMaxCount(maxCount); setRecalculateMax(false); } /** * Updates sum min minCount recalculateMin max maxCount recalculateMax from inputGridStatistics. */ public void updateGridStatisticsFrom(AbstractGridStatistics inputGridStatistics) { if (inputGridStatistics instanceof GridStatistics1_0) { GridStatistics1_0 inGridStatistics = (GridStatistics1_0) inputGridStatistics; setRecalculateMin(inGridStatistics.getRecalculateMin()); setRecalculateMax(inGridStatistics.getRecalculateMax()); } else { setRecalculateMin(false); setRecalculateMax(false); } setSum(inputGridStatistics.getSum()); setMin(inputGridStatistics.getMin()); setMinCount(inputGridStatistics.getMinCount()); setMax(inputGridStatistics.getMax()); setMaxCount(inputGridStatistics.getMaxCount()); } }