@@ -204,20 +204,10 @@ |
* timeseries of the annual flow data against the water demand. |
* @param sortedData a string[][] containing daily average stream flow values in the following format: column1 = dates (yyyy-mm-dd format), |
* column2 = daily average stream flow values (cfs) |
- * @param lambdaString contains either the user provided value of lambda or "optimize" which tells the program to optimize lambda based on the dataset |
- * @param action if "optimize", this only optimizes the lambda and phi values for the model and then reports these back to the user, |
- * if "all" then it generates data based on the calculated phi values and finishes performing the drought analysis, |
- * if "useParameters" then it takes the previously generated parameters and uses these to perform the regression |
- * @param phiValues |
- * @param thetaValues |
* @return a String[] containing a tab-delimited summary of the droughts (water supply < water demand) |
* @throws IOException |
*/ |
- public String[] generalDroughtAnalysis(String[][] sortedData, |
- String lambdaString, |
- String action, |
- String phiValues, |
- String thetaValues) throws IOException{ |
+ public String[] generalDroughtAnalysis(String[][] sortedData) throws IOException{ |
DoubleMath doubleMath = new DoubleMath(); |
DoubleArray doubleArray = new DoubleArray(); |
//Calculate total annual flows |
@@ -229,7 +219,7 @@ |
|
|
//Call built in function to perform the drough analysis and graph the resulting data |
- String[] droughtInfo = generalDroughtAnalysis(sortedData, droughtLimit, lambdaString, action, phiValues, thetaValues); |
+ String[] droughtInfo = generalDroughtAnalysis(sortedData, droughtLimit); |
|
|
return droughtInfo; |
@@ -242,168 +232,158 @@ |
* @param sortedData a string[][] containing daily average stream flow values in the following format: column1 = dates (yyyy-mm-dd format), |
* column2 = daily average stream flow values (cfs) |
* @param droughtLimit a double representing the annual drought limit (water demand) on the watershed as specified by the user (in units of acre-ft/year) |
- * @param lambdaString contains either the user provided value of lambda or "optimize" which tells the program to optimize lambda based on the dataset |
- * @param action if "optimize", this only optimizes the phi values for the model and then reports these back to the user, |
- * if "all" then it generates data based on the calculated phi values and finishes performing the drought analysis, |
- * if "useParameters" then it takes the previously generated parameters and uses these to perform the regression |
- * @param phiValues |
- * @param thetaValues |
* @return a String[] containing a tab-delimited summary of the droughts (water supply < water demand) |
* @throws IOException |
*/ |
@SuppressWarnings("unchecked") |
public String[] generalDroughtAnalysis(String[][] sortedData, |
- double droughtLimit, |
- String lambdaString, |
- String action, |
- String phiValues, |
- String thetaValues) throws IOException{ |
+ double droughtLimit) throws IOException{ |
// //Test AR(p) model on sample data |
// double[][] annualData = sumAnnualFlows(sortedData); |
// Object[] returnArray = autoRegression.AR(p, annualData); |
// annualData = (double[][]) returnArray[0]; |
// double[][] generatedData = (double[][]) returnArray[1]; |
// autoRegression.graphAR1Double(annualData, generatedData); |
- DoubleMath doubleMath = new DoubleMath(); |
- DoubleArray doubleArray = new DoubleArray(); |
- AutoRegression autoRegression = new AutoRegression(); |
+ DoubleMath doubleMath = new DoubleMath(); |
+ DoubleArray doubleArray = new DoubleArray(); |
+ AutoRegression autoRegression = new AutoRegression(); |
|
- //Calculate total annual flows |
- double[][] annualData = sumAnnualFlows(sortedData); |
+ //Calculate total annual flows |
+ double[][] annualData = sumAnnualFlows(sortedData); |
|
|
- //Convert the data to only the stoicastic portion to modeled using AR(1) or ARMA(1,1) |
- double average = doubleMath.Average(doubleArray.getColumn(annualData, 1)); |
- double stDev = doubleMath.StandardDeviationSample(doubleArray.getColumn(annualData, 1)); |
- double[][] stocaisticData = autoRegression.StoicasticConversion(annualData, average, stDev, true); |
+ //Convert the data to only the stoicastic portion to modeled using AR(1) or ARMA(1,1) |
+ double average = doubleMath.Average(doubleArray.getColumn(annualData, 1)); |
+ double stDev = doubleMath.StandardDeviationSample(doubleArray.getColumn(annualData, 1)); |
+ double[][] stocaisticData = autoRegression.StoicasticConversion(annualData, average, stDev, true); |
|
|
- //Perform a transformation on the stoicastic data to change its distribution to a normal distribution |
- double lambda = 1.0; |
- if(lambdaString.equalsIgnoreCase("optimize")){ |
- lambda = autoRegression.BoxCox(stocaisticData); |
- }else{ |
- lambda = Double.parseDouble(lambdaString); |
- } |
- double[][] transformedData = autoRegression.BoxCox(lambda, stocaisticData, true); |
+ //Perform a transformation on the stoicastic data to change its distribution to a normal distribution |
+ double lambda = 1.0; |
+ if(lambdaString.equalsIgnoreCase("optimize")){ |
+ lambda = autoRegression.BoxCox(stocaisticData); |
+ }else{ |
+ lambda = Double.parseDouble(lambdaString); |
+ } |
+ double[][] transformedData = autoRegression.BoxCox(lambda, stocaisticData, true); |
// double[][] transformedData = autoRegression.SalasExampleTransformation(stocaisticData, true); |
|
|
|
- //Run the user specified auto-regressive model on the data |
- double[][] fittedData = null; |
- double[][] predictedData = null; |
- String methodType = ""; |
- Object[] returnArray = autoRegression.AutoregressiveModel(mainFolder, action, phiValues, thetaValues, transformedData); |
- if(action.equalsIgnoreCase("optimizeParameters")){ |
- //Find the parameters of the regression only and report these back |
- String[] stringArray = (String[]) returnArray; |
+ //Run the user specified auto-regressive model on the data |
+ double[][] fittedData = null; |
+ double[][] predictedData = null; |
+ String methodType = ""; |
+ Object[] returnArray = autoRegression.AutoregressiveModel(mainFolder, action, phiValues, thetaValues, transformedData); |
+ if(action.equalsIgnoreCase("optimizeParameters")){ |
+ //Find the parameters of the regression only and report these back |
+ String[] stringArray = (String[]) returnArray; |
|
|
- //Perform regression with data and graph the resulting data |
- Object[] dataArray = autoRegression.AutoregressiveModel(mainFolder, "useParameters", stringArray[0], stringArray[1], transformedData); |
+ //Perform regression with data and graph the resulting data |
+ Object[] dataArray = autoRegression.AutoregressiveModel(mainFolder, "useParameters", stringArray[0], stringArray[1], transformedData); |
|
- //Keep the data from the regression and graph it |
- methodType = (String) dataArray[0]; |
- transformedData = (double[][]) dataArray[1]; |
- fittedData = (double[][]) dataArray[2]; |
- predictedData = (double[][]) dataArray[3]; |
+ //Keep the data from the regression and graph it |
+ methodType = (String) dataArray[0]; |
+ transformedData = (double[][]) dataArray[1]; |
+ fittedData = (double[][]) dataArray[2]; |
+ predictedData = (double[][]) dataArray[3]; |
|
- }else if(action.equalsIgnoreCase("optimizeModel")){ |
- if(thetaValues.equalsIgnoreCase("")){ |
- //Calculate optimal AR(p) model and return the optimal phi values |
- ArrayList<Double> aic = (ArrayList<Double>) returnArray[0]; |
- ArrayList<Double> bic = (ArrayList<Double>) returnArray[1]; |
- String phi = (String) returnArray[2]; |
- String theta = (String) returnArray[3]; |
+ }else if(action.equalsIgnoreCase("optimizeModel")){ |
+ if(thetaValues.equalsIgnoreCase("")){ |
+ //Calculate optimal AR(p) model and return the optimal phi values |
+ ArrayList<Double> aic = (ArrayList<Double>) returnArray[0]; |
+ ArrayList<Double> bic = (ArrayList<Double>) returnArray[1]; |
+ String phi = (String) returnArray[2]; |
+ String theta = (String) returnArray[3]; |
|
- //Graph the AIC/BIC curve for the user |
- graphAR_AIC_BIC(aic, bic); |
+ //Graph the AIC/BIC curve for the user |
+ graphAR_AIC_BIC(aic, bic); |
|
- String[] optimalValues = {phi + "$$", theta}; |
- return optimalValues; |
- |
- }else{ |
- //Calculate optimal ARMA(p,q) model and return the optimal phi/theta values |
- double[][] results = (double[][]) returnArray[0]; |
- String phi = (String) returnArray[1]; |
- String theta = (String) returnArray[2]; |
- |
- //Graph the AIC/BIC curve for the user |
- graphARMA_AIC_BIC("AIC", results, 3); |
- graphARMA_AIC_BIC("BIC" , results, 4); |
- |
- String[] optimalValues = {phi + "$$", theta}; |
- return optimalValues; |
- } |
+ String[] optimalValues = {phi + "$$", theta}; |
+ return optimalValues; |
|
}else{ |
- //Keep the data from the regression and graph it |
- methodType = (String) returnArray[0]; |
- transformedData = (double[][]) returnArray[1]; |
- fittedData = (double[][]) returnArray[2]; |
- predictedData = (double[][]) returnArray[3]; |
+ //Calculate optimal ARMA(p,q) model and return the optimal phi/theta values |
+ double[][] results = (double[][]) returnArray[0]; |
+ String phi = (String) returnArray[1]; |
+ String theta = (String) returnArray[2]; |
+ |
+ //Graph the AIC/BIC curve for the user |
+ graphARMA_AIC_BIC("AIC", results, 3); |
+ graphARMA_AIC_BIC("BIC" , results, 4); |
+ |
+ String[] optimalValues = {phi + "$$", theta}; |
+ return optimalValues; |
} |
|
- //Un-transform the stoicastic historic and stoicastic generated data so as to graph real stream flow values |
- transformedData = autoRegression.BoxCox(lambda, transformedData, false); |
- fittedData = autoRegression.BoxCox(lambda, fittedData, false); |
- predictedData = autoRegression.BoxCox(lambda, predictedData, false); |
+ }else{ |
+ //Keep the data from the regression and graph it |
+ methodType = (String) returnArray[0]; |
+ transformedData = (double[][]) returnArray[1]; |
+ fittedData = (double[][]) returnArray[2]; |
+ predictedData = (double[][]) returnArray[3]; |
+ } |
+ |
+ //Un-transform the stoicastic historic and stoicastic generated data so as to graph real stream flow values |
+ transformedData = autoRegression.BoxCox(lambda, transformedData, false); |
+ fittedData = autoRegression.BoxCox(lambda, fittedData, false); |
+ predictedData = autoRegression.BoxCox(lambda, predictedData, false); |
// transformedData = autoRegression.SalasExampleTransformation(transformedData, false); |
// fittedData = autoRegression.SalasExampleTransformation(fittedData, false); |
// predictedData = autoRegression.SalasExampleTransformation(predictedData, false); |
|
|
- //Convert back from the stoicastic component of the data to the entire original data |
- double[][] originalData = autoRegression.StoicasticConversion(transformedData, average, stDev, false); |
- fittedData = autoRegression.StoicasticConversion(fittedData, average, stDev, false); |
- predictedData = autoRegression.StoicasticConversion(predictedData, average, stDev, false); |
+ //Convert back from the stoicastic component of the data to the entire original data |
+ double[][] originalData = autoRegression.StoicasticConversion(transformedData, average, stDev, false); |
+ fittedData = autoRegression.StoicasticConversion(fittedData, average, stDev, false); |
+ predictedData = autoRegression.StoicasticConversion(predictedData, average, stDev, false); |
|
|
- //Calculate the droughts, their accumulated deficits, durations, and intensities |
- DroughtProperties historicDroughtProps = new DroughtProperties(annualData, droughtLimit); |
- DroughtProperties predictedDroughtProps = new DroughtProperties(predictedData, droughtLimit); |
+ //Calculate the droughts, their accumulated deficits, durations, and intensities |
+ DroughtProperties historicDroughtProps = new DroughtProperties(annualData, droughtLimit); |
+ DroughtProperties predictedDroughtProps = new DroughtProperties(predictedData, droughtLimit); |
|
|
|
- //Determine the return periods for the droughts on record |
- double[][] historicDroughts = recurrenceInterval(historicDroughtProps, droughtLimit, annualData); |
- double[][] predictedDroughts = recurrenceInterval(predictedDroughtProps, droughtLimit, predictedData); |
+ //Determine the return periods for the droughts on record |
+ double[][] historicDroughts = recurrenceInterval(historicDroughtProps, droughtLimit, annualData); |
+ double[][] predictedDroughts = recurrenceInterval(predictedDroughtProps, droughtLimit, predictedData); |
|
|
- //Graph the drought data |
- graphTimeseries(annualData, droughtLimit); //graph1 |
- graphNegativeBarChart(annualData, droughtLimit); //graph2 |
- graphFittedData(originalData, fittedData, methodType); //graph3 |
- graphPredictedData(originalData, predictedData, methodType);//graph4 |
- graphReturnPeriod(historicDroughts, predictedDroughts); //graph5 |
+ //Graph the drought data |
+ graphTimeseries(annualData, droughtLimit); //graph1 |
+ graphNegativeBarChart(annualData, droughtLimit); //graph2 |
+ graphFittedData(originalData, fittedData, methodType); //graph3 |
+ graphPredictedData(originalData, predictedData, methodType);//graph4 |
+ graphReturnPeriod(historicDroughts, predictedDroughts); //graph5 |
|
|
|
|
- //Populate the return array with the information gained from the drought analysis |
- String[] droughtInfo = new String[historicDroughtProps.numberOfDroughts() + 1]; |
- droughtInfo[0] = "Deficit [acre-ft]\tLambda\tDuration [years]\tIntensity\tFinal Year"; |
- for(int i=0; i<historicDroughtProps.numberOfDroughts(); i++){ |
- droughtInfo[i+1] = String.valueOf(historicDroughtProps.getDeficit(i)) + "\t" + |
- String.valueOf(historicDroughtProps.getDeficit(i)/droughtLimit) + "\t" + |
- String.valueOf(historicDroughtProps.getDuration(i)) + "\t" + |
- String.valueOf(historicDroughtProps.getIntensity(i)) + "\t" + |
- String.valueOf(historicDroughtProps.getEndYear(i)); |
- } |
+ //Populate the return array with the information gained from the drought analysis |
+ String[] droughtInfo = new String[historicDroughtProps.numberOfDroughts() + 1]; |
+ droughtInfo[0] = "Deficit [acre-ft]\tLambda\tDuration [years]\tIntensity\tFinal Year"; |
+ for(int i=0; i<historicDroughtProps.numberOfDroughts(); i++){ |
+ droughtInfo[i+1] = String.valueOf(historicDroughtProps.getDeficit(i)) + "\t" + |
+ String.valueOf(historicDroughtProps.getDeficit(i)/droughtLimit) + "\t" + |
+ String.valueOf(historicDroughtProps.getDuration(i)) + "\t" + |
+ String.valueOf(historicDroughtProps.getIntensity(i)) + "\t" + |
+ String.valueOf(historicDroughtProps.getEndYear(i)); |
+ } |
|
- if(action.equalsIgnoreCase("optimizeParameters")){ |
- //Return only the parameters of the regression |
- String[] stringArray = (String[]) returnArray; |
- stringArray[0] = stringArray[0] + "$$"; |
- return stringArray; |
- }else if(action.equalsIgnoreCase("updateParameters")){ |
- //Return only the parameters of the regression |
- String[] stringArray = {phiValues + "$$", thetaValues}; |
- return stringArray; |
- } |
+ if(action.equalsIgnoreCase("optimizeParameters")){ |
+ //Return only the parameters of the regression |
+ String[] stringArray = (String[]) returnArray; |
+ stringArray[0] = stringArray[0] + "$$"; |
+ return stringArray; |
+ }else if(action.equalsIgnoreCase("updateParameters")){ |
+ //Return only the parameters of the regression |
+ String[] stringArray = {phiValues + "$$", thetaValues}; |
+ return stringArray; |
+ } |
|
- return droughtInfo; |
+ return droughtInfo; |
} |
/** |
* Calculates the average recurrence interval for each drought on record and the lambda coefficient of each drought (deficit = lambda * droughtLimit) |
@@ -1240,7 +1220,7 @@ |
|
//Write the summary to the file |
for(int i=0; i < dynamicSummary.length; i++) { |
- print_line.printf("%s" + "%n", dynamicSummary[i]); |
+ print_line.printf("%s" + "%n", dynamicSummary[i]); |
} |
print_line.close(); |
writer.close(); |
@@ -1308,10 +1288,10 @@ |
|
if(Double.compare(droughtLimit, 0) < 0){ |
//If no drought limit is provided (aka -1 is provided) then calculate the drought limit = average(annual flows) |
- droughtInfo = generalDroughtAnalysis(sortedData_combined, lambdaString, action, phiValues, thetaValues); |
+ droughtInfo = generalDroughtAnalysis(sortedData_combined); |
}else{ |
//If a drought limit is provided (aka greater than or equal to zero) then use this as the drought limit |
- droughtInfo = generalDroughtAnalysis(sortedData_combined, droughtLimit, lambdaString, action, phiValues, thetaValues); |
+ droughtInfo = generalDroughtAnalysis(sortedData_combined, droughtLimit); |
} |
|
//Get today's date for the source reference |