codama R package

website·Indexed 30 days ago

https://ob7-ird.github.io/codama/index.html

An 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.

Tokens
39.1K
Snippets
126
Records
271
Agent score
64%

What's inside codama

  1. 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.
  2. Identify inconsistencies between floating objects and observed systems

    The 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")
    )
  3. Identify inconsistencies between sampling activity and well plan trip numbers

    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_id
    • sample_well
    • activity_id
    • trip_id
    • wellactivity_id
    • well_label
    • vesseltype_code
    logbook_well_number_control(
      dataframe1,
      dataframe2,
      dataframe3,
      output,
      vessel_type = c("5", "6", "10")
    )
  4. Install codama R package from GitHub

    Install the current version of the codama package using devtools. The --no-multiarch option is used during installation.
    devtools::install_github("https://github.com/OB7-IRD/codama",
                             INSTALL_opts=c("--no-multiarch"))
  5. Example: Detect conflicts between vessel activity and object operations

    This example demonstrates how to identify conflicts where 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 operation
  6. Example: Detecting harbour inconsistencies in trip data

    This example demonstrates how to use logbook_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")
  7. Example: Detecting temporal inconsistencies in logbook data

    This example demonstrates how to use 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")
  8. Example usage of marine_area_overlay_control

    This example demonstrates how to run a control check on marine area overlays using a set of coordinates and an ICES statistical rectangle RData file, requesting a detailed report as output.
    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"
    )
  9. Identify time inconsistencies for operations on the same buoy

    The 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)
  10. Example: Detect missing buoys in vessel activity logs

    This example demonstrates how to use the function to identify floating objects that are missing required buoys based on their operation and activity codes.
    # 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")
  11. Example: Detecting subsample numbering errors with logbook_super_sample_number_control

    This example demonstrates how to use 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")