Skip to content

Commit

Permalink
Merge pull request #184 from GlobalFishingWatch/main
Browse files Browse the repository at this point in the history
update develop to current version
  • Loading branch information
AndreaSanchezTapia authored Jan 21, 2025
2 parents d9e9630 + 7900108 commit c93f96a
Show file tree
Hide file tree
Showing 58 changed files with 3,061 additions and 2,174 deletions.
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
Package: gfwr
Title: Access data from Global Fishing Watch APIs
Version: 2.0.0
Version: 2.0.1
Authors@R: c(
person("Tyler", "Clavelle", , "[email protected]", role = c("aut", "cre"),
person("Tyler", "Clavelle", , "[email protected]", role = c("aut"),
comment = c(ORCID = "0000-0002-2155-2459")),
person("Rocío", "Joo", , "[email protected]",
role = c("aut"),
comment = c(ORCID = "0000-0003-0319-4210")),
person("Nate", "Miller", , "[email protected]",
role = c("aut")),
person("Andrea", "Sánchez-Tapia", , "[email protected]",
role = c("aut"),
role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-3521-4338"))
)
Description: This package connects to several Global Fishing Watch APIs to get vessel and events information in an R-friendly format.
License: Apache License (>= 2)
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Imports:
dplyr,
geojsonsf,
Expand Down
36 changes: 36 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,41 @@
# gfwr 2.0.1

2024-11-28

## Major change - bug fix

- We updated the parsing of the output of `get_vessel_info()`. For some advanced
queries using `where`, the function was returning only a subset of the vessels.
This issue is now solved and the number of results should be equal to the number
of vessels returned by Vessel Viewer on our map. (solves #176)

## Breaking changes

- Some fields in the response were renamed across outputs (addressing issue #146):

- `get_vessel_info()`: in `$registryInfo` we renamed `id` to `registryId`
- `get_event()`: we renamed `id` to `eventId` and `type` to `eventType`


## New features

- `get_vessel_info()`: We added an `index` column to indicate which `vesselIds`
are grouped together and belong to the same vessel. This should help associate
information from the returned datasets and guide the user when requesting events
for a single vessel or a group of vessels.

- `get_event()`: We unnested the column-list `"vessel"` to give more visibility to
the vessels each event corresponds to.

## Minor changes

- We updated the `get_event()` section in the README to improve the workflow and
send groups of `vesselIds` corresponding to one or multiple vessels.


# gfwr 2.0.0


__`gfwr` was updated to work with version 3 of our APIs.__ This results in various breaking changes in
parameter names and output formats. We aim to list here the major modifications but please also
check [the API documentation](https://globalfishingwatch.org/our-apis/documentation#version-3-api)
Expand Down
26 changes: 14 additions & 12 deletions R/get_event.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,20 @@
#' library(gfwr)
#' # port visits
#' get_event(event_type = "PORT_VISIT",
#' vessels = c("e0c9823749264a129d6b47a7aabce377",
#' "8c7304226-6c71-edbe-0b63-c246734b3c01"),
#' vessels = c("8c7304226-6c71-edbe-0b63-c246734b3c01"),
#' start_date = "2017-01-26",
#' end_date = "2017-12-31",
#' confidence = c(3, 4), # only for port visits
#' key = gfw_auth())
#' #encounters
#' get_event(event_type = "ENCOUNTER",
#' vessels = c("e0c9823749264a129d6b47a7aabce377",
#' "8c7304226-6c71-edbe-0b63-c246734b3c01"),
#' start_date = "2018-01-30",
#' end_date = "2023-02-04",
#' vessels = c("8c7304226-6c71-edbe-0b63-c246734b3c01"),
#' start_date = "2012-01-30",
#' end_date = "2024-02-04",
#' key = gfw_auth())
#' # fishing
#' get_event(event_type = "FISHING",
#' vessels = c("8c7304226-6c71-edbe-0b63-c246734b3c01"),
#' vessels = c("9b3e9019d-d67f-005a-9593-b66b997559e5"),
#' start_date = "2017-01-26",
#' end_date = "2023-02-04",
#' key = gfw_auth())
Expand Down Expand Up @@ -132,8 +130,8 @@
#' sf::st_as_sfc() |>
#' sf::st_as_sf()
#'get_event(event_type = 'FISHING',
#' start_date = "2020-10-01",
#' end_date = "2020-12-31",
#' start_date = "2022-01-01",
#' end_date = "2024-01-01",
#' region = test_polygon,
#' region_source = 'USER_SHAPEFILE',
#' key = gfw_auth())
Expand Down Expand Up @@ -302,20 +300,24 @@ get_event <- function(event_type,
df_out <- tibble::tibble(
start = purrr::map_chr(all_entries, 'start'),
end = purrr::map_chr(all_entries, 'end'),
id = purrr::map_chr(all_entries, 'id'),
type = purrr::map_chr(all_entries, 'type'),
eventId = purrr::map_chr(all_entries, 'id'),
eventType = purrr::map_chr(all_entries, 'type'),
lat = purrr::map_dbl(all_entries, purrr::pluck, 'position','lat'),
lon = purrr::map_dbl(all_entries, purrr::pluck, 'position','lon'),
regions = purrr::map(all_entries, purrr::pluck, 'regions'),
boundingBox = purrr::map(all_entries, 'boundingBox'),
distances = purrr::map(all_entries, 'distances'),
vessel = purrr::map(all_entries, 'vessel'),
event_info = purrr::map(all_entries, length(all_entries[[1]])) # the event_info is always the last element
event_info = purrr::map(all_entries, length(all_entries[[1]])) # the event_info is always the last element and changes names
)

# Map function to each event to convert to data frame
event_df <- df_out %>%
dplyr::mutate(dplyr::across(c(start, end), make_datetime))
# Unnest vessel information
event_df <- event_df %>%
tidyr::unnest_wider(vessel, names_sep = "_") %>%
dplyr::rename(vesselId = vessel_id)
#
# # Print out total events
total <- nrow(event_df)
Expand Down
2 changes: 1 addition & 1 deletion R/get_last_report.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ get_last_report <- function(key = gfw_auth()) {
NA
},
warning = function(cond) {
message(paste("Request caused a warning:", url))
message(paste("Request caused a warning:"))
message("Here's the original warning message:")
message(conditionMessage(cond))
# Choose a return value in case of warning
Expand Down
8 changes: 4 additions & 4 deletions R/get_raster.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#' @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 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 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 @@ -58,8 +58,8 @@ get_raster <- function(spatial_resolution = NULL,
temporal_resolution = NULL,
group_by = NULL,
filter_by = NULL,
start_date = NULL,
end_date = NULL,
start_date = "2023-01-01",
end_date = "2023-12-31",
region = NULL,
region_source = NULL,
key = gfw_auth(),
Expand Down
Loading

0 comments on commit c93f96a

Please sign in to comment.