/// <summary> /// Creates a list of Series , one subset for each day /// used for math functions that need subset by day /// </summary> /// <param name="s"></param> /// <returns></returns> private static Series DailySubsetCalculatorPoint(Series s, Func <Series, Point> func) { Series rval = new Series(); rval.TimeInterval = TimeInterval.Daily; DateTime t; if (s.Count > 0) { t = s[0].DateTime.Date; // midnight } else { return(rval); } while (t < s.MaxDateTime) { var subset = Math.Subset(s, new DateRange(t, t.AddDays(1)), false); subset.RemoveMissing(); if (subset.Count > 0) { Point pt = func(subset); rval.Add(t, pt.Value, PointFlag.Computed); } t = t.AddDays(1).Date; } return(rval); }
public static Series WaterYearResidual(Series inflow, int endMonth) { Series rval = new Series(); rval.TimeInterval = TimeInterval.Daily; if (inflow.Count < 0) { return(rval); } var y1 = inflow[0].DateTime.WaterYear(); var y2 = inflow[inflow.Count - 1].DateTime.WaterYear(); for (int wy = y1; wy <= y2; wy++) { DateTime t1 = new DateTime(wy - 1, 10, 1); int cy = wy; // calendar year if (endMonth > 9) { cy = wy - 1; } DateTime t2 = new DateTime(wy, endMonth, DateTime.DaysInMonth(cy, endMonth)); var singleYear = Math.Subset(inflow, t1, t2); var t = t1; while (t <= t2) { var sub = Math.Subset(singleYear, t, t2); var val = Math.Sum(sub); rval.Add(t, val); t = t.AddDays(1); } } return(rval); }
/// <summary> /// Function that averages a series based on a defined Time-Interval /// </summary> /// <param name="s">Input Series</param> /// <param name="tInterval">Averaging Time-Interval</param> /// <returns></returns> public static Series Average(Series s, TimeInterval tInterval) { Series rval = s.Clone(); if (s.Count == 0) { return(rval); } // Define starting date of averaging process DateTime t = new DateTime(s[0].DateTime.Year, s[0].DateTime.Month, s[0].DateTime.Day, s[0].DateTime.Hour, 0, 0); // Find which averaging process to accomplish if (tInterval == TimeInterval.Daily) { // Define series time-interval rval.TimeInterval = TimeInterval.Daily; // Loop through the dates while (t < s[s.Count - 1].DateTime.Date) { // Get the series subset based on the averaging time-interval Series sTemp = s.Subset(t, t.AddDays(1)); // Average the values of the subset DoAverage(rval, t, sTemp); // Increment DateTime by averaging time-interval t = t.AddDays(1); } } // Ditto on the other processes below else if (tInterval == TimeInterval.Monthly) { rval.TimeInterval = TimeInterval.Monthly; while (t < s[s.Count - 1].DateTime.Date) { Series sTemp = s.Subset(t, t.AddMonths(1)); DoAverage(rval, t, sTemp); t = t.AddMonths(1); } } else if (tInterval == TimeInterval.Hourly) { rval.TimeInterval = TimeInterval.Hourly; while (t < s.MaxDateTime) { Series sTemp = Math.Subset(s, new DateRange(t, t.AddHours(1)), false); DoAverage(rval, t, sTemp); t = t.AddHours(1); } } else { throw new Exception("Time Interval " + tInterval.ToString() + " not supported!"); } return(rval); }
/// <summary> /// Creates a list of Series , one subset for each day /// used for math functions that need subset by day /// </summary> /// <param name="s"></param> /// <returns></returns> private static Series DailySubsetCalculatorValue(Series s, Func <Series, double> func, int requiredNumberOfPoints = 0) { Series rval = new Series(); rval.TimeInterval = TimeInterval.Daily; DateTime t; if (s.Count > 0) { t = s[0].DateTime.Date; // midnight } else { return(rval); } while (t < s.MaxDateTime) { var subset = Math.Subset(s, new DateRange(t, t.AddDays(1)), false); subset.RemoveMissing(true); if (subset.Count < requiredNumberOfPoints) { Logger.WriteLine("Error: not enough data points " + s.Name); Logger.WriteLine("expected " + requiredNumberOfPoints + " points, but had only " + subset.Count); rval.AddMissing(t); } else if (subset.Count > 0) { double d = func(subset); rval.Add(t, d, PointFlag.Computed); } t = t.AddDays(1).Date; } return(rval); }
private static SeriesList FilterBySelectedRange(MonthDayRange range, SeriesList wyList) { SeriesList list = new SeriesList(); foreach (Series item in wyList) { //// bug fix: leap years shifted to year 2000 //// have extra data point in October of next year. //// delete this. //if (item.Count > 0 && item[0].DateTime.Month == 10 // && item[item.Count - 1].DateTime.Month == 10 // && range.Month2 != 10) //{ // item.ReadOnly = false; // item.RemoveAt(item.Count - 1); //} list.Add(Math.ShiftToYear(Math.Subset(item, range), 2000)); } return(list); }
/* * CHECK > run * * * MAX/MIN SUMMARY PROCESS DATE: 18-JUL-06 * * Station name RIR Begin and end year 1963-2006 * Parameter code QD Begin and end date OCT 1-SEP 30 * Option MAX * * YEAR DATE MAXIMUM DATE MINIMUM MISS * * 1963 FEB 3 700.00 AUG 30 6.10 0 * 1964 MAY 15 1570.00 OCT 5 17.00 0 * 1965 APR 24 1740.00 OCT 1 39.00 0 * 1966 APR 18 628.00 AUG 12 10.00 0 * 1967 MAY 11 1090.00 AUG 28 17.00 0 * 1968 MAY 3 814.00 NOV 28 21.00 0 * 1969 APR 25 2300.00 NOV 27 27.00 0 * 1970 MAY 19 1820.00 DEC 6 23.00 0 * 1971 MAY 4 2660.00 JAN 7 24.00 0 * 1972 MAY 9 1510.00 JAN 4 44.00 0 * 1973 MAY 6 1320.00 AUG 31 36.00 0 * 1974 APR 26 2170.00 AUG 12 1.20 0 * 1975 MAY 20 2290.00 MAY 7 23.00 0 * 1976 MAY 8 1520.00 JAN 6 0.27 0 * 1977 OCT 28 310.00 FEB 22 8.70 0 * 1978 AUG 3 206.00 NOV 30 4.50 0 * 1979 SEP 19 396.00 JAN 9 0.10 0 * 1980 JUN 4 415.00 JAN 1 0.00 0 * 1981 OCT 10 503.00 DEC 10 0.73 3 * 1982 MAY 20 1284.11 FEB 24 0.00 0 * 1983 MAY 27 1320.13 DEC 30 0.00 0 * 1984 MAY 22 1720.05 FEB 16 0.00 0 * 1985 APR 19 729.47 MAR 31 0.00 1 * 1986 MAY 7 1230.00 NOV 22 0.00 0 * 1987 OCT 11 592.00 DEC 11 0.00 0 * 1988 SEP 23 847.00 NOV 17 0.00 0 * 1989 SEP 23 871.00 NOV 2 0.00 0 * 1990 OCT 1 807.00 NOV 2 0.00 0 * 1991 SEP 24 571.00 NOV 23 0.00 0 * 1992 OCT 5 872.00 NOV 1 0.00 0 * 1993 SEP 29 773.00 NOV 3 0.00 0 * 1994 AUG 5 750.00 NOV 1 0.00 0 * 1995 MAY 26 478.00 NOV 1 0.00 0 * 1996 MAY 20 888.00 NOV 2 0.00 0 * 1997 MAY 7 1750.00 NOV 22 0.00 0 * 1998 MAY 24 745.00 NOV 13 0.00 0 * 1999 MAY 6 885.00 NOV 14 0.00 0 * 2000 OCT 6 414.00 NOV 30 0.00 0 * 2001 AUG 18 429.00 NOV 16 0.00 0 * 2002 AUG 29 455.00 OCT 1 0.00 0 * 2003 AUG 26 439.00 OCT 1 0.00 0 * 2004 AUG 31 348.20 OCT 1 0.00 0 * 2005 SEP 21 202.02 OCT 13 0.00 0 * 2006 MAY 2 1119.98 NOV 22 0.00 75 * * Avg of 44 yrs 1010.95 6.88 * */ /// <summary> /// Test annual sum and compare to check program /// VOLAF option for heise unregulated flow /// </summary> public void Vol_AF_HEII() { //heii_quAF.csv string fn = TestData.DataPath + @"\heii_quAF.csv"; TextSeries ts = new TextSeries(fn); ts.Read(); Assert.AreEqual(28916, ts.Count, "file has changed"); MonthDayRange r = new MonthDayRange(3, 12, 5, 1); Series sum = Math.AnnualSum(ts, r, 10); double[] expected = { 380313.47, 424559.03, 476518.66, 522272.94, 451835.38, 702204.13 }; // sum.WriteToConsole(); for (int yr = 2001; yr <= 2006; yr++) { DateTime t1 = new DateTime(yr, 1, 1); DateTime t2 = new DateTime(yr, 12, 31); Series sYear = Math.Subset(sum, t1, t2); Assert.AreEqual(expected[yr - 2001], sYear[0].Value, 3); } }
public static string[] UsgsMonthlyTextReport(Series s, bool showFlags, double scale = 1.0) { List <string> report = new List <string>(); if (s.TimeInterval != TimeInterval.Monthly) { report.Add("Error: " + s.Name + " is not Monthly."); return(report.ToArray()); } report.Add(""); report.Add(""); report.Add(""); report.Add(""); report.Add(""); report.Add(" UNITED STATES"); report.Add(" DEPARTMENT OF THE INTERIOR"); report.Add(" BUREAU OF RECLAMATION"); report.Add(""); report.Add(s.Name + " " + s.Parameter + " " + s.Units); report.Add(""); report.Add("Year Oct Nov Dec Jan Feb Mar Apr May Jun Jul Aug Sep Total"); report.Add(""); if (s.Count == 0) { return(report.ToArray()); } int wy1 = s[0].DateTime.WaterYear(); int wy2 = s[s.Count - 1].DateTime.WaterYear(); for (int wy = wy1; wy <= wy2; wy++) { string line = " " + wy.ToString() + " "; DateTime t1 = new DateTime(wy - 1, 10, 1); DateTime t2 = new DateTime(wy, 9, 1); DateTime t = t1; do { line += FormatValue(s, t, .001, showFlags); t = t.AddMonths(1).FirstOfMonth(); } while (t <= t2); var singleYear = Math.Subset(s, new DateRange(t1, t2)); // total if (singleYear.CountMissing() > 0) { line += " - "; } else { line += " " + (Math.Sum(singleYear) * .001).ToString("F2").PadLeft(9); } report.Add(line); } // All October var oct = Math.Subset(s, new int[] { 10 }); var sumOct = Math.Sum(oct); //var avgOct = Math.Average(oct, TimeInterval.Monthly); double avgOct = Math.AverageOfSeries(oct); return(report.ToArray()); }