Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public void ReservoirContentsWithDatabase()
        {
            Logger.EnableLogger();
            var fn = FileUtility.GetTempFileName(".pdb");
            System.IO.File.Delete(fn);

            SQLiteServer svr = new SQLiteServer(fn);
            var db = new TimeSeriesDatabase(svr, Reclamation.TimeSeries.Parser.LookupOption.TableName,false);

            var c = new CalculationSeries("instant_karl_af");
            var path = Path.Combine(Globals.TestDataPath, "rating_tables");
            path = Path.Combine(path, "karl_af.txt");

            c.Expression = "FileRatingTable(instant_karl_fb,\""+path+"\")";
            c.TimeInterval = TimeInterval.Irregular;
            db.AddSeries(c);

            var fb = new Series("instant_karl_fb");
            fb.TimeInterval = TimeInterval.Irregular;
            db.AddSeries(fb);
            fb.Add("1-1-2013", 1);
            fb.Add("1-2-2013", 2);
            fb.Add("1-3-2013", 3);
            fb.Add("1-4-2013", 4);
            TimeSeriesImporter ti = new TimeSeriesImporter(db);
            ti.Import(fb,computeDependencies:true);// this should force a calculation...

            var af = db.GetSeriesFromTableName("instant_karl_af");
            Assert.NotNull(af, "Series not created");

            af.Read();

            Assert.AreEqual(4, af.Count);
            Assert.AreEqual(300, af[2].Value);
        }
        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);
        }
Ejemplo n.º 4
0
        public void ImportDecodesAndProcessWithFlagLimits()
        {
            Logger.EnableLogger();
            FileUtility.CleanTempPath();
            var fn1 = FileUtility.GetTempFileName(".pdb");
            Console.WriteLine(fn1);
            var svr = new SQLiteServer(fn1);
            var db = new TimeSeriesDatabase(svr, Reclamation.TimeSeries.Parser.LookupOption.TableName,false);

            var tmpDir = CopyTestDecodesFileToTempDirectory("decodes_lapo.txt");

               var rtlapo = CreateTempRatingTable("lapo.csv", new double[] {3.50,3.54,3.55,5.54 },
                                             new double[] {1,2,3,10 });
            // set limits  gh: low=3.53, high 3.6,  rate of change/hour 1
               Quality q = new Quality(db);
               q.SaveLimits("instant_lapo_gh", 3.6, 3.53, 1.0);
               q.SaveLimits("instant_lapo_q", 5, 1.1, 0);

               var site = db.GetSiteCatalog();
               site.AddsitecatalogRow("lapo", "", "OR");
               db.Server.SaveTable(site);
            var c = new CalculationSeries("instant_lapo_q");
            c.SiteID = "lapo";
            c.Expression = "FileRatingTable(%site%_gh,\""+rtlapo+"\")";
            db.AddSeries(c);

            //SeriesExpressionParser.Debug = true;
            FileImporter import = new FileImporter(db);
            import.Import(tmpDir,RouteOptions.None,computeDependencies:true,searchPattern:"*.txt");
            db.Inventory();

            var s = db.GetSeriesFromTableName("instant_lapo_gh");
            var expectedFlags = new string[] { "", "", "", "+", "", "", "", "-" };
            for (int i = 0; i < s.Count; i++)
            {
                  Assert.AreEqual(expectedFlags[i], s[i].Flag, " flag not expected ");
            }

            s = db.GetSeriesFromTableName("instant_lapo_q");
            s.Read();
            Assert.IsTrue(s.Count > 0, "No flow data computed lapo");
            s.WriteToConsole(true);
             // computed flows should be: 2 2 2 10 2 2 1
            expectedFlags = new string[]{"","","","+","","","","-"}; //q>=1 and q<= 5
            for (int i = 0; i < s.Count; i++)
            {
                 Assert.AreEqual(expectedFlags[i], s[i].Flag.Trim()," Flag check on Flow (Q) ");
            }

            SeriesExpressionParser.Debug = false;
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        public static void BasicDatabaseTest(TimeSeriesDatabase db)
        {
            Assert.IsTrue(db.GetSeriesCatalog().Rows.Count ==1 , " initial catalog should have root");
            Reclamation.TimeSeries.Hydromet.HydrometInfoUtility.AutoUpdate = true;
            DateTime t2 = DateTime.Now.Date.AddDays(-10);
            DateTime t1 = DateTime.Now.Date.AddDays(-30);
            Series s = new HydrometDailySeries("jck", "af");
            int id = db.AddSeries(s);

             s = db.GetSeries(id);
             s.Read(t1, t2);
             s.WriteToConsole();
             Assert.AreEqual(21, s.Count);

            s.Read(t1, DateTime.Now.Date.AddDays(-9)); //force auto update.(HydrometDaily supports this)
            // check if auto update worked.
            Assert.AreEqual(22, s.Count);

            Assert.AreEqual(2, db.GetSeriesCatalog().Rows.Count, "Catalog row count");
            var por = s.GetPeriodOfRecord();
            Assert.AreEqual(22, por.Count,"period of record");
        }
Ejemplo n.º 7
0
        public void Interpolate2DWithDatabase()
        {
            Logger.EnableLogger();
            var fn = FileUtility.GetTempFileName(".pdb");
            File.Delete(fn);

            SQLiteServer svr = new SQLiteServer(fn);
            var db = new TimeSeriesDatabase(svr,false );

            var c = new CalculationSeries("rir_q");
            var path = Path.Combine(TestData.DataPath, "rating_tables");
            path = Path.Combine(path, "rir_q.txt");

            c.Expression = "FileLookupInterpolate2D(rir_fb, rir_ra, \"" + path + "\")" +
                " + FileLookupInterpolate2D(rir_fb, rir_rb, \"" + path + "\")";
            c.TimeInterval = TimeInterval.Irregular;
            db.AddSeries(c);

            var fb = new Series("rir_fb");
            fb.TimeInterval = TimeInterval.Irregular;
            db.AddSeries(fb);
            fb.Add("6-1-2011", 5110.99);
            fb.Add("6-2-2011", 5111.31);
            fb.Add("6-3-2011", 5111.71);
            fb.Add("6-4-2011", 5112.09);

            var ra = new Series("rir_ra");
            ra.TimeInterval = TimeInterval.Irregular;
            ra.Add("6-1-2011", 2.1);
            ra.Add("6-2-2011", 1.29);
            ra.Add("6-3-2011", 1.29);
            ra.Add("6-4-2011", 1.29);
            db.AddSeries(ra);

            var rb = new Series("rir_rb");
            rb.TimeInterval = TimeInterval.Irregular;
            rb.Add("6-1-2011", 2.1);
            rb.Add("6-2-2011", 1.28);
            rb.Add("6-3-2011", 1.28);
            rb.Add("6-4-2011", 1.28);
            db.AddSeries(rb);

            TimeSeriesImporter ti = new TimeSeriesImporter(db);
            ti.Import(fb, computeDependencies: true);// this should force a calculation...

            var q = db.GetSeriesFromTableName("rir_q");
            Assert.NotNull(q, "Series not created");

            q.Read();

            /*
             * Flows from Hydromet
             * 6-1-2011, 1009.87
             * 6-2-2011, 602.24
             * 6-3-2011, 603.32
             * 6-4-2011, 604.34
             */

            Assert.AreEqual(4, q.Count);
            Assert.AreEqual(1009.87, System.Math.Round(q[0].Value, 2));
            Assert.AreEqual(603.32, System.Math.Round(q[2].Value, 2));
        }
Ejemplo n.º 8
0
        // ENTRY POINT FOR PROCESSING
        static void ProcessRogueBiOP(DateTime t1, DateTime t2, string piscesFile)
        {
            // Toggle to read flagged data
            HydrometInstantSeries.KeepFlaggedData = true;

            // Create pisces database to store data
            if (File.Exists(piscesFile))
                File.Delete(piscesFile);
            var DB = new SQLiteServer(piscesFile);
            var pDB = new TimeSeriesDatabase(DB);

            // PROCESS INSTANT DATA
            PiscesFolder rFldr = pDB.AddFolder("RawData");
            Console.Write("Processing Instant Series... ");
            var emiQ = GetInstantSeries("EMI", "Q", t1, t2, pDB, rFldr);
            var emiQC = GetInstantSeries("EMI", "QC", t1, t2, pDB, rFldr);

            var basoQ = GetInstantSeries("BASO", "Q", t1, t2, pDB, rFldr);
            var taloQC = GetInstantSeries("TALO", "QC", t1, t2, pDB, rFldr);
            var bctoQ = GetInstantSeries("BCTO", "Q", t1, t2, pDB, rFldr);
            var phxoQC = GetInstantSeries("PHXO", "QC", t1, t2, pDB, rFldr);

            var giloQ = GetInstantSeries("GILO", "Q", t1, t2, pDB, rFldr);
            var giloGH = GetInstantSeries("GILO", "GH", t1, t2, pDB, rFldr);
            var dicoQC = GetInstantSeries("DICO", "QC", t1, t2, pDB, rFldr);
            var slboQC = GetInstantSeries("SLBO", "QC", t1, t2, pDB, rFldr);

            var antoQ = GetInstantSeries("ANTO", "Q", t1, t2, pDB, rFldr);
            var antoQC = GetInstantSeries("ANTO", "QC", t1, t2, pDB, rFldr);
            var antoGH = GetInstantSeries("ANTO", "GH", t1, t2, pDB, rFldr);

            Console.WriteLine("Done importing instant data!");

            // PROCESS HOURLY DATA
            PiscesFolder dFldr = pDB.AddFolder("HourlyData");
            Console.WriteLine("");
            Console.Write("Processing Hourly Series... ");
            var emiQ_h = ProcessHourlySeries(emiQ, "EMI_Q", pDB, dFldr);
            var emiQC_h = ProcessHourlySeries(emiQC, "EMI_QC", pDB, dFldr);

            var basoQ_h = ProcessHourlySeries(basoQ, "BASO_Q", pDB, dFldr);
            var taloQC_h = ProcessHourlySeries(taloQC, "TALO_QC", pDB, dFldr);
            var bctoQ_h = ProcessHourlySeries(bctoQ, "BCTO_Q", pDB, dFldr);
            var phxoQC_h = ProcessHourlySeries(phxoQC, "PHXO_QC", pDB, dFldr);

            var giloQ_h = ProcessHourlySeries(giloQ, "GILO_Q", pDB, dFldr);
            var giloGH_h = ProcessHourlySeries(giloGH, "GILO_GH", pDB, dFldr);
            var dicoQC_h = ProcessHourlySeries(dicoQC, "DICO_QC", pDB, dFldr);
            var slboQC_h = ProcessHourlySeries(slboQC, "SLBO_QC", pDB, dFldr);

            var antoQ_h = ProcessHourlySeries(antoQ, "ANTO_Q", pDB, dFldr);
            var antoQC_h = ProcessHourlySeries(antoQC, "ANTO_QC", pDB, dFldr);
            var antoGH_h = ProcessHourlySeries(antoGH, "ANTO_GH", pDB, dFldr);

            Console.WriteLine("Done computing hourly data!");

            // CHECK BIOP STUFF
            Console.WriteLine("");
            Console.WriteLine("Data Processing: Checking Ramping Rates and Flows...");
            Console.WriteLine("");
            PiscesFolder ckFldr = pDB.AddFolder("RampingRateChecks");

            Console.WriteLine("Checking EMI flows");
            Series EMIHourlyDownRamp = CheckEMIHourlyDownRampingRate(emiQ_h);
            EMIHourlyDownRamp = CheckSourceSeries(emiQ_h, EMIHourlyDownRamp);
            pDB.AddSeries(EMIHourlyDownRamp, ckFldr);

            Series EMIDailyDownRamp = CheckEMIDailyDownRampingRate(emiQ_h);
            EMIDailyDownRamp = CheckSourceSeries(emiQ_h, EMIDailyDownRamp);
            pDB.AddSeries(EMIDailyDownRamp, ckFldr);

            Series EMIHourlyUpRamp = CheckEMIUpRampingRate(emiQ_h);
            EMIHourlyUpRamp = CheckSourceSeries(emiQ_h, EMIHourlyUpRamp);
            pDB.AddSeries(EMIHourlyUpRamp, ckFldr);

            Console.WriteLine("Checking BASO flows");
            Series BASOHourlyDownRamp = CheckBASODownRampingRate(basoQ_h, taloQC_h);
            BASOHourlyDownRamp = CheckSourceSeries(basoQ_h, BASOHourlyDownRamp);
            BASOHourlyDownRamp = CheckSourceSeries(taloQC_h, BASOHourlyDownRamp);
            pDB.AddSeries(BASOHourlyDownRamp, ckFldr);

            Console.WriteLine("Checking BCTO flows");
            Series BCTOHourlyDownRamp = CheckBCTODownRampingRate(bctoQ_h, phxoQC_h);
            BCTOHourlyDownRamp = CheckSourceSeries(bctoQ_h, BCTOHourlyDownRamp);
            BCTOHourlyDownRamp = CheckSourceSeries(phxoQC_h, BCTOHourlyDownRamp);
            pDB.AddSeries(BCTOHourlyDownRamp, ckFldr);

            Console.WriteLine("Checking GILO flows and gage height");
            Series GILOUpRamp = new Series(); Series GILODownRamp = new Series();
            CheckGILOFlowRampingRate(giloQ_h, slboQC_h, dicoQC_h, out GILODownRamp, out GILOUpRamp);
            GILODownRamp = CheckSourceSeries(giloQ_h, GILODownRamp);
            GILODownRamp = CheckSourceSeries(slboQC_h, GILODownRamp);
            GILODownRamp = CheckSourceSeries(dicoQC_h, GILODownRamp);
            GILOUpRamp = CheckSourceSeries(giloQ_h, GILOUpRamp);
            GILOUpRamp = CheckSourceSeries(slboQC_h, GILOUpRamp);
            GILOUpRamp = CheckSourceSeries(dicoQC_h, GILOUpRamp);
            pDB.AddSeries(GILOUpRamp, ckFldr);
            pDB.AddSeries(GILODownRamp, ckFldr);

            Series GILOGageUpRamp = CheckGILOGageRampingRate(giloGH_h, slboQC_h, dicoQC_h);
            GILOGageUpRamp = CheckSourceSeries(giloGH_h, GILOGageUpRamp);
            GILOGageUpRamp = CheckSourceSeries(slboQC_h, GILOGageUpRamp);
            GILOGageUpRamp = CheckSourceSeries(dicoQC_h, GILOGageUpRamp);
            pDB.AddSeries(GILOGageUpRamp, ckFldr);

            Console.WriteLine("Checking ANTO flows and gage height");
            Series ANTOUpRamp = new Series(); Series ANTODownRamp = new Series();
            CheckANTOFlowRampingRate(antoQ_h, antoQC_h, out ANTODownRamp, out ANTOUpRamp);
            ANTODownRamp = CheckSourceSeries(antoQ_h, ANTODownRamp);
            ANTODownRamp = CheckSourceSeries(antoQC_h, ANTODownRamp);
            ANTOUpRamp = CheckSourceSeries(antoQ_h, ANTOUpRamp);
            ANTOUpRamp = CheckSourceSeries(antoQC_h, ANTOUpRamp);
            pDB.AddSeries(ANTOUpRamp, ckFldr);
            pDB.AddSeries(ANTODownRamp, ckFldr);

            Series ANTOGageUpRamp = CheckANTOGageRampingRate(antoGH_h, antoQC_h);
            ANTOGageUpRamp = CheckSourceSeries(antoGH_h, ANTOGageUpRamp);
            ANTOGageUpRamp = CheckSourceSeries(antoQC_h, ANTOGageUpRamp);
            pDB.AddSeries(ANTOGageUpRamp, ckFldr);
        }
Ejemplo n.º 9
0
 // Does the conversion from an instant series to an hourly series.
 private static Series ProcessHourlySeries(Series sIn, string sName, TimeSeriesDatabase pDB, PiscesFolder dFldr)
 {
     Console.Write(sName + ", ");
     // Hourly averaging
     Series rval = Reclamation.TimeSeries.Math.Average(sIn, TimeInterval.Hourly);
     rval.Provider = "Series";
     rval.Name = sName;
     pDB.AddSeries(rval, dFldr);
     return rval;
 }
Ejemplo n.º 10
0
 // Populates Pisces DB with instant 15-minute data
 private static Series GetInstantSeries(string CBTT, string PCODE, DateTime t1, DateTime t2, TimeSeriesDatabase pDB,
     PiscesFolder rFldr)
 {
     Console.Write(CBTT + "_" + PCODE + ", ");
     Series rval = new HydrometInstantSeries(CBTT, PCODE);
     rval.Read(t1, t2);
     rval.Name = CBTT + "_" + PCODE + "15min";
     pDB.AddSeries(rval, rFldr);
     return rval;
 }
Ejemplo n.º 11
0
        public void ImportDecodesWithMissingGageHeight()
        {
            FileUtility.CleanTempPath();
            var fn1 = FileUtility.GetTempFileName(".pdb");
            Console.WriteLine(fn1);
            var svr = new SQLiteServer(fn1);
            var db = new TimeSeriesDatabase(svr, Reclamation.TimeSeries.Parser.LookupOption.TableName,false);
            Logger.EnableLogger();

            var tmpDir = CopyTestDecodesFileToTempDirectory("decodes_mabo_missing_gh.txt");
            var ratingTableFileName =CreateTempRatingTable("mabo.csv", 2.37, 2.8, x => (x*10));
            var c = new CalculationSeries("instant_mabo_q");
            c.Expression = "FileRatingTable(mabo_gh,\""+ratingTableFileName+"\")";
            db.AddSeries(c);

            FileImporter import = new FileImporter(db);
            import.Import(tmpDir, RouteOptions.Outgoing, computeDependencies: true,searchPattern:"*.txt");
            db.Inventory();

            var s = db.GetSeriesFromTableName("instant_mabo_q");

            s.Read();
            Assert.IsTrue(s.CountMissing() == 0);
            Assert.IsTrue(s.Count > 0, "No flow data computed");
        }
Ejemplo n.º 12
0
 public void AddSeries(Series s)
 {
     m_db.AddSeries(s, this);
 }
Ejemplo n.º 13
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);
 }
        private static void AddSeries(string period, string scenario,
                                  TimeSeriesDatabase db, VariableResolver vr,
                                  string name, string equation, ModsimType mType)
        {
            if (name.Trim().ToLower() == "nan")
            {
            return;
            }

            if (name.Trim() == "")
            {
            Console.WriteLine("--- WARNING modsim Node Name is missing. Type = " +
                              mType.ToString());
            return;
            }

            CalculationSeries cs = new CalculationSeries(name);
            cs.TimeInterval = TimeInterval.Monthly;

            if (mType == ModsimType.Gain)
            {
            cs.Expression = string.Format("Max({0}, 0)", equation);
            }
            if (mType == ModsimType.Negative)
            {
            cs.Expression = string.Format("Abs(Min({0}, 0))", equation);
            }
            cs.TimeSeriesDatabase = db;
            cs.Parser.VariableResolver = vr;
            cs.Units = "cfs";
            db.AddSeries(cs);    // add series before calcualte to get an id assigned.
            cs.Calculate(); // Calculate also saves the data.

            SetSeriesDatesToBeginningOfMonth(cs);
            ConsolePrintSeriesNameAndCount(cs);
        }