├── .github ├── .gitignore └── workflows │ ├── R-CMD-check.yaml │ └── test-coverage.yaml ├── vignettes ├── .gitignore └── qualr.Rmd ├── _pkgdown.yml ├── LICENSE ├── R ├── sysdata.rda ├── qualR.R ├── check_cetesb_code.R ├── write_csv.R ├── data.R ├── monitor_ar_retrieve_pol.R ├── monitor_ar_retrieve_met.R ├── monitor_ar_retrieve_met_pol.R ├── cetesb_retrieve_met.R ├── cetesb_retrieve_pol.R ├── cetesb_retrieve_param.R ├── cetesb_retrieve_met_pol.R ├── cetesb_retrieve.R └── monitor_ar_retrieve_param.R ├── data ├── cetesb_aqs.rda ├── cetesb_param.rda ├── monitor_ar_aqs.rda └── monitor_ar_param.rda ├── tests ├── testthat.R └── testthat │ ├── sysdata.rda │ ├── test-monitor_ar_retrieve_met.R │ ├── test-monitor_ar_retrieve_pol.R │ ├── test-cetesb_retrieve_met.R │ ├── test-monitor_ar_retrieve_param.R │ ├── test-cetesb_retrieve_param.R │ ├── test-cetesb_retrieve_pol.R │ ├── test-monitor_ar_retrieve_met_pol.R │ └── test-cetesb_retrieve_met_pol.R ├── .gitignore ├── docs ├── reference │ ├── Rplot001.png │ ├── figures │ │ └── README-pressure-1.png │ ├── qualR.html │ └── index.html ├── pkgdown.yml ├── articles │ ├── qualr_files │ │ ├── figure-html │ │ │ ├── unnamed-chunk-5-1.png │ │ │ └── unnamed-chunk-7-1.png │ │ └── accessible-code-block-0.0.1 │ │ │ └── empty-anchor.js │ └── index.html ├── link.svg ├── sitemap.xml ├── bootstrap-toc.css ├── docsearch.js ├── pkgdown.js ├── bootstrap-toc.js ├── LICENSE-text.html ├── 404.html ├── LICENSE.html ├── CONTRIBUTING.html ├── authors.html └── news │ └── index.html ├── inst ├── paper │ ├── pin_nox_lock20.png │ ├── rj_centro_2019.png │ ├── usp_o3_aug21.png │ └── paper.bib └── CITATION ├── man ├── figures │ └── README-pressure-1.png ├── cetesb_param.Rd ├── monitor_ar_param.Rd ├── cetesb_aqs.Rd ├── monitor_ar_aqs.Rd ├── qualR.Rd ├── monitor_ar_retrieve_pol.Rd ├── monitor_ar_retrieve_met.Rd ├── monitor_ar_retrieve_param.Rd ├── cetesb_retrieve.Rd ├── monitor_ar_retrieve_met_pol.Rd ├── cetesb_retrieve_pol.Rd ├── cetesb_retrieve_met.Rd ├── cetesb_retrieve_met_pol.Rd └── cetesb_retrieve_param.Rd ├── .travis.yml ├── .Rbuildignore ├── NAMESPACE ├── codecov.yml ├── data-raw ├── monitor_ar_aqs.R ├── cetesb_variables.dat ├── monitor_ar_variables.dat ├── monitor_ar_qualR.dat ├── cetesb_param.R ├── monitor_ar_param.R ├── cetesb.R ├── cetesb_aqs.R ├── cetesb_qualR.dat └── cetesb_aqs.dat ├── CONTRIBUTING.md ├── qualR.Rproj ├── LICENSE.md ├── appveyor.yml ├── NEWS.md ├── DESCRIPTION ├── codemeta.json └── CODE_OF_CONDUCT.md /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /vignettes/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | *.R 3 | -------------------------------------------------------------------------------- /_pkgdown.yml: -------------------------------------------------------------------------------- 1 | url: ~ 2 | template: 3 | bootstrap: 5 4 | 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2020 2 | COPYRIGHT HOLDER: Mario Gavidia-Calderón 3 | -------------------------------------------------------------------------------- /R/sysdata.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/qualR/HEAD/R/sysdata.rda -------------------------------------------------------------------------------- /data/cetesb_aqs.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/qualR/HEAD/data/cetesb_aqs.rda -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(qualR) 3 | 4 | test_check("qualR") 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .qualR.Rproj 5 | inst/doc 6 | docs 7 | -------------------------------------------------------------------------------- /data/cetesb_param.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/qualR/HEAD/data/cetesb_param.rda -------------------------------------------------------------------------------- /data/monitor_ar_aqs.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/qualR/HEAD/data/monitor_ar_aqs.rda -------------------------------------------------------------------------------- /data/monitor_ar_param.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/qualR/HEAD/data/monitor_ar_param.rda -------------------------------------------------------------------------------- /tests/testthat/sysdata.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/qualR/HEAD/tests/testthat/sysdata.rda -------------------------------------------------------------------------------- /docs/reference/Rplot001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/qualR/HEAD/docs/reference/Rplot001.png -------------------------------------------------------------------------------- /inst/paper/pin_nox_lock20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/qualR/HEAD/inst/paper/pin_nox_lock20.png -------------------------------------------------------------------------------- /inst/paper/rj_centro_2019.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/qualR/HEAD/inst/paper/rj_centro_2019.png -------------------------------------------------------------------------------- /inst/paper/usp_o3_aug21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/qualR/HEAD/inst/paper/usp_o3_aug21.png -------------------------------------------------------------------------------- /man/figures/README-pressure-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/qualR/HEAD/man/figures/README-pressure-1.png -------------------------------------------------------------------------------- /docs/reference/figures/README-pressure-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/qualR/HEAD/docs/reference/figures/README-pressure-1.png -------------------------------------------------------------------------------- /docs/pkgdown.yml: -------------------------------------------------------------------------------- 1 | pandoc: 3.1.3 2 | pkgdown: 2.0.6 3 | pkgdown_sha: ~ 4 | articles: 5 | qualr: qualr.html 6 | last_built: 2024-08-08T01:55Z 7 | 8 | -------------------------------------------------------------------------------- /docs/articles/qualr_files/figure-html/unnamed-chunk-5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/qualR/HEAD/docs/articles/qualr_files/figure-html/unnamed-chunk-5-1.png -------------------------------------------------------------------------------- /docs/articles/qualr_files/figure-html/unnamed-chunk-7-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/qualR/HEAD/docs/articles/qualr_files/figure-html/unnamed-chunk-7-1.png -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # R for travis: see documentation at https://docs.travis-ci.com/user/languages/r 2 | 3 | language: R 4 | cache: packages 5 | 6 | os: 7 | - linux 8 | # - osx 9 | 10 | after_success: 11 | - Rscript -e 'covr::codecov(type = "all")' 12 | -------------------------------------------------------------------------------- /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^qualR\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^LICENSE\.md$ 4 | ^data-raw$ 5 | ^README\.Rmd$ 6 | ^paper$ 7 | ^\.travis\.yml$ 8 | ^appveyor\.yml$ 9 | ^codecov\.yml$ 10 | ^NEWS.md 11 | ^_pkgdown\.yml$ 12 | ^docs$ 13 | ^pkgdown$ 14 | ^codemeta\.json$ 15 | ^CONTRIBUTING\.md$ 16 | ^CODE_OF_CONDUCT\.md$ 17 | ^inst/paper$ 18 | ^\.github$ 19 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(cetesb_retrieve_met) 4 | export(cetesb_retrieve_met_pol) 5 | export(cetesb_retrieve_param) 6 | export(cetesb_retrieve_pol) 7 | export(monitor_ar_retrieve_met) 8 | export(monitor_ar_retrieve_met_pol) 9 | export(monitor_ar_retrieve_param) 10 | export(monitor_ar_retrieve_pol) 11 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | comment: false 2 | 3 | language: R 4 | sudo: false 5 | cache: packages 6 | after_success: 7 | - Rscript -e 'covr::codecov()' 8 | 9 | coverage: 10 | status: 11 | project: 12 | default: 13 | target: auto 14 | threshold: 1% 15 | informational: true 16 | patch: 17 | default: 18 | target: auto 19 | threshold: 1% 20 | informational: true 21 | 22 | -------------------------------------------------------------------------------- /data-raw/monitor_ar_aqs.R: -------------------------------------------------------------------------------- 1 | ## code to prepare `monitor_ar_aqs` dataset goes here 2 | 3 | monitor_ar_aqs <- read.table("~/Downloads/aqs_rio.csv", header = TRUE, stringsAsFactors = FALSE, 4 | sep = ",", dec=".") 5 | monitor_ar_aqs <- monitor_ar_aqs[, c(4, 8, 1, 2, 12, 13)] 6 | names(monitor_ar_aqs) <- c("name", "code", "lon", "lat", "x_utm_sirgas2000", "y_utm_sirgas2000") 7 | monitor_ar_aqs$name <- iconv(monitor_ar_aqs$name, from = "UTF-8", to = "ASCII//TRANSLIT") 8 | 9 | usethis::use_data(monitor_ar_aqs, overwrite = TRUE) 10 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to contribute 2 | We welcome any suggestion, requests and bug report through the [issue tracker](https://github.com/quishqa/qualR/issues). 3 | 4 | ## Any bugs? 5 | - If you found any issue while using `qualR`, submit an issue [here](https://github.com/quishqa/qualR/issues). 6 | - Remember to add a reproducible example and the output of `sessionInfo()`. 7 | 8 | ## A little bit shy? 9 | - You can email the person as maintainer in the `DESCRIPTION` file (in portuguese or english). 10 | 11 | 12 | Thanks for your contribution :) 13 | -------------------------------------------------------------------------------- /R/qualR.R: -------------------------------------------------------------------------------- 1 | #' qualR: An R package to download Sao Paulo and Rio de Janeiro 2 | #' air pollution data 3 | #' 4 | #' @name qualR 5 | #' @author Mario Gavidia-Calderon and Daniel Schuch and Maria de Fatima Andrade 6 | #' @docType package 7 | #' 8 | #' @seealso 9 | #'\strong{Useful links:} 10 | #' \itemize{ 11 | #' \item{Development repository: 12 | #' \url{https://github.com/ropensci/qualR}} 13 | #' \item{Report bugs: 14 | #' \url{https://github.com/ropensci/qualR/issues}} 15 | #' \item{qualR site: 16 | #' \url{https://docs.ropensci.org/qualR/}} 17 | #' } 18 | "_PACKAGE" 19 | -------------------------------------------------------------------------------- /qualR.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | ProjectId: 99a2c02e-7918-41e1-a5fc-bd82519f7b2a 3 | 4 | RestoreWorkspace: No 5 | SaveWorkspace: No 6 | AlwaysSaveHistory: Default 7 | 8 | EnableCodeIndexing: Yes 9 | UseSpacesForTab: Yes 10 | NumSpacesForTab: 2 11 | Encoding: UTF-8 12 | 13 | RnwWeave: Sweave 14 | LaTeX: pdfLaTeX 15 | 16 | AutoAppendNewline: Yes 17 | StripTrailingWhitespace: Yes 18 | LineEndingConversion: Posix 19 | 20 | BuildType: Package 21 | PackageUseDevtools: Yes 22 | PackageInstallArgs: --no-multiarch --with-keep.source 23 | PackageCheckArgs: --as-cran --run-donttest --no-multiarch 24 | PackageRoxygenize: rd,collate,namespace 25 | -------------------------------------------------------------------------------- /inst/CITATION: -------------------------------------------------------------------------------- 1 | citHeader("To cite qualR in publications use:") 2 | 3 | citEntry( 4 | entry = "Manual", 5 | title = "qualR: An R package to download São Paulo and Rio de Janeiro air pollution data", 6 | doi = "10.5281/zenodo.5904262", 7 | author = c(person("Mario", "Gavidia-Calderón"), 8 | person("Daniel", "Schuch"), 9 | person("Maria de Fatima", "Andrade")), 10 | year = 2022, 11 | url = "https://docs.ropensci.org/qualR/", 12 | textVersion = paste("Gavidia-Calderón, M., Schuch, D., Andrade, Maria de Fatima (2022).", 13 | "qualR: An R package to download Sao Paulo and Rio de Janeiro air pollution data.", 14 | "URL: https://docs.ropensci.org/qualR/" 15 | ) 16 | ) 17 | -------------------------------------------------------------------------------- /man/cetesb_param.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{cetesb_param} 5 | \alias{cetesb_param} 6 | \title{CETESB Parameters} 7 | \format{ 8 | A data frame with 20 observations and 3 variables: 9 | \describe{ 10 | \item{name}{CETESB QUALAR parameter abbreviation and name.} 11 | \item{units}{Parameter units.} 12 | \item{code}{Parameter CETESB QUALAR code.} 13 | } 14 | } 15 | \usage{ 16 | cetesb_param 17 | } 18 | \description{ 19 | List of CETESB QUALAR available parameters and units. Use this to check the 20 | \code{parameters} argument. 21 | Parameter names are without diacritics. 22 | } 23 | \examples{ 24 | cetesb_param 25 | } 26 | \keyword{datasets} 27 | -------------------------------------------------------------------------------- /data-raw/cetesb_variables.dat: -------------------------------------------------------------------------------- 1 | "code","name" 2 | 61,"BEN (Benzeno)" 3 | 16,"CO (Monoxido de Carbono)" 4 | 23,"DV (Direcao do Vento)" 5 | 21,"DVG (Direcao do Vento Global)" 6 | 19,"ERT (Enxofre Reduzido Total)" 7 | 59,"HCNM (Hidrocarbonetos Totais menos Metano)" 8 | 12,"MP10 (Particulas Inalaveis)" 9 | 57,"MP2.5 (Particulas Inalaveis Finas)" 10 | 17,"NO (Monoxido de Nitrogenio)" 11 | 15,"NO2 (Dioxido de Nitrogenio)" 12 | 18,"NOx (Oxidos de Nitrogenio)" 13 | 63,"O3 (Ozonio)" 14 | 29,"PRESS (Pressao Atmosferica)" 15 | 26,"RADG (Radiacao Solar Global)" 16 | 56,"RADUV (Radiacao Ultra-violeta)" 17 | 13,"SO2 (Dioxido de Enxofre)" 18 | 25,"TEMP (Temperatura do Ar)" 19 | 62,"TOL (Tolueno)" 20 | 28,"UR (Umidade Relativa do Ar)" 21 | 24,"VV (Velocidade do Vento)" 22 | -------------------------------------------------------------------------------- /data-raw/monitor_ar_variables.dat: -------------------------------------------------------------------------------- 1 | "code","name","units" 2 | "SO2","Dioxido de enxofre","ug/m3" 3 | "NO2","Dioxido de nitrogenio","ug/m3" 4 | "NO","Monoxido de Nitrogenio","ug/m3" 5 | "NOx","Oxidos de nitrogenio","ug/m3" 6 | "HCNM","Hidrocarbonetos Totais menos Metano","ppm" 7 | "HCT","Hidrocarbonetos Totais","ppm" 8 | "CH4","Metano","ug/m3" 9 | "CO","Monoxido de Carbono","ppm" 10 | "O3","Ozonio","ug/m3" 11 | "PM10","Particulas Inalaveis","ug/m3" 12 | "PM2_5","Particulas Inalaveis Finas","ug/m3" 13 | "Chuva","Precipitacao Pluviometrica","mm" 14 | "Pres","Pressao Atmosferica","mbar" 15 | "RS","Radiacao Solar","W/m2" 16 | "Temp","Temperatura","ºC" 17 | "UR","Umidade Relativa do Ar","%" 18 | "Dir_Vento","Direcao do Vento","º" 19 | "Vel_Vento","Velocidade do Vento","m/s" 20 | -------------------------------------------------------------------------------- /man/monitor_ar_param.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{monitor_ar_param} 5 | \alias{monitor_ar_param} 6 | \title{Monitor Ar Parameters} 7 | \format{ 8 | A data frame with 18 observations and 3 variables: 9 | \describe{ 10 | \item{code}{MonitorAr parameter abbreviation or code.} 11 | \item{name}{MonitorAr parameter name} 12 | \item{units}{Parameter units.} 13 | } 14 | } 15 | \usage{ 16 | monitor_ar_param 17 | } 18 | \description{ 19 | List of Monitor Ar Rio available parameters. Use this to check the 20 | parameters argument in MonitorArRetrieveParam() function. 21 | Parameter names are without diacritics. 22 | } 23 | \examples{ 24 | monitor_ar_param 25 | } 26 | \keyword{datasets} 27 | -------------------------------------------------------------------------------- /docs/articles/qualr_files/accessible-code-block-0.0.1/empty-anchor.js: -------------------------------------------------------------------------------- 1 | // Hide empty tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) --> 2 | // v0.0.1 3 | // Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020. 4 | 5 | document.addEventListener('DOMContentLoaded', function() { 6 | const codeList = document.getElementsByClassName("sourceCode"); 7 | for (var i = 0; i < codeList.length; i++) { 8 | var linkList = codeList[i].getElementsByTagName('a'); 9 | for (var j = 0; j < linkList.length; j++) { 10 | if (linkList[j].innerHTML === "") { 11 | linkList[j].setAttribute('aria-hidden', 'true'); 12 | } 13 | } 14 | } 15 | }); 16 | -------------------------------------------------------------------------------- /data-raw/monitor_ar_qualR.dat: -------------------------------------------------------------------------------- 1 | "name","code","lon","lat","X_UTM_Sirgas2000","Y_UTM_Sirgas2000" 2 | "ESTACAO PEDRA DE GUARATIBA","PG",-43.629010366464,-23.0043789751932,640505.9556,7455338.4492 3 | "ESTACAO BANGU","BG",-43.47107415449,-22.887909592765,656828.8045,7468074.5684 4 | "ESTACAO CAMPO GRANDE","CG",-43.5565219722468,-22.8862546758774,648064.4921,7468346.2624 5 | "ESTACAO IRAJA","IR",-43.326844698961,-22.831620802504,671696.6238,7474146.6215 6 | "ESTACAO COPACABANA","AV",-43.1804816536037,-22.9650037338809,686537.0128,7459198.4024 7 | "ESTACAO TIJUCA","SP",-43.2326565174968,-22.9249153429029,681240.2399,7463702.987 8 | "ESTACAO SAO CRISTOVAO","SC",-43.2217454099382,-22.8977710880779,682395.7505,7466695.3372 9 | "ESTACAO CENTRO","CA",-43.178151756386,-22.9083442826264,686853.7075,7465469.7974 10 | -------------------------------------------------------------------------------- /data-raw/cetesb_param.R: -------------------------------------------------------------------------------- 1 | ## code to prepare `cetesb_param` dataset goes here 2 | 3 | cetesb_param <- read.table("~/R_tests/cetesb_variables.dat", header = FALSE, 4 | sep = ",", col.names = c("code", "name"), 5 | stringsAsFactors = FALSE) 6 | cetesb_param <- cetesb_param[, c(2, 1)] 7 | cetesb_param$name <- iconv(cetesb_param$name, from = "UTF-8", to = "ASCII//TRANSLIT") 8 | cetesb_param$units <- c("ug/m3", "ppm", "º", "º", "ppb", 9 | "-", "ug/m3", "ug/m3", "ug/m3", "ug/m3", 10 | "ppb", "ug/m3", "hPa", "W/m2", "W/m2", 11 | "ug/m3", "ºC", "ug/m3", "%", "m/s") 12 | cetesb_param <- cetesb_param[c("name", "units", "code")] 13 | 14 | usethis::use_data(cetesb_param, overwrite = TRUE) 15 | -------------------------------------------------------------------------------- /man/cetesb_aqs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{cetesb_aqs} 5 | \alias{cetesb_aqs} 6 | \title{CETESB AQS station latitude and longitude} 7 | \format{ 8 | A data frame with 74 observations and 5 variables: 9 | \describe{ 10 | \item{name}{CETESB AQS name.} 11 | \item{code}{CETESB AQS code in QUALAR System.} 12 | \item{lat}{CETESB AQS latitude.} 13 | \item{lon}{CETESB AQS longitude.} 14 | \item{loc}{CETESB AQS location.} 15 | } 16 | } 17 | \usage{ 18 | cetesb_aqs 19 | } 20 | \description{ 21 | List of CETESB QUALAR air quality stations (AQS) latitudes and longitudes. 22 | Use this to check the AQS \code{aqs_code} argument in CetesbRetrieveParam() 23 | function. AQS names are without diacritics. 24 | } 25 | \examples{ 26 | cetesb_aqs 27 | } 28 | \keyword{datasets} 29 | -------------------------------------------------------------------------------- /docs/link.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /R/check_cetesb_code.R: -------------------------------------------------------------------------------- 1 | #' Internal function - Check if CETESB AQS code or name is valid 2 | #' 3 | #' @param aqs data frame with cetesb aqs code and names 4 | #' @param aqs_code user's input code or name 5 | #' 6 | #' @noRd 7 | #' @keywords internal 8 | 9 | check_cetesb_code <- function(aqs, aqs_code){ 10 | if (is.numeric(aqs_code) & aqs_code %in% aqs$code){ 11 | aqs_code <- aqs_code 12 | aqs_name <- aqs$ascii[aqs$code == aqs_code] 13 | } else if (is.character(aqs_code)){ 14 | aqs_code_ascii <- iconv(aqs_code, from = "UTF-8", to = "ASCII//TRANSLIT") 15 | aqs_name <- aqs_code_ascii 16 | aqs_code <- aqs$code[aqs$ascii == aqs_code_ascii] 17 | } else { 18 | stop("Wrong aqs_code value or aqs name, please check cetesb_aqs", # nocov 19 | call. = FALSE) # nocov 20 | } 21 | aqs_code_name <- c(aqs_name, aqs_code) 22 | return(aqs_code_name) 23 | } 24 | -------------------------------------------------------------------------------- /R/write_csv.R: -------------------------------------------------------------------------------- 1 | #' Internal function - Export to csv data download 2 | #' 3 | #' @param aqs_data_frame Downloaded dataframe 4 | #' @param aqs_name AQS name 5 | #' @param start_date Download start date 6 | #' @param end_date Download end date 7 | #' @param vars identifier in file name 8 | #' 9 | #' @noRd 10 | #' @keywords internal 11 | 12 | write_csv <- function(aqs_data_df, aqs_name, start_date, end_date, 13 | vars, csv_path){ 14 | file_name <- paste0(aqs_name, "_", 15 | paste0(vars, collapse = "_"), "_", 16 | gsub("/", "-", start_date), "_", 17 | gsub("/", "-", end_date), ".csv") 18 | 19 | if (csv_path == ""){ 20 | file_path <- paste(getwd(), file_name, sep = "/") # nocov 21 | } else { 22 | file_path <- paste(csv_path, file_name, sep = "/") # nocov 23 | } 24 | 25 | utils::write.table(aqs_data_df, file_path, sep = ",", row.names = FALSE) 26 | message(paste(file_path, "was created")) 27 | } 28 | -------------------------------------------------------------------------------- /man/monitor_ar_aqs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{monitor_ar_aqs} 5 | \alias{monitor_ar_aqs} 6 | \title{Monitor Ar AQS stations.} 7 | \format{ 8 | A data frame with 8 observation and 6 variables: 9 | \describe{ 10 | \item{name}{MonitorAr Program AQS name.} 11 | \item{code}{MonitorAr Program AQS abbreviation.} 12 | \item{lon}{MonitorAr Program AQS longitude.} 13 | \item{lat}{MonitorAr Program AQS latitude.} 14 | \item{x_utm_sirgas2000}{MonitorAr Program AQS longitude in SIRGAS 2000 15 | (EPSG:31983).} 16 | \item{y_utm_sirgas2000}{MonitorAr Program AQS latitude in SIRGAS 2000 17 | (EPSG:31983).} 18 | } 19 | } 20 | \usage{ 21 | monitor_ar_aqs 22 | } 23 | \description{ 24 | List of Monitor Ar Rio air quality stations (AQS) with their codes 25 | and locations. Use this to check the parameters argument in 26 | MonitorArRetrieveParam() function. 27 | } 28 | \examples{ 29 | monitor_ar_aqs 30 | } 31 | \keyword{datasets} 32 | -------------------------------------------------------------------------------- /man/qualR.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/qualR.R 3 | \docType{package} 4 | \name{qualR} 5 | \alias{qualR-package} 6 | \alias{qualR} 7 | \title{qualR: An R package to download Sao Paulo and Rio de Janeiro 8 | air pollution data} 9 | \description{ 10 | A package to download information from CETESB QUALAR \url{https://cetesb.sp.gov.br/ar/qualar/} and MonitorAr \url{http://jeap.rio.rj.gov.br/je-metinfosmac/institucional/index.html} systems. It contains function to download different parameters, a set of criteria pollutants and the most frequent meteorological parameters used in air quality data analysis and air quality model evaluation. 11 | } 12 | \seealso{ 13 | \strong{Useful links:} 14 | \itemize{ 15 | \item{Development repository: 16 | \url{https://github.com/ropensci/qualR}} 17 | \item{Report bugs: 18 | \url{https://github.com/ropensci/qualR/issues}} 19 | \item{qualR site: 20 | \url{https://docs.ropensci.org/qualR/}} 21 | } 22 | } 23 | \author{ 24 | Mario Gavidia-Calderon and Daniel Schuch and Maria de Fatima Andrade 25 | } 26 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | Copyright (c) 2020 Mario Gavidia-Calderón 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /data-raw/monitor_ar_param.R: -------------------------------------------------------------------------------- 1 | ## code to prepare `monitor_ar_param` dataset goes here 2 | 3 | param_code <- c("SO2", "NO2", "NO", "NOx", "HCNM", "HCT", 4 | "CH4", "CO", "O3", "PM10", "PM2_5", 5 | "Chuva", "Pres", "RS", "Temp", "UR", 6 | "Dir_Vento", "Vel_Vento") 7 | param_name <- c("Dioxido de enxofre", "Dioxido de nitrogenio", "Monoxido de Nitrogenio", "Oxidos de nitrogenio", 8 | "Hidrocarbonetos Totais menos Metano", "Hidrocarbonetos Totais", "Metano", "Monoxido de Carbono", 9 | "Ozonio", "Particulas Inalaveis", "Particulas Inalaveis Finas", "Precipitacao Pluviometrica", 10 | "Pressao Atmosferica", "Radiacao Solar", "Temperatura", "Umidade Relativa do Ar", 11 | "Direcao do Vento", "Velocidade do Vento") 12 | param_units <- c("ug/m3", "ug/m3", "ug/m3", "ug/m3", "ppm", "ppm", 13 | "ug/m3", "ppm", "ug/m3", "ug/m3", "ug/m3", 14 | "mm", "mbar", "W/m2", "ºC", "%", 15 | "º", "m/s") 16 | 17 | monitor_ar_param <- data.frame(code = param_code, 18 | name = param_name, 19 | units = param_units) 20 | usethis::use_data(monitor_ar_param, overwrite = TRUE) 21 | -------------------------------------------------------------------------------- /tests/testthat/test-monitor_ar_retrieve_met.R: -------------------------------------------------------------------------------- 1 | test_that("monitor_ar_retrieve_met works!", { 2 | 3 | start_date <- "01/01/2020" 4 | end_date <- "07/01/2020" 5 | ca_met <- monitor_ar_retrieve_met(start_date, end_date, "CA") 6 | 7 | # Testing data.frame dims 8 | expect_equal(ncol(ca_met), 7) 9 | expect_equal(TRUE, ncol(ca_met) <= 145) 10 | 11 | # Testing data.frame values 12 | met_means<- colMeans(ca_met[, 2:6], na.rm = TRUE) 13 | expect_equal(met_means["tc"] > 28, met_means["tc"] < 29) 14 | expect_equal(met_means["rh"] > 74, met_means["rh"] < 75) 15 | expect_equal(met_means["ws"] > 0.8, met_means["ws"] < 0.9) 16 | expect_equal(met_means["wd"] > 157, met_means["wd"] < 158) 17 | expect_equal(met_means["p"] > 1007, met_means["p"] < 1008) 18 | 19 | # Testing data.frame classes 20 | expect_equal(TRUE, "data.frame" %in% class(ca_met)) 21 | expect_equal(TRUE, "character" %in% class(ca_met$aqs)) 22 | expect_equal(TRUE, "POSIXct" %in% class(ca_met$date)) 23 | expect_equal(TRUE, "numeric" %in% class(ca_met$tc)) 24 | expect_equal(TRUE, "numeric" %in% class(ca_met$rh)) 25 | expect_equal(TRUE, "numeric" %in% class(ca_met$ws)) 26 | expect_equal(TRUE, "numeric" %in% class(ca_met$wd)) 27 | expect_equal(TRUE, "numeric" %in% class(ca_met$p)) 28 | 29 | }) 30 | -------------------------------------------------------------------------------- /tests/testthat/test-monitor_ar_retrieve_pol.R: -------------------------------------------------------------------------------- 1 | test_that("monitor_ar_retrieve_pol works!", { 2 | 3 | start_date <- "01/01/2020" 4 | end_date <- "07/01/2020" 5 | ca_pol <- monitor_ar_retrieve_pol(start_date, end_date, "CA") 6 | 7 | # Testing data.frame dims 8 | expect_equal(ncol(ca_pol), 9) 9 | expect_equal(TRUE, nrow(ca_pol) >= 144) 10 | 11 | # Testing data.frame values 12 | pol_means<- colMeans(ca_pol[, 2:8], na.rm = TRUE) 13 | expect_equal(pol_means["o3"] > 33, pol_means["o3"] < 35) 14 | expect_equal(pol_means["co"] > 0.5, pol_means["co"] < 0.6) 15 | expect_equal(pol_means["pm10"] > 22, pol_means["pm10"] < 23) 16 | 17 | # Testind data.frame classes 18 | expect_equal(TRUE, "data.frame" %in% class(ca_pol)) 19 | expect_equal(TRUE, "POSIXct" %in% class(ca_pol$date)) 20 | expect_equal(TRUE, "numeric" %in% class(ca_pol$o3)) 21 | expect_equal(TRUE, "numeric" %in% class(ca_pol$no)) 22 | expect_equal(TRUE, "numeric" %in% class(ca_pol$no2)) 23 | expect_equal(TRUE, "numeric" %in% class(ca_pol$nox)) 24 | expect_equal(TRUE, "numeric" %in% class(ca_pol$co)) 25 | expect_equal(TRUE, "numeric" %in% class(ca_pol$pm10)) 26 | expect_equal(TRUE, "numeric" %in% class(ca_pol$pm25)) 27 | expect_equal(TRUE, "character" %in% class(ca_pol$aqs)) 28 | 29 | }) 30 | -------------------------------------------------------------------------------- /tests/testthat/test-cetesb_retrieve_met.R: -------------------------------------------------------------------------------- 1 | test_that("cetesb_retrieve_met works!", { 2 | 3 | load("sysdata.rda") 4 | 5 | pin_met <- cetesb_retrieve_met(u,p,aqs_code = 99, 6 | start_date = "01/01/2020", 7 | end_date = "07/01/2020") 8 | 9 | # Testing data.frame dims 10 | expect_equal(ncol(pin_met), 7) 11 | expect_equal(nrow(pin_met), 169) 12 | 13 | # Testing data.frame values 14 | param_means<- colMeans(pin_met[, 2:6], na.rm = TRUE) 15 | expect_equal(param_means["tc"] > 23, param_means["tc"] < 24) 16 | expect_equal(param_means["rh"] > 74, param_means["rh"] < 75) 17 | expect_equal(param_means["ws"] > 1, param_means["ws"] < 2) 18 | expect_equal(param_means["wd"] > 238, param_means["wd"] < 239) 19 | 20 | # Testing data.frame classes 21 | expect_equal(TRUE, "data.frame" %in% class(pin_met)) 22 | expect_equal(TRUE, "character" %in% class(pin_met$aqs)) 23 | expect_equal(TRUE, "POSIXct" %in% class(pin_met$date)) 24 | expect_equal(TRUE, "numeric" %in% class(pin_met$tc)) 25 | expect_equal(TRUE, "numeric" %in% class(pin_met$rh)) 26 | expect_equal(TRUE, "numeric" %in% class(pin_met$ws)) 27 | expect_equal(TRUE, "numeric" %in% class(pin_met$wd)) 28 | expect_equal(TRUE, "numeric" %in% class(pin_met$p)) 29 | }) 30 | -------------------------------------------------------------------------------- /tests/testthat/test-monitor_ar_retrieve_param.R: -------------------------------------------------------------------------------- 1 | test_that("monitor_ar_retrieve works!", { 2 | 3 | csv_path <- file.path(tempdir(), "cetesb-data") 4 | dir.create(csv_path) 5 | 6 | ca_o3 <- monitor_ar_retrieve_param(start_date = "01/02/2015", 7 | end_date = "01/03/2015", 8 | aqs_code = "CA", 9 | parameters = "O3", 10 | to_csv = TRUE, 11 | csv_path = csv_path) 12 | # Testing writing output 13 | expect_equal(TRUE, 14 | file.exists( 15 | paste0(csv_path, 16 | "/ESTACAO CENTRO_O3_01-02-2015_01-03-2015.csv") 17 | )) 18 | 19 | # Testing data.frame output 20 | expect_equal(ncol(ca_o3), 3) 21 | expect_equal(TRUE, nrow(ca_o3) >= 672) 22 | 23 | # Testing data.frame values 24 | o3_mean <- mean(ca_o3$o3, na.rm = TRUE) 25 | expect_equal(o3_mean > 22, o3_mean < 23) 26 | 27 | # Testing data.frame classes 28 | expect_equal(TRUE, "data.frame" %in% class(ca_o3)) 29 | expect_equal(TRUE, "character" %in% class(ca_o3$aqs)) 30 | expect_equal(TRUE, "POSIXct" %in% class(ca_o3$date)) 31 | expect_equal(TRUE, "numeric" %in% class(ca_o3$o3)) 32 | }) 33 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | # DO NOT CHANGE the "init" and "install" sections below 2 | 3 | # Download script file from GitHub 4 | init: 5 | ps: | 6 | $ErrorActionPreference = "Stop" 7 | Invoke-WebRequest http://raw.github.com/krlmlr/r-appveyor/master/scripts/appveyor-tool.ps1 -OutFile "..\appveyor-tool.ps1" 8 | Import-Module '..\appveyor-tool.ps1' 9 | 10 | install: 11 | ps: Bootstrap 12 | 13 | cache: 14 | - C:\RLibrary 15 | 16 | environment: 17 | NOT_CRAN: true 18 | # env vars that may need to be set, at least temporarily, from time to time 19 | # see https://github.com/krlmlr/r-appveyor#readme for details 20 | # USE_RTOOLS: true 21 | # R_REMOTES_STANDALONE: true 22 | global: 23 | WARNINGS_ARE_ERRORS: 1 24 | 25 | 26 | # Adapt as necessary starting from here 27 | 28 | build_script: 29 | - travis-tool.sh install_deps 30 | 31 | test_script: 32 | - travis-tool.sh run_tests 33 | 34 | on_failure: 35 | - 7z a failure.zip *.Rcheck\* 36 | - appveyor PushArtifact failure.zip 37 | 38 | artifacts: 39 | - path: '*.Rcheck\**\*.log' 40 | name: Logs 41 | 42 | - path: '*.Rcheck\**\*.out' 43 | name: Logs 44 | 45 | - path: '*.Rcheck\**\*.fail' 46 | name: Logs 47 | 48 | - path: '*.Rcheck\**\*.Rout' 49 | name: Logs 50 | 51 | - path: '\*_*.tar.gz' 52 | name: Bits 53 | 54 | - path: '\*_*.zip' 55 | name: Bits 56 | -------------------------------------------------------------------------------- /man/monitor_ar_retrieve_pol.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/monitor_ar_retrieve_pol.R 3 | \name{monitor_ar_retrieve_pol} 4 | \alias{monitor_ar_retrieve_pol} 5 | \title{Download criteria pollutants from Monitor Ar program} 6 | \usage{ 7 | monitor_ar_retrieve_pol( 8 | start_date, 9 | end_date, 10 | aqs_code, 11 | verbose = TRUE, 12 | to_local = TRUE, 13 | to_csv = FALSE, 14 | csv_path = "" 15 | ) 16 | } 17 | \arguments{ 18 | \item{start_date}{Date to start downloading in dd/mm/yyyy.} 19 | 20 | \item{end_date}{Date to end downloading in dd/mm/yyyy.} 21 | 22 | \item{aqs_code}{Code of AQS.} 23 | 24 | \item{verbose}{Print query summary.} 25 | 26 | \item{to_local}{Date information in local time. TRUE by default.} 27 | 28 | \item{to_csv}{Creates a csv file. FALSE by default.} 29 | 30 | \item{csv_path}{Path to save the csv file.} 31 | } 32 | \value{ 33 | data.frame with O3, NO, NO2, NOx, PM2.5, PM10 and CO 34 | information. 35 | } 36 | \description{ 37 | This function download the criteria pollutants from 38 | one air quality station (AQS) of Monitor Ar Program. 39 | It will pad out the date with missing data with NA. 40 | } 41 | \examples{ 42 | \dontrun{ 43 | # Downloading criteria pollutants from CENTRO AQS 44 | # from January first to 7th of 2020 45 | start_date <- "01/01/2020" 46 | end_date <- "07/01/2020" 47 | ca_pol <- monitor_ar_retrieve_pol(start_date, end_date, "CA") 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /data-raw/cetesb.R: -------------------------------------------------------------------------------- 1 | ## code to prepare internal datasets goes here 2 | 3 | cetesb <- read.table("data-raw/cetesb_qualR.dat", sep = ",", 4 | header = TRUE, col.names = c("code", "name")) 5 | cetesb$ascii <- stri_trans_general(cetesb$name, "ASCII") 6 | 7 | cetesb$ascii <- gsub("^", "", cetesb$ascii) 8 | cetesb$ascii <- gsub("~", "", cetesb$ascii) 9 | cetesb$ascii <- gsub("'", "", cetesb$ascii) 10 | 11 | params <- read.table("data-raw/cetesb_variables.dat", header = TRUE, 12 | sep = ",", col.names = c("code", "name"), 13 | stringsAsFactors = FALSE) 14 | 15 | params_code <- data.frame( 16 | name = do.call( 17 | rbind, 18 | lapply(strsplit(toupper(params$name), " "), 19 | function(x) x[[1]][1]) 20 | ), 21 | code = params$code 22 | ) 23 | 24 | # Monitor Ar data 25 | param_monitor_ar <- read.table("data-raw/monitor_ar_variables.dat", 26 | header = TRUE, sep = ",", 27 | stringsAsFactors = FALSE) 28 | 29 | aqs_monitor_ar <- read.table("data-raw/monitor_ar_qualR.dat", header = TRUE, stringsAsFactors = FALSE, 30 | sep = ",", dec=".") 31 | aqs_monitor_ar$name <- iconv(aqs_monitor_ar$name, from = "UTF-8", to = "ASCII//TRANSLIT") 32 | 33 | 34 | usethis::use_data(cetesb, params, params_code, 35 | param_monitor_ar, aqs_monitor_ar, 36 | internal = TRUE, overwrite = TRUE) 37 | -------------------------------------------------------------------------------- /tests/testthat/test-cetesb_retrieve_param.R: -------------------------------------------------------------------------------- 1 | test_that("cetesb_retrieve_param works!", { 2 | 3 | load("sysdata.rda") 4 | 5 | csv_path <- file.path(tempdir(), "cetesb-data2") 6 | dir.create(csv_path) 7 | 8 | pin_param <- cetesb_retrieve_param(u,p,c("o3","NOX", "VV"), 99, 9 | "01/01/2020", "07/01/2020", 10 | to_csv = TRUE, csv_path = csv_path) 11 | # Testing writing output 12 | expect_equal(TRUE, 13 | file.exists( 14 | paste0(csv_path, 15 | "/Pinheiros_O3_NOX_VV_01-01-2020_07-01-2020.csv") 16 | )) 17 | 18 | # Testing data.frame dims 19 | expect_equal(ncol(pin_param), 5) 20 | expect_equal(nrow(pin_param), 169) 21 | 22 | # Testing data.frame values 23 | param_means<- colMeans(pin_param[, 3:5], na.rm = TRUE) 24 | expect_equal(param_means["nox"] > 20, param_means["nox"] < 21) 25 | expect_equal(param_means["o3"] > 27, param_means["o3"] < 28) 26 | expect_equal(param_means["ws"] > 1, param_means["ws"] < 2) 27 | 28 | # Testing data.frame classes 29 | expect_equal(TRUE, "data.frame" %in% class(pin_param)) 30 | expect_equal(TRUE, "character" %in% class(pin_param$aqs)) 31 | expect_equal(TRUE, "POSIXct" %in% class(pin_param$date)) 32 | expect_equal(TRUE, "numeric" %in% class(pin_param$o3)) 33 | expect_equal(TRUE, "numeric" %in% class(pin_param$nox)) 34 | expect_equal(TRUE, "numeric" %in% class(pin_param$ws)) 35 | }) 36 | -------------------------------------------------------------------------------- /man/monitor_ar_retrieve_met.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/monitor_ar_retrieve_met.R 3 | \name{monitor_ar_retrieve_met} 4 | \alias{monitor_ar_retrieve_met} 5 | \title{Download meteorological parameters from Monitor Ar program} 6 | \usage{ 7 | monitor_ar_retrieve_met( 8 | start_date, 9 | end_date, 10 | aqs_code, 11 | verbose = TRUE, 12 | to_local = TRUE, 13 | to_csv = FALSE, 14 | csv_path = "" 15 | ) 16 | } 17 | \arguments{ 18 | \item{start_date}{Date to start downloading in dd/mm/yyyy.} 19 | 20 | \item{end_date}{Date to end downloading in dd/mm/yyyy.} 21 | 22 | \item{aqs_code}{Code of AQS. See \code{monitor_ar_aqs}.} 23 | 24 | \item{verbose}{Print query summary.} 25 | 26 | \item{to_local}{Date information in local time. TRUE by default.} 27 | 28 | \item{to_csv}{Create a csv file. FALSE by default.} 29 | 30 | \item{csv_path}{Path to save the csv file.} 31 | } 32 | \value{ 33 | data.frame with Temperature (c), Relative Humidity (\%), 34 | Wind speed (m/s) and direction (degrees) and Pressure information. 35 | } 36 | \description{ 37 | This function download the main meteorological parameters from one 38 | air quality station (AQS) of Monitor Ar network. It will 39 | pad out the date with missing data with NA. 40 | } 41 | \examples{ 42 | \dontrun{ 43 | # Downloading meteorological data from CENTRO AQS 44 | # from January first to 7th of 2020 45 | start_date <- "01/01/2020" 46 | end_date <- "07/01/2020" 47 | ca_met <- monitor_ar_retrieve_met(start_date, end_date, "CA") 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # qualR 0.9.6 2 | 3 | ## Changes 4 | - Function names from CamelCase to snake_case 5 | - Better and consistent naming of returned data frames variables and datasets. 6 | 7 | ## New Features 8 | - Updated qualR site. 9 | - Vignette with examples are available. 10 | 11 | # qualR 0.9.5 12 | 13 | ## Changes 14 | - `CetesbRetrive` function is now depreciated. Use `CetesbRetrieveParam` instead. 15 | - `CetesbRetrieveAll` is now called `CetesbRetrieveMetPol` 16 | 17 | ## New Features 18 | - [Monitor Ar Program air quality network](https://www.rio.rj.gov.br/web/smac/monitorar-rio1) is included. Download meteorological parameters and air pollution from Rio de Janeiro city are now available through `MonitorArRetrieve` functions. 19 | - All functions has verbose option to print query summary. 20 | - All functions can export downloaded data to `.csv` files. 21 | - Units added in parameters datasets `cetesb_param`and `monitor_ar_param`. 22 | 23 | ## Bug Fixes 24 | - Now `qualR` uses `httr` instead of `RCurl` package to fix SSL23_SERVER_HELLO error on Windows. 25 | 26 | 27 | # qualR 0.9.1 28 | 29 | ## Features 30 | - Initial version 31 | - Download one parameter from one air quality station with `CetesbRetrieve` function. 32 | - Download criteria pollutants from one air quality station with `CetesbRetrievePol` function. 33 | - Download meteorological parameters from one air quality station with `CetesbRetrieveMet` function. 34 | - Download criteria pollutants and meteorological parameters from one air quality station with `CetesbRetrieveAll` function. 35 | -------------------------------------------------------------------------------- /.github/workflows/R-CMD-check.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | branches: [main, master] 8 | 9 | name: R-CMD-check 10 | 11 | jobs: 12 | R-CMD-check: 13 | runs-on: ${{ matrix.config.os }} 14 | 15 | name: ${{ matrix.config.os }} (${{ matrix.config.r }}) 16 | 17 | strategy: 18 | fail-fast: false 19 | matrix: 20 | config: 21 | - {os: macos-latest, r: 'release'} 22 | - {os: windows-latest, r: 'release'} 23 | - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} 24 | - {os: ubuntu-latest, r: 'release'} 25 | - {os: ubuntu-latest, r: 'oldrel-1'} 26 | 27 | env: 28 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 29 | R_KEEP_PKG_SOURCE: yes 30 | 31 | steps: 32 | - uses: actions/checkout@v3 33 | 34 | - uses: r-lib/actions/setup-pandoc@v2 35 | 36 | - uses: r-lib/actions/setup-r@v2 37 | with: 38 | r-version: ${{ matrix.config.r }} 39 | http-user-agent: ${{ matrix.config.http-user-agent }} 40 | use-public-rspm: true 41 | 42 | - uses: r-lib/actions/setup-r-dependencies@v2 43 | with: 44 | extra-packages: any::rcmdcheck 45 | needs: check 46 | 47 | - uses: r-lib/actions/check-r-package@v2 48 | with: 49 | upload-snapshots: true 50 | -------------------------------------------------------------------------------- /man/monitor_ar_retrieve_param.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/monitor_ar_retrieve_param.R 3 | \name{monitor_ar_retrieve_param} 4 | \alias{monitor_ar_retrieve_param} 5 | \title{Download air quality and meteorology information from MonitorAr-Rio} 6 | \usage{ 7 | monitor_ar_retrieve_param( 8 | start_date, 9 | end_date, 10 | aqs_code, 11 | parameters, 12 | to_local = TRUE, 13 | verbose = TRUE, 14 | to_csv = FALSE, 15 | csv_path = "" 16 | ) 17 | } 18 | \arguments{ 19 | \item{start_date}{Date to start downloading in dd/mm/yyyy} 20 | 21 | \item{end_date}{Date to end downloading in dd/mm/yyyy} 22 | 23 | \item{aqs_code}{AQS code} 24 | 25 | \item{parameters}{Parameters to download. 26 | It can be a vector with many parameters.} 27 | 28 | \item{to_local}{Date information in local time. TRUE by default.} 29 | 30 | \item{verbose}{Print query summary.} 31 | 32 | \item{to_csv}{Creates a csv file. FALSE by default} 33 | 34 | \item{csv_path}{Path to save the csv file.} 35 | } 36 | \value{ 37 | data.frame with the selected parameter information 38 | } 39 | \description{ 40 | This function download air quality and meteorology measurements from 41 | MonitorAr-Rio program from Rio de Janeiro city. 42 | } 43 | \examples{ 44 | \dontrun{ 45 | # Downloading Ozone information from Centro AQS 46 | # from February of 2019 47 | date_start <- "01/02/2019" 48 | date_end <- "01/03/2019" 49 | aqs_code <- "CA" 50 | param <- "O3" 51 | ca_o3 <- monitor_ar_retrieve_param(date_start, date_end, aqs_code, param) 52 | 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /.github/workflows/test-coverage.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | branches: [main, master] 8 | 9 | name: test-coverage 10 | 11 | jobs: 12 | test-coverage: 13 | runs-on: ubuntu-latest 14 | env: 15 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 16 | 17 | steps: 18 | - uses: actions/checkout@v3 19 | 20 | - uses: r-lib/actions/setup-r@v2 21 | with: 22 | use-public-rspm: true 23 | 24 | - uses: r-lib/actions/setup-r-dependencies@v2 25 | with: 26 | extra-packages: any::covr 27 | needs: coverage 28 | 29 | - name: Test coverage 30 | run: | 31 | covr::codecov( 32 | quiet = FALSE, 33 | clean = FALSE, 34 | install_path = file.path(Sys.getenv("RUNNER_TEMP"), "package") 35 | ) 36 | shell: Rscript {0} 37 | 38 | - name: Show testthat output 39 | if: always() 40 | run: | 41 | ## -------------------------------------------------------------------- 42 | find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true 43 | shell: bash 44 | 45 | - name: Upload test results 46 | if: failure() 47 | uses: actions/upload-artifact@v4 48 | with: 49 | name: coverage-test-failures 50 | path: ${{ runner.temp }}/package 51 | -------------------------------------------------------------------------------- /tests/testthat/test-cetesb_retrieve_pol.R: -------------------------------------------------------------------------------- 1 | test_that("cetesb_retrieve_pol works!", { 2 | 3 | load("sysdata.rda") 4 | 5 | pin_pol <- cetesb_retrieve_pol(u,p,aqs_code = "Pinheiros", 6 | start_date = "01/01/2020", 7 | end_date = "07/01/2020") 8 | # Testing data.frame dims 9 | expect_equal(ncol(pin_pol), 9) 10 | expect_equal(nrow(pin_pol), 169) 11 | 12 | # Testing data.frame values 13 | pol_means<- colMeans(pin_pol[, 2:8], na.rm = TRUE) 14 | expect_equal(pol_means["o3"] > 27, pol_means["o3"] < 28) 15 | expect_equal(pol_means["no"] > 8, pol_means["no"] < 9) 16 | expect_equal(pol_means["no2"] > 26, pol_means["no2"] < 27) 17 | expect_equal(pol_means["nox"] > 20, pol_means["nox"] < 21) 18 | expect_equal(pol_means["co"] > 0.3, pol_means["co"] < 0.4) 19 | expect_equal(pol_means["pm10"] > 19, pol_means["pm10"] < 20) 20 | expect_equal(pol_means["pm25"] > 5, pol_means["pm25"] < 6) 21 | 22 | # Testing data.frame classes 23 | expect_equal(TRUE, "data.frame" %in% class(pin_pol)) 24 | expect_equal(TRUE, "POSIXct" %in% class(pin_pol$date)) 25 | expect_equal(TRUE, "numeric" %in% class(pin_pol$o3)) 26 | expect_equal(TRUE, "numeric" %in% class(pin_pol$no)) 27 | expect_equal(TRUE, "numeric" %in% class(pin_pol$no2)) 28 | expect_equal(TRUE, "numeric" %in% class(pin_pol$nox)) 29 | expect_equal(TRUE, "numeric" %in% class(pin_pol$co)) 30 | expect_equal(TRUE, "numeric" %in% class(pin_pol$pm10)) 31 | expect_equal(TRUE, "numeric" %in% class(pin_pol$pm25)) 32 | expect_equal(TRUE, "character" %in% class(pin_pol$aqs)) 33 | }) 34 | -------------------------------------------------------------------------------- /man/cetesb_retrieve.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cetesb_retrieve.R 3 | \name{cetesb_retrieve} 4 | \alias{cetesb_retrieve} 5 | \title{Download a single parameter from CETESB QUALAR system} 6 | \usage{ 7 | cetesb_retrieve( 8 | username, 9 | password, 10 | pol_code, 11 | aqs_code, 12 | start_date, 13 | end_date, 14 | verbose = TRUE, 15 | to_csv = FALSE 16 | ) 17 | } 18 | \arguments{ 19 | \item{username}{User name of CETESB QUALAR} 20 | 21 | \item{password}{User name's password of CETESB QUALAR} 22 | 23 | \item{pol_code}{Code of parameter} 24 | 25 | \item{aqs_code}{Code of AQS} 26 | 27 | \item{start_date}{Date to start downloading in dd/mm/yyyy} 28 | 29 | \item{end_date}{Date to end downloading in dd/mm/yyyy} 30 | 31 | \item{verbose}{Print query summary} 32 | 33 | \item{to_csv}{Creates a csv file. FALSE by default} 34 | } 35 | \value{ 36 | data.frame with the selected parameter information 37 | } 38 | \description{ 39 | This function download one parameter from one air quality stations (AQS) 40 | of CETESB AQS network. It will pad out the date with missing data with NA. 41 | } 42 | \examples{ 43 | \dontrun{ 44 | # Downloading Ozone information from Pinheiros AQS 45 | # from January first to 7th of 2020 46 | my_user_name <- "John Doe" 47 | my_pass_word <- "drowssap" 48 | o3_code <- 63 # Check with cetesb_param 49 | pin_code <- 99 # Check with cetesb_aqs 50 | start_date <- "01/01/2020" 51 | end_date <- "07/01/2020" 52 | 53 | pin_o3 <- cetesb_retrieve(my_user_name, my_pass_word, o3_code, pin_code, 54 | start_date, end_date) 55 | 56 | } 57 | } 58 | \keyword{internal} 59 | -------------------------------------------------------------------------------- /man/monitor_ar_retrieve_met_pol.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/monitor_ar_retrieve_met_pol.R 3 | \name{monitor_ar_retrieve_met_pol} 4 | \alias{monitor_ar_retrieve_met_pol} 5 | \title{Download meteorological and pollutant data from Monitor Ar Program} 6 | \usage{ 7 | monitor_ar_retrieve_met_pol( 8 | start_date, 9 | end_date, 10 | aqs_code, 11 | verbose = TRUE, 12 | to_local = TRUE, 13 | to_csv = FALSE, 14 | csv_path = "" 15 | ) 16 | } 17 | \arguments{ 18 | \item{start_date}{Date to start downloading dd/mm/yyyy} 19 | 20 | \item{end_date}{Date to end downloading dd/mm/yyyy} 21 | 22 | \item{aqs_code}{Code of AQS} 23 | 24 | \item{verbose}{Print query summary} 25 | 26 | \item{to_local}{Date information in local time. TRUE by default.} 27 | 28 | \item{to_csv}{Creates a csv file. FALSE by default.} 29 | 30 | \item{csv_path}{Path to save the csv file.} 31 | } 32 | \value{ 33 | data.frame with Temperature (C), Relative Humidity (\%), 34 | Wind Speed (m/s) and Direction (degrees), Pressure information (hPa), 35 | O3, NO, NO2, NOx, PM2.5, PM10 and CO information. 36 | } 37 | \description{ 38 | This function download the main meteorological parameters for model 39 | evaluation, together with criteria pollutants for in air quality station 40 | (AQS) of Monitor Ar program. 41 | It will pad out the date with missing data with NA 42 | } 43 | \examples{ 44 | \dontrun{ 45 | # Downloading main meteorological parameters and criteria pollutant 46 | # from CENTRO AQS from January first to 7th of 2020 47 | start_date <- "01/01/2020" 48 | end_date <- "07/01/2020" 49 | ca_all <- monitor_ar_retrieve_met_pol(start_date, end_date, "CA") 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /data-raw/cetesb_aqs.R: -------------------------------------------------------------------------------- 1 | ## code to prepare `DATASET` dataset goes here 2 | 3 | cetesb_aqs <- read.table("data-raw/cetesb_aqs.dat", 4 | sep = ",", header = TRUE, dec = ".", 5 | stringsAsFactors = F) 6 | 7 | sao_paulo_city <- c(269, 91, 95, 73, 98, 83, 262, 8 | 266, 97, 270, 85, 96, 72, 284, 9 | 99, 63, 64) 10 | rmsp <- c(118, 263, 92, 264, 279, 65, 120, 11 | 100, 101, 272, 102, 86, 103) 12 | litoral <- c(87, 119, 66, 258, 260) 13 | interior <- c(290, 107, 106, 108, 89, 276, 275, 14 | 248, 289, 259, 110, 109, 281, 111, 15 | 117, 112, 113, 288, 88, 277, 278, 16 | 273, 67, 256, 280, 116) 17 | 18 | cetesb_aqs$loc[cetesb_aqs$code %in% sao_paulo_city] <- "São Paulo" 19 | cetesb_aqs$loc[cetesb_aqs$code %in% rmsp] <- "MASP" 20 | cetesb_aqs$loc[cetesb_aqs$code %in% litoral] <- "Coast" 21 | cetesb_aqs$loc[cetesb_aqs$code %in% interior] <- "Interior" 22 | 23 | missing_aqs <- data.frame( 24 | name = c("Lapa", "Perus", "Americana-Vila Sta Maria", 25 | "Paulínia-Sta Terezinha", "Rio Claro-Jd.Guanabara", 26 | "São Sebastião" ), 27 | code = c(84, 293, 105, 291, 292, 294), 28 | lat = c(-23.50897, -23.41321, -22.72425, 29 | -22.78021, -22.43906, -23.8052), 30 | lon = c(-46.70122, -46.75605, -41.33955, 31 | -41.113904, -41.58144, -39.40007), 32 | loc = c("São Paulo", "São Paulo", "Interior", "Interior", 33 | "Interior", "Litoral") 34 | ) 35 | 36 | cetesb_aqs <- rbind(cetesb_aqs, missing_aqs) 37 | cetesb_aqs <- cetesb_aqs[order(cetesb_aqs$name), ] 38 | row.names(cetesb_aqs) <- NULL 39 | 40 | Encoding(cetesb_aqs$name) <- "UTF-8" 41 | save(cetesb_aqs, file = "data/cetesb_aqs.rda") 42 | usethis::use_data(cetesb_aqs, overwrite = TRUE) 43 | -------------------------------------------------------------------------------- /tests/testthat/test-monitor_ar_retrieve_met_pol.R: -------------------------------------------------------------------------------- 1 | test_that("monitor_ar_retrieve_met_pol works!", { 2 | 3 | start_date <- "01/01/2020" 4 | end_date <- "07/01/2020" 5 | ca_all <- monitor_ar_retrieve_met_pol(start_date, end_date, "CA") 6 | 7 | # Testing data.frame dims 8 | expect_equal(ncol(ca_all), 14) 9 | expect_equal(TRUE, ncol(ca_all) <= 145) 10 | 11 | # Testing data.frame values 12 | all_means<- colMeans(ca_all[, 2:13], na.rm = TRUE) 13 | expect_equal(all_means["tc"] > 28, all_means["tc"] < 29) 14 | expect_equal(all_means["rh"] > 74, all_means["rh"] < 75) 15 | expect_equal(all_means["ws"] > 0.8, all_means["ws"] < 0.9) 16 | expect_equal(all_means["wd"] > 157, all_means["wd"] < 159) 17 | expect_equal(all_means["p"] > 1007, all_means["p"] < 1008) 18 | expect_equal(all_means["o3"] > 33, all_means["o3"] < 35) 19 | expect_equal(all_means["co"] > 0.5, all_means["co"] < 0.6) 20 | expect_equal(all_means["pm10"] > 22, all_means["pm10"] < 23) 21 | 22 | # Testing data.frame classes 23 | expect_equal(TRUE, "data.frame" %in% class(ca_all)) 24 | expect_equal(TRUE, "numeric" %in% class(ca_all$tc)) 25 | expect_equal(TRUE, "numeric" %in% class(ca_all$rh)) 26 | expect_equal(TRUE, "numeric" %in% class(ca_all$ws)) 27 | expect_equal(TRUE, "numeric" %in% class(ca_all$wd)) 28 | expect_equal(TRUE, "numeric" %in% class(ca_all$p)) 29 | expect_equal(TRUE, "numeric" %in% class(ca_all$o3)) 30 | expect_equal(TRUE, "numeric" %in% class(ca_all$no)) 31 | expect_equal(TRUE, "numeric" %in% class(ca_all$no2)) 32 | expect_equal(TRUE, "numeric" %in% class(ca_all$nox)) 33 | expect_equal(TRUE, "numeric" %in% class(ca_all$co)) 34 | expect_equal(TRUE, "numeric" %in% class(ca_all$pm10)) 35 | expect_equal(TRUE, "numeric" %in% class(ca_all$pm25)) 36 | expect_equal(TRUE, "character" %in% class(ca_all$aqs)) 37 | }) 38 | -------------------------------------------------------------------------------- /data-raw/cetesb_qualR.dat: -------------------------------------------------------------------------------- 1 | "code","name" 2 | 290,"Americana" 3 | 105,"Americana-Vila Sta Maria" 4 | 107,"Araçatuba" 5 | 106,"Araraquara" 6 | 108,"Bauru" 7 | 90,"Cambuci" 8 | 89,"Campinas-Centro" 9 | 276,"Campinas-Taquaral" 10 | 275,"Campinas-V.União" 11 | 269,"Capão Redondo" 12 | 263,"Carapicuíba" 13 | 248,"Catanduva" 14 | 94,"Centro" 15 | 91,"Cerqueira César" 16 | 95,"Cid.Universitária-USP-Ipen" 17 | 73,"Congonhas" 18 | 87,"Cubatão-Centro" 19 | 66,"Cubatão-V.Parisi" 20 | 119,"Cubatão-Vale do Mogi" 21 | 92,"Diadema" 22 | 98,"Grajaú-Parelheiros" 23 | 289,"Guaratinguetá" 24 | 118,"Guarulhos" 25 | 264,"Guarulhos-Paço Municipal" 26 | 279,"Guarulhos-Pimentas" 27 | 83,"Ibirapuera" 28 | 262,"Interlagos" 29 | 266,"Itaim Paulista" 30 | 97,"Itaquera" 31 | 259,"Jacareí" 32 | 110,"Jaú" 33 | 109,"Jundiaí" 34 | 84,"Lapa" 35 | 281,"Limeira" 36 | 270,"Marg.Tietê-Pte Remédios" 37 | 111,"Marília" 38 | 65,"Mauá" 39 | 287,"Mogi das Cruzes" 40 | 85,"Mooca" 41 | 96,"N.Senhora do Ó" 42 | 120,"Osasco" 43 | 72,"Parque D.Pedro II" 44 | 117,"Paulínia" 45 | 112,"Paulínia Sul" 46 | 291,"Paulínia-Sta Terezinha" 47 | 293,"Perus" 48 | 284,"Pico do Jaraguá" 49 | 99,"Pinheiros" 50 | 113,"Piracicaba" 51 | 268,"Pirassununga-EM" 52 | 114,"Presidente Prudente" 53 | 288,"Ribeirão Preto" 54 | 115,"Ribeirão Preto-Ipiranga" 55 | 292,"Rio Claro-Jd.Guanabara" 56 | 100,"S.André Capuava" 57 | 101,"S.André-Centro" 58 | 254,"S.André-Paço Municipal" 59 | 272,"S.Bernardo-Centro" 60 | 102,"S.Bernardo-Paulicéia" 61 | 88,"S.José Campos" 62 | 277,"S.José Campos-Jd.Satélite" 63 | 278,"S.José Campos-Vista Verde" 64 | 236,"S.Miguel Paulista" 65 | 273,"Santa Gertrudes" 66 | 63,"Santana" 67 | 64,"Santo Amaro" 68 | 258,"Santos" 69 | 260,"Santos-Ponta da Praia" 70 | 86,"São Caetano do Sul" 71 | 116,"São José Do Rio Preto" 72 | 294,"São Sebastião" 73 | 67,"Sorocaba" 74 | 103,"Taboão da Serra" 75 | 256,"Tatuí" 76 | 280,"Taubaté" 77 | -------------------------------------------------------------------------------- /man/cetesb_retrieve_pol.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cetesb_retrieve_pol.R 3 | \name{cetesb_retrieve_pol} 4 | \alias{cetesb_retrieve_pol} 5 | \title{Download criteria pollutants from CETESB QUALAR} 6 | \usage{ 7 | cetesb_retrieve_pol( 8 | username, 9 | password, 10 | aqs_code, 11 | start_date, 12 | end_date, 13 | verbose = TRUE, 14 | to_csv = FALSE, 15 | csv_path = "" 16 | ) 17 | } 18 | \arguments{ 19 | \item{username}{User name of CETESB QUALAR} 20 | 21 | \item{password}{User name's password of CETESB QUALAR} 22 | 23 | \item{aqs_code}{Code of AQS} 24 | 25 | \item{start_date}{Date to start downloading in dd/mm/yyyy} 26 | 27 | \item{end_date}{Date to end downloading in dd/mm/yyyy} 28 | 29 | \item{verbose}{Print query summary} 30 | 31 | \item{to_csv}{Creates a csv file. FALSE by default} 32 | 33 | \item{csv_path}{Path to save the csv file} 34 | } 35 | \value{ 36 | data.frame with O3, NO, NO2, PM2.5, PM10 and CO information. 37 | Units are ug/m3 except for CO which is in ppm, and NOx which is in ppb. 38 | } 39 | \description{ 40 | This function download the criteria pollutants from one air quality station 41 | (AQS) of CETESB AQS network. 42 | It will pad out the date with missing data with NA. 43 | This function required to have 44 | \href{https://seguranca.cetesb.sp.gov.br/Home/CadastrarUsuario}{an account} 45 | in \href{https://qualar.cetesb.sp.gov.br/qualar/home.do}{CETESB QUALAR}. 46 | } 47 | \examples{ 48 | \dontrun{ 49 | # Downloading criteria pollutants from Pinheiros AQS 50 | # from January first to 7th of 2020 51 | my_user_name <- "John Doe" 52 | my_pass_word <- "drowssap" 53 | pin_code <- 99 # Check with cetesb_aqs 54 | start_date <- "01/01/2020" 55 | end_date <- "07/01/2020" 56 | 57 | pin_pol <- cetesb_retrieve_pol(my_user_name, my_pass_word, pin_code, 58 | start_date, end_date) 59 | 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /man/cetesb_retrieve_met.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cetesb_retrieve_met.R 3 | \name{cetesb_retrieve_met} 4 | \alias{cetesb_retrieve_met} 5 | \title{Download meteorological parameters from CETESB QUALAR} 6 | \usage{ 7 | cetesb_retrieve_met( 8 | username, 9 | password, 10 | aqs_code, 11 | start_date, 12 | end_date, 13 | verbose = TRUE, 14 | to_csv = FALSE, 15 | csv_path = "" 16 | ) 17 | } 18 | \arguments{ 19 | \item{username}{User name of CETESB QUALAR} 20 | 21 | \item{password}{User name's password of CETESB QUALAR} 22 | 23 | \item{aqs_code}{Code of AQS} 24 | 25 | \item{start_date}{Date to start downloading in dd/mm/yyyy} 26 | 27 | \item{end_date}{Date to end downloading in dd/mm/yyyy} 28 | 29 | \item{verbose}{Print query summary} 30 | 31 | \item{to_csv}{Creates a csv file. FALSE by default} 32 | 33 | \item{csv_path}{Path to save the csv file.} 34 | } 35 | \value{ 36 | data.frame with Temperature (C), Relative Humidity (\%), 37 | Wind Speed (m/s) and Direction (degrees), and Pressure information. 38 | } 39 | \description{ 40 | This function download the main meteorological parameters for 41 | model evaluation from one air quality station (AQS) of CETESB AQS network. 42 | It will pad out the date with missing data with NA. 43 | This function requires to have 44 | \href{https://seguranca.cetesb.sp.gov.br/Home/CadastrarUsuario}{an account} 45 | in \href{https://qualar.cetesb.sp.gov.br/qualar/home.do}{CETESB QUALAR}. 46 | } 47 | \examples{ 48 | \dontrun{ 49 | # Downloading meteorological data from Pinheiros AQS 50 | # from January first to 7th of 2020 51 | my_user_name <- "John Doe" 52 | my_pass_word <- "drowssap" 53 | pin_code <- 99 # Check with cetesb_aqs 54 | start_date <- "01/01/2020" 55 | end_date <- "07/01/2020" 56 | 57 | pin_pol <- cetesb_retrieve_met(my_user_name, my_pass_word, pin_code, 58 | start_date, end_date) 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /docs/sitemap.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | /404.html 5 | 6 | 7 | /CODE_OF_CONDUCT.html 8 | 9 | 10 | /CONTRIBUTING.html 11 | 12 | 13 | /LICENSE-text.html 14 | 15 | 16 | /LICENSE.html 17 | 18 | 19 | /articles/index.html 20 | 21 | 22 | /articles/qualr.html 23 | 24 | 25 | /authors.html 26 | 27 | 28 | /index.html 29 | 30 | 31 | /news/index.html 32 | 33 | 34 | /reference/CetesbRetrievePol.html 35 | 36 | 37 | /reference/cetesb_aqs.html 38 | 39 | 40 | /reference/cetesb_param.html 41 | 42 | 43 | /reference/cetesb_retrieve.html 44 | 45 | 46 | /reference/cetesb_retrieve_met.html 47 | 48 | 49 | /reference/cetesb_retrieve_met_pol.html 50 | 51 | 52 | /reference/cetesb_retrieve_param.html 53 | 54 | 55 | /reference/cetesb_retrieve_pol.html 56 | 57 | 58 | /reference/index.html 59 | 60 | 61 | /reference/monitor_ar_aqs.html 62 | 63 | 64 | /reference/monitor_ar_param.html 65 | 66 | 67 | /reference/monitor_ar_retrieve_met.html 68 | 69 | 70 | /reference/monitor_ar_retrieve_met_pol.html 71 | 72 | 73 | /reference/monitor_ar_retrieve_param.html 74 | 75 | 76 | /reference/monitor_ar_retrieve_pol.html 77 | 78 | 79 | /reference/qualR.html 80 | 81 | 82 | -------------------------------------------------------------------------------- /man/cetesb_retrieve_met_pol.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cetesb_retrieve_met_pol.R 3 | \name{cetesb_retrieve_met_pol} 4 | \alias{cetesb_retrieve_met_pol} 5 | \title{Download meteorological and pollutant data from CETESB QUALAR} 6 | \usage{ 7 | cetesb_retrieve_met_pol( 8 | username, 9 | password, 10 | aqs_code, 11 | start_date, 12 | end_date, 13 | verbose = TRUE, 14 | to_csv = FALSE, 15 | csv_path = "" 16 | ) 17 | } 18 | \arguments{ 19 | \item{username}{User name of CETESB QUALAR} 20 | 21 | \item{password}{User name's password of CETESB QUALAR} 22 | 23 | \item{aqs_code}{Code of AQS} 24 | 25 | \item{start_date}{Date to start downloading in dd/mm/yyyy} 26 | 27 | \item{end_date}{Date to end downloading in dd/mm/yyyy} 28 | 29 | \item{verbose}{Print query summary} 30 | 31 | \item{to_csv}{Creates a csv file. FALSE by default} 32 | 33 | \item{csv_path}{Path to save the csv file.} 34 | } 35 | \value{ 36 | data.frame with Temperature (C), Relative Humidity (\%), 37 | Wind Speed (m/s) and Direction (degrees), Pressure information (hPa), 38 | O3, NO, NO2, NOx, PM2.5, PM10 and CO information. 39 | } 40 | \description{ 41 | This function download the main meteorological parameters for model 42 | evaluation, together with criteria pollutants for one 43 | air quality station (AQS). It will pad out the date with 44 | missing data with NA. 45 | This function required to have 46 | \href{https://seguranca.cetesb.sp.gov.br/Home/CadastrarUsuario}{an account} 47 | in \href{https://qualar.cetesb.sp.gov.br/qualar/home.do}{CETESB QUALAR}. 48 | } 49 | \examples{ 50 | \dontrun{ 51 | # Downloading main meteorological parameters and criteria pollutants 52 | # from Pinheiros AQS from January first to 7th of 2020 53 | my_user_name <- "John Doe" 54 | my_pass_word <- "drowssap" 55 | pin_code <- 99 # Check with cetesb_aqs 56 | start_date <- "01/01/2020" 57 | end_date <- "07/01/2020" 58 | 59 | pin_all <- cetesb_retrieve_met_pol(my_user_name, my_pass_word, pin_code, 60 | start_date, end_date) 61 | 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /docs/bootstrap-toc.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | 6 | /* modified from https://github.com/twbs/bootstrap/blob/94b4076dd2efba9af71f0b18d4ee4b163aa9e0dd/docs/assets/css/src/docs.css#L548-L601 */ 7 | 8 | /* All levels of nav */ 9 | nav[data-toggle='toc'] .nav > li > a { 10 | display: block; 11 | padding: 4px 20px; 12 | font-size: 13px; 13 | font-weight: 500; 14 | color: #767676; 15 | } 16 | nav[data-toggle='toc'] .nav > li > a:hover, 17 | nav[data-toggle='toc'] .nav > li > a:focus { 18 | padding-left: 19px; 19 | color: #563d7c; 20 | text-decoration: none; 21 | background-color: transparent; 22 | border-left: 1px solid #563d7c; 23 | } 24 | nav[data-toggle='toc'] .nav > .active > a, 25 | nav[data-toggle='toc'] .nav > .active:hover > a, 26 | nav[data-toggle='toc'] .nav > .active:focus > a { 27 | padding-left: 18px; 28 | font-weight: bold; 29 | color: #563d7c; 30 | background-color: transparent; 31 | border-left: 2px solid #563d7c; 32 | } 33 | 34 | /* Nav: second level (shown on .active) */ 35 | nav[data-toggle='toc'] .nav .nav { 36 | display: none; /* Hide by default, but at >768px, show it */ 37 | padding-bottom: 10px; 38 | } 39 | nav[data-toggle='toc'] .nav .nav > li > a { 40 | padding-top: 1px; 41 | padding-bottom: 1px; 42 | padding-left: 30px; 43 | font-size: 12px; 44 | font-weight: normal; 45 | } 46 | nav[data-toggle='toc'] .nav .nav > li > a:hover, 47 | nav[data-toggle='toc'] .nav .nav > li > a:focus { 48 | padding-left: 29px; 49 | } 50 | nav[data-toggle='toc'] .nav .nav > .active > a, 51 | nav[data-toggle='toc'] .nav .nav > .active:hover > a, 52 | nav[data-toggle='toc'] .nav .nav > .active:focus > a { 53 | padding-left: 28px; 54 | font-weight: 500; 55 | } 56 | 57 | /* from https://github.com/twbs/bootstrap/blob/e38f066d8c203c3e032da0ff23cd2d6098ee2dd6/docs/assets/css/src/docs.css#L631-L634 */ 58 | nav[data-toggle='toc'] .nav > .active > ul { 59 | display: block; 60 | } 61 | -------------------------------------------------------------------------------- /man/cetesb_retrieve_param.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cetesb_retrieve_param.R 3 | \name{cetesb_retrieve_param} 4 | \alias{cetesb_retrieve_param} 5 | \title{Download list of observation from CETESB QUALAR} 6 | \usage{ 7 | cetesb_retrieve_param( 8 | username, 9 | password, 10 | parameters, 11 | aqs_code, 12 | start_date, 13 | end_date, 14 | verbose = TRUE, 15 | to_csv = FALSE, 16 | csv_path = "" 17 | ) 18 | } 19 | \arguments{ 20 | \item{username}{User name of CETESB QUALAR} 21 | 22 | \item{password}{User name's password of CETESB QUALAR} 23 | 24 | \item{parameters}{a character vector with the parameters abbreviations 25 | to download} 26 | 27 | \item{aqs_code}{Code of AQS} 28 | 29 | \item{start_date}{Date to start downloading in dd/mm/yyyy} 30 | 31 | \item{end_date}{Date to end downloading in dd/mm/yyyy} 32 | 33 | \item{verbose}{Print query summary} 34 | 35 | \item{to_csv}{Creates a csv file. FALSE by default} 36 | 37 | \item{csv_path}{Path to save the csv file} 38 | } 39 | \value{ 40 | data.frame with parameters described in \code{params} vector 41 | } 42 | \description{ 43 | This function downloads the parameters in a vector. These parameters 44 | can be both pollutants or meteorological observations for one air 45 | quality station (AQS). It will pad out the date with missing data 46 | with NA. This function requires to have 47 | \href{https://seguranca.cetesb.sp.gov.br/Home/CadastrarUsuario}{an account} 48 | in \href{https://qualar.cetesb.sp.gov.br/qualar/home.do}{CETESB QUALAR}. 49 | } 50 | \examples{ 51 | \dontrun{ 52 | # Download ozone, nitrogen dioxide, and wind speed 53 | # from Pinheiros AQS, from January first to 7th of 2020 54 | 55 | my_user_name <- "John Doe" 56 | my_pass_word <- "drowssap" 57 | pin_code <- 99 # Check with cetesb_aqs 58 | start_date <- "01/01/2020" 59 | end_date <- "07/01/2020" 60 | params <- c("o3","NOX", "VV") 61 | 62 | pin_param <- cetesb_retrieve_param(my_user_name, my_pass_word, 63 | params, pin_code, 64 | start_date, end_date) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: qualR 2 | Title: An R package to download São Paulo and Rio de Janeiro air pollution data 3 | Version: 0.9.7 4 | Authors@R: c( 5 | person(given = "Mario", 6 | family = "Gavidia-Calderón", 7 | role = c("aut", "cre"), 8 | email = "mario.calderon@iag.usp.br", 9 | comment = c(ORCID = "0000-0002-7371-1116")), 10 | person(given = "Maria de Fatima", 11 | family = "Andrade", 12 | role = c("ctb", "ths"), 13 | email = "maria.andrade@iag.usp.br", 14 | comment = c(ORCID = "0000-0001-5351-8311")), 15 | person(given = "Daniel", 16 | family = "Schuch", 17 | role = c("aut","ctb"), 18 | email = "d.schuch@northeastern.edu", 19 | comment = c(ORCID = "0000-0001-5977-4519")), 20 | person(given = "Beatriz", 21 | family = "Milz", 22 | role = "rev", 23 | comment = "Beatriz reviewed the package (v. 0.9.6) for rOpenSci"), 24 | person(given = "Kaue", 25 | family = "de Sousa", 26 | role = "rev", 27 | comment = "Kaue reviewed the package (v. 0.9.6) for rOpenSci") 28 | ) 29 | Description: A package to download information from 30 | CETESB QUALAR and 31 | MonitorAr 32 | systems. It contains function to download different parameters, a set of 33 | criteria pollutants and the most frequent meteorological parameters used in 34 | air quality data analysis and air quality model evaluation. 35 | License: MIT + file LICENSE 36 | Encoding: UTF-8 37 | LazyData: true 38 | Roxygen: list(markdown = TRUE) 39 | RoxygenNote: 7.3.2 40 | Imports: 41 | XML, 42 | httr, 43 | jsonlite 44 | URL: https://docs.ropensci.org/qualR (website) https://github.com/ropensci/qualR 45 | BugReports: https://github.com/ropensci/qualR/issues 46 | Suggests: 47 | knitr, 48 | covr, 49 | testthat (>= 3.0.0), 50 | rmarkdown, 51 | openair, 52 | ggplot2, 53 | purrr, 54 | magrittr 55 | Depends: 56 | R (>= 3.5.0) 57 | Config/testthat/edition: 3 58 | VignetteBuilder: knitr 59 | -------------------------------------------------------------------------------- /tests/testthat/test-cetesb_retrieve_met_pol.R: -------------------------------------------------------------------------------- 1 | test_that("cetesb_retrieve_met_pol works!", { 2 | 3 | load("sysdata.rda") 4 | 5 | pinheiros <- cetesb_retrieve_met_pol(u,p,aqs_code = 99, 6 | start_date = "01/01/2020", 7 | end_date = "07/01/2020") 8 | 9 | # Testing data.frame dims 10 | expect_equal(ncol(pinheiros), 14) 11 | expect_equal(nrow(pinheiros), 169) 12 | 13 | # Testing data.frame values 14 | param_means<- colMeans(pinheiros[, 2:13], na.rm = TRUE) 15 | expect_equal(param_means["tc"] > 23, param_means["tc"] < 24) 16 | expect_equal(param_means["rh"] > 74, param_means["rh"] < 75) 17 | expect_equal(param_means["ws"] > 1, param_means["ws"] < 2) 18 | expect_equal(param_means["wd"] > 238, param_means["wd"] < 239) 19 | expect_equal(param_means["o3"] > 27, param_means["o3"] < 28) 20 | expect_equal(param_means["no"] > 8, param_means["no"] < 9) 21 | expect_equal(param_means["no2"] > 26, param_means["no2"] < 27) 22 | expect_equal(param_means["nox"] > 20, param_means["nox"] < 21) 23 | expect_equal(param_means["co"] > 0.3, param_means["co"] < 0.4) 24 | # expect_equal(param_means["pm10"] > 19, param_means["pm10"] < 20) # I tested in a Mac, it worked 25 | expect_equal(param_means["pm25"] > 5, param_means["pm25"] < 7) 26 | 27 | # Testing data.frame classes 28 | expect_equal(TRUE, "data.frame" %in% class(pinheiros)) 29 | expect_equal(TRUE, "numeric" %in% class(pinheiros$tc)) 30 | expect_equal(TRUE, "numeric" %in% class(pinheiros$rh)) 31 | expect_equal(TRUE, "numeric" %in% class(pinheiros$ws)) 32 | expect_equal(TRUE, "numeric" %in% class(pinheiros$wd)) 33 | expect_equal(TRUE, "numeric" %in% class(pinheiros$p)) 34 | expect_equal(TRUE, "numeric" %in% class(pinheiros$o3)) 35 | expect_equal(TRUE, "numeric" %in% class(pinheiros$no)) 36 | expect_equal(TRUE, "numeric" %in% class(pinheiros$no2)) 37 | expect_equal(TRUE, "numeric" %in% class(pinheiros$nox)) 38 | expect_equal(TRUE, "numeric" %in% class(pinheiros$co)) 39 | expect_equal(TRUE, "numeric" %in% class(pinheiros$pm10)) 40 | expect_equal(TRUE, "numeric" %in% class(pinheiros$pm25)) 41 | expect_equal(TRUE, "character" %in% class(pinheiros$aqs)) 42 | }) 43 | -------------------------------------------------------------------------------- /docs/docsearch.js: -------------------------------------------------------------------------------- 1 | $(function() { 2 | 3 | // register a handler to move the focus to the search bar 4 | // upon pressing shift + "/" (i.e. "?") 5 | $(document).on('keydown', function(e) { 6 | if (e.shiftKey && e.keyCode == 191) { 7 | e.preventDefault(); 8 | $("#search-input").focus(); 9 | } 10 | }); 11 | 12 | $(document).ready(function() { 13 | // do keyword highlighting 14 | /* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */ 15 | var mark = function() { 16 | 17 | var referrer = document.URL ; 18 | var paramKey = "q" ; 19 | 20 | if (referrer.indexOf("?") !== -1) { 21 | var qs = referrer.substr(referrer.indexOf('?') + 1); 22 | var qs_noanchor = qs.split('#')[0]; 23 | var qsa = qs_noanchor.split('&'); 24 | var keyword = ""; 25 | 26 | for (var i = 0; i < qsa.length; i++) { 27 | var currentParam = qsa[i].split('='); 28 | 29 | if (currentParam.length !== 2) { 30 | continue; 31 | } 32 | 33 | if (currentParam[0] == paramKey) { 34 | keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20")); 35 | } 36 | } 37 | 38 | if (keyword !== "") { 39 | $(".contents").unmark({ 40 | done: function() { 41 | $(".contents").mark(keyword); 42 | } 43 | }); 44 | } 45 | } 46 | }; 47 | 48 | mark(); 49 | }); 50 | }); 51 | 52 | /* Search term highlighting ------------------------------*/ 53 | 54 | function matchedWords(hit) { 55 | var words = []; 56 | 57 | var hierarchy = hit._highlightResult.hierarchy; 58 | // loop to fetch from lvl0, lvl1, etc. 59 | for (var idx in hierarchy) { 60 | words = words.concat(hierarchy[idx].matchedWords); 61 | } 62 | 63 | var content = hit._highlightResult.content; 64 | if (content) { 65 | words = words.concat(content.matchedWords); 66 | } 67 | 68 | // return unique words 69 | var words_uniq = [...new Set(words)]; 70 | return words_uniq; 71 | } 72 | 73 | function updateHitURL(hit) { 74 | 75 | var words = matchedWords(hit); 76 | var url = ""; 77 | 78 | if (hit.anchor) { 79 | url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor; 80 | } else { 81 | url = hit.url + '?q=' + escape(words.join(" ")); 82 | } 83 | 84 | return url; 85 | } 86 | -------------------------------------------------------------------------------- /R/data.R: -------------------------------------------------------------------------------- 1 | #' CETESB AQS station latitude and longitude 2 | #' 3 | #' List of CETESB QUALAR air quality stations (AQS) latitudes and longitudes. 4 | #' Use this to check the AQS \code{aqs_code} argument in CetesbRetrieveParam() 5 | #' function. AQS names are without diacritics. 6 | #' 7 | #' @format A data frame with 74 observations and 5 variables: 8 | #' \describe{ 9 | #' \item{name}{CETESB AQS name.} 10 | #' \item{code}{CETESB AQS code in QUALAR System.} 11 | #' \item{lat}{CETESB AQS latitude.} 12 | #' \item{lon}{CETESB AQS longitude.} 13 | #' \item{loc}{CETESB AQS location.} 14 | #' } 15 | #' @examples 16 | #' cetesb_aqs 17 | "cetesb_aqs" 18 | 19 | #' CETESB Parameters 20 | #' 21 | #' List of CETESB QUALAR available parameters and units. Use this to check the 22 | #' \code{parameters} argument. 23 | #' Parameter names are without diacritics. 24 | #' 25 | #' @format A data frame with 20 observations and 3 variables: 26 | #' \describe{ 27 | #' \item{name}{CETESB QUALAR parameter abbreviation and name.} 28 | #' \item{units}{Parameter units.} 29 | #' \item{code}{Parameter CETESB QUALAR code.} 30 | #' } 31 | #' @examples 32 | #' cetesb_param 33 | "cetesb_param" 34 | 35 | #' Monitor Ar AQS stations. 36 | #' 37 | #' List of Monitor Ar Rio air quality stations (AQS) with their codes 38 | #' and locations. Use this to check the parameters argument in 39 | #' MonitorArRetrieveParam() function. 40 | #' 41 | #' @format A data frame with 8 observation and 6 variables: 42 | #' \describe{ 43 | #' \item{name}{MonitorAr Program AQS name.} 44 | #' \item{code}{MonitorAr Program AQS abbreviation.} 45 | #' \item{lon}{MonitorAr Program AQS longitude.} 46 | #' \item{lat}{MonitorAr Program AQS latitude.} 47 | #' \item{x_utm_sirgas2000}{MonitorAr Program AQS longitude in SIRGAS 2000 48 | #' (EPSG:31983).} 49 | #' \item{y_utm_sirgas2000}{MonitorAr Program AQS latitude in SIRGAS 2000 50 | #' (EPSG:31983).} 51 | #' } 52 | #' @examples 53 | #' monitor_ar_aqs 54 | "monitor_ar_aqs" 55 | 56 | #' Monitor Ar Parameters 57 | #' 58 | #' List of Monitor Ar Rio available parameters. Use this to check the 59 | #' parameters argument in MonitorArRetrieveParam() function. 60 | #' Parameter names are without diacritics. 61 | #' 62 | #' @format A data frame with 18 observations and 3 variables: 63 | #' \describe{ 64 | #' \item{code}{MonitorAr parameter abbreviation or code.} 65 | #' \item{name}{MonitorAr parameter name} 66 | #' \item{units}{Parameter units.} 67 | #' } 68 | #' @examples 69 | #' monitor_ar_param 70 | "monitor_ar_param" 71 | -------------------------------------------------------------------------------- /R/monitor_ar_retrieve_pol.R: -------------------------------------------------------------------------------- 1 | #' Download criteria pollutants from Monitor Ar program 2 | #' 3 | #' This function download the criteria pollutants from 4 | #' one air quality station (AQS) of Monitor Ar Program. 5 | #' It will pad out the date with missing data with NA. 6 | #' 7 | #' @param start_date Date to start downloading in dd/mm/yyyy. 8 | #' @param end_date Date to end downloading in dd/mm/yyyy. 9 | #' @param aqs_code Code of AQS. 10 | #' @param verbose Print query summary. 11 | #' @param to_local Date information in local time. TRUE by default. 12 | #' @param to_csv Creates a csv file. FALSE by default. 13 | #' @param csv_path Path to save the csv file. 14 | #' 15 | #' @return data.frame with O3, NO, NO2, NOx, PM2.5, PM10 and CO 16 | #' information. 17 | #' @export 18 | #' 19 | #' @examples 20 | #' \dontrun{ 21 | #' # Downloading criteria pollutants from CENTRO AQS 22 | #' # from January first to 7th of 2020 23 | #' start_date <- "01/01/2020" 24 | #' end_date <- "07/01/2020" 25 | #' ca_pol <- monitor_ar_retrieve_pol(start_date, end_date, "CA") 26 | #' } 27 | monitor_ar_retrieve_pol <- function(start_date, end_date, aqs_code, 28 | verbose = TRUE, to_local = TRUE, 29 | to_csv = FALSE, csv_path = ""){ 30 | # Check is aqs_code is valid 31 | if (!(aqs_code %in% aqs_monitor_ar$code)){ 32 | stop("Wrong aqs_code, please check monitor_ar_aqs", call. = FALSE) # nocov 33 | } 34 | 35 | params <- c("O3", "NO", "NO2", "NOx", "CO", "PM10", "PM2_5") 36 | 37 | # Adding query summary 38 | aqs_name <- aqs_monitor_ar$name[aqs_monitor_ar$code == aqs_code] 39 | 40 | if (verbose){ 41 | message("Your query is:") 42 | message("Parameter: ", paste(params, collapse = ", ")) 43 | message("Air quality station: ", aqs_name) 44 | message("Period: From ", start_date, " to ", end_date) 45 | } 46 | 47 | all_pol <- monitor_ar_retrieve_param(start_date, end_date, aqs_code, 48 | params, to_local = to_local, 49 | verbose = FALSE) 50 | 51 | names(all_pol) <- c("date", tolower(params), "aqs") 52 | names(all_pol)[8] <- "pm25" 53 | 54 | # Ensure columns as numeric 55 | cols_unchange <- !(colnames(all_pol) %in% c("date", "aqs")) 56 | all_pol[, cols_unchange] <- sapply(all_pol[, cols_unchange], as.numeric) 57 | 58 | if (to_csv){ 59 | write_csv(all_pol, aqs_name, start_date, end_date, "POL", csv_path) # nocov 60 | } 61 | 62 | return(all_pol) 63 | } 64 | -------------------------------------------------------------------------------- /R/monitor_ar_retrieve_met.R: -------------------------------------------------------------------------------- 1 | #' Download meteorological parameters from Monitor Ar program 2 | #' 3 | #' This function download the main meteorological parameters from one 4 | #' air quality station (AQS) of Monitor Ar network. It will 5 | #' pad out the date with missing data with NA. 6 | #' 7 | #' @param start_date Date to start downloading in dd/mm/yyyy. 8 | #' @param end_date Date to end downloading in dd/mm/yyyy. 9 | #' @param aqs_code Code of AQS. See `monitor_ar_aqs`. 10 | #' @param verbose Print query summary. 11 | #' @param to_local Date information in local time. TRUE by default. 12 | #' @param to_csv Create a csv file. FALSE by default. 13 | #' @param csv_path Path to save the csv file. 14 | #' 15 | #' @return data.frame with Temperature (c), Relative Humidity (%), 16 | #' Wind speed (m/s) and direction (degrees) and Pressure information. 17 | #' @export 18 | #' 19 | #' @examples 20 | #' \dontrun{ 21 | #' # Downloading meteorological data from CENTRO AQS 22 | #' # from January first to 7th of 2020 23 | #' start_date <- "01/01/2020" 24 | #' end_date <- "07/01/2020" 25 | #' ca_met <- monitor_ar_retrieve_met(start_date, end_date, "CA") 26 | #' } 27 | monitor_ar_retrieve_met <- function(start_date, end_date, aqs_code, 28 | verbose = TRUE, to_local = TRUE, 29 | to_csv = FALSE, csv_path = ""){ 30 | # Check is aqs_code is valid 31 | if (!(aqs_code %in% aqs_monitor_ar$code)){ 32 | stop("Wrong aqs_code, please check monitor_ar_aqs", call. = FALSE) # nocov 33 | } 34 | 35 | params <- c("Temp", "UR", "Vel_Vento", "Dir_Vento", "Pres") 36 | 37 | # Adding query summary 38 | aqs_name <- aqs_monitor_ar$name[aqs_monitor_ar$code == aqs_code] 39 | 40 | if (verbose){ 41 | message("Your query is:") 42 | message("Parameter: ", paste(params, collapse = ", ")) 43 | message("Air quality station: ", aqs_name) 44 | message("Period: From ", start_date, " to ", end_date) 45 | } 46 | 47 | all_met <- monitor_ar_retrieve_param(start_date, end_date, aqs_code, 48 | params, to_local = to_local, 49 | verbose = FALSE) 50 | 51 | names(all_met) <- c("date", "tc", "rh", "ws", "wd", "p", "aqs") 52 | 53 | cols_unchage <- -c(1, ncol(all_met)) 54 | all_met[, cols_unchage] <- sapply(all_met[, cols_unchage], as.numeric) 55 | 56 | if (to_csv){ 57 | write_csv(all_met, aqs_name, start_date, end_date, "MET", csv_path) # nocov 58 | } 59 | 60 | return(all_met) 61 | } 62 | -------------------------------------------------------------------------------- /R/monitor_ar_retrieve_met_pol.R: -------------------------------------------------------------------------------- 1 | #' Download meteorological and pollutant data from Monitor Ar Program 2 | #' 3 | #' This function download the main meteorological parameters for model 4 | #' evaluation, together with criteria pollutants for in air quality station 5 | #' (AQS) of Monitor Ar program. 6 | #' It will pad out the date with missing data with NA 7 | #' 8 | #' @param start_date Date to start downloading dd/mm/yyyy 9 | #' @param end_date Date to end downloading dd/mm/yyyy 10 | #' @param aqs_code Code of AQS 11 | #' @param verbose Print query summary 12 | #' @param to_local Date information in local time. TRUE by default. 13 | #' @param to_csv Creates a csv file. FALSE by default. 14 | #' @param csv_path Path to save the csv file. 15 | #' 16 | #' @return data.frame with Temperature (C), Relative Humidity (%), 17 | #' Wind Speed (m/s) and Direction (degrees), Pressure information (hPa), 18 | #' O3, NO, NO2, NOx, PM2.5, PM10 and CO information. 19 | #' @export 20 | #' 21 | #' @examples 22 | #' \dontrun{ 23 | #' # Downloading main meteorological parameters and criteria pollutant 24 | #' # from CENTRO AQS from January first to 7th of 2020 25 | #' start_date <- "01/01/2020" 26 | #' end_date <- "07/01/2020" 27 | #' ca_all <- monitor_ar_retrieve_met_pol(start_date, end_date, "CA") 28 | #' } 29 | monitor_ar_retrieve_met_pol <- function(start_date, end_date, aqs_code, 30 | verbose = TRUE, to_local = TRUE, 31 | to_csv = FALSE, csv_path = ""){ 32 | # Check is aqs_code is valid 33 | if (!(aqs_code %in% aqs_monitor_ar$code)){ 34 | stop("Wrong aqs_code, please check monitor_ar_aqs", call. = FALSE) # nocov 35 | } 36 | 37 | params <- c("Temp", "UR", "Vel_Vento", "Dir_Vento", "Pres", 38 | "O3", "NO", "NO2", "NOx", "CO", "PM10", "PM2_5") 39 | 40 | # Adding query summary 41 | aqs_name <- aqs_monitor_ar$name[aqs_monitor_ar$code == aqs_code] 42 | 43 | if (verbose){ 44 | message("Your query is: ") 45 | message("Parameter: ", paste(params, collapse = ", ")) 46 | message("Air quality station: ", aqs_name) 47 | message("Period: From ", start_date, " to ", end_date) 48 | } 49 | 50 | all_data <- monitor_ar_retrieve_param(start_date, end_date, aqs_code, 51 | params, to_local = to_local, 52 | verbose = FALSE) 53 | 54 | names(all_data) <- c("date", tolower(params), "aqs") 55 | names(all_data)[2:6] <- c("tc", "rh", "ws", "wd", "p") 56 | names(all_data)[13] <- "pm25" 57 | 58 | cols_unchange <- -c(1, ncol(all_data)) 59 | all_data[, cols_unchange] <- sapply(all_data[, cols_unchange], 60 | as.numeric) 61 | 62 | if (to_csv){ # nocov start 63 | write_csv(all_data, aqs_name, start_date, end_date, "MET_POL", csv_path) 64 | } # nocov end 65 | 66 | return(all_data) 67 | } 68 | -------------------------------------------------------------------------------- /R/cetesb_retrieve_met.R: -------------------------------------------------------------------------------- 1 | #' Download meteorological parameters from CETESB QUALAR 2 | #' 3 | #' This function download the main meteorological parameters for 4 | #' model evaluation from one air quality station (AQS) of CETESB AQS network. 5 | #' It will pad out the date with missing data with NA. 6 | #' This function requires to have 7 | #' \href{https://seguranca.cetesb.sp.gov.br/Home/CadastrarUsuario}{an account} 8 | #' in \href{https://qualar.cetesb.sp.gov.br/qualar/home.do}{CETESB QUALAR}. 9 | #' 10 | #' @param username User name of CETESB QUALAR 11 | #' @param password User name's password of CETESB QUALAR 12 | #' @param aqs_code Code of AQS 13 | #' @param start_date Date to start downloading in dd/mm/yyyy 14 | #' @param end_date Date to end downloading in dd/mm/yyyy 15 | #' @param verbose Print query summary 16 | #' @param to_csv Creates a csv file. FALSE by default 17 | #' @param csv_path Path to save the csv file. 18 | #' 19 | #' @return data.frame with Temperature (C), Relative Humidity (%), 20 | #' Wind Speed (m/s) and Direction (degrees), and Pressure information. 21 | #' @export 22 | #' 23 | #' @examples 24 | #' \dontrun{ 25 | #' # Downloading meteorological data from Pinheiros AQS 26 | #' # from January first to 7th of 2020 27 | #' my_user_name <- "John Doe" 28 | #' my_pass_word <- "drowssap" 29 | #' pin_code <- 99 # Check with cetesb_aqs 30 | #' start_date <- "01/01/2020" 31 | #' end_date <- "07/01/2020" 32 | #' 33 | #' pin_pol <- cetesb_retrieve_met(my_user_name, my_pass_word, pin_code, 34 | #' start_date, end_date) 35 | #' } 36 | cetesb_retrieve_met <- function(username, password, 37 | aqs_code, start_date, 38 | end_date, verbose = TRUE, 39 | to_csv = FALSE, csv_path = ""){ 40 | 41 | # Check if aqs_code is valid 42 | aqs <- cetesb 43 | check_code <- check_cetesb_code(aqs, aqs_code) 44 | aqs_name <- check_code[1] 45 | aqs_code <- as.numeric(check_code[2]) 46 | 47 | # Adding query summary 48 | if (verbose){ 49 | message("Your query is:") 50 | message("Parameter: TC, RH, WS, WD, Pressure") 51 | message("Air quality station: ", aqs_name) 52 | message("Period: From ", start_date, " to ", end_date) 53 | } 54 | 55 | tc <- cetesb_retrieve(username, password, 25, 56 | aqs_code, start_date, 57 | end_date, verbose = FALSE) 58 | 59 | rh <- cetesb_retrieve(username, password, 28, 60 | aqs_code, start_date, 61 | end_date, verbose = FALSE) 62 | 63 | ws <- cetesb_retrieve(username, password, 24, 64 | aqs_code, start_date, 65 | end_date, verbose = FALSE) 66 | 67 | wd <- cetesb_retrieve(username, password, 23, 68 | aqs_code, start_date, 69 | end_date, verbose = FALSE) 70 | 71 | p <- cetesb_retrieve(username, password, 29, 72 | aqs_code, start_date, 73 | end_date, verbose = FALSE) 74 | 75 | all_met <- data.frame(date = tc$date, 76 | tc = tc$pol, 77 | rh = rh$pol, 78 | ws = ws$pol, 79 | wd = wd$pol, 80 | p = p$pol, 81 | aqs = tc$aqs, 82 | stringsAsFactors = FALSE) 83 | 84 | cols_unchange <- -c(1, ncol(all_met)) 85 | all_met[, cols_unchange] <- sapply(all_met[, cols_unchange], as.numeric) 86 | 87 | message(paste( 88 | "Download complete for", unique(all_met$aqs) 89 | )) 90 | 91 | if (to_csv){ 92 | write_csv(all_met, aqs_name, start_date, end_date, "MET", csv_path) # nocov 93 | } 94 | 95 | return(all_met) 96 | } 97 | -------------------------------------------------------------------------------- /R/cetesb_retrieve_pol.R: -------------------------------------------------------------------------------- 1 | #' Download criteria pollutants from CETESB QUALAR 2 | #' 3 | #' This function download the criteria pollutants from one air quality station 4 | #' (AQS) of CETESB AQS network. 5 | #' It will pad out the date with missing data with NA. 6 | #' This function required to have 7 | #' \href{https://seguranca.cetesb.sp.gov.br/Home/CadastrarUsuario}{an account} 8 | #' in \href{https://qualar.cetesb.sp.gov.br/qualar/home.do}{CETESB QUALAR}. 9 | #' 10 | #' @param username User name of CETESB QUALAR 11 | #' @param password User name's password of CETESB QUALAR 12 | #' @param aqs_code Code of AQS 13 | #' @param start_date Date to start downloading in dd/mm/yyyy 14 | #' @param end_date Date to end downloading in dd/mm/yyyy 15 | #' @param verbose Print query summary 16 | #' @param to_csv Creates a csv file. FALSE by default 17 | #' @param csv_path Path to save the csv file 18 | #' 19 | #' @return data.frame with O3, NO, NO2, PM2.5, PM10 and CO information. 20 | #' Units are ug/m3 except for CO which is in ppm, and NOx which is in ppb. 21 | #' @export 22 | #' 23 | #' @examples 24 | #' \dontrun{ 25 | #' # Downloading criteria pollutants from Pinheiros AQS 26 | #' # from January first to 7th of 2020 27 | #' my_user_name <- "John Doe" 28 | #' my_pass_word <- "drowssap" 29 | #' pin_code <- 99 # Check with cetesb_aqs 30 | #' start_date <- "01/01/2020" 31 | #' end_date <- "07/01/2020" 32 | #' 33 | #' pin_pol <- cetesb_retrieve_pol(my_user_name, my_pass_word, pin_code, 34 | #' start_date, end_date) 35 | #' 36 | #' } 37 | cetesb_retrieve_pol <- function(username, password, 38 | aqs_code, start_date, 39 | end_date, verbose = TRUE, 40 | to_csv = FALSE, csv_path = ""){ 41 | 42 | # Check if aqs_code is valid 43 | aqs <- cetesb 44 | check_code <- check_cetesb_code(aqs, aqs_code) 45 | aqs_name <- check_code[1] 46 | aqs_code <- as.numeric(check_code[2]) 47 | 48 | # Adding query summary 49 | if (verbose){ 50 | message("Your query is:") 51 | message("Parameter: O3, NO, NO2, NOX, MP2.5, MP10, CO") 52 | message("Air quality station: ", aqs_name) 53 | message("Period: From ", start_date, " to ", end_date) 54 | } 55 | 56 | o3 <- cetesb_retrieve(username, password, 63, 57 | aqs_code, start_date, 58 | end_date, verbose = FALSE) 59 | 60 | no <- cetesb_retrieve(username, password, 17, 61 | aqs_code, start_date, 62 | end_date, verbose = FALSE) 63 | 64 | no2 <- cetesb_retrieve(username, password, 15, 65 | aqs_code, start_date, 66 | end_date, verbose = FALSE) 67 | 68 | nox <- cetesb_retrieve(username, password, 18, 69 | aqs_code, start_date, 70 | end_date, verbose = FALSE) 71 | 72 | pm25 <- cetesb_retrieve(username, password, 57, 73 | aqs_code, start_date, 74 | end_date, verbose = FALSE) 75 | 76 | pm10 <- cetesb_retrieve(username, password, 12, 77 | aqs_code, start_date, 78 | end_date, verbose = FALSE) 79 | 80 | co <- cetesb_retrieve(username, password, 16, 81 | aqs_code, start_date, 82 | end_date, verbose = FALSE) 83 | 84 | 85 | all_pol <- data.frame(date = o3$date, 86 | o3 = o3$pol, 87 | no = no$pol, 88 | no2 = no2$pol, 89 | nox = nox$pol, 90 | co = co$pol, 91 | pm10 = pm10$pol, 92 | pm25 = pm25$pol, 93 | aqs = o3$aqs, 94 | stringsAsFactors = FALSE) 95 | 96 | cols_unchange <- -c(1, ncol(all_pol)) 97 | all_pol[, cols_unchange] <- sapply(all_pol[, cols_unchange], as.numeric) 98 | 99 | message(paste( 100 | "Download complete for", unique(all_pol$aqs) 101 | )) 102 | 103 | if (to_csv){ 104 | write_csv(all_pol, aqs_name, start_date, end_date, "POL", csv_path) # nocov 105 | } 106 | 107 | return(all_pol) 108 | } 109 | -------------------------------------------------------------------------------- /data-raw/cetesb_aqs.dat: -------------------------------------------------------------------------------- 1 | "name","code","lat","lon","loc" 2 | "Americana",290,-22.7242526995067,-47.3395492909725,"Interior" 3 | "Araçatuba",107,-21.1868410998752,-50.4393168498844,"Interior" 4 | "Araraquara",106,-21.7825221457448,-48.1858318132219,"Interior" 5 | "Bauru",108,-22.326608396587,-49.092759305391,"Interior" 6 | "Cambuci",90,-23.5677084050662,-46.6122728561358,NA 7 | "Campinas-Centro",89,-22.9025248038637,-47.0572107427735,"Interior" 8 | "Campinas-Taquaral",276,-22.8746189449543,-47.0589727566842,"Interior" 9 | "Campinas-V.União",275,-22.9467284160848,-47.1192808618633,"Interior" 10 | "Capão Redondo",269,-23.6683561456718,-46.7800433836767,"São Paulo" 11 | "Carapicuíba",263,-23.5313950283077,-46.8357797276639,"MASP" 12 | "Catanduva",248,-21.1419427576013,-48.9830752705603,"Interior" 13 | "Centro",94,-23.5478061597037,-46.6424144996321,NA 14 | "Cerqueira César",91,-23.5535425616777,-46.6727047692529,"São Paulo" 15 | "Cid.Universitária-USP-Ipen",95,-23.5663417755292,-46.7374142819519,"São Paulo" 16 | "Congonhas",73,-23.6163200788182,-46.6634655273702,"São Paulo" 17 | "Cubatão-Centro",87,-23.8790267306876,-46.418483361896,"Coast" 18 | "Cubatão-V.Parisi",66,-23.8494161699591,-46.3886762431427,"Coast" 19 | "Cubatão-Vale do Mogi",119,-23.8315890081254,-46.3695687908739,"Coast" 20 | "Diadema",92,-23.6858764117137,-46.6116219323751,"MASP" 21 | "Grajaú-Parelheiros",98,-23.776265984399,-46.6969610783657,"São Paulo" 22 | "Guaratinguetá",289,-22.8019171385919,-45.1911223603662,"Interior" 23 | "Guarulhos",118,-23.4632093829649,-46.4962135994365,"MASP" 24 | "Guarulhos-Paço Municipal",264,-23.4555342581023,-46.5185334030574,"MASP" 25 | "Guarulhos-Pimentas",279,-23.4401170078091,-46.4099487710006,"MASP" 26 | "Ibirapuera",83,-23.5918419901379,-46.6606875025418,"São Paulo" 27 | "Interlagos",262,-23.6805076511499,-46.6750431583082,"São Paulo" 28 | "Itaim Paulista",266,-23.5015473609702,-46.4207368394923,"São Paulo" 29 | "Itaquera",97,-23.5800148313619,-46.4666514114578,"São Paulo" 30 | "Jacareí",259,-23.2941992435412,-45.9682338642508,"Interior" 31 | "Jaú",110,-22.2986196635248,-48.5674574048007,"Interior" 32 | "Jundiaí",109,-23.192003743039,-46.8970972725384,"Interior" 33 | "Limeira",281,-22.5636037767457,-47.4143140341751,"Interior" 34 | "Marg.Tietê-Pte Remédios",270,-23.5187058310122,-46.7433200408467,"São Paulo" 35 | "Marília",111,-22.1998094871228,-49.9599697461499,"Interior" 36 | "Mauá",65,-23.6685489997822,-46.4660002742069,"MASP" 37 | "Mogi das Cruzes",287,-23.518172230148,-46.1868605711067,NA 38 | "Mooca",85,-23.5497340450694,-46.6004166453369,"São Paulo" 39 | "N.Senhora do Ó",96,-23.4800987059504,-46.6920519221288,"São Paulo" 40 | "Osasco",120,-23.5267214190038,-46.7920776611899,"MASP" 41 | "Parque D.Pedro II",72,-23.5448456586808,-46.6276755923666,"São Paulo" 42 | "Paulínia",117,-22.772321379337,-47.1548428657284,"Interior" 43 | "Paulínia Sul",112,-22.7868064343791,-47.1365588816311,"Interior" 44 | "Pico do Jaraguá",284,-23.4562688997476,-46.7660977590058,"São Paulo" 45 | "Pinheiros",99,-23.5614598947311,-46.7020165084763,"São Paulo" 46 | "Piracicaba",113,-22.7012223402754,-47.6496526898721,"Interior" 47 | "Pirassununga-EM",268,-22.0077128811569,-47.4275644904649,NA 48 | "Presidente Prudente",114,-22.1199367347659,-51.4087770680215,NA 49 | "Ribeirão Preto",288,-21.1539418919679,-47.828480526621,"Interior" 50 | "Ribeirão Preto-Ipiranga",115,-21.15394,-47.82848,"Interior" 51 | "S.André Capuava",100,-23.6398036991568,-46.4916367657882,"MASP" 52 | "S.André-Centro",101,-23.6456163828539,-46.5363346692648,"MASP" 53 | "S.André-Paço Municipal",254,-23.6569941995448,-46.5309187564731,NA 54 | "S.Bernardo-Centro",272,-23.6986710864522,-46.5462321867186,"MASP" 55 | "S.Bernardo-Paulicéia",102,-23.6713539571073,-46.5846678858857,"MASP" 56 | "S.José Campos",88,-23.1878873302518,-45.8711976230777,"Interior" 57 | "S.José Campos-Jd.Satélite",277,-23.2236454817019,-45.8907999962971,"Interior" 58 | "S.José Campos-Vista Verde",278,-23.1836973451392,-45.8308969846329,"Interior" 59 | "S.Miguel Paulista",236,-23.4985264108007,-46.4448027795288,NA 60 | "Santa Gertrudes",273,-22.4599552691691,-47.5362983394974,"Interior" 61 | "Santana",63,-23.5059927222475,-46.6289602999862,"São Paulo" 62 | "Santo Amaro",64,-23.6549772296114,-46.7099983817602,"São Paulo" 63 | "Santos",258,-23.9630572042475,-46.3211700936539,"Coast" 64 | "Santos-Ponta da Praia",260,-23.9812951573645,-46.3005095935412,"Coast" 65 | "São Caetano do Sul",86,-23.6184427729695,-46.5563539375078,"MASP" 66 | "São José Do Rio Preto",116,-20.7846892839301,-49.3982777928726,"Interior" 67 | "Sorocaba",67,-23.5024265843066,-47.4790299116269,"Interior" 68 | "Taboão da Serra",103,-23.6093238641752,-46.7582943678197,"MASP" 69 | "Tatuí",256,-23.3607515378568,-47.8707990664729,"Interior" 70 | "Taubaté",280,-23.0323509589424,-45.5758050249834,"Interior" 71 | -------------------------------------------------------------------------------- /docs/pkgdown.js: -------------------------------------------------------------------------------- 1 | /* http://gregfranko.com/blog/jquery-best-practices/ */ 2 | (function($) { 3 | $(function() { 4 | 5 | $('nav.navbar').headroom(); 6 | 7 | Toc.init({ 8 | $nav: $("#toc"), 9 | $scope: $("main h2, main h3, main h4, main h5, main h6") 10 | }); 11 | 12 | if ($('#toc').length) { 13 | $('body').scrollspy({ 14 | target: '#toc', 15 | offset: $("nav.navbar").outerHeight() + 1 16 | }); 17 | } 18 | 19 | // Activate popovers 20 | $('[data-bs-toggle="popover"]').popover({ 21 | container: 'body', 22 | html: true, 23 | trigger: 'focus', 24 | placement: "top", 25 | sanitize: false, 26 | }); 27 | 28 | $('[data-bs-toggle="tooltip"]').tooltip(); 29 | 30 | /* Clipboard --------------------------*/ 31 | 32 | function changeTooltipMessage(element, msg) { 33 | var tooltipOriginalTitle=element.getAttribute('data-original-title'); 34 | element.setAttribute('data-original-title', msg); 35 | $(element).tooltip('show'); 36 | element.setAttribute('data-original-title', tooltipOriginalTitle); 37 | } 38 | 39 | if(ClipboardJS.isSupported()) { 40 | $(document).ready(function() { 41 | var copyButton = ""; 42 | 43 | $("div.sourceCode").addClass("hasCopyButton"); 44 | 45 | // Insert copy buttons: 46 | $(copyButton).prependTo(".hasCopyButton"); 47 | 48 | // Initialize tooltips: 49 | $('.btn-copy-ex').tooltip({container: 'body'}); 50 | 51 | // Initialize clipboard: 52 | var clipboard = new ClipboardJS('[data-clipboard-copy]', { 53 | text: function(trigger) { 54 | return trigger.parentNode.textContent.replace(/\n#>[^\n]*/g, ""); 55 | } 56 | }); 57 | 58 | clipboard.on('success', function(e) { 59 | changeTooltipMessage(e.trigger, 'Copied!'); 60 | e.clearSelection(); 61 | }); 62 | 63 | clipboard.on('error', function() { 64 | changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy'); 65 | }); 66 | 67 | }); 68 | } 69 | 70 | /* Search marking --------------------------*/ 71 | var url = new URL(window.location.href); 72 | var toMark = url.searchParams.get("q"); 73 | var mark = new Mark("main#main"); 74 | if (toMark) { 75 | mark.mark(toMark, { 76 | accuracy: { 77 | value: "complementary", 78 | limiters: [",", ".", ":", "/"], 79 | } 80 | }); 81 | } 82 | 83 | /* Search --------------------------*/ 84 | /* Adapted from https://github.com/rstudio/bookdown/blob/2d692ba4b61f1e466c92e78fd712b0ab08c11d31/inst/resources/bs4_book/bs4_book.js#L25 */ 85 | // Initialise search index on focus 86 | var fuse; 87 | $("#search-input").focus(async function(e) { 88 | if (fuse) { 89 | return; 90 | } 91 | 92 | $(e.target).addClass("loading"); 93 | var response = await fetch($("#search-input").data("search-index")); 94 | var data = await response.json(); 95 | 96 | var options = { 97 | keys: ["what", "text", "code"], 98 | ignoreLocation: true, 99 | threshold: 0.1, 100 | includeMatches: true, 101 | includeScore: true, 102 | }; 103 | fuse = new Fuse(data, options); 104 | 105 | $(e.target).removeClass("loading"); 106 | }); 107 | 108 | // Use algolia autocomplete 109 | var options = { 110 | autoselect: true, 111 | debug: true, 112 | hint: false, 113 | minLength: 2, 114 | }; 115 | var q; 116 | async function searchFuse(query, callback) { 117 | await fuse; 118 | 119 | var items; 120 | if (!fuse) { 121 | items = []; 122 | } else { 123 | q = query; 124 | var results = fuse.search(query, { limit: 20 }); 125 | items = results 126 | .filter((x) => x.score <= 0.75) 127 | .map((x) => x.item); 128 | if (items.length === 0) { 129 | items = [{dir:"Sorry 😿",previous_headings:"",title:"No results found.",what:"No results found.",path:window.location.href}]; 130 | } 131 | } 132 | callback(items); 133 | } 134 | $("#search-input").autocomplete(options, [ 135 | { 136 | name: "content", 137 | source: searchFuse, 138 | templates: { 139 | suggestion: (s) => { 140 | if (s.title == s.what) { 141 | return `${s.dir} >
${s.title}
`; 142 | } else if (s.previous_headings == "") { 143 | return `${s.dir} >
${s.title}
> ${s.what}`; 144 | } else { 145 | return `${s.dir} >
${s.title}
> ${s.previous_headings} > ${s.what}`; 146 | } 147 | }, 148 | }, 149 | }, 150 | ]).on('autocomplete:selected', function(event, s) { 151 | window.location.href = s.path + "?q=" + q + "#" + s.id; 152 | }); 153 | }); 154 | })(window.jQuery || window.$) 155 | 156 | 157 | -------------------------------------------------------------------------------- /R/cetesb_retrieve_param.R: -------------------------------------------------------------------------------- 1 | #' Download list of observation from CETESB QUALAR 2 | #' 3 | #' This function downloads the parameters in a vector. These parameters 4 | #' can be both pollutants or meteorological observations for one air 5 | #' quality station (AQS). It will pad out the date with missing data 6 | #' with NA. This function requires to have 7 | #' \href{https://seguranca.cetesb.sp.gov.br/Home/CadastrarUsuario}{an account} 8 | #' in \href{https://qualar.cetesb.sp.gov.br/qualar/home.do}{CETESB QUALAR}. 9 | #' 10 | #' @param username User name of CETESB QUALAR 11 | #' @param password User name's password of CETESB QUALAR 12 | #' @param parameters a character vector with the parameters abbreviations 13 | #' to download 14 | #' @param aqs_code Code of AQS 15 | #' @param start_date Date to start downloading in dd/mm/yyyy 16 | #' @param end_date Date to end downloading in dd/mm/yyyy 17 | #' @param verbose Print query summary 18 | #' @param to_csv Creates a csv file. FALSE by default 19 | #' @param csv_path Path to save the csv file 20 | #' 21 | #' @return data.frame with parameters described in `params` vector 22 | #' @export 23 | #' 24 | #' @examples 25 | #' \dontrun{ 26 | #' # Download ozone, nitrogen dioxide, and wind speed 27 | #' # from Pinheiros AQS, from January first to 7th of 2020 28 | #' 29 | #' my_user_name <- "John Doe" 30 | #' my_pass_word <- "drowssap" 31 | #' pin_code <- 99 # Check with cetesb_aqs 32 | #' start_date <- "01/01/2020" 33 | #' end_date <- "07/01/2020" 34 | #' params <- c("o3","NOX", "VV") 35 | #' 36 | #' pin_param <- cetesb_retrieve_param(my_user_name, my_pass_word, 37 | #' params, pin_code, 38 | #' start_date, end_date) 39 | #' } 40 | cetesb_retrieve_param <- function(username, password, parameters, 41 | aqs_code, start_date, end_date, 42 | verbose = TRUE, to_csv = FALSE, 43 | csv_path = ""){ 44 | 45 | # Check if aqs_code is valid 46 | aqs <- cetesb 47 | check_code <- check_cetesb_code(aqs, aqs_code) 48 | aqs_name <- check_code[1] 49 | aqs_code <- as.numeric(check_code[2]) 50 | 51 | # Check parameters code 52 | param <- toupper(parameters) 53 | all_params <- c(params_code$name, params_code$code) 54 | param_exist <- param %in% all_params 55 | 56 | if (FALSE %in% param_exist){ 57 | stop(paste(paste(param[!param_exist], collapse = ", "), # nocov 58 | "are wrong parameters, please check cetesb_param"), # nocov 59 | call. = FALSE) # nocov 60 | } else { 61 | codes_df <- params_code[params_code$name %in% param, ] 62 | if (nrow(codes_df) != length(param)){ 63 | codesd_df2 <- params_code[params_code$code %in% param, ] # nocov 64 | codes_df <- rbind(codes_df, codesd_df2) # nocov 65 | codes_df <- unique(codes_df) # nocov 66 | } 67 | } 68 | 69 | 70 | # Adding query summary 71 | if (verbose){ 72 | message("Your query is:") 73 | message("Parameter: ", paste(codes_df$name, collapse = ", ")) 74 | message("Air quality station: ", aqs_name) 75 | message("Period: From ", start_date, " to ", end_date) 76 | } 77 | 78 | # Downloading data 79 | aqs_data <- lapply(codes_df$code, cetesb_retrieve, 80 | username = username, 81 | password = password, 82 | aqs_code = aqs_code, 83 | start_date = start_date, 84 | end_date = end_date, 85 | verbose = FALSE) 86 | 87 | for (i in seq(length(aqs_data))){ 88 | names(aqs_data[[i]]) <- c("date", tolower(codes_df$name[i]), "aqs") 89 | } 90 | 91 | aqs_data_df <- Reduce(merge, aqs_data) 92 | 93 | # Changing wind speed and direction columns to ws and wd 94 | if ("dv" %in% names(aqs_data_df)){ 95 | names(aqs_data_df)[names(aqs_data_df) == "dv"] <- "wd" # nocov 96 | } 97 | if ("vv" %in% names(aqs_data_df)){ 98 | names(aqs_data_df)[names(aqs_data_df) == "vv"] <- "ws" 99 | } 100 | if ("ur" %in% names(aqs_data_df)){ 101 | names(aqs_data_df)[names(aqs_data_df) == "ur"] <- "rh" # nocov 102 | } 103 | if ("temp" %in% names(aqs_data_df)){ 104 | names(aqs_data_df)[names(aqs_data_df) == "temp"] <- "tc" # nocov 105 | } 106 | if ("mp10" %in% names(aqs_data_df)){ 107 | names(aqs_data_df)[names(aqs_data_df) == "mp10"] <- "pm10" # nocov 108 | } 109 | if ("mp2.5" %in% names(aqs_data_df)){ 110 | names(aqs_data_df)[names(aqs_data_df) == "mp2.5"] <- "pm25" # nocov 111 | } 112 | 113 | # Ensure columns as numeric 114 | cols_unchange <- !(colnames(aqs_data_df) %in% c("date", "aqs")) 115 | aqs_data_df[, cols_unchange] <- sapply(aqs_data_df[, cols_unchange], 116 | as.numeric) 117 | 118 | if (to_csv){ # nocov start 119 | write_csv(aqs_data_df, aqs_name, start_date, end_date, param, csv_path) 120 | } # nocov end 121 | 122 | return(aqs_data_df) 123 | } 124 | -------------------------------------------------------------------------------- /codemeta.json: -------------------------------------------------------------------------------- 1 | { 2 | "@context": ["https://doi.org/10.5063/schema/codemeta-2.0", "http://schema.org"], 3 | "@type": "SoftwareSourceCode", 4 | "identifier": "qualR", 5 | "description": "A package to download information from CETESB QUALAR and\n MonitorAr systems. It contains function to download different parameters, a set of\n criteria pollutants and the most frequent meteorological parameters used in\n air quality data analysis and air quality model evaluation.", 6 | "name": "qualR: An R package to download Sao Paulo and Rio de Janeiro air pollution data", 7 | "codeRepository": "https://github.com/quishqa/qualR", 8 | "issueTracker": "https://github.com/quishqa/qualR/issues", 9 | "license": "https://spdx.org/licenses/MIT", 10 | "version": "0.9.5", 11 | "programmingLanguage": { 12 | "@type": "ComputerLanguage", 13 | "name": "R", 14 | "url": "https://r-project.org" 15 | }, 16 | "runtimePlatform": "R version 4.0.3 (2020-10-10)", 17 | "author": [ 18 | { 19 | "@type": "Person", 20 | "givenName": "Mario", 21 | "familyName": "Gavidia-Calderón", 22 | "email": "mario.calderon@iag.usp.br", 23 | "@id": "https://orcid.org/0000-0002-7371-1116" 24 | }, 25 | { 26 | "@type": "Person", 27 | "givenName": "Daniel", 28 | "familyName": "Schuch", 29 | "email": "d.schuch@northeastern.edu", 30 | "@id": "https://orcid.org/0000-0001-5977-4519" 31 | } 32 | ], 33 | "contributor": [ 34 | { 35 | "@type": "Person", 36 | "givenName": "Maria de Fatima", 37 | "familyName": "Andrade", 38 | "email": "maria.andrade@iag.usp.br", 39 | "@id": "https://orcid.org/0000-0001-5351-8311" 40 | }, 41 | { 42 | "@type": "Person", 43 | "givenName": "Daniel", 44 | "familyName": "Schuch", 45 | "email": "d.schuch@northeastern.edu", 46 | "@id": "https://orcid.org/0000-0001-5977-4519" 47 | }, 48 | { 49 | "@type": "Person", 50 | "givenName": "Maria de Fatima", 51 | "familyName": "Andrade", 52 | "email": "maria.andrade@iag.usp.br", 53 | "@id": "https://orcid.org/0000-0001-5351-8311" 54 | } 55 | ], 56 | "copyrightHolder": {}, 57 | "funder": {}, 58 | "maintainer": [ 59 | { 60 | "@type": "Person", 61 | "givenName": "Mario", 62 | "familyName": "Gavidia-Calderón", 63 | "email": "mario.calderon@iag.usp.br", 64 | "@id": "https://orcid.org/0000-0002-7371-1116" 65 | } 66 | ], 67 | "softwareSuggestions": [ 68 | { 69 | "@type": "SoftwareApplication", 70 | "identifier": "covr", 71 | "name": "covr", 72 | "provider": { 73 | "@id": "https://cran.r-project.org", 74 | "@type": "Organization", 75 | "name": "Comprehensive R Archive Network (CRAN)", 76 | "url": "https://cran.r-project.org" 77 | }, 78 | "sameAs": "https://CRAN.R-project.org/package=covr" 79 | }, 80 | { 81 | "@type": "SoftwareApplication", 82 | "identifier": "testthat", 83 | "name": "testthat", 84 | "version": ">= 3.0.0", 85 | "provider": { 86 | "@id": "https://cran.r-project.org", 87 | "@type": "Organization", 88 | "name": "Comprehensive R Archive Network (CRAN)", 89 | "url": "https://cran.r-project.org" 90 | }, 91 | "sameAs": "https://CRAN.R-project.org/package=testthat" 92 | } 93 | ], 94 | "softwareRequirements": [ 95 | { 96 | "@type": "SoftwareApplication", 97 | "identifier": "XML", 98 | "name": "XML", 99 | "provider": { 100 | "@id": "https://cran.r-project.org", 101 | "@type": "Organization", 102 | "name": "Comprehensive R Archive Network (CRAN)", 103 | "url": "https://cran.r-project.org" 104 | }, 105 | "sameAs": "https://CRAN.R-project.org/package=XML" 106 | }, 107 | { 108 | "@type": "SoftwareApplication", 109 | "identifier": "httr", 110 | "name": "httr", 111 | "provider": { 112 | "@id": "https://cran.r-project.org", 113 | "@type": "Organization", 114 | "name": "Comprehensive R Archive Network (CRAN)", 115 | "url": "https://cran.r-project.org" 116 | }, 117 | "sameAs": "https://CRAN.R-project.org/package=httr" 118 | }, 119 | { 120 | "@type": "SoftwareApplication", 121 | "identifier": "jsonlite", 122 | "name": "jsonlite", 123 | "provider": { 124 | "@id": "https://cran.r-project.org", 125 | "@type": "Organization", 126 | "name": "Comprehensive R Archive Network (CRAN)", 127 | "url": "https://cran.r-project.org" 128 | }, 129 | "sameAs": "https://CRAN.R-project.org/package=jsonlite" 130 | }, 131 | { 132 | "@type": "SoftwareApplication", 133 | "identifier": "R", 134 | "name": "R", 135 | "version": ">= 3.5.0" 136 | } 137 | ], 138 | "releaseNotes": "https://github.com/quishqa/qualR/blob/master/NEWS.md", 139 | "readme": "https://github.com/quishqa/qualR/blob/master/README.md", 140 | "fileSize": "80.892KB", 141 | "contIntegration": ["https://travis-ci.com/quishqa/qualR", "https://ci.appveyor.com/project/quishqa/qualR"], 142 | "keywords": ["cetesb", "sao-paulo", "brazil", "air-quality-data", "air-quality-measurements", "rio-de-janeiro", "air-pollutants"] 143 | } 144 | -------------------------------------------------------------------------------- /docs/bootstrap-toc.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | (function() { 6 | 'use strict'; 7 | 8 | window.Toc = { 9 | helpers: { 10 | // return all matching elements in the set, or their descendants 11 | findOrFilter: function($el, selector) { 12 | // http://danielnouri.org/notes/2011/03/14/a-jquery-find-that-also-finds-the-root-element/ 13 | // http://stackoverflow.com/a/12731439/358804 14 | var $descendants = $el.find(selector); 15 | return $el.filter(selector).add($descendants).filter(':not([data-toc-skip])'); 16 | }, 17 | 18 | generateUniqueIdBase: function(el) { 19 | var text = $(el).text(); 20 | var anchor = text.trim().toLowerCase().replace(/[^A-Za-z0-9]+/g, '-'); 21 | return anchor || el.tagName.toLowerCase(); 22 | }, 23 | 24 | generateUniqueId: function(el) { 25 | var anchorBase = this.generateUniqueIdBase(el); 26 | for (var i = 0; ; i++) { 27 | var anchor = anchorBase; 28 | if (i > 0) { 29 | // add suffix 30 | anchor += '-' + i; 31 | } 32 | // check if ID already exists 33 | if (!document.getElementById(anchor)) { 34 | return anchor; 35 | } 36 | } 37 | }, 38 | 39 | generateAnchor: function(el) { 40 | if (el.id) { 41 | return el.id; 42 | } else { 43 | var anchor = this.generateUniqueId(el); 44 | el.id = anchor; 45 | return anchor; 46 | } 47 | }, 48 | 49 | createNavList: function() { 50 | return $(''); 51 | }, 52 | 53 | createChildNavList: function($parent) { 54 | var $childList = this.createNavList(); 55 | $parent.append($childList); 56 | return $childList; 57 | }, 58 | 59 | generateNavEl: function(anchor, text) { 60 | var $a = $('
'); 61 | $a.attr('href', '#' + anchor); 62 | $a.text(text); 63 | var $li = $('
  • '); 64 | $li.append($a); 65 | return $li; 66 | }, 67 | 68 | generateNavItem: function(headingEl) { 69 | var anchor = this.generateAnchor(headingEl); 70 | var $heading = $(headingEl); 71 | var text = $heading.data('toc-text') || $heading.text(); 72 | return this.generateNavEl(anchor, text); 73 | }, 74 | 75 | // Find the first heading level (`

    `, then `

    `, etc.) that has more than one element. Defaults to 1 (for `

    `). 76 | getTopLevel: function($scope) { 77 | for (var i = 1; i <= 6; i++) { 78 | var $headings = this.findOrFilter($scope, 'h' + i); 79 | if ($headings.length > 1) { 80 | return i; 81 | } 82 | } 83 | 84 | return 1; 85 | }, 86 | 87 | // returns the elements for the top level, and the next below it 88 | getHeadings: function($scope, topLevel) { 89 | var topSelector = 'h' + topLevel; 90 | 91 | var secondaryLevel = topLevel + 1; 92 | var secondarySelector = 'h' + secondaryLevel; 93 | 94 | return this.findOrFilter($scope, topSelector + ',' + secondarySelector); 95 | }, 96 | 97 | getNavLevel: function(el) { 98 | return parseInt(el.tagName.charAt(1), 10); 99 | }, 100 | 101 | populateNav: function($topContext, topLevel, $headings) { 102 | var $context = $topContext; 103 | var $prevNav; 104 | 105 | var helpers = this; 106 | $headings.each(function(i, el) { 107 | var $newNav = helpers.generateNavItem(el); 108 | var navLevel = helpers.getNavLevel(el); 109 | 110 | // determine the proper $context 111 | if (navLevel === topLevel) { 112 | // use top level 113 | $context = $topContext; 114 | } else if ($prevNav && $context === $topContext) { 115 | // create a new level of the tree and switch to it 116 | $context = helpers.createChildNavList($prevNav); 117 | } // else use the current $context 118 | 119 | $context.append($newNav); 120 | 121 | $prevNav = $newNav; 122 | }); 123 | }, 124 | 125 | parseOps: function(arg) { 126 | var opts; 127 | if (arg.jquery) { 128 | opts = { 129 | $nav: arg 130 | }; 131 | } else { 132 | opts = arg; 133 | } 134 | opts.$scope = opts.$scope || $(document.body); 135 | return opts; 136 | } 137 | }, 138 | 139 | // accepts a jQuery object, or an options object 140 | init: function(opts) { 141 | opts = this.helpers.parseOps(opts); 142 | 143 | // ensure that the data attribute is in place for styling 144 | opts.$nav.attr('data-toggle', 'toc'); 145 | 146 | var $topContext = this.helpers.createChildNavList(opts.$nav); 147 | var topLevel = this.helpers.getTopLevel(opts.$scope); 148 | var $headings = this.helpers.getHeadings(opts.$scope, topLevel); 149 | this.helpers.populateNav($topContext, topLevel, $headings); 150 | } 151 | }; 152 | 153 | $(function() { 154 | $('nav[data-toggle="toc"]').each(function(i, el) { 155 | var $nav = $(el); 156 | Toc.init($nav); 157 | }); 158 | }); 159 | })(); 160 | -------------------------------------------------------------------------------- /inst/paper/paper.bib: -------------------------------------------------------------------------------- 1 | @article{Andrade2017, 2 | author = {Andrade, Maria de Fatima and Kumar, Prashant and de Freitas, Edmilson Dias and Ynoue, Rita Yuri and Martins, Jorge and Martins, Leila D. and Nogueira, Thiago and Perez-Martinez, Pedro and de Miranda, Regina Maura and Albuquerque, Taciana and Gon{\c{c}}alves, Fabio Luiz Teixeira and Oyama, Beatriz and Zhang, Yang}, 3 | doi = {10.1016/j.atmosenv.2017.03.051}, 4 | issn = {18732844}, 5 | journal = {Atmospheric Environment}, 6 | keywords = {Air pollution,Climate change,Emissions,Exposure,Fuel and energy,Megacity of S{\~{a}}o Paulo}, 7 | pages = {66--82}, 8 | publisher = {Elsevier Ltd}, 9 | title = {Air quality in the megacity of S{\~{a}}o Paulo: Evolution over the last 30 years and future perspectives}, 10 | url = {http://dx.doi.org/10.1016/j.atmosenv.2017.03.051}, 11 | volume = {159}, 12 | year = {2017} 13 | } 14 | 15 | @article{Riojas-Rodriguez2016, 16 | author = {Riojas-Rodr{\'{i}}guez, Horacio and {Da Silva}, Agnes Soares and Texcalac-Sangrador, Jos{\'{e}} Luis and Moreno-Banda, Grea Litai}, 17 | issn = {16805348}, 18 | journal = {Revista Panamericana de Salud Publica/Pan American Journal of Public Health}, 19 | keywords = {Air pollution,Caribbean region,Climate change,Environment and public health environmental policy,Latin America,South America}, 20 | number = {3}, 21 | pages = {150--159}, 22 | pmid = {27991972}, 23 | title = {Air pollution management and control in Latin America and the Caribbean: Implications for climate change}, 24 | volume = {40}, 25 | year = {2016} 26 | } 27 | 28 | @book{Seinfeld2016, 29 | author = {Seinfeld, John H. and Pandis, Spyros N.}, 30 | edition = {3}, 31 | isbn = {9781118947401}, 32 | pages = {1152}, 33 | publisher = {John Wiley {\&} Sons}, 34 | title = {Atmospheric Chemistry and Physics: From Air Pollution to Climate Change}, 35 | year = {2016} 36 | } 37 | 38 | @article{Carslaw2012, 39 | author = {Carslaw, David C. and Ropkins, Karl}, 40 | doi = {10.1016/j.envsoft.2011.09.008}, 41 | isbn = {1364-8152}, 42 | issn = {13648152}, 43 | journal = {Environmental Modelling {\&} Software}, 44 | keywords = {Air pollution,Dispersion modelling,Open source software,R,Reproducibility}, 45 | mendeley-groups = {paper1,biblio{\_}final,all,6th{\_}semi-anual{\_}report}, 46 | month = {jan}, 47 | pages = {52--61}, 48 | publisher = {Elsevier Ltd}, 49 | title = {openair — An R package for air quality data analysis}, 50 | url = {http://dx.doi.org/10.1016/j.envsoft.2011.09.008 https://linkinghub.elsevier.com/retrieve/pii/S1364815211002064}, 51 | volume = {27-28}, 52 | year = {2012} 53 | } 54 | 55 | @article{Gavidia-Calderon2018, 56 | author = {Gavidia-Calder{\'{o}}n, M. and Vara-Vela, A. and Crespo, N. M. and Andrade, M. F.}, 57 | doi = {10.1016/j.atmosenv.2018.09.026}, 58 | issn = {18732844}, 59 | journal = {Atmospheric Environment}, 60 | keywords = {Chemical boundary conditions,MOZART-4,S{\~{a}}o Paulo megacity,Tropospheric ozone,WRF-Chem}, 61 | number = {March}, 62 | pages = {112--124}, 63 | publisher = {Elsevier}, 64 | title = {Impact of time-dependent chemical boundary conditions on tropospheric ozone simulation with WRF-Chem: An experiment over the Metropolitan Area of S{\~{a}}o Paulo}, 65 | url = {https://doi.org/10.1016/j.atmosenv.2018.09.026}, 66 | volume = {195}, 67 | year = {2018} 68 | } 69 | 70 | 71 | @book{Dasu2003, 72 | author = {Dasu, Tamraparni and Johnson, Theodore}, 73 | edition = {1}, 74 | isbn = {978-0-471-26851-2}, 75 | pages = {203}, 76 | publisher = {John Wiley {\&} Sons, Inc}, 77 | title = {Exploratory Data Mining and Data Cleaning}, 78 | year = {2003} 79 | } 80 | 81 | @Manual{RCoreTeam2020, 82 | title = {R: A Language and Environment for Statistical Computing}, 83 | author = {{R Core Team}}, 84 | organization = {R Foundation for Statistical Computing}, 85 | address = {Vienna, Austria}, 86 | year = {2020}, 87 | url = {https://www.r-project.org/} 88 | } 89 | 90 | @Manual{XML, 91 | title = {XML: Tools for Parsing and Generating XML Within R and S-Plus}, 92 | author = {Duncan Temple Lang}, 93 | year = {2020}, 94 | note = {R package version 3.99-0.5}, 95 | url = {https://CRAN.R-project.org/package=XML} 96 | } 97 | 98 | @Manual{httr, 99 | title = {httr: Tools for Working with URLs and HTTP}, 100 | author = {Hadley Wickham}, 101 | year = {2020}, 102 | note = {R package version 1.4.2}, 103 | url = {https://httr.r-lib.org/} 104 | } 105 | 106 | @article{Dantas2020, 107 | author = {Dantas, Guilherme and Siciliano, Bruno and Fran{\c{c}}a, Bruno Boscaro and da Silva, Cleyton M. and Arbilla, Graciela}, 108 | doi = {10.1016/j.scitotenv.2020.139085}, 109 | issn = {18791026}, 110 | journal = {Science of the Total Environment}, 111 | keywords = {COVID-19,Carbon monoxide,Lockdown,Nitrogen dioxide,Ozone,PM10}, 112 | pages = {139085}, 113 | publisher = {Elsevier B.V.}, 114 | title = {{The impact of COVID-19 partial lockdown on the air quality of the city of Rio de Janeiro, Brazil}}, 115 | url = {https://doi.org/10.1016/j.scitotenv.2020.139085}, 116 | volume = {729}, 117 | year = {2020} 118 | } 119 | 120 | @article{Ooms, 121 | archivePrefix = {arXiv}, 122 | arxivId = {1403.2805}, 123 | author = {Ooms, Jeroen}, 124 | eprint = {1403.2805}, 125 | month = {mar}, 126 | pages = {1--29}, 127 | title = {{The jsonlite Package: A Practical and Consistent Mapping Between JSON Data and R Objects}}, 128 | url = {http://arxiv.org/abs/1403.2805}, 129 | year = {2014} 130 | } 131 | -------------------------------------------------------------------------------- /R/cetesb_retrieve_met_pol.R: -------------------------------------------------------------------------------- 1 | #' Download meteorological and pollutant data from CETESB QUALAR 2 | #' 3 | #' This function download the main meteorological parameters for model 4 | #' evaluation, together with criteria pollutants for one 5 | #' air quality station (AQS). It will pad out the date with 6 | #' missing data with NA. 7 | #' This function required to have 8 | #' \href{https://seguranca.cetesb.sp.gov.br/Home/CadastrarUsuario}{an account} 9 | #' in \href{https://qualar.cetesb.sp.gov.br/qualar/home.do}{CETESB QUALAR}. 10 | #' 11 | #' @param username User name of CETESB QUALAR 12 | #' @param password User name's password of CETESB QUALAR 13 | #' @param aqs_code Code of AQS 14 | #' @param start_date Date to start downloading in dd/mm/yyyy 15 | #' @param end_date Date to end downloading in dd/mm/yyyy 16 | #' @param verbose Print query summary 17 | #' @param to_csv Creates a csv file. FALSE by default 18 | #' @param csv_path Path to save the csv file. 19 | #' 20 | #' @return data.frame with Temperature (C), Relative Humidity (%), 21 | #' Wind Speed (m/s) and Direction (degrees), Pressure information (hPa), 22 | #' O3, NO, NO2, NOx, PM2.5, PM10 and CO information. 23 | #' @export 24 | #' 25 | #' @examples 26 | #' \dontrun{ 27 | #' # Downloading main meteorological parameters and criteria pollutants 28 | #' # from Pinheiros AQS from January first to 7th of 2020 29 | #' my_user_name <- "John Doe" 30 | #' my_pass_word <- "drowssap" 31 | #' pin_code <- 99 # Check with cetesb_aqs 32 | #' start_date <- "01/01/2020" 33 | #' end_date <- "07/01/2020" 34 | #' 35 | #' pin_all <- cetesb_retrieve_met_pol(my_user_name, my_pass_word, pin_code, 36 | #' start_date, end_date) 37 | #' 38 | #' } 39 | cetesb_retrieve_met_pol <- function(username, password, 40 | aqs_code, start_date, 41 | end_date, verbose = TRUE, 42 | to_csv = FALSE, csv_path = ""){ 43 | 44 | # Check if aqs_code is valid 45 | aqs <- cetesb 46 | check_code <- check_cetesb_code(aqs, aqs_code) 47 | aqs_name <- check_code[1] 48 | aqs_code <- as.numeric(check_code[2]) 49 | 50 | # Adding query summary 51 | if (verbose){ 52 | message("Your query is: ") 53 | message(paste("Parameter: TC, RH, WS, WD, Pressure,", 54 | "O3, NO, NO2, NOX, PM2.5, PM10, CO")) 55 | message("Air quality station: ", aqs_name) 56 | message("Period: From ", start_date, " to ", end_date) 57 | } 58 | 59 | tc <- cetesb_retrieve(username, password, 25, 60 | aqs_code, start_date, 61 | end_date, verbose = FALSE) 62 | 63 | rh <- cetesb_retrieve(username, password, 28, 64 | aqs_code, start_date, 65 | end_date, verbose = FALSE) 66 | 67 | ws <- cetesb_retrieve(username, password, 24, 68 | aqs_code, start_date, 69 | end_date, verbose = FALSE) 70 | 71 | wd <- cetesb_retrieve(username, password, 23, 72 | aqs_code, start_date, 73 | end_date, verbose = FALSE) 74 | 75 | p <- cetesb_retrieve(username, password, 29, 76 | aqs_code, start_date, 77 | end_date, verbose = FALSE) 78 | 79 | o3 <- cetesb_retrieve(username, password, 63, 80 | aqs_code, start_date, 81 | end_date, verbose = FALSE) 82 | 83 | no <- cetesb_retrieve(username, password, 17, 84 | aqs_code, start_date, 85 | end_date, verbose = FALSE) 86 | 87 | no2 <- cetesb_retrieve(username, password, 15, 88 | aqs_code, start_date, 89 | end_date, verbose = FALSE) 90 | 91 | nox <- cetesb_retrieve(username, password, 18, 92 | aqs_code, start_date, 93 | end_date, verbose = FALSE) 94 | 95 | pm25 <- cetesb_retrieve(username, password, 57, 96 | aqs_code, start_date, 97 | end_date, verbose = FALSE) 98 | 99 | pm10 <- cetesb_retrieve(username, password, 12, 100 | aqs_code, start_date, 101 | end_date, verbose = FALSE) 102 | 103 | co <- cetesb_retrieve(username, password, 16, 104 | aqs_code, start_date, 105 | end_date, verbose = FALSE) 106 | 107 | 108 | all_data <- data.frame(date = o3$date, 109 | tc = tc$pol, 110 | rh = rh$pol, 111 | ws = ws$pol, 112 | wd = wd$pol, 113 | p = p$pol, 114 | o3 = o3$pol, 115 | no = no$pol, 116 | no2 = no2$pol, 117 | nox = nox$pol, 118 | co = co$pol, 119 | pm10 = pm10$pol, 120 | pm25 = pm25$pol, 121 | aqs = o3$aqs, 122 | stringsAsFactors = FALSE) 123 | 124 | cols_unchange <- -c(1, ncol(all_data)) 125 | all_data[, cols_unchange] <- sapply(all_data[, cols_unchange], as.numeric) 126 | 127 | message(paste( 128 | "Download complete for", unique(all_data$aqs) 129 | )) 130 | 131 | if (to_csv){ # nocov start 132 | write_csv(all_data, aqs_name, start_date, end_date, "MET_POL", csv_path) 133 | } # nocov end 134 | 135 | return(all_data) 136 | } 137 | -------------------------------------------------------------------------------- /docs/LICENSE-text.html: -------------------------------------------------------------------------------- 1 | 2 | License • qualR 6 | Skip to contents 7 | 8 | 9 |
    47 |
    48 |
    52 | 53 |
    YEAR: 2020
    54 | COPYRIGHT HOLDER: Mario Gavidia-Calderón
    55 | 
    56 | 57 |
    58 | 59 | 60 |
    63 | 64 | 67 | 68 |
    69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, religion, or sexual identity and 10 | orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | * Demonstrating empathy and kindness toward other people 21 | * Being respectful of differing opinions, viewpoints, and experiences 22 | * Giving and gracefully accepting constructive feedback 23 | * Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | * Focusing on what is best not just for us as individuals, but for the overall 26 | community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | * The use of sexualized language or imagery, and sexual attention or 31 | advances of any kind 32 | * Trolling, insulting or derogatory comments, and personal or political attacks 33 | * Public or private harassment 34 | * Publishing others' private information, such as a physical or email 35 | address, without their explicit permission 36 | * Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards 42 | of acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies 54 | when an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail 56 | address, posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at [INSERT CONTACT 63 | METHOD]. All complaints will be reviewed and investigated promptly and fairly. 64 | 65 | All community leaders are obligated to respect the privacy and security of the 66 | reporter of any incident. 67 | 68 | ## Enforcement Guidelines 69 | 70 | Community leaders will follow these Community Impact Guidelines in determining 71 | the consequences for any action they deem in violation of this Code of Conduct: 72 | 73 | ### 1. Correction 74 | 75 | **Community Impact**: Use of inappropriate language or other behavior deemed 76 | unprofessional or unwelcome in the community. 77 | 78 | **Consequence**: A private, written warning from community leaders, providing 79 | clarity around the nature of the violation and an explanation of why the 80 | behavior was inappropriate. A public apology may be requested. 81 | 82 | ### 2. Warning 83 | 84 | **Community Impact**: A violation through a single incident or series of 85 | actions. 86 | 87 | **Consequence**: A warning with consequences for continued behavior. No 88 | interaction with the people involved, including unsolicited interaction with 89 | those enforcing the Code of Conduct, for a specified period of time. This 90 | includes avoiding interactions in community spaces as well as external channels 91 | like social media. Violating these terms may lead to a temporary or permanent 92 | ban. 93 | 94 | ### 3. Temporary Ban 95 | 96 | **Community Impact**: A serious violation of community standards, including 97 | sustained inappropriate behavior. 98 | 99 | **Consequence**: A temporary ban from any sort of interaction or public 100 | communication with the community for a specified period of time. No public or 101 | private interaction with the people involved, including unsolicited interaction 102 | with those enforcing the Code of Conduct, is allowed during this period. 103 | Violating these terms may lead to a permanent ban. 104 | 105 | ### 4. Permanent Ban 106 | 107 | **Community Impact**: Demonstrating a pattern of violation of community 108 | standards, including sustained inappropriate behavior, harassment of an 109 | individual, or aggression toward or disparagement of classes of individuals. 110 | 111 | **Consequence**: A permanent ban from any sort of public interaction within the 112 | community. 113 | 114 | ## Attribution 115 | 116 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 117 | version 2.0, 118 | available at https://www.contributor-covenant.org/version/2/0/ 119 | code_of_conduct.html. 120 | 121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 122 | enforcement ladder](https://github.com/mozilla/diversity). 123 | 124 | [homepage]: https://www.contributor-covenant.org 125 | 126 | For answers to common questions about this code of conduct, see the FAQ at 127 | https://www.contributor-covenant.org/faq. Translations are available at https:// 128 | www.contributor-covenant.org/translations. 129 | -------------------------------------------------------------------------------- /docs/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Page not found (404) • qualR 9 | 10 | 11 | 12 | 13 | 14 | 18 | 19 | 20 | Skip to contents 21 | 22 | 23 |
    66 |
    67 |
    71 | 72 | Content not found. Please use links in the navbar. 73 | 74 |
    75 |
    76 | 77 | 78 |
    82 | 83 | 87 | 88 |
    89 |
    90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /docs/articles/index.html: -------------------------------------------------------------------------------- 1 | 2 | Articles • qualR 6 | Skip to contents 7 | 8 | 9 |
    47 |
    48 |
    51 | 52 |
    53 |

    All vignettes

    54 |

    55 | 56 |
    How to use qualR
    57 |
    58 |
    59 |
    60 | 61 | 62 |
    65 | 66 | 69 | 70 |
    71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /R/cetesb_retrieve.R: -------------------------------------------------------------------------------- 1 | #' Download a single parameter from CETESB QUALAR system 2 | #' 3 | #' This function download one parameter from one air quality stations (AQS) 4 | #' of CETESB AQS network. It will pad out the date with missing data with NA. 5 | #' 6 | #' @param username User name of CETESB QUALAR 7 | #' @param password User name's password of CETESB QUALAR 8 | #' @param pol_code Code of parameter 9 | #' @param aqs_code Code of AQS 10 | #' @param start_date Date to start downloading in dd/mm/yyyy 11 | #' @param end_date Date to end downloading in dd/mm/yyyy 12 | #' @param verbose Print query summary 13 | #' @param to_csv Creates a csv file. FALSE by default 14 | #' 15 | #' @return data.frame with the selected parameter information 16 | #' @keywords internal 17 | #' 18 | #' @examples 19 | #' \dontrun{ 20 | #' # Downloading Ozone information from Pinheiros AQS 21 | #' # from January first to 7th of 2020 22 | #' my_user_name <- "John Doe" 23 | #' my_pass_word <- "drowssap" 24 | #' o3_code <- 63 # Check with cetesb_param 25 | #' pin_code <- 99 # Check with cetesb_aqs 26 | #' start_date <- "01/01/2020" 27 | #' end_date <- "07/01/2020" 28 | #' 29 | #' pin_o3 <- cetesb_retrieve(my_user_name, my_pass_word, o3_code, pin_code, 30 | #' start_date, end_date) 31 | #' 32 | #' } 33 | cetesb_retrieve <- function(username, password, 34 | pol_code, aqs_code, 35 | start_date, end_date, 36 | verbose = TRUE, to_csv = FALSE){ 37 | 38 | # Renaming dataframes 39 | aqs <- cetesb 40 | pols <- params 41 | 42 | # Check if pol_code is valid 43 | if (is.numeric(pol_code) & pol_code %in% pols$code){ # nocov start 44 | pol_code <- pol_code 45 | } else if (is.character(pol_code) & toupper(pol_code) %in% 46 | (params_code$name)){ 47 | pol_code <- params_code$code[params_code$name == toupper(pol_code)] 48 | } else { 49 | stop("Wrong pol_code value, please check cetesb_param", 50 | call. = FALSE) 51 | } # nocov end 52 | 53 | # Getting full pollutant name 54 | pol_name <- pols$name[pols$code == pol_code] 55 | pol_abr <- params_code$name[params_code$code == pol_code] 56 | 57 | # Getting aqs_name in ascii 58 | aqs_name <- aqs$ascii[aqs$code == aqs_code] 59 | 60 | # Adding query summary 61 | if (verbose){ 62 | message("Your query is:") # nocov 63 | message("Parameter: ", pol_name) # nocov 64 | message("Air quality staion: ", aqs_name) # nocov 65 | message("Period: From ", start_date," to ", end_date) # nocov 66 | } 67 | 68 | 69 | # Logging to CETESB QUALAR 70 | log_params <- list( 71 | cetesb_login = username, 72 | cetesb_password = password 73 | ) 74 | 75 | url_log <- "https://qualar.cetesb.sp.gov.br/qualar/autenticador" 76 | log_qualar <- httr::POST(url_log, body = log_params, encode = "form") 77 | 78 | # Downloading data from Air quality stations 79 | url_aqs <- paste0("https://qualar.cetesb.sp.gov.br/qualar/", 80 | "exportaDados.do?method=pesquisar") 81 | 82 | aqs_params <- list(irede = 'A', 83 | dataInicialStr = start_date, 84 | dataFinalStr = end_date, 85 | iTipoDado = 'P', 86 | estacaoVO.nestcaMonto = aqs_code, 87 | parametroVO.nparmt = pol_code) 88 | 89 | ask <- httr::POST(url_aqs, body = aqs_params, encode = "form") 90 | 91 | # Transforming query to dataframe 92 | # 'Encoding "UTF-8", preserves special characteres 93 | pars <- XML::htmlParse(ask, encoding = "UTF-8") 94 | tabl <- XML::getNodeSet(pars, "//table") 95 | dat <- XML::readHTMLTable(tabl[[2]], skip.rows = 1, stringsAsFactors = FALSE) 96 | 97 | # Creating a complete date data frame to merge and to pad out with NA 98 | end_date2 <- as.character(as.Date(end_date, format = '%d/%m/%Y') + 1) 99 | all.dates <- data.frame( 100 | date = seq( 101 | as.POSIXct(strptime(start_date, format = '%d/%m/%Y'), 102 | tz = 'UTC'), 103 | as.POSIXct(strptime(end_date2, format = '%Y-%m-%d'), 104 | tz = 'UTC'), 105 | by = 'hour' 106 | ) 107 | ) 108 | 109 | # These are the columns of the html table 110 | cet.names <- c('emp1', 'red', 'mot', 'type', 'day', 'hour', 'cod', 'est', 111 | 'pol', 'unit', 'value', 'mov','test', 'dt.amos', 'dt.inst', 112 | 'dt.ret', 'con', 'tax', 'emp2') 113 | 114 | # In case there is no data 115 | if (ncol(dat) != 19){ 116 | dat <- data.frame(date = all.dates$date , pol = NA, aqs = aqs_name, # nocov 117 | stringsAsFactors = FALSE) # nocov 118 | message(paste0( # nocov 119 | 'No data available for ', # nocov 120 | pol_name, # nocov 121 | ". Filling with NA.")) # nocov 122 | } 123 | 124 | if (ncol(dat) == 19) { 125 | names(dat) <- cet.names 126 | dat$date <- paste(dat$day, dat$hour, sep = '_') 127 | dat$date <- as.POSIXct(strptime(dat$date, format = '%d/%m/%Y_%H:%M'), 128 | tz = 'UTC') 129 | dat$value <- as.numeric(gsub(",", ".", gsub("\\.", "", dat$value))) 130 | dat <- dat[dat$test == 'Sim', ] 131 | dat <- merge(all.dates, dat, all = TRUE) 132 | 133 | if (nrow(dat) != nrow(all.dates)){ 134 | message(paste0('Dates missmatch ', # nocov start 135 | unique(stats::na.omit(dat$est)))) 136 | message('Duplicated date in ', 137 | dat$date[duplicated(dat$date)]) 138 | dat <- data.frame(date = dat$date , pol = dat$value, 139 | aqs = aqs_name, 140 | stringsAsFactors = FALSE) 141 | } else { 142 | message(paste0('Download OK ', pol_abr)) 143 | dat <- data.frame(date = all.dates$date , pol = dat$value , 144 | aqs = aqs_name, stringsAsFactors = FALSE) 145 | } # nocov end 146 | } 147 | 148 | if (to_csv){ 149 | write_csv(dat, aqs_name, start_date, end_date, pol_abr) # nocov 150 | } 151 | 152 | return(dat) 153 | } 154 | -------------------------------------------------------------------------------- /docs/LICENSE.html: -------------------------------------------------------------------------------- 1 | 2 | MIT License • qualR 6 | Skip to contents 7 | 8 | 9 |
    47 |
    48 |
    52 | 53 |
    54 | 55 |

    Copyright (c) 2020 Mario Gavidia-Calderón

    56 |

    Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

    57 |

    The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

    58 |

    THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

    59 |
    60 | 61 |
    62 | 63 | 64 |
    67 | 68 | 71 | 72 |
    73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /docs/CONTRIBUTING.html: -------------------------------------------------------------------------------- 1 | 2 | How to contribute • qualR 6 | Skip to contents 7 | 8 | 9 |
    47 |
    48 |
    52 | 53 |
    54 | 55 |

    We welcome any suggestion, requests and bug report through the issue tracker.

    56 |
    57 |

    Any bugs?

    58 |
    • If you found any issue while using qualR, submit an issue here.
    • 59 |
    • Remember to add a reproducible example and the output of sessionInfo().
    • 60 |
    61 |
    62 |

    A little bit shy?

    63 |
    • You can email the person as maintainer in the DESCRIPTION file (in portuguese or english).
    • 64 |

    Thanks for your contribution :)

    65 |
    66 |
    67 | 68 |
    70 | 71 | 72 |
    75 | 76 | 79 | 80 |
    81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /R/monitor_ar_retrieve_param.R: -------------------------------------------------------------------------------- 1 | #' Download air quality and meteorology information from MonitorAr-Rio 2 | #' 3 | #' This function download air quality and meteorology measurements from 4 | #' MonitorAr-Rio program from Rio de Janeiro city. 5 | #' 6 | #' @param start_date Date to start downloading in dd/mm/yyyy 7 | #' @param end_date Date to end downloading in dd/mm/yyyy 8 | #' @param aqs_code AQS code 9 | #' @param parameters Parameters to download. 10 | #' It can be a vector with many parameters. 11 | #' @param to_local Date information in local time. TRUE by default. 12 | #' @param verbose Print query summary. 13 | #' @param to_csv Creates a csv file. FALSE by default 14 | #' @param csv_path Path to save the csv file. 15 | #' 16 | #' @return data.frame with the selected parameter information 17 | #' @export 18 | #' 19 | #' @examples 20 | #' \dontrun{ 21 | #' # Downloading Ozone information from Centro AQS 22 | #' # from February of 2019 23 | #' date_start <- "01/02/2019" 24 | #' date_end <- "01/03/2019" 25 | #' aqs_code <- "CA" 26 | #' param <- "O3" 27 | #' ca_o3 <- monitor_ar_retrieve_param(date_start, date_end, aqs_code, param) 28 | #' 29 | #' } 30 | monitor_ar_retrieve_param <- function(start_date, end_date, aqs_code, 31 | parameters, to_local=TRUE, verbose = TRUE, 32 | to_csv = FALSE, csv_path = ""){ 33 | 34 | # Check if params are measured 35 | if (!prod(parameters %in% param_monitor_ar$code)){ 36 | stop("One or all wrong param codes, please check monitor_ar_param", # nocov 37 | call. = FALSE) # nocov 38 | } 39 | 40 | if (!(aqs_code %in% aqs_monitor_ar$code )){ 41 | stop("Wrong aqs_code, please check monitor_ar_aqs", # nocov 42 | call. = FALSE) # nocov 43 | } 44 | 45 | aqs_name <- aqs_monitor_ar$name[aqs_monitor_ar$code == aqs_code] 46 | 47 | # Adding query summary 48 | if (verbose){ 49 | message("Your query is:") 50 | message("Parameter: ", paste(parameters, collapse = ", ")) 51 | message("Air quality station: ", aqs_name) 52 | message("Period: From ", start_date, " to ", end_date) 53 | } 54 | 55 | start_date_format <- as.POSIXct(strptime(start_date, format="%d/%m/%Y"), 56 | tz = "UTC") 57 | end_date_format <- as.POSIXct(strptime(end_date, format="%d/%m/%Y"), 58 | tz = "UTC") 59 | 60 | # Function to create the WHERE query 61 | where_query <- function(ds, de, aqs){ 62 | ds_format <- format(ds, format="%Y-%m-%d %H:%M:%S") 63 | de_format <- format(de, format="%Y-%m-%d %H:%M:%S") 64 | date_range <- paste0("Data >= TIMESTAMP'", ds_format, "' AND ", 65 | "Data <= TIMESTAMP'", de_format) 66 | aqs <- paste0("' AND Esta", iconv("\u00e7\u00e3", "", "utf-8", "byte"), 67 | "o = '", aqs, "'") 68 | where <- paste0(date_range, aqs) 69 | return(where) 70 | } 71 | 72 | # Creating outFiled 73 | if (length(parameters) == 1){ 74 | outfields <- paste("Data", parameters, sep = ",") 75 | } else { 76 | outfields <- paste("Data", paste(parameters, collapse = ","), 77 | sep = ",") # nocov 78 | } 79 | 80 | url <- paste0("https://services1.arcgis.com/OlP4dGNtIcnD3RYf/arcgis/rest/", 81 | "services/Qualidade_do_ar_dados_horarios_2011_2018/", 82 | "FeatureServer/2/query?") 83 | 84 | res <- httr::GET(url, 85 | query = list( 86 | where = where_query(start_date_format, end_date_format, 87 | aqs_code), 88 | outFields = outfields, 89 | f = 'json' 90 | )) 91 | # Checking request 92 | if (res$status_code == 200){ 93 | message("Succesful request") 94 | message(paste("Downloading ", paste(parameters, collapse = " "))) 95 | } else { 96 | stop("Unsuccesful request. Something goes wrong", call. = FALSE) # nocov 97 | } 98 | 99 | # Reading json 100 | raw_data <- jsonlite::fromJSON(rawToChar(res$content)) 101 | 102 | # Create an empty data frame is there is no input 103 | if (length(raw_data$feature) == 0){ 104 | message("Data unavailable") # nocov start 105 | data_aqs <- data.frame(Data = NA) 106 | for (p in parameters){ 107 | data_aqs[[p]] <- NA # nocov end 108 | } 109 | } else { 110 | data_aqs <- raw_data$features[[1]] # nocov 111 | } 112 | 113 | 114 | # Changing epoch to human readable date 115 | data_aqs$data <- as.POSIXct(data_aqs$data/1000, 116 | origin = "1970-01-01", tz = "UTC") 117 | 118 | # Check completion 119 | start_date2 <- paste(as.character(as.Date(start_date_format)), "00:30") 120 | end_date2 <- paste(as.character(as.Date(end_date_format) - 1), "23:30") 121 | 122 | all_dates <- data.frame( 123 | data = seq(as.POSIXct(strptime(start_date2, format="%Y-%m-%d %H:%M"), 124 | tz = "UTC"), 125 | as.POSIXct(strptime(end_date2, format="%Y-%m-%d %H:%M"), 126 | tz = "UTC"), 127 | by = "hour") 128 | ) 129 | 130 | if (nrow(all_dates) != nrow(data_aqs)){ 131 | message("Padding out missing dates with NA") # nocov 132 | data_aqs <- merge(all_dates, data_aqs, all = TRUE) # nocov 133 | } 134 | 135 | # Adding aqs code to dataframe 136 | 137 | data_aqs$aqs <- aqs_code 138 | 139 | # Changing to local time 140 | if (to_local){ 141 | attributes(data_aqs$data)$tzone <- "America/Sao_Paulo" 142 | } 143 | 144 | 145 | # Changing Data column name to date 146 | colnames(data_aqs)[1] <- "date" 147 | 148 | # Ensure columns as numeric 149 | cols_unchange <- !(colnames(data_aqs) %in% c("date", "aqs")) 150 | data_aqs[, cols_unchange] <- sapply(data_aqs[, cols_unchange], as.numeric) 151 | 152 | # Changing wind speed and direction columns to ws and wd 153 | if ("dir_vento" %in% names(data_aqs)){ 154 | names(data_aqs)[names(data_aqs) == "dir_vento"] <- "wd" # nocov 155 | } 156 | if ("vel_vento" %in% names(data_aqs)){ 157 | names(data_aqs)[names(data_aqs) == "vel_vento"] <- "ws" 158 | } 159 | if ("ur" %in% names(data_aqs)){ 160 | names(data_aqs)[names(data_aqs) == "ur"] <- "rh" # nocov 161 | } 162 | if ("chuva" %in% names(data_aqs)){ 163 | names(data_aqs)[names(data_aqs) == "chuva"] <- "rain" # nocov 164 | } 165 | if ("Pres" %in% names(data_aqs)){ 166 | names(data_aqs)[names(data_aqs) == "Pres"] <- "p" # nocov 167 | } 168 | if ("temp" %in% names(data_aqs)){ 169 | names(data_aqs)[names(data_aqs) == "temp"] <- "tc" # nocov 170 | } 171 | if ("PM2_5" %in% names(data_aqs)){ 172 | names(data_aqs)[names(data_aqs) == "PM2_5"] <- "pm25" # nocov 173 | } 174 | 175 | names(data_aqs)[-c(1, ncol(data_aqs))] <- tolower( 176 | names(data_aqs)[-c(1, ncol(data_aqs))] 177 | ) 178 | 179 | 180 | if (to_csv){ # nocov start 181 | write_csv (data_aqs, aqs_name, start_date, end_date, parameters, csv_path) 182 | } # nocov end 183 | 184 | return(data_aqs) 185 | } 186 | -------------------------------------------------------------------------------- /docs/authors.html: -------------------------------------------------------------------------------- 1 | 2 | Authors and Citation • qualR 6 | Skip to contents 7 | 8 | 9 |
    47 |
    48 |
    51 | 52 |
    53 |

    Authors

    54 | 55 |
    • 56 |

      Mario Gavidia-Calderón. Author, maintainer. 57 |

      58 |
    • 59 |
    • 60 |

      Maria de Fatima Andrade. Contributor, thesis advisor. 61 |

      62 |
    • 63 |
    • 64 |

      Daniel Schuch. Author, contributor. 65 |

      66 |
    • 67 |
    • 68 |

      Beatriz Milz. Reviewer. 69 |
      Beatriz reviewed the package (v. 0.9.6) for rOpenSci

      70 |
    • 71 |
    • 72 |

      Kaue de Sousa. Reviewer. 73 |
      Kaue reviewed the package (v. 0.9.6) for rOpenSci

      74 |
    • 75 |
    76 | 77 |
    78 |

    Citation

    79 |

    Source: inst/CITATION

    80 | 81 |

    Gavidia-Calderón, M., Schuch, D., Andrade, Maria de Fatima (2022). qualR: An R package to download Sao Paulo and Rio de Janeiro air pollution data. URL: https://docs.ropensci.org/qualR/

    82 |
    @Manual{,
     83 |   title = {qualR: An R package to download São Paulo and Rio de Janeiro air pollution data},
     84 |   doi = {10.5281/zenodo.5904262},
     85 |   author = {Mario Gavidia-Calderón and Daniel Schuch and Maria de Fatima Andrade},
     86 |   year = {2022},
     87 |   url = {https://docs.ropensci.org/qualR/},
     88 | }
    89 |
    90 |
    92 | 93 | 94 |
    97 | 98 | 101 | 102 |
    103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /vignettes/qualr.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "How to use qualR" 3 | author: 4 | - name: Mario Gavidia-Calderón, Daniel Schuch & Maria de Fatima Andrade 5 | date: "`r Sys.Date()`" 6 | output: rmarkdown::html_vignette 7 | vignette: > 8 | %\VignetteIndexEntry{How to use qualR} 9 | %\VignetteEngine{knitr::rmarkdown} 10 | %\VignetteEncoding{UTF-8} 11 | --- 12 | 13 | ```{r, include = FALSE} 14 | knitr::opts_chunk$set( 15 | collapse = TRUE, 16 | comment = "#>" 17 | ) 18 | ``` 19 | 20 | # Context 21 | Both the State of São Paulo and Rio de Janeiro have one of the most extensive 22 | air quality stations network in South America. 23 | [CETESB QUALAR System](https://cetesb.sp.gov.br/ar/qualar/) provide to the user the air quality data from the State 24 | of São Paulo. QUALAR System limits the download to one parameter from one air 25 | station for one year in a simple query (three parameter in advance query). 26 | The data can have missing hours (e.g. due to calibration), 27 | the decimal separator is ",", and the output is a CSV file. 28 | [data.rio](https://www.data.rio/maps/PCRJ::qualidade-do-ar-dados-hor%C3%A1rios/about) hosts the air quality information from Monitor Ar Program. 29 | It is not an user-friendly API and the data needs the same preprocessor as the 30 | data from QUALAR System. 31 | 32 | `qualR` surpasses these limitations and brings to your R session ready-to use 33 | data frames with the information of air quality station from the State of 34 | São Paulo and the city of Rio de Janeiro. 35 | 36 | # Approach 37 | 38 | `qualR` has the following functions: 39 | 40 | * `cetesb_retrieve_param`: Download a list of different parameter from one air quality station (AQS) from CETESB QUALAR System. 41 | * `cetesb_retrieve_pol`: Download criteria pollutants from one AQS from CETESB QUALAR System. 42 | * `cetesb_retrieve_met`: Download meteorological parameters from one AQS from CETESB QUALAR System. 43 | * `cetesb_retrieve_met_pol`: Download meteorological parameters and criteria pollutants from one AQS from CETESB QUALAR System. 44 | * `monitor_ar_retrieve_param`: Download a list of different parameters from MonitorAr - Rio program. 45 | * `monitor_ar_retrieve_pol`: Download criteria pollutants from one AQS from MonitorAr - Rio program. 46 | * `monitor_ar_retrieve_met`: Download meteorological parameters from one AQS from MonitorAr - Rio program. 47 | * `monitor_ar_retrieve_met_pol`: Download meteorological parameters and criteria pollutants from one AQS from MonitorAr - Rio Program. 48 | 49 | 50 | 51 | # Example to download data from Rio de Janeiro 52 | 53 | In this example we want to download one year PM10 concentration from an 54 | air quality station located in Rio de Janeiro downtown. We need to do the following: 55 | 56 | 1. Check for the code or abbreviation of the station. 57 | ```{r setup} 58 | library(qualR) 59 | monitor_ar_aqs 60 | ``` 61 | 2. Check for the code or abbreviation of the parameters. 62 | ```{r} 63 | monitor_ar_param 64 | ``` 65 | 3. We have that the air quality station `code` is `CA` (Estação Centro), and 66 | PM10 `code` is `PM10`. So we use the function `monitor_ar_retrieve_param()`. 67 | ```{r} 68 | rj_centro <- monitor_ar_retrieve_param(start_date = "01/01/2019", 69 | end_date = "31/12/2019", 70 | aqs_code = "CA", 71 | parameters = "PM10") 72 | 73 | head(rj_centro) 74 | ``` 75 | 4. We can download multiple parameters too. For example, maybe we need to know 76 | the relationship between PM10 and Wind Speed. To do that we just need to 77 | define a vector with the parameters we need. 78 | ```{r} 79 | to_dwld <- c("PM10", "Vel_Vento") 80 | 81 | rj_ca_params <- monitor_ar_retrieve_param(start_date = "01/01/2019", 82 | end_date = "31/12/2019", 83 | aqs_code = "CA", 84 | parameters = to_dwld) 85 | head(rj_ca_params) 86 | ``` 87 | 5. Now we can make a simple plot 88 | ```{r fig.height=5, fig.width=5} 89 | plot(rj_ca_params$ws, rj_ca_params$pm10, 90 | xlab = "Wind speed (m/s)", 91 | ylab = "", 92 | xlim = c(0,4), 93 | ylim = c(0,120)) 94 | mtext(expression(PM[10]~" ("*mu*"g/m"^3*")"), side = 2, line = 2.5) 95 | 96 | ``` 97 | 98 | # An example using `tidyverse` 99 | 100 | `tidyverse` is a powerful collection of R package. Here is an example using `purrr`to download data from multiple stations and `ggplot2`to visualize the relation between Ozone and air temperature. 101 | As we know Ozone is formed by photochemical reaction which means the participation of solar radiation. 102 | 103 | ```{r} 104 | library(qualR) 105 | library(purrr) 106 | 107 | # Retrieve data from all stations in Rio 108 | rj_params <- purrr::map_dfr(.x = qualR::monitor_ar_aqs$code, 109 | .f = monitor_ar_retrieve_param, 110 | start_date = "01/01/2020", 111 | end_date = "31/12/2020", 112 | parameters = c("O3", "Temp") 113 | ) 114 | ``` 115 | 116 | Now we can visualize all the data simultaneity using `ggplot2` facet: 117 | 118 | ```{r fig.height=5, fig.width=5} 119 | library(magrittr) 120 | library(ggplot2) 121 | 122 | # making the graph with facet 123 | rj_params %>% 124 | ggplot() + 125 | geom_point(aes(x = tc, y = o3), size = 0.5, alpha = 0.5) + 126 | labs(x = "Air temperature (º)", 127 | y = expression(O[3]~" ("*mu*"g/m"^3*")"), 128 | caption = "Source: Data from MonitorAr - Rio, retrieved with qualR R package. " 129 | )+ 130 | theme_bw()+ 131 | facet_wrap(~aqs) 132 | ``` 133 | 134 | PS: Special thanks to [@beatrizmilz](https://github.com/beatrizmilz) for inspiring this example. 135 | 136 | # Compatibility with `openair` 137 | `qualR` functions returns a completed data frame (i.e. missing hours padded out 138 | with `NA`) with a `date` column in `POSIXct`. This ensure compatibility with the 139 | `openair`package. 140 | 141 | Here is the code to use openair `timeVariation()` function. Note that no 142 | preprocessing is needed. 143 | ```{r fig.height=5, fig.width=5, eval=FALSE} 144 | #install.package("openair") 145 | library(openair) 146 | openair::timeVariation(rj_centro, pollutant = "pm10") 147 | ``` 148 | 149 | # Example to download data from São Paulo State stations 150 | To use `cetesb_retrieve` you first need to create an account in 151 | [CETESB QUALAR System](https://seguranca.cetesb.sp.gov.br/Home/CadastrarUsuario). 152 | The `cetesb_retrieve` functions are similar as `monitor_ar_retrieve_param` functions, but 153 | they require the `username` and `password` arguments. 154 | [Check this section](https://github.com/quishqa/qualR#a-better-way-to-save-your-credentials) on `qualR` README to safely configure your user name and 155 | password on your R session. 156 | 157 | In this example, we download Ozone concentration from an air quality station 158 | located at Universidade de São Paulo (USP-Ipen) for August, 2021. 159 | 1. Check the station `code` or `name` 160 | ```{r} 161 | head(cetesb_aqs, 15) 162 | ``` 163 | 2. Check ozone `code` or abbreviation 164 | ```{r} 165 | head(cetesb_param, 15) 166 | ``` 167 | 3. The air quality station is `95` and ozone code is `63`. So to retrieve the 168 | data we should use the `cetesb_retrieve_param`function like this: 169 | ```{r eval=FALSE} 170 | usp_o3 <- cetesb_retrieve_param(username = my_user, 171 | password = my_password, 172 | parameters = "O3", # or 63 173 | aqs_code = "Cid.Universitaria-USP-Ipen", # or 95 174 | start_date = "01/08/2021", 175 | end_date = "31/08/2021") 176 | ``` 177 | 178 | 179 | 180 | # More information 181 | - You can check [`qualR` README](https://github.com/quishqa/qualR#readme) for more examples and good practices. 182 | - You can also check [this tutorial](https://github.com/quishqa/qualR_tuto) for more examples of `qualR` and how it works 183 | with `openair`. 184 | -------------------------------------------------------------------------------- /docs/reference/qualR.html: -------------------------------------------------------------------------------- 1 | 2 | qualR: An R package to download Sao Paulo and Rio de Janeiro 3 | air pollution data — qualR • qualR 8 | Skip to contents 9 | 10 | 11 |
    49 |
    50 |
    56 | 57 |
    58 |

    A package to download information from CETESB QUALAR https://cetesb.sp.gov.br/ar/qualar/ and MonitorAr http://jeap.rio.rj.gov.br/je-metinfosmac/institucional/index.html systems. It contains function to download different parameters, a set of criteria pollutants and the most frequent meteorological parameters used in air quality data analysis and air quality model evaluation.

    59 |
    60 | 61 | 62 |
    63 |

    See also

    64 |

    Useful links:

    71 |
    72 |
    73 |

    Author

    74 |

    Mario Gavidia-Calderon and Daniel Schuch and Maria de Fatima Andrade

    75 |
    76 | 77 |
    79 | 80 | 81 |
    84 | 85 | 88 | 89 |
    90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /docs/reference/index.html: -------------------------------------------------------------------------------- 1 | 2 | Function reference • qualR 6 | Skip to contents 7 | 8 | 9 |
    47 |
    48 |
    51 | 52 |
    53 |

    All functions

    54 | 55 | 56 | 57 | 58 |
    59 | 60 | 61 | 62 | 63 |
    64 | 65 | cetesb_aqs 66 |
    67 |
    CETESB AQS station latitude and longitude
    68 |
    69 | 70 | cetesb_param 71 |
    72 |
    CETESB Parameters
    73 |
    74 | 75 | cetesb_retrieve_met() 76 |
    77 |
    Download meteorological parameters from CETESB QUALAR
    78 |
    79 | 80 | cetesb_retrieve_met_pol() 81 |
    82 |
    Download meteorological and pollutant data from CETESB QUALAR
    83 |
    84 | 85 | cetesb_retrieve_param() 86 |
    87 |
    Download list of observation from CETESB QUALAR
    88 |
    89 | 90 | cetesb_retrieve_pol() 91 |
    92 |
    Download criteria pollutants from CETESB QUALAR
    93 |
    94 | 95 | monitor_ar_aqs 96 |
    97 |
    Monitor Ar AQS stations.
    98 |
    99 | 100 | monitor_ar_param 101 |
    102 |
    Monitor Ar Parameters
    103 |
    104 | 105 | monitor_ar_retrieve_met() 106 |
    107 |
    Download meteorological parameters from Monitor Ar program
    108 |
    109 | 110 | monitor_ar_retrieve_met_pol() 111 |
    112 |
    Download meteorological and pollutant data from Monitor Ar Program
    113 |
    114 | 115 | monitor_ar_retrieve_param() 116 |
    117 |
    Download air quality and meteorology information from MonitorAr-Rio
    118 |
    119 | 120 | monitor_ar_retrieve_pol() 121 |
    122 |
    Download criteria pollutants from Monitor Ar program
    123 |
    124 | 125 | qualR qualR-package 126 |
    127 |
    qualR: An R package to download Sao Paulo and Rio de Janeiro 128 | air pollution data
    129 |
    130 |
    131 | 132 | 133 |
    136 | 137 | 140 | 141 |
    142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | -------------------------------------------------------------------------------- /docs/news/index.html: -------------------------------------------------------------------------------- 1 | 2 | Changelog • qualR 6 | Skip to contents 7 | 8 | 9 |
    47 |
    48 |
    52 | 53 |
    54 |

    qualR 0.9.6

    55 |
    56 |

    Changes

    57 |
    • Function names from CamelCase to snake_case
    • 58 |
    • Better and consistent naming of returned data frames variables and datasets.
    • 59 |
    60 |
    61 |

    New Features

    62 |
    • Updated qualR site.
    • 63 |
    • Vignette with examples are available.
    • 64 |
    65 |
    66 |
    67 |

    qualR 0.9.5

    68 |
    69 |

    Changes

    70 |
    • 71 | CetesbRetrive function is now depreciated. Use CetesbRetrieveParam instead.
    • 72 |
    • 73 | CetesbRetrieveAll is now called CetesbRetrieveMetPol 74 |
    • 75 |
    76 |
    77 |

    New Features

    78 |
    • 79 | Monitor Ar Program air quality network is included. Download meteorological parameters and air pollution from Rio de Janeiro city are now available through MonitorArRetrieve functions.
    • 80 |
    • All functions has verbose option to print query summary.
    • 81 |
    • All functions can export downloaded data to .csv files.
    • 82 |
    • Units added in parameters datasets cetesb_paramand monitor_ar_param.
    • 83 |
    84 |
    85 |

    Bug Fixes

    86 |
    • Now qualR uses httr instead of RCurl package to fix SSL23_SERVER_HELLO error on Windows.
    • 87 |
    88 |
    89 |
    90 |

    qualR 0.9.1

    91 |
    92 |

    Features

    93 |
    • Initial version
    • 94 |
    • Download one parameter from one air quality station with CetesbRetrieve function.
    • 95 |
    • Download criteria pollutants from one air quality station with CetesbRetrievePol function.
    • 96 |
    • Download meteorological parameters from one air quality station with CetesbRetrieveMet function.
    • 97 |
    • Download criteria pollutants and meteorological parameters from one air quality station with CetesbRetrieveAll function.
    • 98 |
    99 |
    100 |
    102 | 103 | 104 |
    113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | --------------------------------------------------------------------------------