From 20d1547bbc78e2de786d0d3f44754fa9a52a4db9 Mon Sep 17 00:00:00 2001 From: Krzysztof Dyba <35004826+kadyb@users.noreply.github.com> Date: Tue, 7 Dec 2021 12:19:18 +0100 Subject: [PATCH 01/21] calculate distances on spheroid --- R/nearest_stations_imgw.R | 77 ++++++++++++++++++++++----------------- R/spheroid_dist.R | 31 ++++++++++++++++ 2 files changed, 75 insertions(+), 33 deletions(-) create mode 100644 R/spheroid_dist.R diff --git a/R/nearest_stations_imgw.R b/R/nearest_stations_imgw.R index a813e11..d6cfc62 100644 --- a/R/nearest_stations_imgw.R +++ b/R/nearest_stations_imgw.R @@ -5,20 +5,20 @@ #' #' @param type data name;"meteo" (default), "hydro" #' @param rank rank of the stations: "synop" (default), "climate", or "precip"; Only valid if type = "meteo -#' @param year select year for serching nearest station +#' @param year select year for searching nearest station #' @param add_map logical - whether to draw a map for a returned data frame (requires maps/mapdata packages) #' @param point a vector of two coordinates (longitude, latitude) for a point we want to find nearest stations to (e.g. c(15, 53)); If not provided calculated as a mean longitude and latitude for the entire dataset #' @param no_of_stations how many nearest stations will be returned from the given geographical coordinates. 50 used by default #' @param ... extra arguments to be provided to the [graphics::plot()] function (only if add_map = TRUE) #' @importFrom XML readHTMLTable #' @export -#' @return A data.frame with a list of nearest stations. Each row represents metadata for station which collected measurements in a given year. Particular columns contain stations metadata (e.g. station ID, geographical coordinates, official name, distance from a given coordinates). +#' @return A data.frame with a list of nearest stations. Each row represents metadata for station which collected measurements in a given year. Particular columns contain stations metadata (e.g. station ID, geographical coordinates, official name, distance in kilometers from a given coordinates). #' #' @examples #' \donttest{ #' nearest_stations_imgw(type = "hydro", -#' rank="synop", -#' year=2018, +#' rank = "synop", +#' year = 2018, #' point = c(17, 52), #' add_map = TRUE, #' no_of_stations = 4) @@ -30,58 +30,67 @@ nearest_stations_imgw = function(type = "meteo", year = 2018, add_map = TRUE, point = NULL, - no_of_stations = 50, ...){ - if (length(point)>2) { + no_of_stations = 50, ...) { + if (length(point) > 2) { stop("Too many points for the distance calculations. Please provide just one pair of coordinates (e.g. point = c(17,53))") - } else if (length(point)<2 | length(point) == 0) { + } else if (length(point) < 2) { message(" The point argument should have two coordinates. We will provide nearest stations for mean location of all available stations. - To change it please change the `point` argument c(LON,LAT)" ) + To change it please change the `point` argument c(LON,LAT)") Sys.sleep(2) } - - if (max(year)>=as.integer(substr(Sys.Date(),1,4))-1) { + if (point[1] > 180) { + stop("x should be longitude") + } else if (point[2] > 90) { + stop("y should be latitude") + } + + 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://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/") } - if (type == "meteo"){ - result = unique(meteo_imgw_monthly(rank = rank, year = year, coords = T)[,c(2:5)]) - } else if (type=="hydro"){ - result = unique(hydro_imgw_annual(year = year, coords = T)[,c(1:4)]) + 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)]) } else { stop("You've provided wrong type argument; please use: \"meteo\", or \"hydro\"") } - if (dim(result)[1]==0) { + if (dim(result)[1] == 0) { stop("Propobly there is no data in the downloaded object. Please check available records: https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/") - } - if (is.null(point)){ + } + + if (is.null(point)) { # workaround for different column names: - if(any(colnames(result)=="LON")) point = c(round(mean(result$LON,na.rm=T),2),round(mean(result$LAT,na.rm=T),2)) - if(any(colnames(result)=="X")) point = c(round(mean(result$X,na.rm=T),2),round(mean(result$Y,na.rm=T),2)) + if (any(colnames(result) == "LON")) + point = c(round(mean(result$LON, na.rm = TRUE), 2), + round(mean(result$LAT, na.rm = TRUE), 2)) + if (any(colnames(result) == "X")) + point = c(round(mean(result$X, na.rm = TRUE), 2), + round(mean(result$Y, na.rm = TRUE), 2)) } + dist_vec = double(nrow(result)) + for (i in seq_along(dist_vec)) { + dist_vec[i] = spheroid_dist(point, c(result$X[i], result$Y[i])) + } - point = as.data.frame(t(point)) - names(point) = c("X", "Y") - distmatrix = rbind(point,result[, 2:3]) - distance_points = stats::dist(distmatrix, method = "euclidean")[1:dim(result)[1]] - result["distance [km]"] = round(distance_points * 112.196672, 3) + result["distance"] = round(dist_vec, 3) orderd_distance = result[order(result$distance), ] result = orderd_distance[1:no_of_stations, ] - message('Currently "climate" package use approximate distance calculation\nIn order to get accurate results please use GIS-based solutions') - + # removing rows with all NA records from the obtained dataset; # otherwise there might be problems with plotting infinite xlim, ylim, etc.. - result = result[!apply(is.na(result), 1, sum) == ncol(result),] + result = result[!apply(is.na(result), 1, sum) == ncol(result), ] - if(add_map == TRUE){ - if (!requireNamespace("maps", quietly = TRUE)){ + if (add_map == TRUE) { + if (!requireNamespace("maps", quietly = TRUE)) { stop("package maps required, please install it first") } # plot a little bit more: @@ -96,8 +105,10 @@ nearest_stations_imgw = function(type = "meteo", pch = 19, xlab = "longitude", ylab = "latitude", - xlim = (c(min(c(result$X, point$X), na.rm = T) - 1, max(c(result$X, point$X),na.rm = T) + 1)), - ylim = (c(min(c(result$Y, point$Y), na.rm = T) - 1, max(c(result$Y, point$Y),na.rm = T) + 1)), + xlim = (c(min(c(result$X, point$X), na.rm = TRUE) - 1, + max(c(result$X, point$X), na.rm = TRUE) + 1)), + ylim = (c(min(c(result$Y, point$Y), na.rm = TRUE) - 1, + max(c(result$Y, point$Y), na.rm = TRUE) + 1)), ... ) graphics::points( @@ -117,9 +128,9 @@ nearest_stations_imgw = function(type = "meteo", maps::map(add = TRUE) } - if (length(year)>1) { + + if (length(year) > 1) { message("Please provide only one year. For more years station's metadata may change (name, location or station may stop collecting data)") } return(result) } - diff --git a/R/spheroid_dist.R b/R/spheroid_dist.R new file mode 100644 index 0000000..2fa5382 --- /dev/null +++ b/R/spheroid_dist.R @@ -0,0 +1,31 @@ +#' Distance between two points on a spheroid +#' +#' Calculate the distance between two points on the surface of a spheroid +#' using Vincenty's formula +#' +#' @param p1 coordinates of the first point in decimal degrees (LON, LAT) +#' @param p2 coordinates of the second point in decimal degrees (LON, LAT) +#' +#' @return distance between two points in kilometers + +#' @examples +#' \donttest{ +#' p1 = c(18.633333, 54.366667) # Gdańsk +#' p2 = c(17.016667, 54.466667) # Słupsk +#' spheroid_dist(p1, p2) +#' } +spheroid_dist = function(p1, p2) { + + r = 6371009 # mean earth radius in meters + + vec = c(p1, p2) * pi / 180 # convert degrees to radians + diff_long = vec[3] - vec[1] + # diff_lat = vec[4] - vec[2] + + num = (cos(vec[4]) * sin(diff_long))^2 + (cos(vec[2]) * sin(vec[4]) - sin(vec[2]) * cos(vec[4]) * cos(diff_long))^2 + denom = sin(vec[2]) * sin(vec[4]) + cos(vec[2]) * cos(vec[4]) * cos(diff_long) + d = atan(sqrt(num) / denom) + d = d * r + return(d / 1000) # output in km + +} From 18d78bd7d0e25ec27bd110cdc46654232ccf61f5 Mon Sep 17 00:00:00 2001 From: Krzysztof Dyba <35004826+kadyb@users.noreply.github.com> Date: Tue, 7 Dec 2021 12:34:48 +0100 Subject: [PATCH 02/21] update NEWS --- NEWS.md | 211 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 108 insertions(+), 103 deletions(-) diff --git a/NEWS.md b/NEWS.md index 9442862..f283718 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,103 +1,108 @@ -# climate 1.0.3 - -* Adding possibility to download BUFR vertical sounding dataset from `http://weather.uwyo.edu/upperair/sounding.html`; extra information with supporting example added to the `sounding_wyoming`'s documentation -* `hydro_imgw` supports now exception for current year which has no flow data until it is verified by the IMGW-PIB -* `ogimet_daily` automatically detects column names to be used for extraction in final data.frame; extra debugging info when temperature or precipitation columns are missing -* minor changes in documentation (e.g. updated links to NOAA website) - -# climate 1.0.1 - -* Adding `data.table` package to read CP1250 on machines that do not support this encoding (translit used instead) - -# climate 0.9.9 - -* Changing URL `danepubliczne.imgw.pl` to `dane.imgw.pl` where needed -* Fixing minor ogimet and IMGW bugs -* Do not stop downloading data from `ogimet.com`, instead check for all available data in given period of time - -# climate 0.9.8 - -* Adding informative message if problems with NOAA hourly dataset occur -* Informative message if problems with downloading detected for non-IMGW dataset - -# climate 0.9.7 - -* stop working if no internet connection detected - -# climate 0.9.6 - -* Adding nearest_stations_noaa for NOAA hourly dataset - -# climate 0.9.5 - -* Following CRAN policies - * Adding information if connection issues detected or URL no accessible - * RCurl dependency removal - * CO2 & Wyoming examplary data can be loaded offline - -# climate 0.9.4 - -* New dataset: - * Hourly NOAA ISH (Integrated Surface Hourly) data - global meteorological dataset dated back up to 1900 - -# climate 0.9.3 - -* Bug fixes - * #27 -* New datasets: - * CO2 concentration from Mauna Loa observatory - -# climate 0.9.2 - -* Bug fixes - * #26 - -# climate 0.9.1 - -* climate is independent of imgw package -* Bug fixes - * #24 -* restored possibility of downloading single station from Polish (IMGW) repository - -# climate 0.3 - -* improves API - -# climate 0.2 - -* splits imgw into two packages: imgw and climate - -# imgw 0.1.1 - -* New datasets - * Synop data from ogimet (http://ogimet.com/index.phtml.en) -* New functions -* adding function for reading station's coordinates from "Ogimet" webportal - * `ogimet()` - downloading Synop hourly or monthly data from the "Ogimet" webportal - * `ogimet_hourly()` - downloading Synop hourly data from the "Ogimet" webportal - * `ogimet_daily()` - downloading Synop daily aggregates from the "Ogimet" webportal - * `ogimet_stations()` - retrieving geographical coordinates, altitude, WMO IDs and station names for the user-specified country nam; optionally plot results on a map -* Improvements -* Bug fixes - * Fixes a bug in the `hydro_daily()` that prevented from merging more than 1 dataset - -# imgw 0.1.0 - -* Deploying the package on CRAN! -* New functions - * New function `meteo()` for downloading monthly, daily, and hourly meteorological data - * New function `meteo_monthly()` for downloading monthly meteorological data - * New function `meteo_daily()` for downloading daily meteorological data - * New function `meteo_hourly()` for downloading hourly meteorological data - * New function `hydro()` for downloading semiannual and annual, monthly, and daily hydrological data - * New function `hydro_annual()` for downloading semiannual and annual hydrological data - * New function `hydro_monthly()` for downloading monthly hydrological data - * New function `hydro_daily()` for downloading daily hydrological data - * New function `meteo_metadata()` for downloading the metadata of the meteorological data - * New function `hydro_metadata()` for downloading the metadata of the hydrological data - * New function `meteo_sounding()` for downloading the mea (i.e. measurements of the vertical profile of atmosphere) sounding data -* New datasets - * New dataset `meteo_stations` containing Polish meteorological station's localizations - * New dataset `hydro_stations` containing Polish hydrological station's localizations -* Improvements - * Added a `NEWS.md` file to track changes to the package. +# climate 1.0.4 + +* Function `nearest_stations_imgw()` now uses the Vincenty's formula to calculate the distance between points on a spheroid, not the Euclidean distance +(the results were inaccurate) + +# climate 1.0.3 + +* Adding possibility to download BUFR vertical sounding dataset from `http://weather.uwyo.edu/upperair/sounding.html`; extra information with supporting example added to the `sounding_wyoming`'s documentation +* `hydro_imgw` supports now exception for current year which has no flow data until it is verified by the IMGW-PIB +* `ogimet_daily` automatically detects column names to be used for extraction in final data.frame; extra debugging info when temperature or precipitation columns are missing +* minor changes in documentation (e.g. updated links to NOAA website) + +# climate 1.0.1 + +* Adding `data.table` package to read CP1250 on machines that do not support this encoding (translit used instead) + +# climate 0.9.9 + +* Changing URL `danepubliczne.imgw.pl` to `dane.imgw.pl` where needed +* Fixing minor ogimet and IMGW bugs +* Do not stop downloading data from `ogimet.com`, instead check for all available data in given period of time + +# climate 0.9.8 + +* Adding informative message if problems with NOAA hourly dataset occur +* Informative message if problems with downloading detected for non-IMGW dataset + +# climate 0.9.7 + +* stop working if no internet connection detected + +# climate 0.9.6 + +* Adding nearest_stations_noaa for NOAA hourly dataset + +# climate 0.9.5 + +* Following CRAN policies + * Adding information if connection issues detected or URL no accessible + * RCurl dependency removal + * CO2 & Wyoming examplary data can be loaded offline + +# climate 0.9.4 + +* New dataset: + * Hourly NOAA ISH (Integrated Surface Hourly) data - global meteorological dataset dated back up to 1900 + +# climate 0.9.3 + +* Bug fixes + * #27 +* New datasets: + * CO2 concentration from Mauna Loa observatory + +# climate 0.9.2 + +* Bug fixes + * #26 + +# climate 0.9.1 + +* climate is independent of imgw package +* Bug fixes + * #24 +* restored possibility of downloading single station from Polish (IMGW) repository + +# climate 0.3 + +* improves API + +# climate 0.2 + +* splits imgw into two packages: imgw and climate + +# imgw 0.1.1 + +* New datasets + * Synop data from ogimet (http://ogimet.com/index.phtml.en) +* New functions +* adding function for reading station's coordinates from "Ogimet" webportal + * `ogimet()` - downloading Synop hourly or monthly data from the "Ogimet" webportal + * `ogimet_hourly()` - downloading Synop hourly data from the "Ogimet" webportal + * `ogimet_daily()` - downloading Synop daily aggregates from the "Ogimet" webportal + * `ogimet_stations()` - retrieving geographical coordinates, altitude, WMO IDs and station names for the user-specified country nam; optionally plot results on a map +* Improvements +* Bug fixes + * Fixes a bug in the `hydro_daily()` that prevented from merging more than 1 dataset + +# imgw 0.1.0 + +* Deploying the package on CRAN! +* New functions + * New function `meteo()` for downloading monthly, daily, and hourly meteorological data + * New function `meteo_monthly()` for downloading monthly meteorological data + * New function `meteo_daily()` for downloading daily meteorological data + * New function `meteo_hourly()` for downloading hourly meteorological data + * New function `hydro()` for downloading semiannual and annual, monthly, and daily hydrological data + * New function `hydro_annual()` for downloading semiannual and annual hydrological data + * New function `hydro_monthly()` for downloading monthly hydrological data + * New function `hydro_daily()` for downloading daily hydrological data + * New function `meteo_metadata()` for downloading the metadata of the meteorological data + * New function `hydro_metadata()` for downloading the metadata of the hydrological data + * New function `meteo_sounding()` for downloading the mea (i.e. measurements of the vertical profile of atmosphere) sounding data +* New datasets + * New dataset `meteo_stations` containing Polish meteorological station's localizations + * New dataset `hydro_stations` containing Polish hydrological station's localizations +* Improvements + * Added a `NEWS.md` file to track changes to the package. From a2ec0712ec21bfb5bc3e034718d3314c3824b0a4 Mon Sep 17 00:00:00 2001 From: Krzysztof Dyba <35004826+kadyb@users.noreply.github.com> Date: Tue, 7 Dec 2021 12:38:10 +0100 Subject: [PATCH 03/21] update docs --- man/nearest_stations_imgw.Rd | 8 ++++---- man/spheroid_dist.Rd | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 man/spheroid_dist.Rd diff --git a/man/nearest_stations_imgw.Rd b/man/nearest_stations_imgw.Rd index 0024c0d..66894d9 100644 --- a/man/nearest_stations_imgw.Rd +++ b/man/nearest_stations_imgw.Rd @@ -19,7 +19,7 @@ nearest_stations_imgw( \item{rank}{rank of the stations: "synop" (default), "climate", or "precip"; Only valid if type = "meteo} -\item{year}{select year for serching nearest station} +\item{year}{select year for searching nearest station} \item{add_map}{logical - whether to draw a map for a returned data frame (requires maps/mapdata packages)} @@ -30,7 +30,7 @@ nearest_stations_imgw( \item{...}{extra arguments to be provided to the \code{\link[graphics:plot.default]{graphics::plot()}} function (only if add_map = TRUE)} } \value{ -A data.frame with a list of nearest stations. Each row represents metadata for station which collected measurements in a given year. Particular columns contain stations metadata (e.g. station ID, geographical coordinates, official name, distance from a given coordinates). +A data.frame with a list of nearest stations. Each row represents metadata for station which collected measurements in a given year. Particular columns contain stations metadata (e.g. station ID, geographical coordinates, official name, distance in kilometers from a given coordinates). } \description{ Returns a data frame of meteorological or hydrological stations with their coordinates in particular year. @@ -39,8 +39,8 @@ The returned object is valid only for a given year and type of stations (e.g. "s \examples{ \donttest{ nearest_stations_imgw(type = "hydro", - rank="synop", - year=2018, + rank = "synop", + year = 2018, point = c(17, 52), add_map = TRUE, no_of_stations = 4) diff --git a/man/spheroid_dist.Rd b/man/spheroid_dist.Rd new file mode 100644 index 0000000..70a02bf --- /dev/null +++ b/man/spheroid_dist.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/spheroid_dist.R +\name{spheroid_dist} +\alias{spheroid_dist} +\title{Distance between two points on a spheroid} +\usage{ +spheroid_dist(p1, p2) +} +\arguments{ +\item{p1}{coordinates of the first point in decimal degrees (LON, LAT)} + +\item{p2}{coordinates of the second point in decimal degrees (LON, LAT)} +} +\value{ +distance between two points in kilometers +} +\description{ +Calculate the distance between two points on the surface of a spheroid +using Vincenty's formula +} +\examples{ +\donttest{ + p1 = c(18.633333, 54.366667) # Gdańsk + p2 = c(17.016667, 54.466667) # Słupsk + spheroid_dist(p1, p2) +} +} From 176e30dbd8716f032969a7ff98045ae55fb6c721 Mon Sep 17 00:00:00 2001 From: Krzysztof Dyba <35004826+kadyb@users.noreply.github.com> Date: Tue, 7 Dec 2021 14:56:08 +0100 Subject: [PATCH 04/21] fix var in `nearest_stations_imgw()` --- R/nearest_stations_imgw.R | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/R/nearest_stations_imgw.R b/R/nearest_stations_imgw.R index d6cfc62..a0c72f8 100644 --- a/R/nearest_stations_imgw.R +++ b/R/nearest_stations_imgw.R @@ -25,17 +25,17 @@ #' } #' -nearest_stations_imgw = function(type = "meteo", - rank = "synop", - year = 2018, - add_map = TRUE, - point = NULL, - no_of_stations = 50, ...) { +nearest_stations_imgw = function(type = "meteo", + rank = "synop", + year = 2018, + add_map = TRUE, + point = NULL, + no_of_stations = 50, + ...) { if (length(point) > 2) { stop("Too many points for the distance calculations. Please provide just one pair of coordinates (e.g. point = c(17,53))") } else if (length(point) < 2) { - message(" - The point argument should have two coordinates. + message("The point argument should have two coordinates. We will provide nearest stations for mean location of all available stations. To change it please change the `point` argument c(LON,LAT)") Sys.sleep(2) @@ -60,7 +60,7 @@ nearest_stations_imgw = function(type = "meteo", stop("You've provided wrong type argument; please use: \"meteo\", or \"hydro\"") } - if (dim(result)[1] == 0) { + if (nrow(result) == 0) { stop("Propobly there is no data in the downloaded object. Please check available records: https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/") } @@ -105,10 +105,10 @@ nearest_stations_imgw = function(type = "meteo", pch = 19, xlab = "longitude", ylab = "latitude", - xlim = (c(min(c(result$X, point$X), na.rm = TRUE) - 1, - max(c(result$X, point$X), na.rm = TRUE) + 1)), - ylim = (c(min(c(result$Y, point$Y), na.rm = TRUE) - 1, - max(c(result$Y, point$Y), na.rm = TRUE) + 1)), + xlim = c(min(c(result$X, point[1]), na.rm = TRUE) - 1, + max(c(result$X, point[1]), na.rm = TRUE) + 1), + ylim = c(min(c(result$Y, point[2]), na.rm = TRUE) - 1, + max(c(result$Y, point[2]), na.rm = TRUE) + 1), ... ) graphics::points( From 003e0f835e571a6e992386f614ec710521fe47d5 Mon Sep 17 00:00:00 2001 From: Krzysztof Dyba <35004826+kadyb@users.noreply.github.com> Date: Sun, 12 Dec 2021 23:19:10 +0100 Subject: [PATCH 05/21] Revert "update NEWS" --- NEWS.md | 211 +++++++++++++++++++++++++++----------------------------- 1 file changed, 103 insertions(+), 108 deletions(-) diff --git a/NEWS.md b/NEWS.md index f283718..9442862 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,108 +1,103 @@ -# climate 1.0.4 - -* Function `nearest_stations_imgw()` now uses the Vincenty's formula to calculate the distance between points on a spheroid, not the Euclidean distance -(the results were inaccurate) - -# climate 1.0.3 - -* Adding possibility to download BUFR vertical sounding dataset from `http://weather.uwyo.edu/upperair/sounding.html`; extra information with supporting example added to the `sounding_wyoming`'s documentation -* `hydro_imgw` supports now exception for current year which has no flow data until it is verified by the IMGW-PIB -* `ogimet_daily` automatically detects column names to be used for extraction in final data.frame; extra debugging info when temperature or precipitation columns are missing -* minor changes in documentation (e.g. updated links to NOAA website) - -# climate 1.0.1 - -* Adding `data.table` package to read CP1250 on machines that do not support this encoding (translit used instead) - -# climate 0.9.9 - -* Changing URL `danepubliczne.imgw.pl` to `dane.imgw.pl` where needed -* Fixing minor ogimet and IMGW bugs -* Do not stop downloading data from `ogimet.com`, instead check for all available data in given period of time - -# climate 0.9.8 - -* Adding informative message if problems with NOAA hourly dataset occur -* Informative message if problems with downloading detected for non-IMGW dataset - -# climate 0.9.7 - -* stop working if no internet connection detected - -# climate 0.9.6 - -* Adding nearest_stations_noaa for NOAA hourly dataset - -# climate 0.9.5 - -* Following CRAN policies - * Adding information if connection issues detected or URL no accessible - * RCurl dependency removal - * CO2 & Wyoming examplary data can be loaded offline - -# climate 0.9.4 - -* New dataset: - * Hourly NOAA ISH (Integrated Surface Hourly) data - global meteorological dataset dated back up to 1900 - -# climate 0.9.3 - -* Bug fixes - * #27 -* New datasets: - * CO2 concentration from Mauna Loa observatory - -# climate 0.9.2 - -* Bug fixes - * #26 - -# climate 0.9.1 - -* climate is independent of imgw package -* Bug fixes - * #24 -* restored possibility of downloading single station from Polish (IMGW) repository - -# climate 0.3 - -* improves API - -# climate 0.2 - -* splits imgw into two packages: imgw and climate - -# imgw 0.1.1 - -* New datasets - * Synop data from ogimet (http://ogimet.com/index.phtml.en) -* New functions -* adding function for reading station's coordinates from "Ogimet" webportal - * `ogimet()` - downloading Synop hourly or monthly data from the "Ogimet" webportal - * `ogimet_hourly()` - downloading Synop hourly data from the "Ogimet" webportal - * `ogimet_daily()` - downloading Synop daily aggregates from the "Ogimet" webportal - * `ogimet_stations()` - retrieving geographical coordinates, altitude, WMO IDs and station names for the user-specified country nam; optionally plot results on a map -* Improvements -* Bug fixes - * Fixes a bug in the `hydro_daily()` that prevented from merging more than 1 dataset - -# imgw 0.1.0 - -* Deploying the package on CRAN! -* New functions - * New function `meteo()` for downloading monthly, daily, and hourly meteorological data - * New function `meteo_monthly()` for downloading monthly meteorological data - * New function `meteo_daily()` for downloading daily meteorological data - * New function `meteo_hourly()` for downloading hourly meteorological data - * New function `hydro()` for downloading semiannual and annual, monthly, and daily hydrological data - * New function `hydro_annual()` for downloading semiannual and annual hydrological data - * New function `hydro_monthly()` for downloading monthly hydrological data - * New function `hydro_daily()` for downloading daily hydrological data - * New function `meteo_metadata()` for downloading the metadata of the meteorological data - * New function `hydro_metadata()` for downloading the metadata of the hydrological data - * New function `meteo_sounding()` for downloading the mea (i.e. measurements of the vertical profile of atmosphere) sounding data -* New datasets - * New dataset `meteo_stations` containing Polish meteorological station's localizations - * New dataset `hydro_stations` containing Polish hydrological station's localizations -* Improvements - * Added a `NEWS.md` file to track changes to the package. +# climate 1.0.3 + +* Adding possibility to download BUFR vertical sounding dataset from `http://weather.uwyo.edu/upperair/sounding.html`; extra information with supporting example added to the `sounding_wyoming`'s documentation +* `hydro_imgw` supports now exception for current year which has no flow data until it is verified by the IMGW-PIB +* `ogimet_daily` automatically detects column names to be used for extraction in final data.frame; extra debugging info when temperature or precipitation columns are missing +* minor changes in documentation (e.g. updated links to NOAA website) + +# climate 1.0.1 + +* Adding `data.table` package to read CP1250 on machines that do not support this encoding (translit used instead) + +# climate 0.9.9 + +* Changing URL `danepubliczne.imgw.pl` to `dane.imgw.pl` where needed +* Fixing minor ogimet and IMGW bugs +* Do not stop downloading data from `ogimet.com`, instead check for all available data in given period of time + +# climate 0.9.8 + +* Adding informative message if problems with NOAA hourly dataset occur +* Informative message if problems with downloading detected for non-IMGW dataset + +# climate 0.9.7 + +* stop working if no internet connection detected + +# climate 0.9.6 + +* Adding nearest_stations_noaa for NOAA hourly dataset + +# climate 0.9.5 + +* Following CRAN policies + * Adding information if connection issues detected or URL no accessible + * RCurl dependency removal + * CO2 & Wyoming examplary data can be loaded offline + +# climate 0.9.4 + +* New dataset: + * Hourly NOAA ISH (Integrated Surface Hourly) data - global meteorological dataset dated back up to 1900 + +# climate 0.9.3 + +* Bug fixes + * #27 +* New datasets: + * CO2 concentration from Mauna Loa observatory + +# climate 0.9.2 + +* Bug fixes + * #26 + +# climate 0.9.1 + +* climate is independent of imgw package +* Bug fixes + * #24 +* restored possibility of downloading single station from Polish (IMGW) repository + +# climate 0.3 + +* improves API + +# climate 0.2 + +* splits imgw into two packages: imgw and climate + +# imgw 0.1.1 + +* New datasets + * Synop data from ogimet (http://ogimet.com/index.phtml.en) +* New functions +* adding function for reading station's coordinates from "Ogimet" webportal + * `ogimet()` - downloading Synop hourly or monthly data from the "Ogimet" webportal + * `ogimet_hourly()` - downloading Synop hourly data from the "Ogimet" webportal + * `ogimet_daily()` - downloading Synop daily aggregates from the "Ogimet" webportal + * `ogimet_stations()` - retrieving geographical coordinates, altitude, WMO IDs and station names for the user-specified country nam; optionally plot results on a map +* Improvements +* Bug fixes + * Fixes a bug in the `hydro_daily()` that prevented from merging more than 1 dataset + +# imgw 0.1.0 + +* Deploying the package on CRAN! +* New functions + * New function `meteo()` for downloading monthly, daily, and hourly meteorological data + * New function `meteo_monthly()` for downloading monthly meteorological data + * New function `meteo_daily()` for downloading daily meteorological data + * New function `meteo_hourly()` for downloading hourly meteorological data + * New function `hydro()` for downloading semiannual and annual, monthly, and daily hydrological data + * New function `hydro_annual()` for downloading semiannual and annual hydrological data + * New function `hydro_monthly()` for downloading monthly hydrological data + * New function `hydro_daily()` for downloading daily hydrological data + * New function `meteo_metadata()` for downloading the metadata of the meteorological data + * New function `hydro_metadata()` for downloading the metadata of the hydrological data + * New function `meteo_sounding()` for downloading the mea (i.e. measurements of the vertical profile of atmosphere) sounding data +* New datasets + * New dataset `meteo_stations` containing Polish meteorological station's localizations + * New dataset `hydro_stations` containing Polish hydrological station's localizations +* Improvements + * Added a `NEWS.md` file to track changes to the package. From 561b84d9886e9702a59b5e6a457b3623bd083d1e Mon Sep 17 00:00:00 2001 From: Krzysztof Dyba <35004826+kadyb@users.noreply.github.com> Date: Sun, 12 Dec 2021 23:19:55 +0100 Subject: [PATCH 06/21] update NEWS --- NEWS.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/NEWS.md b/NEWS.md index 9442862..ab4fe27 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +# climate 1.0.4 + +* Function `nearest_stations_imgw()` now uses the Vincenty's formula to calculate the distance between points on a spheroid, not the Euclidean distance +(the results were inaccurate) + # climate 1.0.3 * Adding possibility to download BUFR vertical sounding dataset from `http://weather.uwyo.edu/upperair/sounding.html`; extra information with supporting example added to the `sounding_wyoming`'s documentation From a61c2e703c3706e89d273d5f55271cb543ca63a7 Mon Sep 17 00:00:00 2001 From: Krzysztof Dyba <35004826+kadyb@users.noreply.github.com> Date: Sun, 12 Dec 2021 23:36:06 +0100 Subject: [PATCH 07/21] review fixes --- R/nearest_stations_imgw.R | 47 ++++++++++++++++++++---------------- man/nearest_stations_imgw.Rd | 4 +-- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/R/nearest_stations_imgw.R b/R/nearest_stations_imgw.R index a0c72f8..6c3e084 100644 --- a/R/nearest_stations_imgw.R +++ b/R/nearest_stations_imgw.R @@ -3,14 +3,13 @@ #' Returns a data frame of meteorological or hydrological stations with their coordinates in particular year. #' The returned object is valid only for a given year and type of stations (e.g. "synop", "climate" or "precip"). If `add_map = TRUE` additional map of downloaded data is added. #' -#' @param type data name;"meteo" (default), "hydro" -#' @param rank rank of the stations: "synop" (default), "climate", or "precip"; Only valid if type = "meteo +#' @param type data name; "meteo" (default), "hydro" +#' @param rank rank of the stations: "synop" (default), "climate", or "precip"; Only valid if type = "meteo" #' @param year select year for searching nearest station #' @param add_map logical - whether to draw a map for a returned data frame (requires maps/mapdata packages) #' @param point a vector of two coordinates (longitude, latitude) for a point we want to find nearest stations to (e.g. c(15, 53)); If not provided calculated as a mean longitude and latitude for the entire dataset #' @param no_of_stations how many nearest stations will be returned from the given geographical coordinates. 50 used by default #' @param ... extra arguments to be provided to the [graphics::plot()] function (only if add_map = TRUE) -#' @importFrom XML readHTMLTable #' @export #' @return A data.frame with a list of nearest stations. Each row represents metadata for station which collected measurements in a given year. Particular columns contain stations metadata (e.g. station ID, geographical coordinates, official name, distance in kilometers from a given coordinates). #' @@ -33,23 +32,27 @@ nearest_stations_imgw = function(type = "meteo", no_of_stations = 50, ...) { if (length(point) > 2) { - stop("Too many points for the distance calculations. Please provide just one pair of coordinates (e.g. point = c(17,53))") + stop(paste("Too many points for the distance calculations.", + "Please provide just one pair of coordinates (e.g. point = c(17,53))")) } else if (length(point) < 2) { - message("The point argument should have two coordinates. - We will provide nearest stations for mean location of all available stations. - To change it please change the `point` argument c(LON,LAT)") - Sys.sleep(2) + msg = paste("The point argument should have two coordinates.", + "We will provide nearest stations for mean location of all available stations.", + "To change it please change the `point` argument c(LON,LAT)", + sep = "\n") + message(msg) + Sys.sleep(2) # display message for 2 sec } - if (point[1] > 180) { + if (!is.null(point) && point[1] > 180) { stop("x should be longitude") - } else if (point[2] > 90) { + } else if (!is.null(point) && point[2] > 90) { stop("y should be latitude") } 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://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/") + Sys.sleep(2) } if (type == "meteo") { @@ -60,17 +63,17 @@ nearest_stations_imgw = function(type = "meteo", stop("You've provided wrong type argument; please use: \"meteo\", or \"hydro\"") } - if (nrow(result) == 0) { + if (dim(result)[1] == 0) { stop("Propobly there is no data in the downloaded object. Please check available records: https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/") } if (is.null(point)) { # workaround for different column names: - if (any(colnames(result) == "LON")) + if ("LON" %in% colnames(result)) point = c(round(mean(result$LON, na.rm = TRUE), 2), round(mean(result$LAT, na.rm = TRUE), 2)) - if (any(colnames(result) == "X")) + if ("X" %in% colnames(result)) point = c(round(mean(result$X, na.rm = TRUE), 2), round(mean(result$Y, na.rm = TRUE), 2)) } @@ -81,8 +84,8 @@ nearest_stations_imgw = function(type = "meteo", } result["distance"] = round(dist_vec, 3) - orderd_distance = result[order(result$distance), ] - result = orderd_distance[1:no_of_stations, ] + result = result[order(result$distance), ] + result = result[1:no_of_stations, ] # removing rows with all NA records from the obtained dataset; @@ -94,7 +97,8 @@ nearest_stations_imgw = function(type = "meteo", stop("package maps required, please install it first") } # plot a little bit more: - addfactor = as.numeric(diff(stats::quantile(result$Y, na.rm = TRUE, c(0.48, 0.51)))) #lat Y + addfactor = stats::quantile(result$Y, c(0.48, 0.51), na.rm = TRUE) #lat Y + addfactor = as.numeric(diff(addfactor)) addfactor = ifelse(addfactor > 0.2, 0.2, addfactor) addfactor = ifelse(addfactor < 0.05, 0.05, addfactor) @@ -105,10 +109,10 @@ nearest_stations_imgw = function(type = "meteo", pch = 19, xlab = "longitude", ylab = "latitude", - xlim = c(min(c(result$X, point[1]), na.rm = TRUE) - 1, - max(c(result$X, point[1]), na.rm = TRUE) + 1), - ylim = c(min(c(result$Y, point[2]), na.rm = TRUE) - 1, - max(c(result$Y, point[2]), na.rm = TRUE) + 1), + xlim = c(min(c(result[["X"]], point[1]), na.rm = TRUE) - 1, + max(c(result[["X"]], point[1]), na.rm = TRUE) + 1), + ylim = c(min(c(result[["Y"]], point[2]), na.rm = TRUE) - 1, + max(c(result[["Y"]], point[2]), na.rm = TRUE) + 1), ... ) graphics::points( @@ -130,7 +134,8 @@ nearest_stations_imgw = function(type = "meteo", } if (length(year) > 1) { - message("Please provide only one year. For more years station's metadata may change (name, location or station may stop collecting data)") + message(paste0("Please provide only one year. For more years station's metadata", + "may change (name, location or station may stop collecting data)")) } return(result) } diff --git a/man/nearest_stations_imgw.Rd b/man/nearest_stations_imgw.Rd index 66894d9..135cfac 100644 --- a/man/nearest_stations_imgw.Rd +++ b/man/nearest_stations_imgw.Rd @@ -15,9 +15,9 @@ nearest_stations_imgw( ) } \arguments{ -\item{type}{data name;"meteo" (default), "hydro"} +\item{type}{data name; "meteo" (default), "hydro"} -\item{rank}{rank of the stations: "synop" (default), "climate", or "precip"; Only valid if type = "meteo} +\item{rank}{rank of the stations: "synop" (default), "climate", or "precip"; Only valid if type = "meteo"} \item{year}{select year for searching nearest station} From 207620598b9d1d22555a46ce5933e89a35a6fa5e Mon Sep 17 00:00:00 2001 From: bczernecki Date: Tue, 14 Dec 2021 11:13:45 +0100 Subject: [PATCH 08/21] add test-spheroid and lintr --- DESCRIPTION | 2 +- NAMESPACE | 1 + R/check_locale.R | 4 +--- R/meteo_imgw_daily.R | 24 ++++++++++++------------ R/spheroid_dist.R | 15 +++++++-------- man/spheroid_dist.Rd | 12 ++++++------ tests/testthat/test-spheroid_dist.R | 12 ++++++++++++ 7 files changed, 40 insertions(+), 30 deletions(-) create mode 100644 tests/testthat/test-spheroid_dist.R diff --git a/DESCRIPTION b/DESCRIPTION index 223c6d3..2146a23 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: climate Title: Interface to Download Meteorological (and Hydrological) Datasets -Version: 1.0.3 +Version: 1.0.4 Authors@R: c(person(given = "Bartosz", family = "Czernecki", role = c("aut", "cre"), diff --git a/NAMESPACE b/NAMESPACE index ee0e7d7..f0add8e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -18,6 +18,7 @@ export(nearest_stations_ogimet) export(ogimet_daily) export(ogimet_hourly) export(sounding_wyoming) +export(spheroid_dist) export(stations_ogimet) export(test_url) import(httr) diff --git a/R/check_locale.R b/R/check_locale.R index 2bcb2bc..b32e745 100644 --- a/R/check_locale.R +++ b/R/check_locale.R @@ -6,16 +6,14 @@ check_locale = function(){ - if(Sys.getlocale("LC_CTYPE") %in% c("C.UTF-8", "en_US.iso885915")){ + if (Sys.getlocale("LC_CTYPE") %in% c("C.UTF-8", "en_US.iso885915")) { locale = Sys.getlocale("LC_CTYPE") message(paste0(" Your system locale is: " , locale," 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') ")) Sys.sleep(4) return(1) - } else { - return(0) } diff --git a/R/meteo_imgw_daily.R b/R/meteo_imgw_daily.R index 964f26d..98a6744 100644 --- a/R/meteo_imgw_daily.R +++ b/R/meteo_imgw_daily.R @@ -91,7 +91,7 @@ meteo_imgw_daily = function(rank = "synop", year, status = FALSE, coords = FALSE colnames(data1) = meta[[1]]$parameters file2 = paste(temp2, dir(temp2), sep = "/")[2] - if(translit){ + if (translit) { data2 = as.data.frame(data.table::fread(cmd = paste("iconv -f CP1250 -t ASCII//TRANSLIT", file2))) } else { data2 = read.csv(file2, header = FALSE, stringsAsFactors = FALSE, fileEncoding = "CP1250") @@ -99,7 +99,7 @@ meteo_imgw_daily = function(rank = "synop", year, status = FALSE, coords = FALSE colnames(data2) = meta[[2]]$parameters # usuwa statusy - if(status == FALSE){ + if (status == FALSE) { data1[grep("^Status", colnames(data1))] = NULL data2[grep("^Status", colnames(data2))] = NULL } @@ -123,7 +123,7 @@ meteo_imgw_daily = function(rank = "synop", year, status = FALSE, coords = FALSE ###################### ###### KLIMAT: ####### - if(rank == "climate") { + if (rank == "climate") { address = paste0(base_url, "dane_meteorologiczne/dobowe/klimat", "/", catalog, "/") #folder_contents = getURL(address, ftp.use.epsv = FALSE, dirlistonly = FALSE) # zawartosc folderu dla wybranego yearu @@ -138,13 +138,13 @@ meteo_imgw_daily = function(rank = "synop", year, status = FALSE, coords = FALSE # w tym miejscu trzeba przemyslec fragment kodu do dodania dla pojedynczej stacji jesli tak sobie zazyczy uzytkownik: # na podstawie zawartosci obiektu files - for(j in seq_along(addresses_to_download)){ + for (j in seq_along(addresses_to_download)) { temp = tempfile() temp2 = tempfile() test_url(addresses_to_download[j], temp) unzip(zipfile = temp, exdir = temp2) file1 = paste(temp2, dir(temp2), sep = "/")[1] - if(translit){ + if (translit) { data1 = as.data.frame(data.table::fread(cmd = paste("iconv -f CP1250 -t ASCII//TRANSLIT", file1))) } else { data1 = read.csv(file1, header = FALSE, stringsAsFactors = FALSE, fileEncoding = "CP1250") @@ -152,7 +152,7 @@ meteo_imgw_daily = function(rank = "synop", year, status = FALSE, coords = FALSE colnames(data1) = meta[[1]]$parameters file2 = paste(temp2, dir(temp2), sep = "/")[2] - if(translit){ + if (translit) { data2 = as.data.frame(data.table::fread(cmd = paste("iconv -f CP1250 -t ASCII//TRANSLIT", file2))) } else { data2 = read.csv(file2, header = FALSE, stringsAsFactors = FALSE, fileEncoding = "CP1250") @@ -160,7 +160,7 @@ meteo_imgw_daily = function(rank = "synop", year, status = FALSE, coords = FALSE colnames(data2) = meta[[2]]$parameters # usuwa statusy - if(status == FALSE){ + if (status == FALSE) { data1[grep("^Status", colnames(data1))] = NULL data2[grep("^Status", colnames(data2))] = NULL } @@ -176,7 +176,7 @@ meteo_imgw_daily = function(rank = "synop", year, status = FALSE, coords = FALSE ###################### ######## OPAD: ####### - if(rank == "precip") { + if (rank == "precip") { address = paste0(base_url, "dane_meteorologiczne/dobowe/opad", "/", catalog, "/") #folder_contents = getURL(address, ftp.use.epsv = FALSE, dirlistonly = FALSE) # zawartosc folderu dla wybranego yearu @@ -189,13 +189,13 @@ meteo_imgw_daily = function(rank = "synop", year, status = FALSE, coords = FALSE files = as.character(readHTMLTable(folder_contents)[[1]]$Name[ind]) addresses_to_download = paste0(address, files) - for(j in seq_along(addresses_to_download)){ + for (j in seq_along(addresses_to_download)) { temp = tempfile() temp2 = tempfile() test_url(addresses_to_download[j], temp) unzip(zipfile = temp, exdir = temp2) file1 = paste(temp2, dir(temp2), sep = "/")[1] - if(translit){ + if (translit) { data1 = as.data.frame(data.table::fread(cmd = paste("iconv -f CP1250 -t ASCII//TRANSLIT", file1))) } else { data1 = read.csv(file1, header = FALSE, stringsAsFactors = FALSE, fileEncoding = "CP1250") @@ -203,7 +203,7 @@ meteo_imgw_daily = function(rank = "synop", year, status = FALSE, coords = FALSE colnames(data1) = meta[[1]]$parameters # usuwa statusy - if(status == FALSE){ + if (status == FALSE) { data1[grep("^Status", colnames(data1))] = NULL } @@ -250,7 +250,7 @@ meteo_imgw_daily = function(rank = "synop", year, status = FALSE, coords = FALSE } # sortowanie w zaleznosci od nazw kolumn - raz jest "kod stacji", raz "id" - if(sum(grepl(x = colnames(all_data), pattern = "Kod stacji"))){ + if (sum(grepl(x = colnames(all_data), pattern = "Kod stacji"))) { all_data = all_data[order(all_data$`Kod stacji`, all_data$Rok, all_data$Miesiac, all_data$Dzien), ] } else { all_data = all_data[order(all_data$id, all_data$Rok, all_data$Miesiac, all_data$Dzien), ] diff --git a/R/spheroid_dist.R b/R/spheroid_dist.R index 2fa5382..4adf33c 100644 --- a/R/spheroid_dist.R +++ b/R/spheroid_dist.R @@ -1,26 +1,25 @@ #' Distance between two points on a spheroid #' #' Calculate the distance between two points on the surface of a spheroid -#' using Vincenty's formula +#' using Vincenty's formula. This function can be used when GIS libraries +#' for calculating distance are not available. #' #' @param p1 coordinates of the first point in decimal degrees (LON, LAT) #' @param p2 coordinates of the second point in decimal degrees (LON, LAT) #' -#' @return distance between two points in kilometers +#' @return distance between two locations in kilometers +#' @export #' @examples -#' \donttest{ -#' p1 = c(18.633333, 54.366667) # Gdańsk -#' p2 = c(17.016667, 54.466667) # Słupsk +#' p1 = c(18.633333, 54.366667) # longitude and latitude for Gdansk +#' p2 = c(17.016667, 54.466667) # longitude and latitude for Slupsk #' spheroid_dist(p1, p2) -#' } +#' spheroid_dist = function(p1, p2) { r = 6371009 # mean earth radius in meters - vec = c(p1, p2) * pi / 180 # convert degrees to radians diff_long = vec[3] - vec[1] - # diff_lat = vec[4] - vec[2] num = (cos(vec[4]) * sin(diff_long))^2 + (cos(vec[2]) * sin(vec[4]) - sin(vec[2]) * cos(vec[4]) * cos(diff_long))^2 denom = sin(vec[2]) * sin(vec[4]) + cos(vec[2]) * cos(vec[4]) * cos(diff_long) diff --git a/man/spheroid_dist.Rd b/man/spheroid_dist.Rd index 70a02bf..5628e2f 100644 --- a/man/spheroid_dist.Rd +++ b/man/spheroid_dist.Rd @@ -12,16 +12,16 @@ spheroid_dist(p1, p2) \item{p2}{coordinates of the second point in decimal degrees (LON, LAT)} } \value{ -distance between two points in kilometers +distance between two locations in kilometers } \description{ Calculate the distance between two points on the surface of a spheroid -using Vincenty's formula +using Vincenty's formula. This function can be used when GIS libraries +for calculating distance are not available. } \examples{ -\donttest{ - p1 = c(18.633333, 54.366667) # Gdańsk - p2 = c(17.016667, 54.466667) # Słupsk + p1 = c(18.633333, 54.366667) # longitude and latitude for Gdansk + p2 = c(17.016667, 54.466667) # longitude and latitude for Slupsk spheroid_dist(p1, p2) -} + } diff --git a/tests/testthat/test-spheroid_dist.R b/tests/testthat/test-spheroid_dist.R new file mode 100644 index 0000000..895f9ef --- /dev/null +++ b/tests/testthat/test-spheroid_dist.R @@ -0,0 +1,12 @@ +context("spheroid_dist") + +test_that("spheroid_dist works!", { + + p1 = c(18.633333, 54.366667) # longitude and latitude for Gdansk + p2 = c(17.016667, 54.466667) # longitude and latitude for Slupsk + res = spheroid_dist(p1, p2) + + testthat::expect_true(res > 105 & res < 106) + +}) + From 50034fcf600453546c5a8bae2029844e18661a23 Mon Sep 17 00:00:00 2001 From: bczernecki Date: Tue, 22 Feb 2022 15:48:32 +0100 Subject: [PATCH 09/21] update NEWS --- .Rbuildignore | 2 +- NEWS.md | 6 ++++-- tests/testthat/test-meteo_imgw_daily.R | 6 ++++++ 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 tests/testthat/test-meteo_imgw_daily.R diff --git a/.Rbuildignore b/.Rbuildignore index a5292df..351af5d 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -9,5 +9,5 @@ ^\.httr-oauth$ ^data-raw$ ^vignettes/articles$ - ^\.github$ +^\.Rhistory$ diff --git a/NEWS.md b/NEWS.md index ab4fe27..50c21db 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,9 @@ # climate 1.0.4 -* Function `nearest_stations_imgw()` now uses the Vincenty's formula to calculate the distance between points on a spheroid, not the Euclidean distance -(the results were inaccurate) +* Function `spheroid_dist` added to improve accuracy of calculations between points, but also avoid installing GIS dependencies (thanks to @kadyb) +* Function `nearest_stations_imgw()` now uses the Vincenty's formula in `spheroid_dist` to calculate the distance between points on a spheroid, not the Euclidean distance (previously results were inaccurate for some specific cases) +* minor bugs fixes and improvements + # climate 1.0.3 diff --git a/tests/testthat/test-meteo_imgw_daily.R b/tests/testthat/test-meteo_imgw_daily.R new file mode 100644 index 0000000..ea6eff5 --- /dev/null +++ b/tests/testthat/test-meteo_imgw_daily.R @@ -0,0 +1,6 @@ +context("meteo_imgw_daily") +y <- 1900 # year not supported + +test_that("meteo_imgw_daily", { + expect_error(meteo_imgw_daily(rank = "synop", year = y, status = TRUE, coords = TRUE)) +}) From b1704a4bee59d47b4ae4b74a158ed37e77749a7c Mon Sep 17 00:00:00 2001 From: bczernecki Date: Tue, 22 Feb 2022 15:52:15 +0100 Subject: [PATCH 10/21] gitlab CI update --- .github/workflows/R-CMD-check.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index d59d8cb..7a25bfa 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -32,8 +32,8 @@ jobs: config: - {os: macOS-latest, r: 'release'} - {os: windows-latest, r: '3.6'} - - {os: ubuntu-16.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"} - - {os: ubuntu-16.04, r: '3.5', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"} + - {os: ubuntu-18.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"} + - {os: ubuntu-18.04, r: '3.5', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"} env: R_REMOTES_NO_ERRORS_FROM_WARNINGS: true RSPM: ${{ matrix.config.rspm }} From 793b68232a551de3754911d0738661eee77b7bc6 Mon Sep 17 00:00:00 2001 From: bczernecki Date: Tue, 22 Feb 2022 16:44:00 +0100 Subject: [PATCH 11/21] more up-to-date ubuntu --- .github/workflows/R-CMD-check.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 7a25bfa..e37153b 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -32,8 +32,8 @@ jobs: config: - {os: macOS-latest, r: 'release'} - {os: windows-latest, r: '3.6'} - - {os: ubuntu-18.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"} - - {os: ubuntu-18.04, r: '3.5', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"} + - {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"} + - {os: ubuntu-20.04, r: '3.6', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"} env: R_REMOTES_NO_ERRORS_FROM_WARNINGS: true RSPM: ${{ matrix.config.rspm }} From 842ea17e06316c4aac98e1261d5294cbb73c9a44 Mon Sep 17 00:00:00 2001 From: bczernecki Date: Tue, 22 Feb 2022 16:44:13 +0100 Subject: [PATCH 12/21] and windows --- .github/workflows/R-CMD-check.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index e37153b..1076ea6 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -31,7 +31,7 @@ jobs: matrix: config: - {os: macOS-latest, r: 'release'} - - {os: windows-latest, r: '3.6'} + - {os: windows-latest, r: 'release'} - {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"} - {os: ubuntu-20.04, r: '3.6', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"} env: From db9bbe05994a7468ccbb319f108bcef24475af4f Mon Sep 17 00:00:00 2001 From: bczernecki Date: Tue, 22 Feb 2022 16:54:41 +0100 Subject: [PATCH 13/21] rspm update --- .github/workflows/R-CMD-check.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 1076ea6..47e15ea 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -32,8 +32,8 @@ jobs: config: - {os: macOS-latest, r: 'release'} - {os: windows-latest, r: 'release'} - - {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"} - - {os: ubuntu-20.04, r: '3.6', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"} + - {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} + - {os: ubuntu-20.04, r: '3.6', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} env: R_REMOTES_NO_ERRORS_FROM_WARNINGS: true RSPM: ${{ matrix.config.rspm }} From e6e45ee12425548fd62c68fbd487c3c20d62c64e Mon Sep 17 00:00:00 2001 From: bczernecki Date: Tue, 22 Feb 2022 17:38:27 +0100 Subject: [PATCH 14/21] avoid polish chars in examples --- R/meteo_imgw_monthly.R | 4 ++-- man/meteo_imgw_monthly.Rd | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/R/meteo_imgw_monthly.R b/R/meteo_imgw_monthly.R index 9ae9878..ce92159 100644 --- a/R/meteo_imgw_monthly.R +++ b/R/meteo_imgw_monthly.R @@ -26,8 +26,8 @@ #' #' # please note that station names may change over time #' # and thus 2 names are required in some cases: -#' df = meteo_imgw_monthly(rank = 'synop', year = 1991:2000, -#' coords = TRUE, station = c("POZNAŃ","POZNAŃ-ŁAWICA")) +#' # df = meteo_imgw_monthly(rank = 'synop', year = 1991:2000, +#' # coords = TRUE, station = c("POZNAŃ","POZNAŃ-ŁAWICA")) #' } #' meteo_imgw_monthly = function(rank = "synop", year, status = FALSE, coords = FALSE, station = NULL, col_names = "short", ...){ diff --git a/man/meteo_imgw_monthly.Rd b/man/meteo_imgw_monthly.Rd index 825997a..ae6bbfd 100644 --- a/man/meteo_imgw_monthly.Rd +++ b/man/meteo_imgw_monthly.Rd @@ -45,8 +45,8 @@ Downloading monthly (meteorological) data from the SYNOP / CLIMATE / PRECIP stat # please note that station names may change over time # and thus 2 names are required in some cases: - df = meteo_imgw_monthly(rank = 'synop', year = 1991:2000, - coords = TRUE, station = c("POZNAŃ","POZNAŃ-ŁAWICA")) + # df = meteo_imgw_monthly(rank = 'synop', year = 1991:2000, + # coords = TRUE, station = c("POZNAŃ","POZNAŃ-ŁAWICA")) } } From e67c1da899985b4e301ee7da7bfd77df7f85639b Mon Sep 17 00:00:00 2001 From: bczernecki Date: Tue, 22 Feb 2022 17:59:09 +0100 Subject: [PATCH 15/21] check ubuntu 18.04 --- .github/workflows/R-CMD-check.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 47e15ea..8cfb57e 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -32,8 +32,8 @@ jobs: config: - {os: macOS-latest, r: 'release'} - {os: windows-latest, r: 'release'} - - {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} - - {os: ubuntu-20.04, r: '3.6', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} + - {os: ubuntu-18.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"} + - {os: ubuntu-18.04, r: '3.6', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"} env: R_REMOTES_NO_ERRORS_FROM_WARNINGS: true RSPM: ${{ matrix.config.rspm }} From d0f76dbb2037c2f7d8446d5ed7ffbc59270fb54f Mon Sep 17 00:00:00 2001 From: Bartosz Date: Tue, 22 Feb 2022 18:43:33 +0100 Subject: [PATCH 16/21] roxygen update --- DESCRIPTION | 2 +- man/climate-package.Rd | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 2146a23..390f4f3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -27,7 +27,7 @@ License: MIT + file LICENSE Encoding: UTF-8 LazyData: true Roxygen: list(markdown = TRUE) -RoxygenNote: 7.1.1 +RoxygenNote: 7.1.2 Depends: R (>= 3.1) Imports: diff --git a/man/climate-package.Rd b/man/climate-package.Rd index a3373cb..73268a1 100644 --- a/man/climate-package.Rd +++ b/man/climate-package.Rd @@ -8,12 +8,7 @@ \description{ \if{html}{\figure{logo.png}{options: align='right' alt='logo' width='120'}} -Automatize downloading of meteorological and hydrological data from publicly available repositories: - OGIMET (), - University of Wyoming - atmospheric vertical profiling data (), - Polish Institute of Meterology and Water Management - National Research Institute (), - and National Oceanic & Atmospheric Administration (NOAA). - This package also allows for adding geographical coordinates for each observation. +Automatize downloading of meteorological and hydrological data from publicly available repositories: OGIMET (), University of Wyoming - atmospheric vertical profiling data (), Polish Institute of Meterology and Water Management - National Research Institute (), and National Oceanic & Atmospheric Administration (NOAA). This package also allows for adding geographical coordinates for each observation. } \seealso{ Useful links: From 0d9904271d6b3189dcaf759718b8dd9a268865d7 Mon Sep 17 00:00:00 2001 From: bczernecki Date: Tue, 22 Feb 2022 18:52:25 +0100 Subject: [PATCH 17/21] no rspm --- .github/workflows/R-CMD-check.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 8cfb57e..245d8e2 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -32,8 +32,8 @@ jobs: config: - {os: macOS-latest, r: 'release'} - {os: windows-latest, r: 'release'} - - {os: ubuntu-18.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"} - - {os: ubuntu-18.04, r: '3.6', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"} + - {os: ubuntu-18.04, r: 'release'} + - {os: ubuntu-18.04, r: '3.6'} env: R_REMOTES_NO_ERRORS_FROM_WARNINGS: true RSPM: ${{ matrix.config.rspm }} From 15a515ebc65b1dfd94f411ab1609a687b5cfb572 Mon Sep 17 00:00:00 2001 From: Bartosz Date: Tue, 22 Feb 2022 19:04:13 +0100 Subject: [PATCH 18/21] Renviron --- .Renviron | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .Renviron diff --git a/.Renviron b/.Renviron new file mode 100644 index 0000000..e83f339 --- /dev/null +++ b/.Renviron @@ -0,0 +1,12 @@ +LC_CTYPE = "en_US.UTF-8" +LC_NUMERIC = "C" +LC_TIME = "en_US.UTF-8" +LC_COLLATE = "C" +LC_MONETARY = "en_US.UTF-8" +LC_MESSAGES = "en_US.UTF-8" +LC_PAPER = "en_US.UTF-8" +LC_NAME = "C" +LC_ADDRESS = "C" +LC_TELEPHONE = "C" +LC_MEASUREMENT = "en_US.UTF-8" +LC_IDENTIFICATION = "C" From 103fdd6301f951a57c447ec3f3e4fdc98f0cd67e Mon Sep 17 00:00:00 2001 From: Bartosz Date: Tue, 22 Feb 2022 19:16:07 +0100 Subject: [PATCH 19/21] no renviron for windows + env var for linux --- .Renviron | 12 ------------ .github/workflows/R-CMD-check.yaml | 13 +++++++++++++ 2 files changed, 13 insertions(+), 12 deletions(-) delete mode 100644 .Renviron diff --git a/.Renviron b/.Renviron deleted file mode 100644 index e83f339..0000000 --- a/.Renviron +++ /dev/null @@ -1,12 +0,0 @@ -LC_CTYPE = "en_US.UTF-8" -LC_NUMERIC = "C" -LC_TIME = "en_US.UTF-8" -LC_COLLATE = "C" -LC_MONETARY = "en_US.UTF-8" -LC_MESSAGES = "en_US.UTF-8" -LC_PAPER = "en_US.UTF-8" -LC_NAME = "C" -LC_ADDRESS = "C" -LC_TELEPHONE = "C" -LC_MEASUREMENT = "en_US.UTF-8" -LC_IDENTIFICATION = "C" diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 245d8e2..ac0bbaa 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -67,6 +67,19 @@ jobs: - name: Install system dependencies if: runner.os == 'Linux' run: | + export LC_CTYPE = "en_US.UTF-8" + export LC_NUMERIC = "C" + export LC_TIME = "en_US.UTF-8" + export LC_COLLATE = "C" + export LC_MONETARY = "en_US.UTF-8" + export LC_MESSAGES = "en_US.UTF-8" + export LC_PAPER = "en_US.UTF-8" + export LC_NAME = "C" + export LC_ADDRESS = "C" + export LC_TELEPHONE = "C" + export LC_MEASUREMENT = "en_US.UTF-8" + export LC_IDENTIFICATION = "C" + while read -r cmd do eval sudo $cmd From 865946064a58690bc2bb0f65e23b4ad629f4dc6f Mon Sep 17 00:00:00 2001 From: Bartosz Date: Tue, 22 Feb 2022 19:22:53 +0100 Subject: [PATCH 20/21] env var for linux --- .github/workflows/R-CMD-check.yaml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index ac0bbaa..6de782d 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -67,18 +67,18 @@ jobs: - name: Install system dependencies if: runner.os == 'Linux' run: | - export LC_CTYPE = "en_US.UTF-8" - export LC_NUMERIC = "C" - export LC_TIME = "en_US.UTF-8" - export LC_COLLATE = "C" - export LC_MONETARY = "en_US.UTF-8" - export LC_MESSAGES = "en_US.UTF-8" - export LC_PAPER = "en_US.UTF-8" - export LC_NAME = "C" - export LC_ADDRESS = "C" - export LC_TELEPHONE = "C" - export LC_MEASUREMENT = "en_US.UTF-8" - export LC_IDENTIFICATION = "C" + export LC_CTYPE="en_US.UTF-8" + export LC_NUMERIC="C" + export LC_TIME="en_US.UTF-8" + export LC_COLLATE="C" + export LC_MONETARY="en_US.UTF-8" + export LC_MESSAGES="en_US.UTF-8" + export LC_PAPER="en_US.UTF-8" + export LC_NAME="C" + export LC_ADDRESS="C" + export LC_TELEPHONE="C" + export LC_MEASUREMENT="en_US.UTF-8" + export LC_IDENTIFICATION="C" while read -r cmd do From 578050a674046e253ae704f184f7eeb271358a76 Mon Sep 17 00:00:00 2001 From: Bartosz Date: Tue, 22 Feb 2022 19:35:52 +0100 Subject: [PATCH 21/21] .renviron for linux --- .github/workflows/R-CMD-check.yaml | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 6de782d..efc6629 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -67,23 +67,14 @@ jobs: - name: Install system dependencies if: runner.os == 'Linux' run: | - export LC_CTYPE="en_US.UTF-8" - export LC_NUMERIC="C" - export LC_TIME="en_US.UTF-8" - export LC_COLLATE="C" - export LC_MONETARY="en_US.UTF-8" - export LC_MESSAGES="en_US.UTF-8" - export LC_PAPER="en_US.UTF-8" - export LC_NAME="C" - export LC_ADDRESS="C" - export LC_TELEPHONE="C" - export LC_MEASUREMENT="en_US.UTF-8" - export LC_IDENTIFICATION="C" + ls + pwd + echo -e 'LC_CTYPE = "en_US.UTF-8"\nLC_NUMERIC="C"\nLC_TIME="en_US.UTF-8"\nLC_COLLATE="C"\nLC_MONETARY="en_US.UTF-8"\nLC_MESSAGES="en_US.UTF-8"\nLC_PAPER="en_US.UTF-8"\nLC_NAME="C"\nLC_ADDRESS="C"\nLC_TELEPHONE="C"\nLC_MEASUREMENT="en_US.UTF-8"\nLC_IDENTIFICATION="C"' > .Renviron while read -r cmd do eval sudo $cmd - done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "16.04"))') + done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "18.04"))') - name: Install dependencies run: |