├── .Rbuildignore ├── R ├── sysdata.rda ├── get_station_dates.R ├── get_distances.R ├── nearest_stations.R ├── get_station_coordinates.R ├── get_inmet_data.R ├── list_stations.R └── get_inpe_data.R ├── .gitignore ├── man ├── hello.Rd ├── inpe_station_period.Rd ├── inpe_station_coordinates.Rd ├── get_distances.Rd ├── inpe_station_data.Rd ├── inpe_stations.Rd ├── nearest_stations.Rd └── inmet_station_data.Rd ├── NAMESPACE ├── DESCRIPTION └── README.md /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | -------------------------------------------------------------------------------- /R/sysdata.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gustavobio/brclimate/HEAD/R/sysdata.rda -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | brclimate.Rproj 6 | -------------------------------------------------------------------------------- /man/hello.Rd: -------------------------------------------------------------------------------- 1 | \name{hello} 2 | \alias{hello} 3 | \title{Hello, World!} 4 | \usage{ 5 | hello() 6 | } 7 | \description{ 8 | Prints 'Hello, world!'. 9 | } 10 | \examples{ 11 | hello() 12 | } 13 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(inmet_station_data) 4 | export(inpe_station_coordinates) 5 | export(inpe_station_data) 6 | export(inpe_station_period) 7 | export(inpe_stations) 8 | export(nearest_stations) 9 | import(rvest) 10 | -------------------------------------------------------------------------------- /man/inpe_station_period.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_station_dates.R 3 | \name{inpe_station_period} 4 | \alias{inpe_station_period} 5 | \title{Get the span of the data of an INPE climate station.} 6 | \usage{ 7 | inpe_station_period(station_id = 31973) 8 | } 9 | \arguments{ 10 | \item{station_id}{A numeric vector with the station id.} 11 | } 12 | \value{ 13 | A character vector. 14 | } 15 | \description{ 16 | Get the span of the data of an INPE climate station. 17 | } 18 | 19 | -------------------------------------------------------------------------------- /man/inpe_station_coordinates.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_station_coordinates.R 3 | \name{inpe_station_coordinates} 4 | \alias{inpe_station_coordinates} 5 | \title{Get the geographical coordinates of a climate station (INPE only so far)} 6 | \usage{ 7 | inpe_station_coordinates(station_id = 31973) 8 | } 9 | \arguments{ 10 | \item{station_id}{A numeric vector with the station id} 11 | } 12 | \value{ 13 | A named numeric vector 14 | } 15 | \description{ 16 | Get the geographical coordinates of a climate station (INPE only so far) 17 | } 18 | 19 | -------------------------------------------------------------------------------- /R/get_station_dates.R: -------------------------------------------------------------------------------- 1 | #' Get the span of the data of an INPE climate station. 2 | #' 3 | #' @param station_id A numeric vector with the station id. 4 | #' @return A character vector. 5 | #' @export 6 | inpe_station_period <- function(station_id = 31973) { 7 | dates <- rvest::html_session(paste("http://sinda.crn.inpe.br/PCD/SITE/novo/site/historico/passo2.php?id=", station_id, sep = "")) %>% 8 | rvest::html_nodes(xpath = "//form//b") %>% 9 | rvest::html_text() 10 | if (length(dates) == 0L) { 11 | message("Station not found") 12 | return(NA) 13 | } 14 | setNames(as.Date(dates), c("start", "end")) 15 | } 16 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: brclimate 2 | Type: Package 3 | Title: Scrape Brazilian Historical Climate Data 4 | Version: 0.1.0 5 | Authors@R: person("Gustavo", "Carvalho", email = "gustavo.bio@gmail.com", role = c("aut", "cre")) 6 | Description: Get historical climate data from over 1000 climate stations located 7 | in Brazil. The package include a set of tools for 8 | scraping data from INPE (http: //sinda.crn2.inpe.br/PCD/SITE/novo/site/ 9 | index.php) and INMET (http://www.inmet.gov.br/portal/) 10 | License: GPL 11 | LazyData: TRUE 12 | RoxygenNote: 5.0.1 13 | Imports: rvest, 14 | httr, 15 | tidyr, 16 | dplyr 17 | Depends: R (>= 3.2.4) 18 | -------------------------------------------------------------------------------- /man/get_distances.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_distances.R 3 | \name{get_distances} 4 | \alias{get_distances} 5 | \title{Get the distance in kilometers between two points.} 6 | \usage{ 7 | get_distances(lat1, long1, lat2, long2) 8 | } 9 | \arguments{ 10 | \item{lat1}{Latitude in decimals} 11 | 12 | \item{long1}{Longitude in decimals} 13 | 14 | \item{lat2}{Latitude in decimals} 15 | 16 | \item{long2}{Longitude in decimals} 17 | } 18 | \value{ 19 | A numeric vector with the distance in kilometers. 20 | } 21 | \description{ 22 | Get the distance in kilometers between two points. 23 | } 24 | 25 | -------------------------------------------------------------------------------- /man/inpe_station_data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_inpe_data.R 3 | \name{inpe_station_data} 4 | \alias{inpe_station_data} 5 | \title{Get climate data from stations INPE} 6 | \usage{ 7 | inpe_station_data(station_id = 31973, start_date = "2005/01/01", 8 | end_date = "2005/02/02") 9 | } 10 | \arguments{ 11 | \item{station_id}{A numeric vector with the station id.} 12 | 13 | \item{start_date}{Start date.} 14 | 15 | \item{end_date}{End date (Maximum of one year between start and end dates).} 16 | } 17 | \value{ 18 | A data frame containing the climate data and attributes. 19 | } 20 | \description{ 21 | Get climate data from stations INPE 22 | } 23 | 24 | -------------------------------------------------------------------------------- /man/inpe_stations.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/list_stations.R 3 | \name{inpe_stations} 4 | \alias{inmet_stations} 5 | \alias{inpe_stations} 6 | \title{List all available climate stations} 7 | \usage{ 8 | inpe_stations(states = "all") 9 | 10 | inmet_stations(username, password, states = "all") 11 | } 12 | \arguments{ 13 | \item{states}{A character vector with abbreviated Brazilian states names or "all" for all PCDs.} 14 | 15 | \item{username}{INMET username. Only used if you are querying INMET.} 16 | 17 | \item{password}{INMET password.} 18 | } 19 | \value{ 20 | A data frame. 21 | } 22 | \description{ 23 | List all available climate stations 24 | } 25 | 26 | -------------------------------------------------------------------------------- /man/nearest_stations.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/nearest_stations.R 3 | \name{nearest_stations} 4 | \alias{nearest_stations} 5 | \title{Order climate stations by their distances in kilometers from a given point.} 6 | \usage{ 7 | nearest_stations(lat = -22.410259, long = -47.560156, source = "both") 8 | } 9 | \arguments{ 10 | \item{lat}{Latitude in decimals.} 11 | 12 | \item{long}{Longitude in decimals.} 13 | 14 | \item{source}{"inpe", "inmet", or "both" (default).} 15 | } 16 | \value{ 17 | A data frame ordered by the distances to the stations. 18 | } 19 | \description{ 20 | Order climate stations by their distances in kilometers from a given point. 21 | } 22 | 23 | -------------------------------------------------------------------------------- /man/inmet_station_data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_inmet_data.R 3 | \name{inmet_station_data} 4 | \alias{inmet_station_data} 5 | \title{Get climate data from INMET} 6 | \usage{ 7 | inmet_station_data(station_id = 83726, start_date = "01/01/1901", 8 | end_date = "13/04/2016", interval = "monthly", username, password) 9 | } 10 | \arguments{ 11 | \item{station_id}{The ID of the station.} 12 | 13 | \item{start_date}{Start date.} 14 | 15 | \item{end_date}{End date.} 16 | 17 | \item{username}{INMET username.} 18 | 19 | \item{password}{INMET password.} 20 | 21 | \item{intervale}{daily or monthly (default) data?} 22 | } 23 | \description{ 24 | Get climate data from INMET 25 | } 26 | 27 | -------------------------------------------------------------------------------- /R/get_distances.R: -------------------------------------------------------------------------------- 1 | #' Get the distance in kilometers between two points. 2 | #' 3 | #' @param lat1 Latitude in decimals 4 | #' @param long1 Longitude in decimals 5 | #' @param lat2 Latitude in decimals 6 | #' @param long2 Longitude in decimals 7 | #' @return A numeric vector with the distance in kilometers. 8 | #' 9 | get_distances <- function(lat1, long1, lat2, long2) { 10 | deg2rad <- function(deg) { 11 | return(deg * (pi/180)) 12 | } 13 | R <- 6371; # Radius of the earth in km 14 | d_lat <- deg2rad(lat2 - lat1) 15 | d_long <- deg2rad(long2 - long1) 16 | a <- 17 | sin(d_lat/2) * sin(d_lat/2) + 18 | cos(deg2rad(lat1)) * cos(deg2rad(lat2)) * 19 | sin(d_long/2) * sin(d_long/2) 20 | c1 <- 2 * atan2(sqrt(a), sqrt(1-a)) 21 | d <- R * c1; # Distance in km 22 | return(d) 23 | } 24 | -------------------------------------------------------------------------------- /R/nearest_stations.R: -------------------------------------------------------------------------------- 1 | #' Order climate stations by their distances in kilometers from a given point. 2 | #' 3 | #' @param lat Latitude in decimals. 4 | #' @param long Longitude in decimals. 5 | #' @param source "inpe", "inmet", or "both" (default). 6 | #' @return A data frame ordered by the distances to the stations. 7 | #' @export 8 | nearest_stations <- function(lat = -22.410259, long = -47.560156, source = "both") { 9 | distances <- apply(stations[, c("lat", "long")], 1, function(x) get_distances(lat, long, x[1], x[2])) 10 | source <- match.arg(source, choices = c("both", "inpe", "inmet")) 11 | ordered_stations <- data.frame(stations, distance = distances) 12 | ordered_stations <- ordered_stations[order(ordered_stations$distance), ] 13 | if (source != "both") ordered_stations <- ordered_stations[ordered_stations$source %in% source, ] 14 | ordered_stations 15 | } -------------------------------------------------------------------------------- /R/get_station_coordinates.R: -------------------------------------------------------------------------------- 1 | #' Get the geographical coordinates of a climate station (INPE only so far) 2 | #' 3 | #' @param station_id A numeric vector with the station id 4 | #' @return A named numeric vector 5 | #' @export 6 | inpe_station_coordinates <- function(station_id = 31973) { 7 | calendar_page <- rvest::html_session(paste("http://sinda.crn.inpe.br/PCD/SITE/novo/site/historico/passo2.php?id=", station_id, sep = "")) 8 | source_code <- httr::content(calendar_page$response, as = "text") 9 | matches <- regexec("Latitude\\:.*Longitude\\:.*\\, Altitude", source_code) 10 | if (matches == -1) { 11 | message("No available coordinates") 12 | return(NA) 13 | } 14 | coordinates <- regmatches(source_code, matches) 15 | coordinates <- gsub("[A-z]|\\s|\\:", "", coordinates) 16 | coordinates <- gsub("\\,$", "", coordinates) 17 | coordinates <- as.numeric(strsplit(coordinates, "\\,")[[1]]) 18 | if (any(is.na(coordinates))) { 19 | message("No available coordinates.") 20 | return(NA) 21 | } 22 | names(coordinates) <- c("lat", "long") 23 | coordinates 24 | } 25 | -------------------------------------------------------------------------------- /R/get_inmet_data.R: -------------------------------------------------------------------------------- 1 | #' Get climate data from INMET 2 | #' 3 | #' @param station_id The ID of the station. 4 | #' @param start_date Start date. 5 | #' @param end_date End date. 6 | #' @param intervale daily or monthly (default) data? 7 | #' @param username INMET username. 8 | #' @param password INMET password. 9 | #' @export 10 | inmet_station_data <- function(station_id = 83726, start_date = "01/01/1901", end_date = "13/04/2016", interval = "monthly", username, password) { 11 | auth_page <- rvest::html_session( 12 | "http://www.inmet.gov.br/projetos/rede/pesquisa/inicio.php" 13 | ) 14 | auth_form <- auth_page %>% rvest::html_node("form") %>% html_form() 15 | filled_auth_form <- rvest::set_values(auth_form, 16 | mCod = username, 17 | mSenha = password 18 | ) 19 | session <- rvest::submit_form(auth_page, filled_auth_form) 20 | base_url <- "http://www.inmet.gov.br/projetos/rede/pesquisa/" 21 | interval <- match.arg(interval, c("monthly", "daily")) 22 | if (interval == "monthly") { 23 | method <- "gera_serie_txt_mensal.php?" 24 | query_string <- paste("mRelEstacao=", 25 | station_id, 26 | "&btnProcesso=serie&mRelDtInicio=", 27 | start_date, 28 | "&mRelDtFim=", 29 | end_date, 30 | "&mAtributos=,,,,,,,1,1,1,,1,1,1,1,1,", sep = "") 31 | } else { 32 | method <- "gera_serie_txt.php?" 33 | query_string <- paste("&mRelEstacao=", 34 | station_id, 35 | "&btnProcesso=serie&mRelDtInicio=", 36 | start_date, 37 | "&mRelDtFim=", 38 | end_date, 39 | "&mAtributos=,,1,1,,,,,,1,1,,1,1,1,1,", sep = "") 40 | } 41 | col_classes <- c(rep(NA, 11), "NULL") 42 | col_classes[3] <- "character" 43 | response <- session %>% 44 | jump_to(paste(base_url, method, query_string, sep = "")) %>% 45 | rvest::html_nodes(xpath = "//pre") %>% 46 | rvest::html_text() 47 | climate_data <- readLines(textConnection(response), warn = FALSE) 48 | lat <- gsub(".*\\:\\s", "", climate_data[5]) # This is kinda ugly, but I'm lazy. 49 | long <- gsub(".*\\:\\s", "", climate_data[6]) 50 | station_name <- trimws(gsub("^\\w*\\s*\\:", "", climate_data[4])) 51 | structure(read.csv2(text = climate_data, skip = 16, dec = ".", sep = ";", 52 | colClasses = col_classes), 53 | lat = lat, long = long, station_name = station_name) 54 | } 55 | -------------------------------------------------------------------------------- /R/list_stations.R: -------------------------------------------------------------------------------- 1 | #' List all available climate stations 2 | #' 3 | #' @param username INMET username. Only used if you are querying INMET. 4 | #' @param password INMET password. 5 | #' @param states A character vector with abbreviated Brazilian states names or "all" for all PCDs. 6 | #' @return A data frame. 7 | #' @export 8 | #' @import rvest 9 | inpe_stations <- function(states = "all") { 10 | calendar_page <- rvest::html_session("http://sinda.crn.inpe.br/PCD/SITE/novo/site/historico/index.php") 11 | stations <- calendar_page %>% 12 | rvest::html_nodes(xpath = "//form//option") %>% 13 | rvest::html_text() 14 | stations <- strsplit(stations, "\\-") 15 | stations <- lapply(stations, function(x) c(x[1:2], paste(x[-c(1:2)], collapse = "-"))) 16 | stations <- do.call(rbind.data.frame, stations) 17 | names(stations) <- c("ID", "state", "locality") 18 | stations$ID <- as.numeric(as.character(stations$ID)) 19 | if ("all" %in% states) { 20 | return(stations) 21 | } else { 22 | return(stations[stations$state %in% toupper(states), ]) 23 | } 24 | } 25 | 26 | #' @rdname inpe_stations 27 | inmet_stations <- function(username, password, states = "all") { 28 | auth_page <- rvest::html_session( 29 | "http://www.inmet.gov.br/projetos/rede/pesquisa/inicio.php" 30 | ) 31 | auth_form <- auth_page %>% rvest::html_node("form") %>% html_form() 32 | filled_auth_form <- rvest::set_values(auth_form, 33 | mCod = username, 34 | mSenha = password 35 | ) 36 | session <- rvest::submit_form(auth_page, filled_auth_form) 37 | response <- session %>% 38 | jump_to("http://www.inmet.gov.br/projetos/rede/pesquisa/mapas_mensal_sem.php?&mOpcaoAtrib11=1") %>% 39 | rvest::html_nodes(xpath = "//script") %>% 40 | rvest::html_text() 41 | raw_page <- readLines(textConnection(response), warn = FALSE) 42 | raw_names <- raw_page[grep("font", raw_page)] 43 | stations <- regmatches(raw_names, regexec("(?<=).+?(?=
)", raw_names, perl = TRUE)) 44 | stations <- gsub("Estacao: ", "", stations) 45 | coordinates <- regmatches(raw_names, regexec("Latitude:.*altitude", raw_names)) 46 | coordinates <- gsub("
", "", coordinates) 47 | coordinates <- gsub(" altitude", "", coordinates) 48 | coordinates <- gsub("Latitude: ", "", coordinates) 49 | coordinates <- gsub("Longitude: ", "", coordinates) 50 | coordinates <- trimws(coordinates) 51 | coordinates <- gsub("\\s+", " ", coordinates) 52 | coordinates <- gsub(" ", "|", coordinates) 53 | coordinates <- separate(data.frame(coordinates = coordinates), coordinates, c("lat", "long"), sep = "\\|", convert = TRUE) 54 | stations <- separate(data.frame(station = stations), station, c("ID", "locality", "state"), sep = "-", convert = TRUE) 55 | stations$locality <- trimws(stations$locality) 56 | stations$state <- trimws(stations$state) 57 | stations <- data.frame(stations, coordinates) 58 | if ("all" %in% states) { 59 | return(stations) 60 | } else { 61 | return(stations[stations$state %in% toupper(states), ]) 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /R/get_inpe_data.R: -------------------------------------------------------------------------------- 1 | #' Get climate data from stations INPE 2 | #' 3 | #' @param station_id A numeric vector with the station id. 4 | #' @param start_date Start date. 5 | #' @param end_date End date (Maximum of one year between start and end dates). 6 | #' @return A data frame containing the climate data and attributes. 7 | #' @export 8 | inpe_station_data <- function(station_id = 31973, start_date = "2005/01/01", end_date = "2005/02/02") { 9 | if (!station_id %in% stations$ID[stations$source %in% "inpe"]) stop("Couldn't find any station with the provided ID.") 10 | start_date <- as.Date(start_date) 11 | end_date <- as.Date(end_date) 12 | station_timeframe <- inpe_station_period(station_id = station_id) 13 | if (start_date > end_date) {stop("Impossible dates.")} # Better this. 14 | if (start_date < station_timeframe["start"] | start_date > station_timeframe["end"]) { 15 | message(paste("No data for the provided start date. Beginning to query from ", station_timeframe["start"], ".")) 16 | start_date <- station_timeframe["start"] 17 | } 18 | if (end_date > station_timeframe["end"] | end_date < station_timeframe["start"]) { 19 | message(paste("No data for the provided end date. Ending query on ", station_timeframe["end"], ".")) 20 | end_date <- station_timeframe["end"] 21 | } 22 | if ((end_date - start_date) > 365) { 23 | timeframe <- seq(start_date, end_date, by = "year") 24 | if (timeframe[length(timeframe)] != end_date) timeframe <- c(timeframe, end_date) 25 | start_dates <- c(timeframe[1], timeframe[2:(length(timeframe) - 1)] + 1) 26 | end_dates <- c(timeframe[2:length(timeframe)]) 27 | } else { 28 | start_dates <- start_date 29 | end_dates <- end_date 30 | } 31 | # The website only accepts queries < 365 days, so I have to split the timeframe in 32 | # 12 month intervals when needed. 33 | get_partial_climate <- function(start_date, end_date) { 34 | calendar_page <- rvest::html_session( 35 | paste("http://sinda.crn.inpe.br/PCD/SITE/novo/site/historico/passo2.php?id=", station_id, sep = "") 36 | ) 37 | form <- calendar_page %>% rvest::html_node("form") %>% html_form() 38 | form_completed <- rvest::set_values(form, 39 | dia_inicial = format(start_date, "%d"), 40 | mes_inicial = format(start_date, "%m"), 41 | ano_inicial = format(start_date, "%Y"), 42 | dia_final = format(end_date, "%d"), 43 | mes_final = format(end_date, "%m"), 44 | ano_final = format(end_date, "%Y") 45 | ) 46 | r <- rvest::submit_form(calendar_page, form_completed) 47 | if (httr::headers(r)$`content-type` != "application/vnd.ms-excel; charset=utf-8") { 48 | message("No data for the selected period.") 49 | return(NA) 50 | } 51 | temp_file <- tempfile() 52 | writeBin(httr::content(r$response), temp_file) 53 | raw_page <- xml2::read_html(readChar(temp_file, nchars = 10^7L)) 54 | fields <- raw_page %>% 55 | rvest::html_nodes(xpath = "//tr//td//b") %>% 56 | rvest::html_text() 57 | processed_page <- raw_page %>% 58 | rvest::html_nodes(xpath = "//tr//td") %>% 59 | rvest::html_text() 60 | n_fields <- length(fields) 61 | indexes <- mapply(seq, (n_fields + 1):(n_fields * 2), length(processed_page), by = n_fields) 62 | climate <- data.frame(matrix(processed_page[c(indexes)], ncol = n_fields), stringsAsFactors = FALSE) 63 | names(climate) <- gsub("\\s*\\(.*\\)", "", fields) 64 | climate <- tidyr::separate(climate, DataHora, c("Data", "Hora"), sep = " ") 65 | climate <- do.call(cbind.data.frame, list(lapply(climate, type.convert, as.is = TRUE), stringsAsFactors = FALSE)) 66 | structure(climate, fields = fields) 67 | } 68 | climate <- do.call(rbind.data.frame, 69 | mapply(get_partial_climate, start_date = start_dates, end_date = end_dates, SIMPLIFY = FALSE)) 70 | climate[order(climate$Data, climate$Hora, decreasing = FALSE), ] 71 | } 72 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # brclimate 2 | 3 | This R package includes a set of tools for scraping climate data from INPE http://sinda.crn2.inpe.br/PCD/SITE/novo/site/index.php and INMET http://www.inmet.gov.br/portal/. The code here can become outdated quickly due to changes in the source, so please fork it and submit a pull request if you fix anything locally. 4 | 5 | ## Installation 6 | ```coffee 7 | ## You will need to install the latest R version. You will also need Rtools if 8 | ## running Windows. 9 | install.packages("devtools") 10 | devtools::install_github("gustavobio/brclimate") 11 | ``` 12 | 13 | ## Usage: 14 | 15 | List all INPE climate stations: 16 | ```coffee 17 | inpe_stations() 18 | ID state locality 19 | 1 32105 AC Assis Brasil 20 | 2 32392 AC Brasileia 21 | 3 32383 AC Cruzeiro do Sul 22 | 4 32076 AC Cruzeiro do Sul 23 | 5 32106 AC Fazenda Santo Afonso 24 | 6 32083 AC Feijo 25 | ... 26 | ID state locality 27 | 997 30870 TO Rio Santo Antonio 28 | 998 30873 TO Rio Sao Martinho 29 | 999 30869 TO Rio Urubu 30 | 1000 32307 TO Tocantinopolis 31 | 1001 32549 TO UHE Isamu Ikeda Montante 32 | 1002 32619 TO Xambioa 33 | ``` 34 | 35 | List all INMET climate stations: 36 | ```coffee 37 | inmet_stations(username, password) 38 | ID locality state lat long 39 | 1 82294 ACARAU CE -2.88 -40.13 40 | 2 82989 AGUA BRANCA AL -9.28 -37.90 41 | 3 83595 AIMORES MG -19.49 -41.07 42 | 4 83249 ALAGOINHAS BA -12.28 -38.54 43 | 5 82353 ALTAMIRA PA -3.21 -52.21 44 | 6 82970 ALTO PARNAIBA MA -9.10 -45.93 45 | ... 46 | ID locality state lat long 47 | 260 82870 VALE DO GURGUEIA (CRISTIANO CASTRO) PI -8.41 -43.71 48 | 261 83642 VICOSA MG -20.75 -42.85 49 | 262 83648 VITORIA ES -20.31 -40.31 50 | 263 83344 VITORIA DA CONQUISTA BA -14.88 -40.79 51 | 264 83623 VOTUPORANGA SP -20.41 -49.98 52 | 265 82376 ZE DOCA MA -3.26 -45.65 53 | ``` 54 | 55 | Get the coordinates of a given station (INPE only so far): 56 | ```coffee 57 | inpe_station_coordinates(station_id = 31973) 58 | lat long 59 | -22.169 -47.893 60 | ``` 61 | 62 | Order stations by their distances to a given coordinate: 63 | ```coffee 64 | nearest_stations(lat = -22.41, long = -42.01, source = "both") 65 | ID state locality lat long source distance 66 | 705 31956 RJ Santa Maria Madalena -21.953 -42.005 inpe 50.81869 67 | 1209 83718 RJ CORDEIRO -22.010 -42.350 inmet 56.59830 68 | 708 31954 RJ Teresopolis -22.407 -42.793 inpe 80.49186 69 | 707 32655 RJ Sao Fidelis -21.650 -41.750 inpe 88.65575 70 | 706 32656 RJ Santo Antonio de Padua -21.533 -42.183 inpe 99.13623 71 | 1208 83698 RJ CAMPOS -21.750 -41.330 inmet 101.46529 72 | ... 73 | ``` 74 | ```coffee 75 | nearest_stations(lat = -22.41, long = -42.01, source = "inpe") 76 | ID state locality lat long source distance 77 | 705 31956 RJ Santa Maria Madalena -21.953 -42.005 inpe 50.81869 78 | 708 31954 RJ Teresopolis -22.407 -42.793 inpe 80.49186 79 | 707 32655 RJ Sao Fidelis -21.650 -41.750 inpe 88.65575 80 | 706 32656 RJ Santo Antonio de Padua -21.533 -42.183 inpe 99.13623 81 | 433 32510 MG Leopoldina -21.468 -42.723 inpe 127.98307 82 | 695 69151 RJ Baia de Guanabara -22.891 -43.145 inpe 128.16467 83 | ``` 84 | ```coffee 85 | nearest_stations(lat = -22.41, long = -42.01, source = "inmet") 86 | ID state locality lat long source distance 87 | 1209 83718 RJ CORDEIRO -22.01 -42.35 inmet 56.5983 88 | 1208 83698 RJ CAMPOS -21.75 -41.33 inmet 101.4653 89 | 1212 83743 RJ RIO DE JANEIRO -22.88 -43.18 inmet 130.9486 90 | 1210 83695 RJ ITAPERUNA -21.20 -41.90 inmet 135.0242 91 | 1207 83049 RJ AVELAR (P.DO ALFERES) -22.35 -43.41 inmet 144.1015 92 | 1121 83692 MG JUIZ DE FORA -21.76 -43.35 inmet 155.8410 93 | ``` 94 | 95 | Get the data: 96 | ```coffee 97 | inpe_station_data(station_id = 31973, start_date = "2005/01/01", end_date = "2007/02/02") 98 | Data Hora Bateria ContAguaSolo100 ContAguaSolo200 ContAguaSolo400 CorrPSol DirVelVentoMax DirVento Pluvio PressaoAtm RadSolAcum TempAr TempMax TempMin TempSolo100 TempSolo200 TempSolo400 UmidInt UmidRel VelVento10m VelVentoMax 99 | 252 2005-01-01 00:00:00 12.5 0.45 0.48 0.48 0 150 140 0 929 0 16.5 33.5 10.5 22 23 23 0 76 1.6 6.2 100 | 251 2005-01-01 03:00:00 12.5 0.45 0.48 0.48 0 150 170 0 928 0 16.0 33.5 10.5 22 23 23 0 84 2.9 6.2 101 | 250 2005-01-01 06:00:00 12.5 0.45 0.48 0.48 0 150 140 0 929 0 16.5 33.5 10.5 22 23 23 0 76 1.6 6.2 102 | 249 2005-01-01 09:00:00 NA NA 0.00 NA NA NA 140 0 929 0 16.5 NA NA NA NA 0 NA 76 1.6 NA 103 | 248 2005-01-01 12:00:00 12.5 0.45 0.48 0.48 0 150 140 0 929 0 16.5 33.5 10.5 22 23 23 0 76 1.6 6.2 104 | 247 2005-01-01 15:00:00 12.5 0.45 0.48 0.48 0 150 140 0 929 0 16.5 33.5 10.5 22 23 23 0 76 1.6 6.2 105 | 246 2005-01-01 18:00:00 12.5 0.45 0.48 0.48 0 150 140 0 929 0 16.5 33.5 10.5 22 23 23 0 76 1.6 6.2 106 | 245 2005-01-01 21:00:00 12.5 0.45 0.48 0.48 0 150 140 0 929 0 16.5 33.5 10.5 22 23 23 0 76 1.6 6.2 107 | 244 2005-01-02 00:00:00 12.5 0.45 0.48 0.48 0 150 140 0 929 0 16.5 33.5 10.5 22 23 23 0 76 1.6 6.2 108 | 243 2005-01-02 03:00:00 12.5 0.45 0.48 0.48 0 150 140 0 929 0 16.5 33.5 10.5 22 23 23 0 76 1.6 6.2 109 | 242 2005-01-02 06:00:00 12.5 0.45 0.48 0.48 0 150 140 0 929 0 16.5 33.5 10.5 22 23 23 0 76 1.6 6.2 110 | 241 2005-01-02 09:00:00 12.5 0.45 0.48 0.48 0 150 140 0 929 0 16.5 33.5 10.5 22 23 23 0 76 1.6 6.2 111 | 240 2005-01-02 12:00:00 12.5 0.45 0.48 0.48 0 150 140 0 929 0 16.5 33.5 10.5 22 23 23 0 76 1.6 6.2 112 | 239 2005-01-02 15:00:00 12.5 0.45 0.48 0.48 0 150 140 0 929 0 16.5 33.5 10.5 22 23 23 0 76 1.6 6.2 113 | 238 2005-01-02 18:00:00 12.5 0.45 0.48 0.48 0 150 140 0 929 0 16.5 33.5 10.5 22 23 23 0 76 1.6 6.2 114 | 237 2005-01-02 21:00:00 12.5 0.45 0.48 0.48 0 150 140 0 929 0 16.5 33.5 10.5 22 23 23 0 76 1.6 6.2 115 | 236 2005-01-03 00:00:00 12.5 0.45 0.48 0.48 0 150 140 0 929 0 16.5 33.5 10.5 22 23 23 0 76 1.6 6.2 116 | 235 2005-01-03 03:00:00 12.5 0.45 0.48 0.48 0 150 140 0 929 0 16.5 33.5 10.5 22 23 23 0 76 1.6 6.2 117 | 234 2005-01-03 06:00:00 12.5 0.45 0.48 0.48 0 150 140 0 929 0 16.5 33.5 10.5 22 23 23 0 76 1.6 6.2 118 | 233 2005-01-03 09:00:00 12.5 0.45 0.48 0.48 0 150 140 0 929 0 16.5 33.5 10.5 22 23 23 0 76 1.6 6.2 119 | 232 2005-01-03 12:00:00 12.5 0.45 0.48 0.48 0 150 140 0 929 0 16.5 33.5 10.5 22 23 23 0 76 1.6 6.2 120 | 231 2005-01-03 15:00:00 12.5 0.45 0.48 0.48 0 150 170 0 928 0 16.0 33.5 10.5 22 23 23 0 84 2.9 6.2 121 | ``` 122 | 123 | ```coffee 124 | inmet_station_data(station_id = 83726, username = username, password = password) 125 | Estacao Data Hora NebulosidadeMedia NumDiasPrecipitacao PrecipitacaoTotal PressaoMedia TempMaximaMedia TempCompensadaMedia TempMinimaMedia UmidadeRelativaMedia 126 | 1 83726 31/01/1961 0000 6.586957 19 186.7 915.3217 26.86129 22.05742 17.93548 86.25000 127 | 2 83726 28/02/1961 0000 6.571429 25 284.6 917.2940 26.65357 21.81071 17.80357 81.77679 128 | 3 83726 31/03/1961 0000 5.408602 14 177.0 918.1570 27.63871 22.20000 17.32258 74.69355 129 | 4 83726 30/04/1961 0000 4.866667 8 53.1 918.5633 26.77000 21.37133 16.36333 72.09167 130 | 5 83726 31/05/1961 0000 4.010753 6 78.0 920.5935 24.67097 18.95613 13.53871 70.51613 131 | 6 83726 30/06/1961 0000 4.133333 3 5.0 922.1756 23.59000 18.08667 13.01333 66.82500 132 | ``` 133 | --------------------------------------------------------------------------------