library(devtools)
install_github('jdtatsch/inmetr')
data_description()
varname description unit
1 date date and time information -
2 id station ID -
3 prec precipitation mm
4 tair air temperature deg C
5 tw wet bulb temperature deg C
6 tmax maximum air temperature deg C
7 tmin minimum air temperature deg C
8 urmax maximum relative humidity %
9 patm atmospheric pressure hPa
10 pnmm mean sea level atmospheric pressure hPa
11 wd wind direction deg
12 wsmax wind gust m/s
13 n sunshine hours h
14 cc cloud cover -
15 evap evaporation mm
16 ur relative humidity %
17 ws wind speed m/s
Algum tempo atrás o Alisson Lucrecio e o Éder Comunello estavam trabalhando em um tópico sobre obtenção de dados do INMET.Como precisei obter alguns dados hoje, resolvi testar o código, que por sinal funcionou perfeitamente.Como os dados são salvos em formato ```.html```, tentei montar um script organizar os dados em um ```data.frame```, assim como deixar apenas uma linha para cada dia de coletado, pois os dados do originais do INMET tem formato de duas linhas para cada dia de coleta.Segue o script com os comentários:obs: a função que ordena os dias é não tem uma boa performance, pois faz um bom tempo que fiz ela.#=========================================================== ====== # Rafael Tieppo# 29-08-2016#=========================================================== ====== ##### Goal 1### Script to sign in - INMET### Historical Data### Original Source:##### Goal 2### Ordering and filtering DATA from INMET### use oneline() function from#*********************************************************** * #*********************************************************** * # GOAL 1#*********************************************************** * #*********************************************************** * #----------------------------------------------------------- - ### Packageslibrary(RCurl)library(bitops)#----------------------------------------------------------- - #----------------------------------------------------------- - ### Logging INMET### Login link### Data link#----------------------------------------------------------- - #----------------------------------------------------------- - ### Access DatamyParams=list(mCod="EMAIL", ### alterar!mSenha="PASSWORD", ### alterar!btnProcesso = " Acessar ")#----------------------------------------------------------- - #----------------------------------------------------------- - ### Getting DatamyCurl <- getCurlHandle()curlSetOpt(cookiejar="cookies.txt", useragent="Chrome/10.0.648. 133" , followlocation=TRUE, curl=myCurl) ###"Mozilla/5.0"login <- postForm(myURL1, .params=myParams, curl=myCurl)DATA <- getURLContent(myURL2, curl=myCurl)#----------------------------------------------------------- - #*********************************************************** * #*********************************************************** * # GOAL 2#*********************************************************** * #*********************************************************** * #----------------------------------------------------------- - ### Tiding Data### Using shell script to separate DATA from text#### grep "^83309" < ESTACAO_83309.html > ESTACAO_83303_DATA.csv### Shell script, get all lines that starts with "83309" (station number)SHELL_FUN = paste("grep", "^83309", "<", "ESTACAO_83309.html",">", "ESTACAO_83303_DATA.csv",sep = ' ')###system(SHELL_FUN)DATA_83303 <- read.csv("ESTACAO_83303_DATA.csv", sep = ";", dec = ".") colnames(DATA_83303) <- c("Estacao", "Data", "Hora", "Precipitacao","TempMaxima", "TempMinima", "Insolacao","Evaporacao_Piche", "Temp_Comp_Media","UR_Media", "Vel_Vent_Media")names(DATA_83303)#----------------------------------------------------------- - #----------------------------------------------------------- - ### Organizing DATA### Data from INMET has two lines for each### To put one line for each day, use oneline() function### Calling ONE_LINE function### ATTENTION### To use oneline() is mandatory a data.frame with a specific cols data### order, as follow (names doen not matter, only sequence):### Estacao; Data; Hora; Precipitacao; TempMaxima; TempMinima;### Insolacao; Umidade Relativa Media; Velocidade do Vento Media;DATA_83303 <- DATA_83303[c(1:7,10:11)]Estacao;Data;Hora;Precipitacao;TempMaxima; TempMinima;Insolacao; Evaporacao Piche;Temp Comp Media;Umidade Relativa Media;Velocidade do Vento Media;### Ordering with oneline() functionDATA_83303_one_line <- one_line(DATA_83303)edit(DATA_83303_one_line)#----------------------------------------------------------- - Rafael Tieppo
State University of Mato Grosso - Department of Agricultural Engineering
site: http://docente.unemat.br/rafaeltieppo/ blog: https://fuidebicicleta.wordpress.com "Evite o desperdício: antes de imprimir pense na sua responsabilidade com o ambiente".
_______________________________________________
R-br mailing list
R-br@listas.c3sl.ufpr.br
https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br
Leia o guia de postagem (http://www.leg.ufpr.br/r-br-guia ) e forneça código mínimo reproduzível.