Exemplo n.º 1
0
        static void Main(string[] args)
        {
            /*if(  args.Length != 4)
             * {
             * Console.WriteLine("Usage:hdf_to_dss.exe file.h5 StartDateTime interval output.dss");
             * Console.WriteLine("example:hdf_to_dss.exe file.h5 \"1-1-2000 1:00 am\"  1Hour  output.dss");
             * return;
             * }
             */
            string   interval = "1Hour";
            DateTime t        = DateTime.Parse("1-1-2000 1:00 am");
            string   fnDss    = "a.dss";
            string   fnHDF    = @"C:\project\HDF_To_DSS\HDF_To_DSS\SampleData100Years.wg";

            //add dss 6 example
            using (Hec.Dss.DssWriter dss = new Hec.Dss.DssWriter(fnDss)) {
                using (H5Assist.H5Reader h5 = new H5Reader(fnHDF))
                {
                    var realizations = h5.GetGroupNames(H5Reader.Root); // realization level.
                    foreach (var realization in realizations)
                    {
                        int startLifeCycleNumber = (int.Parse(realization.ToLower().Replace("realization", "")) - 1) * 20;
                        var binNames             = h5.GetGroupNames(Path(realization));
                        foreach (var bin in binNames)
                        {
                            startLifeCycleNumber++;
                            var     names = h5.GetDatasetNames(Path(realization, bin));
                            float[] data  = null;
                            foreach (var dsn in names)
                            {
                                String binPath = Path(realization, bin, dsn);
                                //var tn = h5.GetAttributeNamesAndTypes(binPath);
                                int ndims = h5.GetDatasetNDims(binPath);
                                if (ndims != 1)
                                {
                                    throw new Exception("Expecting 1D data sets...");
                                }
                                h5.ReadDataset(binPath, ref data);

                                Console.WriteLine(binPath + " : " + data.Length);

                                //string dssPath = BuildDssPath(dsn,binPath)
                                string F         = "C:" + startLifeCycleNumber.ToString().PadLeft(6, '0') + "|swg";
                                string parameter = "PRECIP-INC";
                                string units     = "inches";
                                string dataType  = "PER-CUM";
                                if (dsn.ToLower().Contains("temperature"))
                                {
                                    units     = "F";
                                    dataType  = "PER-AVER";
                                    parameter = "Temperature";
                                }
                                string dssPath = "/Trinity/" + dsn + "/" + parameter + "//" + interval + "/" + F + "/";
                                WriteToDss(dss, data, dssPath, t, units, dataType);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public static Watershed Read(H5Reader h5r, string watershedName)
        {
            string root = Path(H5Reader.Root, "Watersheds", watershedName);

            long[] dtTicks = null;
            float[,] data = null;

            Watershed retn = new Watershed(watershedName);

            var locationNames = h5r.GetGroupNames(root);

            foreach (var loc in locationNames)
            {
                var forecastNames = h5r.GetGroupNames(Path(root, loc));

                foreach (var forecastDate in forecastNames)
                {
                    //Watersheds/EastSierra/BCAC1/2013_307
                    string forecastPath = Path(root, loc, forecastDate);
                    if (!TryParseIssueDate(forecastDate, out DateTime issueDate))
                    {
                        Console.WriteLine("ERROR IN HDF5 PATH: " + forecastPath);
                        continue;
                    }

                    h5r.ReadDataset(Path(forecastPath, "Times"), ref dtTicks);
                    h5r.ReadDataset(Path(forecastPath, "Values"), ref data);
                    var _times = dtTicks.Select(t => new DateTime(t)).ToArray();
                    retn.AddForecast(loc, issueDate, data, _times);
                }
            }

            return(retn);
        }
        private static void ReadAllFormats(string watershedName)
        {
            //TODO - compare validateWatershed data with computed

            File.AppendAllText(logFile, NL);
            File.AppendAllText(logFile, "---------- Reading  Ensembles ----------" + NL);
            string fn;

            // TimeSeriesOfEnsembleLocations wshedData=null;
            DateTime startTime = DateTime.MinValue;
            DateTime endTime   = DateTime.MaxValue;

            // DSS
            fn = "ensemble_V7_" + tag + ".dss";
            ReadTimed(fn, () =>
            {
                return(DssEnsemble.Read(watershedName, startTime, endTime, fn));
            });

            fn = "ensemble_V7_profiles_" + tag + ".dss";
            ReadTimed(fn, () =>
            {
                return(DssEnsemble.ReadTimeSeriesProfiles(watershedName, startTime, endTime, fn));
            });

            // SQLITE
            fn = "ensemble_sqlite_blob_" + tag + ".db";
            ReadTimed(fn, () =>
            {
                return(SqLiteEnsemble.Read(watershedName, startTime, endTime, fn));
            });

            // Pisces
            fn = "ensemble_pisces_" + tag + ".pdb";
            ReadTimed(fn, () =>
            {
                return(SqLiteEnsemble.Read(watershedName, startTime, endTime, fn));
            });

            // Serial HDF5
            fn = "ensemble_serial_1RowPerChunk.h5";
            ReadTimed(fn, () =>
            {
                using (var hr = new H5Reader(fn))
                    return(HDF5Ensemble.Read(hr, watershedName));
            });


            // Parallel HDF5
            foreach (int c in new[] { 1, 10, -1 })
            {
                fn = "ensemble_parallel_" + c.ToString() + "RowsPerChunk.h5";
                ReadTimed(fn, () =>
                {
                    using (var hr = new H5Reader(fn))
                        return(HDF5Ensemble.Read(hr, watershedName));
                });
            }
        }