Skip to content

Commit

Permalink
fix: remove hydro semiannual and annual
Browse files Browse the repository at this point in the history
  • Loading branch information
bczernecki committed Oct 21, 2024
1 parent 6edd6bd commit 9ac7075
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 251 deletions.
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

export(.onAttach)
export(hydro_imgw)
export(hydro_imgw_annual)
export(hydro_imgw_daily)
export(hydro_imgw_monthly)
export(hydro_shortening_imgw)
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# climate 1.2.2

* Fixes for `hydro_imgw()` set of functions due to changes in the IMGW-PIB hydrological datasets
* Fixes and modifications for `hydro_imgw()` set of functions due to changes in the IMGW-PIB hydrological datasets
* adjusting code to recognize different encoding and directory structure
* adjusting changes in metadata
* removed option to download data for "semiannual and annual" time resolutions due to inconsistencies in the data
* Fix unit tests for ogimet-related datasets

# climate 1.2.1
Expand Down
17 changes: 0 additions & 17 deletions R/clean_metadata_hydro.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,5 @@ clean_metadata_hydro = function(address, interval) {
if (interval == "daily") {
b = data.frame(parameters = a[1:10])
}
if (interval == "semiannual_and_annual") {
godzina = paste0(a[13], ":", a[14])
data = c(a[10:12], godzina)
data_od = paste0("wystapienie_od_", data)
data_do = paste0("wystapienie_do_", data)
SPT = unlist(strsplit(a[8], "]/")) # stan/przeplyw/temperatura
SPT[1] = paste0(SPT[1], "]")
SPT[2] = paste0(SPT[2], "]")
b = NULL
for (i in seq_along(SPT)) {
tmp = c(a[1:7], SPT[i], data_od, data_do)
b = cbind(b, tmp)
}
b = list("H" = data.frame(parameters = b[, 1]),
"Q" = data.frame(parameters = b[, 2]),
"T" = data.frame(parameters = b[, 3]))
}
return(b)
}
14 changes: 3 additions & 11 deletions R/hydro_imgw.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
#' Downloading 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 interval temporal resolution of the data ("daily" or "monthly")
#' @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
Expand Down Expand Up @@ -38,20 +37,13 @@ hydro_imgw = function(interval,
# dobowe
calosc = hydro_imgw_daily(year = year, coords = coords, station = station, col_names = col_names, ...)
} else if (interval == "monthly") {
#miesieczne
# miesieczne
calosc = hydro_imgw_monthly(year = year,
coords = coords,
station = station,
col_names = col_names, ...)
} else if (interval == "semiannual_and_annual") {
# polroczne_i_roczne
calosc = hydro_imgw_annual(year = year,
coords = coords,
value = value,
station = station,
col_names = col_names, ...)
} else{
stop("Wrong `interval` value. It should be either 'daily', 'monthly', or 'semiannual_and_annual'.", call. = FALSE)
stop("Wrong `interval` value. It should be either 'daily' or 'monthly'", call. = FALSE)
}
return(calosc)
}
146 changes: 0 additions & 146 deletions R/hydro_imgw_annual.R

This file was deleted.

8 changes: 2 additions & 6 deletions R/hydro_metadata_imgw.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' 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")
#' @param interval temporal resolution of the data ("daily" or "monthly")
#' @param allow_failure logical - whether to proceed or stop on failure. By default set to TRUE (i.e. don't stop on error). For debugging purposes change to FALSE
#' @keywords internal
#' @noRd
Expand Down Expand Up @@ -37,12 +37,8 @@ hydro_metadata_imgw_bp = function(interval) {
#miesieczne
address_meta = paste0(base_url, "miesieczne/mies_info.txt")
meta = clean_metadata_hydro(address_meta, interval)
} else if (interval == "semiannual_and_annual") {
# polroczne_i_roczne
address_meta = paste0(base_url, "polroczne_i_roczne/polr_info.txt")
meta = clean_metadata_hydro(address_meta, interval)
} else {
stop("Wrong `interval` value. It should be either 'daily', 'monthly', or 'semiannual_and_annual'.")
stop("Wrong `interval` value. It should be either 'daily' or 'monthly'.")
}

return(meta)
Expand Down
2 changes: 1 addition & 1 deletion R/nearest_stations_imgw.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ nearest_stations_imgw_bp = function(type,
if (type == "meteo") {
result = unique(meteo_imgw_monthly(rank = rank, year = year, coords = TRUE)[, c(2:5)])
} else if (type == "hydro") {
result = unique(hydro_imgw_annual(year = year, coords = TRUE)[, c(1:4)])
result = unique(hydro_imgw_monthly(year = year, coords = TRUE)[, c(1:4)])
} else {
stop("You've provided wrong type argument; please use: \"meteo\", or \"hydro\"")
}
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ It is a wrapper for `meteo_monthly()`, `meteo_daily()`, and `meteo_hourly()`

- **hydro_imgw()** - Downloading hourly, daily, and monthly hydrological data from the SYNOP / CLIMATE / PRECIP stations available in the
danepubliczne.imgw.pl collection.
It is a wrapper for previously developed set of functions such as: `hydro_annual()`, `hydro_monthly()`, and `hydro_daily()`
It is a wrapper for previously developed set of functions such as: `hydro_monthly()`, and `hydro_daily()`

### Auxiliary functions and datasets

Expand Down Expand Up @@ -166,15 +166,15 @@ head(m)
#> 580 21.3 -4.3 5.7 13.8 -8.3 9.4
#> 581 23.1 1.0 9.6 16.6 -1.8 36.4
h = hydro_imgw(interval = "semiannual_and_annual", year = 2010:2011)
h = hydro_imgw(interval = "daily", year = 2010:2011)
head(h)
id station riv_or_lake hyy idyy Mesu idex H beyy bemm bedd behm
3223 150210180 ANNOPOL Wisła (2) 2010 13 H 1 227 2009 12 19 NA
3224 150210180 ANNOPOL Wisła (2) 2010 13 H 2 319 NA NA NA NA
3225 150210180 ANNOPOL Wisła (2) 2010 13 H 3 531 2010 3 3 18
3226 150210180 ANNOPOL Wisła (2) 2010 14 H 1 271 2010 8 29 NA
3227 150210180 ANNOPOL Wisła (2) 2010 14 H 1 271 2010 10 27 NA
3228 150210180 ANNOPOL Wisła (2) 2010 14 H 2 392 NA NA NA NA
id station riv_or_lake hyy idhyy dd H Q T mm thick id_ice p_ice
97843 150210180 ANNOPOL Wisła (2) 2010 1 1 287 436 NA 11 NA NA NA
507527 150210180 ANNOPOL Wisła (2) 2010 1 1 287 436 NA 11 NA NA NA
97844 150210180 ANNOPOL Wisła (2) 2010 1 2 282 412 NA 11 NA NA NA
507528 150210180 ANNOPOL Wisła (2) 2010 1 2 282 412 NA 11 NA NA NA
97845 150210180 ANNOPOL Wisła (2) 2010 1 3 272 368 NA 11 NA NA NA
507529 150210180 ANNOPOL Wisła (2) 2010 1 3 272 368 NA 11 NA NA NA
```

## Example 5
Expand Down
3 changes: 1 addition & 2 deletions man/hydro_imgw.Rd

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

47 changes: 0 additions & 47 deletions man/hydro_imgw_annual.Rd

This file was deleted.

13 changes: 8 additions & 5 deletions tests/testthat/test-hydro_imgw.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ test_that("hydro_imgw_not_available", {
testthat::expect_true(nrow(h2022_2023) > 50000)
}

h2022_2023d = hydro_imgw(interval = "daily",
year = 2022:2023,
coord = TRUE,
allow_failure = FALSE)
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)
}

expect_error(suppressWarnings(hydro_imgw(interval = "semiannual_and_annual", year = 1960, coord = TRUE,
station = "not available", allow_failure = FALSE)))

expect_error(suppressWarnings(hydro_imgw(interval = "semiannual_and_annual", year = 1960, coord = TRUE,
station = 999, allow_failure = FALSE)))
})
4 changes: 0 additions & 4 deletions tests/testthat/test-hydro_metadata_imgw.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@ context("hydro-metadata")

h_d <- suppressWarnings(hydro_metadata_imgw("daily"))
h_m <- suppressWarnings(hydro_metadata_imgw("monthly"))
h_a <- suppressWarnings(hydro_metadata_imgw("semiannual_and_annual"))

test_that("hydro-metadata works!", {
if (is.list(h_d) && is.list(h_m) && is.list(h_a)) {
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))
expect_equal(dim(h_a[[1]]), c(16, 1))
expect_equal(dim(h_a[[2]]), c(16, 1))
expect_equal(dim(h_a[[3]]), c(16, 1))
}
})
2 changes: 1 addition & 1 deletion vignettes/getstarted.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ It is a wrapper for `meteo_monthly()`, `meteo_daily()`, and `meteo_hourly()`

- **hydro_imgw()** - Downloading hourly, daily, and monthly hydrological data from the SYNOP / CLIMATE / PRECIP stations available in the
danepubliczne.imgw.pl collection.
It is a wrapper for `hydro_annual()`, `hydro_monthly()`, and `hydro_daily()`
It is a wrapper for `hydro_monthly()`, and `hydro_daily()`

### Auxiliary functions and datasets

Expand Down

0 comments on commit 9ac7075

Please sign in to comment.