Displaying differences for changeset
 
display as  

src/java/cfa/CDPHE_lowFlowStats.java

@@ -40,7 +40,7 @@
                                      String stationName,
                                      String[][] flowData,
                                      int m,
-                                     int R,
+                                     double R,
                                      String waterYearBegin) throws IOException, ParseException{
         DoubleArray doubleArray =  new DoubleArray();
         DoubleMath doubleMath = new DoubleMath();
@@ -83,26 +83,28 @@
         
         //Calculate Flow statistics for each water-year in time period
         ArrayList<Double> mDay_annualNonZero = new ArrayList<Double>();
-        int mDay_annual = 0;
+        double mDay_annual = 0;
         boolean moreYears = finalYear > nextYear;
         while(moreYears){
             //Get current water year's data and calculate it's statistics
             String[][] partialData = doubleArray.getPeriodData(flowData, beginDate, endDate);
-            
-            //Calculate m-day statistics
-            Object[] resultArray = doubleArray.getMdayData(partialData, m, "arithmetic");
-            //ArrayList<String> average_Mday_date = (ArrayList<String>) resultArray[0];
-            ArrayList<Double> average_Mday = (ArrayList<Double>) resultArray[1];
-            
-            //Calculate minimum flow and save it
-            double mDay_min = doubleMath.min(average_Mday);
-            if(mDay_min > 0) mDay_annualNonZero.add(mDay_min);
-            mDay_annual++;
-            
-            //Add this water year's statistics to the existing results
-            String waterYearHeader = "Water Year " + String.valueOf(currentYear);
-            String[] additionalSummary = {"", waterYearHeader, "--", String.valueOf(mDay_min), "", ""};
-            statsSummaryTable = doubleArray.appendcolumn_Matrix(statsSummaryTable, additionalSummary);
+            if(partialData.length > 0){
+                
+                //Calculate m-day statistics
+                Object[] resultArray = doubleArray.getMdayData(partialData, m, "arithmetic");
+                //ArrayList<String> average_Mday_date = (ArrayList<String>) resultArray[0];
+                ArrayList<Double> average_Mday = (ArrayList<Double>) resultArray[1];
+
+                //Calculate minimum flow and save it
+                double mDay_min = doubleMath.min(average_Mday);
+                if(mDay_min > 0) mDay_annualNonZero.add(mDay_min);
+                mDay_annual++;
+
+                //Add this water year's statistics to the existing results
+                String waterYearHeader = "Water Year " + String.valueOf(currentYear);
+                String[] additionalSummary = {"", waterYearHeader, "--", String.valueOf(mDay_min), "", ""};
+                statsSummaryTable = doubleArray.appendcolumn_Matrix(statsSummaryTable, additionalSummary);
+            }
             
             //Check if this is the last year
             if(finalYear >= nextYear){
@@ -128,10 +130,11 @@
         double G = doubleMath.SkewnessSample(lnMday_annualNonZero);//Skewness
         
         //Determine fraction of m-day low flows that are zero
-        double f0 = (mDay_annual - mDay_annualNonZero.size()) / mDay_annualNonZero.size();
+        double nonZeroFlows = Double.parseDouble(String.valueOf(mDay_annualNonZero.size()));
+        double f0 = (mDay_annual - nonZeroFlows) / mDay_annual;
         
         //Determine cumulative probability of corresponding user-supplied return period
-        double P = (1./R - f0) / (1 - f0);
+        double P = ((1./R) - f0) / (1 - f0);
         
         //Determine standard normal deviate from cumulative probability (Joiner and Rosenblatt, 1971)
         double Z = 4.91 * (Math.pow(P, 0.14) - Math.pow(1-P, 0.14));
@@ -143,7 +146,8 @@
         double designFlow = Math.exp(U + K*S);
         
         //Call file writer for outputs fo flow statistics
-        statsSummaryTable[2][0] = String.valueOf(doubleMath.round(designFlow, 3));
+        designFlow = doubleMath.round(designFlow, 3);
+        statsSummaryTable[2][0] = String.valueOf(designFlow);
         writeStatsSummaryFile(mainFolder, statsSummaryTable);
         
         return designFlow;
@@ -242,7 +246,8 @@
         }
         
         //Call file writer for outputs fo flow statistics
-        statsSummaryTable[2][0] = String.valueOf(doubleMath.round(designFlow, 3));
+        designFlow = doubleMath.round(designFlow, 3);
+        statsSummaryTable[2][0] = String.valueOf(designFlow);
         writeStatsSummaryFile(mainFolder, statsSummaryTable);
         
         return designFlow;
@@ -401,6 +406,7 @@
             flowOnlyData[i] = Double.parseDouble(flowData[i][1]);
         }
         double designFlow = doubleMath.meanHarmonic(flowOnlyData);
+        designFlow = doubleMath.round(designFlow, 3);
         
         //Initialize the summary result table
         String[][] statsSummaryTable = new String[5][2];
@@ -412,7 +418,7 @@
         
         statsSummaryTable[0][1] = "";
         statsSummaryTable[1][1] = beginDate + " to " + endDate;
-        statsSummaryTable[2][1] = String.valueOf(doubleMath.round(designFlow, 3));
+        statsSummaryTable[2][1] = String.valueOf(designFlow);
         statsSummaryTable[3][1] = "";
         statsSummaryTable[4][1] = "";
         

src/java/cfa/DoubleMath.java

@@ -800,15 +800,13 @@
         return skewness;
     }
     /**
-    * Sub-function to calculate the sample skewness (Fisher-Pearson skewness) of a dataset. 
-    * Skewness = (n /((n-1)(n-2))) * sum{ ((x - average)/standard Deviation) ^ 3 }
+    * Sub-function to calculate the sample skewness of a dataset. 
     * @param dataList  input list data for skewness
     * @return skewness of the dataset.
     */
     public double SkewnessSample(ArrayList<Double> dataList){
         //Get the average and standard deviation for use in the skewness formula
         double average = meanArithmetic(dataList);
-        double variance = VarianceSample(dataList);
         double count = dataList.size();
         if(count == 0){//fix divide by zero errors
             count = 1;
@@ -816,11 +814,14 @@
 
         //Create list of values to compute the expected value (average) of in order to get the skewness
         double[] list = new double[dataList.size()];
+        double[] list2 = new double[dataList.size()];
         for(int i=0; i<dataList.size(); i++){
-            list[i] = Math.pow((dataList.get(i) - average)/variance, 3);
+            list[i] = Math.pow(dataList.get(i) - average, 3);
+            list2[i] = Math.pow(dataList.get(i) - average , 2);
         }
-        double coefficient = count /( (count - 1)*(count - 2) );
-        double skewness = coefficient * sum(list);
+        double numerator = (1/count) * sum(list);
+        double denominator = Math.pow( (1/(count - 1)) * sum(list2), 1.5);
+        double skewness = numerator/denominator;
 
         return skewness;
     }

src/java/cfa/guiTimeseries_Model.java

@@ -49,7 +49,7 @@
     String mainFolder = "C:/Projects/TylerWible/CodeDirectories/NetBeans/CSIP/data/CFA/Timeseries";
     String database = "USGS";//"CDWR";//"STORET";//"UserData";//
     String organizationName = "USGS";//"Co. Division of Water Resources";//"Colorado Dept. of Public Health & Environment";//
-    String stationID = "06764880";//"CLAGRECO";//"000028";//
+    String stationID = "06822000";//"06764880";//"CLAGRECO";//"000028";//
     String stationName = "South Platte River at Roscoe, Nebr.";//"Cache La Poudre Near Greeley";//"BIG THOMPSON R NEAR MOUTH";//
     String wqTest = "flow";//"00600        Total nitrogen, water, unfiltered, milligrams per liter, mg/L";
     String beginDate = "";
@@ -71,8 +71,8 @@
     double lowPercentile = 0.25;
     boolean showMonthlyStatsTF = false;
     boolean calcCDPHElowflowTF = true;
-    String CDPHE_lowFlowType = "all";//"extreme-value";//"biological";//"human-health";//
-    int CDPHE_m = 3;//m-day average                          //only used if CDPHE_lowFlowType == "all" or "extreme-value" or "biological"
+    String CDPHE_lowFlowType = "biological";//"all";//"extreme-value";//"human-health";//
+    int CDPHE_m = 4;//m-day average                          //only used if CDPHE_lowFlowType == "all" or "extreme-value" or "biological"
     int CDPHE_R = 10;//R-year return period for cdphe flows  //only used if CDPHE_lowFlowType == "all" or "extreme-value" or "biological"
     String CDPHE_waterYearBegin = "04-01";//"MM-dd"          //only used if CDPHE_lowFlowType == "all" or "extreme-value"
     int CDPHE_clusterLength = 120;                           //only used if CDPHE_lowFlowType == "all" or "biological"