Ejemplo n.º 1
0
 private static void Route(TimeInterval interval, string cbtt, string pcode, Series s)
 {
     Console.WriteLine("Processing " + cbtt + "_" + pcode + " " + s.Count + " records");
     if (interval == TimeInterval.Daily)
     {
         TimeSeriesRouting.RouteDaily(s, cbtt, pcode, RouteOptions.Outgoing);
     }
     else
     {
         TimeSeriesRouting.RouteInstant(s, cbtt, pcode, RouteOptions.Outgoing);
     }
 }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            if (args.Length != 6)
            {
                Console.WriteLine("Usage:  GetIdahowPowerData stationID q|d type ndays cbtt pcode ");
                Console.WriteLine("Where:   q     -- quarter hour (15 minute data)");
                Console.WriteLine("         d     -- daily data");
                Console.WriteLine("        type   -- idaho power code  i.e. 'HCOut' ");
                Console.WriteLine("        ndays  -- how many days to retrieve");
                Console.WriteLine("        cbtt   -- hydromet cbtt ");
                Console.WriteLine("        pcode  -- hydromet parameter code");
                return;
            }


            string stationID = args[0];
            string period    = args[1];
            string ipcoType  = args[2];
            int    numDays   = 7;

            int.TryParse(args[3], out numDays);
            string cbtt  = args[4];
            string pcode = args[5];

            TimeInterval interval = TimeInterval.Daily;

            if (period.ToLower() != "d")
            {
                interval = TimeInterval.Irregular;
            }


            var s = Reclamation.TimeSeries.IdahoPower.IdahoPowerSeries.GetIdahoPowerData(stationID, ipcoType, numDays, interval);

            if (interval == TimeInterval.Daily)
            {
                TimeSeriesRouting.RouteDaily(s, cbtt, pcode, RouteOptions.Outgoing);
            }
            if (interval == TimeInterval.Irregular)
            {
                TimeSeriesRouting.RouteInstant(s, cbtt, pcode, RouteOptions.Outgoing);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// reads USGS instant streamflow data and saves in Hydromet format
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine("Usage: ImportUsgs site_list.csv hoursBack");
                return;
            }

            int hoursBack = Convert.ToInt32(args[1]);

            Point.MissingValueFlag = 998877;
            bool errors = false;

            CsvFile csv = new CsvFile(args[0], CsvFile.FieldTypes.AllText);

            foreach (DataRow row in csv.Rows)
            {
                var    interval       = GetInterval(row);
                string site_id        = row["site_id"].ToString();
                string usgs_parameter = row["usgs_parameter"].ToString();
                string pcode          = row["pcode"].ToString();
                string cbtt           = row["cbtt"].ToString();
                Series s;

                Console.WriteLine(cbtt);
                if (interval == TimeInterval.Daily)
                {
                    if (usgs_parameter.ToLower() == "gageheight")
                    {
                        s = new UsgsDailyValueSeries(site_id, UsgsDailyParameter.DailyMeanDischarge);
                    }
                    else
                    {
                        Logger.WriteLine("Error: the parameter '" + usgs_parameter + "' is not yet supported");
                        s = new Series();
                    }
                    s.Read(DateTime.Now.AddHours(-hoursBack), DateTime.Now);
                    TimeSeriesRouting.RouteDaily(s, cbtt, pcode, RouteOptions.Outgoing);
                }
                else if (interval == TimeInterval.Irregular)
                {
                    if (usgs_parameter.ToLower() == "watertemp")
                    {
                        s = new UsgsRealTimeSeries(site_id, UsgsRealTimeParameter.Temperature);
                    }
                    else
                    if (usgs_parameter.ToLower() == "gageheight")
                    {
                        s = new UsgsRealTimeSeries(site_id, UsgsRealTimeParameter.GageHeight);
                    }
                    else if (usgs_parameter.ToLower() == "discharge")
                    {
                        s = new UsgsRealTimeSeries(site_id, UsgsRealTimeParameter.Discharge);
                    }
                    else
                    {
                        Logger.WriteLine("Error: the parameter '" + usgs_parameter + "' is not yet supported");
                        s = new Series();
                    }

                    try
                    {
                        s.Read(DateTime.Now.AddHours(-hoursBack), DateTime.Now);

                        if (usgs_parameter.ToLower() == "watertemp" && pcode.ToLower() == "wf")
                        {
                            //(°C × 9/5) + 32 = °F
                            s = s * 9.0 / 5.0 + 32.0;
                        }

                        s.RemoveMissing();
                        if (s.Count > 0)
                        {
                            TimeSeriesRouting.RouteInstant(s, cbtt, pcode, RouteOptions.Outgoing);
                        }
                    }
                    catch (Exception e)
                    {
                        errors = true;
                        Console.WriteLine(e.Message);
                    }
                }
            }



            if (errors)
            {
                throw new Exception("Error reading one or more sites");
            }
        }