The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.

Title: Data from Japan Meteorological Agency
Version: 0.5.2
Description: Includes climate data from Japan Meteorological Agency ('JMA') https://www.jma.go.jp/jma/indexe.html. Can download climate data from 'JMA'.
License: MIT + file LICENSE
Encoding: UTF-8
RoxygenNote: 7.2.3
Depends: R (≥ 3.5.0)
URL: https://github.com/matutosi/clidatajp https://github.com/matutosi/clidatajp/tree/develop (devel)
LazyData: true
Imports: curl, dplyr, httr, magrittr, rlang, rvest, stringi, stringr, tibble, tidyr, utils
Suggests: ggplot2, knitr, rmarkdown, testthat (≥ 3.0.0)
VignetteBuilder: knitr
Config/testthat/edition: 3
Language: en-US
NeedsCompilation: no
Packaged: 2023-03-05 03:49:51 UTC; test
Author: Toshikazu Matsumura [aut, cre]
Maintainer: Toshikazu Matsumura <matutosi@gmail.com>
Repository: CRAN
Date/Publication: 2023-03-05 05:00:02 UTC

Pipe operator

Description

See magrittr::%>% for details.

Usage

lhs %>% rhs

Arguments

lhs

A value or the magrittr placeholder.

rhs

A function call using the magrittr semantics.

Value

The result of calling rhs(lhs).


Wrapper function to convert into numeric without warnings

Description

Wrapper function to convert into numeric without warnings

Usage

as_numeric_without_warnings(x)

Arguments

x

A string.

Value

A numeric or NA.


Choose data with menu.

Description

Choose data with menu.

Usage

choose_with_menu(df, filter_cols, extract = NULL)

Arguments

df

A dataframe

filter_cols

A string or string vector

extract

A string

Value

If extract is NULL, return a dataframe, else return a vector.

Examples

if(interactive()){
  data(climate_world)
  climate_world <- 
    climate_world %>%
    dplyr::mutate_all(stringi::stri_unescape_unicode)
  
  choose_with_menu(climate_world, filter_cols = "continent")
  4  # input
  
  choose_with_menu(climate_world, filter_cols = c("continent", "country", "station"))
  4  # input
  3  # input
  2  # input
}


Clean up station information

Description

Helper function for download_climate().

Usage

clean_station(station)

Arguments

station

A String of station information.

Value

A tibble including station information.

Examples

data(station_links)
station_links %>%
  head(1) %>%
  `$`("station") %>%
  stringi::stri_unescape_unicode() %>%
  clean_station()


Climate data in Japan

Description

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/

Usage

climate_jp

japan_climate

Format

A data frame with 3768 (157 stations * 12 months * 2 periods) rows and 14 variable:

no

Station no

month

Month

period

Period of observations

temperature

Mean temperature

precipitation

Mean precipitation

snowfall

Mean snowfall

insolation

Mean insolation

station

Station name. To avoid duplication, including country name after station name. Can split by "_". Escaped by stringi::stri_escape_unicode().

country

Country name. Escaped by stringi::stri_escape_unicode().

latitude

Latitude. (degree)

NS

North or South.

longitude

Longitude. (degree)

WE

West or East.

altitude

Altitude (m)

An object of class tbl_df (inherits from tbl, data.frame) with 3768 rows and 14 columns.

Examples

library(magrittr)
library(stringi)
library(dplyr)
data(japan_climate)
japan_climate %>%
  dplyr::mutate_all(stringi::stri_unescape_unicode)

Climate data in the world

Description

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/

Usage

climate_world

world_climate

Format

A data frame with 41328 (3444 stations * 12 months) rows and 12 variable:

no

Station no

continent

Continent. Escaped by stringi::stri_escape_unicode().

country

Country name. Escaped by stringi::stri_escape_unicode().

station

Station name. To avoid duplication, including country name after station name. Can split by "_". Escaped by stringi::stri_escape_unicode().

month

Month

temperature

Mean temperature

precipitation

Mean precipitation

latitude

Latitude. (degree)

NS

North or South.

longitude

Longitude. (degree)

WE

West or East.

altitude

Altitude (m)

An object of class tbl_df (inherits from tbl, data.frame) with 41328 rows and 12 columns.

Examples

library(magrittr)
library(stringi)
library(dplyr)
data(world_climate)
world_climate %>%
  dplyr::mutate_all(stringi::stri_unescape_unicode)

Download climate data of the world

Description

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/

Usage

download_climate(url)

Arguments

url

A String to specify target html.

Value

A tibble including climate and station information, or NULL when failed.

Examples

# 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
}


Description

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/

Usage

download_area_links(
  url = "https://www.data.jma.go.jp/gmd/cpd/monitor/nrmlist/"
)

download_links(url)

Arguments

url

A String to specify target html.

Value

A string vector of url links, or NULL when failed.

Examples

# 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

Description

Graceful fail

Usage

gracefully_fail(remote_file)

Arguments

remote_file

A string of remote file.

Value

 An XML document when successed, or invisible NULL when failed.

References

https://gist.github.com/kvasilopoulos/47f24348ed75cdb6365312b17f4b914c


Wrapper function to head 3 items

Description

Wrapper function to head 3 items

Usage

head_3(x)

Arguments

x

An object.

Value

An object like x with length 3.


Wrapper function to sleep

Description

Wrapper function to sleep

Usage

sleep(sec = 5)

Arguments

sec

A numeric to sleep (sec).

Value

No return value, called for side effects.


Climate stations in Japan

Description

Climate stations in Japan

Usage

station_jp

Format

A data frame with 3444 rows and 4 variable:

region

Rejon. Escaped by stringi::stri_escape_unicode().

pref

Prefecture. Escaped by stringi::stri_escape_unicode()

no

Station no.

station

Station name. To avoid duplication, including country name after station name. Can split by "_". Escaped by stringi::stri_escape_unicode().

altitude

Altitude. (m)

latitude

Latitude. (degree)

longitude

Longitude. (degree)

NS

North or South.

WE

West or East.

yomi

Pronunciation in Japanese. Escaped by stringi::stri_escape_unicode()

city

City name. Escaped by stringi::stri_escape_unicode().

Examples

library(magrittr)
library(stringi)
library(dplyr)
data(station_jp)
station_jp %>%
  dplyr::mutate_all(stringi::stri_unescape_unicode)

Description

Station name and its URL

Usage

station_links

Format

A data frame with 3444 rows and 4 variable:

no

Station no

station

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

URL of station.

continent

Continent. Escaped by stringi::stri_escape_unicode().

Examples

library(magrittr)
library(stringi)
library(dplyr)
data(station_links)
station_links %>%
  dplyr::mutate_all(stringi::stri_unescape_unicode)

Climate stations of the world

Description

Climate stations of the world

Usage

station_world

Format

A data frame with 3444 rows and 9 variable:

no

Station no

station

Station name. To avoid duplication, including country name after station name. Can split by "_". Escaped by stringi::stri_escape_unicode().

continent

Continent. Escaped by stringi::stri_escape_unicode().

country

Country name. Escaped by stringi::stri_escape_unicode().

altitude

Altitude (m)

latitude

Latitude (degree)

NS

North or South.

longitude

Longitude (degree)

WE

West or East

Examples

library(magrittr)
library(stringi)
library(dplyr)
data(station_world)
station_world %>%
  dplyr::mutate_all(stringi::stri_unescape_unicode)

Calculate warm index and cold index

Description

Calculate warm index and cold index

Usage

wi(x)

ci(x)

Arguments

x

A numeric vector

Value

A string vector of url links.

References

Kira, T. 1945. A new classification of climate in eastern Asia as the basis for agricultural geography, Hort. Inst. K,yoto 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 temprature 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.

Examples

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))

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.