public void CheckIfDPartComingOutAsDateTimeNoRange() { string dssFile = @".\tempdssfile.dss"; string srcFile = TestUtility.BasePath + "version7AlbersGrid.dss"; File.Delete(dssFile); CopyAsReadWrite(srcFile, dssFile); string path = @"/SHG/TRUCKEE RIVER/TEMP-AIR/31JAN2016:2400//INTERPOLATED-ROUNDED/"; using (DssReader dss = new DssReader(dssFile)) { DssPathCollection paths = dss.GetCatalog(); var dsspath = paths.FindExactPath(path); if (dsspath != DssPath.NotFound) { var dpartdt = dsspath.GetDPartAsDateTime(); Assert.IsTrue(dpartdt.Month == 2); Assert.IsTrue(dpartdt.Day == 1); Assert.IsTrue(dpartdt.Year == 2016); Assert.IsTrue(dpartdt.Hour == 0); Assert.IsTrue(dpartdt.Minute == 0); } else { Assert.Fail(); } } }
public void ReadConnecticutGrids() { // This path doesn't have a E part..... DssPath path = new DssPath("/SHG/CONNECTICUT/AIRTEMP/07MAY2019:1400//GAGEINTERP/"); string fn = TestUtility.BasePath + "ConnecticutGrids.dss"; DssReader r = new DssReader(fn); var catalog = r.GetCatalog(); for (int i = 0; i < catalog.Count; i++) { var p = catalog[i].FullPath; if (p.IndexOf("GAGEINTERP") > 0) { Console.WriteLine(p); } } Assert.IsTrue(r.ExactPathExists(path)); Grid g1 = r.GetGrid(path, false); Grid g2 = r.GetGrid(path, true); Assert.IsNotNull(g1); Assert.IsNotNull(g2); string expected = Hec.Dss.Native.DSS.AlbersSRS(); Console.WriteLine("expected:\n" + expected); Console.WriteLine(g2.SRSDefinition); Assert.IsTrue(expected.ToLower() == g2.SRSDefinition.ToLower()); // Assert.IsTrue(g1.SRSDefinitionType == 1); }
public void ReadAllGrids() { string fn = TestUtility.BasePath + "precip.2018.09.dss"; string pathname = "/SHG/MARFC/PRECIP///NEXRAD/"; var targetDSSPath = new DssPath(pathname); double sum = 0; using (var dssr = new DssReader(fn, DssReader.MethodID.MESS_METHOD_GENERAL_ID, DssReader.LevelID.MESS_LEVEL_CRITICAL)) { var cat = dssr.GetCatalog(false); var paths = cat.Paths.Select(dssPath => dssPath.FullPath).ToArray(); var filterPaths = PathAssist.FilterByPart(paths, targetDSSPath); for (int i = 0; i < filterPaths.Count; i++) { string subpath = filterPaths[i]; var dssPath = new DssPath(subpath); var grd = dssr.GetGrid(dssPath, true); sum += grd.MaxDataValue; } Console.WriteLine(sum.ToString()); } }
public void CheckIfDPartComingOutAsDateTimeWithRange() { string dssFile = @".\tempdssfile.dss"; string srcFile = TestUtility.BasePath + "version7AlbersGridsTimeSeries.dss"; File.Delete(dssFile); CopyAsReadWrite(srcFile, dssFile); string path = @"//BERLIN/FLOW/01May2016-01Jun2016/1Hour/Q0W0/"; using (DssReader dss = new DssReader(dssFile)) { DssPathCollection paths = dss.GetCatalog(); var dsspath = paths.FindExactPath(path); if (dsspath != DssPath.NotFound) { var dpartdt = (dsspath as DssPathCondensed).GetDPartAsDateTimeRange(); Assert.IsTrue(dpartdt.Item1.Month == 5); Assert.IsTrue(dpartdt.Item1.Day == 1); Assert.IsTrue(dpartdt.Item1.Year == 2016); Assert.IsTrue(dpartdt.Item2.Month == 6); Assert.IsTrue(dpartdt.Item2.Day == 1); Assert.IsTrue(dpartdt.Item2.Year == 2016); } else { Assert.Fail(); } } }
public void FilterTest() { string fn = Path.GetFullPath(TestUtility.BasePath + "NDFD_Wind.dss"); string pathname = "/SHG/CONUS/WIND DIRECTION///NDFD (YUBZ98) (001-003)/"; /* Catalog.Paths: * [0]: "/SHG/CONUS/WIND DIRECTION/08SEP2018:2400-11SEP2018:2400//NDFD (YUBZ98) (001-003)/" * [1]: "/SHG/CONUS/WIND SPEED/08SEP2018:2400-11SEP2018:2400//NDFD (YWUZ98) (001-003)/" */ using (var dssr = new DssReader(fn)) { var targetDSSPath = new DssPath(pathname); // Should cache catalogue in local var? var cat = dssr.GetCatalog(false); // var paths = cat.Paths.Select(dssPath => dssPath.FullPath).ToArray(); // var filterPaths = PathAssist.FilterByPart(paths, targetDSSPath); // No 'FilterByPart' overload that takes DSSPath objects (not strings) and accepts a dss path to filter on // D and E part are empty, but filtering is failing. Is there a wildcard? var filterPaths = PathAssist.FilterByPart(cat.Paths, targetDSSPath.Apart, targetDSSPath.Bpart, targetDSSPath.Cpart, targetDSSPath.Dpart, targetDSSPath.Epart, targetDSSPath.Fpart); if (filterPaths.Count == 0) { Console.WriteLine("No filtered paths found."); return; } } }
static void Main(string[] args) { string fn = @"C:\Users\q0hecngn\Downloads\precip.2018.09.dss"; string pathname = "/SHG/MARFC/PRECIP///NEXRAD/"; var targetDSSPath = new DssPath(pathname); double sum = 0; for (int j = 0; j < 4; j++) { using (var dssr = new DssReader(fn, DssReader.MethodID.MESS_METHOD_GENERAL_ID, DssReader.LevelID.MESS_LEVEL_CRITICAL)) { var cat = dssr.GetCatalog(false); var paths = cat.Paths.Select(dssPath => dssPath.FullPath).ToArray(); var filterPaths = PathAssist.FilterByPart(paths, targetDSSPath); for (int i = 0; i < filterPaths.Count; i++) { string subpath = filterPaths[i]; var dssPath = new DssPath(subpath); var grd = dssr.GetGrid(dssPath, true); sum += grd.MaxDataValue; } Console.WriteLine(sum.ToString()); } } }
public void TryReadCondensedPathNameFail() { using (DssReader r = new DssReader(TestUtility.BasePath + "sample7.dss")) { var catalog = r.GetCatalog(true); bool result = catalog.TryGetCondensedPath(new DssPath("//SACRAMENTO/PRECIP-INC/nothing/1Day/OBS/"), out DssPathCondensed nothing); Assert.IsFalse(result); } }
private static void RunReadTest(string dssFile) { using (DssReader dss = new DssReader(dssFile)) { DssPathCollection paths = dss.GetCatalog(); var pathsFound = paths.FilterByPart(); string path = pathsFound[0].FullPath; } }
public void CondensedPathTest() { using (DssReader r = new DssReader(TestUtility.BasePath + "AAA.dss")) { var p = r.GetCatalog(); Assert.IsTrue(p.CondensedPaths.Count == 6); Assert.IsTrue(Enumerable.SequenceEqual(p.UnCondensedPaths.OrderBy(e => e), p.Paths.OrderBy(e => e))); } }
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); } }
/// <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 void TestGetRecordType () { 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 recordType = r.GetRecordType(path); Assert.IsTrue(recordType == RecordType.RegularTimeSeries); } }
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); }
public void MissingPartF() { // var filename = @"C:\project\dotnet\Output\x64\Debug\dot_net_ReadWriteDailyRegular.dss"; string filename = TestUtility.BasePath + "sample7.dss"; DataTable rval = new DataTable(); using (DssReader r = new DssReader(filename)) { var catalog = r.GetCatalog(true); rval = catalog.ToDataTable(); } }
public void FilterGridByParts() { string fn = TestUtility.BasePath + "NDFD_Wind.dss"; using (DssReader dssr = new DssReader(fn)) { var cat = dssr.GetCatalog(false); var paths = cat.Paths.Select(dssPath => dssPath.FullPath).ToArray(); string _pathname = "/SHG/CONUS/WIND DIRECTION///NDFD (YUBZ98) (001-003)/"; var targetDSSPath = new DssPath(_pathname); var filterPaths = PathAssist.FilterByPart(paths, targetDSSPath); } }
//[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 CheckGetCorrespondingCondensedPath() { string dssFile = @".\tempdssfile.dss"; string srcFile = TestUtility.BasePath + @"benchmarks6\Ark.dss"; File.Delete(dssFile); CopyAsReadWrite(srcFile, dssFile); DssPath path = new DssPath(@"/A34-01 A34-01/-2600.0/FLOW/01JAN2003/1DAY/VER 6.1.3 03-05/"); using (DssReader reader = new DssReader(dssFile)) { DssPathCollection paths = reader.GetCatalog(); DssPathCondensed conPath = paths.GetCondensedPath(path); Assert.IsTrue(conPath != null); } }
public void ExpandPathTest() { string fn = TestUtility.BasePath + "NDFD_Wind.dss"; var sum = 0; using (var dssr = new DssReader(fn, DssReader.MethodID.MESS_METHOD_GENERAL_ID, DssReader.LevelID.MESS_LEVEL_CRITICAL)) { var cat = dssr.GetCatalog(false); foreach (var item in cat.CondensedPaths) { sum += cat.ExpandPath(item, true).Count; } Assert.IsTrue(sum == cat.UnCondensedPaths.Count); } }
public void GetHeaderInformationPairedData() { string dssFile = @".\tempdssfile.dss"; string srcFile = TestUtility.BasePath + @"benchmarks6\BaldEDmbrk.dss"; File.Delete(dssFile); CopyAsReadWrite(srcFile, dssFile); string path = @"/BALD EAGLE LOC HAV//LOCATION-ELEV//19FEB1999 2055/DAMBRKSIMBRCH/"; using (DssReader dss = new DssReader(dssFile)) { DssPathCollection paths = dss.GetCatalog(); var dsspath = paths.FindExactPath(path); var pd = dss.GetPairedData(dsspath.FullPath); Assert.IsTrue(pd.UnitsDependent == "FEET"); Assert.IsTrue(pd.TypeDependent == "UNT"); } }
public void RegularDssPathCollection() { string dssFile = @".\tempdssfile.dss"; string srcFile = TestUtility.BasePath + @"benchmarks6/BaldEDmbrk.dss"; File.Delete(dssFile); CopyAsReadWrite(srcFile, dssFile); string path = @"/BALD EAGLE LOC HAV/105178.6/FLOW-CUM/17FEB1999-23FEB1999/1MIN/DAMBRKSIMBRCH/"; using (DssReader dss = new DssReader(dssFile)) { DssPathCollection paths = dss.GetCatalog(true); var dsspath = paths.FindExactPath(path); var ts = dss.GetEmptyTimeSeries(dsspath); Assert.IsTrue(ts.Units == "ACRE-FT"); Assert.IsTrue(ts.DataType == "INST-CUM"); } }
public void GetHeaderInformationGrid() { string dssFile = @".\tempdssfile.dss"; string srcFile = TestUtility.BasePath + @"containsGrids7.dss"; File.Delete(dssFile); CopyAsReadWrite(srcFile, dssFile); string path = @"/SHG/LAKE WINNEBAGO/PRECIP/01JUN2016:0600/01JUN2016:1200/WPC-QPF/"; using (DssReader dss = new DssReader(dssFile)) { DssPathCollection paths = dss.GetCatalog(); var dsspath = paths.FindExactPath(path); var grid = dss.GetGrid(dsspath, false); Console.WriteLine(""); Assert.IsTrue(grid.DataUnits == "mm"); Assert.IsTrue(grid.DataType.ToString() == "PER_CUM"); } }
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 SupplementalInfo() { using (var r = new DssReader(TestUtility.BasePath + "VerticalDatumTest_v7.dss")) { var P = r.GetCatalog(); for (int i = 0; i < P.Count; i++) { if (P[i].Cpart.ToLower().StartsWith("location")) { Console.WriteLine(P[i].FullPath); } } var L = r.GetLocationInfo("//KEYS/Location Info////"); Console.WriteLine(L.Supplemental); //verticalDatumInfo:H4sIAAAAAAAAAHXQwQrCMAwG4PueouzedQ4mE2phIHjz6D1oCoWuhTXt89taUNR5C/8fvkBkwpXMDSy/A8WFG6c9i87QsdXUqoYx6YBMwtqry/l64sNBio+0rKHFlDPv1H43doMU76DUXuuAxDCQWYAw82ADPi/klvy3/0rqQgIbUfVdL0Udiykquu3TGjf4OfPT9JcfN/kc/n5JNQ84o4x9PAEAAA==; /** * * <vertical-datum-info unit="ft"> * <native-datum>NGVD-29</native-datum> * <elevation>615.2</elevation> * <offset estimate="false"> * <to-datum>NGVD-29</to-datum> * <value>0.0</value> * </offset> * <offset estimate="true"> * <to-datum>NAVD-88</to-datum> * <value>0.5</value> * </offset> * </vertical-datum-info> * * **/ var vdi = L.VerticalDatumInfo; var xml = vdi.ToXml(true); Console.WriteLine(xml); DoAssertions(CreateVDI(), vdi); } }
private static DataTable Catalog(string filename, bool extendedInfo = false) { DataTable rval = new DataTable(); using (DssReader r = new DssReader(filename)) { Console.WriteLine(Directory.GetCurrentDirectory()); Console.WriteLine(System.IO.Path.GetFileName(filename)); var catalog = r.GetCatalog(extendedInfo); rval = catalog.ToDataTable(); //PrintDataTable(rval); //foreach (var item in catalog) //{ // Console.WriteLine(item.FullPath + ", " + item.RecordTypeName); //} //Console.WriteLine(catalog.Count); } return(rval); }
public static Watershed ReadTimeSeriesProfiles(string watershedName, DateTime start, DateTime end, string dssFileName) { Watershed rval = new Watershed(watershedName); float[,] profile = null; using (DssReader dss = new DssReader(dssFileName, DssReader.MethodID.MESS_METHOD_GENERAL_ID, DssReader.LevelID.MESS_LEVEL_NONE)) { Console.WriteLine("Reading" + dssFileName); DssPathCollection dssPaths = dss.GetCatalog(); // sorted // var dssPaths = rawDssPaths.OrderBy(a => a, new PathComparer()).ToArray(); // sorted int size = dssPaths.Count(); if (size == 0) { throw new Exception("Empty DSS catalog"); } // /RUSSIANNAPA/APCC1/FLOW/01SEP2019/1HOUR/|T:0212019/ for (int i = 0; i < size; i++) { if (i % 100 == 0) { Console.Write("."); } DssPath path = dssPaths[i]; DateTime issueDate = ParseIssueDate(path.Fpart); if (issueDate >= start && issueDate <= end && path.Apart == watershedName) { var ts = dss.GetTimeSeriesProfile(path); ArrayUtility.TransposeDoubleToFloat(ts.Values, ref profile); rval.AddForecast(path.Bpart, issueDate, profile, ts.Times); } } } return(rval); }
static void Main(string[] args) { if (args.Length != 2) { Console.WriteLine("Usage: file.dss file.db)"); return; } var dssFileName = args[0]; var sqliteFileName = args[1]; if (File.Exists(sqliteFileName)) { throw new Exception("File allready exists " + sqliteFileName); } using (DssReader r = new DssReader(dssFileName)) { var catalog = r.GetCatalog(); var uc = GetCollections(catalog); Console.WriteLine("catlog.count = " + catalog.Count); } }