Overview of the codama R package
The codama package provides a series of standardized and generic control processes designed for data quality assessment and monitoring. It is open-source (GPL version 3) and hosted on GitHub.
website·Indexed 30 days ago
https://ob7-ird.github.io/codama/index.htmlAn R package providing a suite of data control and correction functions for fisheries data, including tools for weight null correction, sex and size distribution control, and vessel activity validation. Version 1.4.10.
codama package provides a series of standardized and generic control processes designed for data quality assessment and monitoring.logbook_observed_system_floatting_object_pair_control function checks for incoherence in vessel activity data. Specifically, it verifies that if a vessel activity (defined by vessel_activity code) contains a floating object, it must also have an associated observer system (defined by observed_system code), and vice versa.logbook_observed_system_floatting_object_pair_control(
dataframe1,
dataframe2,
dataframe3,
output,
vessel_activity = c("6"),
observed_system = c("20")
)Use the logbook_well_number_control function to detect discrepancies between sample well numbers and associated trip well numbers. The function requires three data frames (typically CSVs or outputs from data_extraction) and an output format specification.
To function correctly, the input data frames must collectively contain the following columns:
sampleactivity_idsample_wellactivity_idtrip_idwellactivity_idwell_labelvesseltype_codelogbook_well_number_control(
dataframe1,
dataframe2,
dataframe3,
output,
vessel_type = c("5", "6", "10")
)devtools. The --no-multiarch option is used during installation.devtools::install_github("https://github.com/OB7-IRD/codama",
INSTALL_opts=c("--no-multiarch"))vesselactivity_code '6' is incompatible with objectoperation_code '1'.# dataframe1 contains activity IDs and vessel activity codes
dataframe1 <- data.frame(
activity_id = c("1", "2", "3", "4", "5"),
vesselactivity_code = c("6", "1", "6", NA, "6")
)
# dataframe2 contains object IDs, operation codes, and activity IDs
dataframe2 <- data.frame(
floatingobject_id = c("1", "2", "3", "4"),
objectoperation_code = c("2", "1", "1", NA),
activity_id = c("1", "2", "3", "5")
)
# Generate a report of inconsistencies
logbook_vessel_activity_object_operation_control(dataframe1, dataframe2, output = "report")
# Expected Output:
# activity_id vesselactivity_code logical
# 1 1 6 TRUE
# 2 2 1 TRUE
# 3 3 6 FALSE <-- Conflict: Activity 6 vs Operation 1
# 4 4 <NA> FALSE <-- Missing activity
# 5 5 6 FALSE <-- Missing operationlogbook_harbour_control with a report output to identify trips where the departure harbour does not match the previous trip's landing harbour.# Setup sample data
# Trip 1 and 2 are consistent
# Trip 3 has a different harbour
# Trip 4 has no departure harbour
# Trip 5 has no previous landing harbour
dataframe1 <- data.frame(
trip_id = c("1", "2", "3", "4", "5"),
harbour_id_departure = c("1", "2", "3", NA, "1"),
harbour_label_departure = c("Harbour_1", "Harbour_2", "Harbour_3", NA, "Harbour_1"),
trip_previous_id = c(NA, "1", "2", NA, "6"),
harbour_id_landing_trip_previous = c(NA, "2", "2", NA, NA),
harbour_label_landing_trip_previous = c(NA, "Harbour_2", "Harbour_2", NA, NA)
)
# Generate the inconsistency report
logbook_harbour_control(dataframe1, output = "report")logbook_temporal_limit_control to find errors such as extra days, missing start/end dates, and double-counted activity days.# Trip data with various inconsistencies
dataframe1 <- data.frame(
trip_id = c("1", "2", "3", "4", "5", "6", "7"),
trip_startdate = as.Date(c("2020/01/01", "2020/01/01", NA, "2020/01/24", "2020/02/01", "2020/02/13", "2020/03/10")),
trip_enddate = as.Date(c("2020/01/02", "2020/01/02", "2020/01/24", NA, "2020/02/03", "2020/02/14", "2020/03/11"))
)
# Activity data
dataframe2 <- data.frame(
route_id = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14"),
activity_date = as.Date(c("2020/01/01", "2020/01/02", "2020/01/01", "2020/01/02", "2020/01/03", "2020/01/24", "2020/01/24", "2020/02/01", "2020/02/03", "2020/02/13", "2020/02/13", "2020/02/14", "2020/03/10", "2020/03/11")),
trip_id = c("1", "1", "2", "2", "2", "3", "4", "5", "5", "6", "6", "6", "7", "7")
)
# Activity IDs
dataframe3 <- data.frame(
activity_id = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14"),
route_id = c("1", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13")
)
# Generate a detailed report of inconsistencies
logbook_temporal_limit_control(dataframe1, dataframe2, dataframe3, output = "report")marine_area_overlay_control(
data_longitude = as.character(c(1.09, 8.37, 19.35, -4.04, -4.54)),
data_latitude = as.character(c(2.47, -3.19, 24.55, 5.22, 49.73)),
overlay_expected = "ices_area",
area_file_path = "ICES_Statistical_Rectangles_Eco.RData",
output = "report"
)logbook_buoy_time_control function detects inconsistencies in the time elapsed between operations on the same floating object (buoy). It compares two dataframes to find operations that occur within a specified time threshold.logbook_buoy_time_control(dataframe1, dataframe2, output, threshold_time = 60)# dataframe1: Floating object and operation mapping
dataframe1 <- data.frame(floatingobject_id = c("1", "2", "3", "4", "5", "6"),
objectoperation_code = c("1", "1", "2", "1", "1", "1"),
activity_id = c("1", "2", "3", "4", "4", "5"))
# dataframe2: Activity and vessel activity codes
dataframe2 <- data.frame(activity_id = c("1", "2", "3", "4", "5"),
vesselactivity_code = c("13", "1", "13", "13", NA))
# dataframe3: Buoy transmission mapping
dataframe3 <- data.frame(transmittingbuoy_id = c("1", "2"),
floatingobject_id = c("1", "4"))
# Generate a report of inconsistencies
logbook_vessel_activity_floating_object_missing_buoy_control(dataframe1,
dataframe2,
dataframe3,
output = "report")logbook_super_sample_number_control to find errors such as non-super samples starting at 1 instead of 0, super samples with duplicate sub-sample numbers, or discontinuous numbering.# Define sample metadata
dataframe1 <- data.frame(
sample_id = c("1", "2", "3", "4", "5", "6", "7", "8"),
sample_supersample = c(FALSE, TRUE, FALSE, TRUE, FALSE, TRUE, TRUE, TRUE)
)
# Define species/subsample metadata
dataframe2 <- data.frame(
samplespecies_id = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13"),
samplespecies_subsamplenumber = c(0, 0, 1, 1, 2, 1, 1, 1, 0, 1, 1, 1, 3),
sample_id = c("1", "1", "2", "2", "2", "3", "4", "4", "6", "6", "7", "8", "8")
)
# Generate a detailed report of inconsistencies
logbook_super_sample_number_control(dataframe1, dataframe2, output = "report")