@@ -1065,6 +1065,343 @@ |
} |
} |
/** |
+ * Graph the quantile plot CDF of the time series data and save the resulting graph to the specified location. |
+ * @param sortedData the String[][] containing sorted data for the time series |
+ * (column 1 = dates (yyyy-mm-dd if timeStep = "daily", yyyy-mm if |
+ * timeStep = "monthly", yyyy if timeStep = "yearly") column 2 = value |
+ * @param sortedData_user the String[][] containing sorted user data for the |
+ * time series (column 1 = dates (yyyy-mm-dd if timeStep = "daily", yyyy-mm |
+ * if timeStep = "monthly", yyyy if timeStep = "yearly") column 2 = value |
+ * @param period1Data the String[][] containing sorted data for the time |
+ * series contained by period1 (column 1 = dates (yyyy-mm-dd if timeStep = |
+ * "daily", yyyy-mm if timeStep = "monthly", yyyy if timeStep = "yearly") |
+ * column 2 = value |
+ * @param period2Data the String[][] containing sorted data for the time |
+ * series contained by period2 (column 1 = dates (yyyy-mm-dd if timeStep = |
+ * "daily", yyyy-mm if timeStep = "monthly", yyyy if timeStep = "yearly") |
+ * column 2 = value |
+ * @param period3Data the String[][] containing sorted data for the time |
+ * series contained by period3 (column 1 = dates (yyyy-mm-dd if timeStep = |
+ * "daily", yyyy-mm if timeStep = "monthly", yyyy if timeStep = "yearly") |
+ * column 2 = value |
+ * @param color the color of the merged dataset (Java.Color) |
+ * @param color2 the color of the user dataset (Java.Color) |
+ * @param xAxisTitle the String label for the x axis of the graph |
+ */ |
+ private void createTimeseriesCDF(String[][] sortedData, |
+ String[][] sortedData_user, |
+ String[][] period1Data, |
+ String[][] period2Data, |
+ String[][] period3Data, |
+ Color color, |
+ Color color2, |
+ String xAxisTitle) throws ParseException, IOException { |
+ DoubleArray doubleArray = new DoubleArray(); |
+ double[][] xyRanks = doubleArray.weibullPlottingPosition(sortedData); |
+ double[][] xyRanks_user = doubleArray.weibullPlottingPosition(sortedData_user); |
+ double[][] xyRanks_period1 = doubleArray.weibullPlottingPosition(period1Data); |
+ double[][] xyRanks_period2 = doubleArray.weibullPlottingPosition(period2Data); |
+ double[][] xyRanks_period3 = doubleArray.weibullPlottingPosition(period3Data); |
+ |
+ //Calculate cdf for the entire dataset |
+ XYSeries series = new XYSeries(stationID + ": Data"); |
+ XYSeries series_user = new XYSeries(stationID + ": User Data"); |
+ XYSeries period1_series = new XYSeries(stationID + ": Period 1"); |
+ XYSeries period2_series = new XYSeries(stationID + ": Period 2"); |
+ XYSeries period3_series = new XYSeries(stationID + ": Period 3"); |
+ String[][] cdfData = new String[xyRanks.length][8]; |
+ for(int i=0; i<xyRanks.length; i++){ |
+ double x = xyRanks[i][1]; //flow |
+ double y = 1 - (xyRanks[i][0]/100); //rank |
+ series.add(x, y); |
+ cdfData[i][0] = String.valueOf(x); |
+ cdfData[i][1] = String.valueOf(y); |
+ //Add user data (if any) |
+ if(i < xyRanks_user.length){ |
+ x = xyRanks_user[i][1]; //flow |
+ y = 1 - (xyRanks_user[i][0]/100); //rank |
+ series_user.add(x, y); |
+ } |
+ //Add period 1 data (if any) |
+ if(i < xyRanks_period1.length){ |
+ x = xyRanks_period1[i][1]; //flow |
+ y = 1 - (xyRanks_period1[i][0]/100); //rank |
+ period1_series.add(x, y); |
+ cdfData[i][2] = String.valueOf(x); |
+ cdfData[i][3] = String.valueOf(y); |
+ }else{ |
+ cdfData[i][2] = "-1"; |
+ cdfData[i][3] = "-1"; |
+ } |
+ //Add period 2 data (if any) |
+ if(i < xyRanks_period2.length){ |
+ x = xyRanks_period2[i][1]; //flow |
+ y = 1 - (xyRanks_period2[i][0]/100); //rank |
+ period2_series.add(x, y); |
+ cdfData[i][4] = String.valueOf(x); |
+ cdfData[i][5] = String.valueOf(y); |
+ }else{ |
+ cdfData[i][4] = "-1"; |
+ cdfData[i][5] = "-1"; |
+ } |
+ //Add period 3 data (if any) |
+ if(i < xyRanks_period3.length){ |
+ x = xyRanks_period3[i][1]; //flow |
+ y = 1 - (xyRanks_period3[i][0]/100); //rank |
+ period3_series.add(x, y); |
+ cdfData[i][6] = String.valueOf(x); |
+ cdfData[i][7] = String.valueOf(y); |
+ }else{ |
+ cdfData[i][6] = "-1"; |
+ cdfData[i][7] = "-1"; |
+ } |
+ } |
+ //Save cdf data for JHighCharts |
+ doubleArray.writeXYseries(mainFolder, cdfData, getCDFoutput().getName()); |
+ |
+ //Create renderer, and axis for timeseries graph |
+ XYPlot plot = new XYPlot(); |
+ XYDataset xyDataset = new XYSeriesCollection(series); |
+ XYDataset xyDataset_user = new XYSeriesCollection(series_user); |
+ XYDataset xyDataset_period1 = new XYSeriesCollection(period1_series); |
+ XYDataset xyDataset_period2 = new XYSeriesCollection(period2_series); |
+ XYDataset xyDataset_period3 = new XYSeriesCollection(period3_series); |
+ XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false); |
+ renderer.setSeriesPaint(0, color); |
+ |
+ //Set the line data, renderer, and axis into plot |
+ plot.setDataset(0, xyDataset); |
+ plot.setRenderer(0, renderer); |
+ boolean legendTF = false; |
+ |
+ if(sortedData_user.length > 0){ |
+ XYItemRenderer renderer_user = new XYLineAndShapeRenderer(true, false); |
+ renderer_user.setSeriesPaint(0, color2); |
+ plot.setDataset(1, xyDataset_user); |
+ plot.setRenderer(1, renderer_user); |
+ legendTF = true; |
+ } |
+ if(period1Data.length > 0){ |
+ XYItemRenderer renderer_period1 = new XYLineAndShapeRenderer(true, false); |
+ renderer_period1.setSeriesPaint(0, Color.red); |
+ plot.setDataset(2, xyDataset_period1); |
+ plot.setRenderer(2, renderer_period1); |
+ legendTF = true; |
+ } |
+ if(period2Data.length > 0){ |
+ XYItemRenderer renderer_period2 = new XYLineAndShapeRenderer(true, false); |
+ renderer_period2.setSeriesPaint(0, new Color(255, 135, 0));//gold |
+ plot.setDataset(3, xyDataset_period2); |
+ plot.setRenderer(3, renderer_period2); |
+ legendTF = true; |
+ } |
+ if(period3Data.length > 0){ |
+ XYItemRenderer renderer_period3 = new XYLineAndShapeRenderer(true, false); |
+ renderer_period3.setSeriesPaint(0, Color.green); |
+ plot.setDataset(4, xyDataset_period3); |
+ plot.setRenderer(4, renderer_period3); |
+ legendTF = true; |
+ } |
+ |
+ //Map the line to the first Domain and first Range |
+ plot.mapDatasetToDomainAxis(0, 0); |
+ plot.mapDatasetToRangeAxis(0, 0); |
+ |
+ //Create Y Axis |
+ ValueAxis rangeAxis = new NumberAxis("Non-Exceedance"); |
+ rangeAxis.setRange(0, 1); |
+ plot.setRangeAxis(0, rangeAxis); |
+ |
+ //Create X Axis |
+ LogarithmicAxis xAxis = new LogarithmicAxis(xAxisTitle); |
+ xAxis.setAllowNegativesFlag(true); |
+ plot.setDomainAxis(0, xAxis); |
+ |
+ //Set extra plot preferences |
+ Graphing graphing = new Graphing(); |
+ plot = graphing.setLogXaxisPreferences(plot); |
+ |
+ //Create the charts out of the plots |
+ String graphTitle = "CDF for " + database + " Station: " + stationID + "; " + stationName; |
+ JFreeChart chart = new JFreeChart(graphTitle, graphing.titleFont, plot, legendTF); |
+ |
+ //Set legend Font |
+ if(legendTF){ |
+ LegendTitle legendTitle = chart.getLegend(); |
+ legendTitle.setItemFont(graphing.masterFont); |
+ } |
+ |
+ //Save monthly timeseries graph for use later |
+ try{ |
+ String path = mainFolder + File.separator + getCDF(); |
+ ChartUtilities.saveChartAsJPEG(new File(path), chart, 1280, 800); |
+ System.out.println("JFreeChart created properly at: " + path); |
+ |
+ }catch(IOException e){ |
+ System.err.println("A problem occurred while trying to creating the chart."); |
+ } |
+ } |
+ /** |
+ * Graph the time series verses the month/day for each year and long term average/median |
+ * and user data and save the resulting graph to the specified location. |
+ * @param sortedData the String[][] containing sorted data for the time series |
+ * (column 1 = dates (yyyy-mm-dd), column 2 = value |
+ * @param yAxisTitle the String label for the y axis of the graph |
+ */ |
+ private void createTimeseriesEnvelopeGraph(String[][] sortedData, |
+ String yAxisTitle, |
+ boolean logYaxis_TF) throws IOException { |
+ DoubleArray doubleArray = new DoubleArray(); |
+ DoubleMath doubleMath = new DoubleMath(); |
+ Graphing graphing = new Graphing(); |
+ |
+ //Initialize variables |
+ int currentYear = Integer.parseInt(end.substring(0,4)); |
+ int firstYear = Integer.parseInt(start.substring(0,4)); |
+ int lastYear = Integer.parseInt(end.substring(0,4)); |
+ String[][] graphData = new String[366][2]; |
+ String[] dayList = new String[366]; |
+ int seriesIndex = 0; |
+ |
+ //Plot each year and the long term average and the most recent year |
+ XYPlot plot = new XYPlot(); |
+ String longTermSeriesName = "Average"; |
+ if(medianTF) longTermSeriesName = "Median"; |
+ TimeSeries average_TS = new TimeSeries(longTermSeriesName); |
+ for(int j=1; j<=366; j++){ |
+ ArrayList<Double> dateData = new ArrayList<Double>(); |
+ dayList[j-1] = String.valueOf(j); |
+ |
+ for(int i=0; i<sortedData.length; i++){ |
+ double value = Double.parseDouble(sortedData[i][1]); |
+ double d = Double.parseDouble(sortedData[i][0].substring(8)); |
+ double m = Double.parseDouble(sortedData[i][0].substring(5,7)); |
+ double y = Double.parseDouble(sortedData[i][0].substring(0,4)); |
+ int day = (int)d; |
+ int month = (int)m; |
+ int year = (int)y; |
+ Calendar currentDate = new GregorianCalendar(year,month - 1, day); |
+ if(currentDate.get(Calendar.DAY_OF_YEAR) == j){ |
+ dateData.add(value); |
+ } |
+ } |
+ //Calculate average/median |
+ double dayValue = doubleMath.meanArithmetic(dateData); |
+ if(medianTF){ |
+ dayValue = doubleMath.median(dateData); |
+ } |
+ |
+ Calendar currentDate = new GregorianCalendar(2000, 0, 1); |
+ currentDate.set(Calendar.DAY_OF_YEAR, j); |
+ Day graphDay = new Day(currentDate.get(Calendar.DAY_OF_MONTH), currentDate.get(Calendar.MONTH) + 1, 2000); |
+ average_TS.add(graphDay, dayValue); |
+ graphData[j-1][0] = String.valueOf(j); |
+ graphData[j-1][1] = String.valueOf(dayValue); |
+ } |
+ |
+ //Create renderer, and axis for timeseries graph |
+ graphing.addTimeseriesData(plot, average_TS, true, Color.gray, false, false, true, true, seriesIndex); |
+ seriesIndex++; |
+ seriesIndex++;//Increase series so the most recent month can be plotted second |
+ |
+ //Graph a line for each year of monthly data in time period |
+ boolean moreYears = sortedData.length > 0; |
+ String[][] mostRecentYearData = new String[0][2]; |
+ while(moreYears){ |
+ //Get current year's data and graph it |
+ String[][] partialData = doubleArray.getYearsData(sortedData, String.valueOf(currentYear)); |
+ for(int i=0; i<partialData.length; i++){ |
+ String month_day = partialData[i][0].substring(5); |
+ partialData[i][0] = "2000-" + month_day; |
+ } |
+ TimeSeries currentYear_TS = createTimeSeriesFromData(partialData, "temp", "daily"); |
+ graphing.addTimeseriesData(plot, currentYear_TS, true, Color.lightGray, false, false, false, false, seriesIndex); |
+ seriesIndex++; |
+ |
+ if(currentYear == lastYear){ |
+ mostRecentYearData = partialData; |
+ } |
+ |
+ //Save results for output for JHighCharts |
+ String[] partialDayData = new String[dayList.length]; |
+ int ctr = 0; |
+ for(int i=0; i<dayList.length; i++){ |
+ partialDayData[i] = "-1";//value |
+ try{ |
+ double d = Double.parseDouble(partialData[ctr][0].substring(8)); |
+ double m = Double.parseDouble(partialData[ctr][0].substring(5,7)); |
+ double y = Double.parseDouble(partialData[ctr][0].substring(0,4)); |
+ int day = (int)d; |
+ int month = (int)m; |
+ int year = (int)y; |
+ Calendar currentDate = new GregorianCalendar(year,month - 1, day); |
+ if(currentDate.get(Calendar.DAY_OF_YEAR) == (i+1)){ |
+ partialDayData[i] = partialData[ctr][1];//value |
+ ctr++; |
+ } |
+ }catch(IndexOutOfBoundsException e){ |
+ //do nothing as it already has a -1 value |
+ } |
+ } |
+ graphData = doubleArray.appendcolumn_Matrix(graphData, dayList);//Add list of days (aka x points) |
+ graphData = doubleArray.appendcolumn_Matrix(graphData, partialDayData);//Add day values (aka y points) |
+ |
+ //Determine the next data year to continue looping over |
+ int previousYear = currentYear - 1; |
+ if(firstYear <= previousYear){ |
+ currentYear = previousYear; |
+ }else{ |
+ moreYears = false; |
+ } |
+ } |
+ |
+ //Re-add the most recent year to the graph so it renders on top |
+ TimeSeries finalYear_TS = createTimeSeriesFromData(mostRecentYearData, String.valueOf(lastYear), "daily"); |
+ graphing.addTimeseriesData(plot, finalYear_TS, true, Color.red, false, false, true, true, 1); |
+ |
+ //Output monthly boxplot and timeseries data for use with JHighCharts |
+ doubleArray.writeXYseries(mainFolder, graphData, getTimeseriesEnvelopeOutput().getName()); |
+ |
+ //Create Y Axis |
+ if(logYaxis_TF){ |
+ LogarithmicAxis rangeAxis = new LogarithmicAxis(yAxisTitle); |
+ rangeAxis.setAllowNegativesFlag(true); |
+ plot.setRangeAxis(0, rangeAxis); |
+ }else{ |
+ ValueAxis rangeAxis = new NumberAxis(yAxisTitle); |
+ plot.setRangeAxis(0, rangeAxis); |
+ } |
+ |
+ //Create X Axis |
+ DateAxis domainTime = new DateAxis("Date"); |
+ domainTime.setLowerMargin(0.05); |
+ domainTime.setUpperMargin(0.05); |
+ SimpleDateFormat xlabelDateFormat = new SimpleDateFormat("MMM"); |
+ domainTime.setDateFormatOverride(xlabelDateFormat); |
+ plot.setDomainAxis(0, domainTime); |
+ |
+ //Set extra plot preferences |
+ plot = graphing.setAxisPreferences(plot); |
+ |
+ //Create the charts out of the plots |
+ String graphTitle = "Time Series Range for " + database + " Station: " + stationID + "; " + stationName; |
+ JFreeChart chart = new JFreeChart(graphTitle, graphing.titleFont, plot, true); |
+ |
+ //Set legend Font |
+ LegendTitle legendTitle = chart.getLegend(); |
+ legendTitle.setItemFont(graphing.masterFont); |
+ |
+ //Save monthly timeseries graph for use later |
+ try{ |
+ String path = mainFolder + File.separator + getTimeseriesEnvelope(); |
+ ChartUtilities.saveChartAsJPEG(new File(path), chart, 1280, 800); |
+ System.out.println("JFreeChart created properly at: " + path); |
+ |
+ }catch(IOException e){ |
+ System.err.println("A problem occurred while trying to creating the chart."); |
+ } |
+ } |
+ /** |
* Graph a histogram of the time series and user data and save the resulting graph to the specified location |
* @param sortedData the String[][] containing sorted data for the time series |
* (column 1 = dates (yyyy-mm-dd if timeStep = "daily", yyyy-mm if |
@@ -1264,160 +1601,6 @@ |
} |
} |
/** |
- * Graph the time series verses the month/day for each year and long term average/median |
- * and user data and save the resulting graph to the specified location. |
- * @param sortedData the String[][] containing sorted data for the time series |
- * (column 1 = dates (yyyy-mm-dd), column 2 = value |
- * @param yAxisTitle the String label for the y axis of the graph |
- */ |
- private void createTimeseriesEnvelopeGraph(String[][] sortedData, |
- String yAxisTitle, |
- boolean logYaxis_TF) throws IOException { |
- DoubleArray doubleArray = new DoubleArray(); |
- DoubleMath doubleMath = new DoubleMath(); |
- Graphing graphing = new Graphing(); |
- |
- //Initialize variables |
- String currentYear = start.substring(0,4); |
- String finalYear = end.substring(0,4); |
- boolean leapYearTF = doubleArray.getLeapYearTF(Integer.parseInt(finalYear)); |
- String[][] graphData = new String[366][2]; |
- String[] dayList = new String[366]; |
- int seriesIndex = 0; |
- |
- //Plot each year and the long term average and the most recent year |
- XYPlot plot = new XYPlot(); |
- String longTermSeriesName = "Average"; |
- if(medianTF) longTermSeriesName = "Median"; |
- TimeSeries average_TS = new TimeSeries(longTermSeriesName); |
- for(int j=1; j<=366; j++){ |
- ArrayList<Double> dateData = new ArrayList<Double>(); |
- dayList[j-1] = String.valueOf(j); |
- |
- for(int i=0; i<sortedData.length; i++){ |
- double value = Double.parseDouble(sortedData[i][1]); |
- double d = Double.parseDouble(sortedData[i][0].substring(8)); |
- double m = Double.parseDouble(sortedData[i][0].substring(5,7)); |
- double y = Double.parseDouble(sortedData[i][0].substring(0,4)); |
- int day = (int)d; |
- int month = (int)m; |
- int year = (int)y; |
- Calendar currentDate = new GregorianCalendar(year,month - 1, day); |
- if(currentDate.get(Calendar.DAY_OF_YEAR) == j){ |
- dateData.add(value); |
- } |
- } |
- //Calculate average/median |
- double dayValue = doubleMath.meanArithmetic(dateData); |
- if(medianTF){ |
- dayValue = doubleMath.median(dateData); |
- } |
- |
- Calendar currentDate = new GregorianCalendar(2000, 0, 1); |
- currentDate.set(Calendar.DAY_OF_YEAR, j); |
- Day graphDay = new Day(currentDate.get(Calendar.DAY_OF_MONTH), currentDate.get(Calendar.MONTH) + 1, 2000); |
- average_TS.add(graphDay, dayValue); |
- graphData[j-1][0] = String.valueOf(j); |
- graphData[j-1][1] = String.valueOf(dayValue); |
- } |
- |
- //Create renderer, and axis for timeseries graph |
- graphing.addTimeseriesData(plot, average_TS, true, Color.gray, false, false, true, true, seriesIndex); |
- seriesIndex++; |
- seriesIndex++;//Increase series so the most recent month can be plotted second |
- |
- //Graph a line for each year of monthly data in time period |
- boolean moreYears = sortedData.length > 0; |
- while(moreYears){ |
- //Get current year's data and graph it |
- String[][] partialData = doubleArray.getYearsData(sortedData, currentYear); |
- for(int i=0; i<partialData.length; i++){ |
- String month_day = partialData[i][0].substring(5); |
- partialData[i][0] = "2000-" + month_day; |
- } |
- TimeSeries currentYear_TS = createTimeSeriesFromData(partialData, "temp", "daily"); |
- graphing.addTimeseriesData(plot, currentYear_TS, true, Color.lightGray, false, false, false, false, seriesIndex); |
- seriesIndex++; |
- |
- //Save results for output for JHighCharts |
- String[] partialDayData = new String[dayList.length]; |
- int ctr = 0; |
- for(int i=0; i<dayList.length; i++){ |
- partialDayData[i] = "-1";//value |
- try{ |
- double d = Double.parseDouble(partialData[ctr][0].substring(8)); |
- double m = Double.parseDouble(partialData[ctr][0].substring(5,7)); |
- double y = Double.parseDouble(partialData[ctr][0].substring(0,4)); |
- int day = (int)d; |
- int month = (int)m; |
- int year = (int)y; |
- Calendar currentDate = new GregorianCalendar(year,month - 1, day); |
- if(currentDate.get(Calendar.DAY_OF_YEAR) == (i+1)){ |
- partialDayData[i] = partialData[ctr][1];//value |
- ctr++; |
- } |
- }catch(IndexOutOfBoundsException e){ |
- //do nothing as it already has a -1 value |
- } |
- } |
- graphData = doubleArray.appendcolumn_Matrix(graphData, dayList);//Add list of days (aka x points) |
- graphData = doubleArray.appendcolumn_Matrix(graphData, partialDayData);//Add day values (aka y points) |
- |
- //Determine the next data year to continue looping over |
- int nextYear = Integer.parseInt(currentYear) + 1; |
- if(finalYear.compareToIgnoreCase(String.valueOf(nextYear)) >= 0){ |
- currentYear = String.valueOf(nextYear); |
- }else{ |
- //Re-add the most recent year to the graph so it renders on top |
- TimeSeries finalYear_TS = createTimeSeriesFromData(partialData, finalYear, "daily"); |
- graphing.addTimeseriesData(plot, finalYear_TS, true, Color.red, false, false, true, true, 1); |
- moreYears = false; |
- } |
- } |
- |
- //Output monthly boxplot and timeseries data for use with JHighCharts |
- doubleArray.writeXYseries(mainFolder, graphData, getTimeseriesEnvelopeOutput().getName()); |
- |
- //Create Y Axis |
- if(logYaxis_TF){ |
- LogarithmicAxis rangeAxis = new LogarithmicAxis(yAxisTitle); |
- rangeAxis.setAllowNegativesFlag(true); |
- plot.setRangeAxis(0, rangeAxis); |
- }else{ |
- ValueAxis rangeAxis = new NumberAxis(yAxisTitle); |
- plot.setRangeAxis(0, rangeAxis); |
- } |
- |
- //Create X Axis |
- DateAxis domainTime = new DateAxis("Date"); |
- domainTime.setLowerMargin(0.05); |
- domainTime.setUpperMargin(0.05); |
- SimpleDateFormat xlabelDateFormat = new SimpleDateFormat("MMM"); |
- domainTime.setDateFormatOverride(xlabelDateFormat); |
- plot.setDomainAxis(0, domainTime); |
- |
- //Set extra plot preferences |
- plot = graphing.setAxisPreferences(plot); |
- |
- //Create the charts out of the plots |
- String graphTitle = "Time Series Range for " + database + " Station: " + stationID + "; " + stationName; |
- JFreeChart chart = new JFreeChart(graphTitle, graphing.titleFont, plot, true); |
- |
- //Set legend Font |
- LegendTitle legendTitle = chart.getLegend(); |
- legendTitle.setItemFont(graphing.masterFont); |
- |
- //Save monthly timeseries graph for use later |
- try{ |
- String path = mainFolder + File.separator + getTimeseriesEnvelope(); |
- ChartUtilities.saveChartAsJPEG(new File(path), chart, 1280, 800); |
- System.out.println("JFreeChart created properly at: " + path); |
- |
- }catch(IOException e){ |
- System.err.println("A problem occurred while trying to creating the chart."); |
- } |
- } |
- /** |
* Graph the monthly average time series and user data and save the resulting graph to the specified location. |
* Also creates a boxplot for each month's data in a new graph |
* @param sortedData the String[][] containing sorted data for the time series |
@@ -1689,175 +1872,145 @@ |
} |
} |
/** |
- * Graph the quantile plot CDF of the time series data and save the resulting graph to the specified location. |
+ * Graph the time series calendar day (1-366) verses the year and save the |
+ * resulting graph to the specified location. |
* @param sortedData the String[][] containing sorted data for the time series |
- * (column 1 = dates (yyyy-mm-dd if timeStep = "daily", yyyy-mm if |
- * timeStep = "monthly", yyyy if timeStep = "yearly") column 2 = value |
- * @param sortedData_user the String[][] containing sorted user data for the |
- * time series (column 1 = dates (yyyy-mm-dd if timeStep = "daily", yyyy-mm |
- * if timeStep = "monthly", yyyy if timeStep = "yearly") column 2 = value |
- * @param period1Data the String[][] containing sorted data for the time |
- * series contained by period1 (column 1 = dates (yyyy-mm-dd if timeStep = |
- * "daily", yyyy-mm if timeStep = "monthly", yyyy if timeStep = "yearly") |
- * column 2 = value |
- * @param period2Data the String[][] containing sorted data for the time |
- * series contained by period2 (column 1 = dates (yyyy-mm-dd if timeStep = |
- * "daily", yyyy-mm if timeStep = "monthly", yyyy if timeStep = "yearly") |
- * column 2 = value |
- * @param period3Data the String[][] containing sorted data for the time |
- * series contained by period3 (column 1 = dates (yyyy-mm-dd if timeStep = |
- * "daily", yyyy-mm if timeStep = "monthly", yyyy if timeStep = "yearly") |
- * column 2 = value |
- * @param color the color of the merged dataset (Java.Color) |
- * @param color2 the color of the user dataset (Java.Color) |
- * @param xAxisTitle the String label for the x axis of the graph |
+ * (column 1 = dates (yyyy-mm-dd), column 2 = value |
+ * @param yAxisTitle the String label for the y axis of the graph |
*/ |
- private void createTimeseriesCDF(String[][] sortedData, |
- String[][] sortedData_user, |
- String[][] period1Data, |
- String[][] period2Data, |
- String[][] period3Data, |
- Color color, |
- Color color2, |
- String xAxisTitle) throws ParseException, IOException { |
+ private void createTimeseriesRasterGraph(String[][] sortedData, |
+ String yAxisTitle) throws IOException { |
DoubleArray doubleArray = new DoubleArray(); |
- double[][] xyRanks = doubleArray.weibullPlottingPosition(sortedData); |
- double[][] xyRanks_user = doubleArray.weibullPlottingPosition(sortedData_user); |
- double[][] xyRanks_period1 = doubleArray.weibullPlottingPosition(period1Data); |
- double[][] xyRanks_period2 = doubleArray.weibullPlottingPosition(period2Data); |
- double[][] xyRanks_period3 = doubleArray.weibullPlottingPosition(period3Data); |
+ DoubleMath doubleMath = new DoubleMath(); |
+ Graphing graphing = new Graphing(); |
|
- //Calculate cdf for the entire dataset |
- XYSeries series = new XYSeries(stationID + ": Data"); |
- XYSeries series_user = new XYSeries(stationID + ": User Data"); |
- XYSeries period1_series = new XYSeries(stationID + ": Period 1"); |
- XYSeries period2_series = new XYSeries(stationID + ": Period 2"); |
- XYSeries period3_series = new XYSeries(stationID + ": Period 3"); |
- String[][] cdfData = new String[xyRanks.length][8]; |
- for(int i=0; i<xyRanks.length; i++){ |
- double x = xyRanks[i][1]; //flow |
- double y = 1 - (xyRanks[i][0]/100); //rank |
- series.add(x, y); |
- cdfData[i][0] = String.valueOf(x); |
- cdfData[i][1] = String.valueOf(y); |
- //Add user data (if any) |
- if(i < xyRanks_user.length){ |
- x = xyRanks_user[i][1]; //flow |
- y = 1 - (xyRanks_user[i][0]/100); //rank |
- series_user.add(x, y); |
+ //Initialize variables |
+ String currentYear = start.substring(0,4); |
+ String finalYear = end.substring(0,4); |
+ boolean leapYearTF = doubleArray.getLeapYearTF(Integer.parseInt(finalYear)); |
+ String[][] graphData = new String[366][2]; |
+ String[] dayList = new String[366]; |
+ int seriesIndex = 0; |
+ |
+ //Plot each year and the long term average and the most recent year |
+ XYPlot plot = new XYPlot(); |
+ String longTermSeriesName = "Average"; |
+ if(medianTF) longTermSeriesName = "Median"; |
+ TimeSeries average_TS = new TimeSeries(longTermSeriesName); |
+ for(int j=1; j<=366; j++){ |
+ ArrayList<Double> dateData = new ArrayList<Double>(); |
+ dayList[j-1] = String.valueOf(j); |
+ |
+ for(int i=0; i<sortedData.length; i++){ |
+ double value = Double.parseDouble(sortedData[i][1]); |
+ double d = Double.parseDouble(sortedData[i][0].substring(8)); |
+ double m = Double.parseDouble(sortedData[i][0].substring(5,7)); |
+ double y = Double.parseDouble(sortedData[i][0].substring(0,4)); |
+ int day = (int)d; |
+ int month = (int)m; |
+ int year = (int)y; |
+ Calendar currentDate = new GregorianCalendar(year,month - 1, day); |
+ if(currentDate.get(Calendar.DAY_OF_YEAR) == j){ |
+ dateData.add(value); |
+ } |
} |
- //Add period 1 data (if any) |
- if(i < xyRanks_period1.length){ |
- x = xyRanks_period1[i][1]; //flow |
- y = 1 - (xyRanks_period1[i][0]/100); //rank |
- period1_series.add(x, y); |
- cdfData[i][2] = String.valueOf(x); |
- cdfData[i][3] = String.valueOf(y); |
+ //Calculate average/median |
+ double dayValue = doubleMath.meanArithmetic(dateData); |
+ if(medianTF){ |
+ dayValue = doubleMath.median(dateData); |
+ } |
+ |
+ Calendar currentDate = new GregorianCalendar(2000, 0, 1); |
+ currentDate.set(Calendar.DAY_OF_YEAR, j); |
+ Day graphDay = new Day(currentDate.get(Calendar.DAY_OF_MONTH), currentDate.get(Calendar.MONTH) + 1, 2000); |
+ average_TS.add(graphDay, dayValue); |
+ graphData[j-1][0] = String.valueOf(j); |
+ graphData[j-1][1] = String.valueOf(dayValue); |
+ } |
+ |
+ //Create renderer, and axis for timeseries graph |
+ graphing.addTimeseriesData(plot, average_TS, true, Color.gray, false, false, true, true, seriesIndex); |
+ seriesIndex++; |
+ seriesIndex++;//Increase series so the most recent month can be plotted second |
+ |
+ //Graph a line for each year of monthly data in time period |
+ boolean moreYears = sortedData.length > 0; |
+ while(moreYears){ |
+ //Get current year's data and graph it |
+ String[][] partialData = doubleArray.getYearsData(sortedData, currentYear); |
+ for(int i=0; i<partialData.length; i++){ |
+ String month_day = partialData[i][0].substring(5); |
+ partialData[i][0] = "2000-" + month_day; |
+ } |
+ TimeSeries currentYear_TS = createTimeSeriesFromData(partialData, "temp", "daily"); |
+ graphing.addTimeseriesData(plot, currentYear_TS, true, Color.lightGray, false, false, false, false, seriesIndex); |
+ seriesIndex++; |
+ |
+ //Save results for output for JHighCharts |
+ String[] partialDayData = new String[dayList.length]; |
+ int ctr = 0; |
+ for(int i=0; i<dayList.length; i++){ |
+ partialDayData[i] = "-1";//value |
+ try{ |
+ double d = Double.parseDouble(partialData[ctr][0].substring(8)); |
+ double m = Double.parseDouble(partialData[ctr][0].substring(5,7)); |
+ double y = Double.parseDouble(partialData[ctr][0].substring(0,4)); |
+ int day = (int)d; |
+ int month = (int)m; |
+ int year = (int)y; |
+ Calendar currentDate = new GregorianCalendar(year,month - 1, day); |
+ if(currentDate.get(Calendar.DAY_OF_YEAR) == (i+1)){ |
+ partialDayData[i] = partialData[ctr][1];//value |
+ ctr++; |
+ } |
+ }catch(IndexOutOfBoundsException e){ |
+ //do nothing as it already has a -1 value |
+ } |
+ } |
+ graphData = doubleArray.appendcolumn_Matrix(graphData, dayList);//Add list of days (aka x points) |
+ graphData = doubleArray.appendcolumn_Matrix(graphData, partialDayData);//Add day values (aka y points) |
+ |
+ //Determine the next data year to continue looping over |
+ int nextYear = Integer.parseInt(currentYear) + 1; |
+ if(finalYear.compareToIgnoreCase(String.valueOf(nextYear)) >= 0){ |
+ currentYear = String.valueOf(nextYear); |
}else{ |
- cdfData[i][2] = "-1"; |
- cdfData[i][3] = "-1"; |
- } |
- //Add period 2 data (if any) |
- if(i < xyRanks_period2.length){ |
- x = xyRanks_period2[i][1]; //flow |
- y = 1 - (xyRanks_period2[i][0]/100); //rank |
- period2_series.add(x, y); |
- cdfData[i][4] = String.valueOf(x); |
- cdfData[i][5] = String.valueOf(y); |
- }else{ |
- cdfData[i][4] = "-1"; |
- cdfData[i][5] = "-1"; |
- } |
- //Add period 3 data (if any) |
- if(i < xyRanks_period3.length){ |
- x = xyRanks_period3[i][1]; //flow |
- y = 1 - (xyRanks_period3[i][0]/100); //rank |
- period3_series.add(x, y); |
- cdfData[i][6] = String.valueOf(x); |
- cdfData[i][7] = String.valueOf(y); |
- }else{ |
- cdfData[i][6] = "-1"; |
- cdfData[i][7] = "-1"; |
+ //Re-add the most recent year to the graph so it renders on top |
+ TimeSeries finalYear_TS = createTimeSeriesFromData(partialData, finalYear, "daily"); |
+ graphing.addTimeseriesData(plot, finalYear_TS, true, Color.red, false, false, true, true, 1); |
+ moreYears = false; |
} |
} |
- //Save cdf data for JHighCharts |
- doubleArray.writeXYseries(mainFolder, cdfData, getCDFoutput().getName()); |
- |
- //Create renderer, and axis for timeseries graph |
- XYPlot plot = new XYPlot(); |
- XYDataset xyDataset = new XYSeriesCollection(series); |
- XYDataset xyDataset_user = new XYSeriesCollection(series_user); |
- XYDataset xyDataset_period1 = new XYSeriesCollection(period1_series); |
- XYDataset xyDataset_period2 = new XYSeriesCollection(period2_series); |
- XYDataset xyDataset_period3 = new XYSeriesCollection(period3_series); |
- XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false); |
- renderer.setSeriesPaint(0, color); |
|
- //Set the line data, renderer, and axis into plot |
- plot.setDataset(0, xyDataset); |
- plot.setRenderer(0, renderer); |
- boolean legendTF = false; |
- |
- if(sortedData_user.length > 0){ |
- XYItemRenderer renderer_user = new XYLineAndShapeRenderer(true, false); |
- renderer_user.setSeriesPaint(0, color2); |
- plot.setDataset(1, xyDataset_user); |
- plot.setRenderer(1, renderer_user); |
- legendTF = true; |
- } |
- if(period1Data.length > 0){ |
- XYItemRenderer renderer_period1 = new XYLineAndShapeRenderer(true, false); |
- renderer_period1.setSeriesPaint(0, Color.red); |
- plot.setDataset(2, xyDataset_period1); |
- plot.setRenderer(2, renderer_period1); |
- legendTF = true; |
- } |
- if(period2Data.length > 0){ |
- XYItemRenderer renderer_period2 = new XYLineAndShapeRenderer(true, false); |
- renderer_period2.setSeriesPaint(0, new Color(255, 135, 0));//gold |
- plot.setDataset(3, xyDataset_period2); |
- plot.setRenderer(3, renderer_period2); |
- legendTF = true; |
- } |
- if(period3Data.length > 0){ |
- XYItemRenderer renderer_period3 = new XYLineAndShapeRenderer(true, false); |
- renderer_period3.setSeriesPaint(0, Color.green); |
- plot.setDataset(4, xyDataset_period3); |
- plot.setRenderer(4, renderer_period3); |
- legendTF = true; |
- } |
- |
- //Map the line to the first Domain and first Range |
- plot.mapDatasetToDomainAxis(0, 0); |
- plot.mapDatasetToRangeAxis(0, 0); |
+ //Output monthly boxplot and timeseries data for use with JHighCharts |
+ doubleArray.writeXYseries(mainFolder, graphData, getTimeseriesEnvelopeOutput().getName()); |
|
//Create Y Axis |
- ValueAxis rangeAxis = new NumberAxis("Non-Exceedance"); |
- rangeAxis.setRange(0, 1); |
+ ValueAxis rangeAxis = new NumberAxis(yAxisTitle); |
plot.setRangeAxis(0, rangeAxis); |
|
//Create X Axis |
- LogarithmicAxis xAxis = new LogarithmicAxis(xAxisTitle); |
- xAxis.setAllowNegativesFlag(true); |
- plot.setDomainAxis(0, xAxis); |
+ DateAxis domainTime = new DateAxis("Date"); |
+ domainTime.setLowerMargin(0.05); |
+ domainTime.setUpperMargin(0.05); |
+ SimpleDateFormat xlabelDateFormat = new SimpleDateFormat("MMM"); |
+ domainTime.setDateFormatOverride(xlabelDateFormat); |
+ plot.setDomainAxis(0, domainTime); |
|
//Set extra plot preferences |
- Graphing graphing = new Graphing(); |
- plot = graphing.setLogXaxisPreferences(plot); |
+ plot = graphing.setAxisPreferences(plot); |
|
//Create the charts out of the plots |
- String graphTitle = "CDF for " + database + " Station: " + stationID + "; " + stationName; |
- JFreeChart chart = new JFreeChart(graphTitle, graphing.titleFont, plot, legendTF); |
+ String graphTitle = "Time Series Range for " + database + " Station: " + stationID + "; " + stationName; |
+ JFreeChart chart = new JFreeChart(graphTitle, graphing.titleFont, plot, true); |
|
//Set legend Font |
- if(legendTF){ |
- LegendTitle legendTitle = chart.getLegend(); |
- legendTitle.setItemFont(graphing.masterFont); |
- } |
+ LegendTitle legendTitle = chart.getLegend(); |
+ legendTitle.setItemFont(graphing.masterFont); |
|
//Save monthly timeseries graph for use later |
try{ |
- String path = mainFolder + File.separator + getCDF(); |
+ String path = mainFolder + File.separator + getTimeseriesEnvelope(); |
ChartUtilities.saveChartAsJPEG(new File(path), chart, 1280, 800); |
System.out.println("JFreeChart created properly at: " + path); |
|