Beispiel #1
0
        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);
            }
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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);
            }
        }
Beispiel #4
0
        private void SetPathInExcelFile(string sheet, DssPath path)
        {
            workbook.Worksheets[sheet].Cells[0, 0].Value = "A";
            workbook.Worksheets[sheet].Cells[0, 1].Value = path.Apart;

            workbook.Worksheets[sheet].Cells[1, 0].Value = "B";
            workbook.Worksheets[sheet].Cells[1, 1].Value = path.Bpart;

            workbook.Worksheets[sheet].Cells[2, 0].Value = "C";
            workbook.Worksheets[sheet].Cells[2, 1].Value = path.Cpart;

            workbook.Worksheets[sheet].Cells[3, 0].Value = "D";
            workbook.Worksheets[sheet].Cells[3, 1].Value = path.Dpart;

            workbook.Worksheets[sheet].Cells[4, 0].Value = "E";
            workbook.Worksheets[sheet].Cells[4, 1].Value = path.Epart;

            workbook.Worksheets[sheet].Cells[5, 0].Value = "F";
            workbook.Worksheets[sheet].Cells[5, 1].Value = path.Fpart;
        }
Beispiel #5
0
        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 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);
        }
Beispiel #7
0
        public void Try1SecondEPart()
        {
            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 (DssWriter dss = new DssWriter(dssFile))
            {
                double[] values = new double[121];
                for (int i = 0; i < values.Length; i++)
                {
                    values[i] = 10 + i;
                }
                var dssPath = new DssPath(path);
                dssPath.Epart = "1Second";
                TimeSeries ts = new TimeSeries(dssPath.FullPath, values, dssPath.GetDPartAsDateTime(), "lol", "INST-VAL");
                dss.Write(ts, true);
            }
            //File.Delete(dssFile);
        }
Beispiel #8
0
 public void DssPathBug()
 {
     var p = new DssPath("A", "B", "C", "D", "E", "F");
     var s = p.FullPath;
 }
 public PairedData GetPairedData(DssPath dssPath)
 {
     return(_writer.GetPairedData(dssPath.FullPath));
 }
 public TimeSeries GetTimeSeries(DssPath dssPath, ConsecutiveValueCompression compression = ConsecutiveValueCompression.None)
 {
     return(_writer.GetTimeSeries(dssPath, compression: compression));
 }
 public LocationInformation GetLocationInformation(DssPath dssPath)
 {
     return(_writer.GetLocationInfo(dssPath.FullPath));
 }
 public void ResetPaths()
 {
     ts_paths.Clear();
     pd_path      = new DssPath();
     PreviousPage = null;
 }
        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));
                            }
                        }
                    }
                }
            }
        }
Beispiel #14
0
 private bool PathPartsAreValid(DssPath path)
 {
     return(path.Apart != "" || path.Bpart != "" || path.Cpart != "" || path.Fpart != "");
 }