Access EPA 'ECHO' Data

An R interface to United States Environmental Protection Agency (EPA) Environmental Compliance History Online ('ECHO') Application Program Interface (API). 'ECHO' provides information about EPA permitted facilities, discharges, and other reporting info associated with permitted entities. Data are obtained from < https://echo.epa.gov/>.


CRANstatus

Travis buildstatus AppVeyor buildstatus Coveragestatus

Overview

echor downloads wastewater discharge and air emission data for EPA permitted facilities using the EPA ECHO API.

Installation

echor is on CRAN:

install.packages("echor")

Or install the development version from github:

 
devtools::install_github("mps9506/echor")

Usage

Getting started

Functions

Examples

Download information about facilities with an NPDES permit

We can look up plants by permit id, bounding box, and numerous other parameters. I plan on providing documentation of available parameters. However, arguments can be looked up here: get_cwa_rest_services_get_facility_info

library(tidyverse)
library(echor)
 
## echoWaterGetFacilityInfo() will return a dataframe or simple features (sf) dataframe.
 
df <- echoWaterGetFacilityInfo(output = "df", 
                               xmin = '-96.387509', 
                               ymin = '30.583572', 
                               xmax = '-96.281422', 
                               ymax = '30.640008')
 
head(df)
#> # A tibble: 6 x 26
#>   CWPName    SourceID  CWPStreet  CWPCity CWPState CWPStateDistrict CWPZip
#>   <chr>      <chr>     <chr>      <chr>   <chr>    <chr>            <chr> 
#> 1 ACE TOWNH~ TXR15667I 2136 CHES~ COLLEG~ TX       ""               77845~
#> 2 ASTIN AVI~ TXR05CE76 1770 GEOR~ COLLEG~ TX       ""               77845~
#> 3 AT HOME -~ TXR15591P 2301 EARL~ COLLEG~ TX       ""               77845~
#> 4 BEE CREEK~ TXR15647M THE SITE ~ COLLEG~ TX       ""               77845 
#> 5 BOSSIER P~ LAG830191 3228 BARK~ BENTON  LA       ""               71111 
#> 6 BROADSTON~ TXR10F50H NW OF ATL~ BRYAN   TX       ""               77807 
#> # ... with 19 more variables: MasterExternalPermitNmbr <chr>,
#> #   RegistryID <chr>, CWPCounty <chr>, CWPEPARegion <chr>,
#> #   FacDerivedHuc <chr>, FacLat <dbl>, FacLong <dbl>,
#> #   CWPTotalDesignFlowNmbr <dbl>, CWPActualAverageFlowNmbr <dbl>,
#> #   ReceivingMs4Name <chr>, AssociatedPollutant <chr>,
#> #   MsgpPermitType <chr>, CWPPermitStatusDesc <chr>,
#> #   CWPPermitTypeDesc <chr>, CWPIssueDate <date>, CWPEffectiveDate <date>,
#> #   CWPExpirationDate <date>, CWPSNCStatusDate <date>,
#> #   CWPStateWaterBodyCode <chr>

The ECHO database can provide over 270 different columns. echor returns a subset of these columns that should work for most users. However, you can specify what data you want returned. Use echoWaterGetMeta() to return a dataframe with column numbers, names, and descriptions to identify the columns you want returned. Then include the column numbers as a comma seperated string in the qcolumns argument. In the example below, the qcolumns argument indicates the dataframe will include plant name, 8-digit HUC, latitute, longitude, and total design flow.

df <- echoWaterGetFacilityInfo(output = "df", 
                               xmin = '-96.387509', 
                               ymin = '30.583572', 
                               xmax = '-96.281422', 
                               ymax = '30.640008',
                               qcolumns = '1,14,23,24,25')
head(df)
#> # A tibble: 6 x 6
#>   CWPName          SourceID FacDerivedHuc FacLat FacLong CWPTotalDesignFl~
#>   <chr>            <chr>    <chr>          <dbl>   <dbl>             <dbl>
#> 1 ACE TOWNHOME     TXR1566~ 12070103        30.6   -96.3                NA
#> 2 ASTIN AVIATION   TXR05CE~ 12070101        30.6   -96.4                NA
#> 3 AT HOME - COLLE~ TXR1559~ 12070103        30.6   -96.3                NA
#> 4 BEE CREEK SANIT~ TXR1564~ 12070103        30.6   -96.3                NA
#> 5 BOSSIER PARISH ~ LAG8301~ 12070103        30.6   -96.3                NA
#> 6 BROADSTONE TRAD~ TXR10F5~ 12070101        30.6   -96.4                NA

When returned as sf dataframes, the data is suitable for immediate spatial plotting or analysis:

library(ggmap)
library(sf)
library(ggrepel)
## This example requires the development version of ggplot with support
## for geom_sf()
## and uses theme_ipsum_rc() from library(hrbrthemes)
 
 
df <- echoWaterGetFacilityInfo(output = "sf", 
                               xmin = '-96.387509', 
                               ymin = '30.583572', 
                               xmax = '-96.281422', 
                               ymax = '30.640008')
 
collegestation <- get_map(location = c(-96.387509, 30.583572,
                                       -96.281422, 30.640008), 
                          zoom = 14, maptype = "toner")
 
##to make labels, need to map the coords and use geom_text :(
## can't help but think there is an easier way to do this
 
df <- df %>%
  mutate(
    coords = map(geometry, st_coordinates),
    coords_x = map_dbl(coords, 1),
    coords_y = map_dbl(coords, 2)
  )
 
ggmap(collegestation) + 
  geom_sf(data = df, inherit.aes = FALSE, shape = 21, 
          color = "darkred", fill = "darkred", 
          size = 2, alpha = 0.25) +
  geom_label_repel(data = df, aes(x = coords_x, y = coords_y, label = SourceID),
                   point.padding = .5, min.segment.length = 0.1,
                   size = 2, color = "dodgerblue") +
  theme_ipsum_rc() +
  labs(x = "Longitude", y = "Latitude", 
       title = "NPDES permits near Texas A&M",
       caption = "Source: EPA ECHO database")

Download discharge/emissions data

Use echoGetEffluent() or echoGetCAAPR() to download tidy dataframes of permitted water discharger Discharge Monitoring Report (DMR) or permitted emitters Clean Air Act annual emissions reports.

df <- echoGetEffluent(p_id = 'TX0119407', parameter_code = '00300')
 
df <- df %>%
  filter(!is.na(dmr_value_nmbr) & limit_value_type_code == "C1")
 
ggplot(df) +
  geom_line(aes(monitoring_period_end_date, dmr_value_nmbr)) +
  theme_ipsum_rc(grid = "Y") +
  labs(x = "Monitoring period date",
       y = "Dissolved oxygen concentration (mg/l)",
       title = "Reported minimum dissolved oxygen concentration",
       subtitle = "NPDES ID = TX119407",
       caption = "Source: EPA ECHO")

Test Results

library(echor)
 
date()
#> [1] "Fri Feb 01 20:21:37 2019"
 
devtools::test()
#> v | OK F W S | Context
#> 
/ |  0       | core functions return expected errors
- |  1       | core functions return expected errors
\ |  2       | core functions return expected errors
| |  3       | core functions return expected errors
/ |  4       | core functions return expected errors
- |  5       | core functions return expected errors
\ |  6       | core functions return expected errors
| |  7       | core functions return expected errors
/ |  8       | core functions return expected errors
- |  9       | core functions return expected errors
v |  9       | core functions return expected errors [1.1 s]
#> 
/ |  0       | core functions return expected objects
- |  1       | core functions return expected objects
\ |  2       | core functions return expected objects
| |  3       | core functions return expected objects
/ |  4       | core functions return expected objects
- |  5       | core functions return expected objects
\ |  6       | core functions return expected objects
| |  7       | core functions return expected objects
/ |  8       | core functions return expected objects
- |  9       | core functions return expected objects
\ | 10       | core functions return expected objects
| | 11       | core functions return expected objects
/ | 12       | core functions return expected objects
- | 13       | core functions return expected objects
v | 13       | core functions return expected objects [10.0 s]
#> 
#> == Results =================================================================================================
#> Duration: 11.1 s
#> 
#> OK:       22
#> Failed:   0
#> Warnings: 0
#> Skipped:  0

News

echor 0.1.2

New functions

  • downloadDMRs() Returns a tidy dataframe with dmr reports. (closes #38)

Updated functions

  • echoGetEffluent() uses a different API call to returns a flat dmr report (one plant at a time). Existing arguments remain the same and still returns a dataframe. (closes #37)

echor 0.1.1

  • Single function returns air and water data; echoGetFacilities() and echoGetReports() wrap the individual functions to streamline functions that users need to be familiar with. (closes #33)
  • Added echoWaterGetMeta() and echoAirGetMeta() functions to retrieve column metadata returned by echoWaterGetFacilityInfo() and echoAirGetFacilityInfo(); specify columns returned by respective functions by including qcolumns argument in respective functions. (closes #28).
  • Added default qcolumns argument to echoWaterGetFacilityInfo() to ensure reasonable default columns are returned (#29).
  • echoWaterGetFacilityInfo() properly returns large datasets. The new internal function getDownload() downloads the entire CSV of queried data as a dataframe (closes #27).
  • Added default qcolumns argument to echoAirGetFacilityInfo() to ensure reasonable default columns are returned (#29).
  • echoAirGetFacilityInfo() properly returns large datasets. The new internal function getDownload() downloads the entire CSV of queried data as a dataframe (closes #27).
  • echoSDWGetSystems() downloads data for public drinking water systems.
  • echoSDWGetMeta() downloads metadata for columns returned by echoSDWGetSystems()
  • Unit tests for functions that rely on EPA ECHO API utilize skip_on_cran() instead of httptest::with_mock_API()
  • Imported functions are called explicitly eg. pkg::fun()

echor 0.1.0

  • Added a NEWS.md file to track changes to the package.
  • Intial Release

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("echor")

0.1.2 by Michael Schramm, 5 months ago


Report a bug at https://github.com/mps9506/echor/issues


Browse source code at https://github.com/cran/echor


Authors: Michael Schramm [aut, cre]


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports dplyr, geojsonsf, httr, lubridate, plyr, purrr, readr, rlang, tibble, tidyr, utils

Suggests ggplot2, ggmap, ggrepel, here, httptest, kableExtra, knitr, rmarkdown, sf, testthat


See at CRAN