clidatajp

Japan Meteorological Agency (‘JMA’) web page

‘JMA’ web page consists of some layers. You can use different function for download each component.

Climate data

I recommend to use existing data, which are already downloaded and cleaned up.

When you want to know how to prepare “data(japan_climate)”, please check url shown below.

https://github.com/matutosi/clidatajp/blob/main/data-raw/japan_climate.R

For polite scraping, 5 sec interval is set in download_climate(), it takes over 5 hours to get world climate data of all stations because of huge amount of data (3444 stations). Please use existing data by “data(world_climate)”, if you do not need to renew climate data.

  # existing data
data(japan_climate)
japan_climate %>%
  dplyr::mutate_if(is.character, stringi::stri_unescape_unicode)
#> # A tibble: 3,768 × 14
#>       no station month temperat…¹ preci…² snowf…³ insol…⁴ country period altit…⁵
#>    <dbl> <chr>   <dbl>      <dbl>   <dbl>   <dbl>   <dbl> <chr>   <chr>    <dbl>
#>  1 47401 稚内        1       -4.3    84.6     129    40.6 日本    1991-…     2.8
#>  2 47401 稚内        2       -4.3    60.6     105    74.7 日本    1991-…     2.8
#>  3 47401 稚内        3       -0.6    55.1      68   138.  日本    1991-…     2.8
#>  4 47401 稚内        4        4.5    50.3       9   174.  日本    1991-…     2.8
#>  5 47401 稚内        5        9.1    68.1       0   182.  日本    1991-…     2.8
#>  6 47401 稚内        6       13      65.8      NA   155.  日本    1991-…     2.8
#>  7 47401 稚内        7       17.2   101.       NA   143.  日本    1991-…     2.8
#>  8 47401 稚内        8       19.5   123.       NA   151.  日本    1991-…     2.8
#>  9 47401 稚内        9       17.2   137.       NA   172.  日本    1991-…     2.8
#> 10 47401 稚内       10       11.3   130.        1   135.  日本    1991-…     2.8
#> # … with 3,758 more rows, 4 more variables: latitude <dbl>, longitude <dbl>,
#> #   NS <chr>, WE <chr>, and abbreviated variable names ¹​temperature,
#> #   ²​precipitation, ³​snowfall, ⁴​insolation, ⁵​altitude

data(world_climate)
world_climate %>%
  dplyr::mutate_if(is.character, stringi::stri_unescape_unicode)
#> # A tibble: 41,328 × 11
#>       no month temperature precipi…¹ station country latit…² NS    longi…³ WE   
#>    <dbl> <dbl>       <dbl>     <dbl> <chr>   <chr>     <dbl> <chr>   <dbl> <chr>
#>  1     1     1         7.1      14.9 アイン… アルジ…    32.8 N         0.6 W    
#>  2     1     2         9.2      11.2 アイン… アルジ…    32.8 N         0.6 W    
#>  3     1     3        12.9      15.9 アイン… アルジ…    32.8 N         0.6 W    
#>  4     1     4        16.8      16.9 アイン… アルジ…    32.8 N         0.6 W    
#>  5     1     5        21.5      15   アイン… アルジ…    32.8 N         0.6 W    
#>  6     1     6        26.7       6.9 アイン… アルジ…    32.8 N         0.6 W    
#>  7     1     7        31         4.1 アイン… アルジ…    32.8 N         0.6 W    
#>  8     1     8        29.5      13.5 アイン… アルジ…    32.8 N         0.6 W    
#>  9     1     9        24.4      21   アイン… アルジ…    32.8 N         0.6 W    
#> 10     1    10        18.6      25.8 アイン… アルジ…    32.8 N         0.6 W    
#> # … with 41,318 more rows, 1 more variable: altitude <dbl>, and abbreviated
#> #   variable names ¹​precipitation, ²​latitude, ³​longitude

  # Download new data
  # If you want links for all countries and all sations, remove head().
url <- "https://www.data.jma.go.jp/gmd/cpd/monitor/nrmlist/"
res <- gracefully_fail(url)
if(!is.null(res)){
  station_links <-
    station_links %>%
    head() %>%
    `$`("url")
  climate <- list()
  for(i in seq_along(station_links)){
    print(stringr::str_c(i, " / ", length(station_links)))
    climate[[i]] <- download_climate(station_links[i])
  }
  world_climate <- dplyr::bind_rows(climate)
  world_climate
}
#> [1] "1 / 6"
#> [1] "2 / 6"
#> [1] "3 / 6"
#> [1] "4 / 6"
#> [1] "5 / 6"
#> [1] "6 / 6"
#> # A tibble: 72 × 11
#>    station     country latit…¹ NS    longi…² WE    altit…³ month tempe…⁴ preci…⁵
#>    <chr>       <chr>   <chr>   <chr> <chr>   <chr> <chr>   <dbl>   <dbl>   <dbl>
#>  1 アインセフ… アルジ… 32.77   N     0.60    W     1058        1     7.1    14.9
#>  2 アインセフ… アルジ… 32.77   N     0.60    W     1058        2     9.2    11.2
#>  3 アインセフ… アルジ… 32.77   N     0.60    W     1058        3    12.9    15.9
#>  4 アインセフ… アルジ… 32.77   N     0.60    W     1058        4    16.8    16.9
#>  5 アインセフ… アルジ… 32.77   N     0.60    W     1058        5    21.5    15  
#>  6 アインセフ… アルジ… 32.77   N     0.60    W     1058        6    26.7     6.9
#>  7 アインセフ… アルジ… 32.77   N     0.60    W     1058        7    31       4.1
#>  8 アインセフ… アルジ… 32.77   N     0.60    W     1058        8    29.5    13.5
#>  9 アインセフ… アルジ… 32.77   N     0.60    W     1058        9    24.4    21  
#> 10 アインセフ… アルジ… 32.77   N     0.60    W     1058       10    18.6    25.8
#> # … with 62 more rows, 1 more variable: url <chr>, and abbreviated variable
#> #   names ¹​latitude, ²​longitude, ³​altitude, ⁴​temperature, ⁵​precipitation