Example #1
0
        public void AddBug()
        {
            DateTime           t1  = new DateTime(2013, 1, 1);
            var                t2  = t1.AddDays(365);
            var                fn  = FileUtility.GetTempFileNameInDirectory(@"c:\temp\", ".pdb");
            SQLiteServer       svr = new SQLiteServer(fn);
            TimeSeriesDatabase db  = new Reclamation.TimeSeries.TimeSeriesDatabase(svr, false);
            var                s   = new HydrometDailySeries("pal", "af");

            s.Name = "pal_af";
            s.Read(t1, t2);
            db.AddSeries(s);

            var cs = new CalculationSeries("add_test");

            cs.Expression = "pal_af + pal_af";
            db.AddSeries(cs);


            cs = db.GetSeriesFromName("add_test") as CalculationSeries;
            cs.Calculate(t1, t2);


            cs = db.GetSeriesFromName("add_test") as CalculationSeries;
            cs.Read();

            Assert.IsTrue(cs.Count > 0);
        }
        public void UofIInterpolation()
        {
            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");
            Series monthly = DB.GetSeriesFromName("TS_Mon_Mean");
            Series known   = DB.GetSeriesFromName("C#Disaggregated-Interpolated");

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

            Series infilled = Disaggregation.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);
        }
        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);
        }
        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");
        }
        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);
        }
        private static void AddForecastSeries(string period, string scenario,
                                          TimeSeriesDatabase dbVic, string name,
                                          int thruMonth, string vicName)
        {
            string fn = period + scenario + ".pdb";
            SQLiteServer svr = new SQLiteServer(fn);
            TimeSeriesDatabase db = new TimeSeriesDatabase(svr);

            Series sVic = dbVic.GetSeriesFromName(vicName + period + scenario);
            sVic.Read();

            Series s = new Series(name + "_Forecast");
            s.TimeInterval = TimeInterval.Monthly;
            s.TimeSeriesDatabase = db;
            s.Units = "acre-feet";

            //initial model data start date and value
            s.Add(sVic[0].DateTime, sVic[0].Value * 1.98347 * sVic[0].DateTime.EndOfMonth().Day);

            for (int i = 0; i < sVic.Count; i++)
            {
            int month = sVic[i].DateTime.Month;
            if (month <= 6)
            {
                Point pt = new Point();
                pt.DateTime = sVic[i].DateTime;
                pt.Value = SumThruMonthToAcreFt(sVic, pt.DateTime, thruMonth);
                s.Add(pt);
            }
            }

            db.AddSeries(s);
            SetSeriesDatesToBeginningOfMonth(s);
            ConsolePrintSeriesNameAndCount(s);
        }
Example #7
0
        private void ReadFromPisces()
        {
            Logger.WriteLine("opening " + m_dbName);
            SQLiteServer svr = new SQLiteServer(m_dbName);
            TimeSeriesDatabase db = new TimeSeriesDatabase(svr);

            SeriesList list = new SeriesList();

            for (int i = 0; i < m_seriesName.Count; i++)
            {
                Logger.WriteLine("looking for series '" + m_seriesName[i] + "'");
                var s = db.GetSeriesFromName(m_seriesName[i]);
                if (s != null)
                {
                    s.Read(m_t1, m_t2);
                    list.Add(s);
                }
                else
                {
                    throw new Exception("unable to find series '" + m_seriesName[i] + "' in pisces database '" + m_dbName + "'");
                }
            }

            WriteToRiverwareFiles(list);
        }
Example #8
0
        public void AddBug()
        {
            DateTime t1 = new DateTime(2013,1,1);
            var t2 = t1.AddDays(365);
            var fn = FileUtility.GetTempFileNameInDirectory(@"c:\temp\",".pdb");
            SQLiteServer svr = new SQLiteServer(fn);
            TimeSeriesDatabase db = new Reclamation.TimeSeries.TimeSeriesDatabase(svr,false);
            var s = new HydrometDailySeries("pal","af");
            s.Name = "pal_af";
            s.Read(t1,t2);
            db.AddSeries(s);

            var cs = new CalculationSeries("add_test");
            cs.Expression = "pal_af + pal_af";
            db.AddSeries(cs);

            cs = db.GetSeriesFromName("add_test") as CalculationSeries;
            cs.Calculate(t1, t2);

            cs = db.GetSeriesFromName("add_test") as CalculationSeries;
            cs.Read();

            Assert.IsTrue(cs.Count > 0);
        }