Module: Cdss::SurfaceWater
Overview
Provides methods for accessing surface water data from the CDSS API.
This module includes functionality for retrieving surface water stations and their associated time series data at various time scales (daily, monthly, yearly).
Instance Method Summary collapse
-
#get_sw_stations(aoi: nil, radius: nil, abbrev: nil, county: nil, division: nil, station_name: nil, usgs_id: nil, water_district: nil, api_key: nil) ⇒ Array<Station>
Fetches surface water stations based on various filtering criteria.
-
#get_sw_ts(abbrev: nil, station_number: nil, usgs_id: nil, start_date: nil, end_date: nil, timescale: nil, api_key: nil) ⇒ Array<Reading>
Fetches surface water time series data for specified stations.
Methods included from Utils
#batch_dates, #build_query, #fetch_paginated_data, #format_date, #format_query_param, #parse_timestamp, #safe_float, #safe_integer
Instance Method Details
#get_sw_stations(aoi: nil, radius: nil, abbrev: nil, county: nil, division: nil, station_name: nil, usgs_id: nil, water_district: nil, api_key: nil) ⇒ Array<Station>
Fetches surface water stations based on various filtering criteria.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/cdss/surface_water.rb', line 29 def get_sw_stations(aoi: nil, radius: nil, abbrev: nil, county: nil, division: nil, station_name: nil, usgs_id: nil, water_district: nil, api_key: nil) query = { format: "json", dateFormat: "spaceSepToSeconds", abbrev: abbrev, county: county, division: division, stationName: station_name, usgsSiteId: usgs_id, waterDistrict: water_district } if aoi if aoi.is_a?(Hash) && aoi[:latitude] && aoi[:longitude] query.merge!(longitude: aoi[:longitude], latitude: aoi[:latitude]) elsif aoi.is_a?(Array) && aoi.count == 2 query.merge!(longitude: aoi[0], latitude: aoi[1]) else raise ArgumentError, "Invalid 'aoi' parameter" end query[:radius] = radius || 20 query[:units] = "miles" end fetch_paginated_data( endpoint: "/surfacewater/surfacewaterstations/", query: query ) { |data| Parser.parse_stations(data) } end |
#get_sw_ts(abbrev: nil, station_number: nil, usgs_id: nil, start_date: nil, end_date: nil, timescale: nil, api_key: nil) ⇒ Array<Reading>
Fetches surface water time series data for specified stations.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/cdss/surface_water.rb', line 76 def get_sw_ts(abbrev: nil, station_number: nil, usgs_id: nil, start_date: nil, end_date: nil, timescale: nil, api_key: nil) timescale ||= "day" day_lst = %w[day days daily d] month_lst = %w[month months monthly mon m] year_lst = %w[wyear water_year wyears water_years wateryear wateryears wy year years yearly annual annually yr y] timescale_lst = day_lst + month_lst + year_lst unless timescale_lst.include?(timescale) valid_timescales = timescale_lst.join(", ") raise ArgumentError, "Invalid 'timescale' argument: '#{timescale}'. Valid values are: #{valid_timescales}" end case timescale when *day_lst get_sw_ts_day(abbrev: abbrev, station_number: station_number, usgs_id: usgs_id, start_date: start_date, end_date: end_date, api_key: api_key) when *month_lst get_sw_ts_month(abbrev: abbrev, station_number: station_number, usgs_id: usgs_id, start_date: start_date, end_date: end_date, api_key: api_key) when *year_lst get_sw_ts_wyear(abbrev: abbrev, station_number: station_number, usgs_id: usgs_id, start_date: start_date, end_date: end_date, api_key: api_key) else raise ArgumentError, "Invalid 'timescale' argument: '#{timescale}'" end end |