https://github.com/mps9506/echor
Download EPA ECHO data in R
https://github.com/mps9506/echor
epa pollution r r-package rstats water-quality
Last synced: about 1 month ago
JSON representation
Download EPA ECHO data in R
- Host: GitHub
- URL: https://github.com/mps9506/echor
- Owner: mps9506
- License: other
- Created: 2018-02-19T23:01:20.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-05-15T19:08:56.000Z (about 1 year ago)
- Last Synced: 2025-04-12T19:10:02.996Z (about 1 month ago)
- Topics: epa, pollution, r, r-package, rstats, water-quality
- Language: R
- Homepage: https://mps9506.github.io/echor/
- Size: 41.7 MB
- Stars: 9
- Watchers: 1
- Forks: 1
- Open Issues: 6
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
README
---
output: github_document
---```{r echo=FALSE, message=FALSE, warning=FALSE, paged.print=FALSE}
knitr::opts_chunk$set(
dev = "ragg_png",
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
fig.retina = 2
)options(crayon.enabled = NULL)
library(dplyr)
library(ggplot2)
library(mpsTemplates)
library(echor)
library(ragg)
```# echor
[](https://cran.r-project.org/package=echor)
[](https://mps9506.r-universe.dev)[](https://github.com/mps9506/echor/actions)
[](https://app.codecov.io/github/mps9506/echor?branch=master)
[](https://zenodo.org/badge/latestdoi/122131508)## Overview
echor downloads wastewater discharge and air emission data for EPA permitted facilities using the [EPA ECHO API](https://echo.epa.gov/).
## Installation
echor is on CRAN:
```{r Install, eval=FALSE, message=FALSE, warning=FALSE, paged.print=FALSE}
install.packages("echor")
```Or install the development version:
```{r InstallDev, eval=FALSE, message=FALSE, warning=FALSE, paged.print=FALSE}
install.packages('echor', repos = 'https://mps9506.r-universe.dev')
```## Usage
[Getting started](https://mps9506.github.io/echor/articles/introduction.html)
[Functions](https://mps9506.github.io/echor/reference/index.html)
## 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](https://echo.epa.gov/tools/web-services/facility-search-water#!/Facility_Information/get_cwa_rest_services_get_facility_info)
```{r example1, echo=TRUE, message=FALSE, warning=FALSE}
library(echor)## echoWaterGetFacilityInfo() will return a dataframe or simple features (sf) dataframe.
df <- echoWaterGetFacilityInfo(output = "df",
p_c1lon = '-96.387509',
p_c1lat = '30.583572',
p_c2lon = '-96.281422',
p_c2lat = '30.640008',
p_ptype = "NPD")head(df)
```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 separated string in the `qcolumns` argument. In the example below, the `qcolumns` argument indicates the dataframe will include plant name, 8-digit HUC, latitude, longitude, and total design flow.
```{r example2, echo=TRUE, message=FALSE, warning=FALSE}
df <- echoWaterGetFacilityInfo(output = "df",
p_c1lon = '-96.387509',
p_c1lat = '30.583572',
p_c2lon = '-96.281422',
p_c2lat = '30.640008',
qcolumns = '1,14,23,24,25',
p_ptype = "NPD")
head(df)
```When returned as sf dataframes, the data is suitable for immediate spatial plotting or analysis.
```{r example3, eval=TRUE, echo=TRUE, message=FALSE, warning=FALSE, paged.print=FALSE, out.width="100%"}
library(ggspatial)
library(sf)
library(ggrepel)
library(prettymapr)df <- echoWaterGetFacilityInfo(output = "sf",
p_c1lon = '-96.387509',
p_c1lat = '30.583572',
p_c2lon = '-96.281422',
p_c2lat = '30.640008',
p_ptype = "NPD")ggplot(df) +
annotation_map_tile(zoomin = -1, progress = "none") +
geom_sf(inherit.aes = FALSE, shape = 21,
color = "darkred", fill = "darkred",
size = 2, alpha = 0.25) +
geom_label_repel(data = df, aes(label = SourceID,
geometry = geometry),
stat = "sf_coordinates",
point.padding = .5, min.segment.length = 0.1,
size = 2, color = "dodgerblue") +
theme_mps_noto() +
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. Please note that all variables are returned as *character* vectors.
```{r message=TRUE, warning=FALSE}
df <- echoGetEffluent(p_id = 'tx0119407', parameter_code = '00300')df <- df %>%
mutate(dmr_value_nmbr = as.numeric(dmr_value_nmbr),
monitoring_period_end_date = as.Date(monitoring_period_end_date,
"%m/%d/%Y")) %>%
filter(!is.na(dmr_value_nmbr) & limit_value_type_code == "C1")ggplot(df) +
geom_line(aes(monitoring_period_end_date, dmr_value_nmbr)) +
theme_mps_noto() +
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")```
## Session Info
```{r message=FALSE, warning=FALSE, error=FALSE}
sessioninfo::platform_info()
sessioninfo::package_info()
```