如何使用 rnoaa 下载降水数据

How to download precipitation data using rnoaa

我是 'rnoaa' R 包的新手。我想知道如何找到 stationsid 名称来识别站点。我有兴趣从威廉王子湾阿拉斯加地区下载 2011 年到 2020 年每小时或每天的降水量数据。我在这里查看:https://www.ncdc.noaa.gov/cdo-web/search 但它似乎只有 2014 年的数据。有人可以提示我使用什么 rnoaa 函数来下载所需的降雨数据吗? 我读到以下 rnoaa 函数:

cpc_prcp(date = "1998-04-23", drop_undefined = TRUE) 

但是,我不知道在函数中包含什么来获取我正在寻找的数据以及日期范围(2011 年到 2020 年)

您可以试试这个工作流程:

互联网搜索得到阿拉斯加威廉王子湾地区的经纬度。

library(rnoaa)

# create a data frame for Prince William latitude and longitude
lat_lon_df <- data.frame(id = "pw",
                         lat = 60.690545,
                         lon = -147.097055)

# find 10 closest monitors to  Prince William
mon_near_pw <- 
  meteo_nearby_stations(
  lat_lon_df = lat_lon_df,
  lat_colname = "lat",
  lon_colname = "lon",
  var = "PRCP",
  year_min = 2011,
  year_max = 2020,
  limit = 10,
)


mon_near_pw
#> $pw
#> # A tibble: 10 x 5
#>    id          name                      latitude longitude distance
#>    <chr>       <chr>                        <dbl>     <dbl>    <dbl>
#>  1 USC00501240 CANNERY CREEK                 61.0     -148.     42.9
#>  2 USC00509747 WALLY NOERENBERG HATCHERY     60.8     -148.     55.1
#>  3 USS0048L06S Esther Island                 60.8     -148.     55.3
#>  4 USC00505604 MAIN BAY                      60.5     -148.     57.6
#>  5 USS0046M04S Sugarloaf Mtn                 61.1     -146.     61.1
#>  6 USC00509687 VALDEZ                        61.1     -146.     62.4
#>  7 USW00026442 VALDEZ WSO                    61.1     -146.     63.4
#>  8 US1AKVC0005 VALDEZ 3.6 ENE                61.1     -146.     66.3
#>  9 USC00509685 VALDEZ AIRPORT                61.1     -146.     67.3
#> 10 USC00502179 CORDOVA WWTP                  60.5     -146.     74.0

# extract precipitation data for the first location
pw_prcp_dat <- 
  meteo_pull_monitors(
  monitors = mon_near_pw$pw$id[1],
  date_min = "2011-01-01",
  date_max = "2020-12-31",
  var = "PRCP"
)

head(pw_prcp_dat)
#> # A tibble: 6 x 3
#>   id          date        prcp
#>   <chr>       <date>     <dbl>
#> 1 USC00501240 2011-01-01   704
#> 2 USC00501240 2011-01-02   742
#> 3 USC00501240 2011-01-03   211
#> 4 USC00501240 2011-01-04   307
#> 5 USC00501240 2011-01-05   104
#> 6 USC00501240 2011-01-06     0

# out of curiosity have plotted monthly summary of precipitation.
# For metadata see: https://www1.ncdc.noaa.gov/pub/data/ghcn/daily/readme.txt
# PRCP = Precipitation (tenths of mm)

library(dplyr)
library(lubridate)
library(ggplot2)

pw_prcp_dat %>% 
  mutate(year = year(date),
         month = month(date)) %>%
  group_by(year, month) %>% 
  summarise(prcp = sum(prcp, na.rm = TRUE) / 10) %>% 
  ggplot(aes(factor(month), prcp))+
  geom_col()+
  facet_wrap(~year)+
  labs(y = "Precipitation [mm]",
       x = "Month")+
  theme_bw()

reprex package (v2.0.0)

于 2021-08-22 创建