@@ -10,7 +10,7 @@ |
import org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction; |
|
/** |
-* Last Updated: 23-June-2014 |
+* Last Updated: 16-December-2014 |
* @author Tyler Wible |
* @since 21-June-2012 |
*/ |
@@ -186,11 +186,11 @@ |
return roundedColumn; |
} |
/** |
- * Calculates the average of the provided double[] array |
+ * Calculates the arithmetic mean of the provided double[] array |
* @param data the double[] array of which the average is desired |
* @return the double value of the average of the data array |
*/ |
- public double Average(double[] data){ |
+ public double meanArithmetic(double[] data){ |
//Calculates the average of a double array |
double sum = sum(data); |
double count = data.length; |
@@ -202,11 +202,11 @@ |
return average; |
} |
/** |
- * Calculates the average of the provided ArrayList<Double> |
+ * Calculates the arithmetic mean of the provided ArrayList<Double> |
* @param data the ArrayList<Double> of which the average is desired |
* @return the double value of the average of the data array |
*/ |
- public double Average(ArrayList<Double> data){ |
+ public double meanArithmetic(ArrayList<Double> data){ |
//Calculates the average of a double array |
double sum = sum(data); |
double count = data.size(); |
@@ -489,46 +489,6 @@ |
return median; |
} |
/** |
- * Sub-function to find minimum or maximum of a dataset |
- * @param dataList dataset of which the minimum or maximum is desired. |
- * @param maxTrue if true the maximum value is calculated, otherwise the minimum is calculated. |
- * @return the minimum or maximum value |
- */ |
- public double Min_Max(double[] dataList, boolean maxTrue){ |
- double minMax = 0; |
- //sort array |
- Arrays.sort(dataList); |
- if(dataList.length ==0){ |
- //If no data return zero |
- minMax = 0; |
- }else if(maxTrue){ |
- //If maximum, return last value |
- minMax = dataList[dataList.length-1]; |
- }else{ |
- //Otherwise return return first value, minimum |
- minMax = dataList[0]; |
- } |
- return minMax; |
- } |
- /** |
- * Sub-function to find minimum or maximum of a dataset |
- * @param input dataset of which the minimum or maximum is desired. |
- * @param maxTrue if true the maximum value is calculated, otherwise the minimum is calculated. |
- * @return the minimum or maximum value |
- */ |
- public double Min_Max(List<Double> input, boolean maxTrue){ |
- //Create a double[] list of data from the input ArrayList |
- Iterator<Double> iterate = input.iterator(); |
- double[] dataList = new double[input.size()]; |
- int ctr = 0; |
- while(iterate.hasNext()){ |
- dataList[ctr] = (Double) iterate.next(); |
- ctr++; |
- } |
- double minMax = Min_Max(dataList, maxTrue); |
- return minMax; |
- } |
- /** |
* Sub-function to calculate the standard deviation of the population |
* @param dataList input list data for standard deviation |
* @return the population standard deviation of the dataList. |
@@ -556,7 +516,7 @@ |
* @return variance of the data array |
*/ |
public double VariancePopulation(double[] dataList){ |
- double average = Average(dataList); |
+ double average = meanArithmetic(dataList); |
//Calculate sum of differences |
double sum = 0; |
for(int i=0; i<dataList.length; i++){ |
@@ -577,7 +537,7 @@ |
* @return variance of the data array |
*/ |
public double VariancePopulation(ArrayList<Double> dataList){ |
- double average = Average(dataList); |
+ double average = meanArithmetic(dataList); |
//Calculate sum of differences |
double sum = 0; |
for(int i=0; i<dataList.size(); i++){ |
@@ -598,7 +558,7 @@ |
* @return variance of the data array |
*/ |
public double VarianceSample(double[] dataList){ |
- double average = Average(dataList); |
+ double average = meanArithmetic(dataList); |
//Calculate sum of differences |
double sum = 0; |
for(int i=0; i<dataList.length; i++){ |
@@ -625,7 +585,7 @@ |
* @return variance of the data array |
*/ |
public double VarianceSample(ArrayList<Double> dataList){ |
- double average = Average(dataList); |
+ double average = meanArithmetic(dataList); |
//Calculate sum of differences |
double sum = 0; |
for(int i=0; i<dataList.size(); i++){ |
@@ -649,7 +609,7 @@ |
*/ |
public double CoefficientOfVariation(double[] dataList){ |
//Calculate the average and standard deviation for the coefficient of varience |
- double average = Average(dataList); |
+ double average = meanArithmetic(dataList); |
double stDev = StandardDeviationSample(dataList); |
double coefVar = stDev/average; |
|
@@ -662,7 +622,7 @@ |
*/ |
public double CoefficientOfVariation(ArrayList<Double> dataList){ |
//Calculate the average and standard deviation for the coefficient of varience |
- double average = Average(dataList); |
+ double average = meanArithmetic(dataList); |
double stDev = StandardDeviationSample(dataList); |
double coefVar = stDev/average; |
|
@@ -684,8 +644,8 @@ |
double N = xData.length; |
|
//Calculate the average of the two datasets |
- double xBar = Average(xData); |
- double yBar = Average(yData); |
+ double xBar = meanArithmetic(xData); |
+ double yBar = meanArithmetic(yData); |
|
//Sum (Xi - Xbar) * (Yi - Ybar) |
double sum = 0; |
@@ -712,8 +672,8 @@ |
double N = xData.size(); |
|
//Calculate the average of the two datasets |
- double xBar = Average(xData); |
- double yBar = Average(yData); |
+ double xBar = meanArithmetic(xData); |
+ double yBar = meanArithmetic(yData); |
|
//Sum (Xi - Xbar) * (Yi - Ybar) |
double sum = 0; |
@@ -731,7 +691,7 @@ |
*/ |
public double SkewnessPopulation(double[] dataList){ |
//Get the average and standard deviation for use in the skewness formula |
- double average = Average(dataList); |
+ double average = meanArithmetic(dataList); |
double stDev = StandardDeviationSample(dataList); |
|
//Create list of values to compute the expected value (average) of in order to get the skewness |
@@ -739,7 +699,7 @@ |
for(int i=0; i<dataList.length; i++){ |
list[i] = Math.pow(((dataList[i] - average)/stDev), 3); |
} |
- double skewness = Average(list); |
+ double skewness = meanArithmetic(list); |
|
return skewness; |
} |
@@ -750,7 +710,7 @@ |
*/ |
public double SkewnessPopulation(ArrayList<Double> dataList){ |
//Get the average and standard deviation for use in the skewness formula |
- double average = Average(dataList); |
+ double average = meanArithmetic(dataList); |
double stDev = StandardDeviationSample(dataList); |
|
//Create list of values to compute the expected value (average) of in order to get the skewness |
@@ -758,7 +718,7 @@ |
for(int i=0; i<dataList.size(); i++){ |
list[i] = Math.pow(((dataList.get(i) - average)/stDev), 3); |
} |
- double skewness = Average(list); |
+ double skewness = meanArithmetic(list); |
|
return skewness; |
} |
@@ -770,7 +730,7 @@ |
*/ |
public double SkewnessSample(double[] dataList){ |
//Get the average and standard deviation for use in the skewness formula |
- double average = Average(dataList); |
+ double average = meanArithmetic(dataList); |
double variance = VarianceSample(dataList); |
double count = dataList.length; |
if(count == 0){//fix divide by zero errors |
@@ -795,7 +755,7 @@ |
*/ |
public double SkewnessSample(ArrayList<Double> dataList){ |
//Get the average and standard deviation for use in the skewness formula |
- double average = Average(dataList); |
+ double average = meanArithmetic(dataList); |
double variance = VarianceSample(dataList); |
double count = dataList.size(); |
if(count == 0){//fix divide by zero errors |
@@ -818,7 +778,7 @@ |
* @return Sxx of the dataset. |
*/ |
public double Sxx(double[] xData){ |
- double xBar = Average(xData); |
+ double xBar = meanArithmetic(xData); |
double sxx = 0; |
|
for(int i=0; i<xData.length; i++){ |
@@ -833,7 +793,7 @@ |
* @return Sxx of the dataset. |
*/ |
public double Sxx(ArrayList<Double> xData){ |
- double xBar = Average(xData); |
+ double xBar = meanArithmetic(xData); |
double sxx = 0; |
|
for(int i=0; i<xData.size(); i++){ |
@@ -855,8 +815,8 @@ |
xData.length + "\tY data size:\t" + yData.length)); |
} |
|
- double xBar = Average(xData); |
- double yBar = Average(yData); |
+ double xBar = meanArithmetic(xData); |
+ double yBar = meanArithmetic(yData); |
double sxy = 0; |
|
for(int i=0; i<xData.length; i++){ |
@@ -878,8 +838,8 @@ |
xData.size() + "\tY data size:\t" + yData.size())); |
} |
|
- double xBar = Average(xData); |
- double yBar = Average(yData); |
+ double xBar = meanArithmetic(xData); |
+ double yBar = meanArithmetic(yData); |
double sxy = 0; |
|
for(int i=0; i<xData.size(); i++){ |
@@ -1087,7 +1047,7 @@ |
observed.length + "\tModeled data size:\t" + modeled.length)); |
} |
|
- double observed_ave = Average(observed); |
+ double observed_ave = meanArithmetic(observed); |
double numerator = 0; |
double denominator = 0; |
for(int i=0; i<observed.length; i++){ |
@@ -1112,7 +1072,7 @@ |
observed.size() + "\tModeled data size:\t" + modeled.size())); |
} |
|
- double observed_ave = Average(observed); |
+ double observed_ave = meanArithmetic(observed); |
double numerator = 0; |
double denominator = 0; |
for(int i=0; i<observed.size(); i++){ |
@@ -13,7 +13,7 @@ |
import java.util.GregorianCalendar; |
|
/** |
-* Last Updated: 15-September-2014 |
+* Last Updated: 16-December-2014 |
* @author Tyler Wible |
* @since 29-June-2011 |
*/ |
@@ -251,16 +251,11 @@ |
statsSummaryTable[163][0] = "December (Variance)"; |
statsSummaryTable[164][0] = "December (Skewness)"; |
statsSummaryTable[165][0] = "December (Coefficient of Variation)"; |
- statsSummaryTable[166][0] = "Flow Statistics based on Indicators of Hydrologic Alteration from:"; |
- statsSummaryTable[167][0] = "B.D. Richter; J.V. Baumgartner; J. Powell; D.P. Braun. 1996. 'A Method For Assessing Hydrologic Aleration Within Ecosystems.' Conservation Biology 10(4): 1163-1174.\t"; |
- statsSummaryTable[168][0] = "B.D. Richter; J.V. Baumgartner; R. Wigington; D.P Braun. 1997. 'How Much Water Does A River Need?' Freshwater Biology. 37: 231-249.\t"; |
- statsSummaryTable[169][0] = "B.D. Richter; J.V. Baumgartner; D.P. Braun; J. Powell. 1998. 'A Spatial Assessment Of Hydrologic Alteration Within A River Network.' Regul. Rivers: Res. Mgmt. 14: 329-340."; |
- }else{ |
- statsSummaryTable[46][0] = "Flow Statistics based on Indicators of Hydrologic Alteration from:"; |
- statsSummaryTable[47][0] = "B.D. Richter; J.V. Baumgartner; J. Powell; D.P. Braun. 1996. 'A Method For Assessing Hydrologic Aleration Within Ecosystems.' Conservation Biology 10(4): 1163-1174.\t"; |
- statsSummaryTable[48][0] = "B.D. Richter; J.V. Baumgartner; R. Wigington; D.P Braun. 1997. 'How Much Water Does A River Need?' Freshwater Biology. 37: 231-249.\t"; |
- statsSummaryTable[49][0] = "B.D. Richter; J.V. Baumgartner; D.P. Braun; J. Powell. 1998. 'A Spatial Assessment Of Hydrologic Alteration Within A River Network.' Regul. Rivers: Res. Mgmt. 14: 329-340."; |
} |
+ statsSummaryTable[statsSummaryTable.length - 4][0] = "Flow Statistics based on Indicators of Hydrologic Alteration from:"; |
+ statsSummaryTable[statsSummaryTable.length - 3][0] = "B.D. Richter; J.V. Baumgartner; J. Powell; D.P. Braun. 1996. 'A Method For Assessing Hydrologic Aleration Within Ecosystems.' Conservation Biology 10(4): 1163-1174.\t"; |
+ statsSummaryTable[statsSummaryTable.length - 2][0] = "B.D. Richter; J.V. Baumgartner; R. Wigington; D.P Braun. 1997. 'How Much Water Does A River Need?' Freshwater Biology. 37: 231-249.\t"; |
+ statsSummaryTable[statsSummaryTable.length - 1][0] = "B.D. Richter; J.V. Baumgartner; D.P. Braun; J. Powell. 1998. 'A Spatial Assessment Of Hydrologic Alteration Within A River Network.' Regul. Rivers: Res. Mgmt. 14: 329-340."; |
|
//Calculate all data statistics |
//These are not annual statistics because the data can include more than 1 year |
@@ -597,7 +592,7 @@ |
oldValue = value; |
date1 = date2; |
} |
- double mean_all = doubleMath.Average(average_1Day); |
+ double mean_all = doubleMath.meanArithmetic(average_1Day); |
double centroid = centroidSum / sum; |
|
//Calculate 3-day statistics |
@@ -749,12 +744,12 @@ |
additionalSummary[26] = String.valueOf(ctr_falls);//Number of Flow Falls |
additionalSummary[27] = String.valueOf(ctr_highPulse);//Number of High Pulses |
additionalSummary[28] = String.valueOf(doubleMath.round(highLimit,1));//Threshold for High Pulses |
- additionalSummary[29] = String.valueOf(doubleMath.round(doubleMath.Average(highPulses), 3));//Average Duration of High Pulses |
+ additionalSummary[29] = String.valueOf(doubleMath.round(doubleMath.meanArithmetic(highPulses), 3));//Average Duration of High Pulses |
additionalSummary[30] = String.valueOf(ctr_lowPulse);//Number of Low Pulses |
additionalSummary[31] = String.valueOf(doubleMath.round(lowLimit,1));//Threshold for Low Pulses |
- additionalSummary[32] = String.valueOf(doubleMath.round(doubleMath.Average(lowPulses), 3));//Average Duration of Low Pulses |
- additionalSummary[33] = String.valueOf(doubleMath.round(doubleMath.Average(diffPositive),3));//Average Positive Difference Between Consecutive Days |
- additionalSummary[34] = String.valueOf(doubleMath.round(doubleMath.Average(diffNegative),3));//Average Negative Difference Between Consecutive Days |
+ additionalSummary[32] = String.valueOf(doubleMath.round(doubleMath.meanArithmetic(lowPulses), 3));//Average Duration of Low Pulses |
+ additionalSummary[33] = String.valueOf(doubleMath.round(doubleMath.meanArithmetic(diffPositive),3));//Average Positive Difference Between Consecutive Days |
+ additionalSummary[34] = String.valueOf(doubleMath.round(doubleMath.meanArithmetic(diffNegative),3));//Average Negative Difference Between Consecutive Days |
additionalSummary[35] = String.valueOf(doubleMath.round(centroid,2));//Temporal centroid of annual discharge (Julian day, not water-year day) |
|
//Add seasonal stats summary |
@@ -847,7 +842,7 @@ |
statsSummaryTable[index + 2] = String.valueOf(doubleMath.round(doubleMath.Percentile_function(data, 0.75), 3));//Upper Quartile |
statsSummaryTable[index + 3] = String.valueOf(doubleMath.round(doubleMath.Percentile_function(data,0.25), 3));//Lower Quartile |
statsSummaryTable[index + 4] = String.valueOf(doubleMath.round(doubleMath.Median(data), 3));//Median |
- statsSummaryTable[index + 5] = String.valueOf(doubleMath.round(doubleMath.Average(data), 3));//Average |
+ statsSummaryTable[index + 5] = String.valueOf(doubleMath.round(doubleMath.meanArithmetic(data), 3));//Average |
statsSummaryTable[index + 6] = String.valueOf(doubleMath.round(doubleMath.StandardDeviationSample(data), 3));//Standard Deviation |
statsSummaryTable[index + 7] = String.valueOf(doubleMath.round(doubleMath.VarianceSample(data), 3));//Variance |
statsSummaryTable[index + 8] = String.valueOf(doubleMath.round(doubleMath.SkewnessSample(data), 3));//Skewness |
@@ -902,7 +897,7 @@ |
String startDate = mDayDate.get(0); |
String endDate = mDayDate.get(numDays - 1); |
allDate.add(startDate + " to " + endDate); |
- allData.add(doubleMath.Average(mDayData)); |
+ allData.add(doubleMath.meanArithmetic(mDayData)); |
} |
} |
}catch(ArrayIndexOutOfBoundsException e){ |
@@ -915,6 +910,13 @@ |
Object[] returnArray = {allDate, allData}; |
return returnArray; |
} |
+ /** |
+ * Loop through the provided data array and gets the corresponding index to 'value' and returns that index from the dates array |
+ * @param dates a list of dates |
+ * @param data a list of values corresponding to the dates in the above list |
+ * @param value a value |
+ * @return the date corresponding to the provided value |
+ */ |
private String getDateOfValue(ArrayList<String> dates, ArrayList<Double> data, double value){ |
String dateOfValue = "null"; |
for(int i=0; i<dates.size(); i++){ |
@@ -925,6 +927,12 @@ |
} |
return dateOfValue; |
} |
+ /** |
+ * Writes the provided array to a CSV result file |
+ * @param mainFolder the folder location for the result file |
+ * @param statsSummary the desired contents of the file |
+ * @throws IOException |
+ */ |
public void writeStatsSummaryFile(String mainFolder, String[][] statsSummary) throws IOException{ |
//Open a file writer for the summary of the flow statistcs per year |
String path = mainFolder + File.separator + getFlowStatistics_summary(); |
@@ -29,7 +29,7 @@ |
|
|
/** |
- * Last Updated: 15-September-2014 |
+ * Last Updated: 16-December-2014 |
* @author Tyler Wible |
* @since 15-June-2012 |
*/ |
@@ -500,22 +500,22 @@ |
this.bflowStream_max = doubleMath.round(doubleMath.max(getColumn(graphData,1)),3); |
this.bflowStream_min = doubleMath.round(doubleMath.min(getColumn(graphData,1)),3); |
this.bflowStream_median = doubleMath.round(doubleMath.Median(getColumn(graphData,1)),3); |
- this.bflowStream_mean = doubleMath.round(doubleMath.Average(getColumn(graphData,1)),3); |
+ this.bflowStream_mean = doubleMath.round(doubleMath.meanArithmetic(getColumn(graphData,1)),3); |
|
this.bflow1_max = doubleMath.round(doubleMath.max(getColumn(graphData,2)),3); |
this.bflow1_min = doubleMath.round(doubleMath.min(getColumn(graphData,2)),3); |
this.bflow1_median = doubleMath.round(doubleMath.Median(getColumn(graphData,2)),3); |
- this.bflow1_mean = doubleMath.round(doubleMath.Average(getColumn(graphData,2)),3); |
+ this.bflow1_mean = doubleMath.round(doubleMath.meanArithmetic(getColumn(graphData,2)),3); |
|
this.bflow2_max = doubleMath.round(doubleMath.max(getColumn(graphData,3)),3); |
this.bflow2_min = doubleMath.round(doubleMath.min(getColumn(graphData,3)),3); |
this.bflow2_median = doubleMath.round(doubleMath.Median(getColumn(graphData,3)),3); |
- this.bflow2_mean = doubleMath.round(doubleMath.Average(getColumn(graphData,3)),3); |
+ this.bflow2_mean = doubleMath.round(doubleMath.meanArithmetic(getColumn(graphData,3)),3); |
|
this.bflow3_max = doubleMath.round(doubleMath.max(getColumn(graphData,4)),3); |
this.bflow3_min = doubleMath.round(doubleMath.min(getColumn(graphData,4)),3); |
this.bflow3_median = doubleMath.round(doubleMath.Median(getColumn(graphData,4)),3); |
- this.bflow3_mean = doubleMath.round(doubleMath.Average(getColumn(graphData,4)),3); |
+ this.bflow3_mean = doubleMath.round(doubleMath.meanArithmetic(getColumn(graphData,4)),3); |
} |
/** |
* Creates a double[] array of the elements in dataArray[all][column] |