usepa / cam-api-examples Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
R/JSON/Github newbie.. I am trying to extract details of the various types of monitoring equipment used to measure emissions on power plant stacks (manufacturer, model, type).
This information is contained within the "monitoringSystems" element of the JSON object. However, some of these power plants do not use monitoring equipment on their stacks and there is no "monitoringSystems" element.
If I run my script without attempting to filter units without monitoring systems, I get the following error (locName is an element of monitoringSystems, which doesn't exist for index=3):
Caused by error in map(): ℹ In index: 3. Caused by error in dplyr::select(): ! Can't subset columns that don't exist. ✖ Column locName doesn't exist.
I tried skipping those units without a monitoringSystems element using an 'if exists' function, but I get the following error:
Error in mutate(): ! Problem while computing response = get_monitor_data(query). Caused by error in map(): ℹ In index: 1. Caused by error in if (.) ...: ! the condition has length > 1
Here's the a portion of the code that I received from CAM tech support for retrieving other data that I modified for this purpose:
**get_monitor_data <- function(queries) {
response <- queries %>%
map(function(query){
response <- GET(query)
warn_for_status(response)
if (response$status_code == 200) {
mon_json <- content(response, as = "text")
units_tbl <- mon_json %>%
enter_object("data") %>%
spread_all() %>%
enter_object("monitoringLocations") %>%
gather_array() %>%
spread_all() %>%
if(exists("monitoringSystems")) {
enter_object(monitoringSystems) %>%
gather_array() %>%
spread_all() %>%
select(
LOC_NAME = locName,
SYS_ID = sysId,
SYS_TYPE_CODE = sysTypeCode,
COMPONENT_ID = componentId,
SERIAL_NUM = serialNum,
MANUFACTURER = manufacturer,
MODEL_VERSION = modelVersion,
COMPONENT_TYPE_CODE = componentTypeCode,
ACQ_CODE = acqCode,
BASIS_CODE = basisCode,
SYS_BEGIN_DATE_HOUR = sysBeginDateHour,
SYS_END_DATE_HOUR = sysEndDateHour,
COMPONENT_BEGIN_DATE_HOUR = componentBeginDateHour,
COMPONENT_END_DATE_HOUR = componentEndDateHour,
SYSTEM_TYPE_DESCRIPTION = systemTypeDescription,
SYSTEM_DESIGNATION_CODE_DESC = systemDesignationCodeDesc,
ACQ_CODE_DESCRIPTION = acqCodeDescription,
COMPONENT_TYPE_CODE_DESCRIPTION = componentTypeCodeDescription,
BASIS_CODE_DESC = basisCodeDesc
)
}
}
}
)
}
Perform the GET request for each query and pull out the content of the request, and gather the laod dater for each unit.
#Pull out the content of the request
responses <- queries %>%
mutate(
response = get_monitor_data(query)
)
#Unnest the data frames from the response
unit_monitor_data <- unnest(responses, cols = c(response))
unit_monitor_data**
I navigated to the link in the documentation, https://www.epa.gov/airmarkets/cam-api-portal#/api-key-signup, and very quickly received an email with an api key from the email adddress [email protected]. After entering the api key into my local copy of the script bulk_data_api_demo.py, I receive an error message:
Error message: An invalid api_key was supplied. Get one at https://api.epa.gov:443
The error message url returns a page saying 'Sorry, but this web page does not exist.'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.