public void AnyValueCompression() { DssPath p = new DssPath(@"//SACRAMENTO/PRECIP-INC//1Day/OBS/"); using (DssReader r = new DssReader(TestUtility.BasePath + "sample7.dss")) { var ts = r.GetTimeSeries(p); var ts2 = r.GetTimeSeries(p, compression: TimeWindow.ConsecutiveValueCompression.AnyValue); Assert.IsTrue(ts2.Count <= ts.Count); // ts2 should not have more than 2 of the same value at a time } }
public void ZeroAndNoDataCompression() { DssPath p = new DssPath(@"//SACRAMENTO/PRECIP-INC//1Day/OBS/"); using (DssReader r = new DssReader(TestUtility.BasePath + "sample7.dss")) { var ts = r.GetTimeSeries(p); var ts2 = r.GetTimeSeries(p, compression: TimeWindow.ConsecutiveValueCompression.ZeroAndNoData); Assert.IsTrue(ts2.Count <= ts.Count); // ts2 should have no more than 2 consecutive zero's or no data values at a time } }
private static void Run(Options opts) { VerifyExportArgs(opts); using (DssReader r = new DssReader(opts.DssFile)) { object record; ExcelWriter ew = new ExcelWriter(opts.ExcelFile); for (int i = 0; i < opts.Paths.ToList <string>().Count; i++) { string sheet; while (true) { sheet = "dssvue_import_" + ExcelTools.RandomString(5); if (!ew.SheetExists(sheet)) { break; } } DssPath p = new DssPath(opts.Paths.ElementAt(i)); var type = r.GetRecordType(p); if (type is RecordType.RegularTimeSeries || type is RecordType.IrregularTimeSeries) { record = r.GetTimeSeries(p); ew.Write(record as TimeSeries, sheet); } else if (type is RecordType.PairedData) { record = r.GetPairedData(p.FullPath); ew.Write(record as PairedData, sheet); } } } }
public void ReadTs() { DssPath path = new DssPath("//SACRAMENTO/TEMP-MIN/01Jan1877/1Day/OBS/"); DssReader r = new DssReader(TestUtility.BasePath + "sample7.dss"); var ts = r.GetTimeSeries(path); for (int i = 0; i < ts.Count; i++) { var d = ts.Values[i]; if (DssReader.IsValid(d)) { } } //DateTime //11jul1877 24:00 60 DEG-F DateTime t = new DateTime(1877, 7, 12); // next day because of 24:00 //ts.WriteToConsole(); int idx = ts.IndexOf(t); Assert.IsTrue(idx >= 0); Assert.AreEqual(60, ts.Values[idx], 0.001); Console.WriteLine(ts.Values.Length); }
public void SetProgramNameForMultipleRecords_Dss6() { string orig = TestUtility.BasePath + "simpleQCT6_RTS.dss"; string fn = TestUtility.BasePath + "simpleQCT6Copy_RTS.dss"; File.Delete(fn); File.Copy(orig, fn); List <DssPath> paths = new List <DssPath>(); using (DssWriter w = new DssWriter(fn)) { DssGlobals.SetProgramName("DOTNET"); for (int i = 0; i < 10; i++) { var ts = TimeSeriesTest.CreateSampleTimeSeries(new DateTime(2020, 1, 2), "cfs", "INST", size: 10); ts.Path = new DssPath("a" + i.ToString(), "b", "c", "01Jan2020", E: "1Day", F: "f"); paths.Add(ts.Path); w.Write(ts); } } using (DssReader r = new DssReader(fn)) { foreach (DssPath path in paths) { var ts = r.GetTimeSeries(path); Assert.AreEqual("DOTNET", ts.ProgramName); } } }
public TimeSeries ReadTs(String fileName, String path, DateTime t1 = default(DateTime), DateTime t2 = default(DateTime)) { using (DssReader r = new DssReader(fileName)) { TimeSeries ts = null; if (t1 == default(DateTime)) { ts = r.GetTimeSeries(new DssPath(path)); } else { ts = r.GetTimeSeries(new DssPath(path), t1, t2); } return(ts); } }
public void BogusPathTest() { DssPath path = new DssPath("/AmazonRiver/ST. LOUIS/FLOW//1Day/OBS/"); using (DssReader r = new DssReader(TestUtility.BasePath + "sample7.dss")) { r.GetTimeSeries(path); } }
public void ReadMissingBlocks() { using (DssReader r = new DssReader(TestUtility.BasePath + "sample7.dss")) { var path = new DssPath("//SACRAMENTO/PRECIP-INC/01JAN1944/1Day/OBS/"); var timeSeries = r.GetTimeSeries(path, new DateTime(2009, 11, 1), new DateTime(2025, 10, 31)); Assert.AreEqual(0, timeSeries.Values.Length); } }
public void Read1944PathWith1950TimeWindow() { using (DssReader r = new DssReader(TestUtility.BasePath + "sample7.dss")) { var path = new DssPath("//SACRAMENTO/PRECIP-INC/01JAN1944/1Day/OBS/"); var timeSeries = r.GetTimeSeries(path, new DateTime(1950, 11, 1), new DateTime(1952, 10, 31)); Assert.AreEqual(731, timeSeries.Values.Length); } }
public void SimpleQualityConsistencyTestDss6_IRTS() { string orig = TestUtility.BasePath + "simpleQCT6_IRTS.dss"; string fn = TestUtility.BasePath + "simpleQCT6Copy_IRTS.dss"; File.Delete(fn); File.Copy(orig, fn); Array q = Enum.GetValues(typeof(BaseQualityFlags)); Random r = new Random(); var qList = new List <int>(); using (DssWriter w = new DssWriter(fn)) { var ts = w.GetTimeSeries(new DssPath("/A/B/C//IR-YEAR/F/")); for (int i = 0; i < ts.Values.Length; i++) { BaseQualityFlags flag = (BaseQualityFlags)q.GetValue(r.Next(q.Length)); Quality newQuality = new Quality(flag); qList.Add(newQuality.Value); } ts.Qualities = qList.ToArray(); w.Write(ts, true); } using (DssReader reader = new DssReader(fn)) { TimeSeries ts = reader.GetTimeSeries(new DssPath("/A/B/C//IR-YEAR/F/")); for (int i = 0; i < ts.Values.Length; i++) { Assert.AreEqual(ts.Qualities[i], qList[i]); } } using (DssWriter w = new DssWriter(fn)) { var ts = w.GetTimeSeries(new DssPath("/A/B/C//IR-YEAR/F/")); qList.Clear(); for (int i = 0; i < ts.Values.Length; i++) { BaseQualityFlags flag = (BaseQualityFlags)q.GetValue(r.Next(q.Length)); Quality newQuality = new Quality(flag); qList.Add(newQuality.Value); } ts.Qualities = qList.ToArray(); w.Write(ts, true); } using (DssReader reader = new DssReader(fn)) { TimeSeries ts = reader.GetTimeSeries(new DssPath("/A/B/C//IR-YEAR/F/")); for (int i = 0; i < ts.Values.Length; i++) { Assert.AreEqual(ts.Qualities[i], qList[i]); } } }
public void TimeIntervalMethodTest() { DssPath path = new DssPath("/MISSISSIPPI/ST. LOUIS/FLOW//1Day/OBS/"); using (DssReader r = new DssReader(TestUtility.BasePath + "sample7.dss")) { var s = TimeWindow.GetInterval(r.GetTimeSeries(path)); Debug.WriteLine(s); } }
public void ReadCondensedPathNameWithTimeWindow() { using (DssReader r = new DssReader(TestUtility.BasePath + "sample7.dss")) { var catalog = r.GetCatalog(true); var path = catalog.GetCondensedPath(new DssPath("//SACRAMENTO/PRECIP-INC/11Jul1877 - 30Jun2009/1Day/OBS/")); var timeSeries = r.GetTimeSeries(path, new DateTime(1950, 11, 1), new DateTime(1952, 10, 31)); Assert.AreEqual(731, timeSeries.Values.Length); } }
public void OverwriteTimeSeriesUsingTimeSeriesPoints() { DssPath path = new DssPath("//SACRAMENTO/PRECIP-INC//1Day/OBS/"); using (DssReader r = new DssReader(TestUtility.BasePath + "sample7.dss")) { var ts = r.GetTimeSeries(path); var dt = ts.ToDataTable(); } }
public void ToDataTableWithQuality() { DssPath path = new DssPath("/MISSISSIPPI/ST. LOUIS/FLOW//1Day/OBS/"); using (DssReader r = new DssReader(TestUtility.BasePath + "sample7.dss")) { var ts = r.GetTimeSeries(path); var dt = ts.ToDataTable(); } }
public void SimpleQualityConsistencyTestDss7_RTS_floats() { string fn = TestUtility.BasePath + "simpleQCT7.dss"; File.Delete(fn); Array q = Enum.GetValues(typeof(BaseQualityFlags)); Random r = new Random(); var qList = new List <int>(); using (DssWriter w = new DssWriter(fn)) { var ts = TimeSeriesTest.CreateSampleTimeSeries(new DateTime(2020, 1, 1), "cfs", "INST", size: 10); ts.Path = new DssPath("a", "b", "c", "", E: "1Day", F: "f"); for (int i = 0; i < ts.Values.Length; i++) { BaseQualityFlags flag = (BaseQualityFlags)q.GetValue(r.Next(q.Length)); Quality newQuality = new Quality(flag); qList.Add(newQuality.Value); } ts.Qualities = qList.ToArray(); w.Write(ts, true); } using (DssReader reader = new DssReader(fn)) { TimeSeries ts = reader.GetTimeSeries(new DssPath("/a/b/c//1Day/f/")); for (int i = 0; i < ts.Values.Length; i++) { Assert.AreEqual(ts.Qualities[i], qList[i]); } } using (DssWriter w = new DssWriter(fn)) { var ts = w.GetTimeSeries(new DssPath("/a/b/c//1Day/f/")); qList.Clear(); for (int i = 0; i < ts.Values.Length; i++) { BaseQualityFlags flag = (BaseQualityFlags)q.GetValue(r.Next(q.Length)); Quality newQuality = new Quality(flag); qList.Add(newQuality.Value); } ts.Qualities = qList.ToArray(); w.Write(ts, true); } using (DssReader reader = new DssReader(fn)) { TimeSeries ts = reader.GetTimeSeries(new DssPath("/a/b/c//1Day/f/")); for (int i = 0; i < ts.Values.Length; i++) { Assert.AreEqual(ts.Qualities[i], qList[i]); } } }
/// <summary> /// The query for data is outside the range of the stored data. /// we expect to return an empty time series (but please don't crash!) /// </summary> /// <param name="filename"></param> private static void ReadWithDates(string filename) { using (DssReader r = new DssReader(filename)) { var c = r.GetCatalog().ToDataTable(); DateTime t1 = new DateTime(2004, 12, 1); DateTime t2 = t1.AddYears(1); var ts = r.GetTimeSeries(new DssPath("//TYRONE 4 NE BALD EAG/PRECIP-INC/01JUN1972/1HOUR/OBS/"), t1, t2); Assert.IsTrue(ts.Count == 0); } }
public static Watershed Read(string watershedName, DateTime start, DateTime end, string dssPath) { Watershed rval = new Watershed(watershedName); // DssReader.UseTrainingWheels = false; using (DssReader dss = new DssReader(dssPath, DssReader.MethodID.MESS_METHOD_GENERAL_ID, DssReader.LevelID.MESS_LEVEL_NONE)) { Console.WriteLine("Reading " + dssPath); DssPathCollection dssPaths = dss.GetCatalog(); // sorted int size = dssPaths.Count; if (size == 0) { throw new Exception("Empty DSS catalog"); } // /RUSSIANNAPA/APCC1/FLOW/01SEP2019/1HOUR/C:000002|T:0212019/ var seriesList = new List <Hec.Dss.TimeSeries>(); for (int i = 0; i < size; i++) { if (i % 100 == 0) { Console.Write("."); } DssPath path = dssPaths[i]; string location = path.Bpart; float[,] ensemble = null; ParseFPart(path.Fpart, out int memberidx, out DateTime issueDate); if (issueDate >= start && issueDate <= end && string.Equals(path.Apart, watershedName, StringComparison.OrdinalIgnoreCase)) { // Passing in 'path' (not the dateless string) is important, path without date triggers a heinous case in the dss low-level code var ts = dss.GetTimeSeries(path); if (NextForecast(seriesList, ts) || i == size - 1) { if (i == size - 1) { seriesList.Add(ts); } ConvertListToEnsembleArray(seriesList, ref ensemble); rval.AddForecast(path.Bpart, issueDate, ensemble, ts.Times); seriesList.Clear(); } seriesList.Add(ts); } } } return(rval); }
//[TestMethod] public void QueryWithCondensedPath() { var filename = System.IO.Path.Combine(TestUtility.BasePath, "MoRiverObs_TimeWindowTest.dss"); using (DssReader r = new DssReader(filename)) { var catalog = r.GetCatalog(false); var paths = catalog.FilterByPart("CHARITON RIVER", "PRAIRIE HILL, MO", "FLOW", "", "15MIN", "USGS"); var path1 = paths[0]; var t1 = new DateTime(2008, 9, 2); var t2 = new DateTime(2008, 10, 11); var ts = r.GetTimeSeries(path1, t1, t2); } }
public void OpenExistingVersion7FileUsingExplicit7() { DssPath path = new DssPath("//SACRAMENTO/PRECIP-INC//1Day/OBS/"); using (DssReader r = new DssReader(TestUtility.BasePath + "sample7.dss", 6)) { var ts = r.GetTimeSeries(path); var dt = ts.ToDataTable(); } using (DssReader r = new DssReader(TestUtility.BasePath + "sample7.dss", 7)) { Assert.IsTrue(r.GetDSSFileVersion() == 7); } }
private static void ReadWithRange(string fn) { string path = "/CHARITON RIVER/PRAIRIE HILL, MO/FLOW//15MIN/USGS/"; DssReader r = new DssReader(TestUtility.BasePath + fn); var p = new DssPath(path); Assert.IsTrue(r.PathExists(p)); DateTime t1 = new DateTime(2008, 9, 2); DateTime t2 = new DateTime(2008, 10, 12); var ts = r.GetTimeSeries(p, t1, t2); Assert.IsTrue(ts.Count > 100); Console.WriteLine(ts.Count); }
public void ReadTsWithLocationInfo() { DssPath path = new DssPath("/MISSISSIPPI/ST. LOUIS/FLOW//1Day/OBS/"); using (DssReader r = new DssReader(TestUtility.BasePath + "sample7.dss")) { DateTime t1 = DateTime.Parse("1861-01-02"); DateTime t2 = DateTime.Parse("1861-01-18"); var s = r.GetTimeSeries(path, t1, t2); var loc = s.LocationInformation; Console.WriteLine(loc.CoordinateID); Console.WriteLine(loc.XOrdinate); Console.WriteLine(loc.YOrdinate); Console.WriteLine(loc.ZOrdiante); Assert.AreEqual(-901047.2, loc.XOrdinate); Assert.AreEqual(383744.4, loc.YOrdinate); Assert.AreEqual(CoordinateSystem.LatLong, loc.CoordinateSystem); var dt = s.ToDataTable(); //Assert.AreEqual(15, s.Count); Assert.AreEqual(1861, s[14].DateTime.Year); Assert.AreEqual(39800, s[16].Value); Console.WriteLine(s); // read location standalone. //var loc2 = r.GetLocationInfo("/MISSISSIPPI/ST. LOUIS/Location Info///"); var loc2 = r.GetLocationInfo(path.FullPath); Console.WriteLine(loc2); Assert.AreEqual(-901047.2, loc2.XOrdinate); Assert.AreEqual(383744.4, loc2.YOrdinate); Assert.AreEqual(CoordinateSystem.LatLong, loc2.CoordinateSystem); } }
public void TimeSeriesTesting() { var fn = @"C:\temp\dss7_ensemble.dss"; File.Delete(fn); string fileName = Path.Combine(EnsembleTester.CacheDir, "test.csv"); RfcCsvFile csv = new RfcCsvFile(fileName); float[,] ensemble = null; csv.GetEnsemble("SCRN2", ref ensemble); Watershed w = new Watershed("test"); w.AddForecast("SCRN2", DateTime.Parse("2001-11-15"), ensemble, csv.TimeStamps); DssEnsemble.Write(fn, w); using (DssReader r = new DssReader(fn)) { var catalog = r.GetCatalog(); Assert.AreEqual(59, catalog.Count); string path = "/test/SCRN2/Flow/01Nov2013/1Hour/C:000059|T:3192001/"; var ts = r.GetTimeSeries(new DssPath(path)); Assert.AreEqual(-59.0, ts[0].Value); } DateTime t1 = new DateTime(1900, 1, 1); DateTime t2 = DateTime.Now.Date; w = DssEnsemble.Read("test", t1, t2, fn); Assert.AreEqual(1, w.Locations.Count); ensemble = w.Locations[0].Forecasts[0].Ensemble; Assert.AreEqual(337, ensemble.GetLength(1)); Assert.AreEqual(59, ensemble.GetLength(0)); Assert.AreEqual(-59.0f, ensemble[58, 0]); Assert.AreEqual(-59.1f, ensemble[58, 1]); }
public void SetProgramName_Dss7() { string fn = TestUtility.BasePath + "simpleQCT7.dss"; File.Delete(fn); var ts = TimeSeriesTest.CreateSampleTimeSeries(new DateTime(2020, 1, 2), "cfs", "INST", size: 10); ts.Path = new DssPath("a", "b", "c", "01Jan2020", E: "1Day", F: "f"); using (DssWriter w = new DssWriter(fn)) { DssGlobals.SetProgramName("dotnet"); w.Write(ts); } using (DssReader r = new DssReader(fn)) { var temp = r.GetTimeSeries(ts.Path); Assert.AreEqual("dotnet", temp.ProgramName); } }
public void ReadTsIgnoreDPart() { DssPath path = new DssPath("//SACRAMENTO/TEMP-MIN/01Jan2012/1Day/OBS/"); DssReader r = new DssReader(TestUtility.BasePath + "sample7.dss"); DateTime t1 = new DateTime(1965, 1, 1); DateTime t2 = new DateTime(1965, 11, 1); var ts = r.GetTimeSeries(path, t1, t2); //12 Feb 1965, 24:00 36.00 DateTime t = new DateTime(1965, 2, 13); // next day because of 24:00 //ts.WriteToConsole(); int idx = ts.IndexOf(t); Assert.IsTrue(idx >= 0); Assert.AreEqual(36, ts.Values[idx], 0.001); //Assert.AreEqual(11, ts.Count); Console.WriteLine(ts.Values.Length); }
public void QueryTimeWindow() { var filename = System.IO.Path.Combine(TestUtility.BasePath, "MoRiverObs_TimeWindowTest.dss"); //var filename = @"c:\temp\MoRiverObs.dss"; using (DssReader r = new DssReader(filename)) { var t1 = new DateTime(2008, 9, 2); var t2 = new DateTime(2008, 10, 11); var ts = r.GetTimeSeries(new DssPath("/CHARITON RIVER/PRAIRIE HILL, MO/FLOW//15MIN/USGS/"), t1, t2); Console.WriteLine("first point : " + ts[0]); Console.WriteLine("last pont : " + ts[ts.Count - 1]); Assert.IsTrue(ts[0].DateTime == t1); Assert.IsTrue(ts[ts.Count - 1].DateTime == t2); Console.WriteLine(ts); } }
public void SetProgramName_Dss6() { string orig = TestUtility.BasePath + "simpleQCT6_RTS.dss"; string fn = TestUtility.BasePath + "simpleQCT6Copy_RTS.dss"; File.Delete(fn); File.Copy(orig, fn); var ts = TimeSeriesTest.CreateSampleTimeSeries(new DateTime(2020, 1, 2), "cfs", "INST", size: 10); ts.Path = new DssPath("A", "B", "C", "01JAN2020", E: "1DAY", F: "F"); using (DssWriter w = new DssWriter(fn)) { DssGlobals.SetProgramName("DOTNET"); w.Write(ts); } using (DssReader r = new DssReader(fn)) { var temp = r.GetTimeSeries(ts.Path); Assert.AreEqual("DOTNET", temp.ProgramName); } }
private static void Run(Options opts) { if (opts.Command == "import") { VerifyImportArgs(opts); ExcelReader er = new ExcelReader(opts.ExcelFile); using (DssWriter w = new DssWriter(opts.DssFile)) { if (opts.Sheets.ToList <string>().Count == 0) { for (int i = 0; i < er.WorksheetCount; i++) { var t = er.CheckType(i); if (t is RecordType.RegularTimeSeries || t is RecordType.IrregularTimeSeries) { w.Write(er.Read(i) as TimeSeries); } else if (t is RecordType.PairedData) { w.Write(er.Read(i) as PairedData); } } } else { foreach (var sheet in opts.Sheets) { var t = er.CheckType(sheet); if (t is RecordType.RegularTimeSeries || t is RecordType.IrregularTimeSeries) { w.Write(er.Read(sheet) as TimeSeries); } else if (t is RecordType.PairedData) { w.Write(er.Read(sheet) as PairedData); } } } } } else if (opts.Command == "export") { VerifyExportArgs(opts); using (DssReader r = new DssReader(opts.DssFile)) { object record; ExcelWriter ew = new ExcelWriter(opts.ExcelFile); if (opts.Sheets.ToList().Count == 0) { for (int i = 0; i < opts.Paths.ToList <string>().Count; i++) { string sheet = "dssvue_import_" + ExcelTools.RandomString(5); DssPath p = new DssPath(opts.Paths.ElementAt(i)); var type = r.GetRecordType(p); if (type is RecordType.RegularTimeSeries || type is RecordType.IrregularTimeSeries) { record = r.GetTimeSeries(p); ew.Write(record as TimeSeries, sheet); } else if (type is RecordType.PairedData) { record = r.GetPairedData(p.FullPath); ew.Write(record as PairedData, sheet); } } } else { for (int i = 0; i < opts.Sheets.ToList().Count; i++) { DssPath p = new DssPath(opts.Paths.ElementAt(i)); var type = r.GetRecordType(p); if (type is RecordType.RegularTimeSeries || type is RecordType.IrregularTimeSeries) { record = r.GetTimeSeries(p); ew.Write(record as TimeSeries, opts.Sheets.ElementAt(i)); } else if (type is RecordType.PairedData) { record = r.GetPairedData(p.FullPath); ew.Write(record as PairedData, opts.Sheets.ElementAt(i)); } } } } } }
public void SimpleQualityConsistencyTestDss7_IRTS_floats() { string fn = TestUtility.BasePath + "simpleQCT7.dss"; File.Delete(fn); Array q = Enum.GetValues(typeof(BaseQualityFlags)); Random r = new Random(); var qList = new List <int>(); using (DssWriter w = new DssWriter(fn)) { var ts = new TimeSeries(); var times = new List <DateTime>(); var vals = new List <double>(); DateTime start = new DateTime(2020, 1, 1); for (int i = 0; i < 10; i++) { times.Add(start.AddDays(i * i)); vals.Add(i); } ts.Values = vals.ToArray(); ts.Times = times.ToArray(); ts.Path = new DssPath("a", "b", "c", "", E: "IR-Year", F: "f"); ts.Units = "cfs"; ts.DataType = "INST"; for (int i = 0; i < ts.Values.Length; i++) { BaseQualityFlags flag = (BaseQualityFlags)q.GetValue(r.Next(q.Length)); Quality newQuality = new Quality(flag); qList.Add(newQuality.Value); } ts.Qualities = qList.ToArray(); w.Write(ts, true); } using (DssReader reader = new DssReader(fn)) { TimeSeries ts = reader.GetTimeSeries(new DssPath("/a/b/c//IR-Year/f/")); for (int i = 0; i < ts.Values.Length; i++) { Assert.AreEqual(ts.Qualities[i], qList[i]); } } using (DssWriter w = new DssWriter(fn)) { var ts = w.GetTimeSeries(new DssPath("/a/b/c//IR-Year/f/")); qList.Clear(); for (int i = 0; i < ts.Values.Length; i++) { BaseQualityFlags flag = (BaseQualityFlags)q.GetValue(r.Next(q.Length)); Quality newQuality = new Quality(flag); qList.Add(newQuality.Value); } ts.Qualities = qList.ToArray(); w.Write(ts, true); } using (DssReader reader = new DssReader(fn)) { TimeSeries ts = reader.GetTimeSeries(new DssPath("/a/b/c//IR-Year/f/")); for (int i = 0; i < ts.Values.Length; i++) { Assert.AreEqual(ts.Qualities[i], qList[i]); } } }