public void WritePairedData() { var fn = "test_write_paired_data.dss"; File.Delete(fn); using (var w = new DssWriter(fn)) { var x = new double[] { 1.0, 2.0, 3.0 }; var y = new double[] { 10.0, 20.0, 30.0 }; PairedData pd = new PairedData(); pd.Ordinates = x; pd.Values = new List <double[]>(); pd.Values.Add(y); PairedData pd2 = new PairedData( new double[] { 1.0, 2.0, 3.0 }, new double[] { 10.0, 20.0, 30.0 }); var myList = new List <double[]>(3); myList.Add(new double[] { 10.0, 20.0, 30.0 }); myList.Add(new double[] { 100.0, 200.0, 300.0 }); myList.Add(new double[] { 1000.0, 2000.0, 3000.0 }); PairedData pd3 = new PairedData(new double[] { 1.0, 2.0, 3.0 }, myList, new List <string>(), "", "", "", "", "/a/b/stage-flow//e/f/"); w.Write(pd3); } }
public void V6() { string fn = "crash_me6.dss"; File.Delete(fn); Hec.Dss.Native.DSS.ZSet("DSSV", "", 6); using (DssWriter w = new DssWriter(fn)) { for (int pn = 0; pn < 7000; pn++) { var d = CreateDoubles((int)Math.Pow(10, 7)); string path = "/dss-test/csharp/series" + pn + "//1day/file-size-test/"; TimeSeries ts = new TimeSeries(path, d, DateTime.Now.Date, "cfs", "INST-VAL"); //int status = w.StoreTimeSeriesRegular(path, d, 0, DateTime.Now.Date, "cfs", "INST-VAL"); w.Write(ts); if (pn % 10 == 0) { FileInfo fi = new FileInfo(fn); var s = pn + " " + BytesToString(fi.Length); Console.WriteLine(s); } } } }
public void ReadWriteExistingDailyRegular() { var fn = "dot_net_ReadWriteDailyRegular.dss"; var t = new DateTime(1965, 1, 1); var ts = CreateSampleTimeSeries(t, "cfs", "Inst-Val"); ts.Path = new DssPath("/dotnet/csharp/values//1Day//"); File.Delete(fn); using (DssWriter w = new DssWriter(fn)) { w.Write(ts); t = new DateTime(1965, 1, 1); var ts2 = w.GetTimeSeries(ts.Path, ts.StartDateTime, ts.Times[ts.Times.Length - 1]); var t2 = new DateTime(1966, 1, 1); var ts3 = w.GetTimeSeries(ts.Path, t2, t2.AddDays(2)); ts3.Values[0] = 1; ts3.Values[1] = 1; w.Write(ts3); var ts4 = w.GetTimeSeries(ts.Path, ts.StartDateTime, ts.Times[ts.Times.Length - 1]); Assert.AreEqual(ts4.Count, ts2.Count); } }
private static void RunWriteTest(string dssFile) { using (DssWriter dss = new DssWriter(dssFile)) { DssPathCollection paths = dss.GetCatalog(); var pathsFound = paths.FilterByPart("Basin", "Location", "Flow", "", "1Hour", "C Test"); DssPath path = pathsFound[0]; //string path = PathBuilder.FormPathName("Basin", "Location", "Flow", "", "1Hour", "C Test"); double[] values = new double[300]; for (int i = 0; i < 300; i++) { values[i] = (double)i; } DateTime dateTime = new DateTime(2001, 1, 21, 12, 0, 0, 0); TimeSeries ts = new TimeSeries(); ts.Path = path; ts.Values = values; ts.StartDateTime = dateTime; ts.Units = "cfs"; ts.DataType = "Inst-Val"; //dss.StoreTimeSeriesRegular(path, values, 0, dateTime, "cfs", "Inst-Val"); dss.Write(ts, true); //dss.StoreTimeSeriesRegular("/Basin/Location/Flow//1Hour/C Test/", values, 0, "21Jan2001", "1200", "cfs", "Inst-Val"); ts = dss.GetTimeSeries(path); LocationInformation data = dss.GetLocationInfo(path.FullPath); Console.ReadLine(); } }
private void AddTS(DssWriter w, DateTime t, string path) { var ts = TimeSeriesTest.CreateSampleTimeSeries(t, "ft", "", 86400, 11); ts.Path = new DssPath(path); w.Write(ts, true); }
public void LargePartF() {// #define MAX_PART_SIZE 65, want to increase to 150 string fn = "large_F_part.dss"; File.Delete(fn); using (DssWriter w = new DssWriter(fn)) { int size = 60; do { var F = size.ToString().PadRight(size, 'a'); DssPath path = new DssPath("/feature/increase-part-f/FLOW//1day/" + F + "/"); var d = CreateDoubles(10); int status = w.Write(new TimeSeries(path, d, DateTime.Now.Date, "cfs", "INST-VAL")); if (status != 0) { break; } var s = w.GetTimeSeries(path); if (s == null || s.Count != 10) { break; } Console.WriteLine(size + ", " + path); size++; } while (size < 1000); } }
public void WriteThenReadVerticalDatum() { VerticalDatumInfo vdi = CreateVDI(); var locationInfo = new LocationInformation(); LocationInformation loc; locationInfo.XOrdinate = 765.432; locationInfo.VerticalDatumInfo = vdi; string path = "a/b/Location Info"; var dssFile = "WriteThenReadVerticalDatum.dss"; File.Delete(dssFile); using (var w = new DssWriter(dssFile)) { w.StoreLocation(path, locationInfo); } using (var r = new DssReader(dssFile)) { loc = r.GetLocationInfo(path); DoAssertions(CreateVDI(), loc.VerticalDatumInfo); Assert.AreEqual(locationInfo.XOrdinate, loc.XOrdinate); } Console.WriteLine(loc.VerticalDatumInfo.ToXml(true)); }
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 void TestTimeSeriesProfile() { string filename = "TestTimeSeriesProfile.dss"; File.Delete(filename); using (var w = new DssWriter(filename)) { var p = CreateProfileData(10000, 12); w.Write(p, true); var p2 = w.GetTimeSeriesProfile(p.Path); Assert.AreEqual(p.ColumnValues.Length, p2.ColumnValues.Length); for (int r = 0; r < p.Values.GetLength(0); r++) { for (int c = 0; c < p.Values.GetLength(1); c++) { Assert.AreEqual(p.Values[r, c], p2.Values[r, c], 0.0001); } } } }
public void TestCoverIrregular() { TimeSeries ts = new TimeSeries(); ts.Path = new DssPath("/TestCoverIrregular/csharp/flow//IR-Day/v1/"); var timestamps = new List <DateTime>(); timestamps.Add(new DateTime(2000, 1, 21)); timestamps.Add(new DateTime(2002, 1, 1)); timestamps.Add(new DateTime(2002, 1, 1)); timestamps.Add(new DateTime(2002, 1, 2)); timestamps.Add(new DateTime(2002, 1, 3)); timestamps.Add(new DateTime(2003, 2, 1)); ts.Values = new double[6] { 1, 2, 3, 4, 5, 6 }; ts.Times = timestamps.ToArray(); string fn = "TestCoverIrregular.dss"; File.Delete(fn); using (DssWriter w = new DssWriter(fn)) { w.Write(ts); DateTime t1 = new DateTime(2001, 1, 1); DateTime t2 = new DateTime(2002, 3, 1); var c = w.GetCatalog(); var ts2 = w.GetTimeSeries(c[0], t1, t2, TimeWindow.TimeWindowBehavior.Cover); Assert.AreEqual(1, ts2[0].Value); Assert.AreEqual(6, ts2[ts2.Count - 1].Value); } }
public void QualityUsageWithTimeSeriesPoint() { string fn = TestUtility.BasePath + "sample7.dss"; TimeSeriesPoint pt; using (DssWriter w = new DssWriter(fn)) { TimeSeries ts = w.GetTimeSeries(new DssPath("/EF RUSSIAN/COYOTE/FLOW-RES IN/01Mar2006/1Hour/SMOOTH/")); pt = ts[0]; if (!IsQualitySet(pt, BaseQualityFlags.Okay) || IsQualitySet(pt, BaseQualityFlags.Protected | BaseQualityFlags.Okay)) { pt.SetQuality(BaseQualityFlags.Protected | BaseQualityFlags.Okay); } } Assert.AreEqual(pt.Quality, "Okay, Protected, OriginalValue, NoRevision"); Assert.IsTrue(IsQualitySet(pt, BaseQualityFlags.Okay)); Assert.IsTrue(IsQualitySet(pt, BaseQualityFlags.Protected)); /* * if( pt.ModifiedBy == QualityModified.OriginalValue ) * { * * } * pt.ModifiedBy = Modified.DATVUE; * pt.ReplacementMethod = ReplacementMethods.NoRevision; */ }
private static void WriteToDss(DssWriter dss, float[] data, string dssPath, DateTime startTime, string units, string dataType) { double[] d = new double[data.Length]; Array.Copy(data, d, d.Length); // insert leap days... copy prev value... Hec.Dss.TimeSeries ts = new TimeSeries(dssPath, d, startTime, units, dataType); dss.Write(ts, true); }
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 CreateVersion7FileExplicit() { string fn = TestUtility.BasePath + "newV7.dss"; File.Delete(fn); using (DssWriter w = new DssWriter(fn, 7)) { Assert.IsTrue(w.GetDSSFileVersion() == 7); } }
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]); } } }
private void ImportPairedData(string destination, string worksheet) { string fileName = destination; File.Delete(fileName); PairedData pd = GetPairedData(worksheet); using (DssWriter w = new DssWriter(fileName)) { w.Write(pd); } }
public void AppendWithTimeGapRegularTimeSeries6() { DateTime t1 = new DateTime(1965, 1, 1); DateTime t2 = new DateTime(1975, 1, 1); var fn = "dot_net_AppendWithTimeGapRegularTimeSeries6.dss"; using (DssWriter w = new DssWriter(fn)) { var Path = new DssPath("/dotnet/csharp/values//1Day//"); var all = w.GetTimeSeries(Path, t1, t2); Assert.AreEqual(22, all.Count); } }
private void ImportIrregularTimeSeries(string destination, string worksheet) { string fileName = destination; File.Delete(fileName); TimeSeries ts = GetTimeSeries(worksheet); ts.Path = new DssPath("excel", "import", "plugin", "", "IR-Year", "irregularTimeSeries" + RandomString(3)); using (DssWriter w = new DssWriter(fileName)) { w.Write(ts); } }
public void SortedCatalog() { string filename = "test_sorted_catalog.dss"; File.Delete(filename); using (DssWriter w = new DssWriter(filename)) { TimeSeries s = new TimeSeries(); ///YYYYMMDD-hhmm string[] unsorted = new string[] { "/Z/csharp/values/31Dec2000/1Day//", "/A/csharp/values/31Dec2000/1Day/C:000001|T:20130312-1201|/", "/B/csharp/values/31Dec2000/1Day//", "/A/csharp/values/31Dec2000/1Day/C:000001|T:20130311-1201|/", "/B/csharp/values/01Jan2000/1Day/C:000002|T:20130312-1201|/" }; for (int i = 0; i < unsorted.Length; i++) { DateTime t = new DateTime(2000, 12, 31); if (i == 4) { t = new DateTime(2000, 1, 1); } AddTS(w, t, unsorted[i]); } string[] sorted = new string[] { "/A/csharp/values/31Dec2000/1Day/C:000001|T:20130311-1201|/", "/A/csharp/values/31Dec2000/1Day/C:000001|T:20130312-1201|/", "/B/csharp/values/01Jan2000/1Day/C:000002|T:20130312-1201|/", "/B/csharp/values/31Dec2000/1Day//", "/Z/csharp/values/31Dec2000/1Day//" }; var paths = w.GetCatalog(); foreach (var path in paths) { Console.WriteLine(path.FullPath); } Console.WriteLine(); for (int i = 0; i < paths.Count; i++) { Console.WriteLine(paths[i].PathWithoutDate); var p = new DssPath(sorted[i]); Assert.AreEqual(p.PathWithoutDate, paths[i].PathWithoutDate); } } }
public void CheckWhichQualitiesAreSet() { string fn = TestUtility.BasePath + "Russian_TimeSeries.dss"; using (DssWriter w = new DssWriter(fn)) { TimeSeries ts = w.GetTimeSeries(new DssPath("/AUSTIN C/CAZADERO CA/FLOW//15MIN/USGS/")); List <string> qualities = new List <string>(); for (int i = 0; i < 20; i++) { qualities.Add(Quality.ToString(ts.Qualities[i])); } } }
public void CheckWhichQualitiesAreSet2() { string fn = TestUtility.BasePath + "MathFunctions_1-2.dss"; using (DssWriter w = new DssWriter(fn)) { TimeSeries ts = w.GetTimeSeries(new DssPath("/FOX RIVER/LUTZ PARK/FLOW-RES OUT//15Minute/USGS-CST-FIXED/")); List <string> qualities = new List <string>(); for (int i = 0; i < 20; i++) { qualities.Add(Quality.ToString(ts.Qualities[i])); } } }
public void GetQualityStats() { string fn = TestUtility.BasePath + "Russian_TimeSeries.dss"; using (DssWriter w = new DssWriter(fn)) { TimeSeries ts = w.GetTimeSeries(new DssPath("/AUSTIN C/CAZADERO CA/FLOW//15MIN/USGS/")); var l = ts.ToTimeSeriesPoints(); var a = l[0]; var q = a.QualityStats; var b = QualityStats(a, false, true); var c = QualityStats(a, true, false); } }
public static void Write(string dssFileName, Watershed watershed) { bool saveAsFloat = true; float[] ensembleMember = null; int count = 0; using (var w = new DssWriter(dssFileName, DssReader.MethodID.MESS_METHOD_GLOBAL_ID, DssReader.LevelID.MESS_LEVEL_CRITICAL)) { foreach (Location loc in watershed.Locations) { if (count % 100 == 0) { Console.Write("."); } int memberCounter = 0; foreach (Forecast f in loc.Forecasts) { int size = f.Ensemble.GetLength(0); for (int i = 0; i < size; i++) { f.EnsembleMember(i, ref ensembleMember); memberCounter++; /// A/B/FLOW//1 Hour/<FPART></FPART> //// c: ensemble.p var t = f.IssueDate; // /RUSSIANNAPA/APCC1/FLOW/01SEP2019/1HOUR/C:000002|T:0212019/ string F = "C:" + memberCounter.ToString().PadLeft(6, '0') + "|T:" + t.DayOfYear.ToString().PadLeft(3, '0') + t.Year.ToString(); var path = "/" + watershed.Name.ToString() + "/" + loc.Name + "/Flow//1Hour/" + F + "/"; Hec.Dss.TimeSeries timeseries = new Hec.Dss.TimeSeries { Values = Array.ConvertAll(ensembleMember, item => (double)item), Units = "", DataType = "INST-VAL", Path = new DssPath(path), StartDateTime = f.TimeStamps[0] }; w.Write(timeseries, saveAsFloat); count++; } } } } }
private void WriteRecords(IEnumerable <TimeSeries> records) { if (!TrySelectingDssFileName()) { return; } using (DssWriter w = new DssWriter(DssFileName)) { foreach (var record in records) { w.Write(record); } } DisplayImportStatus(DssFileName); }
public void QualitySizeMatchesValueSize() { string fn = TestUtility.BasePath + "Russian_TimeSeries.dss"; using (DssWriter w = new DssWriter(fn)) { TimeSeries ts = w.GetTimeSeries(new DssPath("/AUSTIN C/CAZADERO CA/FLOW//15MIN/USGS/")); if (ts.Qualities == null) { Assert.AreEqual(null, ts.Qualities); } else { Assert.AreEqual(ts.Qualities.Length, ts.Values.Length); } } }
private static void GenerateRecords(string dssFile) { string[] possibleCParts = { "%", "Area", "Code", "Coeff", "Conc", "Cond", "Count", "Currency", "Current", "Depth", "Dir", "Dist", "Elev", "Energy", "Evap", "EvapRate", "Fish", "Flow", "Frost", "Head", "Height", "Irrad", "Length", "Opening", "Power", "Precip", "Pres", "Rad", "Ratio", "Rotation", "Speed", "SpinRate", "Stage", "Stor", "Temp", "Thick", "Timig", "Travel", "Turb", "TurbF", "TurbJ", "TurbN", "Volt", "Volume", "Width", "pH" }; string[] possibleUnits = { "%", "ft2", "n/a", "n/a", "ppm", "umho/cm", "unit", "$", "ampere", "in", "deg", "mi", "ft", "MWH", "in", "in/day", "unit", "cfs", "in", "ft", "ft", "langley/min", "ft", "ft", "MW", "in", "in-hg", "langley", "n/a", "deg", "mph", "rpm", "ft", "ac-ft", "F", "in", "sec", "mi", "JTU", "FNU", "JTU", "NTU", "volt", "ft3", "ft", "su" }; using (DssWriter dss = new DssWriter(dssFile)) { Random rng = new Random(); DateTime start = new DateTime(1969, 1, 1); DateTime randomDate = generateRandomDate(rng, start); for (int i = 0; i < 100; i++) { int cPartchosen = rng.Next(0, possibleCParts.Length); string CPart = possibleCParts[cPartchosen]; string pathname = GenerateRandomPathName(CPart, turnIntoAcceptableDate(randomDate.ToString("MM-dd-yyyy")), rng); dss.Write(new TimeSeries(pathname, new double[300], randomDate, possibleUnits[cPartchosen], "INST-VAL")); } } }
public void ReadWriteBasicIrregular() { var fn = "dot_net_ReadWriteBasicIrregular.dss"; var t = new DateTime(1965, 1, 1); var ts = CreateSampleTimeSeries(t, "CFS", "PER-AVER", size: 10000); ts.Path = new DssPath("/dotnet/csharp/values//IR-Year//"); File.Delete(fn); using (DssWriter w = new DssWriter(fn)) { w.Write(ts); var ts2 = w.GetTimeSeries(ts.Path, ts.StartDateTime, ts.Times[ts.Times.Length - 1]); Console.WriteLine(ts2.Path); Compare(ts, ts2); } }
public void BlockTest() { String fileName = @"C:\temp\block_test.dss"; File.Delete(fileName); using (DssWriter dss = new DssWriter(fileName)) { DateTime t = new DateTime(2020, 1, 2); var ts_12Min = CreateSampleTimeSeries(t, "cfs", "Inst-VAl", 12 * 60, 14400 / 12); var ts_1Min = CreateSampleTimeSeries(t, "cfs", "Inst-VAl", 1 * 60, 14400 / 1); ts_12Min.Path = new DssPath("/test/block_12/c//12Minute/f/"); ts_1Min.Path = new DssPath("/test/block_1/c//1Minute/f/"); dss.Write(ts_12Min); dss.Write(ts_1Min); } }
public void ReadWriteSecondIrregular() { var fn = "dot_net_ReadWriteSecondIrregular.dss"; var t = new DateTime(1970, 2, 28); var ts = CreateSampleTimeSeries(t, "feet", "PER-AVER", 1); ts.Path = new DssPath("/dotnet/csharp/values//IR-Day//"); // ts.Path = "/dotnet/csharp/values//~1Second//"; File.Delete(fn); using (DssWriter w = new DssWriter(fn)) { w.Write(ts); var ts2 = w.GetTimeSeries(ts.Path, ts.StartDateTime, ts.Times[ts.Times.Length - 1]); Console.WriteLine(ts2.Path); Compare(ts, ts2); } }
public void ReadWriteDailyRegular() { var fn = "dot_net_ReadWriteDailyRegular.dss"; var t = new DateTime(1965, 1, 1); var ts = CreateSampleTimeSeries(t, "cfs", "Inst-Val"); ts.Path = new DssPath("/dotnet/csharp/values//1Day//"); File.Delete(fn); using (DssWriter w = new DssWriter(fn)) { w.Write(ts); t = new DateTime(1965, 1, 1); var ts2 = w.GetTimeSeries(ts.Path, ts.StartDateTime, ts.Times[ts.Times.Length - 1]); Console.WriteLine(ts2.Path); Compare(ts, ts2); } }