public void Draw() { table = m_seriesList.ToDataTable(m_seriesList.Count > 1); // m_seriesList. table.RowChanged += new DataRowChangeEventHandler(table_RowChanged); table.RowDeleted += new DataRowChangeEventHandler(table_RowDeleted); dataGridView1.DataSource = null; dataGridView1.DataSource = table; this.dataGridView1.ReadOnly = SeriesList.ReadOnly || SeriesList.Count > 1; this.dataGridView1.AllowUserToAddRows = !SeriesList.ReadOnly; toolBarButtonSave.Enabled = !SeriesList.ReadOnly; dataGridView1.Columns[0].DefaultCellStyle.Format = m_seriesList.DateFormat; if (m_seriesList.Count == 1 && dataGridView1.Columns.Count > 1 && dataGridView1.Columns[1].HeaderText == "value" ) { dataGridView1.Columns[1].HeaderText = m_seriesList[0].Name; } }
public override IExplorerView Run() { Logger.WriteLine("MovingAverageAnalysis.Run()"); SeriesList list = Explorer.CreateSelectedSeries(); ReadSeriesList(list); view.Messages.Add(list.MissingRecordsMessage); SeriesList myList = new SeriesList(); for (int i = 0; i < list.Count; i++) { if (Explorer.PlotRaw) { myList.Add(list[i]); } if (Explorer.PlotMoving24HourAverage) { Series s24 = Math.MovingAvearge(list[i], 24); myList.Add(s24); } if (Explorer.PlotMoving120HourAverage) { Series s120 = Math.MovingAvearge(list[i], 120); myList.Add(s120); } } view.Title = "Moving Average\n" + list.Text.TitleText(); view.SubTitle = list.MissingRecordsMessage; view.SeriesList = myList; view.DataTable = myList.ToDataTable(true); return(view); }
public override IExplorerView Run() { Logger.WriteLine("MovingAverageAnalysis.Run()"); SeriesList list = Explorer.CreateSelectedSeries(); ReadSeriesList(list); view.Messages.Add(list.MissingRecordsMessage); SeriesList myList = new SeriesList(); for (int i = 0; i < list.Count; i++) { if (Explorer.PlotRaw) { myList.Add(list[i]); } if (Explorer.PlotMoving24HourAverage) { Series s24 = Math.MovingAvearge(list[i], 24); myList.Add(s24); } if (Explorer.PlotMoving120HourAverage) { Series s120 = Math.MovingAvearge(list[i], 120); myList.Add(s120); } } view.Title = "Moving Average\n" + list.Text.TitleText(); view.SubTitle = list.MissingRecordsMessage; view.SeriesList = myList; view.DataTable = myList.ToDataTable(true); return view; }
/// <summary> /// Print the daily data from the Series List /// </summary> /// <param name="list"></param> Series list private static void PrintDaily(SeriesList list) { var tbl = list.ToDataTable(false); var title = "\nStation Parameter "; var title2 = "========= ========== ========= ========= ========= ========= ========="; for (int i = 0; i < tbl.Rows.Count; i++) { DateTime t = Convert.ToDateTime(tbl.Rows[i][0]); title += t.ToString("ddd MMMdd"); title += " "; } Console.WriteLine(title); Console.WriteLine(title2); foreach (var item in list) { string x = item.SiteID.PadRight(10) + " " + item.Parameter.PadRight(11) + " "; foreach (var pt in item) { x += pt.Value.ToString("F2").PadLeft(10); } Console.WriteLine(x); } }
public override IExplorerView Run() { Logger.WriteLine("SummaryHydrographAnalysis.Run()"); SeriesList list = Explorer.CreateSelectedSeries(); ReadSeriesList(list); if (Explorer.SelectedSeries.Length == 1 && Explorer.MergeSelected) { // merge single Year Traces. list.RemoveMissing(); var s = list.MergeYearlyScenarios(); list = new SeriesList(); list.Add(s); } view.Messages.Add(list.MissingRecordsMessage); string title = list.Text.TitleText(); string subTitle = list.MissingRecordsMessage; SeriesList myList = new SeriesList(); list.RemoveMissing(); if (Explorer.AlsoPlotYear && list.Count == 1) { YearRange yearRng = new YearRange(Explorer.PlotYear, Explorer.BeginningMonth); DateTime t1 = yearRng.DateTime1; DateTime t2 = yearRng.DateTime2; Series s = Math.Subset(list[0], t1, t2); s.Appearance.LegendText = yearRng.Year.ToString(); view.Messages.Add(yearRng.Year.ToString() + " included as separate series "); myList.Add(s); myList.Add(list.SummaryHydrograph(Explorer.ExceedanceLevels, t1, Explorer.PlotMax, Explorer.PlotMin, Explorer.PlotAvg, true));//,true)); } else { DateTime t = new DateTime(DateTime.Now.Year, Explorer.BeginningMonth, 1); myList = list.SummaryHydrograph(Explorer.ExceedanceLevels, t, Explorer.PlotMax, Explorer.PlotMin, Explorer.PlotAvg, true);//,true); } Explorer.WriteProgressMessage("drawing graph", 80); view.Title = title; view.SubTitle = subTitle; view.SeriesList = myList; view.DataTable = myList.ToDataTable(true); //view.Draw(); return(view); }
public void CompositeTable2() { SeriesList list = new SeriesList(); list.Add(TestData.Simple1Day); list.Add(TestData.Simple2Day); DataTable t2 = list.ToDataTable(list.Count > 1); Assert.IsTrue(t2.Rows.Count == 6); }
public override IExplorerView Run() { Logger.WriteLine("SummaryHydrographAnalysis.Run()"); SeriesList list = Explorer.CreateSelectedSeries(); ReadSeriesList(list); if (Explorer.SelectedSeries.Length == 1 && Explorer.MergeSelected) { // merge single Year Traces. list.RemoveMissing(); var s = list.MergeYearlyScenarios(); list = new SeriesList(); list.Add(s); } view.Messages.Add(list.MissingRecordsMessage); string title = list.Text.TitleText(); string subTitle = list.MissingRecordsMessage; SeriesList myList = new SeriesList(); list.RemoveMissing(); if (Explorer.AlsoPlotYear && list.Count == 1) { YearRange yearRng = new YearRange(Explorer.PlotYear, Explorer.BeginningMonth); DateTime t1 = yearRng.DateTime1; DateTime t2 = yearRng.DateTime2; Series s = Math.Subset(list[0], t1, t2); s.Appearance.LegendText = yearRng.Year.ToString(); view.Messages.Add(yearRng.Year.ToString() + " included as separate series "); myList.Add(s); myList.Add(list.SummaryHydrograph(Explorer.ExceedanceLevels, t1, Explorer.PlotMax, Explorer.PlotMin, Explorer.PlotAvg,true));//,true)); } else { DateTime t = new DateTime(DateTime.Now.Year, Explorer.BeginningMonth, 1); myList = list.SummaryHydrograph(Explorer.ExceedanceLevels, t, Explorer.PlotMax, Explorer.PlotMin, Explorer.PlotAvg,true);//,true); } Explorer.WriteProgressMessage("drawing graph", 80); view.Title = title; view.SubTitle = subTitle; view.SeriesList = myList; view.DataTable = myList.ToDataTable(true); //view.Draw(); return view; }
/// <summary> /// Print the daily data from the Series List /// </summary> /// <param name="list"></param> Series list private static void PrintDaily(SeriesList list) { var tbl = list.ToDataTable(false); if (tbl.Rows.Count == 0) { return; } var t1 = list.MinDateTime; var t2 = list.MaxDateTime; var title = "\nStation Parameter "; var title2 = "========= ========== ========= ========= ========= ========= ========="; DateTime t = t1; while (t <= t2) { title += t.ToString("ddd MMMdd"); title += " "; t = t.AddDays(1); } Console.WriteLine(title); Console.WriteLine(title2); foreach (var item in list) { string x = item.SiteID.PadRight(10) + " " + item.Parameter.PadRight(11) + " "; t = t1; while (t <= t2) { var idx = item.IndexOf(t); if (idx < 0) { x += "".PadLeft(10); } else { x += item[t].Value.ToString("F2").PadLeft(10); } t = t.AddDays(1); } Console.WriteLine(x); } }
public override IExplorerView Run() { Logger.WriteLine("WaterYearsAnalysis.Run()"); SeriesList list = Explorer.CreateSelectedSeries(); // Note: we do not call ReadSeriesList(list) SeriesList wySeries = PiscesAnalysis.WaterYears(list, Explorer.WaterYears, Explorer.ThirtyYearAverage, Explorer.BeginningMonth); Explorer.WriteProgressMessage("drawing graph", 80); view.Title = list.Text.TitleText(); view.SubTitle = list.MissingRecordsMessage; view.SeriesList = wySeries; view.DataTable = wySeries.ToDataTable(true); //view.Draw(); return(view); }
private static void MonthlyCalculation(SpreadsheetRange ssRng, string cbtt, string pcode) { var db = Database.DB(); CalculationSeries series = db.GetCalculationSeries(cbtt, pcode, TimeInterval.Monthly); if (series == null) { return; } var rng = ssRng.SelectedDateRange; series.Calculate(rng.DateTime1.FirstOfMonth(), rng.DateTime2.EndOfMonth()); series.Name = "new"; var old = ssRng.SelectionToMonthlySeries(false); old.Name = "old"; var diff = series - old; diff.Name = "Difference"; var list = new SeriesList(); list.Add(series); list.Add(old); list.Add(diff); var dlg = new MonthlyCalculationPreview(); dlg.DataSource = list.ToDataTable(true); if (dlg.ShowDialog() == DialogResult.OK) { // insert into range.. ssRng.InsertSeriesValues(series, dlg.SelectedFlag); } }
public void CompositeTable1() { SeriesList list = new SeriesList(); Series s1 = TestData.Simple1Day; list.Add(s1); DataTable t2 = list.ToDataTable(false); Assert.IsTrue(t2.Equals(list[0].Table), "expected original table to be retured. not a copy"); Assert.IsTrue(t2.Rows.Count == TestData.Simple1Day.Count, "must have same number of rows if only 1 table"); Series s = new Series(t2, "", TimeInterval.Irregular); for (int i = 0; i < s.Count; i++) { Assert.IsTrue(System.Math.Abs(s[i].Value - s1[i].Value) < 0.0000000001); Assert.IsTrue(s[i].DateTime == s1[i].DateTime); } }
internal Series ConvertToDaily() { Series estimatedDaily = new Series(); estimatedDaily.HasFlags = true; estimatedDaily.TimeInterval = TimeInterval.Daily; if (FillMissingWithZero) { daily = Math.FillMissingWithZero(daily, daily.MinDateTime, daily.MaxDateTime); } else { daily.RemoveMissing(); } //daily.RemoveMissing(); //int[] levels = {5,10,20,30,40,50,60,70,80,90,95}; //int[] levels = {10,20,30,40,50,60,70,80,90}; List <int> levels = new List <int>(); if (MedianOnly) { levels.Add(50); } else { for (int i = 5; i <= 95; i += 2) { levels.Add(i); } } var sHydrograph = Math.SummaryHydrograph(daily, levels.ToArray(), new DateTime(2008, 1, 1), false, false, false, false);//, false); var summaryHydrographTable = sHydrograph.ToDataTable(true); for (int i = 1; i < summaryHydrographTable.Columns.Count; i++) { summaryHydrographTable.Columns[i].ColumnName = levels[i - 1].ToString(); } //DataTableOutput.Write(summaryHydrographTable, @"c:\temp\junk.csv", false); SeriesList monthlySum = new SeriesList(); for (int i = 0; i < sHydrograph.Count; i++) { Series sum = Math.MonthlyValues(sHydrograph[i], Math.Sum); sum.Name = levels[i].ToString(); monthlySum.Add(sum); } var monthlyExceedanceSums = monthlySum.ToDataTable(true); if (monthlySum.Count == 1 && levels.Count == 1) { monthlyExceedanceSums.Columns[1].ColumnName = levels[0].ToString(); } var monthlyTable = monthly.Table; DateTime t = monthly.MinDateTime; DateTime t2 = monthly.MaxDateTime; t2 = new DateTime(t2.Year, t2.Month, DateTime.DaysInMonth(t2.Year, t2.Month)); while (t < t2) { var tm = new DateTime(t.Year, t.Month, 1); if (monthly.IndexOf(tm) < 0) { estimatedDaily.AddMissing(t); } else { double mv = monthly[tm].Value; double mvcfsdays = mv / 1.98347; double exceedanceValue = 0; int exceedancePercent = LookupExceedance(monthlyExceedanceSums, t, mvcfsdays, out exceedanceValue); double ratio = 0; if (exceedanceValue != 0) { ratio = mvcfsdays / exceedanceValue; } else { ratio = 0; } double shcfs = LookupSummaryHydrograph(summaryHydrographTable, t, exceedancePercent); estimatedDaily.Add(t, shcfs * ratio, "scaled with " + exceedancePercent + "%"); } t = t.AddDays(1); } VerifyWithMonthlyVolume(monthly, estimatedDaily); // SmoothSpikes(monthly, daily, estimatedDaily); return(estimatedDaily); }
public override IExplorerView Run() { Logger.WriteLine("TraceAnalysis.Run()"); SeriesList list = Explorer.CreateSelectedSeries(); ReadSeriesList(list); string title = list.Text.TitleText(); string subTitle = list.MissingRecordsMessage; // [JR] don't perform trace analysis if trace count < 10... if (list.Count < 10) { view.Messages.Add("Trace exceedance analysis is not available if trace count < 10"); view.Title = title; view.SubTitle = subTitle; view.SeriesList = list; view.DataTable = list.ToDataTable(true); return(view); } // This seems to be common between all the analysis options if (Explorer.SelectedSeries.Length == 1 && Explorer.MergeSelected) { // merge single Year Traces. list.RemoveMissing(); var s = list.MergeYearlyScenarios(); list = new SeriesList(); list.Add(s); } view.Messages.Add(list.MissingRecordsMessage); list.RemoveMissing(); // Initialize the output container SeriesList traceAnalysisList = new SeriesList(); // Get exceedance curves if (Explorer.traceExceedanceAnalysis) { traceAnalysisList = getTraceExceedances(list, Explorer.ExceedanceLevels, Explorer.AlsoPlotTrace, Explorer.PlotTrace, Explorer.PlotMinTrace, Explorer.PlotAvgTrace, Explorer.PlotMaxTrace); } // Get aggregated values if (Explorer.traceAggregationAnalysis) { string sumType = ""; if (Explorer.sumCYRadio) { sumType = "CY"; } else if (Explorer.sumWYRadio) { sumType = "WY"; } else if (Explorer.sumCustomRangeRadio) { sumType = "XX"; } else { } traceAnalysisList = getTraceSums(list, sumType); } // [JR] Add other analysis/report building options here... Explorer.WriteProgressMessage("drawing graph", 80); view.Title = title; view.SubTitle = subTitle; view.SeriesList = traceAnalysisList; view.DataTable = traceAnalysisList.ToDataTable(true); //view.Draw(); return(view); }
/// <summary> /// Build a SeriesList with the trace exceedances /// </summary> /// <param name="sListIn"></param> /// <param name="excLevels"></param> /// <param name="xtraTraceCheck"></param> /// <param name="xtraTrace"></param> /// <returns></returns> private SeriesList getTraceExceedances(SeriesList sListIn, int[] excLevels, bool xtraTraceCheck, string xtraTrace, bool plotMinTrace, bool plotAvgTrace, bool plotMaxTrace) { SeriesList traceAnalysisList = new SeriesList(); // Define the index numbers from the serieslist wrt the selected exceedance level List <int> sExcIdxs = new List <int>(); foreach (var item in excLevels) { var sNew = new Series(); sNew.TimeInterval = sListIn[0].TimeInterval; sNew.Units = sListIn[0].Units; sNew.ScenarioName = item + "%Exceedance"; traceAnalysisList.Add(sNew); int excIdx; if (item > 50) { excIdx = Convert.ToInt16(System.Math.Ceiling(sListIn.Count * (100.0 - Convert.ToDouble(item)) / 100.0)); } else { excIdx = Convert.ToInt16(System.Math.Floor(sListIn.Count * (100.0 - Convert.ToDouble(item)) / 100.0)); } sExcIdxs.Add(excIdx); } // Add min trace if selected if (plotMinTrace) { var sNew = new Series(); sNew.TimeInterval = sListIn[0].TimeInterval; sNew.Units = sListIn[0].Units; sNew.ScenarioName = "Min"; traceAnalysisList.Add(sNew); sExcIdxs.Add(0); } // Add max trace if selected if (plotMaxTrace) { var sNew = new Series(); sNew.TimeInterval = sListIn[0].TimeInterval; sNew.Units = sListIn[0].Units; sNew.ScenarioName = "Max"; traceAnalysisList.Add(sNew); sExcIdxs.Add(sListIn.Count - 1); } // Define average trace container var sAvg = new Series(); sAvg.TimeInterval = sListIn[0].TimeInterval; sAvg.Units = sListIn[0].Units; sAvg.ScenarioName = "Avg"; // Populate the output serieslist with the exceddance curves var dTab = sListIn.ToDataTable(true); for (int i = 0; i < dTab.Rows.Count; i++) { var dRow = dTab.Rows[i]; DateTime t = DateTime.Parse(dRow[0].ToString()); var values = dRow.ItemArray; // Put the ith timestep values in a C# List and sort by ascending var valList = new List <double>(); var valSum = 0.0; for (int j = 1; j < values.Length; j++) { valList.Add(Convert.ToDouble(values[j].ToString())); valSum += Convert.ToDouble(values[j].ToString()); } valList.Sort(); // Grab the index corresponding to the selected exceedance level and populate the output serieslist for (int j = 0; j < sExcIdxs.Count; j++) { traceAnalysisList[j].Add(t, valList[sExcIdxs[j]], "interpolated"); } // Populate the average trace series if (plotAvgTrace) { sAvg.Add(t, valSum / valList.Count, "interpolated"); } } // Add average trace if selected if (plotAvgTrace) { traceAnalysisList.Add(sAvg); } // Add an extra reference trace if defined if (xtraTraceCheck) { //xtraTrace contains the run name "Name" var scenarioTable = Explorer.Database.GetSelectedScenarios(); var selectedScenarioRow = scenarioTable.Select("[Name] = '" + xtraTrace + "'")[0]; int selectedIdx = scenarioTable.Rows.IndexOf(selectedScenarioRow); //scenariosTable.Rows.IndexOf( if (xtraTrace == "") { throw new Exception("Select an additional trace that is between 1 and the total number of traces"); } else { traceAnalysisList.Add(sListIn[selectedIdx]); } } return(traceAnalysisList); }
/// <summary> /// Print the 15 minute data from the Series List /// </summary> /// <param name="list"></param> private static void PrintInstant(SeriesList list) { var table = list.ToDataTable(false); TablePrinter.Print(table, 4); }
public override IExplorerView Run() { Logger.WriteLine("SummaryHydrographAnalysis.Run()"); SeriesList list = Explorer.CreateSelectedSeries(); ReadSeriesList(list); if (Explorer.SelectedSeries.Length == 1 && Explorer.MergeSelected) { // merge single Year Traces. list.RemoveMissing(); var s = list.MergeYearlyScenarios(); list = new SeriesList(); list.Add(s); } view.Messages.Add(list.MissingRecordsMessage); string title = list.Text.TitleText(); string subTitle = list.MissingRecordsMessage; SeriesList myList = new SeriesList(); list.RemoveMissing(); if (Explorer.AlsoPlotYear && list.Count == 1) { int[] yearsToPlot = Explorer.PlotYear; int xtraYearCount = 0; DateTime tSumHyd1 = DateTime.Now; DateTime tSumHyd2 = DateTime.Now; foreach (var year in yearsToPlot) { YearRange yearRng = new YearRange(year, Explorer.BeginningMonth); DateTime t1 = yearRng.DateTime1; DateTime t2 = yearRng.DateTime2; Series s = Math.Subset(list[0], t1, t2); if (xtraYearCount == 0)//first series { s.Appearance.LegendText = yearRng.Year.ToString(); view.Messages.Add(yearRng.Year.ToString() + " included as separate series "); myList.Add(s); if (yearsToPlot.Length == 1) { myList.Add(list.SummaryHydrograph(Explorer.ExceedanceLevels, t1, Explorer.PlotMax, Explorer.PlotMin, Explorer.PlotAvg, true)); } else { myList.Add(list.SummaryHydrograph(new int[] { }, t1, false, false, false, true)); } tSumHyd1 = t1; tSumHyd2 = t2; } else//every series { Series sDummy = new Series(); foreach (Point pt in s) { if (!(pt.DateTime.Month == 2 && pt.DateTime.Day == 29)) //sigh... leap days... { sDummy.Add(pt.DateTime.AddYears(tSumHyd1.Year - t1.Year), pt.Value); } } sDummy.TimeInterval = s.TimeInterval; sDummy.Name = s.Name; sDummy.Units = s.Units; sDummy.Parameter = s.Parameter; sDummy.Appearance.LegendText = yearRng.Year.ToString();; view.Messages.Add(yearRng.Year.ToString() + " included as separate series "); myList.Add(sDummy); if (xtraYearCount == yearsToPlot.Length - 1)//last series { myList.Add(list.SummaryHydrograph(Explorer.ExceedanceLevels, tSumHyd1, Explorer.PlotMax, Explorer.PlotMin, Explorer.PlotAvg, true)); } else { myList.Add(list.SummaryHydrograph(new int[] { }, tSumHyd1, false, false, false, true)); } } xtraYearCount++; } } else { DateTime t = new DateTime(DateTime.Now.Year, Explorer.BeginningMonth, 1); myList = list.SummaryHydrograph(Explorer.ExceedanceLevels, t, Explorer.PlotMax, Explorer.PlotMin, Explorer.PlotAvg, true);//,true); } Explorer.WriteProgressMessage("drawing graph", 80); view.Title = title; view.SubTitle = subTitle; view.SeriesList = myList; view.DataTable = myList.ToDataTable(true); //view.Draw(); return(view); }
/// <summary> /// Print the 15 minute data from the Series List /// </summary> /// <param name="list"></param> private static void PrintInstant(SeriesList list) { var table = list.ToDataTable(false); TablePrinter.Print(table, 3); }
public override IExplorerView Run() { Logger.WriteLine("TraceAnalysis.Run()"); SeriesList list = Explorer.CreateSelectedSeries(); ReadSeriesList(list); string title = list.Text.TitleText(); string subTitle = list.MissingRecordsMessage; // [JR] don't perform trace analysis if trace count < 10... if (list.Count < 10) { view.Messages.Add("Trace exceedance analysis is not available if trace count < 10"); view.Title = title; view.SubTitle = subTitle; view.SeriesList = list; view.DataTable = list.ToDataTable(true); return view; } // This seems to be common between all the analysis options if (Explorer.SelectedSeries.Length == 1 && Explorer.MergeSelected) { // merge single Year Traces. list.RemoveMissing(); var s = list.MergeYearlyScenarios(); list = new SeriesList(); list.Add(s); } view.Messages.Add(list.MissingRecordsMessage); list.RemoveMissing(); // Initialize the output container SeriesList traceAnalysisList = new SeriesList(); // Get exceedance curves if (Explorer.traceExceedanceAnalysis) { traceAnalysisList = getTraceExceedances(list, Explorer.ExceedanceLevels, Explorer.AlsoPlotTrace, Explorer.PlotTrace, Explorer.PlotMinTrace, Explorer.PlotAvgTrace, Explorer.PlotMaxTrace); } // Get aggregated values if (Explorer.traceAggregationAnalysis) { string sumType = ""; if (Explorer.sumCYRadio) { sumType = "CY"; } else if (Explorer.sumWYRadio) { sumType = "WY"; } else if (Explorer.sumCustomRangeRadio) { sumType = "XX"; } else { } traceAnalysisList = getTraceSums(list, sumType); } // [JR] Add other analysis/report building options here... Explorer.WriteProgressMessage("drawing graph", 80); view.Title = title; view.SubTitle = subTitle; view.SeriesList = traceAnalysisList; view.DataTable = traceAnalysisList.ToDataTable(true); //view.Draw(); return view; }
/// <summary> /// Build a SeriesList with the trace exceedances /// </summary> /// <param name="sListIn"></param> /// <param name="excLevels"></param> /// <param name="xtraTraceCheck"></param> /// <param name="xtraTrace"></param> /// <returns></returns> private SeriesList getTraceExceedances(SeriesList sListIn, int[] excLevels, bool xtraTraceCheck, string xtraTrace, bool plotMinTrace, bool plotAvgTrace, bool plotMaxTrace) { SeriesList traceAnalysisList = new SeriesList(); // Define the index numbers from the serieslist wrt the selected exceedance level List<int> sExcIdxs = new List<int>(); foreach (var item in excLevels) { var sNew = new Series(); sNew.TimeInterval = sListIn[0].TimeInterval; sNew.Units = sListIn[0].Units; sNew.ScenarioName = item + "%Exceedance"; traceAnalysisList.Add(sNew); int excIdx; if (item > 50) { excIdx = Convert.ToInt16(System.Math.Ceiling(sListIn.Count * (100.0 - Convert.ToDouble(item)) / 100.0)); } else { excIdx = Convert.ToInt16(System.Math.Floor(sListIn.Count * (100.0 - Convert.ToDouble(item)) / 100.0)); } sExcIdxs.Add(excIdx); } // Add min trace if selected if (plotMinTrace) { var sNew = new Series(); sNew.TimeInterval = sListIn[0].TimeInterval; sNew.Units = sListIn[0].Units; sNew.ScenarioName = "Min"; traceAnalysisList.Add(sNew); sExcIdxs.Add(0); } // Add max trace if selected if (plotMaxTrace) { var sNew = new Series(); sNew.TimeInterval = sListIn[0].TimeInterval; sNew.Units = sListIn[0].Units; sNew.ScenarioName = "Max"; traceAnalysisList.Add(sNew); sExcIdxs.Add(sListIn.Count - 1); } // Define average trace container var sAvg = new Series(); sAvg.TimeInterval = sListIn[0].TimeInterval; sAvg.Units = sListIn[0].Units; sAvg.ScenarioName = "Avg"; // Populate the output serieslist with the exceddance curves var dTab = sListIn.ToDataTable(true); for (int i = 0; i < dTab.Rows.Count; i++) { var dRow = dTab.Rows[i]; DateTime t = DateTime.Parse(dRow[0].ToString()); var values = dRow.ItemArray; // Put the ith timestep values in a C# List and sort by ascending var valList = new List<double>(); var valSum = 0.0; for (int j = 1; j < values.Length; j++) { valList.Add(Convert.ToDouble(values[j].ToString())); valSum += Convert.ToDouble(values[j].ToString()); } valList.Sort(); // Grab the index corresponding to the selected exceedance level and populate the output serieslist for (int j = 0; j < sExcIdxs.Count; j++) { traceAnalysisList[j].Add(t, valList[sExcIdxs[j]],"interpolated"); } // Populate the average trace series if (plotAvgTrace) { sAvg.Add(t, valSum / valList.Count, "interpolated"); } } // Add average trace if selected if (plotAvgTrace) { traceAnalysisList.Add(sAvg); } // Add an extra reference trace if defined if (xtraTraceCheck) { //xtraTrace contains the run name "Name" var scenarioTable = Explorer.Database.GetSelectedScenarios(); var selectedScenarioRow = scenarioTable.Select("[Name] = '" + xtraTrace + "'")[0]; int selectedIdx = scenarioTable.Rows.IndexOf(selectedScenarioRow); //scenariosTable.Rows.IndexOf( if (xtraTrace == "") { throw new Exception("Select an additional trace that is between 1 and the total number of traces"); } else { traceAnalysisList.Add(sListIn[selectedIdx]); } } return traceAnalysisList; }
internal Series ConvertToDaily() { Series estimatedDaily = new Series(); estimatedDaily.HasFlags = true; estimatedDaily.TimeInterval = TimeInterval.Daily; if (FillMissingWithZero) { daily = Math.FillMissingWithZero(daily, daily.MinDateTime, daily.MaxDateTime); } else { daily.RemoveMissing(); } //daily.RemoveMissing(); //int[] levels = {5,10,20,30,40,50,60,70,80,90,95}; //int[] levels = {10,20,30,40,50,60,70,80,90}; List<int> levels = new List<int>(); if (MedianOnly) { levels.Add(50); } else { for (int i = 5; i <= 95; i += 2) { levels.Add(i); } } var sHydrograph = Math.SummaryHydrograph(daily, levels.ToArray(), new DateTime(2008, 1, 1), false, false, false, false);//, false); var summaryHydrographTable = sHydrograph.ToDataTable(true); for (int i = 1; i < summaryHydrographTable.Columns.Count; i++) { summaryHydrographTable.Columns[i].ColumnName = levels[i - 1].ToString(); } //DataTableOutput.Write(summaryHydrographTable, @"c:\temp\junk.csv", false); SeriesList monthlySum = new SeriesList(); for (int i = 0; i < sHydrograph.Count; i++) { Series sum = Math.MonthlyValues(sHydrograph[i], Math.Sum); sum.Name = levels[i].ToString(); monthlySum.Add(sum); } var monthlyExceedanceSums = monthlySum.ToDataTable(true); if (monthlySum.Count == 1 && levels.Count == 1) monthlyExceedanceSums.Columns[1].ColumnName = levels[0].ToString(); var monthlyTable = monthly.Table; DateTime t = monthly.MinDateTime; DateTime t2 = monthly.MaxDateTime; t2 = new DateTime(t2.Year, t2.Month, DateTime.DaysInMonth(t2.Year, t2.Month)); while (t < t2) { var tm = new DateTime(t.Year, t.Month, 1); if (monthly.IndexOf(tm) < 0) { estimatedDaily.AddMissing(t); } else { double mv = monthly[tm].Value; double mvcfsdays = mv / 1.98347; double exceedanceValue = 0; int exceedancePercent = LookupExceedance(monthlyExceedanceSums, t, mvcfsdays, out exceedanceValue); double ratio = 0; if (exceedanceValue != 0) ratio = mvcfsdays / exceedanceValue; else ratio = 0; double shcfs = LookupSummaryHydrograph(summaryHydrographTable, t, exceedancePercent); estimatedDaily.Add(t, shcfs * ratio,"scaled with "+exceedancePercent+"%"); } t = t.AddDays(1); } VerifyWithMonthlyVolume(monthly, estimatedDaily); // SmoothSpikes(monthly, daily, estimatedDaily); return estimatedDaily; }