Skip to content

Commit 9491d60

Browse files
authored
climate 1.2.6
* feat: selective download for meteo_imgw_daily * fix: selective synop download * fix: styler * climate 1.2.6rc * fix: hydro * fix unit tests * fix: typo in docs
1 parent 4001281 commit 9491d60

16 files changed

+543
-371
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: climate
22
Title: Interface to Download Meteorological (and Hydrological) Datasets
3-
Version: 1.2.5
3+
Version: 1.2.6
44
Authors@R: c(person(given = "Bartosz",
55
family = "Czernecki",
66
role = c("aut", "cre"),

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ importFrom(archive,archive_read)
3333
importFrom(curl,curl_download)
3434
importFrom(curl,has_internet)
3535
importFrom(data.table,as.data.table)
36+
importFrom(data.table,data.table)
3637
importFrom(data.table,fread)
3738
importFrom(stats,na.omit)
3839
importFrom(stats,runif)

NEWS.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# climate 1.2.6
2+
3+
* speeding up selective download for given station names in `meteo_imgw_*` and `hydro_imgw_daily()` functions that simultaneously reduce use of memory
4+
* minor fix for `meteo_imgw_daily` to handle cases with station names containing extra spaces or non-parsable characters
5+
* verbosing currently processed url for easier detection of problematic or corrupted datasets
6+
7+
18
# climate 1.2.5
29

310
* Added 20 sec. pause between subsequent requests to the OGIMET server to avoid server overload.

R/hydro_imgw_daily.R

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#' @param ... other parameters that may be passed to the 'shortening' function that shortens column names
1515
#' @importFrom XML readHTMLTable
1616
#' @importFrom utils download.file unzip read.csv
17-
#' @importFrom data.table fread
17+
#' @importFrom data.table fread data.table
1818
#' @export
1919
#' @returns data.frame with historical hydrological data for the daily time interval
2020
#' @examples \donttest{
@@ -135,10 +135,26 @@ hydro_imgw_daily_bp = function(year,
135135

136136
} #end of loop for (usually monthly) zip files in a given year
137137

138-
all_data[[length(all_data) + 1]] = merge(codz_data, zjaw_data,
138+
all_data[[length(all_data) + 1]] = merge(data.table(codz_data),
139+
data.table(zjaw_data),
139140
by = intersect(colnames(codz_data), colnames(zjaw_data)),
140141
all.x = TRUE)
141142

143+
# station selection and names cleaning:
144+
if (!is.null(station)) {
145+
if (is.character(station)) {
146+
inds = unique(as.numeric(unlist(sapply(station, function(x) grep(pattern = x, x = trimws(all_data[[length(all_data)]]$`Nazwa stacji`))))))
147+
if (any(is.na(inds)) || length(inds) == 0) {
148+
env$logs = c(
149+
env$logs,
150+
paste("At least one of selected station(s) is not available in the database. Returning all available stations")
151+
)
152+
} else {
153+
all_data[[length(all_data)]] = all_data[[length(all_data)]][inds, ]
154+
}
155+
}
156+
}
157+
142158
} # end of loop for years (if more than 1 specified)
143159

144160
all_data = do.call(rbind, all_data)
@@ -171,6 +187,7 @@ hydro_imgw_daily_bp = function(year,
171187
}
172188
}
173189

190+
all_data = as.data.frame(all_data)
174191
all_data = all_data[do.call(order, all_data[grep(x = colnames(all_data), "Nazwa stacji|Rok hydro|w roku hydro|Dzie")]), ]
175192
# fix dates and add as seperate column:
176193
yy_ind = grep(x = colnames(all_data), "Rok hydrologiczny")

R/match_imgw_wmoid_inds.R

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#' Match WMO station IDs for IMGW SYNOP
2+
#' @param station vector or station names provided to imgw_meteo_ family of functions
3+
#' @keywords internal
4+
#' @noRd
5+
match_imgw_wmoid_inds = function(station) {
6+
if (is.null(station)) {
7+
return(NULL)
8+
}
9+
pattern_combined = paste(station, collapse = "|")
10+
ids_idx = grep(
11+
pattern = pattern_combined,
12+
x = climate::imgw_meteo_stations$station,
13+
ignore.case = TRUE
14+
)
15+
ids = climate::imgw_meteo_stations[ids_idx, "id2"]
16+
return(ids[nchar(ids) == 3])
17+
}

0 commit comments

Comments
 (0)