Example #1
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);
        }
Example #2
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);
                            }
                        }
                    }
                }
            }
        }