Package 'clidatajp'

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

Help Index


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
}

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

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

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

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