Code Monkey home page Code Monkey logo

cam-api-examples's People

Contributors

ibarra-michelle avatar j-tafoya avatar kstetsyuk avatar maheese avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

cam-api-examples's Issues

How to Filter Missing JSON Elements in R

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**

api key not working

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.'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.