andriatz
andriatz

Reputation: 622

weatheR data package

using weatheR package i need data from a specific station, so i tried to use getStationByID funciont. The station is GROTTAGLIE and in my station.list df its USAF id is 163240:

require(devtools)
install_github("mpiccirilli/weatheR")
require(weatheR)
station.list <- allStations()

station.list %>% filter(USAF==163240)


USAF     WBAN       NAME   CTRY   STATE    ICAO    LAT    LON      ELEV    BEGIN      END 
 163240   99999  GROTTAGLIE  IT           LIBG    40.518    17.403    65.5    19430927 20170710

if i launch the funcion

grottaglie<- getStationByID(stationID = '163240',station.list = station.list, begin = 2013, 2016)

i get

Error in names(combined.list)[i] <- keys[i] : 'names' attribute [1] must be the same length as the vector [0]

any suggestions?

Upvotes: 0

Views: 645

Answers (2)

Marco Sandri
Marco Sandri

Reputation: 24272

The weatheR package seems to be an abandoned project.
Looking inside the code of the getStationByID function, one can realize that it cannot work.
A modified getStationByID is available here.
Download this file and save it in the working directory with the name mygetStationByID.r.
Then, use the following code:

require(weatheR)
station.list <- allStations()

# Load the modified version of getStationByID   
source("mygetStationByID.r")
# The structure of the fixed-width files 
# downloaded from ftp://ftp.ncdc.noaa.gov/pub/data/noaa/
col.width <- c(4,6,5,8,4,1,6,7,5,5,5,4)
# Column names
col.names <- c("TOT", "USAF", "WBAN", "DATE", "TIME", "DATASOURCE",
 "LAT","LON","CODE","ELEV.DIM","CALL.LETTER","QLT.CTRL")

grottaglie <- mygetStationByID(stationID = 163240,
             station.list = station.list, begin = 2013, end=2016)

str(grottaglie)
# List of 2
#  $ dl_status   :'data.frame':   4 obs. of  4 variables:
#   ..$ File  : chr [1:4] "163240-99999-2013.gz" "163240-99999-2014.gz" "163240-99999-2015.gz" "163240-99999-2016.gz"
#   ..$ Status: chr [1:4] "Failed" "Failed" "Failed" "Failed"
#   ..$ City  : chr [1:4] "Grottaglie, Italy" "Grottaglie, Italy" "Grottaglie, Italy" "Grottaglie, Italy"
#   ..$ rank  : num [1:4] 1 1 1 1
#  $ station_data:List of 1
#   ..$ Grottaglie_163240:'data.frame':   19264 obs. of  12 variables:
#   .. ..$ TOT        : int [1:19264] 126 126 138 137 145 145 145 137 89 89 ...
#   .. ..$ USAF       : int [1:19264] 163240 163240 163240 163240 163240 163240 163240 163240 163240 163240 ...
#   .. ..$ WBAN       : int [1:19264] 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 ...
#   .. ..$ DATE       : int [1:19264] 20130101 20130101 20130101 20130101 20130101 20130101 20130101 20130101 20130101 20130101 ...
#   .. ..$ TIME       : int [1:19264] 650 750 850 950 1050 1250 1350 1450 1550 1650 ...
#   .. ..$ DATASOURCE : int [1:19264] 4 4 4 4 4 4 4 4 4 4 ...
#   .. ..$ LAT        : num [1:19264] 40.5 40.5 40.5 40.5 40.5 ...
#   .. ..$ LON        : int [1:19264] 17400 17400 17400 17400 17400 17400 17400 17400 17400 17400 ...
#   .. ..$ CODE       : Factor w/ 2 levels "FM-15","FM-16": 1 1 1 1 1 1 1 1 1 1 ...
#   .. ..$ ELEV.DIM   : int [1:19264] 69 69 69 69 69 69 69 69 69 69 ...
#   .. ..$ CALL.LETTER: Factor w/ 2 levels "99999","LIBG ": 2 2 2 2 2 2 2 2 2 2 ...
#   .. ..$ QLT.CTRL   : Factor w/ 1 level "V020": 1 1 1 1 1 1 1 1 1 1 ...

# Table by years 
table(as.numeric(substr(grottaglie$station_data[[1]]$DATE, 1, 4)))
# 2013 2014 2015 2016 
# 4866 4816 4794 4788

I hope it can help you.

N.B. If at the first run the code generates an error message, try to rerun it.

Upvotes: 1

sckott
sckott

Reputation: 5913

You can use rnoaa

install.packages("rnoaa")
library(rnoaa)
(res <- isd(usaf=163240, wban=99999, year=1986))
#> # A tibble: 7,364 x 78
#>    total_chars usaf_station wban_station     date  time date_flag latitude longitude type_code elevation
#>          <chr>        <chr>        <chr>    <chr> <chr>     <chr>    <chr>     <chr>     <chr>     <chr>
#>  1        0058       163240        99999 19860101  0032         4   +40517   +017400     FM-15     +0069
#>  2        0058       163240        99999 19860101  0100         4   +40517   +017400     FM-15     +0069
#>  3        0058       163240        99999 19860101  0208         4   +40517   +017400     FM-15     +0069
#>  4        0058       163240        99999 19860101  0308         4   +40517   +017400     FM-15     +0069
#>  5        0058       163240        99999 19860101  0408         4   +40517   +017400     FM-15     +0069
#>  6        0074       163240        99999 19860101  0508         4   +40517   +017400     FM-15     +0069
#>  7        0074       163240        99999 19860101  0610         4   +40517   +017400     FM-15     +0069
#>  8        0074       163240        99999 19860101  0710         4   +40517   +017400     FM-15     +0069
#>  9        0074       163240        99999 19860101  0810         4   +40517   +017400     FM-15     +0069
#> 10        0074       163240        99999 19860101  0910         4   +40517   +017400     FM-15     +0069
#> # ... with 7,354 more rows, and 68 more variables: call_letter <chr>, quality <chr>,
#> #   wind_direction <chr>, wind_direction_quality <chr>, wind_code <chr>, wind_speed <chr>,
#> ...

Upvotes: 2

Related Questions