public void Albuquerque() { string fn = Path.Combine(TestData.DataPath, "RiverWare", "MRG-ESA-Output", "BOtargetsNoContFlow-50pct.rdf"); var s = new RiverWareSeries(fn, "Heron^Albuquerque", "Storage", -1, false); s.Read(); Assert.AreEqual(3652, s.Count); }
public void Albuquerque() { string fn = TestData.DataPath + "\\RiverWare\\MRG-ESA-Output\\" + "BOtargetsNoContFlow-50pct.rdf"; var s = new RiverWareSeries(fn, "Heron^Albuquerque", "Storage", -1, false); s.Read(); Assert.AreEqual(3652, s.Count); }
public void LowerColoradoTraces() { string fn1 = TestData.DataPath + "\\RiverWare\\LowerColoradoTraces.rdf"; var s1 = new RiverWareSeries(fn1, "Powell", "Outflow", 1, false); var s2 = new RiverWareSeries(fn1, "Powell", "Outflow", 100, false); s1.Read(); Assert.AreEqual(800001, s1[0].Value, 0.01); s2.Read(); Assert.AreEqual(801965, s2[0].Value, 0.01); }
public void SnapShotObject() { var s = new RiverWareSeries(TestData.DataPath + "\\RiverWare\\SnapShotObj.rdf", "", "Wolf Gage_Gage Outflow", -1, true); s.Read(); Assert.AreEqual(15706, s.Count, "wrong number of time steps"); Assert.AreEqual(5.001, s[0].Value, 0.0001); Assert.AreEqual(5.0, s[1].Value, 0.0001); }
public void LowerColoradoTraces() { string fn1 = Path.Combine(TestData.DataPath, "RiverWare", "LowerColoradoTraces.rdf"); var s1 = new RiverWareSeries(fn1, "Powell", "Outflow", 1,false); var s2 = new RiverWareSeries(fn1, "Powell", "Outflow", 100,false); s1.Read(); Assert.AreEqual(800001, s1[0].Value, 0.01); s2.Read(); Assert.AreEqual(801965, s2[0].Value, 0.01); }
public void MMS() { var s = new RiverWareSeries(TestData.DataPath + "\\RiverWare\\MMSTracesOutputWY05JunRun.rdf", "TWSA PARW_Data", "Daily TWSA", 10, false); var parw = new RiverWareSeries(TestData.DataPath + "\\RiverWare\\MMSTracesOutputWY05JunRun.rdf", "PARW", "MMS PRMS Unregulated Flow", 51, false); Assert.AreEqual("cfs", parw.Units); // units before Read Assert.AreEqual("acre-ft", s.Units); Assert.AreEqual(TimeInterval.Daily, s.TimeInterval); s.Read(); parw.Read(); Assert.AreEqual(2040.66, parw[0].Value); Assert.AreEqual(934.89, parw[parw.Count - 1].Value); //Console.WriteLine(parw[parw.Count - 1]); Assert.AreEqual("acre-ft", s.Units); Assert.AreEqual("cfs", parw.Units); }
public void MMS() { var s = new RiverWareSeries(Path.Combine(TestData.DataPath, "RiverWare", "MMSTracesOutputWY05JunRun.rdf"), "TWSA PARW_Data", "Daily TWSA", 10, false); var parw = new RiverWareSeries(Path.Combine(TestData.DataPath, "RiverWare", "MMSTracesOutputWY05JunRun.rdf"), "PARW", "MMS PRMS Unregulated Flow", 51, false); Assert.AreEqual("cfs", parw.Units); // units before Read Assert.AreEqual("acre-ft", s.Units); Assert.AreEqual(TimeInterval.Daily, s.TimeInterval); s.Read(); parw.Read(); Assert.AreEqual(2040.66, parw[0].Value); Assert.AreEqual(934.89, parw[parw.Count - 1].Value); //Console.WriteLine(parw[parw.Count - 1]); Assert.AreEqual("acre-ft", s.Units); Assert.AreEqual("cfs", parw.Units); }
public void UpperSnakeTraces() { string fn1 = TestData.DataPath + "\\RiverWare\\UpperSnakeTraces.rdf"; string fn2 = TestData.DataPath + "\\RiverWare\\UpperSnakeTraces.rdf"; var s1 = new RiverWareSeries(fn1, "Jackson", "Inflow", 1, false); var s2 = new RiverWareSeries(fn2, "Jackson", "Inflow", 15, false); s1.Read(); s2.Read(); Assert.AreEqual(s1.Units, "cfs"); Assert.AreEqual(new DateTime(2006, 10, 20, 23, 59, 59), s1[0].DateTime); double[] expected1928 = { 669.96, 559.00, 565.00, 443.04, 674.96 }; double[] expected1942 = { 749.04, 537.29, 749.04, 436.46, 537.29 }; for (int i = 0; i < expected1928.Length; i++) { Assert.AreEqual(expected1928[i], s1[i].Value, 0.01); Assert.AreEqual(expected1942[i], s2[i].Value, 0.01); } }
public void RDF() { var s = new RiverWareSeries(TestData.DataPath + "\\RiverWare\\regular.rdf", "DIVERSION KRD Irrigation", "Diversion", -1, false); s.Read(); Assert.AreEqual(8035, s.Count, "wrong number of time steps"); double[] v = { 0.001, 0.002, 0.003, 0.004, 0.005 }; DateTime[] d = { }; DateTime t = DateTime.Parse("1980-11-1 23:59:59"); for (int i = 0; i < 5; i++) { Assert.AreEqual(v[i], s[i].Value); Assert.AreEqual(t, s[i].DateTime); t = t.AddDays(1); } Assert.AreEqual(true, s[s.Count - 2].IsMissing); Assert.AreEqual(-0.0001, s[s.Count - 1].Value); Assert.AreEqual(DateTime.Parse("2002-10-31 23:59:59"), s[s.Count - 1].DateTime); }
public void RDF() { var s = new RiverWareSeries(Path.Combine(TestData.DataPath, "RiverWare", "regular.rdf"), "DIVERSION KRD Irrigation", "Diversion", -1, false); s.Read(); Assert.AreEqual(8035, s.Count,"wrong number of time steps"); double[] v = { 0.001, 0.002, 0.003, 0.004, 0.005 }; DateTime[] d = { }; DateTime t = DateTime.Parse("1980-11-1 23:59:59"); for (int i = 0; i < 5; i++) { Assert.AreEqual(v[i], s[i].Value); Assert.AreEqual(t, s[i].DateTime); t = t.AddDays(1); } Assert.AreEqual(true,s[s.Count-2].IsMissing); Assert.AreEqual(-0.0001, s[s.Count - 1].Value); Assert.AreEqual(DateTime.Parse("2002-10-31 23:59:59"), s[s.Count - 1].DateTime); }
public void SnapShotObject() { var s = new RiverWareSeries(Path.Combine(TestData.DataPath, "RiverWare", "SnapShotObj.rdf"), "", "Wolf Gage_Gage Outflow", -1, true); s.Read(); Assert.AreEqual(15706, s.Count,"wrong number of time steps"); Assert.AreEqual(5.001,s[0].Value,0.0001); Assert.AreEqual(5.0,s[1].Value,0.0001); }
public void UpperSnakeTraces() { string fn1 = Path.Combine(TestData.DataPath, "RiverWare", "UpperSnakeTraces.rdf"); string fn2 = Path.Combine(TestData.DataPath, "RiverWare", "UpperSnakeTraces.rdf"); var s1 = new RiverWareSeries(fn1, "Jackson", "Inflow", 1,false); var s2 = new RiverWareSeries(fn2, "Jackson", "Inflow", 15,false); s1.Read(); s2.Read(); Assert.AreEqual(s1.Units,"cfs"); Assert.AreEqual(new DateTime(2006, 10, 20, 23, 59, 59),s1[0].DateTime); double[] expected1928 ={669.96,559.00,565.00,443.04,674.96 }; double[] expected1942 ={749.04,537.29,749.04,436.46,537.29}; for (int i = 0; i < expected1928.Length; i++) { Assert.AreEqual(expected1928[i], s1[i].Value, 0.01); Assert.AreEqual(expected1942[i], s2[i].Value, 0.01); } }
/********************************** * * Create a tree file that is usable by pisces * * input : riverware rdf file * output : comma seperated tree file. * * // example portion of input file. (this input file is using snapshots in riverware) ----------------------------------- object_type: SnapShotObj object_name: Most Likely 2 slot_name: Andrews Gage 12447390 at RM 3_5_Gage Outflow END_SLOT_PREAMBLE units: cfs // example output. There is no nesting of tree levels for now. RiverwareName,Description,RiverwareDataType,Level,Units Riverware Results,,,0, Yakima River at Parker PARW,Yakima River at Parker PARW,Gage Outflow,1,cfs Yakima River at Grandview,Yakima River at Grandview,Gage Inflow,1,cfs ... **********************************/ public static void AddRiverWareFileToDatabase(string rdfFilename, PiscesFolder parent, TimeSeriesDatabase db) { Reclamation.Core.TextFile tf = new Reclamation.Core.TextFile(rdfFilename); #region notes /* SnapShotStyle... ------------------------------------- 2001-9-29 24:00 2001-9-30 24:00 object_type: SnapShotObj object_name: Most Likely 2 ### scernario name slot_name: Andrews Gage 12447390 at RM 3_5_Gage Outflow # object_name slotName are combined. END_SLOT_PREAMBLE units: cfs Regular Style ... --------------------------------------- END_COLUMN END_SLOT object_type: StreamGage object_name: Yakima 202_0 at Easton EASW slot_name: Gage Outflow END_SLOT_PREAMBLE units: cfs scale: 1 */ #endregion int number_of_runs = LookupNumberOfRuns(tf); PiscesFolder folder = parent; if (number_of_runs == 1) folder = db.AddFolder(parent, Path.GetFileNameWithoutExtension(rdfFilename)); int sz = tf.Length; // object_type and object_name should occur on consecutive lines. int index = tf.IndexOfBoth("object_name:", "slot_name:", 0); var objectList = new List<string>(); //list to avoid duplicates in tree Performance p1 = new Performance(); Performance p2 = new Performance(); p2.Pause(); int counter = 0; db.SuspendTreeUpdates(); var sc = db.GetSeriesCatalog(); Dictionary<string, int> objTypeID = new Dictionary<string, int>(); Dictionary<string, int> objNameID = new Dictionary<string, int>(); while (index < sz && index > 0) { //slot_name: Andrews Gage 12447390 at RM 3_5_Gage Outflow string slot_name = tf[index + 1].Substring(11); //Andrews Gage 12447390 at RM 3_5_Gage Outflow string object_type = tf[index - 1].Substring(13); string object_name = tf[index].Substring(13); string units = tf[index + 3].Substring(6).Trim(); string tag = object_name + ":" + slot_name; if (!objectList.Contains(tag)) { int scenarioNumber = -1; if (number_of_runs > 1) scenarioNumber = 1; RiverWareSeries s; if (object_type == "SnapShotObj") s = new RiverWareSeries(rdfFilename, "", slot_name, scenarioNumber, true, units); else s = new RiverWareSeries(rdfFilename, object_name, slot_name, scenarioNumber, false, units); s.Units = units; s.ConnectionString = ConnectionStringUtility.MakeFileNameRelative(s.ConnectionString, db.DataSource); p2.Continue(); if (object_type.Contains("Reservoir")) { object_type = "Reservoir"; } else if (object_type.Contains("Reach")) { object_type = "Reach"; } else if (object_type.Contains("Diversion")) { object_type = "Diversion"; } else if (object_type.Contains("Canal")) { object_type = "Canal"; } int id = sc.NextID(); if (!sc.FolderExists(object_type, folder.ID)) { objTypeID.Add(object_type, id); sc.AddFolder(object_type, id, folder.ID); id++; } if (!sc.FolderExists(object_name, objTypeID[object_type])) { objNameID.Add(object_name, id); sc.AddFolder(object_name, id, objTypeID[object_type]); id++; } sc.AddSeriesCatalogRow(s, id, objNameID[object_name], ""); objectList.Add(tag); } index = tf.IndexOfBoth( "object_name:", "slot_name:", index + 2); counter++; } p1.Report("total"); p2.Report("db.add()"); //398.7732813 seconds elapsed. total //384.6792607 seconds elapsed. db.add() // disable tree refresh (doubles perf) // 255.9736646 seconds elapsed. total // 241.7702669 seconds elapsed. db.add() // implemented member ExternalDataSource //34.8756696 seconds elapsed. total //20.3753912 seconds elapsed. db.add() var convention = Reclamation.TimeSeries.RiverWare.ImportRiverWare.ScenarioConvention.Default; if (number_of_runs > 1) // Multiple runs. {// show dialog to allow water year naming or traces var dlg = new Reclamation.TimeSeries.RiverWare.ImportRiverWare(); if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { convention = dlg.NamingConvention; } // Add Scenarios. var tblScen = db.GetScenarios(); for (int i = 0; i < number_of_runs; i++) { string name = "Run" + i; if (convention == RiverWare.ImportRiverWare.ScenarioConvention.ByYear) { name = (dlg.FirstYear + i ).ToString(); } //string scenarioPath = ConnectionStringUtility.MakeFileNameRelative("FileName=" + item, DB.Filename); tblScen.AddScenarioRow(name, true, "ScenarioNumber=" + (i + 1).ToString(), 0); } db.Server.SaveTable(tblScen); } db.Server.SaveTable(sc); db.ResumeTreeUpdates(); db.RefreshFolder(parent); }