| Title: | Toolkit for Investigation and Visualization of Young Anchovies |
|---|---|
| Description: | Specialized toolkit for processing biological and fisheries data from Peru's anchovy (Engraulis ringens) fishery. Provides functions to analyze fishing logbooks, calculate biological indicators (length-weight relationships, juvenile percentages), generate spatial fishing indicators, and visualize regulatory measures from Peru's Ministry of Production. Features automated data processing from multiple file formats, coordinate validation, spatial analysis of fishing zones, and tools for analyzing fishing closure announcements and regulatory compliance. Includes built-in datasets of Peruvian coastal coordinates and parallel lines for analyzing fishing activities within regulatory zones. |
| Authors: | Hans Ttito [aut, cre] (ORCID: <https://orcid.org/0000-0003-3732-9419>) |
| Maintainer: | Hans Ttito <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.1 |
| Built: | 2026-05-15 05:40:22 UTC |
| Source: | https://github.com/hansttito/tivy |
Adds new variables to a dataset, including the proportion of juveniles, the total number of individuals in the sample, the distance to the coast, and the distance category.
add_variables( data, JuvLim = 12, distance_type = "haversine", window = 0.5, unit = "nm", coastline = NULL, suppress_warnings = TRUE )add_variables( data, JuvLim = 12, distance_type = "haversine", window = 0.5, unit = "nm", coastline = NULL, suppress_warnings = TRUE )
data |
Data frame that must contain latitude ( |
JuvLim |
Length threshold to consider juveniles. |
distance_type |
Type of distance calculation to the coast. |
window |
Window parameter to smooth the coastline. |
unit |
Distance unit used in the calculation ("nm", "km", etc.). |
coastline |
Data frame with coastline coordinates. Must have columns named |
suppress_warnings |
Logical. If TRUE, warnings are suppressed. |
Data frame with new variables: juv (proportion of juveniles), sample (total individuals),
dc (distance to coast), and dc_cat (categorical distance).
## Not run: data_hauls <- process_hauls(data_hauls = calas_bitacora) data_fishing_trips <- process_fishing_trips(data_fishing_trips = faenas_bitacora) hauls_length <- process_length(data_length = tallas_bitacora) data_length_trips <- merge( x = data_fishing_trips, y = hauls_length, by = 'fishing_trip_code' ) data_total <- merge_length_fishing_trips_hauls( data_hauls = data_hauls, data_length_fishing_trips = data_length_trips ) results <- add_variables(data = data_total) ## End(Not run)## Not run: data_hauls <- process_hauls(data_hauls = calas_bitacora) data_fishing_trips <- process_fishing_trips(data_fishing_trips = faenas_bitacora) hauls_length <- process_length(data_length = tallas_bitacora) data_length_trips <- merge( x = data_fishing_trips, y = hauls_length, by = 'fishing_trip_code' ) data_total <- merge_length_fishing_trips_hauls( data_hauls = data_hauls, data_length_fishing_trips = data_length_trips ) results <- add_variables(data = data_total) ## End(Not run)
Applies catch weighting to length frequency columns in a data frame. Supports parallel processing for large datasets.
apply_catch_weighting( data, length_cols, catch_col, a, b, parallel = FALSE, num_cores = NULL, block_size = 10000, silence_warnings = TRUE )apply_catch_weighting( data, length_cols, catch_col, a, b, parallel = FALSE, num_cores = NULL, block_size = 10000, silence_warnings = TRUE )
data |
Data frame containing length columns and catch data. |
length_cols |
Character vector of length column names. |
catch_col |
Name of the catch column. |
a |
Coefficient of the length-weight relationship. |
b |
Exponent of the length-weight relationship. |
parallel |
Logical. Use parallel processing. |
num_cores |
Number of cores for parallel processing. If NULL, auto-detect. |
block_size |
Block size for parallel processing. |
silence_warnings |
Logical. Suppress warnings. |
Data frame with original columns plus weighted length columns (prefixed with "weighted_").
## Not run: length_cols <- c("8", "8.5", "9", "9.5", "10", "10.5", "11", "11.5") weighted_data <- apply_catch_weighting( data = fishery_data, length_cols = length_cols, catch_col = "total_catch", a = 0.0001, b = 2.984 ) ## End(Not run)## Not run: length_cols <- c("8", "8.5", "9", "9.5", "10", "10.5", "11", "11.5") weighted_data <- apply_catch_weighting( data = fishery_data, length_cols = length_cols, catch_col = "total_catch", a = 0.0001, b = 2.984 ) ## End(Not run)
Dataset containing information about fishing hauls in the Peruvian sea. Hauls are specific locations where fishing activities are conducted.
calas_bitacoracalas_bitacora
A data.frame with sample data of hauls made by vessels in the Peruvian sea.
Randomly generated data.
data(calas_bitacora)data(calas_bitacora)
Internal function to calculate distances between multiple points and a coastline. Supports different distance calculation methods and spatial filtering.
calculate_distances_vectorized( lon_point, lat_point, coast_lon, coast_lat, distance_type, window, unit, resolution = 0.25 )calculate_distances_vectorized( lon_point, lat_point, coast_lon, coast_lat, distance_type, window, unit, resolution = 0.25 )
lon_point |
Vector of point longitudes. |
lat_point |
Vector of point latitudes. |
coast_lon |
Vector of coastline longitudes. |
coast_lat |
Vector of coastline latitudes. |
distance_type |
Distance calculation method. |
window |
Spatial filter window in degrees. |
unit |
Distance unit. |
resolution |
Grid resolution (only used if distance_type = "grid"). |
List with distance vectors and corresponding indices.
Estimates individual fish weight from length using the length-weight relationship: W = a * L^b
calculate_fish_weight(length, a, b)calculate_fish_weight(length, a, b)
length |
Numeric vector of fish lengths. |
a |
Coefficient of the length-weight relationship. |
b |
Exponent of the length-weight relationship. |
The length-weight relationship follows the allometric equation W = a * L^b, where W is weight, L is length, and a and b are species-specific parameters.
Numeric vector of estimated weights.
Froese, R. (2006). Cube law, condition factor and weight–length relationships: history, meta-analysis and recommendations. Journal of Applied Ichthyology, 22(4), 241-253.
Calculates the percentage of individuals considered juveniles based on a length threshold.
calculate_juvenile_percentage( frequency, length, juvenile_limit = 12, silence_warnings = FALSE )calculate_juvenile_percentage( frequency, length, juvenile_limit = 12, silence_warnings = FALSE )
frequency |
Numeric vector of length frequencies. |
length |
Numeric vector of corresponding lengths. |
juvenile_limit |
Length threshold for juvenile classification. |
silence_warnings |
Logical. Suppress warnings. |
Juvenile percentage calculations are essential for fisheries management decisions, particularly in determining fishing quotas and closure periods.
Percentage of juveniles in the sample.
IMARPE (2020). Protocolo Elaboración de la Tabla de Decisión para la determinación del Límite Máximo Total Permisible por temporada de pesca en la pesquería del stock norte-centro de la anchoveta peruana. IMP-DGIRP/AFDPERP, Edición: 05, Revisión 00, 40p.
Helper function that calculates juvenile percentages in number and weight. Used internally by summarize_juveniles_by_group.
calculate_juvenile_statistics( frequencies, length_values, juvenile_limit = 12, a = 0.0012, b = 3.1242 )calculate_juvenile_statistics( frequencies, length_values, juvenile_limit = 12, a = 0.0012, b = 3.1242 )
frequencies |
Numeric vector of frequencies by length. |
length_values |
Numeric vector of corresponding lengths. |
juvenile_limit |
Length threshold for juveniles. |
a |
Coefficient of length-weight relationship. |
b |
Exponent of length-weight relationship. |
Data frame with juvenile statistics.
frequencies <- c(10, 15, 25, 30, 20, 10) lengths <- c(8, 9, 10, 11, 12, 13) stats <- calculate_juvenile_statistics(frequencies, lengths)frequencies <- c(10, 15, 25, 30, 20, 10) lengths <- c(8, 9, 10, 11, 12, 13) stats <- calculate_juvenile_statistics(frequencies, lengths)
Estimates the distance between a set of points (lon, lat) and a coastline defined by coordinates. Can be executed sequentially or in parallel, and also return the indices of the nearest coastal points.
coast_distance( lon, lat, coastline = NULL, return_indices = FALSE, distance_type = "haversine", unit = "nm", window = 1, parallel = FALSE, cores = 4 )coast_distance( lon, lat, coastline = NULL, return_indices = FALSE, distance_type = "haversine", unit = "nm", window = 1, parallel = FALSE, cores = 4 )
lon |
Numeric vector with the longitudes of the points of interest. |
lat |
Numeric vector with the latitudes of the points of interest. |
coastline |
Data frame with coastline coordinates. Must have columns named |
return_indices |
Logical. If |
distance_type |
Type of geographic distance to use: "haversine", "euclidean", "grid". |
unit |
Unit of measurement for distance: "nm" (nautical miles), "km", etc. |
window |
Search window in degrees around the point to limit calculations and improve efficiency. |
parallel |
Logical. If |
cores |
Number of cores to use for parallel processing. |
If return_indices = FALSE, returns a numeric vector with distances to the coast for each point.
If return_indices = TRUE, returns a list with distance and index components.
## Not run: data_hauls <- process_hauls(data_hauls = calas_bitacora) distances <- coast_distance( lon = data_hauls$lon_final, lat = data_hauls$lat_final, distance_type = "haversine", unit = "nm", parallel = TRUE, cores = 2 ) ## End(Not run)## Not run: data_hauls <- process_hauls(data_hauls = calas_bitacora) distances <- coast_distance( lon = data_hauls$lon_final, lat = data_hauls$lat_final, distance_type = "haversine", unit = "nm", parallel = TRUE, cores = 2 ) ## End(Not run)
Converts numerical length frequencies to weight estimates using length-weight relationship.
convert_numbers_to_weight(data, length_cols, a, b)convert_numbers_to_weight(data, length_cols, a, b)
data |
Data frame with length frequency columns. |
length_cols |
Vector of length column names or numeric values. |
a |
Coefficient of the length-weight relationship. |
b |
Exponent of the length-weight relationship. |
Data frame with original columns plus weight columns (prefixed with "weight_").
## Not run: weight_data <- convert_numbers_to_weight( data = frequency_data, length_cols = c("8", "8.5", "9", "9.5", "10"), a = 0.0012, b = 3.1242 ) ## End(Not run)## Not run: weight_data <- convert_numbers_to_weight( data = frequency_data, length_cols = c("8", "8.5", "9", "9.5", "10"), a = 0.0012, b = 3.1242 ) ## End(Not run)
Converts a vector of dates in various formats to a standard date format.
The function tries to parse each date using predefined formats and returns
the first valid date found for each entry. If a date cannot be interpreted,
it is assigned as NA.
convert_to_date(date_vector, output_type = c("date", "datetime"))convert_to_date(date_vector, output_type = c("date", "datetime"))
date_vector |
A character vector containing dates in various formats. |
output_type |
Type of object to return: "date" for Date, "datetime" for POSIXct. |
A vector of Date or POSIXct objects, or NA if the date cannot be converted.
dates <- c("2025-04-10", "10/04/2025", "April 10, 2025") converted_dates <- convert_to_date(dates) print(converted_dates)dates <- c("2025-04-10", "10/04/2025", "April 10, 2025") converted_dates <- convert_to_date(dates) print(converted_dates)
Generates a comprehensive dashboard for fishery analysis including juvenile analysis, catch trends, spatial distribution, and summary statistics. This function consolidates all dashboard functionality.
create_fishery_dashboard( data, date_col = NULL, length_cols = NULL, a = 1e-04, b = 2.984, latitude_col = NULL, longitude_col = NULL, catch_col = NULL, juvenile_col = NULL, map_xlim = c(-85, -70), map_ylim = c(-20, 0), color_palette = NULL, date_breaks = NULL, sort_comparison = FALSE, comparison_title = NULL, catch_title = NULL, map_title = NULL, trend_title = NULL )create_fishery_dashboard( data, date_col = NULL, length_cols = NULL, a = 1e-04, b = 2.984, latitude_col = NULL, longitude_col = NULL, catch_col = NULL, juvenile_col = NULL, map_xlim = c(-85, -70), map_ylim = c(-20, 0), color_palette = NULL, date_breaks = NULL, sort_comparison = FALSE, comparison_title = NULL, catch_title = NULL, map_title = NULL, trend_title = NULL )
data |
Data frame with complete fishery data. |
date_col |
Date column name. If NULL, auto-detect. |
length_cols |
Length frequency column names. If NULL, auto-detect. |
a |
Length-weight coefficient. |
b |
Length-weight exponent. |
latitude_col |
Latitude column name. If NULL, auto-detect. |
longitude_col |
Longitude column name. If NULL, auto-detect. |
catch_col |
Catch column name. If NULL, auto-detect. |
juvenile_col |
Juvenile percentage column name. If NULL, auto-detect. |
map_xlim |
Map longitude limits. |
map_ylim |
Map latitude limits. |
color_palette |
Custom color palette. |
date_breaks |
Date axis breaks. |
sort_comparison |
Sort comparison plot. |
comparison_title |
Comparison plot title. |
catch_title |
Catch plot title. |
map_title |
Map plot title. |
trend_title |
Trend plot title. |
List with individual plots and combined dashboard (if patchwork available).
## Not run: dashboard <- create_fishery_dashboard( data = complete_fishery_data, date_col = "date", length_cols = paste0("length_", seq(8, 15, 0.5)), catch_col = "total_catch", latitude_col = "latitude", longitude_col = "longitude" ) dashboard$comparison dashboard$catch_trends dashboard$spatial_map dashboard$trends dashboard$dashboard ## End(Not run)## Not run: dashboard <- create_fishery_dashboard( data = complete_fishery_data, date_col = "date", length_cols = paste0("length_", seq(8, 15, 0.5)), catch_col = "total_catch", latitude_col = "latitude", longitude_col = "longitude" ) dashboard$comparison dashboard$catch_trends dashboard$spatial_map dashboard$trends dashboard$dashboard ## End(Not run)
Converts coordinates expressed in degrees, minutes and seconds (DMS) or degrees and minutes (DM) format to decimal degrees. By default, coordinates are assumed to be in the southern hemisphere (negative latitudes). The function can automatically correct common errors such as minutes or seconds greater than 60.
dms_to_decimal(coordinates, hemisphere = "S", correct_errors = TRUE)dms_to_decimal(coordinates, hemisphere = "S", correct_errors = TRUE)
coordinates |
Character vector. Each element should be in formats such as: "D M S", "D M", "17 26 S" |
hemisphere |
Character indicating hemisphere when not specified in the coordinate. One of "N", "S", "E", "W" or "O". "S" and "W"/"O" generate negative values. |
correct_errors |
Logical. If TRUE, automatically corrects out-of-range values. |
Numeric vector with coordinates converted to decimal degrees.
dms_to_decimal(c("73 15 0"), hemisphere = "W")dms_to_decimal(c("73 15 0"), hemisphere = "W")
Helper function to extract numerical length values from column names. Handles different naming patterns like "length_8.5", "weighted_9", "8", etc. Uses multiple extraction strategies to ensure robust parsing of column names.
extract_numeric_values( column_names, use_fallback = TRUE, fallback_type = "sequential", verbose = FALSE )extract_numeric_values( column_names, use_fallback = TRUE, fallback_type = "sequential", verbose = FALSE )
column_names |
Character vector of column names. |
use_fallback |
Logical. If TRUE, uses fallback strategy when numeric values cannot be extracted. |
fallback_type |
Character. Type of fallback to use when use_fallback = TRUE. Options: "sequential", "ones", "zeros". |
verbose |
Logical. Print information about extraction strategy used. |
The function uses the following extraction strategies in order:
Specific prefixes: "length_", "weighted_", "pond_" followed by numbers
Purely numeric column names
General pattern: extracts first number found in each name
Fallback: uses specified fallback strategy if previous methods fail
Numeric vector of length values extracted from column names.
extract_numeric_values(c("length_8.5", "weighted_10", "pond_12")) extract_numeric_values(c("8", "10.5", "12")) extract_numeric_values(c("size_8", "data_10.5", "value_12")) extract_numeric_values(c("length_8", "no_numbers"), use_fallback = FALSE) extract_numeric_values(c("bad_name1", "bad_name2"), fallback_type = "ones")extract_numeric_values(c("length_8.5", "weighted_10", "pond_12")) extract_numeric_values(c("8", "10.5", "12")) extract_numeric_values(c("size_8", "data_10.5", "value_12")) extract_numeric_values(c("length_8", "no_numbers"), use_fallback = FALSE) extract_numeric_values(c("bad_name1", "bad_name2"), fallback_type = "ones")
Processes PDF files containing official fishing announcements and extracts relevant information such as dates, coordinates, and nautical miles. Handles both local files and URLs.
extract_pdf_data( pdf_sources = NULL, temp_dir = NULL, verbose = TRUE, max_retries = 3 )extract_pdf_data( pdf_sources = NULL, temp_dir = NULL, verbose = TRUE, max_retries = 3 )
pdf_sources |
Character vector of PDF file paths or URLs. |
temp_dir |
Temporary directory for downloaded files. If NULL, uses tempdir(). |
verbose |
Show processing messages. |
max_retries |
Maximum download retries for URLs. |
Data frame with extracted announcement information including coordinates, dates, and nautical mile distances.
## Not run: pdf_files <- c("announcement1.pdf", "announcement2.pdf") results <- extract_pdf_data(pdf_sources = pdf_files) pdf_urls <- c( "https://example.com/announcement1.pdf", "https://example.com/announcement2.pdf" ) results <- extract_pdf_data(pdf_sources = pdf_urls) ## End(Not run)## Not run: pdf_files <- c("announcement1.pdf", "announcement2.pdf") results <- extract_pdf_data(pdf_sources = pdf_files) pdf_urls <- c( "https://example.com/announcement1.pdf", "https://example.com/announcement2.pdf" ) results <- extract_pdf_data(pdf_sources = pdf_urls) ## End(Not run)
Dataset containing information about fishing trips conducted along the Peruvian littoral.
faenas_bitacorafaenas_bitacora
A data.frame with sample data of fishing trips made by vessels in the Peruvian sea.
Randomly generated data.
data(faenas_bitacora)data(faenas_bitacora)
Retrieves fishing announcements from official websites within a specified date range. This function is specifically designed for PRODUCE (Peru) but can be adapted for other sources.
fetch_fishing_announcements( start_date, end_date, download = FALSE, download_dir = "downloads", batch_size = 10, verbose = TRUE, source_url = NULL, max_records = 5000 )fetch_fishing_announcements( start_date, end_date, download = FALSE, download_dir = "downloads", batch_size = 10, verbose = TRUE, source_url = NULL, max_records = 5000 )
start_date |
Start date in "dd/mm/yyyy" format. |
end_date |
End date in "dd/mm/yyyy" format. |
download |
Logical. Download PDF files. |
download_dir |
Directory for downloaded files. |
batch_size |
Records per request. |
verbose |
Print detailed information. |
source_url |
Base URL for the announcement source. Defaults to the PRODUCE page: https://consultasenlinea.produce.gob.pe/ConsultasEnLinea/consultas.web/comunicados/suspensionPreventiva |
max_records |
Maximum records to retrieve. |
Data frame with announcement information and download links.
## Not run: announcements <- fetch_fishing_announcements( start_date = "01/01/2023", end_date = "31/12/2023" ) announcements <- fetch_fishing_announcements( start_date = "01/01/2023", end_date = "31/01/2023", download = TRUE, download_dir = "announcements" ) ## End(Not run)## Not run: announcements <- fetch_fishing_announcements( start_date = "01/01/2023", end_date = "31/12/2023" ) announcements <- fetch_fishing_announcements( start_date = "01/01/2023", end_date = "31/01/2023", download = TRUE, download_dir = "announcements" ) ## End(Not run)
Searches for a column in a data frame using multiple pattern options. If multiple columns match, warns the user and returns the first match.
find_column(patterns, column_names, verbose = FALSE)find_column(patterns, column_names, verbose = FALSE)
patterns |
Character vector of regex patterns to search for. |
column_names |
Character vector of column names to search in. |
verbose |
Logical. If TRUE, prints detailed matching information. |
Integer index of the first matching column, or NULL if no match found.
cols <- c("codigo_faena", "numero_cala", "especie", "especies_capturadas") species_patterns <- c("especie", "species", "sp") col_index <- find_column(species_patterns, cols)cols <- c("codigo_faena", "numero_cala", "especie", "especies_capturadas") species_patterns <- c("especie", "species", "sp") col_index <- find_column(species_patterns, cols)
Identifies columns in a data frame that match a specific pattern. Useful for finding length columns, weight columns, etc.
find_columns_by_pattern(data, pattern = "weighted_", sort = TRUE)find_columns_by_pattern(data, pattern = "weighted_", sort = TRUE)
data |
Data frame to search. |
pattern |
Regular expression pattern to match. |
sort |
Logical. Sort results numerically. |
Character vector of matching column names.
# Create dummy data data <- data.frame( weighted_8.5 = c(1, 2, 3), weighted_10 = c(4, 5, 6), `8` = c(7, 8, 9), other = c(10, 11, 12) ) # Find weighted columns weighted_cols <- find_columns_by_pattern(data, pattern = "weighted_") # Find numeric-only named columns (e.g., "8") length_cols <- find_columns_by_pattern(data, pattern = "")# Create dummy data data <- data.frame( weighted_8.5 = c(1, 2, 3), weighted_10 = c(4, 5, 6), `8` = c(7, 8, 9), other = c(10, 11, 12) ) # Find weighted columns weighted_cols <- find_columns_by_pattern(data, pattern = "weighted_") # Find numeric-only named columns (e.g., "8") length_cols <- find_columns_by_pattern(data, pattern = "")
Formats and filters data extracted from announcements, converting dates to proper formats and allowing filtering by date range.
format_extracted_data( data, min_date = NULL, max_date = NULL, convert_coordinates = TRUE )format_extracted_data( data, min_date = NULL, max_date = NULL, convert_coordinates = TRUE )
data |
Data frame with structure from extract_pdf_data. |
min_date |
Minimum date for filtering (YYYY-MM-DD format or Date/POSIXct object). |
max_date |
Maximum date for filtering (YYYY-MM-DD format or Date/POSIXct object). |
convert_coordinates |
Logical. Convert DMS coordinates to decimal. |
Data frame with formatted and filtered announcement data.
## Not run: formatted_data <- format_extracted_data(raw_data) filtered_data <- format_extracted_data( data = raw_data, min_date = "2024-11-01", max_date = "2024-12-31" ) ## End(Not run)## Not run: formatted_data <- format_extracted_data(raw_data) filtered_data <- format_extracted_data( data = raw_data, min_date = "2024-11-01", max_date = "2024-12-31" ) ## End(Not run)
Finds the minimum or maximum length with positive frequency.
get_length_range(frequency, length, type = "min")get_length_range(frequency, length, type = "min")
frequency |
Numeric vector of length frequencies. |
length |
Numeric vector of corresponding lengths. |
type |
Either "min" or "max" to specify which range to return. |
Minimum or maximum length value with frequency > 0.
freq <- c(0, 0, 1, 2, 3, 4, 2, 1, 0) lengths <- c(5, 6, 7, 8, 9, 10, 11, 12, 13) min_length <- get_length_range(freq, lengths, type = "min") max_length <- get_length_range(freq, lengths, type = "max")freq <- c(0, 0, 1, 2, 3, 4, 2, 1, 0) lengths <- c(5, 6, 7, 8, 9, 10, 11, 12, 13) min_length <- get_length_range(freq, lengths, type = "min") max_length <- get_length_range(freq, lengths, type = "max")
Classifies a set of geographic coordinates (longitude and latitude) as "land" or "sea" according to their relative position to a coastline. A point is considered to be on land if its longitude is greater than that of its nearest point on the coastline.
land_points( x_point, y_point, coastline = NULL, parallel = FALSE, cores = 4, distance_type = "haversine", window = 0.5, unit = "nm" )land_points( x_point, y_point, coastline = NULL, parallel = FALSE, cores = 4, distance_type = "haversine", window = 0.5, unit = "nm" )
x_point |
Numeric vector of longitudes (in decimal degrees). |
y_point |
Numeric vector of latitudes (in decimal degrees). |
coastline |
Data frame with coastline coordinates. Must have columns named |
parallel |
Logical. If |
cores |
Number of cores to use for parallel processing. |
distance_type |
Type of geodesic distance to use in the calculation. |
window |
Geographic window in degrees to reduce the number of coastline points to consider. |
unit |
Unit of measurement for distance: "km" or "nm". |
Text vector of the same length as x_point, indicating whether each point
is on "land" or "sea". NA values are maintained as NA.
## Not run: data_hauls <- process_hauls(data_hauls = calas_bitacora) result <- land_points( x_point = data_hauls$lon_final, y_point = data_hauls$lat_final ) table(result) ## End(Not run)## Not run: data_hauls <- process_hauls(data_hauls = calas_bitacora) result <- land_points( x_point = data_hauls$lon_final, y_point = data_hauls$lat_final ) table(result) ## End(Not run)
Joins data from fishing trips, length and hauls, combining catches by species, length ranges (minimum and maximum) and spatial-temporal information of each haul.
merge_length_fishing_trips_hauls(data_hauls, data_length_fishing_trips)merge_length_fishing_trips_hauls(data_hauls, data_length_fishing_trips)
data_hauls |
Data frame processed with |
data_length_fishing_trips |
Data frame with length data by fishing trip and haul. |
Data frame with consolidated data from fishing trips, length and hauls.
## Not run: data_hauls <- process_hauls(data_hauls = calas_bitacora) data_fishing_trips <- process_fishing_trips(data_fishing_trips = faenas_bitacora) data_length <- process_length(data_length = tallas_bitacora) data_length_fishing_trips <- merge( x = data_length, y = data_fishing_trips, by = "fishing_trip_code", all = TRUE ) data_total <- merge_length_fishing_trips_hauls( data_hauls = data_hauls, data_length_fishing_trips = data_length_fishing_trips ) ## End(Not run)## Not run: data_hauls <- process_hauls(data_hauls = calas_bitacora) data_fishing_trips <- process_fishing_trips(data_fishing_trips = faenas_bitacora) data_length <- process_length(data_length = tallas_bitacora) data_length_fishing_trips <- merge( x = data_length, y = data_fishing_trips, by = "fishing_trip_code", all = TRUE ) data_total <- merge_length_fishing_trips_hauls( data_hauls = data_hauls, data_length_fishing_trips = data_length_fishing_trips ) ## End(Not run)
Dataset containing lines parallel to the Peruvian coast at different distances. These lines are useful for spatial analyses related to fishery management.
peru_coast_parallelsperu_coast_parallels
A list of data.frames, each representing a line parallel to the Peruvian coast.
Each data frame contains:
Longitude corresponding to the isoparalittoral area
Latitude corresponding to the isoparalittoral area
Distance to coast category (10-200)
Indicate the data source
data(peru_coast_parallels)data(peru_coast_parallels)
Dataset containing the coastline of Peru represented as a spatial object.
peru_coastlineperu_coastline
A data.frame with the following fields:
Longitude of the Peruvian coastline
Latitude of the Peruvian coastline
Marine Institute of Peru (IMARPE)
data(peru_coastline)data(peru_coastline)
Dataset containing isoparalittoral areas of the Peruvian coast. These areas represent zones with similar characteristics along the littoral.
peru_isoparalitoral_areasperu_isoparalitoral_areas
A data.frame with the following attributes:
Longitude corresponding to the isoparalittoral area
Latitude corresponding to the isoparalittoral area
Isoparalittoral Area code
Latitude category every 0.5 degrees (3 - 19.5)
Distance to coast category (10-200)
Marine Institute of Peru (IMARPE)
data(peru_isoparalitoral_areas)data(peru_isoparalitoral_areas)
Creates visualizations of fishing zones using either ggplot2 (static) or leaflet (interactive). This function consolidates all zone plotting functionality.
plot_fishing_zones( data, coastline = NULL, parallels = NULL, type = "static", title = NULL, colors = NULL, show_legend = FALSE, legend_title = NULL, zone_labels = NULL, add_grid = FALSE, base_layers = FALSE, minimap = FALSE )plot_fishing_zones( data, coastline = NULL, parallels = NULL, type = "static", title = NULL, colors = NULL, show_legend = FALSE, legend_title = NULL, zone_labels = NULL, add_grid = FALSE, base_layers = FALSE, minimap = FALSE )
data |
Data frame with fishing zone coordinates and metadata. |
coastline |
Data frame with coastline coordinates (columns "Long" and "Lat"). If NULL, uses internal dataset. |
parallels |
List of data frames with coast-parallel lines. |
type |
Plot type: "static" for ggplot2 or "interactive" for leaflet. |
title |
Plot title. |
colors |
Vector of colors for zones. If NULL, auto-generated. |
show_legend |
Logical. Show legend/layer control. |
legend_title |
Legend title. |
zone_labels |
Vector of custom labels for zones. |
add_grid |
Logical. Add coordinate grid (static only). |
base_layers |
Logical. Include multiple base map layers (interactive only). |
minimap |
Logical. Add minimap (interactive only). |
ggplot object (static) or leaflet object (interactive).
## Not run: plot_fishing_zones( data = zone_data, coastline = coastline_data, type = "static", title = "Fishing Zones", show_legend = TRUE ) plot_fishing_zones( data = zone_data, coastline = coastline_data, type = "interactive", base_layers = TRUE, minimap = TRUE ) ## End(Not run)## Not run: plot_fishing_zones( data = zone_data, coastline = coastline_data, type = "static", title = "Fishing Zones", show_legend = TRUE ) plot_fishing_zones( data = zone_data, coastline = coastline_data, type = "interactive", base_layers = TRUE, minimap = TRUE ) ## End(Not run)
Creates comprehensive visualizations for juvenile fish analysis including bar charts, line plots, and comparative analyses. This function consolidates all juvenile plotting functionality.
plot_juvenile_analysis( data, x_var, fill_var = NULL, length_cols = NULL, a = 0.0012, b = 3.1242, x_date_breaks = NULL, plot_type = "bars", title = NULL, subtitle = NULL, sort_by = "x", color_palette = NULL, facet_var = NULL, facet_cols = 2, bar_position = "dodge", y_limits = c(0, 100), use_facet_wrap = TRUE, group_by_type = TRUE, reference_line = NULL, theme_style = "light", legend_position = "bottom", rotate_x_labels = TRUE, na_to_zero = FALSE )plot_juvenile_analysis( data, x_var, fill_var = NULL, length_cols = NULL, a = 0.0012, b = 3.1242, x_date_breaks = NULL, plot_type = "bars", title = NULL, subtitle = NULL, sort_by = "x", color_palette = NULL, facet_var = NULL, facet_cols = 2, bar_position = "dodge", y_limits = c(0, 100), use_facet_wrap = TRUE, group_by_type = TRUE, reference_line = NULL, theme_style = "light", legend_position = "bottom", rotate_x_labels = TRUE, na_to_zero = FALSE )
data |
Data frame with juvenile analysis data. |
x_var |
Column name for x-axis variable. |
fill_var |
Column name for fill/color variable. |
length_cols |
Vector of length frequency column names. |
a |
Length-weight relationship coefficient. |
b |
Length-weight relationship exponent. |
x_date_breaks |
Date breaks for x-axis (e.g., "1 day", "1 month"). |
plot_type |
Plot type: "bars", "lines", "points", "mixed". |
title |
Plot title. |
subtitle |
Plot subtitle. |
sort_by |
Sorting method: "x", "number", "weight". |
color_palette |
Custom color palette. |
facet_var |
Variable for faceting. |
facet_cols |
Number of facet columns. |
bar_position |
Bar position: "dodge", "stack", "fill". |
y_limits |
Y-axis limits. |
use_facet_wrap |
Use facet wrap for juvenile type. |
group_by_type |
Group by juvenile type when not faceting. |
reference_line |
Reference line value (e.g., legal limit). |
theme_style |
Theme style: "classic", "minimal", "light", "dark". |
legend_position |
Legend position. |
rotate_x_labels |
Rotate x-axis labels. |
na_to_zero |
Convert NA values to zeros. |
ggplot object.
## Not run: plot_juvenile_analysis( data = fishery_data, x_var = "date", length_cols = paste0("length_", seq(8, 15, 0.5)) ) plot_juvenile_analysis( data = fishery_data, x_var = "date", fill_var = "vessel", length_cols = length_columns, plot_type = "mixed", reference_line = 10, title = "Juvenile Analysis by Vessel and Date" ) ## End(Not run)## Not run: plot_juvenile_analysis( data = fishery_data, x_var = "date", length_cols = paste0("length_", seq(8, 15, 0.5)) ) plot_juvenile_analysis( data = fishery_data, x_var = "date", fill_var = "vessel", length_cols = length_columns, plot_type = "mixed", reference_line = 10, title = "Juvenile Analysis by Vessel and Date" ) ## End(Not run)
Creates an interactive map using leaflet, showing polygons with popup information.
plot_zones_interactive( polygons, coastline, title, colors, show_legend = TRUE, labels = NULL, base_layers = TRUE, minimap = TRUE )plot_zones_interactive( polygons, coastline, title, colors, show_legend = TRUE, labels = NULL, base_layers = TRUE, minimap = TRUE )
polygons |
List of polygons. Each must have fields such as coords, announcement, dates and coordinates. |
coastline |
Data frame with the coastline (columns Long and Lat). |
title |
Title to display at the top of the map. |
colors |
Vector of colors. If NULL, they are automatically assigned with RColorBrewer::brewer.pal. |
show_legend |
Logical. If TRUE, the layers control (legend) is displayed. |
labels |
Optional vector of names to display in the legend and map labels. |
base_layers |
Logical. If TRUE, includes base layers such as satellite and ocean maps. |
minimap |
Logical. If TRUE, displays a minimap in the lower right corner. |
A leaflet object with the interactive map.
Creates a static plot using ggplot2 that displays geographic polygons on a coastline base. Colors are assigned by groups (announcements/labels), not individual polygons.
plot_zones_static( polygons, coastline, title, colors, show_legend = TRUE, name_legend = NULL, labels = NULL, add_grid = TRUE, theme = ggplot2::theme_minimal() )plot_zones_static( polygons, coastline, title, colors, show_legend = TRUE, name_legend = NULL, labels = NULL, add_grid = TRUE, theme = ggplot2::theme_minimal() )
polygons |
List of polygons. Each polygon must contain a coords matrix with longitude and latitude columns. |
coastline |
Data frame with the coastline, with columns Long and Lat. |
title |
Main title of the plot. |
colors |
Vector of colors to fill the polygons. If NULL, colors are automatically assigned by groups. |
show_legend |
Logical. If TRUE, the legend is displayed. |
name_legend |
Name of the legend (optional). If NULL, legend has no title. |
labels |
Vector of labels for the polygons (optional). |
add_grid |
Logical. If TRUE, adds a geographic grid to the plot. |
theme |
ggplot2 theme to use. |
A ggplot object ready to be plotted.
Helper function to process data and prepare polygons using preexisting parallel lines.
prepare_polygons( data, coastline, coast_parallels = NULL, column_names = c("lat", "lon", "dc") )prepare_polygons( data, coastline, coast_parallels = NULL, column_names = c("lat", "lon", "dc") )
data |
Data frame with coordinates. |
coastline |
Data frame with coastline. |
coast_parallels |
List of data frames with lines parallel to the coast. |
column_names |
Vector with column names in coast_parallels data frames. |
List of polygons for visualization.
Processes fishing trip data from PRODUCE logbooks. Automatically detects required columns and creates standardized output with proper date conversion.
process_fishing_trips(data_fishing_trips, verbose = FALSE)process_fishing_trips(data_fishing_trips, verbose = FALSE)
data_fishing_trips |
Data frame with raw fishing trip data. |
verbose |
Logical. Print column mapping information. |
Data frame with 6 standardized columns including trip code, vessel information, and trip dates.
fishing_trips <- process_fishing_trips(data_fishing_trips = faenas_bitacora) fishing_trips <- process_fishing_trips(data_fishing_trips = faenas_bitacora, verbose = TRUE)fishing_trips <- process_fishing_trips(data_fishing_trips = faenas_bitacora) fishing_trips <- process_fishing_trips(data_fishing_trips = faenas_bitacora, verbose = TRUE)
Processes fishing haul data from PRODUCE logbooks. Automatically detects required columns and creates standardized output with coordinates converted to decimal degrees.
process_hauls(data_hauls, correct_coordinates = TRUE, verbose = FALSE)process_hauls(data_hauls, correct_coordinates = TRUE, verbose = FALSE)
data_hauls |
Data frame with raw haul data. |
correct_coordinates |
Logical. Correct coordinate errors during conversion. |
verbose |
Logical. Print column mapping information. |
Data frame with 16 standardized columns including fishing trip code, haul number, dates, coordinates, species, and catch data.
processed_hauls <- process_hauls(data_hauls = calas_bitacora) processed_hauls <- process_hauls(data_hauls = calas_bitacora, verbose = TRUE)processed_hauls <- process_hauls(data_hauls = calas_bitacora) processed_hauls <- process_hauls(data_hauls = calas_bitacora, verbose = TRUE)
Processes length data from PRODUCE logbooks. Automatically detects required columns and transforms from long to wide format.
process_length(data_length, verbose = FALSE)process_length(data_length, verbose = FALSE)
data_length |
Data frame with raw length data. |
verbose |
Logical. Print column mapping information. |
Data frame with length by haul in wide format with individual columns for each length class.
length_data <- process_length(data_length = tallas_bitacora) length_data <- process_length(data_length = tallas_bitacora, verbose = TRUE)length_data <- process_length(data_length = tallas_bitacora) length_data <- process_length(data_length = tallas_bitacora, verbose = TRUE)
Calculates juvenile percentages by specified groups, both in number and weight. Uses modern dplyr approach for efficient processing. Can auto-detect length columns if not specified.
summarize_juveniles_by_group( data, group_cols, length_cols = NULL, juvenile_limit = 12, a = 0.0012, b = 3.1242, remove_empty = TRUE, verbose = FALSE )summarize_juveniles_by_group( data, group_cols, length_cols = NULL, juvenile_limit = 12, a = 0.0012, b = 3.1242, remove_empty = TRUE, verbose = FALSE )
data |
Data frame with length frequency data. |
group_cols |
Vector of column names for grouping. |
length_cols |
Vector of length column names or indices. If NULL, auto-detection is attempted. |
juvenile_limit |
Length threshold for juveniles. |
a |
Coefficient of length-weight relationship. |
b |
Exponent of length-weight relationship. |
remove_empty |
Logical. Remove groups with no data. |
verbose |
Logical. Print information about detected columns. |
Data frame with juvenile statistics by group.
## Not run: juvenile_summary <- summarize_juveniles_by_group( data = fishery_data, group_cols = "date", juvenile_limit = 12 ) ## End(Not run)## Not run: juvenile_summary <- summarize_juveniles_by_group( data = fishery_data, group_cols = "date", juvenile_limit = 12 ) ## End(Not run)
Dataset containing information about lengths of marine species captured along the Peruvian littoral.
tallas_bitacoratallas_bitacora
A data.frame with sample data of lengths sampled from hauls made by vessels in the Peruvian sea.
Indicate the data source
data(tallas_bitacora)data(tallas_bitacora)
Validates data quality metrics for processed fishing trip data.
validate_fishing_trip_data(processed_trips)validate_fishing_trip_data(processed_trips)
processed_trips |
Data frame returned by process_fishing_trips(). |
List with data quality metrics including completeness scores and issue counts.
Validates data quality metrics for processed haul data.
validate_haul_data(processed_hauls)validate_haul_data(processed_hauls)
processed_hauls |
Data frame returned by process_hauls(). |
List with data quality metrics including completeness scores and issue counts.
Validates data quality metrics for processed length data.
validate_length_data(processed_length)validate_length_data(processed_length)
processed_length |
Data frame returned by process_length(). |
List with data quality metrics including completeness scores and distribution statistics.
Validates that a data frame contains the necessary columns for creating fishing zone polygons. Checks for either coordinate-based or distance-based polygon definition data.
validate_polygon_data(data)validate_polygon_data(data)
data |
Data frame to validate. Must contain polygon definition columns. |
The function requires either:
Coordinate-based: StartLatitude, EndLatitude, StartLongitude, EndLongitude
Distance-based: StartLatitude, EndLatitude, StartNauticalMiles, EndNauticalMiles
Returns TRUE invisibly if validation passes, otherwise throws an error.
# Coordinate-based polygon data coord_data <- data.frame( StartLatitude = "15 30 S", EndLatitude = "15 45 S", StartLongitude = "75 30 W", EndLongitude = "75 45 W" ) validate_polygon_data(coord_data) # Distance-based polygon data distance_data <- data.frame( StartLatitude = "15 30 S", EndLatitude = "15 45 S", StartNauticalMiles = 5, EndNauticalMiles = 15 ) validate_polygon_data(distance_data)# Coordinate-based polygon data coord_data <- data.frame( StartLatitude = "15 30 S", EndLatitude = "15 45 S", StartLongitude = "75 30 W", EndLongitude = "75 45 W" ) validate_polygon_data(coord_data) # Distance-based polygon data distance_data <- data.frame( StartLatitude = "15 30 S", EndLatitude = "15 45 S", StartNauticalMiles = 5, EndNauticalMiles = 15 ) validate_polygon_data(distance_data)
Scales observed length frequencies based on total recorded catch using length-weight relationship.
weight_by_catch(frequency, catch, length, a, b, silence_warnings = FALSE)weight_by_catch(frequency, catch, length, a, b, silence_warnings = FALSE)
frequency |
Numeric vector of observed length frequencies. |
catch |
Total catch amount (in kg or tons). |
length |
Numeric vector of lengths corresponding to frequencies. |
a |
Coefficient of the length-weight relationship. |
b |
Exponent of the length-weight relationship. |
silence_warnings |
Logical. Suppress warning messages. |
Catch weighting is used to estimate the size composition of catches when only sub-samples are measured for length frequency analysis.
Numeric vector of weighted frequencies.
IMARPE (2020). Protocolo Elaboración de la Tabla de Decisión para la determinación del Límite Máximo Total Permisible por temporada de pesca en la pesquería del stock norte-centro de la anchoveta peruana. IMP-DGIRP/AFDPERP, Edición: 05, Revisión 00, 40p.