-
Notifications
You must be signed in to change notification settings - Fork 1
/
README.Rmd
161 lines (116 loc) · 5.85 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{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
<!-- badges: start -->
[![CRAN status](https://www.r-pkg.org/badges/version/echor)](https://cran.r-project.org/package=echor)
[![echor status badge](https://mps9506.r-universe.dev/badges/echor)](https://mps9506.r-universe.dev)
[![R build status](https://github.com/mps9506/echor/workflows/R-CMD-check/badge.svg)](https://github.com/mps9506/echor/actions)
[![Coverage status](https://codecov.io/gh/mps9506/echor/branch/master/graph/badge.svg)](https://app.codecov.io/github/mps9506/echor?branch=master)
[![DOI](https://zenodo.org/badge/122131508.svg)](https://zenodo.org/badge/latestdoi/122131508)
<!-- badges: end -->
## 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()
```