Title: | Data from Japan Meteorological Agency |
---|---|
Description: | Includes climate data from Japan Meteorological Agency ('JMA') <https://www.jma.go.jp/jma/indexe.html>. Can download climate data from 'JMA'. |
Authors: | Toshikazu Matsumura [aut, cre] |
Maintainer: | Toshikazu Matsumura <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.5.2.9000 |
Built: | 2025-02-06 03:11:01 UTC |
Source: | https://github.com/matutosi/clidatajp |
Wrapper function to convert into numeric without warnings
as_numeric_without_warnings(x)
as_numeric_without_warnings(x)
x |
A string. |
A numeric or NA.
Helper function for download_climate().
clean_station(station)
clean_station(station)
station |
A String of station information. |
A tibble including station information.
data(station_links) station_links %>% head(1) %>% `$`("station") %>% stringi::stri_unescape_unicode() %>% clean_station()
data(station_links) station_links %>% head(1) %>% `$`("station") %>% stringi::stri_unescape_unicode() %>% clean_station()
Climate data downloaded from Japan Meteorological Agency web pages. URLs of each station are listed in data(station_links). https://www.data.jma.go.jp/gmd/cpd/monitor/nrmlist/
climate_jp japan_climate
climate_jp japan_climate
A data frame with 3768 (157 stations * 12 months * 2 periods) rows and 14 variable:
Station no
Month
Period of observations
Mean temperature
Mean precipitation
Mean snowfall
Mean insolation
Station name. To avoid duplication, including country name after station name. Can split by "_". Escaped by stringi::stri_escape_unicode().
Country name. Escaped by stringi::stri_escape_unicode().
Latitude. (degree)
North or South.
Longitude. (degree)
West or East.
Altitude (m)
An object of class tbl_df
(inherits from tbl
, data.frame
) with 3768 rows and 14 columns.
library(magrittr) library(stringi) library(dplyr) data(japan_climate) japan_climate %>% dplyr::mutate_all(stringi::stri_unescape_unicode)
library(magrittr) library(stringi) library(dplyr) data(japan_climate) japan_climate %>% dplyr::mutate_all(stringi::stri_unescape_unicode)
Climate data downloaded from Japan Meteorological Agency web pages. URLs of each station are listed in data(station_links). https://www.data.jma.go.jp/gmd/cpd/monitor/nrmlist/
climate_world world_climate
climate_world world_climate
A data frame with 41328 (3444 stations * 12 months) rows and 12 variable:
Station no
Continent. Escaped by stringi::stri_escape_unicode().
Country name. Escaped by stringi::stri_escape_unicode().
Station name. To avoid duplication, including country name after station name. Can split by "_". Escaped by stringi::stri_escape_unicode().
Month
Mean temperature
Mean precipitation
Latitude. (degree)
North or South.
Longitude. (degree)
West or East.
Altitude (m)
An object of class tbl_df
(inherits from tbl
, data.frame
) with 41328 rows and 12 columns.
library(magrittr) library(stringi) library(dplyr) data(world_climate) world_climate %>% dplyr::mutate_all(stringi::stri_unescape_unicode)
library(magrittr) library(stringi) library(dplyr) data(world_climate) world_climate %>% dplyr::mutate_all(stringi::stri_unescape_unicode)
For polite scraping, 5 sec interval is set in download_climate(), it takes over 5 hours to get climate data of all stations. Please use existing links by "data(climate_world)", if you do not need to renew climate data. You can see web page as below. https://www.data.jma.go.jp/gmd/cpd/monitor/nrmlist/
download_climate(url)
download_climate(url)
url |
A String to specify target html. |
A tibble including climate and station information, or NULL when failed.
# If you want all climate data, remove head(). # The codes take > 5 sec because of poliste scraping. library(magrittr) library(stringi) library(dplyr) data(station_links) station_links <- station_links %>% dplyr::mutate_all(stringi::stri_unescape_unicode) %>% head(3) %T>% { continent <<- `$`(., "continent") no <<- `$`(., "no") } %>% `$`("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]) } # run only when download_climate() successed if(sum(is.null(climate[[1]]), is.null(climate[[2]]), is.null(climate[[3]])) == 0){ month_per_year <- 12 climate_world <- dplyr::bind_rows(climate) %>% dplyr::bind_cols( tibble::tibble(continent = rep(continent, month_per_year))) %>% dplyr::bind_cols( tibble::tibble(no = rep(no, month_per_year))) %>% dplyr::relocate(no, continent, country, station) climate_world }
# If you want all climate data, remove head(). # The codes take > 5 sec because of poliste scraping. library(magrittr) library(stringi) library(dplyr) data(station_links) station_links <- station_links %>% dplyr::mutate_all(stringi::stri_unescape_unicode) %>% head(3) %T>% { continent <<- `$`(., "continent") no <<- `$`(., "no") } %>% `$`("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]) } # run only when download_climate() successed if(sum(is.null(climate[[1]]), is.null(climate[[2]]), is.null(climate[[3]])) == 0){ month_per_year <- 12 climate_world <- dplyr::bind_rows(climate) %>% dplyr::bind_cols( tibble::tibble(continent = rep(continent, month_per_year))) %>% dplyr::bind_cols( tibble::tibble(no = rep(no, month_per_year))) %>% dplyr::relocate(no, continent, country, station) climate_world }
For polite scraping, 5 sec interval is set in download_links(), it takes about 15 minutes to get all station links. Please use existing links by "data(station_links)", if you do not need to renew links. You can see web page as below. https://www.data.jma.go.jp/gmd/cpd/monitor/nrmlist/
download_area_links( url = "https://www.data.jma.go.jp/gmd/cpd/monitor/nrmlist/" ) download_links(url)
download_area_links( url = "https://www.data.jma.go.jp/gmd/cpd/monitor/nrmlist/" ) download_links(url)
url |
A String to specify target html. |
A string vector of url links, or NULL when failed.
# If you want links for all countries and all sations, remove head(). # The codes take over 5 sec because of poliste scraping. library(magrittr) library(stringi) library(dplyr) library(tibble) area_links <- download_area_links() station_links <- NULL continent <- NULL continents <- c("\\u30a2\\u30d5\\u30ea\\u30ab", "\\u30a2\\u30b8\\u30a2", "\\u5357\\u30a2\\u30e1\\u30ea\\u30ab", "\\u5317\\u4e2d\\u30a2\\u30e1\\u30ea\\u30ab", "\\u30aa\\u30bb\\u30a2\\u30cb\\u30a2", "\\u30e8\\u30fc\\u30ed\\u30c3\\u30d1") area_links <- head(area_links, 1) # for test for(i in seq_along(area_links)){ print(stringr::str_c("area: ", i, " / ", length(area_links))) country_links <- download_links(area_links[i]) country_links <- head(country_links, 1) # for test for(j in seq_along(country_links)){ print(stringr::str_c(" country: ", j, " / ", length(country_links))) links <- download_links(country_links[j]) station_links <- c(station_links, links) continent <- c(continent, rep(continents[i], length(links))) } } station_links <- tibble::tibble(url = station_links, continent = continent) station_links
# If you want links for all countries and all sations, remove head(). # The codes take over 5 sec because of poliste scraping. library(magrittr) library(stringi) library(dplyr) library(tibble) area_links <- download_area_links() station_links <- NULL continent <- NULL continents <- c("\\u30a2\\u30d5\\u30ea\\u30ab", "\\u30a2\\u30b8\\u30a2", "\\u5357\\u30a2\\u30e1\\u30ea\\u30ab", "\\u5317\\u4e2d\\u30a2\\u30e1\\u30ea\\u30ab", "\\u30aa\\u30bb\\u30a2\\u30cb\\u30a2", "\\u30e8\\u30fc\\u30ed\\u30c3\\u30d1") area_links <- head(area_links, 1) # for test for(i in seq_along(area_links)){ print(stringr::str_c("area: ", i, " / ", length(area_links))) country_links <- download_links(area_links[i]) country_links <- head(country_links, 1) # for test for(j in seq_along(country_links)){ print(stringr::str_c(" country: ", j, " / ", length(country_links))) links <- download_links(country_links[j]) station_links <- c(station_links, links) continent <- c(continent, rep(continents[i], length(links))) } } station_links <- tibble::tibble(url = station_links, continent = continent) station_links
Graceful fail
gracefully_fail(remote_file)
gracefully_fail(remote_file)
remote_file |
A string of remote file. |
An XML document when successed, or invisible NULL when failed.
https://gist.github.com/kvasilopoulos/47f24348ed75cdb6365312b17f4b914c
Wrapper function to head 3 items
head_3(x)
head_3(x)
x |
An object. |
An object like x with length 3.
Wrapper function to sleep
sleep(sec = 5)
sleep(sec = 5)
sec |
A numeric to sleep (sec). |
No return value, called for side effects.
Climate stations in Japan
station_jp
station_jp
A data frame with 3444 rows and 4 variable:
Region. Escaped by stringi::stri_escape_unicode().
Prefecture. Escaped by stringi::stri_escape_unicode()
Station no.
Station name. To avoid duplication, including country name after station name. Can split by "_". Escaped by stringi::stri_escape_unicode().
Altitude. (m)
Latitude. (degree)
Longitude. (degree)
North or South.
West or East.
Pronunciation in Japanese. Escaped by stringi::stri_escape_unicode()
City name. Escaped by stringi::stri_escape_unicode().
library(magrittr) library(stringi) library(dplyr) data(station_jp) station_jp %>% dplyr::mutate_all(stringi::stri_unescape_unicode)
library(magrittr) library(stringi) library(dplyr) data(station_jp) station_jp %>% dplyr::mutate_all(stringi::stri_unescape_unicode)
Station name and its URL
station_links
station_links
A data frame with 3444 rows and 4 variable:
Station no
Station information including no, month, temperature, precipitation, station, country, latitude, NS, longitude, WE, altitude. The information is NOT cleaned Row information downloaded from each URL. Escaped by stringi::stri_escape_unicode().
URL of station.
Continent. Escaped by stringi::stri_escape_unicode().
library(magrittr) library(stringi) library(dplyr) data(station_links) station_links %>% dplyr::mutate_all(stringi::stri_unescape_unicode)
library(magrittr) library(stringi) library(dplyr) data(station_links) station_links %>% dplyr::mutate_all(stringi::stri_unescape_unicode)
Climate stations of the world
station_world
station_world
A data frame with 3444 rows and 9 variable:
Station no
Station name. To avoid duplication, including country name after station name. Can split by "_". Escaped by stringi::stri_escape_unicode().
Continent. Escaped by stringi::stri_escape_unicode().
Country name. Escaped by stringi::stri_escape_unicode().
Altitude (m)
Latitude (degree)
North or South.
Longitude (degree)
West or East
library(magrittr) library(stringi) library(dplyr) data(station_world) station_world %>% dplyr::mutate_all(stringi::stri_unescape_unicode)
library(magrittr) library(stringi) library(dplyr) data(station_world) station_world %>% dplyr::mutate_all(stringi::stri_unescape_unicode)
Calculate warm index and cold index
wi(x) ci(x)
wi(x) ci(x)
x |
A numeric vector |
A string vector of url links.
Kira, T. 1945. A new classification of climate in eastern Asia as the basis for agricultural geography, Hort. Inst. Kyoto Univ., Kyoto. (in Japanese) Warmth Index (WI) and Cold Index (CI) was proposed by Kira (1945), which is known closely related to the distribution of vegetation. Indices can are calculated by following equations. wi = sum (Ti - 5), where wi is Warm index, Ti (Celsius) is mean temperature of each month in a year when Ti > 5. Indices can are calculated by following equations. wi = -sum (Ti - 5), where wi is Cold index, when Ti < 5.
temp <- c(-7.8, -7.2, -2.4, 5.2, 11.7, 16.5, 20.5, 21.1, 15.6, 8.8, 2.0, -4.1) wi(temp) ci(temp) wi <- sum(c(0, 0, 0, 0.2, 6.7, 11.5, 15.5, 16.1, 10.6, 3.8, 0, 0)) ci <- sum(c(12.8, 12.2, 7.4, 0, 0, 0, 0, 0, 0, 0, 3.0, 9.1))
temp <- c(-7.8, -7.2, -2.4, 5.2, 11.7, 16.5, 20.5, 21.1, 15.6, 8.8, 2.0, -4.1) wi(temp) ci(temp) wi <- sum(c(0, 0, 0, 0.2, 6.7, 11.5, 15.5, 16.1, 10.6, 3.8, 0, 0)) ci <- sum(c(12.8, 12.2, 7.4, 0, 0, 0, 0, 0, 0, 0, 3.0, 9.1))