Skip to content

Commit

Permalink
Merge pull request #188 from GlobalFishingWatch/rocio-bugsfix-tidy
Browse files Browse the repository at this point in the history
Rocio bugsfix tidy
  • Loading branch information
AndreaSanchezTapia authored Jan 25, 2025
2 parents c242c4c + de1a108 commit d6eaea8
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 85 deletions.
53 changes: 34 additions & 19 deletions R/get_event.R
Original file line number Diff line number Diff line change
@@ -1,31 +1,46 @@
#'
#' Base function to get events from API and convert response to data frame
#'
#' @param vessels A vector of vesselIds, obtained via the `get_vessel_info()` function
#' @param vessels A vector of vesselIds, obtained via the `get_vessel_info()`
#' function
#' @param event_type Type of event to get data of. A vector with any combination
#' of "ENCOUNTER", "FISHING", "GAP", "LOITERING", "PORT_VISIT"
#' @param encounter_types Filters for types of vessels during the encounter. A
#' @param encounter_types Only useful when event_type = "ENCOUNTER". Filters for
#' types of vessels during the encounter. A
#' vector with any combination of: "CARRIER-FISHING", "FISHING-CARRIER",
#' "FISHING-SUPPORT", "SUPPORT-FISHING"
#' @param vessel_types A vector of vessel types, any combination of: "FISHING",
#' "CARRIER", "SUPPORT", "PASSENGER", "OTHER_NON_FISHING", "SEISMIC_VESSEL",
#' "BUNKER_OR_TANKER", "CARGO"
#' @param duration duration, in minutes, of the event, ex. 30
#' @param start_date Start of date range to search events, in YYYY-MM-DD format and including this date
#' @param end_date End of date range to search events, in YYYY-MM-DD format and excluding this date
#' @param confidences Confidence levels (1-4) of events (port visits only)
#' @param region sf shape to filter raster or GFW region code (such as an
#' EEZ code). See details about formatting the geojson
#' @param region_source source of the region ('EEZ','MPA', 'RFMO' or 'USER_SHAPEFILE')
#' @param gap_intentional_disabling Logical. Whether the Gap events are intentional,
#' @param duration minimum duration that the event should have (in minutes). The
#' default value is 1.
#' @param start_date Start of date range to search events, in YYYY-MM-DD format
#' and including this date
#' @param end_date End of date range to search events, in YYYY-MM-DD format and
#' excluding this date
#' @param confidences Only useful when event_type = "PORT_VISIT". Confidence
#' levels (1-4) of events.
#' @param region If region_source is set to "EEZ", "MPA" or "RFMO", GFW region
#' code (see get_region_id()) if region_source = "USER_SHAPEFILE", sf shape with
#' the area of interest.
#' @param region_source source of the region ('EEZ','MPA', 'RFMO' or
#' 'USER_SHAPEFILE'). Null by default but required if a value for region is
#' specified.
#' @param gap_intentional_disabling Logical. Only useful when event_type = "GAP".
#' To show intentional gap events,
#' according to Global Fishing Watch algorithms
#' @param key Authorization token. Can be obtained with gfw_auth() function
#' @param quiet Boolean. Whether to print the number of events returned by the
#' request
#' @param print_request Boolean. Whether to print the request, for debugging
#' purposes. When contacting the GFW team it will be useful to send this string
#' @param limit Limit
#' @param offset Offset
#' @param limit Amount of search results to return. The default value is 99999.
#' @param offset Offset into the search results, used for pagination. It starts
#' at 0. It is used in combination with the param limit, for example you send
#' limit = 5 and you get in the response total vessels =10. So, If you send
#' offset =0 OR you don’t send it, you will get the first 5 results (first page).
#' Therefore, in order to get the second page, you need to send offset = 5 which
#' is the position of the first element you want from the second page.
#' @param flags ISO3 code for the flag of the vessels. Null by default.
#' @param sort How to sort the events. By default, +start, which sorts the events
#' in ascending order (+) of the start dates of the events. Other possible values
Expand Down Expand Up @@ -139,21 +154,21 @@
#' @export

get_event <- function(event_type,
encounter_types = NULL,
start_date = "2012-01-01",
end_date = "2024-12-31",
sort = "+start",
vessels = NULL,
flags = NULL,
vessel_types = NULL,
start_date = "2012-01-01",
end_date = "2024-12-31",
region = NULL,
region_source = NULL,
gap_intentional_disabling = NULL,
region = NULL,
duration = 1,
encounter_types = NULL,
gap_intentional_disabling = NULL,
confidences = c(2, 3, 4),
key = gfw_auth(),
limit = 99999,
offset = 0,
sort = "+start",
key = gfw_auth(),
quiet = FALSE,
print_request = FALSE,
...) {
Expand Down
20 changes: 12 additions & 8 deletions R/get_event_stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,23 @@
#' @param vessels A vector of vesselIds, obtained via the `get_vessel_info()` function
#' @param event_type Type of event to get data of. A vector with any combination
#' of "ENCOUNTER", "FISHING", "GAP", "LOITERING", "PORT_VISIT"
#' @param encounter_types Filters for types of vessels during the encounter. A
#' @param encounter_types Only useful when event_type = "ENCOUNTER".
#' Filters for types of vessels during the encounter. A
#' vector with any combination of: "CARRIER-FISHING", "FISHING-CARRIER",
#' "FISHING-SUPPORT", "SUPPORT-FISHING"
#' @param start_date Start of date range to search events, in YYYY-MM-DD format and including this date
#' @param end_date End of date range to search events, in YYYY-MM-DD format and excluding this date
#' @param confidences Confidence levels (1-4) of events (port visits only)
#' @param confidences Only useful when event_type = "PORT_VISIT". Confidence
#' levels (1-4) of events.
#' @param region_source Optional but mandatory if using the argument region.
#' Source of the region. If 'EEZ','MPA', 'RFMO',
#' then the value for the argument region must be the code for that region.
#' If 'USER_SHAPEFILE', then region has to be an sf object
#' @param region GFW region code (such as an EEZ, MPA or RFMO code) or a
#' formatted geojson shape. See Details about formatting the geojson.
#' @param duration duration, in minutes, of the event, ex. 30
#' @param duration minimum duration of the event in minutes. The default value is 1.
#' @param interval Time series granularity. Must be a string. Possible values: 'HOUR', 'DAY', 'MONTH', 'YEAR'.
#' @param flags ISO3 code for the flag of the vessels. Null by default.
#' @param key Authorization token. Can be obtained with gfw_auth() function
#' @param quiet Boolean. Whether to print the number of events returned by the
#' request
Expand Down Expand Up @@ -85,15 +88,16 @@
#' @export

get_event_stats <- function(event_type,
encounter_types = NULL,
vessels = NULL,
vessel_types = NULL,
start_date = "2012-01-01",
end_date = "2024-12-31",
duration = 1,
interval = NULL,
vessels = NULL,
vessel_types = NULL,
flags = NULL,
region_source = NULL,
region = NULL,
interval = NULL,
duration = 1,
encounter_types = NULL,
confidences = c(2, 3, 4),
key = gfw_auth(),
quiet = FALSE,
Expand Down
19 changes: 12 additions & 7 deletions R/get_raster.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
#' 'DAILY', 'MONTHLY', 'YEARLY'
#' @param group_by parameter to group by. Can be 'VESSEL_ID', 'FLAG', 'GEARTYPE',
#' 'FLAGANDGEARTYPE' or 'MMSI'. Optional.
#' @param filter_by parameter to filter by.
#' @param start_date Required. Start of date range to search events, in YYYY-MM-DD format and including this date
#' @param end_date Required. End of date range to search events, in YYYY-MM-DD format and excluding this date
#' @param filter_by Possible fields to filter AIS-based fishing effort by are:
#' flag, geartype and vessel_id. filter_by works together with group_by.
#' You can aggregate results using group_by,
#' for example by flag, and then do "flag IN ('ESP')".
#' @param start_date Required. Start of date range to search events, in
#' YYYY-MM-DD format and including this date
#' @param end_date Required. End of date range to search events, in
#' YYYY-MM-DD format and excluding this date
#' @param region sf shape to filter raster or GFW region code (such as a
#' Marine Regions Geographic Identifier or EEZ code).
#' @param region_source source of the region ('EEZ','MPA', 'RFMO' or 'USER_SHAPEFILE')
Expand Down Expand Up @@ -54,14 +59,14 @@
#' key = gfw_auth(),
#' print_request = TRUE)
#' }
get_raster <- function(spatial_resolution = NULL,
get_raster <- function(start_date = "2023-01-01",
end_date = "2023-12-31",
spatial_resolution = NULL,
temporal_resolution = NULL,
group_by = NULL,
filter_by = NULL,
start_date = "2023-01-01",
end_date = "2023-12-31",
region = NULL,
region_source = NULL,
region = NULL,
key = gfw_auth(),
print_request = FALSE) {
date_range <- paste(start_date, end_date, sep = ",")
Expand Down
69 changes: 42 additions & 27 deletions man/get_event.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 20 additions & 15 deletions man/get_event_stats.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d6eaea8

Please sign in to comment.