Skip to content

Commit

Permalink
Merge pull request #56 from bczernecki/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
bczernecki authored Mar 31, 2021
2 parents dc9a792 + 0bdbf56 commit 1af6d0f
Show file tree
Hide file tree
Showing 43 changed files with 87 additions and 62 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: climate
Title: Interface to Download Meteorological (and Hydrological) Datasets
Version: 0.9.9
Version: 1.0.0
Authors@R: c(person(given = "Bartosz",
family = "Czernecki",
role = c("aut", "cre"),
Expand All @@ -20,7 +20,7 @@ Authors@R: c(person(given = "Bartosz",
Description: Automatize downloading of meteorological and hydrological data from publicly available repositories:
OGIMET (<http://ogimet.com/index.phtml.en>),
University of Wyoming - atmospheric vertical profiling data (<http://weather.uwyo.edu/upperair/>),
Polish Institute of Meterology and Water Management - National Research Institute (<https://dane.imgw.pl>),
Polish Institute of Meterology and Water Management - National Research Institute (<https://danepubliczne.imgw.pl>),
and National Oceanic & Atmospheric Administration (NOAA).
This package also allows for adding geographical coordinates for each observation.
License: MIT + file LICENSE
Expand Down
12 changes: 12 additions & 0 deletions R/check_locale.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#' Check locale
#'
#' This is an extra check for some systems that make use of "C.UTF-8" that cannot parse properly tags used inside the Polish metservice's repository
#' @noRd

check_locale = function(){
if(any(strsplit(Sys.getlocale(), "/")[[1]] == "C.UTF-8")){
message(" Your system locale contains 'C.UTF-8' which may cause trouble.
Please consider changing it manually while working with climate, e.g.:
Sys.setlocale(category = 'LC_ALL', locale = 'en_US.UTF-8') ")
}
}
8 changes: 4 additions & 4 deletions R/clean_metadata_hydro.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
#' @keywords internal
clean_metadata_hydro <- function(address, interval){
#miesieczne
#address="https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_hydrologiczne/miesieczne/mies_info.txt"
#address="https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_hydrologiczne/miesieczne/mies_info.txt"
#dobowe
#address="https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_hydrologiczne/dobowe/codz_info.txt"
#"https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_hydrologiczne/dobowe/zjaw_info.txt"
#address="https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_hydrologiczne/dobowe/codz_info.txt"
#"https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_hydrologiczne/dobowe/zjaw_info.txt"
#polroczne_i_roczne
#address="https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_hydrologiczne/polroczne_i_roczne/polr_info.txt"
#address="https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_hydrologiczne/polroczne_i_roczne/polr_info.txt"
#a <- suppressWarnings(na.omit(read.fwf(address, widths = c(1000),
# fileEncoding = "CP1250", stringsAsFactors = FALSE)))

Expand Down
6 changes: 4 additions & 2 deletions R/clean_metadata_meteo.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#'
#' @examples
#' \donttest{
#' my_add = paste0("https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/",
#' my_add = paste0("https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/",
#' "dane_meteorologiczne/dobowe/synop/s_d_format.txt")
#' climate:::clean_metadata_meteo(address = my_add, rank = "synop", interval = "hourly")
#' }
Expand All @@ -20,7 +20,7 @@ clean_metadata_meteo <- function(address, rank = "synop", interval = "hourly"){

temp = tempfile()


test_url(link = address, output = temp)
a = readLines(temp, warn = FALSE)

Expand All @@ -47,11 +47,13 @@ clean_metadata_meteo <- function(address, rank = "synop", interval = "hourly"){
# a <- suppressWarnings(na.omit(read.fwf(address, widths = c(1000),
# fileEncoding = "CP1250", stringsAsFactors = FALSE)))


length_char <- max(nchar(a$V1), na.rm = TRUE)

if(rank == "precip" && interval == "hourly") length_char <- 40 # wyjatek dla precipow
if(rank == "precip" && interval == "daily") length_char <- 40 # wyjatek dla precipow dobowych
if(rank == "synop" && interval == "hourly") length_char <- 60 # wyjatek dla synopow terminowych
if(rank == "climate" && interval == "monthly") length_char <- 52 # wyjatek dla synopow terminowych

field <- substr(a$V1, length_char - 3, length_char)

Expand Down
4 changes: 2 additions & 2 deletions R/hydro_imgw.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#' Hydrological data from IMGW
#'
#' Downloading hourly, daily, and monthly hydrological data from the measurement stations available in the dane.imgw.pl collection
#' Downloading hourly, daily, and monthly hydrological data from the measurement stations available in the danepubliczne.imgw.pl collection
#'
#' @param interval temporal resolution of the data ("daily" , "monthly", or "semiannual_and_annual")
#' @param year vector of years (e.g., 1966:2000)
#' @param coords add coordinates of the stations (logical value TRUE or FALSE)
#' @param value type of data (can be: state - "H" (default), flow - "Q", or temperature - "T")
#' @param station vector of hydrological stations dane.imgw.pl; can be given as station name with CAPITAL LETTERS (character)
#' @param station vector of hydrological stations danepubliczne.imgw.pl; can be given as station name with CAPITAL LETTERS (character)
#' It accepts either names (characters in CAPITAL LETTERS) or stations' IDs (numeric)
#' @param col_names three types of column names possible: "short" - default, values with shorten names, "full" - full English description, "polish" - original names in the dataset
#' @param ... other parameters that may be passed to the 'shortening' function that shortens column names
Expand Down
6 changes: 4 additions & 2 deletions R/hydro_imgw_annual.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Semi-annual and annual hydrological data
#'
#' Downloading hydrological data for the semi-annual and annual period
#' available in the dane.imgw.pl collection
#' available in the danepubliczne.imgw.pl collection
#'
#' @param year vector of years (e.g., 1966:2000)
#' @param coords add coordinates of the stations (logical value TRUE or FALSE)
Expand All @@ -22,8 +22,10 @@
hydro_imgw_annual = function(year, coords = FALSE, value = "H", station = NULL, col_names = "short", ...){

# options(RCurlOptions = list(ssl.verifypeer = FALSE)) # required on windows for RCurl

check_locale()

base_url = "https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_hydrologiczne/"
base_url = "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_hydrologiczne/"
interval = "semiannual_and_annual"
interval_pl = "polroczne_i_roczne"

Expand Down
6 changes: 4 additions & 2 deletions R/hydro_imgw_daily.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Daily hydrological data
#'
#' Downloading daily hydrological data from the dane.imgw.pl collection
#' Downloading daily hydrological data from the danepubliczne.imgw.pl collection
#'
#' @param year vector of years (e.g., 1966:2000)
#' @param coords add coordinates of the stations (logical value TRUE or FALSE)
Expand All @@ -20,8 +20,10 @@

hydro_imgw_daily = function(year, coords = FALSE, station = NULL, col_names= "short", ...){
#options(RCurlOptions = list(ssl.verifypeer = FALSE)) # required on windows for RCurl

check_locale()

base_url = "https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_hydrologiczne/"
base_url = "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_hydrologiczne/"
interval = "daily"
interval_pl = "dobowe"

Expand Down
6 changes: 4 additions & 2 deletions R/hydro_imgw_monthly.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Monthly hydrological data
#'
#' Downloading monthly hydrological data from the dane.imgw.pl collection
#' Downloading monthly hydrological data from the danepubliczne.imgw.pl collection
#'
#' @param year vector of years (e.g., 1966:2000)
#' @param coords add coordinates of the stations (logical value TRUE or FALSE)
Expand All @@ -20,8 +20,10 @@
hydro_imgw_monthly <- function(year, coords = FALSE, station = NULL, col_names= "short", ...){

#options(RCurlOptions = list(ssl.verifypeer = FALSE)) # required on windows for RCurl

check_locale()

base_url <- "https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_hydrologiczne/"
base_url <- "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_hydrologiczne/"
interval <- "monthly"
interval_pl <- "miesieczne"

Expand Down
4 changes: 2 additions & 2 deletions R/hydro_metadata_imgw.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Hydrological metadata
#'
#' Downloading the description (metadata) to hydrological data available in the dane.imgw.pl repository.
#' Downloading the description (metadata) to hydrological data available in the danepubliczne.imgw.pl repository.
#' By default, the function returns a list or data frame for a selected subset
#`
#' @param interval temporal resolution of the data ("daily" , "monthly", or "semiannual_and_annual")
Expand All @@ -15,7 +15,7 @@

hydro_metadata_imgw <- function(interval){

base_url <- "https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_hydrologiczne/"
base_url <- "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_hydrologiczne/"

if (interval == "daily"){
# dobowe
Expand Down
2 changes: 1 addition & 1 deletion R/hydro_shortening_imgw.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Shortening column names for hydrological variables
#'
#' Shortening column names of hydrological parameters to improve the readability of downloaded dataset from the dane.imgw.pl collection and removing duplicated column names
#' Shortening column names of hydrological parameters to improve the readability of downloaded dataset from the danepubliczne.imgw.pl collection and removing duplicated column names
#'
#' @param data downloaded dataset with original column names
#' @param col_names three types of column names possible: "short" - default, values with shorten names, "full" - full English description, "polish" - original names in the dataset
Expand Down
2 changes: 1 addition & 1 deletion R/imgw_hydro_abbrev.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#' @name imgw_hydro_abbrev
#' @title Definitions of hydrological parameters used for shortening column names from the dane.imgw.pl collection
#' @title Definitions of hydrological parameters used for shortening column names from the danepubliczne.imgw.pl collection
#'
#' @description The object contains 3 columns that are currently used for improving readability of the downloaded dataset:
#' fullname, abbr_eng, and fullname_eng
Expand Down
2 changes: 1 addition & 1 deletion R/imgw_hydro_stations.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#' @name imgw_hydro_stations
#' @title Location of the hydrological stations from the dane.imgw.pl collection
#' @title Location of the hydrological stations from the danepubliczne.imgw.pl collection
#'
#' @description The object contains weather stations
#' coordinates, ID numbers, and elevations
Expand Down
2 changes: 1 addition & 1 deletion R/imgw_meteo_abbrev.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#' @name imgw_meteo_abbrev
#' @title Definitions of meteorological parameters used for shortening column names for the meteorological data from the dane.imgw.pl collection
#' @title Definitions of meteorological parameters used for shortening column names for the meteorological data from the danepubliczne.imgw.pl collection
#'
#' @description The object contains 3 columns that are currently used for improving readability of the downloaded dataset:
#' fullname, abbr_eng, and fullname_eng
Expand Down
2 changes: 1 addition & 1 deletion R/imgw_meteo_stations.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#' @name imgw_meteo_stations
#' @title Location of the meteorological stations from the dane.imgw.pl collection
#' @title Location of the meteorological stations from the danepubliczne.imgw.pl collection
#'
#' @description The object contains weather stations
#' coordinates, ID numbers, and elevations
Expand Down
4 changes: 2 additions & 2 deletions R/meteo_imgw.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Meteorological data from IMGW
#'
#' Downloading hourly, daily, and monthly meteorological data from the SYNOP / CLIMATE / PRECIP stations available in the dane.imgw.pl collection
#' Downloading hourly, daily, and monthly meteorological data from the SYNOP / CLIMATE / PRECIP stations available in the danepubliczne.imgw.pl collection
#'
#' @param interval temporal resolution of the data ("hourly", "daily", "monthly")
#' @param rank rank of the stations: "synop" (default), "climate" or "precip"
Expand All @@ -9,7 +9,7 @@
#' @param coords add coordinates of the station (logical value TRUE or FALSE)
#' @param col_names three types of column names possible: "short" - default, values with shorten names, "full" - full English description, "polish" - original names in the dataset
#' @param ... other parameters that may be passed to the 'shortening' function that shortens column names
#' @param station vector of hydrological stations dane.imgw.pl can be name of station CAPITAL LETTERS(character)
#' @param station vector of hydrological stations danepubliczne.imgw.pl can be name of station CAPITAL LETTERS(character)
#' It accepts names (characters in CAPITAL LETTERS) or stations' IDs (numeric)
#' @export
#' @return A data.frame with columns describing the meteorological parameters (e.g. temperature, wind speed, precipitation) where each row represent a measurement,
Expand Down
6 changes: 4 additions & 2 deletions R/meteo_imgw_daily.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Daily IMGW meteorological data
#'
#' Downloading daily (meteorological) data from the SYNOP / CLIMATE / PRECIP stations available in the dane.imgw.pl collection
#' Downloading daily (meteorological) data from the SYNOP / CLIMATE / PRECIP stations available in the danepubliczne.imgw.pl collection
#'
#' @param rank rank of the stations: "synop" (default), "climate", or "precip"
#' @param year vector of years (e.g., 1966:2000)
Expand All @@ -24,7 +24,9 @@ meteo_imgw_daily <- function(rank = "synop", year, status = FALSE, coords = FALS

#options(RCurlOptions = list(ssl.verifypeer = FALSE)) # required on windows for RCurl

base_url <- "https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/"
check_locale()

base_url <- "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/"

interval <- "daily" # to mozemy ustawic na sztywno
interval_pl <- "dobowe"
Expand Down
6 changes: 4 additions & 2 deletions R/meteo_imgw_hourly.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Hourly IMGW meteorological data
#'
#' Downloading hourly (meteorological) data from the SYNOP / CLIMATE / PRECIP stations available in the dane.imgw.pl collection
#' Downloading hourly (meteorological) data from the SYNOP / CLIMATE / PRECIP stations available in the danepubliczne.imgw.pl collection
#'
#' @param rank rank of the stations: "synop" (default), "climate", or "precip"
#' @param year vector of years (e.g., 1966:2000)
Expand All @@ -21,12 +21,14 @@
#'

meteo_imgw_hourly <- function(rank = "synop", year, status = FALSE, coords = FALSE, station = NULL, col_names = "short", ...){

check_locale()

stopifnot(rank == "synop" | rank == "climate") # dla terminowek tylko synopy i klimaty maja dane

#options(RCurlOptions = list(ssl.verifypeer = FALSE)) # required on windows for RCurl

base_url <- "https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/"
base_url <- "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/"
interval <- "hourly" # to mozemy ustawic na sztywno
interval_pl <- "terminowe" # to mozemy ustawic na sztywno

Expand Down
7 changes: 4 additions & 3 deletions R/meteo_imgw_monthly.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Monthly IMGW meteorological data
#'
#' Downloading monthly (meteorological) data from the SYNOP / CLIMATE / PRECIP stations available in the dane.imgw.pl collection
#' Downloading monthly (meteorological) data from the SYNOP / CLIMATE / PRECIP stations available in the danepubliczne.imgw.pl collection
#'
#' @param rank rank of the stations: "synop" (default), "climate", or "precip"
#' @param year vector of years (e.g., 1966:2000)
Expand Down Expand Up @@ -29,12 +29,13 @@
#' coords = TRUE, station = c("POZNAŃ","POZNAŃ-ŁAWICA"))
#' }
#'

meteo_imgw_monthly <- function(rank = "synop", year, status = FALSE, coords = FALSE, station = NULL, col_names = "short", ...){

check_locale()

#options(RCurlOptions = list(ssl.verifypeer = FALSE)) # required on windows for RCurl

base_url <- "https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/"
base_url <- "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/"

# if (httr::http_error(base_url)) {
# b = stop(call. = FALSE,
Expand Down
4 changes: 2 additions & 2 deletions R/meteo_metadata_imgw.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
meteo_metadata_imgw <- function(interval, rank){ # interval moze byc: monthly, hourly, hourly
b <- NULL

base_url <- "https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/"
base_url <- "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/"

# METADANE daily:
if(interval == "daily") { # uwaga! daily maja dla climateow i synopow po 2 pliki z metadanymi!!!
Expand All @@ -44,7 +44,7 @@ meteo_metadata_imgw <- function(interval, rank){ # interval moze byc: monthly, h
}


# TODO: pod addressem: https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/monthly/synop/
# TODO: pod addressem: https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/monthly/synop/
# sa 2 ranke metadanych, bo pliki monthly maja 2 ranke danych; w starej wersji paczki tylko jedna wersja jest uwzgledniana
# dodatkowo inne ranke danych beda do pobrania w zaleznosci od danych SYNOP, climate, precip:
if(interval == "monthly") {
Expand Down
2 changes: 1 addition & 1 deletion R/meteo_shortening_imgw.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Shortening column names for meteorological variables
#'
#' Shortening column names of meteorological parameters to improve the readability of downloaded dataset from the dane.imgw.pl collection and removing duplicated column names
#' Shortening column names of meteorological parameters to improve the readability of downloaded dataset from the danepubliczne.imgw.pl collection and removing duplicated column names
#'
#' @param data downloaded dataset with original column names
#' @param col_names three types of column names possible: "short" - default, values with shorten names, "full" - full English description, "polish" - original names in the dataset
Expand Down
4 changes: 2 additions & 2 deletions R/nearest_stations_imgw.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ nearest_stations_imgw <- function(type = "meteo",

if (max(year)>=as.integer(substr(Sys.Date(),1,4))-1) {
message("Data cannot be provided for this repository. Please check the available records at: \n
https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/")
https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/")
}

if (type == "meteo"){
Expand All @@ -57,7 +57,7 @@ nearest_stations_imgw <- function(type = "meteo",

if (dim(result)[1]==0) {
stop("Propobly there is no data in the downloaded object. Please check available records:
https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/")
https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/")
}
if (is.null(point)){
# workaround for different column names:
Expand Down
2 changes: 1 addition & 1 deletion R/test_url.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#' @examples
#' \donttest{
#' link = "https://www1.ncdc.noaa.gov/pub/data/noaa/2019/123300-99999-2019.gz"
#' output = basename(link)
#' output = tempfile()
#' test_url(link = link, output = output)
#' }
#'
Expand Down
2 changes: 1 addition & 1 deletion man/clean_metadata_meteo.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/climate-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1af6d0f

Please sign in to comment.