Esempio n. 1
0
        private void AddStatistics(SeriesList wyList)
        {
            bool anyStats = checkBoxMax.Checked || checkBoxMin.Checked || checkBoxAvg.Checked;

            if (!anyStats)
            {
                return;
            }

            int y1 = 1990;
            int y2 = 2011;

            int.TryParse(this.textBoxWY1.Text, out y1);
            int.TryParse(this.textBoxWY2.Text, out y2);

            DateTime t1 = new DateTime(y1 - 1, 10, 1);
            DateTime t2 = new DateTime(y2, 9, 30);

            var    server = HydrometInfoUtility.HydrometServerFromPreferences();
            Series s      = new HydrometDailySeries(comboBoxCbtt.Text.Trim(), DeterminePcode(), server);

            s.Read(t1, t2);
            s.RemoveMissing();
            s.Appearance.LegendText = "";

            YearRange yr   = new YearRange(2000, 10);
            var       list = Math.SummaryHydrograph(s, new int[] { }, yr.DateTime1, checkBoxMax.Checked, checkBoxMin.Checked, checkBoxAvg.Checked, false); //, false);


            wyList.Add(list);
        }
        public void UofIDisaggregation()
        {
            SQLiteServer       pDB = new SQLiteServer(path);
            TimeSeriesDatabase DB  = new TimeSeriesDatabase(pDB, false);

            // Reads input data required by the calculation
            Series daily = DB.GetSeriesFromName("SS_Day_Mean");

            daily.Read();// Source Station Daily data
            Series monthly = DB.GetSeriesFromName("TS_Mon_Mean");

            monthly.Read();// Target Station Monthly data
            Series known = DB.GetSeriesFromName("C#Disaggregated");

            known.Read(t1, t2);

            Series infilled = Disaggregation.RMSEInterp(daily, monthly);
            var    s        = infilled.Subset(t1, t2);

            s.TimeInterval = TimeInterval.Daily;

            var diff = Math.Sum(known - s);

            Assert.IsTrue(System.Math.Abs(diff) < 0.01, "Error");
        }
Esempio n. 3
0
        public void TestMethod1()
        {
            string fn = Path.Combine(TestData.DataPath, "SimpleResponseFunction.xls");

            var diversion = new ExcelDataReaderSeries(fn, "Sheet1", "Date", "Input");

            diversion.Read();
            var expected = new ExcelDataReaderSeries(fn, "Sheet1", "Date", "ExpectedResponse");

            expected.Read();

            var responseFunction = new ExcelDataReaderSeries(fn, "Sheet1", "Date", "ResponseFunction");

            responseFunction.Read();

            Console.WriteLine(" responseFunction has " + responseFunction.Count + " points");
            Console.WriteLine("diversion has " + diversion.Count);

            Series lag = Math.RoutingWithLags(diversion, responseFunction.Values);

            Assert.AreEqual(7, lag.Count);

            lag.WriteToConsole();
            if (lag.Count != expected.Count)
            {
                Console.WriteLine("Error: expected count not the same as lag count");
            }

            double sumDiff = System.Math.Abs(Math.Sum(expected - lag));

            Console.WriteLine("Sum of difference = " + sumDiff);
            Assert.AreEqual(0, sumDiff, 0.0000001);
        }
        public void TestRMSEMassBalance()
        {
            SQLiteServer       pDB = new SQLiteServer(path);
            TimeSeriesDatabase DB  = new TimeSeriesDatabase(pDB, false);

            // Reads input data required by the calculation
            Series daily   = DB.GetSeriesFromName("CHEI_QD");
            Series monthly = DB.GetSeriesFromName("CHEI_QM");

            daily.Read();
            monthly.Read();

            // disaggregated daily summed to monthly acre-feet
            Series infilled = Disaggregation.RMSEInterp(daily, monthly);
            Series infilledMonthlySumAcreFeet = Math.MonthlySum(infilled) * 1.98347;

            infilledMonthlySumAcreFeet.TimeInterval = TimeInterval.Monthly;

            // get equal time period for infilled data to original monthly data
            Series s = infilledMonthlySumAcreFeet.Subset(monthly.MinDateTime, monthly.MaxDateTime);

            var diff = System.Math.Abs(Math.Sum(monthly - s));

            Assert.IsTrue(diff < 0.01, "UofI RMSEInterp mass balance failed by: " + diff);
        }
Esempio n. 5
0
        public void InvalidAddition()
        {
            Series s1 = new Series(null, "cfs", TimeInterval.Daily);
            Series s2 = new Series(null, "cfs", TimeInterval.Monthly);

            Assert.Throws <InvalidOperationException>(() => Math.Add(s1, s2));
        }
Esempio n. 6
0
        public void UofIInterpolation()
        {
            SQLiteServer       pDB = new SQLiteServer(path);
            TimeSeriesDatabase DB  = new TimeSeriesDatabase(pDB);

            // Reads input data required by the calculation
            Series daily   = DB.GetSeriesFromName("SS_Day_Mean");
            Series monthly = DB.GetSeriesFromName("TS_Mon_Mean");
            Series known   = DB.GetSeriesFromName("C#Disaggregated-Interpolated");

            daily.Read();
            monthly.Read();
            known.Read(t1, t2);

            Series infilled = Math.UofIStreamflowDisaggregation(daily, monthly);
            var    s        = infilled.Subset(t1, t2);
            double diff     = 0.0;

            for (int i = 0; i < known.Count; i++)
            {
                diff += (known[i].Value - s[i].Value);
            }

            Assert.AreEqual(0.00, diff, 0.01);
        }
Esempio n. 7
0
        public void PartialDay()
        {
            string fn = Path.Combine(TestData.DataPath, "wilson.xls");
            var    s  = new ExcelDataReaderSeries(fn, "wilson", "A", "B");

            s.Read();

            Series avg = Math.TimeWeightedDailyAverage(s);
        }
Esempio n. 8
0
        public void DailyAverageTicksBug()
        {
            Series   s    = TestData.LindCouleeWW1InstantanousStage2004;
            DateTime date = DateTime.Parse("2004-01-02");
            Point    pt   = Math.TimeWeightedAverageForDay(s, date);

            Console.WriteLine(pt);
            Assert.AreEqual(0, pt.DateTime.Millisecond, "error #1");
        }
Esempio n. 9
0
        public void Site68OnefullDay()
        {
            Series s = TestData.Site68OneFullDayInstantaneous;

            Series avg = Math.TimeWeightedDailyAverage(s);

            avg.WriteToConsole();
            Assert.AreEqual(1, avg.Count); // should have 1 daily average
        }
Esempio n. 10
0
        public void SingleDayAverageBanks()
        {
            Console.WriteLine("SingleDayAverageBanks Test:  banks lake average water level may 17, 2005 (raw scada data)");
            Series   input = TestData.Banks;
            DateTime date  = new DateTime(2005, 5, 17);
            Point    point = Math.TimeWeightedAverageForDay(input, date);

            Console.WriteLine("Average from raw scada = " + point.Value);
            Assert.AreEqual(1568.5, point.Value, 0.1);
        }
Esempio n. 11
0
        public void SimpleAverageForDay()
        {
            Series input = TestData.Simple1Day;

            input.WriteToConsole();
            Series avg = Math.DailyAverage(input);

            avg.WriteToConsole();
            Assert.AreEqual(1, avg.Count);
            Assert.AreEqual(52.5, avg[0].Value, 0.0001);
        }
Esempio n. 12
0
        public void AverageForDay()
        {
            Series input = TestData.Simple1Day;

            input.WriteToConsole();
            Point pt = Math.TimeWeightedAverageForDay(input, input[0].DateTime);

            Assert.AreEqual(72.291667, pt.Value, 0.0001);

//--call cbp.Soi_DailyAverage('Records','value','2000-01-01','2025-01-01',0,null,0,0)
//-- result = 72.291667
        }
Esempio n. 13
0
        private static Series Get30YearAverageSeries(string cbtt, string pcode, int forecastMonth)
        {
            var t1 = HydrometDataUtility.T1Thirty;
            var t2 = HydrometDataUtility.T2Thirty;
            var s2 = new HydrometDailySeries(cbtt, pcode, HydrometHost.PNLinux);

            s2.Read(t1, t2);

            DateTime t    = new DateTime(2018, forecastMonth, 1);
            var      list = Math.SummaryHydrograph(s2, new int[] { }, t, false, false, true, false);

            return(list[0]);
        }
Esempio n. 14
0
        public void EntiatRiver()
        {
            Series s = TestData.EntiatRiver;

            Console.WriteLine(s.Count);
            Assert.AreEqual(3642, s.Count, "data count has changed!");

            Series sorted = Math.Sort(s, RankType.Weibul);

            TestEntiatRiverSortedValues(sorted);
            //sorted.WriteToConsole(false, true);
            //1822	50.01372495
        }
Esempio n. 15
0
        public void AverageWithFlags()
        {
            Series s = new Series();

            s.Add(DateTime.Parse("1/1/2013 12:30"), -55, "-");
            s.Add(DateTime.Parse("1/1/2013 13:00"), 1);
            s.Add(DateTime.Parse("1/1/2013 13:15"), 1);
            s.Add(DateTime.Parse("1/1/2013 14:01"), 500, "+");
            var avg = Math.DailyAverage(s, 2);

            avg.WriteToConsole();
            Assert.AreEqual(1, avg.Count);
            Assert.AreEqual(1, avg[0].Value, 0.01);
        }
Esempio n. 16
0
        public void TestMergeMassBalance()
        {
            SQLiteServer       pDB = new SQLiteServer(path);
            TimeSeriesDatabase DB  = new TimeSeriesDatabase(pDB, false);

            // Reads input data required by the calculation
            Series daily   = DB.GetSeriesFromName("CHEI_QD");
            Series monthly = DB.GetSeriesFromName("CHEI_QM");

            daily.Read();
            monthly.Read();

            // disaggregate and merge
            Series infilled = Disaggregation.RMSEInterp(daily, monthly);

            Disaggregation.MergeCheckMassBalance(daily, infilled);

            // generate series of monthly volumes only for months with a computed value,
            // these will be compared to the observed monthly
            Series partialMonthlyEstimated = new Series();

            for (int i = 0; i < infilled.Count; i++)
            {
                Point p = infilled[i];

                // Gets the data for the month
                int      numDays = DateTime.DaysInMonth(p.DateTime.Year, p.DateTime.Month);
                DateTime t1      = new DateTime(p.DateTime.Year, p.DateTime.Month, 1);
                DateTime t2      = new DateTime(p.DateTime.Year, p.DateTime.Month, numDays);

                if (p.Flag == PointFlag.Computed && partialMonthlyEstimated.IndexOf(t1) < 0)
                {
                    partialMonthlyEstimated.Add(t1, Math.Sum(infilled.Subset(t1, t2)) * 1.98347);
                }
            }

            // check observed against infilled for months where data was infilled
            double diff = 0.0;

            for (int i = 0; i < partialMonthlyEstimated.Count; i++)
            {
                DateTime estDate = partialMonthlyEstimated[i].DateTime;
                if (monthly.IndexOf(estDate) > 0)
                {
                    diff += (monthly[estDate].Value - partialMonthlyEstimated[estDate].Value);
                }
            }

            Assert.IsTrue(diff < 0.01, "UofI merge mass balance failed by: " + diff);
        }
Esempio n. 17
0
        public void SevenDay()
        {
            string fn = Path.Combine(TestData.DataPath, "sevendayavg.xls");
            var    s  = new ExcelDataReaderSeries(fn, "Sheet1", "A", "B");

            s.Read();
            Assert.AreEqual(2738, s.Count);
            var s7 = Math.WeeklyAverageSimple(s);

            s7.WriteToConsole();
            Assert.AreEqual(DateTime.Parse("2004-02-12 23:59:59.9"), s7[0].DateTime);
            Assert.AreEqual(2.17, s7[0].Value, 0.01);
            Assert.AreEqual(101.32, s7[1].Value, 0.01);
        }
Esempio n. 18
0
        public void Empty()
        {
            Series pp = new Series();

            pp.TimeInterval = TimeInterval.Daily;

            Series pu = new Series();

            pu.TimeInterval = TimeInterval.Daily;
            pu.Add(DateTime.Now, System.Math.PI);

            var x = Math.DailyWaterYearRunningTotal(pp, pu);

            Assert.AreEqual(0, x.Count);
        }
Esempio n. 19
0
        public void HourlyAverage()
        {
            Series s = new Series();

            s.Add("1/1/2013 12:30", 55);
            s.Add("1/1/2013 13:00", 1);
            s.Add("1/1/2013 13:15", 1);
            s.Add("1/1/2013 14:01", 500);
            var avg = Math.Average(s, TimeInterval.Hourly);

            avg.WriteToConsole();

            Assert.AreEqual(55, avg["1/1/2013 12:00:00"].Value);
            Assert.AreEqual(1, avg["1/1/2013 13:00:00"].Value);
            Assert.AreEqual(500, avg["1/1/2013 14:00:00"].Value);
        }
Esempio n. 20
0
        private void AddStatistics(SeriesList wyList)
        {
            bool anyStats = checkBoxMax.Checked || checkBoxMin.Checked || checkBoxAvg.Checked || checkBoxPctls.Checked;

            if (!anyStats)
            {
                return;
            }

            int y1 = 1990;
            int y2 = 2011;

            int[] pctls = new int[] { };

            int.TryParse(this.textBoxWY1.Text, out y1);
            int.TryParse(this.textBoxWY2.Text, out y2);

            if (checkBoxPctls.Checked)
            {
                try
                {
                    string   values = textBoxPctls.Text;
                    string[] tokens = values.Split(',');
                    pctls = Array.ConvertAll <string, int>(tokens, int.Parse);
                }
                catch
                {
                    pctls = new int[] { 10, 50, 90 };
                }
            }

            DateTime t1 = new DateTime(y1 - 1, 10, 1);
            DateTime t2 = new DateTime(y2, 9, 30);

            var    server = HydrometInfoUtility.HydrometServerFromPreferences();
            Series s      = new HydrometDailySeries(comboBoxCbtt.Text.Trim(), DeterminePcode(), server);

            s.Read(t1, t2);
            s.RemoveMissing();
            s.Appearance.LegendText = "";

            YearRange yr   = new YearRange(2000, 10);
            var       list = Math.SummaryHydrograph(s, pctls, yr.DateTime1, checkBoxMax.Checked, checkBoxMin.Checked, checkBoxAvg.Checked, false); //, false);


            wyList.Add(list);
        }
Esempio n. 21
0
        public void EntiatRiver24Points()
        {
            Series s = TestData.EntiatRiver24Points;

            Console.WriteLine(s.Count);
            Assert.AreEqual(24, s.Count, "data count has changed!");

            Series sorted = Math.Sort(s, RankType.Weibul);//new ExceedanceSeries(s);

            sorted.WriteToConsole(true, true);
            Assert.AreEqual(762, sorted[0].Value, 0.01, "Max value not sorted to top");

            Assert.AreEqual(487, sorted[sorted.Count - 1].Value, 0.01, "Max value not sorted to top");

            Assert.AreEqual(642, sorted[12].Value, 0.001, "  value ");
            Assert.AreEqual(52, sorted[12].Percent, 0.01, " percentage ");
        }
Esempio n. 22
0
        public void EntiatRiver()
        {
            Series s = new Series();

            DateTime t = new DateTime(2006, 5, 24);

            for (int i = 0; i < 365; i++)
            {
                s.Add(t, i);
                t = t.AddDays(1);
            }
            Series w = Math.ShiftToYear(s, 2000);

            Assert.AreEqual(2000, w[0].DateTime.Year);
            Assert.AreEqual(5, w[0].DateTime.Month);
            Assert.AreEqual(24, w[0].DateTime.Day);
        }
Esempio n. 23
0
        public void WrongInterval()
        {
            Series pp = new Series();

            pp.TimeInterval = TimeInterval.Irregular;
            pp.Add(DateTime.Now, DateTime.Now.Ticks);

            Series pu = new Series();

            pu.TimeInterval = TimeInterval.Irregular;
            pu.Add(DateTime.Now, DateTime.Now.Ticks);

            var ex = Assert.Throws <ArgumentException>(
                () => Math.DailyWaterYearRunningTotal(pp, pu));

            Assert.AreEqual("Error: arguments must both have daily interval", ex.Message);
        }
Esempio n. 24
0
        private static void Weekly(TextSeries s)
        {
            s.Read(DateTime.Parse("2/6/2004"), DateTime.Parse("12/31/2004"));

            double mf = Point.MissingValueFlag;

            Point.MissingValueFlag = -9999;
            s.RemoveMissing();
            Point.MissingValueFlag = mf;

            s.TimeInterval = TimeInterval.Daily;
            var weekly = Math.WeeklyAverageSimple(s);

            Assert.AreEqual(TimeInterval.Weekly, weekly.TimeInterval);

            Assert.AreEqual(DateTime.Parse("2/12/2004"), weekly[0].DateTime.Date);
            Assert.AreEqual(2.172, weekly[0].Value, 0.01);
        }
Esempio n. 25
0
        private static void SaveToDatabase(string[] args, TimeSeriesDatabase db, string cbtt,
                                           string pcode, Series s)
        {
            Series hmet;

            if (args[1] == "daily")
            {
                hmet = Math.HydrometDaily(cbtt, pcode);
            }
            else
            {
                hmet = Math.HydrometInstant(cbtt, pcode);
            }
            hmet.Read(s.MinDateTime, s.MaxDateTime);
            s.Units = hmet.Units;
            s.Name  = cbtt + "_" + pcode;
            db.AddSeries(s);
            db.AddSeries(hmet);
        }
Esempio n. 26
0
        public void SimpleAverageForDayOnly12Points()
        {
            Series input = new Series();

            DateTime t = DateTime.Now.Date.AddMinutes(15);

            for (int i = 0; i < 12; i++)
            {
                input.Add(t, i * 10);

                t = t.AddMinutes(2);
            }
            input.WriteToConsole();
            Series avg = Math.DailyAverage(input, 96);

            avg.WriteToConsole();
            Assert.AreEqual(1, avg.Count);
            Assert.IsTrue(avg[0].IsMissing);
        }
Esempio n. 27
0
        public void HeiseResidualTest()
        {
            //ExcelDataReaderSeries heii_qu = new ExcelDataReaderSeries(fn, "unregulation", "Date", "HEII_QU", "cfs");
            var heii_qu = new TextSeries(Path.Combine(TestData.DataPath, "heii_qu.csv"));

            heii_qu.Read();

            var heii_resid = Math.WaterYearResidual(heii_qu, 7);

            heii_resid.WriteToConsole();

            var expected = new TextSeries(Path.Combine(TestData.DataPath, "heii_residual.csv"));

            //var expected = new ExcelDataReaderSeries(fn, "unregulation", "Date", "HEII_RESID", "cfs");
            expected.Read();

            var diff = Math.Sum(heii_resid - expected);

            Assert.IsTrue(System.Math.Abs(diff) < 0.01);
        }
Esempio n. 28
0
        public void AnnualSumJanuaryThroughJuly()
        {
            string fn = TestData.DataPath + "\\heii_qd.csv";

            TextSeries ts = new TextSeries(fn);

            ts.Read();
            Console.WriteLine(ts.Count);

            Assert.AreEqual(28905, ts.Count, fn + " has been modified");
            MonthDayRange rng = new MonthDayRange(1, 1, 7, 31);
            Series        sum = Reclamation.TimeSeries.Math.AnnualSum(ts, rng, 10);

            sum.WriteToConsole();
            Assert.AreEqual(1928, sum[0].DateTime.Year);
            Assert.AreEqual(2293240, sum[0].Value);

            Series min = Math.AnnualMin(ts, rng, 10);
            Series max = Math.AnnualMax(ts, rng, 10);
        }
Esempio n. 29
0
        public void LindCoulee2004()
        {
            Series s = TestData.LindCouleeWW1InstantanousStage2004;
            //Point pt =  Math.Calculator.AverageForDay(s,DateTime.Parse("2004-12-20"));
            Series avg = Math.TimeWeightedDailyAverage(s);

            // Console.WriteLine("avg");
            //avg.WriteToConsole();
            Console.WriteLine(avg[0].DateTime.ToString("yyyy-MM-dd HH:mm:ss.ffff"));

            Console.WriteLine("Math.Calculator.DailyAverage(s).Count = " + avg.Count);

            Series dbAverage = TestData.LindCouleeWW1DailyAverageStage2004;

            Console.WriteLine("TestData.LindCouleeWW1DailyAverageStage2004.Count = " + dbAverage.Count);


            Series     diff = avg - dbAverage;
            SeriesList list = new SeriesList();

            list.Add(avg);
            list.Add(dbAverage);
            list.Add(diff);
            list.WriteToConsole();

            Console.WriteLine("summing difference");
            double d = Math.Sum(diff);

            Assert.AreEqual(0, d, 0.1); // actual is about 0.05
            Console.WriteLine("sum of differences = " + d);
            Console.WriteLine("sum of daily " + Math.Sum(avg));
            Assert.AreEqual(dbAverage.Count - 1, avg.Count);
            for (int i = 0; i < avg.Count; i++)
            {
                // database has one (missing) value at beginning we skip that in comparison
                Assert.AreEqual(dbAverage[i + 1].ToString(), avg[i].ToString());
                Assert.AreEqual(dbAverage[i + 1].Value, avg[i].Value, 0.0001);
                Assert.AreEqual(dbAverage[i + 1].DateTime.Ticks, avg[i].DateTime.Ticks, "on line " + i);
            }
        }
Esempio n. 30
0
        private static Series Get30YearAverageSeries(string cbtt, string pcode, int forecastMonth)
        {
            var t1 = HydrometDataUtility.T1Thirty;
            var t2 = HydrometDataUtility.T2Thirty;
            var s2 = new HydrometDailySeries(cbtt, pcode, HydrometHost.PNLinux);

            s2.Read(t1, t2);

            // Resolve current WY
            // [JR] Don't know why this was hard coded to the current WY...
            int currWY = DateTime.Now.Year;

            if (DateTime.Now.Month > 9)
            {
                //currWY = currWY + 1; //[JR] need to check what this does come January...
            }

            DateTime t    = new DateTime(currWY, forecastMonth, 1);
            var      list = Math.SummaryHydrograph(s2, new int[] { }, t, false, false, true, false);

            return(list[0]);
        }