diff --git a/DESCRIPTION b/DESCRIPTION index 3c18e9d2..cefb8a90 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: GeoPressureR Title: Global Positioning by Atmospheric Pressure -Version: 2.5 +Version: 2.6 Authors@R: c( person("Raphaël", "Nussbaumer", , "rafnuss@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-8185-1020")), @@ -17,6 +17,7 @@ Depends: R (>= 3.5.0) Imports: EBImage, + ecmwfr, future, geosphere, httr, @@ -28,7 +29,6 @@ Imports: tools, utils Suggests: - ecmwfr, ggplot2, igraph, knitr, diff --git a/NAMESPACE b/NAMESPACE index 7fb91458..ded93b4a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -11,6 +11,7 @@ export(geopressure_ts) export(geopressure_ts_path) export(graph_add_wind) export(graph_create) +export(graph_download_wind) export(graph_marginal) export(graph_path2edge) export(graph_path2lonlat) diff --git a/R/geolight.R b/R/geolight.R index 0560ef70..d100ef74 100644 --- a/R/geolight.R +++ b/R/geolight.R @@ -224,7 +224,7 @@ find_twilights <- function(light, if (any(id_sr == 1)) { warning( "There is likely a problem with the shiftK, ", sum(id_sr == 1), - " twighlit set at midnight. shift_k=", shift_k + " twilight set at midnight. shift_k=", shift_k ) } id_sr_r <- id_sr + (seq_len(dim(l)[2]) - 1) * dim(l)[1] @@ -234,7 +234,7 @@ find_twilights <- function(light, if (any(id_ss == 1)) { warning( "There is likely a problem with the shiftK, ", sum(id_ss == 1), - " twighlit set at midnight. shift_k=", shift_k + " twilight set at midnight. shift_k=", shift_k ) } id_ss_s <- id_ss + (seq_len(dim(l)[2]) - 1) * dim(l)[1] @@ -266,7 +266,9 @@ light2mat <- function(light, shift_k = 0) { stopifnot(is.numeric(shift_k)) res <- difftime(utils::tail(light$date, -1), utils::head(light$date, -1), units = "secs") - stopifnot(length(unique(res)) == 1) + if (length(unique(res)) != 1) { + stop("Temporal resolution of the light data is not the same. The code currently cannot work.") + } res <- as.numeric(res[1]) # Pad time to start and finish at 00:00 @@ -279,15 +281,22 @@ light2mat <- function(light, shift_k = 0) { ) date <- date - shift_k + # if light$date is not measuring at 00:00 exacly, we need to move date + closest <- which.min(abs(date - light$date[1])) + date <- date - (date[closest] - light$date[1]) + + # Match the observation on the new grid obs <- rep(NA, length(date)) - obs[date %in% light$date] <- light$obs + id <- date %in% light$date + stopifnot(any(id)) + obs[id] <- light$obs # reshape in matrix format mat <- list( obs = matrix(obs, nrow = 24 * 60 * 60 / res), date = matrix(date, nrow = 24 * 60 * 60 / res) ) - # raster::image(obs_r) + # raster::image(mat$obs) mat$date <- as.POSIXct(mat$date, origin = "1970-01-01", tz = "UTC") return(mat) diff --git a/R/geopressure.R b/R/geopressure.R index 81c20c60..dde3828b 100644 --- a/R/geopressure.R +++ b/R/geopressure.R @@ -53,6 +53,7 @@ geopressure_map <- function(pressure, margin = 30) { # Check input stopifnot(is.data.frame(pressure)) + stopifnot(nrow(pressure)>1) stopifnot("date" %in% names(pressure)) stopifnot(inherits(pressure$date, "POSIXt")) stopifnot("obs" %in% names(pressure)) @@ -65,7 +66,7 @@ geopressure_map <- function(pressure, max(pressure$obs[!pressure$isoutliar])) { stop(paste0( "Pressure observation should be between 250 hPa (~10000m) and 1100 hPa (sea level at 1013", - "hPa)" + "hPa). Check unit return by `pam_read()`" )) } stopifnot(is.logical(pressure$isoutliar)) @@ -105,27 +106,35 @@ geopressure_map <- function(pressure, warning("Date of pressure are not on a regular interval. This might cause issue later.") } dt <- as.numeric(stats::median(dtall)) - n <- 1 / dt + 1 + n <- round(1 / dt + 1) # make the convolution for each stationary period separately for (i_s in seq(1, max(pressure$sta_id, na.rm = TRUE))) { - pres_i_s <- pres - pres_i_s[pressure$sta_id != i_s] <- NA - pres_i_s_smoothna <- stats::filter( - c(FALSE, !is.na(pres_i_s), FALSE), - rep(1 / n, n) - ) - pres_i_s[is.na(pres_i_s)] <- 0 - pres_i_s_smooth <- stats::filter(c(0, pres_i_s, 0), rep(1 / n, n)) + if (length(pres) > n){ + pres_i_s <- pres + pres_i_s[pressure$sta_id != i_s] <- NA + pres_i_s_smoothna <- stats::filter( + c(FALSE, !is.na(pres_i_s), FALSE), + rep(1 / n, n) + ) + pres_i_s[is.na(pres_i_s)] <- 0 + pres_i_s_smooth <- stats::filter(c(0, pres_i_s, 0), rep(1 / n, n)) - tmp <- pres_i_s_smooth / pres_i_s_smoothna - tmp <- tmp[seq(2, length(tmp) - 1)] + tmp <- pres_i_s_smooth / pres_i_s_smoothna + tmp <- tmp[seq(2, length(tmp) - 1)] - pres[!is.na(pressure$sta_id) & pressure$sta_id == i_s] <- - tmp[!is.na(pressure$sta_id) & pressure$sta_id == i_s] + pres[!is.na(pressure$sta_id) & pressure$sta_id == i_s] <- + tmp[!is.na(pressure$sta_id) & pressure$sta_id == i_s] + } } # downscale to 1 hour - pres[format(pressure$date, "%M") != "00"] <- NA + # Find the start time closer to the hour + idt_s <- which.min(abs(round.POSIXt(pressure$date[seq_len(1 / dt)], units = "hours") - + pressure$date[seq_len(1 / dt)])) + # Define the index of time to keep + idt <- seq(idt_s, length(pressure$date), by = 1 / dt) + # Remove the other ones + pres[!(seq(1, length(pres)) %in% idt)] <- NA if (sum(!is.na(pres)) == 0) { stop("No pressure to query. Check outliar and staID==0 (for flight).") @@ -156,22 +165,34 @@ geopressure_map <- function(pressure, temp_file <- tempfile("log_geopressure_map_", fileext = ".json") write(jsonlite::toJSON(body_df), temp_file) stop(paste0( - "Error with youre request on http://glp.mgravey.com:24853/GeoPressure/v1/map/. ", + "Error with your request on http://glp.mgravey.com:24853/GeoPressure/v1/map/. ", "Please try again, and if the problem persists, file an issue on Github:", "https://github.com/Rafnuss/GeoPressureAPI/issues/new?body=geopressure_ts&labels=crash with this log file located on your computer: ", temp_file )) } - # Get URIS - uris <- unlist(httr::content(res)$data$urls) - # Note that the order of the uris will be different than requested to optimized the + # Get urls + urls <- httr::content(res)$data$urls + urls[sapply(urls, is.null)] <- NA + urls <- unlist(urls) + # Note that the order of the urls will be different than requested to optimized the # parralelization labels <- unlist(httr::content(res)$data$labels) labels_order <- order(labels) + # Check that the uri exist + if (any(is.na(urls))){ + warning("Not urls returned for stationary periods: ", + paste(labels[is.na(urls)], collapse = ", "), ". It is probably due to request(s) made ", + "for periods where no data are available. Note that ERA5 data is usually only ", + "available on GEE ~3-5 months after.") + labels <- labels[is.na(urls)] + labels_order <- labels_order[is.na(urls)] + urls <- urls[is.na(urls)] + } message( - "Requests generated successfully for ", length(labels), " stationary periods (", - paste(labels, collapse = ", "), ")" + "Requests generated successfully for ", sum(!is.na(urls)), " stationary periods (", + paste(labels[!is.na(urls)], collapse = ", "), ")" ) # Perform the call in parallel @@ -180,28 +201,28 @@ geopressure_map <- function(pressure, f <- c() message("Send requests:") - progress_bar(0, max = length(uris)) - for (i_u in seq_len(length(uris))) { + progress_bar(0, max = length(urls)) + for (i_u in seq_len(length(urls))) { f[[i_u]] <- future::future(expr = { filename <- tempfile() options(timeout = 60 * 5) - httr::GET(uris[i_u], httr::write_disk(filename)) + httr::GET(urls[i_u], httr::write_disk(filename)) return(filename) }, seed = TRUE) - progress_bar(i_u, max = length(uris)) + progress_bar(i_u, max = length(urls)) } # Get the raster pressure_maps <- c() filename <- c() message("Download geotiff:") - progress_bar(0, max = length(uris)) + progress_bar(0, max = length(urls)) tryCatch( expr = { - for (i_u in seq_len(length(uris))) { + for (i_u in seq_len(length(urls))) { filename[i_u] <- future::value(f[[i_u]]) pressure_maps[[i_u]] <- raster::brick(filename[i_u]) - progress_bar(i_u, max = length(uris)) + progress_bar(i_u, max = length(urls)) # Add datum raster::crs(pressure_maps[[i_u]]) <- @@ -227,13 +248,13 @@ geopressure_map <- function(pressure, }, error = function(cond) { message(paste0( - "Error during the reading of the file. We return the uris of the gee request, ", + "Error during the reading of the file. We return the urls of the gee request, ", "the filename to the file already downloaded and the pressure_maps already computed. ", "Here is the original error: " )) message(cond) return(list( - uris = uris, + urls = urls, filename = filename, pressure_maps = pressure_maps, future = f @@ -372,8 +393,9 @@ geopressure_prob_map <- function(pressure_maps, #' @param end_time If `pressure` is not provided, then `end_time` define the ending time of #' the timeserie as POSIXlt. #' @param verbose Display (or not) the progress of the query (logical). -#' @return A data.frame containing the timeserie of pressure and optionally altitude if `pressure` -#' is provided. +#' @return A data.frame containing the timeserie of ERA5 pressure (date, pressure) as well as +#' longitude and latitude (different if over water). If `pressure` is provided, the return +#' data.frame is the same as `pressure` with altitude and pressure0. #' @seealso [`geopressure_ts_path()`], [GeoPressureManual | Pressure Map #' ](https://raphaelnussbaumer.com/GeoPressureManual/pressure-map.html), #' @export @@ -443,7 +465,7 @@ geopressure_ts <- function(lon, # Check for change in position if (res_data$distInter > 0) { warning( - "Requested position is on water We will proceeed the request with the closet point to the ", + "Requested position is on water. We will proceeed the request with the closet point to the ", "shore (https://www.google.com/maps/dir/", lat, ",", lon, "/", res_data$lat, ",", res_data$lon, ") located ", round(res_data$distInter / 1000), " km away). Sending request." ) @@ -452,7 +474,6 @@ geopressure_ts <- function(lon, } # Download the csv file - message("") res2 <- httr::GET(res_data$url) # read csv @@ -485,9 +506,19 @@ geopressure_ts <- function(lon, # Compute the ERA5 pressure normalized to the pressure level (i.e. altitude) of the bird if (!is.null(pressure)) { + if (nrow(out) != nrow(pressure)) { + warning( + "The returned data.frame is had a different number of element than the requested ", + "pressure." + ) + } + + # Use a merge to combine all information possible from out into pressure. + out <- merge(pressure, out, all.x = TRUE) + # find when the bird was in flight or not to be considered id_0 <- pressure$sta_id == 0 | is.na(pressure$sta_id) - # If no ground (ie. no flight) is present, pressure0 has no meaning + # If no ground (ie. only flight) is present, pressure0 has no meaning if (!all(id_0)) { # We compute the mean pressure of the geolocator only when the bird is on the ground # (id_q==0) and when not marked as outliar @@ -498,9 +529,6 @@ geopressure_ts <- function(lon, out$pressure0 <- out$pressure - pressure_out_m + pressure_obs_m } - - # Add sta_id, lat and lon - out$sta_id <- pressure$sta_id } return(out) } diff --git a/R/graph.R b/R/graph.R index 59d32d39..1dbbc149 100644 --- a/R/graph.R +++ b/R/graph.R @@ -337,13 +337,122 @@ graph_trim <- function(gr) { return(gr) } + +#' Download wind data +#' +#' This function download the wind data from ERA5 for all flights. The flight are determined from +#' the stationary periods classified `pam$sta` (see `pam_classify()`). It request a single file for +#' each flight using the exact time (hourly basis) and pressure (altitude). We use +#' `wf_request_batch()` from `ecmwfr` to query multiple wind data at the same time. +#' +#' To be able to download data from the Climate Data Store (CDS), you will need to create an account +#' on [https://cds.climate.copernicus.eu]. You can then save your credential (`cds_key` and +#' `cds_user`) in your `.Rprofile` (see [GeoPressureManual | Wind graph]( +#' https://raphaelnussbaumer.com/GeoPressureManual/wind-graph.html#download-wind-data)). +#' +#' @param pam PAM logger dataset list with `pam$sta` computed. See [`pam_read()`] and [`pam_sta()`]. +#' @param area Geographical extent of the map to query. Either a raster (e.g. `static_prob`) or a +#' list ordered by North, West, South, East (e.g. `c(50,-16,0,20)`). +#' @param sta_id Stationary period identifier of the start of the flight to query as defined in +#' `pam$sta`. Be default, download for all the flight. +#' @param cds_key User (email address) used to sign up for the ECMWF data service. See +#' [`wf_set_key()`]. +#' @param cds_user Token provided by ECMWF. See [`wf_set_key()`]. +#' @param path Path were to store the downloaded data. +#' @return The path of the downloaded (requested file). +#' @seealso [`wf_request()`], [GeoPressureManual | Wind graph +#' ](https://raphaelnussbaumer.com/GeoPressureManual/wind-graph.html#download-wind-data) +#' @export +graph_download_wind <- function(pam, + area, # area is specified as N, W, S, E + sta_id = seq_len(nrow(pam$sta) - 1), + cds_key = Sys.getenv("cds_key"), + cds_user = Sys.getenv("cds_user"), + path = paste0("data/5_wind_graph/", pam$id, "/")) { + stopifnot(is.list(pam)) + stopifnot("pressure" %in% names(pam)) + stopifnot(is.data.frame(pam$pressure)) + stopifnot("date" %in% names(pam$pressure)) + stopifnot("obs" %in% names(pam$pressure)) + stopifnot("sta" %in% names(pam)) + stopifnot(is.data.frame(pam$sta)) + stopifnot("end" %in% names(pam$sta)) + stopifnot("start" %in% names(pam$sta)) + + if (is.list(area)) { + area <- area[[1]] + } + area <- raster::extent(area) + area <- c(area@ymax, area@xmin, area@ymin, area@xmax) + + stopifnot(is.numeric(sta_id)) + stopifnot(all(sta_id %in% pam$sta$sta_id)) + + ecmwfr::wf_set_key(user = cds_user, key = cds_key, service = "cds") + + if (!file.exists(path)) { + stop(paste0("The path ", path, " does not exist. You can create it with: `dir.create(path)`.")) + } + + # see https://confluence.ecmwf.int/display/CKB/ERA5%3A+data+documentation#ERA5:datadocumentation-Levellistings + possible_pressure <- c( + 1, 2, 3, 5, 7, 10, 20, 30, 50, 70, + seq(100, 250, 25), seq(300, 750, 50), seq(775, 1000, 25) + ) + + request_list <- list() + for (i_id in sta_id) { + # Find the index of sta_id + i_s <- which(pam$sta$sta_id == i_id) + + # Get the timeserie of the flight on a 1 hour resolution + flight_time <- seq(round.POSIXt(pam$sta$end[i_s] - 30 * 60, units = "hours"), + round.POSIXt(pam$sta$start[i_s + 1] + 30 * 60, units = "hours"), + by = 60 * 60 + ) + + # Find the pressure level needed during this flight + flight_id <- flight_time[1] <= pam$pressure$date & + pam$pressure$date <= utils::tail(flight_time, 1) + pres_id_min <- sum(!(min(pam$pressure$obs[flight_id]) < possible_pressure)) + pres_id_max <- sum(max(pam$pressure$obs[flight_id]) > possible_pressure) + 1 + flight_pres_id <- seq(pres_id_min, min(pres_id_max, length(possible_pressure))) + + # Prepare the query + request_list[[i_s]] <- list( + dataset_short_name = "reanalysis-era5-pressure-levels", + product_type = "reanalysis", + format = "netcdf", + variable = c("u_component_of_wind", "v_component_of_wind"), + pressure_level = possible_pressure[flight_pres_id], + year = sort(unique(format(flight_time, "%Y"))), + month = sort(unique(format(flight_time, "%m"))), + day = sort(unique(format(flight_time, "%d"))), + time = sort(unique(format(flight_time, "%H:%M"))), + area = area, + target = paste0(pam$id, "_", i_s, ".nc") + ) + } + + ecmwfr::wf_request_batch( + request_list, + workers = 20, + # user = , + path = path, + # time_out = 3600, + # total_timeout = length(request_list) * time_out/workers + ) +} + + #' Add windspeed and airspeed #' #' Read NetCDF file downloaded on your computer and add the average windspeed experienced by the #' bird and the corresponding airspeed for each edge of the graph. #' -#' See the [GeoPressureManual | Wind graph](https://raphaelnussbaumer.com/GeoPressureManual/wind-graph.html#download-wind-data) for explanations and -#' example on how to download the `NetCDF` files from ERA-5. +#' See the [GeoPressureManual | Wind graph]( +#' https://raphaelnussbaumer.com/GeoPressureManual/wind-graph.html#download-wind-data) for +#' explanations and example on how to download the `NetCDF` files from ERA-5. #' #' @param grl graph constructed with [`graph_create()`] #' @param pressure pressure data from a PAM logger. This data.frame needs to contains `date` as @@ -381,13 +490,6 @@ graph_add_wind <- function(grl, # Prepare the matrix of speed to return uv <- matrix(NA, nrow = length(grl$s), ncol = 2) - # Start progress bar - nds_expend_sum <- table(s[, 3]) - progress_bar(0, - max = sum(nds_expend_sum), - text = paste0("| sta = ", 0, "/", grl$sz[3] - 1) - ) - # Check that all the files of wind_speed exist and match the data request for (i1 in seq_len(grl$sz[3] - 1)) { fl_s <- grl$flight[[i1]] @@ -408,13 +510,30 @@ graph_add_wind <- function(grl, pres <- ncdf4::ncvar_get(nc, "level") t_q <- seq(from = t_s, to = t_e, by = 60 * 60) - pres_obs <- pressure$obs[pressure$date %in% t_q] - if (!(min(pres) <= min(pres_obs) && max(pres) >= min(1000, max(pres_obs)))) { + pres_obs <- pressure$obs[pressure$date > t_s & pressure$date < t_e] + if (length(pres_obs) == 0 | + !(min(pres) <= min(pres_obs) && + max(pres) >= min(1000, max(pres_obs)))) { stop(paste0("Pressure not matching for sta=", i_s)) } + + # Check if flight duration is + if (fl_s$start[i2] >= fl_s$end[i2]) { + stop(paste0( + "Flight starting on sta_id=", fl_s$sta_id[i2], " has a start time equal or greater than ", + "the end time. Please review your labeling file." + )) + } } } + # Start progress bar + nds_expend_sum <- table(s[, 3]) + progress_bar(0, + max = sum(nds_expend_sum), + text = paste0("| sta = ", 0, "/", grl$sz[3] - 1) + ) + # Loop through the stationary period kept in the graph for (i1 in seq_len(grl$sz[3] - 1)) { @@ -539,7 +658,7 @@ graph_add_wind <- function(grl, id_time <- which(time == t_q[i3]) # find the two pressure level to query (one above, one under) based on the geolocator # pressure at this timestep - pres_obs <- pressure$obs[pressure$date == t_q[i3]] + pres_obs <- stats::approx(pressure$date, pressure$obs, t_q[i3])$y df <- pres_obs - pres df[df < 0] <- NA id_pres <- which.min(df) @@ -648,7 +767,7 @@ graph_add_wind <- function(grl, #' @param grl graph constructed with [`graph_create()`] #' @return list of raster of the marginal probability at each stationary period #' @seealso [`graph_create()`], [GeoPressureManual | Basic graph]( -#' https://raphaelnussbaumer.com/GeoPressureManual/basic-graph.html#output-2-proability-map-of-stationary-period) +#' https://raphaelnussbaumer.com/GeoPressureManual/basic-graph.html#output-2-marginal-probability-map) #' @export graph_marginal <- function(grl) { stopifnot(is.list(grl)) diff --git a/R/pam.R b/R/pam.R index 155fc512..a22c4aeb 100644 --- a/R/pam.R +++ b/R/pam.R @@ -63,10 +63,12 @@ pam_read <- function(pathname, subset(pam_read_delim_dto(pressure_path), date >= crop_start & date < crop_end) }, "deg" = { - subset( - pam_read_delim_dto(pressure_path, skip = 20, col = 4, date_format = "%d/%m/%Y %H:%M:%S"), - date >= crop_start & date < crop_end + pres <- pam_read_delim_dto(pressure_path, + skip = 20, col = 4, + date_format = "%d/%m/%Y %H:%M:%S" ) + pres$obs <- pres$obs / 100 # return in hPa + subset(pres, date >= crop_start & date < crop_end) }, { data.frame() @@ -88,7 +90,7 @@ pam_read <- function(pathname, ), acceleration = switch(tools::file_ext(acceleration_path), "acceleration" = { - subset(pam_read_delim_dto(acceleration_path), date >= crop_start & date < crop_end) + subset(pam_read_delim_dto(acceleration_path, col = 4), date >= crop_start & date < crop_end) }, { data.frame() diff --git a/inst/geopressureviz/server.R b/inst/geopressureviz/server.R index d10260d9..6753f603 100644 --- a/inst/geopressureviz/server.R +++ b/inst/geopressureviz/server.R @@ -114,7 +114,7 @@ server <- function(input, output, session) { req(input$thr_sta) for (ts in reactVal$ts) { - sta_th <- sta[median(ts$sta_id) == sta$sta_id, ] + sta_th <- sta[median(ts$sta_id, na.rm=TRUE) == sta$sta_id, ] if (nrow(sta_th) > 0) { if (sta_th$duration > as.numeric(input$thr_sta)) { p <- p + diff --git a/man/geopressure_ts.Rd b/man/geopressure_ts.Rd index 4b2ee7cd..61ea14a2 100644 --- a/man/geopressure_ts.Rd +++ b/man/geopressure_ts.Rd @@ -29,8 +29,9 @@ the timeserie as POSIXlt.} \item{verbose}{Display (or not) the progress of the query (logical).} } \value{ -A data.frame containing the timeserie of pressure and optionally altitude if \code{pressure} -is provided. +A data.frame containing the timeserie of ERA5 pressure (date, pressure) as well as +longitude and latitude (different if over water). If \code{pressure} is provided, the return +data.frame is the same as \code{pressure} with altitude and pressure0. } \description{ This function return the surface atmospheric pressure timeseries from ERA5 at a queried location. diff --git a/man/graph_download_wind.Rd b/man/graph_download_wind.Rd new file mode 100644 index 00000000..e871db98 --- /dev/null +++ b/man/graph_download_wind.Rd @@ -0,0 +1,47 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/graph.R +\name{graph_download_wind} +\alias{graph_download_wind} +\title{Download wind data} +\usage{ +graph_download_wind( + pam, + area, + sta_id = seq_len(nrow(pam$sta) - 1), + cds_key = Sys.getenv("cds_key"), + cds_user = Sys.getenv("cds_user"), + path = paste0("data/5_wind_graph/", pam$id, "/") +) +} +\arguments{ +\item{pam}{PAM logger dataset list with \code{pam$sta} computed. See \code{\link[=pam_read]{pam_read()}} and \code{\link[=pam_sta]{pam_sta()}}.} + +\item{area}{Geographical extent of the map to query. Either a raster (e.g. \code{static_prob}) or a +list ordered by North, West, South, East (e.g. \code{c(50,-16,0,20)}).} + +\item{sta_id}{stationary period identifier of the \emph{start} of the flight to query as defined in +\code{pam$sta}.} + +\item{cds_key}{user (email address) used to sign up for the ECMWF data service. See +\code{\link[=wf_set_key]{wf_set_key()}}.} + +\item{cds_user}{token provided by ECMWF. See \code{\link[=wf_set_key]{wf_set_key()}}.} + +\item{path}{path were to store the downloaded data.} +} +\value{ +the path of the downloaded (requested file) +} +\description{ +This function wrap the function Wind data is available at high resolution (1hr, 0.25°, 37 pressure level) on ERA5 hourly data on pressure levels. And this data is easily accessible through the ecmwfr package. As the flight are of short duration, we suggest to download a file for each flight. +} +\details{ +area + +Be default download data for all the flight, thus sta_id is all exetpt the last one (no flight starting from the last stationary period) + +cds_key and cds_user +} +\seealso{ +\code{\link[=wf_request]{wf_request()}}, \href{https://raphaelnussbaumer.com/GeoPressureManual/wind-graph.html#download-wind-data}{GeoPressureManual | Wind graph } +} diff --git a/tests/testthat/test-geolight.R b/tests/testthat/test-geolight.R index a28a044e..bc329101 100644 --- a/tests/testthat/test-geolight.R +++ b/tests/testthat/test-geolight.R @@ -1,12 +1,12 @@ library(testthat) library(GeoPressureR) -pam_data <- pam_read( +pam <- pam_read( pathname = system.file("extdata/0_PAM/18LX", package = "GeoPressureR"), crop_start = "2017-06-20", crop_end = "2018-05-02" ) -twl <- find_twilights(pam_data$light, shift_k = 0) +twl <- find_twilights(pam$light, shift_k = 0) test_that("Check find_twilights()", { expect_true(all(c("twilight", "rise") %in% names(twl))) expect_true(nrow(twl) > 0) diff --git a/tests/testthat/test-geopressure.R b/tests/testthat/test-geopressure.R index efa28c73..84397a06 100644 --- a/tests/testthat/test-geopressure.R +++ b/tests/testthat/test-geopressure.R @@ -11,6 +11,14 @@ pam <- trainset_read( ) pam <- pam_sta(pam) +test_that("Check geopressure_map() for date too recent", { + pressure <- data.frame( + date = c(Sys.time(),Sys.time()+1), + obs = c(1000,1000), + sta_id = c(1,1) + ) + expect_error(raster_list <- geopressure_map(pressure, extent = c(1, 0, 0, 1), scale = 1)) +}) test_that("Check geopressure_map() output", { pressure <- data.frame(