Vignette_v2

library(filteRjsats)
# Choose a Directory 
path <- system.file("extdata", package = "filteRjsats")

# List Files in Directory
file <- list.files(path = path, recursive = TRUE)
# Get a list of Time Zones
# Not Run
# OlsonNames()

# Set Time Zone
timezone <- "America/Los_Angeles"
# Empty list to store dataframes
det_list <- list()

# Process each file in the list of files
for(i in 1:length(file)){
jsats_file <- read_jsats(path, file[i])
det_list[[i]] <- jsats_file
}
#> Warning in scan(file = file, what = what, sep = sep, quote = quote, dec = dec,
#> : embedded nul(s) found in input
#> Warning: Expected 13 pieces. Additional pieces discarded in 1000 rows [1, 2, 3, 4, 5, 6,
#> 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
# Get a list of reference tags
reference_tags <- get_reference_tags()
# Empty list to store dataframes
pref_list <- list()

# Apply prefilter
for(i in 1:length(det_list)){
prefilter_file <- prefilter(det_list[[i]], reference_tags)
pref_list[[i]] <- prefilter_file
}
# View all the fish fields
get_fish_fields()
#>                      variable_name data_type       actual_range
#> 1                            email    String                   
#> 2                 fish_date_tagged    String                   
#> 3                          fish_id    String                   
#> 4                      fish_length       int                   
#> 5                 fish_length_type    String                   
#> 6                      fish_origin    String                   
#> 7                fish_release_date    String                   
#> 8                        fish_type    String                   
#> 9                      fish_weight     float                   
#> 10                release_latitude     float    36.843, 40.9674
#> 11                release_location    String                   
#> 12               release_longitude     float -123.039, -119.933
#> 13                release_river_km     float                   
#> 14                        study_id    String                   
#> 15                  tag_id_decimal       int                   
#> 16                      tag_id_hex    String                   
#> 17                       tag_model    String                   
#> 18 tag_pulse_rate_interval_nominal     float                   
#> 19               tag_warranty_life     float                   
#> 20                      tag_weight     float

# NOT RUN
# Choose important fields if don't want all fields, shown are the minimum
# important_fields <- c("fish_type","tag_id_hex",
#                       "fish_release_date", "release_location",
#                       "release_latitude", "release_longitude",
#                       "tag_pulse_rate_interval_nominal",
#                       "tag_warranty_life", "fish_length_type",
#                       "fish_length","fish_weight")

# Query ERDAPP for all tagged fish
fish <- get_tagged_fish()
# Empty list to store dataframes
fish_list <- list()

# Join fish data to detection and filter based on release date and battery
for(i in 1:length(pref_list)){
fish_file <- add_fish(pref_list[[i]], fish)
fish_list[[i]] <- fish_file
}
#> Detections in File: 996
#> Number of Valid Tag IDs: 1
#> Number of Valid Detections: 967
#> Detections in File: 941
#> Number of Valid Tag IDs: 5
#> Number of Valid Detections: 941
# Empty list to store dataframes
final_list <- list()

# Apply the final 2 hit or 4 hit filter
for(i in 1:length(fish_list)){
final_filter <- second_filter_2h4h(fish_list[[i]])
final_list[[i]] <- final_filter
}
#> Number of Valid Tag IDs: 1
#> Number of Valid Detections: 959
#> Number of Tags with Spurious Detections: 1
#> Warning: Unknown or uninitialised column: `TagHex`.
#> Tags with Only Spurious Detections:
#> Number of Spurious Detections: 8
#> Number of Valid Tag IDs: 4
#> Number of Valid Detections: 865
#> Number of Tags with Spurious Detections: 5
#> Warning: Unknown or uninitialised column: `TagHex`.
#> Tags with Only Spurious Detections:
#> Number of Spurious Detections: 76

# NOT RUN
# Alternately apply a 4 hit filter
# for(i in 1:length(fish_list)){
# final_filter <- second_filter_4h(fish_list[[i]])
# final_list[[i]] <- final_filter
# }
# View all the receiver metadata fields
get_rcvr_fields()
#>                 variable_name data_type       actual_range
#> 1                      dep_id       int            1, 4761
#> 2                    latitude     float   36.7735, 40.7988
#> 3                   longitude     float -123.039, -119.769
#> 4             receiver_agency    String                   
#> 5      receiver_beacon_id_dec    String                   
#> 6      receiver_beacon_id_hex    String                   
#> 7         receiver_beacon_pri     float                   
#> 8   receiver_coverage_problem    String                   
#> 9      receiver_data_coverage    String                   
#> 10             receiver_depth     float                   
#> 11               receiver_end    String                   
#> 12  receiver_general_latitude     float                   
#> 13  receiver_general_location    String                   
#> 14 receiver_general_longitude     float                   
#> 15  receiver_general_river_km     float                   
#> 16        receiver_last_valid    String                   
#> 17          receiver_location    String                   
#> 18              receiver_make    String                   
#> 19            receiver_region    String                   
#> 20          receiver_river_km     float                   
#> 21     receiver_serial_number       int                   
#> 22             receiver_start    String

# NOT RUN
# # Choose important fields if don't want all fields, shown are the minimum
# rcvr_fields <- c("dep_id","receiver_serial_number","latitude","longitude",
#                  "receiver_location","receiver_river_km",
#                  "receiver_general_location","receiver_general_river_km",
#                  "receiver_beacon_id_hex", "receiver_start",
#                  "receiver_end")

#Get the receiver metadata
rcvr_data <- get_rcvr_data()

#Join the receiver metadata to the filtered detections
for(i in 1:length(final_list)){
  out <- join_rcvr_data(final_list[[i]], rcvr_data)
  final_list[[i]]
}

print(final_list[[1]])
#> # A tibble: 959 × 47
#> # Groups:   Tag_Hex [1]
#>    ReceiverSN Make  DateTime_Local      Tag_Decimal Tag_Hex  Tilt  Volt  Temp
#>    <chr>      <chr> <dttm>                    <int> <chr>   <dbl> <dbl> <dbl>
#>  1 17111      ATS   2021-06-20 00:00:02       50760 C648       41  4.15  26.0
#>  2 17111      ATS   2021-06-20 00:00:05       50760 C648       41  4.16  26.0
#>  3 17111      ATS   2021-06-20 00:00:08       50760 C648       41  4.16  26.0
#>  4 17111      ATS   2021-06-20 00:00:11       50760 C648       41  4.16  26.0
#>  5 17111      ATS   2021-06-20 00:00:14       50760 C648       41  4.16  26.0
#>  6 17111      ATS   2021-06-20 00:00:17       50760 C648       41  4.15  26.0
#>  7 17111      ATS   2021-06-20 00:00:20       50760 C648       41  4.15  26.0
#>  8 17111      ATS   2021-06-20 00:00:23       50760 C648       41  4.15  26.0
#>  9 17111      ATS   2021-06-20 00:00:26       50760 C648       41  4.15  26.0
#> 10 17111      ATS   2021-06-20 00:00:28       50760 C648       41  4.15  26.0
#> # ℹ 949 more rows
#> # ℹ 39 more variables: SigStr <dbl>, Freq <dbl>, Thres <dbl>, CheckMBP <lgl>,
#> #   TagInFile <lgl>, fish_id <chr>, study_id <chr>, fish_type <chr>,
#> #   fish_origin <chr>, fish_date_tagged <chr>, fish_release_date <dttm>,
#> #   tag_id_decimal <int>, tag_weight <chr>, tag_model <chr>,
#> #   tag_pulse_rate_interval_nominal <chr>, tag_warranty_life <chr>,
#> #   fish_length_type <chr>, fish_length <chr>, fish_weight <chr>, …
print(final_list[[2]])
#> # A tibble: 865 × 45
#> # Groups:   Tag_Hex [4]
#>    ReceiverSN Make  DateTime_Local      Tag_Decimal Tag_Hex  Volt SigStr  Freq
#>    <chr>      <chr> <dttm>                    <int> <chr>   <dbl>  <dbl> <dbl>
#>  1 156007     Tekno 2021-07-05 08:39:29       28477 6F3D     3.71   25.5  417.
#>  2 156007     Tekno 2021-07-05 08:39:32       28477 6F3D     3.71   27.5  417.
#>  3 156007     Tekno 2021-07-05 08:39:35       28477 6F3D     3.71   15.4  417.
#>  4 156007     Tekno 2021-07-05 08:39:38       28477 6F3D     3.71   26.9  417.
#>  5 156007     Tekno 2021-07-05 08:39:41       28477 6F3D     3.71   23.3  417.
#>  6 156007     Tekno 2021-07-05 08:39:43       28477 6F3D     3.71   26.3  417.
#>  7 156007     Tekno 2021-07-05 08:39:49       28477 6F3D     3.71   20.5  417.
#>  8 156007     Tekno 2021-07-05 08:39:52       28477 6F3D     3.71   22.6  417.
#>  9 156007     Tekno 2021-07-05 08:39:55       28477 6F3D     3.71   20.7  417.
#> 10 156007     Tekno 2021-07-05 08:40:01       28477 6F3D     3.71   25.9  417.
#> # ℹ 855 more rows
#> # ℹ 37 more variables: Thres <int>, CheckMBP <lgl>, TagInFile <lgl>,
#> #   fish_id <chr>, study_id <chr>, fish_type <chr>, fish_origin <chr>,
#> #   fish_date_tagged <chr>, fish_release_date <dttm>, tag_id_decimal <int>,
#> #   tag_weight <chr>, tag_model <chr>, tag_pulse_rate_interval_nominal <chr>,
#> #   tag_warranty_life <chr>, fish_length_type <chr>, fish_length <chr>,
#> #   fish_weight <chr>, release_location <chr>, release_latitude <dbl>, …