Skip to contents

Example Script Using R Package GAPsurvey

Last updated April 2024

Open Rstudio script example_script.R. This should already be located on desktop, otherwise find it using the link below.

system.file("r/example_script.R", package = "GAPsurvey")
#> [1] "C:/Users/sean.rohan/AppData/Local/Temp/RtmpWSLcfB/temp_libpath15cc58f34baf/GAPsurvey/r/example_script.R"

Install R package

Rerun this only when there is a new version of the package to install. The user may install from GitHub:

devtools::install_github("afsc-gap-products/GAPsurvey")

or install from local file .tar.gz:

# example, the user may have a different path
install.packages('C:/Users/User/Downloads/GAPsurvey_2023.04.04.tar.gz',
                 repos=NULL, type='source')

Load libraries

Now we can use functions from GAPSurvey!

What have we historically caught at this station?

Learn more about and find examples using…

?get_catch_haul_history
get_catch_haul_history(
  years = 2021:2023, # optional; if you only want to see a specific year, not the last 10
  species_codes = c(21720, 21740), # optional; pacific cod and walleye pollock ONLY
  survey = "EBS", # for example
  station = "I-13") # for example
#> $catch
#> $catch$`2021`
#>   station     scientific_name     common_name count weight_kg cpue_kgkm2
#> 5    I-13 Gadus chalcogrammus walleye pollock   793   550.359 11529.7821
#> 6    I-13 Gadus macrocephalus     Pacific cod    91    31.140   652.3695
#>   cpue_nokm2
#> 5   16613.01
#> 6    1906.41
#> 
#> $catch$`2022`
#>   station     scientific_name     common_name count weight_kg cpue_kgkm2
#> 3    I-13 Gadus chalcogrammus walleye pollock   135   140.138   3252.886
#> 4    I-13 Gadus macrocephalus     Pacific cod   173   104.016   2414.421
#>   cpue_nokm2
#> 3   3133.623
#> 4   4015.679
#> 
#> $catch$`2023`
#>   station     scientific_name     common_name count weight_kg cpue_kgkm2
#> 1    I-13 Gadus chalcogrammus walleye pollock    70    41.744    898.023
#> 2    I-13 Gadus macrocephalus     Pacific cod    31     9.190    197.701
#>   cpue_nokm2
#> 1  1505.8837
#> 2   666.8913
#> 
#> 
#> $catch_means
#>       scientific_name     common_name station count weight_kg cpue_kgkm2
#> 1 Gadus chalcogrammus walleye pollock    I-13 332.7    244.08    5226.90
#> 2 Gadus macrocephalus     Pacific cod    I-13  98.3     48.12    1088.16
#>   cpue_nokm2 Freq
#> 1    7084.17    3
#> 2    2196.33    3
#> 
#> $haul
#>   year station haul stratum        vessel_name           date_time
#> 1 2021    I-13    7      31      ALASKA KNIGHT 2021-06-02 12:05:29
#> 2 2022    I-13   12      31        VESTERAALEN 2022-06-01 16:20:20
#> 3 2023    I-13   16      31 NORTHWEST EXPLORER 2023-05-30 13:43:02
#>   latitude_dd_start longitude_dd_start bottom_temperature_c
#> 1          57.65493          -160.2535                  4.4
#> 2          57.65502          -160.2754                  3.6
#> 3          57.66505          -160.2725                  3.4
#>   surface_temperature_c depth_m distance_fished_km net_width_m net_height_m
#> 1                   4.7      55              2.954      16.159        1.794
#> 2                   7.6      54              2.854      15.095        2.566
#> 3                   3.4      55              2.879      16.146        2.175
#>   area_swept_km2 duration_hr total_weight_kg
#> 1       0.047734       0.522            1220
#> 2       0.043081       0.531            1190
#> 3       0.046484       0.516             812

What time is sunrise and sunset?

Learn more about and find examples using…

?get_sunrise_sunset
get_sunrise_sunset(chosen_date = "2024-06-10",
                   survey = "AI",
                   station = "33-47")
#> Using survey station (AI 33-47) centroid location information (lat = 53.013, lon = 172.407) to calculate sunrise and sunset.
#> Sunrise is at 2024-06-10 08:04:00 AKDT
#> Sunset is at 2024-06-10 00:54:00 AKDT

get_sunrise_sunset(chosen_date = Sys.Date(),
                   survey = "GOA",
                   station = "323-176")
#> Using survey station (GOA 323-176) centroid location information (lat = 60.052, lon = -143.311) to calculate sunrise and sunset.
#> Sunrise is at 2024-04-06 06:41:00 AKDT
#> Sunset is at 2024-04-05 20:29:00 AKDT

get_sunrise_sunset(chosen_date = "2024-08-04",
                   survey = "EBS",
                   station = "P-31")
#> Using survey station (EBS P-31) centroid location information (lat = 60, lon = -177.356) to calculate sunrise and sunset.
#> Sunrise is at 2024-08-04 07:38:00 AKDT
#> Sunset is at 2024-08-04 00:12:00 AKDT

get_sunrise_sunset(chosen_date = "2024-06-04",
                   survey = "NBS",
                   station = "ZZ-01")
#> Using survey station (NBS ZZ-01) centroid location information (lat = 63.334, lon = -168.244) to calculate sunrise and sunset.
#> Sunrise is at 2024-06-04 05:14:00 AKDT
#> Sunset is at 2024-06-04 01:08:00 AKDT

get_sunrise_sunset(chosen_date = "2024-08-04",
                   survey = NULL,
                   latitude = 60,
                   longitude = -162)
#> Using latitude and longitude to calcualte sunrise and sunset.
#> Sunrise is at 2024-08-04 06:37:00 AKDT
#> Sunset is at 2024-08-03 23:10:00 AKDT

Convert CTD data to BTD as a backup for SBE39 (aka ‘the BT’)

?convert_ctd_btd
convert_ctd_btd(
  filepath_hex = system.file(paste0("exdata/convert_ctd_btd/",
                                    "SBE19plus_01908106_2023_06_18_0001.hex"),
                             package = "GAPsurvey"),
  filepath_xmlcon = system.file(paste0("exdata/convert_ctd_btd/",
                                       "SBE19plusV2_8106_ph_DO_leg2.xmlcon"),
                                package = "GAPsurvey"),
  VESSEL = 162,
  CRUISE = 202301,
  HAUL = 97,
  latitude = 59.01693, # Approximate - for depth estimation
  MODEL_NUMBER = "",
  VERSION_NUMBER = "",
  SERIAL_NUMBER = 8106)