Skip to content

Commit

Permalink
corrected all examples
Browse files Browse the repository at this point in the history
  • Loading branch information
remip48 committed Jan 23, 2024
1 parent c1fb5c6 commit 2989331
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 9 deletions.
4 changes: 2 additions & 2 deletions R/00_AIStravel_interpolate_extract.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@
#' ais <- ais %>%
#' mutate(timestamp = as.numeric(ymd_hms(datetime)))
#'
#' AIStravel_interpolate_extract(data,
#' ais_data,
#' AIStravel_interpolate_extract(data = point_to_extract,
#' ais_data = ais,
#' mmsi_time_to_order = T,
#' search_into_radius_m = 50000,
#' run_AIStravel = T,
Expand Down
7 changes: 6 additions & 1 deletion R/02b_AISidentify_stations_aircraft.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
#' \dontrun{
#' data("ais")
#'
#' AISidentify_stations_aircraft(ais_data)}
#' library(dplyr)
#' library(lubridate)
#' ais <- ais %>%
#' mutate(timestamp = as.numeric(ymd_hms(datetime)))

#' AISidentify_stations_aircraft(ais_data = ais)}
#' @export

AISidentify_stations_aircraft <- function(ais_data,
Expand Down
2 changes: 1 addition & 1 deletion R/02c_AIScorrect_speed.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#' return_sf = F,
#' return_3035_coords = F)
#'
#' AIScorrect_speed(ais_data,
#' AIScorrect_speed(ais_data = ais,
#' mmsi_time_to_order = T,
#' threshold_speed_to_correct = 100,
#' time_stop = 5*60*60)}
Expand Down
61 changes: 57 additions & 4 deletions R/04a_AISextract.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
#' filter_high_speed = T,
#' parallelize = F)
#'
#'#' AISextract(data = point_to_extract,
#' AISextract(data = point_to_extract,
#' ais_data = ais,
#' search_into_radius_m = 50000,
#' duplicate_time = F,
Expand Down Expand Up @@ -83,6 +83,59 @@ AISextract <- function(data,
ais_data <- ais_data[ais_data$timestamp > (min(data$timestamp, na.rm = T) - (max_time_diff + t_gap + average_at)) &
ais_data$timestamp < (max(data$timestamp, na.rm = T) + t_gap + average_at), ]

if (!(all(c("ais_X", "ais_Y") %in% colnames(ais_data)))) {
if (!(all(c("X", "Y") %in% colnames(ais_data)))) {
if (!("sf" %in% class(ais_data))) {
ais_data <- ais_data %>%
dplyr::mutate(tlon = lon,
tlat = lat) %>%
st_as_sf(coords = c("tlon", "tlat"), crs = 4326)
}
if (st_crs(ais_data)$input != "EPSG:3035") {
ais_data <- ais_data %>%
st_transform(crs = 3035)
}

coords_eff <- ais_data %>%
st_coordinates() %>%
as.data.frame()

ais_data <- ais_data %>%
st_drop_geometry() %>%
dplyr::mutate(X = coords_eff[,1],
Y = coords_eff[,2])

rm(coords_eff)
} else {
ais_data <- ais_data %>%
mutate(ais_X = X, ais_Y = Y)
}
}

if (!(all(c("X", "Y") %in% colnames(data)))) {
if (!("sf" %in% class(data))) {
data <- data %>%
dplyr::mutate(tlon = lon,
tlat = lat) %>%
st_as_sf(coords = c("tlon", "tlat"), crs = 4326)
}
if (st_crs(data)$input != "EPSG:3035") {
data <- data %>%
st_transform(crs = 3035)
}

coords_eff <- data %>%
st_coordinates() %>%
as.data.frame()

data <- data %>%
st_drop_geometry() %>%
dplyr::mutate(X = coords_eff[,1],
Y = coords_eff[,2])

rm(coords_eff)
}

if (duplicate_time) {
data <- DATAextend_time(data = data, accelerate = accelerate, max_time_diff = max_time_diff, t_gap = t_gap, average_at = average_at)
# } else if (accelerate) {
Expand Down Expand Up @@ -126,9 +179,9 @@ AISextract <- function(data,
eff_dt <- data[data$timestamp_AIS_to_extract == dt,]

mmsi_ref <- ais_data[ais_data$timestamp > (dt - t_gap - average_at) &
ais_data$timestamp < (dt + t_gap + average_at) &
ais_data$ais_X >= (min(eff_dt$X) - search_into_radius_m) & ais_data$ais_X <= (max(eff_dt$X) + search_into_radius_m) &
ais_data$ais_Y >= (min(eff_dt$Y) - search_into_radius_m) & ais_data$ais_Y <= (max(eff_dt$Y) + search_into_radius_m),]
ais_data$timestamp < (dt + t_gap + average_at) &
ais_data$ais_X >= (min(eff_dt$X) - search_into_radius_m) & ais_data$ais_X <= (max(eff_dt$X) + search_into_radius_m) &
ais_data$ais_Y >= (min(eff_dt$Y) - search_into_radius_m) & ais_data$ais_Y <= (max(eff_dt$Y) + search_into_radius_m),]

if (nrow(mmsi_ref) > 1) {
mmsi_ref <- mmsi_ref %>%
Expand Down
2 changes: 1 addition & 1 deletion R/05a_MMSI_infos.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#' \dontrun{
#' data("ais")
#'
#' MMSI_infos(ais_data,
#' MMSI_infos(ais_data = ais,
#' threshold_length = 475,
#' weight_complete_data = 10)}
#' @export
Expand Down

0 comments on commit 2989331

Please sign in to comment.