コード例 #1
0
ファイル: UsgsUtility.cs プロジェクト: woohn/Pisces
        public static TimeSeriesDatabaseDataSet.RatingTableDataTable GetRatingTable(string siteNumber)
        {
            //string url = "http://waterdata.usgs.gov/nwisweb/data/exsa_rat/13236500.rdb";
            string url = "http://waterdata.usgs.gov/nwisweb/get_ratings?site_no=13081500&file_type=exsa";

            url = url.Replace("13081500", siteNumber);
            string[] data = Web.GetPage(url);

            TextFile tf = new TextFile(data);

            UsgsRDBFile rdb = new UsgsRDBFile(data);

            TimeSeriesDatabaseDataSet.RatingTableDataTable t = new TimeSeriesDatabaseDataSet.RatingTableDataTable();

            t.XUnits = LookupUnits(tf, "# //RATING_INDEP");
            t.YUnits = LookupUnits(tf, "# //RATING_DEP");

            for (int i = 0; i < rdb.Rows.Count; i++)
            {
                double x = Convert.ToDouble(rdb.Rows[i]["indep"]);
                double y = Convert.ToDouble(rdb.Rows[i]["dep"]);
                var    r = t.FindByx(x);
                if (r == null)
                {
                    t.AddRatingTableRow(x, y);
                }
                else
                {
                    Console.WriteLine("Warning: duplicate x " + x);
                }
            }
            t.Name = "Usgs " + siteNumber;
            return(t);
        }
コード例 #2
0
ファイル: UsgsUtility.cs プロジェクト: usbr/Pisces
        public static TimeSeriesDatabaseDataSet.RatingTableDataTable GetRatingTable(string siteNumber)
        {
            //string url = "http://waterdata.usgs.gov/nwisweb/data/exsa_rat/13236500.rdb";
              string url = "http://waterdata.usgs.gov/nwisweb/get_ratings?site_no=13081500&file_type=exsa";
              url = url.Replace("13081500", siteNumber);
              string[] data = Web.GetPage(url);

              TextFile tf = new TextFile(data);

              UsgsRDBFile rdb = new UsgsRDBFile(data);

              TimeSeriesDatabaseDataSet.RatingTableDataTable t = new TimeSeriesDatabaseDataSet.RatingTableDataTable();

              t.XUnits = LookupUnits(tf,"# //RATING_INDEP");
              t.YUnits = LookupUnits(tf,"# //RATING_DEP");

              for (int i = 0; i < rdb.Rows.Count; i++)
              {
              double x = Convert.ToDouble(rdb.Rows[i]["indep"]);
              double y = Convert.ToDouble(rdb.Rows[i]["dep"]);
              t.AddRatingTableRow(x, y);
              }
              t.Name = "Usgs " + siteNumber;
              return t;
        }
コード例 #3
0
ファイル: UsgsInventory.cs プロジェクト: woohn/Pisces
        /*  Example Inventory
         #
         #
         # US Geological Survey
         # retrieved: 2007-03-09 10:33:58 EST
         # URL: http://nwis.waterdata.usgs.gov/nwis/inventory
         #
         # The Site File stores location and general information about ground water,
         # surface water, and meteorological sites
         # for sites in USA.
         #
         # The following selected fields are included in this output:
         #
         #  agency_cd       -- Agency
         #  site_no         -- Site identification number
         #  station_nm      -- Site name
         #  lat_va          -- DMS latitude
         #  long_va         -- DMS longitude
         #  dec_lat_va      -- Decimal latitude
         #  dec_long_va     -- Decimal longitude
         #  coord_meth_cd   -- Latitude-longitude method
         #  coord_acy_cd    -- Latitude-longitude accuracy
         #  coord_datum_cd  -- Latitude-longitude datum
         #  dec_coord_datum_cd -- Decimal Latitude-longitude datum
         #  district_cd     -- District code
         #  state_cd        -- State code
         #  county_cd       -- County code
         #  country_cd      -- Country code
         #  land_net_ds     -- Land net location description
         #  map_nm          -- Name of location map
         #  map_scale_fc    -- Scale of location map
         #  alt_va          -- Altitude of Gage/land surface
         #  alt_meth_cd     -- Method altitude determined
         #  alt_acy_va      -- Altitude accuracy
         #  alt_datum_cd    -- Altitude datum
         #  huc_cd          -- Hydrologic unit code
         #  basin_cd        -- Drainage basin code
         #  topo_cd         -- Topographic setting code
         #  station_type_cd -- Site type code
         #  agency_use_cd   -- Agency use of site code
         #  data_types_cd   -- Flags for the type of data collected
         #  instruments_cd  -- Flags for instruments at site
         #  construction_dt -- Date of first construction
         #  inventory_dt    -- Date site established or inventoried
         #  drain_area_va   -- Drainage area
         #  contrib_drain_area_va -- Contributing drainage area
         #  tz_cd           -- Mean Greenwich time offset
         #  local_time_fg   -- Local standard time flag
         #  reliability_cd  -- Data reliability code
         #  gw_file_cd      -- Data-other GW files
         #  gw_type_cd      -- Type of ground water site
         #  nat_aqfr_cd     -- National aquifer code
         #  aqfr_cd         -- Local aquifer code
         #  aqfr_type_cd    -- Local aquifer type code
         #  well_depth_va   -- Well depth
         #  hole_depth_va   -- Hole depth
         #  depth_src_cd    -- Source of depth data
         #  project_no      -- Project number
         #  rt_bol          -- Real-time data flag
         #  discharge_begin_date -- Daily streamflow data begin date
         #  discharge_end_date -- Daily streamflow data end date
         #  discharge_count_nu -- Daily streamflow data count
         #  peak_begin_date -- Peak streamflow data begin date
         #  peak_end_date   -- Peak streamflow data end date
         #  peak_count_nu   -- Peak streamflow data count
         #  qw_begin_date   -- Water quality data begin date
         #  qw_end_date     -- Water quality data end date
         #  qw_count_nu     -- Water quality data count
         #  gw_begin_date   -- Ground-water data begin date
         #  gw_end_date     -- Ground-water data end date
         #  gw_count_nu     -- Ground-water data count
         #
         #
         # query started 2007-03-09 10:33:58 EST
         #
         # there are 1 sites matching the search criteria.
         #
         #
         # agency_cd	site_no	station_nm	lat_va	long_va	dec_lat_va	dec_long_va	coord_meth_cd	coord_acy_cd	coord_datum_cd	dec_coord_datum_cd	district_cd	state_cd	county_cd	country_cd	land_net_ds	map_nm	map_scale_fc	alt_va	alt_meth_cd	alt_acy_va	alt_datum_cd	huc_cd	basin_cd	topo_cd	station_type_cd	agency_use_cd	data_types_cd	instruments_cd	construction_dt	inventory_dt	drain_area_va	contrib_drain_area_va	tz_cd	local_time_fg	reliability_cd	gw_file_cd	gw_type_cd	nat_aqfr_cd	aqfr_cd	aqfr_type_cd	well_depth_va	hole_depth_va	depth_src_cd	project_no	rt_bol	discharge_begin_date	discharge_end_date	discharge_count_nu	peak_begin_date	peak_end_date	peak_count_nu	qw_begin_date	qw_end_date	qw_count_nu	gw_begin_date	gw_end_date	gw_count_nu
         # 5s	15s	50s	11s	12s	16n	16n	1s	1s	10s	10s	3s	2s	3s	2s	23s	20s	7s	8s	1s	3s	10s	16s	2s	1s	20s	1s	30s	30s	8s	8s	8s	8s	6s	1s	1s	30s	1s	10s	8s	1s	8s	8s	1s	12s
         # USGS	13010065	SNAKE RIVER AB JACKSON LAKE AT FLAGG RANCH WY	440556	1104003	44.09888889	-110.66750000	G	S	NAD83	NAD83	16	56	039	US		Flagg Ranch	  24000	6801.61	L	.01	NGVD29	17040101			YNNNNNNNNNNNNNNNNNNN	A	ANNANNNNNNNNNNNNNNNNNNNNNNNNNN	YNNNYNNNNNNNNNNNNNNNNNNNNNNNNN			486	486	MST	Y		NNNNNNNN									1	1983-10-01	2007-02-06	8530	1984-05-31	2006-05-22	23	1985-10-01	2004-09-22	255	0000-00-00	0000-00-00	0
         #
         */

        public UsgsInventory(string siteNumber)
        {
            string url = s_exactMatch.Replace("search_site_no=13010065", "search_site_no=" + siteNumber);

            string[] data = Web.GetPage(url, true);
            inventoryTable = new UsgsRDBFile(data);

            if (inventoryTable.Rows.Count <= 0)
            {
                throw new Exception("Site " + siteNumber + " not found");
            }
        }
コード例 #4
0
        private void ReadSeriesData(string url, DateTime t1, DateTime t2)
        {
            url += "&startDT=" + t1.ToString("yyyy-MM-dd") + "&endDT=" + t2.ToString("yyyy-MM-dd");
            string[] response = Web.GetPage(url, true);

            m_rdb = new UsgsRDBFile(response, true);
            ParsePreamble();
            m_columnName = "lev_va";

            for (int i = 0; i < m_rdb.Rows.Count; i++)
            {
                DataRow  row = m_rdb.Rows[i];
                DateTime t   = DateTime.MinValue;

                if (!DateTime.TryParse(row["lev_dt"].ToString(), out t))
                {
                    break;
                }
                // Read Time component
                string s = row["lev_tm"].ToString().Trim();
                if (s.Length == 4 && Regex.IsMatch(s, "[0-9]{4}"))
                {
                    int hr  = Convert.ToInt32(s.Substring(0, 2));
                    int min = Convert.ToInt32(s.Substring(2));
                    t = t.AddHours(hr);
                    t = t.AddMinutes(min);
                }

                if (t < t1 || t > t2)
                {
                    continue;
                }

                double d  = Point.MissingValueFlag;
                Point  pt = Point.Missing;
                pt.DateTime = t;
                pt.Flag     = row["lev_status_cd"].ToString();
                if (!Double.TryParse(row[m_columnName].ToString(), out d))
                {
                    Messages.Add("Error reading '" + row[m_columnName] + "' as a number");
                    AddMissing(t);
                }
                else
                {
                    pt.Value = d;
                    Add(pt);
                }
            }
        }
コード例 #5
0
ファイル: UsgsDailiyValueSeries.cs プロジェクト: woohn/Pisces
        private void ReadSeriesData(string url)
        {
            string[] response = Web.GetPage(url, true);

            m_rdb = new UsgsRDBFile(response);
            ParsePreamble();
            if (m_columnName == "")
            {
                return;
            }

            for (int i = 0; i < m_rdb.Rows.Count; i++)
            {
                DataRow  row = m_rdb.Rows[i];
                DateTime t   = DateTime.MinValue;

                if (!DateTime.TryParse(row["dateTime"].ToString(), out t))
                {
                    break;
                }
                double d  = Point.MissingValueFlag;
                Point  pt = Point.Missing;
                pt.DateTime = t;
                pt.Flag     = row[m_flagColumnName].ToString();
                if (!Double.TryParse(row[m_columnName].ToString(), out d))
                {
                    Messages.Add("Error reading '" + row[m_columnName] + "' as a number");
                    AddMissing(t);
                }
                else
                {
                    pt.Value = d;
                    Add(pt);
                }
            }
        }
コード例 #6
0
        private void ReadSeriesData(string url)
        {
            int errorCount = 0;

            string[] response = Web.GetPage(url, true);

            m_rdb = new UsgsRDBFile(response);
            ParsePreamble();
            if (m_columnName == "")
            {
                return;
            }

            for (int i = 0; i < m_rdb.Rows.Count; i++)
            {
                DataRow  row = m_rdb.Rows[i];
                DateTime t   = DateTime.MinValue;

                if (!DateTime.TryParse(row["dateTime"].ToString(), out t))
                {
                    break;
                }
                double d  = Point.MissingValueFlag;
                Point  pt = Point.Missing;
                pt.DateTime = t;
                pt.Flag     = row[m_flagColumnName].ToString();

                if (!Double.TryParse(row[m_columnName].ToString(), out d))
                {
                    Messages.Add("Error reading '" + row[m_columnName] + "' as a number");
                }
                else
                {
                    pt.Value = d;
                }

                int idxTime = this.IndexOf(t);

                if (idxTime >= 0)
                {
                    errorCount++;
                    if (errorCount > 100)
                    {
                        continue;
                    }
                    string msg = "duplicate record found at date = '" + t.ToString() + "', value =" + d;
                    Logger.WriteLine(msg);
                    Messages.Add(msg);
                    msg = "previously imported record at date ='" + this[idxTime].DateTime + "', value =" + this[idxTime].Value;
                    Logger.WriteLine(msg);
                    Messages.Add(msg);
                }
                else
                {
                    Add(pt);
                }
            }

            if (errorCount > 100)
            {
                Logger.WriteLine("Skipped " + (errorCount - 100) + " messages");
            }
        }
コード例 #7
0
ファイル: UsgsRealTimeSeries.cs プロジェクト: usbr/Pisces
        private void ReadSeriesData(string url)
        {
            int errorCount = 0;
            string[] response = Web.GetPage(url,true);

            m_rdb = new UsgsRDBFile(response);
            ParsePreamble();
            if (m_columnName == "")
            {
                return;
            }

            for (int i = 0; i < m_rdb.Rows.Count; i++)
            {
                DataRow row = m_rdb.Rows[i];
                DateTime t = DateTime.MinValue;

                if( !DateTime.TryParse(row["dateTime"].ToString(),out t))
                {
                    break;
                }
                double d = Point.MissingValueFlag;
                Point pt = Point.Missing;
                pt.DateTime = t;
                pt.Flag = row[m_flagColumnName].ToString();

                if (!Double.TryParse(row[m_columnName].ToString(), out  d))
                {
                    Messages.Add("Error reading '" + row[m_columnName] + "' as a number");
                }
                    else
                    {
                        pt.Value = d;
                    }

                int idxTime = this.IndexOf(t);

                if (idxTime >= 0)
                {
                    errorCount++;
                    if (errorCount > 100)
                        continue;
                    string msg = "duplicate record found at date = '" + t.ToString() + "', value =" + d;
                    Logger.WriteLine(msg);
                    Messages.Add(msg);
                    msg = "previously imported record at date ='"+this[idxTime].DateTime+"', value =" + this[idxTime].Value;
                    Logger.WriteLine(msg);
                    Messages.Add(msg);
                }
                    else
                    {
                        Add(pt);
                    }
            }

            if (errorCount > 100)
            {
                Logger.WriteLine("Skipped " + (errorCount - 100) + " messages");
            }
        }
コード例 #8
0
ファイル: UsgsInventory.cs プロジェクト: usbr/Pisces
        /*  Example Inventory
        #
        #
        # US Geological Survey
        # retrieved: 2007-03-09 10:33:58 EST
        # URL: http://nwis.waterdata.usgs.gov/nwis/inventory
        #
        # The Site File stores location and general information about ground water,
        # surface water, and meteorological sites
        # for sites in USA.
        #
        # The following selected fields are included in this output:
        #
        #  agency_cd       -- Agency
        #  site_no         -- Site identification number
        #  station_nm      -- Site name
        #  lat_va          -- DMS latitude
        #  long_va         -- DMS longitude
        #  dec_lat_va      -- Decimal latitude
        #  dec_long_va     -- Decimal longitude
        #  coord_meth_cd   -- Latitude-longitude method
        #  coord_acy_cd    -- Latitude-longitude accuracy
        #  coord_datum_cd  -- Latitude-longitude datum
        #  dec_coord_datum_cd -- Decimal Latitude-longitude datum
        #  district_cd     -- District code
        #  state_cd        -- State code
        #  county_cd       -- County code
        #  country_cd      -- Country code
        #  land_net_ds     -- Land net location description
        #  map_nm          -- Name of location map
        #  map_scale_fc    -- Scale of location map
        #  alt_va          -- Altitude of Gage/land surface
        #  alt_meth_cd     -- Method altitude determined
        #  alt_acy_va      -- Altitude accuracy
        #  alt_datum_cd    -- Altitude datum
        #  huc_cd          -- Hydrologic unit code
        #  basin_cd        -- Drainage basin code
        #  topo_cd         -- Topographic setting code
        #  station_type_cd -- Site type code
        #  agency_use_cd   -- Agency use of site code
        #  data_types_cd   -- Flags for the type of data collected
        #  instruments_cd  -- Flags for instruments at site
        #  construction_dt -- Date of first construction
        #  inventory_dt    -- Date site established or inventoried
        #  drain_area_va   -- Drainage area
        #  contrib_drain_area_va -- Contributing drainage area
        #  tz_cd           -- Mean Greenwich time offset
        #  local_time_fg   -- Local standard time flag
        #  reliability_cd  -- Data reliability code
        #  gw_file_cd      -- Data-other GW files
        #  gw_type_cd      -- Type of ground water site
        #  nat_aqfr_cd     -- National aquifer code
        #  aqfr_cd         -- Local aquifer code
        #  aqfr_type_cd    -- Local aquifer type code
        #  well_depth_va   -- Well depth
        #  hole_depth_va   -- Hole depth
        #  depth_src_cd    -- Source of depth data
        #  project_no      -- Project number
        #  rt_bol          -- Real-time data flag
        #  discharge_begin_date -- Daily streamflow data begin date
        #  discharge_end_date -- Daily streamflow data end date
        #  discharge_count_nu -- Daily streamflow data count
        #  peak_begin_date -- Peak streamflow data begin date
        #  peak_end_date   -- Peak streamflow data end date
        #  peak_count_nu   -- Peak streamflow data count
        #  qw_begin_date   -- Water quality data begin date
        #  qw_end_date     -- Water quality data end date
        #  qw_count_nu     -- Water quality data count
        #  gw_begin_date   -- Ground-water data begin date
        #  gw_end_date     -- Ground-water data end date
        #  gw_count_nu     -- Ground-water data count
        #
        #
        # query started 2007-03-09 10:33:58 EST
        #
        # there are 1 sites matching the search criteria.
        #
        #
        agency_cd	site_no	station_nm	lat_va	long_va	dec_lat_va	dec_long_va	coord_meth_cd	coord_acy_cd	coord_datum_cd	dec_coord_datum_cd	district_cd	state_cd	county_cd	country_cd	land_net_ds	map_nm	map_scale_fc	alt_va	alt_meth_cd	alt_acy_va	alt_datum_cd	huc_cd	basin_cd	topo_cd	station_type_cd	agency_use_cd	data_types_cd	instruments_cd	construction_dt	inventory_dt	drain_area_va	contrib_drain_area_va	tz_cd	local_time_fg	reliability_cd	gw_file_cd	gw_type_cd	nat_aqfr_cd	aqfr_cd	aqfr_type_cd	well_depth_va	hole_depth_va	depth_src_cd	project_no	rt_bol	discharge_begin_date	discharge_end_date	discharge_count_nu	peak_begin_date	peak_end_date	peak_count_nu	qw_begin_date	qw_end_date	qw_count_nu	gw_begin_date	gw_end_date	gw_count_nu
        5s	15s	50s	11s	12s	16n	16n	1s	1s	10s	10s	3s	2s	3s	2s	23s	20s	7s	8s	1s	3s	10s	16s	2s	1s	20s	1s	30s	30s	8s	8s	8s	8s	6s	1s	1s	30s	1s	10s	8s	1s	8s	8s	1s	12s
        USGS	13010065	SNAKE RIVER AB JACKSON LAKE AT FLAGG RANCH WY	440556	1104003	44.09888889	-110.66750000	G	S	NAD83	NAD83	16	56	039	US		Flagg Ranch	  24000	6801.61	L	.01	NGVD29	17040101			YNNNNNNNNNNNNNNNNNNN	A	ANNANNNNNNNNNNNNNNNNNNNNNNNNNN	YNNNYNNNNNNNNNNNNNNNNNNNNNNNNN			486	486	MST	Y		NNNNNNNN									1	1983-10-01	2007-02-06	8530	1984-05-31	2006-05-22	23	1985-10-01	2004-09-22	255	0000-00-00	0000-00-00	0

        */
        public UsgsInventory(string siteNumber)
        {
            string url = s_exactMatch.Replace("search_site_no=13010065", "search_site_no=" + siteNumber);

            string[] data = Web.GetPage(url, true);
            inventoryTable = new UsgsRDBFile(data);

            if (inventoryTable.Rows.Count <= 0)
            {
                throw new Exception("Site " + siteNumber + " not found");
            }
        }
コード例 #9
0
        private void ReadSeriesData(string url, DateTime t1, DateTime t2)
        {
            double siteElev = -999.0;

            if (offsetReadingsWithSiteElevation)
            {
                string siteInfoUrl = @"https://waterservices.usgs.gov/nwis/site/?format=rdb&sites=" + m_site_no;

                var         data = Reclamation.Core.Web.GetPage(siteInfoUrl);
                UsgsRDBFile rdb  = new UsgsRDBFile(data);
                DataTable   tbl  = DataTableUtility.Transpose(rdb);
                siteElev = Convert.ToDouble(rdb.Rows[0]["alt_va"]);
            }

            url += "&startDT=" + t1.ToString("yyyy-MM-dd") + "&endDT=" + t2.ToString("yyyy-MM-dd");
            string[] response = Web.GetPage(url, true);

            m_rdb = new UsgsRDBFile(response, true);
            ParsePreamble();
            m_columnName = "lev_va";

            for (int i = 0; i < m_rdb.Rows.Count; i++)
            {
                DataRow  row = m_rdb.Rows[i];
                DateTime t   = DateTime.MinValue;

                if (!DateTime.TryParse(row["lev_dt"].ToString(), out t))
                {
                    break;
                }
                // Read Time component
                string s = row["lev_tm"].ToString().Trim();
                if (s.Length == 4 && Regex.IsMatch(s, "[0-9]{4}"))
                {
                    int hr  = Convert.ToInt32(s.Substring(0, 2));
                    int min = Convert.ToInt32(s.Substring(2));
                    t = t.AddHours(hr);
                    t = t.AddMinutes(min);
                }

                if (t < t1 || t > t2)
                {
                    continue;
                }

                double d  = Point.MissingValueFlag;
                Point  pt = Point.Missing;
                pt.DateTime = t;
                pt.Flag     = row["lev_status_cd"].ToString();
                try
                {
                    if (!Double.TryParse(row[m_columnName].ToString(), out d))
                    {
                        Messages.Add("Error reading '" + row[m_columnName] + "' as a number");
                        AddMissing(t);
                    }
                    else
                    {
                        if (offsetReadingsWithSiteElevation)
                        {
                            pt.Value = siteElev - d;
                        }
                        else
                        {
                            pt.Value = d;
                        }
                        Add(pt);
                    }
                }
                catch
                {
                    //[JR] fix this!
                }
            }
        }