2017-07-13 19 views
0

使用weatheR包我需要來自特定站點的數據,所以我嘗試使用getStationByID funciont。 該站是格羅塔列在我station.list DF其美國空軍編號爲163240:weatheR數據包

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 

如果我啓動funcion

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

我得到了名

錯誤(合併.list)[i] < - keys [i]: 'names'屬性[1]的長度必須與向量[0]的長度相同

有什麼建議嗎?

回答

1

weatheR包似乎是一個被遺棄的項目。
查看getStationByID函數的代碼,可以認識到它不能工作。
修改後的getStationByID可用here
下載此文件並將其保存在名稱爲mygetStationByID.r的工作目錄中。
然後,使用下面的代碼:

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 

我希望它可以幫助你。

N.B.如果在第一次運行時代碼生成錯誤消息,請嘗試重新運行它。

+0

我剛剛在github頁面上打開了一個問題。軟件包創建者回答說,他將爲此工作 – andriatz

2

您可以使用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>, 
#> ... 
+0

'rnoaa'被積極維護,並有很多貢獻者 - 只是fyi – sckott

+0

謝謝你rnoaa是一個偉大的包!我有一個關於像高程或溫度等變量格式的問題:爲什麼我得到像「+0020」這樣的值?我如何解釋它? – andriatz

+0

@andriatz所以'rnoaa'是許多NOAA數據集的封裝,所以我們首先關注獲取數據和做好這些數據。然後再着重於微調數據格式等。對於ISD數據,我們正在變得更好,我們有一個sep。 pakcage https://github.com/ropensci/isdparser解析ISD數據b/c它是如此可怕的解析 - 這可能是一個提出格式問題的好地方 – sckott