Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ vignettes/articles/usecase.Rmd
^\.positai$
^\.claude$
CLAUDE.md$
^\.posit/assistant$
2 changes: 1 addition & 1 deletion .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Run commands from the package root.
- **OGIMET**: HTML is scraped with `XML::readHTMLTable`; station identity is based on WMO IDs. Hourly precipitation post-processing is handled by `precip_split()`.
- **NOAA / Wyoming**: direct file or page downloads for ISH hourly data, Mauna Loa CO2, and Wyoming soundings.

- IMGW column renaming is a distinct normalization layer. Most IMGW functions accept `col_names = "short" | "full" | "polish"` and pass results through `meteo_shortening_imgw()` or `hydro_shortening_imgw()`. The mapping tables live in built-in datasets backed by `data-raw/`.
- IMGW column renaming is a distinct normalization layer. IMGW functions return short English names and attach the original full parameter label as a per-column `label` attribute through `meteo_shortening_imgw()` or `hydro_shortening_imgw()`. The mapping tables live in built-in datasets backed by `data-raw/`.

- Package data and docs follow standard R package patterns:
- exported code in `R/`
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ pkgdown
test-out.txt
.positai
.aider*
.posit/assistant
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Run from the package root in R:
- **OGIMET**: HTML scraping via `XML::readHTMLTable` from `ogimet.com`. Stations are identified by WMO ID. `precip_split` / `R/precip_split.R` handles 6/12/24h precipitation disaggregation for hourly data.
- **NOAA / Wyoming**: direct file downloads (ISH gzipped fixed-width, CO2 text, sounding HTML).

**Column-name shortening layer.** Most IMGW download functions accept `col_names = "short" | "full" | "polish"` and pass the raw frame through `meteo_shortening_imgw()` / `hydro_shortening_imgw()` (in `R/*_shortening_imgw.R`). Full and short names are looked up against `imgw_meteo_abbrev` / `imgw_hydro_abbrev` (built-in data). When you add a new IMGW column, update both the abbrev table (`data-raw/`) and the shortener.
**Column-name shortening layer.** IMGW download functions return short English names and attach the original full IMGW parameter label as a per-column `label` attribute. Names are looked up against `imgw_meteo_abbrev` / `imgw_hydro_abbrev` (built-in data). When you add a new IMGW column, update both the abbrev table (`data-raw/`) and the shortener.

**Graceful network failure** is required for CRAN. Use `test_url()` (`R/test_url.R`) to gate downloads, and follow the existing `allow_failure = TRUE` pattern: wrap the real worker (`*_bp` "best practice" inner function) in `tryCatch` so user-facing functions return `NULL`/`invisible()` with a `message()` instead of erroring. Tests follow the same convention — every network test starts with `if (!curl::has_internet()) return(invisible(NULL))`. Don't add tests that fail when offline.

Expand Down
2 changes: 1 addition & 1 deletion 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: 1.4.0
Version: 1.4.1
Authors@R: c(person(given = "Bartosz",
family = "Czernecki",
role = c("aut", "cre"),
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# climate 1.4.1

* fixed IMGW meteorological and hydrological parameter mappings for current metadata labels
* removed the `col_names` choice between short, full, and Polish column names to simplify usage
* original full IMGW parameter names are available through each column's `label` attribute
* updated documentation, README, and vignettes to describe the simplified naming scheme


# climate 1.4.0

* adding the `synop_parser()` function for reading raw SYNOP messages
Expand Down
15 changes: 11 additions & 4 deletions R/hydro_imgw.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#' @return A data.frame with columns describing the hydrological parameters
#' (e.g. flow, water level) where each row represent a measurement,
#' depending on the interval, at a given hour, month or year.
#' IMGW parameter columns carry a `label` attribute with the original metadata label.
#' If `coords = TRUE` additional two columns with geographic coordinates are added.
#' @examples
#' \donttest{
Expand All @@ -30,12 +31,18 @@ hydro_imgw = function(interval,

if (interval == "daily") {
# dobowe
calosc = hydro_imgw_daily(year = year, station = station, ...)
calosc = hydro_imgw_daily(
year = year,
station = station,
...
)
} else if (interval == "monthly") {
# miesieczne
calosc = hydro_imgw_monthly(year = year,
station = station,
...)
calosc = hydro_imgw_monthly(
year = year,
station = station,
...
)
} else{
stop("Wrong `interval` value. It should be either 'daily' or 'monthly'", call. = FALSE)
}
Expand Down
2 changes: 2 additions & 0 deletions R/hydro_imgw_daily.R
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ hydro_imgw_daily_bp = function(year,
attr(all_data[[cols]], "label") = meta$label[ind]
}
}
all_data = imgw_rename_params_to_labels(all_data, meta)
all_data = hydro_shortening_imgw(all_data, ...)

return(all_data)
}
2 changes: 2 additions & 0 deletions R/hydro_imgw_monthly.R
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ hydro_imgw_monthly_bp = function(year,
attr(all_data[[cols]], "label") = meta$label[ind]
}
}
all_data = imgw_rename_params_to_labels(all_data, meta)
all_data = hydro_shortening_imgw(all_data, ...)

return(all_data)
}
60 changes: 30 additions & 30 deletions R/hydro_shortening_imgw.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,58 @@
#' 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
#' @param remove_duplicates whether to remove duplicated column names
#' (default TRUE - i.e., columns with duplicated names are deleted)
#' @export
#' @returns data.frame with shorten names of hydrological parameters
#' @returns data.frame with short English names of hydrological parameters.
#' Existing column attributes, including the original IMGW `label` metadata,
#' are preserved.
#' @examples
#' \donttest{
#' monthly = data = hydro_imgw("monthly", year = 1969, col_names = "polish")
#' monthly = data = hydro_imgw("monthly", year = 1969)
#'
#' if (is.data.frame(monthly)) {
#' abbr = hydro_shortening_imgw(data = monthly,
#' col_names = "full",
#' remove_duplicates = TRUE)
#' abbr = hydro_shortening_imgw(data = monthly, remove_duplicates = TRUE)
#' head(abbr)
#' }
#' }
#'

hydro_shortening_imgw = function(data,
col_names = "short",
remove_duplicates = TRUE) {

if (col_names != "polish") {
abbrev = climate::imgw_hydro_abbrev
# additional workarounds for mac os but not only...
abbrev$fullname = gsub(x = abbrev$fullname, pattern = "'", replacement = "")
abbrev$fullname = gsub(x = abbrev$fullname, pattern = "\\^", replacement = "")
# end of workaround
orig_columns = trimws(gsub("\\s+", " ", colnames(data))) # remove double spaces
data = as.data.frame(data)
column_attributes = lapply(data, attributes)

matches = match(orig_columns, abbrev$fullname)
matches = matches[!is.na(matches)]
abbrev = climate::imgw_hydro_abbrev
# additional workarounds for mac os but not only...
abbrev$fullname = gsub(x = abbrev$fullname, pattern = "'", replacement = "")
abbrev$fullname = gsub(x = abbrev$fullname, pattern = "\\^", replacement = "")
abbrev$fullname = stringi::stri_trans_general(abbrev$fullname, "LATIN-ASCII")
# end of workaround
orig_columns = trimws(gsub("\\s+", " ", colnames(data))) # remove double spaces
orig_columns = gsub(x = orig_columns, pattern = "'", replacement = "")
orig_columns = gsub(x = orig_columns, pattern = "\\^", replacement = "")
orig_columns = stringi::stri_trans_general(orig_columns, "LATIN-ASCII")
# `Data` is created by the package and is not an IMGW parameter.
orig_columns[orig_columns == "Data"] = NA_character_

if (col_names == "short") {
# abbrev english
colnames(data)[orig_columns %in% abbrev$fullname] = abbrev$abbr_eng[matches]
}

if (col_names == "full") {
# full english names:
colnames(data)[orig_columns %in% abbrev$fullname] = abbrev$fullname_eng[matches]
}
}
matches = match(orig_columns, abbrev$fullname)
matches = matches[!is.na(matches)]
colnames(data)[orig_columns %in% abbrev$fullname] = abbrev$abbr_eng[matches]

# removing duplicated column names: (e.g. station's name)
if (remove_duplicates == TRUE) {
data = data[, !duplicated(colnames(data))]
keep = !duplicated(colnames(data))
data = data[, keep, drop = FALSE]
column_attributes = column_attributes[keep]
}
data = unique(data)
for (ind in seq_along(column_attributes)) {
if (!is.null(column_attributes[[ind]])) {
attributes(data[[ind]]) = column_attributes[[ind]]
}
}
rownames(data) = NULL
return(data)
}
13 changes: 4 additions & 9 deletions R/meteo_imgw.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
#' (default `FALSE` — status columns are deleted). Not used when `rank = "telemetry"`.
#' @param coords add coordinates of the station (logical value `TRUE` or `FALSE`).
#' Default `FALSE`.
#' @param col_names column name style: `"short"` (default), `"full"` (English descriptions),
#' or `"polish"` (original dataset names). Not used when `rank = "telemetry"`.
#' @param station name of meteorological station(s).
#' For ranks `"synop"`, `"climate"`, `"precip"`: station name(s) in CAPITAL LETTERS.
#' Please note that station names may change over time — sometimes two names are required,
Expand All @@ -33,6 +31,7 @@
#' @return A data.frame with meteorological parameters where each row is a measurement.
#' For ranks `"synop"`, `"climate"`, `"precip"`: measurements at a given hour, day, or month,
#' depending on `interval`. If `coords = TRUE` two additional coordinate columns are appended.
#' IMGW parameter columns also carry a `label` attribute with the original Polish metadata label.
#' For `rank = "telemetry"`: a data.table with 10-minute interval observations (not
#' expert-validated). If `coords = TRUE` columns `name`, `lon`, `lat`, and `alt` are appended.
#' @examples
Expand All @@ -52,7 +51,6 @@ meteo_imgw = function(interval = NULL,
status = FALSE,
coords = FALSE,
station = NULL,
col_names = "short",
parameters = NULL,
...) {
if (rank == "telemetry") {
Expand All @@ -70,22 +68,19 @@ meteo_imgw = function(interval = NULL,
year = year,
status = status,
coords = coords,
station = station,
col_names = col_names, ...)
station = station, ...)
} else if (interval == "monthly") {
result = meteo_imgw_monthly(rank = rank,
year = year,
status = status,
coords = coords,
station = station,
col_names = col_names, ...)
station = station, ...)
} else if (interval == "hourly") {
result = meteo_imgw_hourly(rank = rank,
year = year,
status = status,
coords = coords,
station = station,
col_names = col_names, ...)
station = station, ...)
} else {
stop("Wrong `interval` value. It should be either 'hourly', 'daily', or 'monthly'.")
}
Expand Down
12 changes: 2 additions & 10 deletions R/meteo_imgw_daily.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
#' database and thus providing both names is needed
#' (e.g. `station = c("POZNAŃ", "POZNAŃ-ŁAWICA", "WARSZAWA", "WARSZAWA-OKĘCIE")`).
#' Stations' IDs (numeric) are no longer valid
#' @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 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
#' @param ... other parameters that may be passed to the 'shortening' function that
#' shortens column names
Expand All @@ -35,7 +31,6 @@ meteo_imgw_daily = function(rank = "synop",
status = FALSE,
coords = FALSE,
station = NULL,
col_names = "short",
allow_failure = TRUE,
...) {
if (allow_failure) {
Expand All @@ -45,8 +40,7 @@ meteo_imgw_daily = function(rank = "synop",
year,
status,
coords,
station,
col_names
station
),
error = function(e) {
message(paste(
Expand All @@ -63,7 +57,6 @@ meteo_imgw_daily = function(rank = "synop",
status,
coords,
station,
col_names,
...
)
}
Expand All @@ -74,7 +67,6 @@ meteo_imgw_daily_bp = function(rank,
status,
coords,
station,
col_names,
...) {
translit = check_locale()
base_url = "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/"
Expand Down Expand Up @@ -399,7 +391,7 @@ meteo_imgw_daily_bp = function(rank,
}

all_data = imgw_rename_params_to_labels(all_data, meta)
all_data = meteo_shortening_imgw(all_data, col_names = col_names, remove_duplicates = TRUE)
all_data = meteo_shortening_imgw(all_data, remove_duplicates = TRUE)

# check if there any messages gathered in env$logs and if it is not empty then print them:
if (length(env$logs) > 0) {
Expand Down
15 changes: 4 additions & 11 deletions R/meteo_imgw_hourly.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
#' (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 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
#' @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
#' @param ... other parameters that may be passed to the 'shortening'
#' function that shortens column names
Expand All @@ -31,7 +28,6 @@ meteo_imgw_hourly = function(rank = "synop",
status = FALSE,
coords = FALSE,
station = NULL,
col_names = "short",
allow_failure = TRUE,
...) {
if (allow_failure) {
Expand All @@ -41,8 +37,7 @@ meteo_imgw_hourly = function(rank = "synop",
year,
status,
coords,
station,
col_names, ...
station, ...
),
error = function(e) {
message(paste(
Expand All @@ -58,8 +53,7 @@ meteo_imgw_hourly = function(rank = "synop",
year,
status,
coords,
station,
col_names, ...
station, ...
)
}
}
Expand All @@ -70,8 +64,7 @@ meteo_imgw_hourly_bp = function(rank,
year,
status,
coords,
station,
col_names, ...) {
station, ...) {
translit = check_locale()
stopifnot(rank == "synop" | rank == "climate") # for hourly data only synop and climate has data
base_url = "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/"
Expand Down Expand Up @@ -279,7 +272,7 @@ meteo_imgw_hourly_bp = function(rank,
}

all_data = imgw_rename_params_to_labels(all_data, meta)
all_data = meteo_shortening_imgw(all_data, col_names = col_names, ...)
all_data = meteo_shortening_imgw(all_data, ...)

# check if there any messages gathered in env$logs and if it is not empty then print them:
if (length(env$logs) > 0) {
Expand Down
Loading
Loading