packages <- c("qs", "dplyr", "ggplot2", "sf", "lubridate", "here", "ows4R", "patchwork", "kableExtra")
lapply(packages, function(pkg) {
  if (!require(pkg, character.only = TRUE)) install.packages(pkg)
  library(pkg, character.only = TRUE)
})

📥 Download and load the file

From qs (if you want to download geometry as well, it can be heavy)

qs_file <- "global_catch_tunaatlasird_level2.qs"
if (!file.exists(qs_file)) {
  download.file("https://zenodo.org/record/15221705/files/global_catch_tunaatlasird_level2.qs?download=1", qs_file, mode = "wb")
}
catch_data <- qs::qread(qs_file)

catch_data$geom_wkt <- NULL 

From csv (geometry can be downloaded from github, downloading is slower and the dataset is close to 1GB).

csv_file <- "global_catch_tunaatlasird_level2 (without_geom).csv"
if (!file.exists(csv_file)) {
  download.file("https://zenodo.org/records/15221705/files/global_catch_tunaatlasird_level2%20(without_geom).csv?download=1", csv_file, mode = "wb")
}
catch_data <- readr::read_csv(csv_file) %>% dplyr::mutate(geographic_identifier = as.character(geographic_identifier))

First lines

kableExtra::kable(head(catch_data))
source_authority fishing_fleet time_start time_end geographic_identifier gear_type species fishing_mode measurement_unit measurement_value GRIDTYPE species_group gear_label fishing_fleet_label species_label species_definition ocean fishing_mode_label
CCSBT AUS 1975-12-01 1975-12-31 5237150 01.1 SBF UNK Tons 59.8000 1deg_x_1deg SCOMBROIDEI Purse seines Australia Southern bluefin tuna Thunnus maccoyii WCPFC Undefined school
CCSBT AUS 1976-09-01 1976-09-30 5237150 09.1 SBF UNK Tons 36.2000 1deg_x_1deg SCOMBROIDEI Handlines and hand-operated pole-and-lines Australia Southern bluefin tuna Thunnus maccoyii WCPFC Undefined school
CCSBT AUS 1976-10-01 1976-10-31 5237150 09.1 SBF UNK Tons 41.0000 1deg_x_1deg SCOMBROIDEI Handlines and hand-operated pole-and-lines Australia Southern bluefin tuna Thunnus maccoyii WCPFC Undefined school
CCSBT AUS 1976-12-01 1976-12-31 5232132 09.1 SBF UNK Tons 2109.5199 1deg_x_1deg SCOMBROIDEI Handlines and hand-operated pole-and-lines Australia Southern bluefin tuna Thunnus maccoyii IOTC Undefined school
CCSBT AUS 1976-12-01 1976-12-31 5233134 09.1 SBF UNK Tons 448.3517 1deg_x_1deg SCOMBROIDEI Handlines and hand-operated pole-and-lines Australia Southern bluefin tuna Thunnus maccoyii IOTC Undefined school
CCSBT AUS 1976-12-01 1976-12-31 5234134 09.1 SBF UNK Tons 711.5694 1deg_x_1deg SCOMBROIDEI Handlines and hand-operated pole-and-lines Australia Southern bluefin tuna Thunnus maccoyii IOTC Undefined school

As the geometry can be heavy, we propose to remove it and to add it when necessary in plots.

📊 Data overview

This dataset provides monthly records of tuna and tuna-like species catches at the global scale between 1950 and 2021. Here is a description of the columns:

dplyr::glimpse(catch_data)
## Rows: 5,035,119
## Columns: 18
## $ source_authority      <chr> "CCSBT", "CCSBT", "CCSBT", "CCSBT", "CCSBT", "CC…
## $ fishing_fleet         <chr> "AUS", "AUS", "AUS", "AUS", "AUS", "AUS", "AUS",…
## $ time_start            <date> 1975-12-01, 1976-09-01, 1976-10-01, 1976-12-01,…
## $ time_end              <date> 1975-12-31, 1976-09-30, 1976-10-31, 1976-12-31,…
## $ geographic_identifier <chr> "5237150", "5237150", "5237150", "5232132", "523…
## $ gear_type             <chr> "01.1", "09.1", "09.1", "09.1", "09.1", "09.1", …
## $ species               <chr> "SBF", "SBF", "SBF", "SBF", "SBF", "SBF", "SBF",…
## $ fishing_mode          <chr> "UNK", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK",…
## $ measurement_unit      <chr> "Tons", "Tons", "Tons", "Tons", "Tons", "Tons", …
## $ measurement_value     <dbl> 59.80000, 36.20000, 41.00000, 2109.51994, 448.35…
## $ GRIDTYPE              <chr> "1deg_x_1deg", "1deg_x_1deg", "1deg_x_1deg", "1d…
## $ species_group         <chr> "SCOMBROIDEI", "SCOMBROIDEI", "SCOMBROIDEI", "SC…
## $ gear_label            <chr> "Purse seines", "Handlines and hand-operated pol…
## $ fishing_fleet_label   <chr> "Australia", "Australia", "Australia", "Australi…
## $ species_label         <chr> "Southern bluefin tuna", "Southern bluefin tuna"…
## $ species_definition    <chr> "Thunnus maccoyii", "Thunnus maccoyii", "Thunnus…
## $ ocean                 <chr> "WCPFC", "WCPFC", "WCPFC", "IOTC", "IOTC", "IOTC…
## $ fishing_mode_label    <chr> "Undefined school", "Undefined school", "Undefin…
summary(catch_data$measurement_value)
##      Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
##       0.0       0.8       4.1      94.2      21.6 1158525.0
kableExtra::kable(table(catch_data$measurement_unit))
Var1 Freq
Number of fish 580236
Tons 4454883

🗺️ Catch map

This map shows the spatial distribution of catches or effort aggregated by geographic grid cell. The measurement_value is summed per area.

catch_summary_by_unit <- catch_data %>%
  dplyr::group_by(geographic_identifier, measurement_unit) %>%
  dplyr::summarise(total = sum(measurement_value, na.rm = TRUE), .groups = "drop")

catch_summary_geom <- catch_summary_by_unit %>%
  dplyr::inner_join(cwp_grid %>% dplyr::select(cwp_code, geom), by = c("geographic_identifier" = "cwp_code")) %>%
  sf::st_as_sf()

plots <- catch_summary_geom %>%
  dplyr::group_split(measurement_unit) %>%
  purrr::map(function(df) {
    unit <- unique(df$measurement_unit)
    
    ggplot2::ggplot() +
      ggplot2::geom_sf(data = continent, fill = "gray90", color = "gray60") +
      ggplot2::geom_sf(data = df, ggplot2::aes(fill = total), color = NA) +
      ggplot2::scale_fill_viridis_c(option = "plasma", trans = "log", na.value = "transparent") +
      ggplot2::labs(title = paste("Unit:", unit), fill = "Catch Total") +
      ggplot2::theme_minimal()
  })

patchwork::wrap_plots(plots, ncol = 2)

Your turn:

If you want to use only part of the data you can filter the dataset using the dimensison provided exemple, here let’s focus on silky sharks (note that this only concern catch data as effort cannot be related to species)

silky_sharks <- catch_data %>% dplyr::filter(species_label == "Silky shark")
silky_sharks %>%
  dplyr::group_by(year = lubridate::year(time_start), measurement_unit) %>%
  dplyr::summarise(total = sum(measurement_value, na.rm = TRUE)) %>%
  ggplot2::ggplot(ggplot2::aes(x = year, y = total)) +
  ggplot2::geom_line() +
  ggplot2::facet_wrap(~measurement_unit, scales = "free_y") +
  ggplot2::labs(title = "Total catches by Year and Measurement unit", y = "Measured Value", x = "Year")

Let’s decompose the data for some dimensions

groupped_gear <- silky_sharks %>% dplyr::group_by(gear_label, time_start, measurement_unit) %>% 
  dplyr::summarise(measurement_value = sum(measurement_value))

ggplot(groupped_gear) +
  aes(
    x = time_start,
    y = measurement_value,
    colour = gear_label
  ) +
  geom_line() +  #
  geom_point() +
  scale_color_hue(direction = 1) +
  theme_minimal() +
  facet_wrap(vars(measurement_unit), scales = "free")

groupped_fishing_fleet <- silky_sharks %>% dplyr::group_by(fishing_fleet_label, time_start, measurement_unit) %>% 
  dplyr::summarise(measurement_value = sum(measurement_value))

ggplot(groupped_fishing_fleet) +
  aes(
    x = time_start,
    y = measurement_value,
    colour = fishing_fleet_label
  ) +
  geom_line() +  #
  geom_point() +
  scale_color_hue(direction = 1) +
  theme_minimal() +
  facet_wrap(vars(measurement_unit), scales = "free")
groupped_source_auth <- silky_sharks %>% dplyr::group_by(source_authority, time_start, measurement_unit) %>% 
  dplyr::summarise(measurement_value = sum(measurement_value))

ggplot(groupped_source_auth) +
  aes(
    x = time_start,
    y = measurement_value,
    colour = source_authority
  ) +
  geom_line() +  #
  geom_point() +
  scale_color_hue(direction = 1) +
  theme_minimal() +
  facet_wrap(vars(measurement_unit), scales = "free")

How to aggregate data from 1 deg to 5 deg ?

source("https://raw.githubusercontent.com/firms-gta/geoflow-tunaatlas/master/R/sardara_functions/transform_cwp_code_from_1deg_to_5deg.R")

one_degree <- silky_sharks %>% dplyr::filter(substr(geographic_identifier, 1, 1) == "5")
five_degree <- silky_sharks %>% dplyr::filter(substr(geographic_identifier, 1, 1) == "6")
silky_sharks_aggregated <- one_degree %>% rowwise() %>% 
  dplyr::mutate(geographic_identifier = transform_cwp_code_from_1deg_to_5deg(geographic_identifier))

How to disaggregate ? (need connection to DB for now)

source("https://raw.githubusercontent.com/eblondel/geoflow-tunaatlas/master/R/tunaatlas_scripts/generation/spatial_curation_downgrade_resolution.R")

georef_dataset<-spatial_curation_downgrade_resolution(con,silky_sharks,resolution = 1 , remove = FALSE)