def get_discharge(domain_shp,discharge_data_csv,discharge_station_csv,nwis_discharge_format='rdb',model_epsg=None,sep='\t'): '''Retrieves NWIS discharge and the associated station information and writes them to .csv.''' bbox = get_bbox(domain_shp) bbox = gu.bbox_to_latlon(bbox,model_epsg) bbox_string = get_bbox_string(bbox) # Configure the NWIS request dv_data_root = nwis_root + 'dv/?' dv_site_root = nwis_root + 'site/?' param_codes = '00060' # Discharge in ft3/s discharge_site_type = 'ST' period = 'P30000D' # NOTE: Default period for webservices API = 'most recent' # For convenience, reduce the number of columns in the station dataframe keep_station_cols = ['site_no', 'station_nm','dec_lat_va','dec_long_va','alt_va','site_tp_cd'] # Configure the urls site_url = dv_site_root + 'format=' + nwis_discharge_format + '&bBox=' + bbox_string + '&siteType=' + discharge_site_type + '&siteOutput=expanded' data_url = dv_data_root + 'format=' + nwis_discharge_format + '&bBox=' + bbox_string + \ '¶meterCd=' + param_codes + '&siteType=' + discharge_site_type + '&period=' + period station_df = get_station_df(site_url,discharge_site_type,keep_station_cols,sep=sep) data_df = get_discharge_results(data_url,sep=sep) station_df.to_csv(discharge_station_csv) data_df.to_csv(discharge_data_csv) return
def get_wq(domain_shp,data_csv,station_df,nwis_format='csv',nwis_param=None,model_epsg=None): '''Downloads NWIS (NOT STORET - need separate call) water quality data to .csv. Note that current workflow only includes sites for which groundwater level or discharge information exists; as a result, this function does not retrieve station information but instead uses the station_df argument to filter observations.''' bbox = get_bbox(domain_shp) bbox = gu.bbox_to_latlon(bbox,model_epsg) bbox_string = get_bbox_string(bbox) # Water quality services uses different format string for bbox call bbox_string = bbox_string.replace(',','%2C') # Configure the web services request dv_data_root = 'http://waterqualitydata.us/Result/search?' data_url = dv_data_root + 'mimeType=' + nwis_format + '&bBox=' + bbox_string if nwis_param is not None: data_url = data_url + '&pCode=' + nwis_param wq_df = get_wq_results(data_url,sep=',') # Water quality webservices does not allow filtering by site type. # Consequently need to filter using user-specified station information. wq_df = pd.merge(station_df,wq_df,on='site_no',how='inner') wq_df = wq_df.dropna(subset=['Value']) wq_df.to_csv(data_csv) return wq_df
def get_gw(domain_shp,head_data_csv,head_station_csv,nwis_gw_format='rdb',model_epsg=None,sep='\t'): '''Retrieves NWIS groundwater levels and the associated station information and writes them to .csv.''' bbox = get_bbox(domain_shp) bbox = gu.bbox_to_latlon(bbox,model_epsg) bbox_string = get_bbox_string(bbox) # Configure the NWIS request gw_data_root = nwis_root + 'gwlevels/?' gw_site_root = nwis_root + 'site/?' param_codes = '72019' # Other possible GW Level param codes = 62610,62611,72019,72150,72020 gw_site_type = 'GW' period = 'P30000D' # NOTE: Default period for webservices API = 'most recent' # For convenience, reduce the number of columns in the station dataframe keep_station_cols = ['site_no', 'station_nm','dec_lat_va','dec_long_va','alt_va','well_depth_va','hole_depth_va','site_tp_cd'] # Configure the urls site_url = gw_site_root + 'format=' + nwis_gw_format + '&bBox=' + bbox_string + '&siteType=' + gw_site_type + '&siteOutput=expanded' data_url = gw_data_root + 'format=' + nwis_gw_format + '&bBox=' + bbox_string + \ '¶meterCd=' + param_codes + '&siteType=' + gw_site_type + '&period=' + period station_df = get_station_df(site_url,gw_site_type,keep_station_cols,sep=sep) data_df = get_head_results(data_url,sep=sep) station_df.to_csv(head_station_csv) data_df.to_csv(head_data_csv) return