diff --git a/.github/workflows/html5-check.yaml b/.github/workflows/html5-check.yaml
index d31bd6e..0ba7814 100644
--- a/.github/workflows/html5-check.yaml
+++ b/.github/workflows/html5-check.yaml
@@ -34,8 +34,14 @@ jobs:
- name: Install tidy and pandoc
run: sudo apt install tidy pandoc
+ - name: Remove cached R libraries
+ run: rm -rf /home/runner/work/_temp/Library/data.table
+
- name: Install dependencies
- run: R -e 'install.packages(c("knitr", "rmarkdown", "XML", "httr", "data.table", "maps", "dplyr", "tidyr", "xml2", "testthat", "archive"))'
+ run: R -e 'install.packages(c("knitr", "rmarkdown", "XML", "httr", "maps", "dplyr", "tidyr", "xml2", "testthat", "archive"))'
+
+ - name: Install data.table from source
+ run: Rscript -e 'install.packages("data.table", type = "source")'
- uses: r-lib/actions/check-r-package@v2
with:
diff --git a/DESCRIPTION b/DESCRIPTION
index c23b156..d45741a 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,6 +1,6 @@
Package: climate
Title: Interface to Download Meteorological (and Hydrological) Datasets
-Version: 1.2.9
+Version: 1.3.0
Authors@R: c(person(given = "Bartosz",
family = "Czernecki",
role = c("aut", "cre"),
diff --git a/NAMESPACE b/NAMESPACE
index c7dc955..399347f 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -1,6 +1,7 @@
# Generated by roxygen2: do not edit by hand
export(.onAttach)
+export(find_all_station_names)
export(hydro_imgw)
export(hydro_imgw_daily)
export(hydro_imgw_datastore)
diff --git a/NEWS.md b/NEWS.md
index 8f061e3..ce48e34 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,3 +1,16 @@
+# climate 1.3.0
+
+* adapting code to most recent changes in the IMGW-PIB repository:
+ * fixes for `meteo_imgw_monthly()`
+ * changes in metadata and downloading functions for hydrological datasets
+ * updated Polish vignette for hydro dataset
+ * added `find_all_station_names()` function to find all station names in the IMGW-PIB
+ repository that match the provided name(s) and return all available datasets for
+ those stations (e.g.entry "WARSZAWA" will also search for: "WARSZAWA-BIELANY",
+ "WARSZAWA-OKECIE", "WARSZAWA-OBSERWATORIUM", etc.)
+
+
+
# climate 1.2.9
* fixes for corrupted header files in `meteo_imgw_` family of functions due to changes in the IMGW-PIB repository
diff --git a/R/clean_metadata_hydro.R b/R/clean_metadata_hydro.R
index a5dc1d6..3dd9a22 100644
--- a/R/clean_metadata_hydro.R
+++ b/R/clean_metadata_hydro.R
@@ -8,21 +8,15 @@
#' @noRd
clean_metadata_hydro = function(address, interval) {
- temp = tempfile()
+ temp = tempfile()
test_url(link = address, output = temp)
- a = read.csv(temp, header = FALSE, stringsAsFactors = FALSE,
- fileEncoding = "CP1250", skip = 1, sep = "\t")$V1
- a = gsub(a, pattern = "\\?", replacement = "")
- a = gsub(x = a, pattern = "'", replacement = "")
- a = trimws(gsub(x = a, pattern = "\\^", replacement = ""))
- a = gsub(a, pattern = "\\s+", replacement = " ")
-
- if (interval == "monthly") {
- b = list(data.frame(parameters = a[1:10]))
- }
- if (interval == "daily") {
- b = data.frame(parameters = a[1:10])
- }
- return(b)
+ a = read.csv(temp, header = FALSE, stringsAsFactors = FALSE)$V1
+
+ inds = grepl("^[A-Z]{2}.{5}", a)
+
+ code = trimws(substr(a, 1, 7))[inds]
+ name = trimws(substr(a, 10, nchar(a)))[inds]
+ a = data.frame(parameters = code, label = name)
+ return(a)
}
diff --git a/R/hydro_imgw_daily.R b/R/hydro_imgw_daily.R
index 336cdbe..09f2a29 100644
--- a/R/hydro_imgw_daily.R
+++ b/R/hydro_imgw_daily.R
@@ -129,7 +129,7 @@ hydro_imgw_daily_bp = function(year,
unzip(zipfile = temp, exdir = temp2)
file2 = paste(temp2, dir(temp2), sep = "/")[1]
data2 = imgw_read(translit, file2)
- colnames(data2) = meta[[2]][, 1]
+ colnames(data2) = gsub(x = meta[[2]][, 1], "^ZJ", "CO") # rename colnames starting with ^ZJ to be changed to ^CO:
zjaw_data = rbind(zjaw_data, data2)
}
@@ -140,10 +140,9 @@ hydro_imgw_daily_bp = function(year,
by = intersect(colnames(codz_data), colnames(zjaw_data)),
all.x = TRUE)
- # station selection and names cleaning:
if (!is.null(station)) {
if (is.character(station)) {
- inds = unique(as.numeric(unlist(sapply(station, function(x) grep(pattern = x, x = trimws(all_data[[length(all_data)]]$`Nazwa stacji`))))))
+ inds = unique(as.numeric(unlist(sapply(station, function(x) grep(pattern = x, x = trimws(all_data[[length(all_data)]]$PSNZWP))))))
if (any(is.na(inds)) || length(inds) == 0) {
env$logs = c(
env$logs,
@@ -166,39 +165,22 @@ hydro_imgw_daily_bp = function(year,
if (coords) {
all_data = merge(climate::imgw_hydro_stations, all_data,
by.x = "id",
- by.y = "Kod stacji",
+ by.y = "PSKDSZS",
all.y = TRUE)
}
- #station selection
- if (!is.null(station)) {
- if (is.character(station)) {
- all_data = all_data[substr(all_data$`Nazwa stacji`, 1, nchar(station)) == station, ]
- if (nrow(all_data) == 0) {
- stop("Selected station(s) is not available in the database.", call. = FALSE)
- }
- } else if (is.numeric(station)) {
- all_data = all_data[all_data$`Kod stacji` %in% station, ]
- if (nrow(all_data) == 0) {
- stop("Selected station(s) is not available in the database.", call. = FALSE)
- }
- } else {
- stop("Selected station(s) are not in the proper format.", call. = FALSE)
- }
- }
-
all_data = as.data.frame(all_data)
- all_data = all_data[do.call(order, all_data[grep(x = colnames(all_data), "Nazwa stacji|Rok hydro|w roku hydro|Dzie")]), ]
+ all_data = all_data[do.call(order, all_data[grep(x = colnames(all_data), "PSNZWP|COROKH|COMSCH|CODZIEN")]), ]
# fix dates and add as seperate column:
- yy_ind = grep(x = colnames(all_data), "Rok hydrologiczny")
- mm_ind = grep(x = colnames(all_data), "kalendarzowy")
- dd_ind = grep(x = colnames(all_data), "Dzie")
+ yy_ind = grep(x = colnames(all_data), "COROKH")
+ mm_ind = grep(x = colnames(all_data), "COMSCK")
+ dd_ind = grep(x = colnames(all_data), "CODZIEN")
data_df = all_data[, c(yy_ind, mm_ind, dd_ind)]
data_df$yy = ifelse(data_df[, 2] >= 11, data_df[, 1] - 1, data_df[, 1])
all_data$Data = as.Date(ISOdate(year = data_df$yy, month = data_df[, 2], day = data_df[, 3]))
- all_data = all_data[, c(1:3, ncol(all_data), 4:(ncol(all_data) - 1)), ]
-
- all_data = hydro_shortening_imgw(all_data, col_names = col_names, ...)
-
+ #all_data = all_data[, c(1:3, ncol(all_data), 4:(ncol(all_data) - 1)), ]
+ #all_data = hydro_shortening_imgw(all_data, col_names = col_names, ...)
+ all_data = unique(all_data)
+ rownames(all_data) = 1:nrow(all_data)
return(all_data)
}
\ No newline at end of file
diff --git a/R/hydro_imgw_monthly.R b/R/hydro_imgw_monthly.R
index 92c1ba7..8f86377 100644
--- a/R/hydro_imgw_monthly.R
+++ b/R/hydro_imgw_monthly.R
@@ -25,7 +25,7 @@
hydro_imgw_monthly = function(year,
coords = FALSE,
station = NULL,
- col_names= "short",
+ col_names = "short",
allow_failure = TRUE,
...) {
@@ -86,7 +86,7 @@ hydro_imgw_monthly_bp = function(year,
unzip(zipfile = temp, exdir = temp2)
file1 = paste(temp2, dir(temp2), sep = "/")[1]
data1 = imgw_read(translit, file1)
- colnames(data1) = meta[[1]][, 1]
+ colnames(data1) = meta[, 1]
all_data[[i]] = data1
}
all_data = do.call(rbind, all_data)
@@ -94,20 +94,20 @@ hydro_imgw_monthly_bp = function(year,
all_data[all_data == 9999] = NA
all_data[all_data == 99999.999] = NA
all_data[all_data == 99.9] = NA
- colnames(all_data) = meta[[1]][, 1]
+ colnames(all_data) = meta[, 1]
# coords
if (coords) {
- all_data = merge(climate::imgw_hydro_stations, all_data, by.x = "id", by.y = "Kod stacji", all.y = TRUE)
+ all_data = merge(climate::imgw_hydro_stations, all_data, by.x = "id", by.y = "PSKDSZS", all.y = TRUE)
}
#station selection
if (!is.null(station)) {
if (is.character(station)) {
- all_data = all_data[substr(all_data$`Nazwa stacji`, 1, nchar(station)) == station, ]
+ all_data = all_data[substr(all_data$PSNZWP, 1, nchar(station)) == station, ]
if (nrow(all_data) == 0) {
stop("Selected station(s) is not available in the database.", call. = FALSE)
}
} else if (is.numeric(station)) {
- all_data = all_data[all_data$`Kod stacji` %in% station, ]
+ all_data = all_data[all_data$PSKDSZS %in% station, ]
if (nrow(all_data) == 0) {
stop("Selected station(s) is not available in the database.", call. = FALSE)
}
@@ -115,17 +115,17 @@ hydro_imgw_monthly_bp = function(year,
stop("Selected station(s) are not in the proper format.", call. = FALSE)
}
}
- all_data = all_data[do.call(order, all_data[grep(x = colnames(all_data), "Nazwa stacji|Rok hydrologiczny|w roku hydro")]), ]
+ all_data = all_data[do.call(order, all_data[grep(x = colnames(all_data), "PSNZWP|MCROKH")]), ]
# fix dates and add as seperate column:
- yy_ind = grep(x = colnames(all_data), "Rok hydrologiczny")
- mm_ind = grep(x = colnames(all_data), "kalendarzowy")
+ yy_ind = grep(x = colnames(all_data), "MCROKH")
+ mm_ind = grep(x = colnames(all_data), "MCMSCK")
data_df = all_data[, c(yy_ind, mm_ind)]
data_df$day = 1
data_df$yy = ifelse(data_df[, 2] >= 11, data_df[, 1] - 1, data_df[, 1])
all_data$Data = as.Date(ISOdate(year = data_df$yy, month = data_df[, 2], day = data_df$day))
all_data = all_data[, c(1:3, ncol(all_data), 4:(ncol(all_data) - 1)), ]
- all_data = hydro_shortening_imgw(all_data, col_names = col_names, ...)
+ #all_data = hydro_shortening_imgw(all_data, col_names = col_names, ...)
return(all_data)
}
diff --git a/R/hydro_metadata_imgw.R b/R/hydro_metadata_imgw.R
index fcd5419..2cff223 100644
--- a/R/hydro_metadata_imgw.R
+++ b/R/hydro_metadata_imgw.R
@@ -29,13 +29,13 @@ hydro_metadata_imgw_bp = function(interval) {
if (interval == "daily") {
# dobowe
- address_meta1 = paste0(base_url, "dobowe/codz_info.txt")
- address_meta2 = paste0(base_url, "dobowe/zjaw_info.txt")
+ address_meta1 = paste0(base_url, "dobowe/CODZ_publiczne_format.txt")
+ address_meta2 = paste0(base_url, "dobowe/ZJAW_publiczne_format.txt")
meta = list(clean_metadata_hydro(address_meta1, interval),
clean_metadata_hydro(address_meta2, interval))
} else if (interval == "monthly") {
#miesieczne
- address_meta = paste0(base_url, "miesieczne/mies_info.txt")
+ address_meta = paste0(base_url, "miesieczne/MIES_publiczne_format.txt")
meta = clean_metadata_hydro(address_meta, interval)
} else {
stop("Wrong `interval` value. It should be either 'daily' or 'monthly'.")
diff --git a/R/match_imgw_wmoid_inds.R b/R/match_imgw_wmoid_inds.R
index ad050b3..ee39e7a 100644
--- a/R/match_imgw_wmoid_inds.R
+++ b/R/match_imgw_wmoid_inds.R
@@ -1,5 +1,5 @@
#' Match WMO station IDs for IMGW SYNOP
-#' @param station vector or station names provided to imgw_meteo_ family of functions
+#' @param station vector or station names provided to meteo_imgw_ family of functions
#' @keywords internal
#' @noRd
match_imgw_wmoid_inds = function(station) {
diff --git a/R/meteo_imgw.R b/R/meteo_imgw.R
index 4e66261..b8cc50d 100644
--- a/R/meteo_imgw.R
+++ b/R/meteo_imgw.R
@@ -12,9 +12,10 @@
#' @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 danepubliczne.imgw.pl
-#' can be name of station CAPITAL LETTERS(character).
-#' It accepts names (characters in CAPITAL LETTERS) or stations' IDs (numeric)
+#' @param station name of meteorological station(s).
+#' It accepts names (characters in CAPITAL LETTERS). Stations' IDs (numeric) are no longer supported.
+#' Please note that station names may change over time and thus sometimes 2 names
+#' are required in some cases, e.g. `c("POZNAŃ", "POZNAŃ-ŁAWICA")`.
#' @export
#' @return A data.frame with columns describing the meteorological parameters
#' (e.g. temperature, wind speed, precipitation) where each row represent a measurement,
diff --git a/R/meteo_imgw_daily.R b/R/meteo_imgw_daily.R
index d883fa2..268d249 100644
--- a/R/meteo_imgw_daily.R
+++ b/R/meteo_imgw_daily.R
@@ -90,6 +90,7 @@ meteo_imgw_daily_bp = function(rank,
# match WMO ID of a given station(s) to download selectively for SYNOP stations
if (!is.null(station) && rank == "synop") {
+ station = find_all_station_names(station)
ids_to_download = match_imgw_wmoid_inds(station)
} else {
ids_to_download = NULL
diff --git a/R/meteo_imgw_hourly.R b/R/meteo_imgw_hourly.R
index f02c8ef..f3f8ec2 100644
--- a/R/meteo_imgw_hourly.R
+++ b/R/meteo_imgw_hourly.R
@@ -8,8 +8,7 @@
#' @param status leave the columns with measurement and observation statuses
#' (default status = FALSE - i.e. the status columns are deleted)
#' @param coords add coordinates of the station (logical value TRUE or FALSE)
-#' @param station name or ID of meteorological station(s).
-#' It accepts names (characters in CAPITAL LETTERS) or stations' IDs (numeric)
+#' @param station name of meteorological station(s) (character vector)
#' @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
@@ -250,6 +249,7 @@ meteo_imgw_hourly_bp = function(rank,
# station selection and names cleaning:
if (!is.null(station)) {
if (is.character(station)) {
+ find_all_station_names(station)
inds = unique(as.numeric(unlist(sapply(station, function(x) grep(pattern = x, x = trimws(all_data$POST))))))
if (any(is.na(inds)) || length(inds) == 0) {
env$logs = c(
diff --git a/R/meteo_imgw_monthly.R b/R/meteo_imgw_monthly.R
index 7ccbe7f..aec6c9c 100644
--- a/R/meteo_imgw_monthly.R
+++ b/R/meteo_imgw_monthly.R
@@ -8,8 +8,8 @@
#' @param status leave the columns with measurement and observation statuses
#' (default status = FALSE - i.e. the status columns are deleted)
#' @param coords add coordinates of the station (logical value TRUE or FALSE)
-#' @param station name or ID of meteorological station(s).
-#' It accepts names (characters in CAPITAL LETTERS) or stations' IDs (numeric).
+#' @param station name of meteorological station(s).
+#' It accepts names (characters in CAPITAL LETTERS). Stations' IDs (numeric) are no longer supported.
#' Please note that station names may change over time and thus sometimes 2 names
#' are required in some cases, e.g. `c("POZNAŃ", "POZNAŃ-ŁAWICA")`.
#' @param col_names three types of column names possible: "short" - default,
@@ -39,13 +39,13 @@
#' }
#'
meteo_imgw_monthly = function(rank = "synop",
- year,
- status = FALSE,
- coords = FALSE,
- station = NULL,
- col_names = "short",
- allow_failure = TRUE,
- ...) {
+ year,
+ status = FALSE,
+ coords = FALSE,
+ station = NULL,
+ col_names = "short",
+ allow_failure = TRUE,
+ ...) {
if (allow_failure) {
tryCatch(
meteo_imgw_monthly_bp(
@@ -113,7 +113,7 @@ meteo_imgw_monthly_bp = function(rank,
ind = lapply(years_in_catalogs, function(x) sum(x %in% year) > 0)
catalogs = catalogs[unlist(ind)]
- all_data = vector("list", length = length(catalogs))
+ all_data = NULL
for (i in seq_along(catalogs)) {
catalog = gsub(catalogs[i], pattern = "/", replacement = "")
@@ -155,8 +155,8 @@ meteo_imgw_monthly_bp = function(rank,
if (file.exists(file2)) {
data2 = imgw_read(translit, file2)
colnames(data2) = meta[[2]]$parameters
- for (labs in seq_along(meta[[1]]$parameters)) {
- attr(data2[[labs]], "label") = meta[[1]]$label[[labs]]
+ for (labs in seq_along(meta[[2]]$parameters)) {
+ attr(data2[[labs]], "label") = meta[[2]]$label[[labs]]
}
data2$POST = trimws(data2$POST)
data.table::setDT(data2)
@@ -248,7 +248,6 @@ meteo_imgw_monthly_bp = function(rank,
# adding option to shorten columns and removing duplicates:
# TODO: turned off temporarily, consistent with daily implementation
# all_data = meteo_shortening_imgw(all_data, col_names = col_names, ...)
- rownames(all_data) = NULL
-
+ rownames(all_data) = 1:nrow(all_data)
return(all_data) # clipping to selected years only
}
diff --git a/R/utils.R b/R/utils.R
index d227012..fe79e87 100644
--- a/R/utils.R
+++ b/R/utils.R
@@ -49,3 +49,36 @@ remove_status = function(df) {
return(df)
}
+
+
+
+#' Find all variants of station' names
+#'
+#' For IMGW-PIB stations different naming were used historically. For example,
+#' `POZNAŃ` and ``POZNAŃ-ŁAWICA, thus both names should be used when searching
+#'for the station. This function finds all variants of station' names
+#' status information and expand the created object
+#'
+#' @param station_name character vector of station names
+#' @export
+#' @returns character vector of station names with all variants of station's names
+#' @examples {
+#' find_all_station_names(c("WARSZAWA", "POZNAŃ"))
+#' }
+
+find_all_station_names = function(station_name) {
+
+ pattern = paste0("(?=.*", toupper(station_name), ")(?=.*-)")
+ matches = unlist(
+ sapply(pattern, function(x) {
+ grep(x, climate::imgw_meteo_stations$station,
+ perl = TRUE,
+ ignore.case = TRUE,
+ value = TRUE)
+ }
+ )
+ )
+ names(matches) = NULL
+
+ return(sort(unique(c(station_name, matches))))
+}
diff --git a/man/find_all_station_names.Rd b/man/find_all_station_names.Rd
new file mode 100644
index 0000000..d8d3de7
--- /dev/null
+++ b/man/find_all_station_names.Rd
@@ -0,0 +1,25 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/utils.R
+\name{find_all_station_names}
+\alias{find_all_station_names}
+\title{Find all variants of station' names}
+\usage{
+find_all_station_names(station_name)
+}
+\arguments{
+\item{station_name}{character vector of station names}
+}
+\value{
+character vector of station names with all variants of station's names
+}
+\description{
+For IMGW-PIB stations different naming were used historically. For example,
+\code{POZNAŃ} and ``POZNAŃ-ŁAWICA, thus both names should be used when searching
+for the station. This function finds all variants of station' names
+status information and expand the created object
+}
+\examples{
+{
+find_all_station_names(c("WARSZAWA", "POZNAŃ"))
+}
+}
diff --git a/man/meteo_imgw.Rd b/man/meteo_imgw.Rd
index 4ed5913..5e6bc86 100644
--- a/man/meteo_imgw.Rd
+++ b/man/meteo_imgw.Rd
@@ -27,9 +27,10 @@ meteo_imgw(
\item{coords}{add coordinates of the station (logical value TRUE or FALSE)}
-\item{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)}
+\item{station}{name of meteorological station(s).
+It accepts names (characters in CAPITAL LETTERS). Stations' IDs (numeric) are no longer supported.
+Please note that station names may change over time and thus sometimes 2 names
+are required in some cases, e.g. \code{c("POZNAŃ", "POZNAŃ-ŁAWICA")}.}
\item{col_names}{three types of column names possible: "short" - default, values with shorten names,
"full" - full English description, "polish" - original names in the dataset}
diff --git a/man/meteo_imgw_hourly.Rd b/man/meteo_imgw_hourly.Rd
index c0fcb0d..7f11607 100644
--- a/man/meteo_imgw_hourly.Rd
+++ b/man/meteo_imgw_hourly.Rd
@@ -25,8 +25,7 @@ meteo_imgw_hourly(
\item{coords}{add coordinates of the station (logical value TRUE or FALSE)}
-\item{station}{name or ID of meteorological station(s).
-It accepts names (characters in CAPITAL LETTERS) or stations' IDs (numeric)}
+\item{station}{name of meteorological station(s) (character vector)}
\item{col_names}{three types of column names possible: "short" - default,
values with shorten names, "full" - full English description,
diff --git a/man/meteo_imgw_monthly.Rd b/man/meteo_imgw_monthly.Rd
index 3ea4887..3d3f222 100644
--- a/man/meteo_imgw_monthly.Rd
+++ b/man/meteo_imgw_monthly.Rd
@@ -25,8 +25,8 @@ meteo_imgw_monthly(
\item{coords}{add coordinates of the station (logical value TRUE or FALSE)}
-\item{station}{name or ID of meteorological station(s).
-It accepts names (characters in CAPITAL LETTERS) or stations' IDs (numeric).
+\item{station}{name of meteorological station(s).
+It accepts names (characters in CAPITAL LETTERS). Stations' IDs (numeric) are no longer supported.
Please note that station names may change over time and thus sometimes 2 names
are required in some cases, e.g. \code{c("POZNAŃ", "POZNAŃ-ŁAWICA")}.}
diff --git a/tests/testthat/test-hydro_imgw.R b/tests/testthat/test-hydro_imgw.R
index 9fa844b..2892d46 100644
--- a/tests/testthat/test-hydro_imgw.R
+++ b/tests/testthat/test-hydro_imgw.R
@@ -3,12 +3,6 @@ y <- 2017
test_that("hydro_imgw_not_available", {
- expect_error(suppressWarnings(hydro_imgw(interval = "daily", year = 1960, coord = TRUE,
- station = "not available", allow_failure = FALSE)))
-
- expect_error(suppressWarnings(hydro_imgw(interval = "daily", year = 1960, coord = TRUE,
- station = 999, allow_failure = FALSE)))
-
expect_error(suppressWarnings(hydro_imgw(interval = "monthly", year = 1960, coord = TRUE,
station = "not available", allow_failure = FALSE)))
@@ -24,7 +18,7 @@ test_that("hydro_imgw_not_available", {
if (is.data.frame(h2022_2023) & nrow(h2022_2023 > 50000)) {
testthat::expect_true(is.data.frame(h2022_2023))
testthat::expect_true(nrow(h2022_2023) > 50000)
- testthat::expect_true(class(h2022_2023$date) == "Date")
+ testthat::expect_true(class(h2022_2023$Data) == "Date")
}
}
@@ -36,7 +30,7 @@ test_that("hydro_imgw_not_available", {
if (is.data.frame(h2022_2023d) & nrow(h2022_2023d > 50000)) {
testthat::expect_true(is.data.frame(h2022_2023d))
testthat::expect_true(nrow(h2022_2023d) > 50000)
- testthat::expect_true(class(h2022_2023d$date) == "Date")
+ testthat::expect_true(class(h2022_2023d$Data) == "Date")
}
}
diff --git a/tests/testthat/test-hydro_metadata_imgw.R b/tests/testthat/test-hydro_metadata_imgw.R
index c344052..62982d4 100644
--- a/tests/testthat/test-hydro_metadata_imgw.R
+++ b/tests/testthat/test-hydro_metadata_imgw.R
@@ -4,9 +4,11 @@ h_d <- suppressWarnings(hydro_metadata_imgw("daily"))
h_m <- suppressWarnings(hydro_metadata_imgw("monthly"))
test_that("hydro-metadata works!", {
- if (is.list(h_d) && is.list(h_m)) {
- expect_equal(dim(h_d[[1]]), c(10, 1))
- expect_equal(dim(h_d[[2]]), c(10, 1))
- expect_equal(dim(h_m[[1]]), c(10, 1))
+ if (is.list(h_d)) {
+ expect_equal(dim(h_d[[1]]), c(10, 2))
+ expect_equal(dim(h_d[[2]]), c(10, 2))
+ }
+ if (is.data.frame(h_m)) {
+ expect_equal(dim(h_m), c(10, 2))
}
})
diff --git a/tests/testthat/test-meteo_imgw.R b/tests/testthat/test-meteo_imgw.R
index 93e9d83..ba1940a 100644
--- a/tests/testthat/test-meteo_imgw.R
+++ b/tests/testthat/test-meteo_imgw.R
@@ -19,12 +19,9 @@ test_that("meteo_imgw works!", {
x <- meteo_imgw("monthly", "synop", year = y, status = TRUE)
x <- meteo_imgw("monthly", "synop", year = y, coords = TRUE)
x <- meteo_imgw("monthly", "synop", year = y, col_names = "full")
- x <- meteo_imgw("monthly", "synop", year = y, coords = TRUE, col_names = "full")
- x <- meteo_imgw("monthly", "synop", year = y, col_names = "polish")
x <- meteo_imgw("monthly", "synop", year = y, coords = TRUE, col_names = "polish")
- x <- meteo_imgw("monthly", "synop", year = y, station = "BIAŁYSTOK")
- x2 <- meteo_imgw("monthly", "synop", year = y, station = 353230295)
-
testthat::expect_message(x <- suppressWarnings(meteo_imgw_daily(rank = "synop", year = 2001, station = "blabla")))
+ leszno = meteo_imgw(interval = "monthly", rank = "synop", year = 2020:2021, station = "LESZNO")
+ testthat::expect_equal(nrow(leszno), 24)
}
})
diff --git a/vignettes/articles/pl.Rmd b/vignettes/articles/pl.Rmd
index 40a1bd4..74763b3 100644
--- a/vignettes/articles/pl.Rmd
+++ b/vignettes/articles/pl.Rmd
@@ -48,18 +48,11 @@ framework powinna być dostępne po roku 2000 roku
- **meteo_imgw()** - Pozwala pobrać dane meteorologiczne interwale godzinowym, dziennym lub
miesięcznym o danej randze stacji(SYNOP / CLIMATE / PRECIP) dostępnych w kolekcji dane.imgw.pl.
-Jest to wrapper funckji `meteo_monthly()`, `meteo_daily()` oraz `meteo_hourly()`z pakietu **imgw** (poprzedniej wersji paczki).
-
-- **meteo\_shortening()** - Skracanie nazw kolumn parametrów meteorologicznych
- poprawiając czytelność pobranego zestawu danych i usuwanie zduplikowanych nazw kolumn.
2. Dane hydrologiczne:
- **hydro_imgw()** - Pobieranie danych hydrologicznych o interwale dziennym, miesięcznym lub rocznym ze
stacji dostępnych w repozytorium dane.imgw.pl.
-Jest to wrapper funckji `meteo_monthly()`, `meteo_daily()` oraz `meteo_hourly()`z pakietu **imgw** (poprzedniej
-wersji paczki).
-
3. Dane radiosondażowe :
@@ -79,22 +72,22 @@ h = hydro_imgw(interval = "monthly", year = 2001:2010, coords = TRUE)
head(h)
```
-Zmienna `idex` reprezentuje id ekstremum, gdzie "1" oznacza minimum, "2" oznacza średnią, a "3" maksimum. ^[Więcej informacji na ten temat można znaleźć w zestawie danych`hydro_abbrev`.]
+Zmienna `MCWSKEX` reprezentuje id ekstremum, gdzie "1" oznacza minimum, "2" oznacza średnią, a "3" maksimum. ^[Więcej informacji na ten temat można znaleźć w zestawie danych`hydro_abbrev`.]
Analizy hydrologiczne często koncentrują się na jednej grupy zjawisk, np. związanych z przepływami maksymalnymi. W tym
celu pozostaną w ramce danych tylko wartości przepływów maksymalnych oraz kolumny zawierające interesujące nas
-informacje, tj. identyfikator stacji - `id`, rok hydrologiczny (` hyy`), szerokość geograficzną `X` i długość
+informacje, tj. identyfikator stacji - `id`, rok hydrologiczny (`MCROKH`), szerokość geograficzną `X` i długość
geograficzną` Y`.
Następnie obliczymy średnią maksymalną wartość przepływu na stacjach w każdym roku za pomocą ** dplyr ** `summarise()`,
-oraz rozdzielimy dane według roku używając ** tidyr **' `spread ()` aby uzyskać roczne średnie maksymalne przepływy w
+oraz rozdzielimy dane według roku używając ** tidyr **' `spread ()` aby uzyskać roczne średnie maksymalne przepływy (`MCPRZP`) w
kolejnych kolumnach.
```{r filtering, eval=TRUE, include=TRUE}
h2 = h %>%
- filter(idex == 3) %>%
- select(id, station, X, Y, hyy, Q) %>%
- group_by(hyy, id, station, X, Y) %>%
- summarise(srednie_roczne_Q = round(mean(Q, na.rm = TRUE),1)) %>%
- spread(hyy, srednie_roczne_Q)
+ filter(MCWSKEX == 3) %>%
+ select(id, PSNZWP, X, Y, MCROKH, MCPRZP) %>%
+ group_by(MCROKH, id, PSNZWP, X, Y) %>%
+ summarise(srednie_roczne_Q = round(mean(MCPRZP, na.rm = TRUE),1)) %>%
+ spread(MCROKH, srednie_roczne_Q)
```
```{r filtering2, echo=FALSE}
@@ -126,7 +119,7 @@ world = ne_countries(scale = "medium", returnclass = "sf")
h3 = h2 %>%
filter(!is.na(X)) %>%
- st_as_sf(coords = c("X", "Y"))
+ st_as_sf(coords = c("X", "Y"), crs = 4326)
tm_shape(h3) +
tm_symbols(size = as.character(c(2001:2010)),
diff --git a/vignettes/articles/usecase_ogimet.Rmd b/vignettes/articles/usecase_ogimet.Rmd
index 880fb3a..0eb99d4 100644
--- a/vignettes/articles/usecase_ogimet.Rmd
+++ b/vignettes/articles/usecase_ogimet.Rmd
@@ -33,7 +33,7 @@ df$date <- df$Date
df <- left_join(df, wdir)
df$ws <- df$ffkmh / 3.6 # conversion to m/s from km/h
-df$gust <- df$Gustkmh / 3.6 # conversion to m/s from km/h
+df$gust <- as.numeric(df$Gustmax) / 3.6 # conversion to m/s from km/h
windRose(mydata = df, ws = "ws", wd = "dir", type = "season", paddle = FALSE,
main = "Svalbard Lufthavn (2018)", ws.int = 3, dig.lab = 3, layout = c(4, 1))