diff --git a/.gitignore b/.gitignore index 12144d5..5403a7d 100644 --- a/.gitignore +++ b/.gitignore @@ -25,4 +25,5 @@ public/data/**/*.csv public/data/**/*.json .Rproj.user -dev/ \ No newline at end of file +dev/ +*.tar.gz diff --git a/r/R/external.R b/r/R/external.R index 7cc5056..516ee27 100644 --- a/r/R/external.R +++ b/r/R/external.R @@ -17,7 +17,18 @@ tar_option_set(packages = c( targets_external <- list( tar_target(external_dir, "data/external", format = "file", cue = tar_cue("always")), tar_target(external_db_tables_file, file.path(external_dir, "db-tables.rds"), format = "file"), - tar_target(external_db_tables, read_rds(external_db_tables_file)), + tar_target(external_db_tables, { + x <- read_rds(external_db_tables_file) + swfsc_bw_species_codes <- c("BWBB", "BWMS", "BWMC", "BW43", "BWC", "NBHF") + stopifnot(!any(swfsc_bw_species_codes %in% x$species$SPECIES_CODE)) + + # add beaked species from SWFSC + x$species <- x$species %>% + bind_rows( + tibble(SPECIES_CODE = swfsc_bw_species_codes) + ) + x + }), tar_target(external_submission_groups, { tibble( id = setdiff(list.dirs(external_dir, recursive = FALSE, full.names = FALSE), c("_queue", "_archive")) @@ -34,28 +45,45 @@ targets_external <- list( tibble( id = external_submission_groups$id, metadata = list(x$metadata), - detectiondata = list(x$detectiondata) + detectiondata = list(x$detectiondata), + gpsdata = list(x$gpsdata) ) }, pattern = map(external_submission_groups) ), tar_target(external_submissions_merge, external_submission_branches, iteration = "vector"), tar_target(external_submissions, { - rules <- load_external_rules()$detectiondata + detectiondata_rules <- load_external_rules()$detectiondata + gpsdata_rules <- load_external_rules()$gpsdata codes <- load_codes(external_db_tables) codes[["UNIQUE_ID"]] <- unique(external_metadata$UNIQUE_ID) external_submissions_merge %>% rowwise() %>% mutate( detectiondata = list({ - print(detectiondata) out <- tibble() if (nrow(detectiondata) > 0) { out <- detectiondata %>% rowwise() %>% mutate( validation = list({ - validate_data(joined, rules, codes) + validate_data(joined, detectiondata_rules, codes) + }), + validation_errors = list(extract_validation_errors(validation)), + n_errors = nrow(validation_errors) + ) %>% + ungroup() + } + out + }), + gpsdata = list({ + out <- tibble() + if (nrow(gpsdata) > 0) { + out <- gpsdata %>% + rowwise() %>% + mutate( + validation = list({ + validate_data(joined, gpsdata_rules, codes) }), validation_errors = list(extract_validation_errors(validation)), n_errors = nrow(validation_errors) @@ -94,6 +122,20 @@ targets_external <- list( select(id, filename, validation_errors) %>% unnest(validation_errors) }), + tar_target(external_gpsdata, { + external_submissions %>% + select(gpsdata) %>% + unnest(gpsdata) %>% + select(id, filename, parsed) %>% + unnest(parsed) + }), + tar_target(external_gpsdata_errors, { + external_submissions %>% + select(gpsdata) %>% + unnest(gpsdata) %>% + select(id, filename, validation_errors) %>% + unnest(validation_errors) + }), tar_target(themes_species, { tribble( ~theme, ~species_code, @@ -110,9 +152,16 @@ targets_external <- list( "beaked", "MEME", "beaked", "SOBW", "beaked", "NBWH", + "beaked", "BWBB", + "beaked", "BWMS", + "beaked", "BWMC", + "beaked", "BW43", + "beaked", "BWC", "kogia", "UNKO", + "nbhf", "NBHF", + "dolphin", "UNDO", "risso", "GRAM", @@ -122,11 +171,46 @@ targets_external <- list( "harbor", "HAPO" ) }), + tar_target(external_tracks, { + x <- external_gpsdata %>% + select(UNIQUE_ID, DATETIME, LATITUDE, LONGITUDE) %>% + clean_names() %>% + arrange(unique_id, datetime) %>% + group_by(unique_id, datetime = floor_date(datetime, "hour")) %>% + slice_head(n = 1) %>% + ungroup() + + sf_points <- x %>% + st_as_sf(coords = c("longitude", "latitude"), crs = 4326) + + sf_points %>% + group_by(unique_id) %>% + summarise( + start = min(datetime), + end = max(datetime), + do_union = FALSE, + .groups = "drop" + ) %>% + st_cast("LINESTRING") + }), tar_target(external_analyses, { - x <- external_detectiondata %>% + x_detections <- external_detectiondata %>% select(-id, -filename, -row) %>% - clean_names() %>% + clean_names() + x_calltypes <- x_detections %>% + distinct(unique_id, species_code, call_type_code) %>% + group_by(unique_id, species_code) %>% + summarise( + # n = n(), + call_type_code = str_c(call_type_code, collapse = ", "), + .groups = "drop" + ) + x_analyses <- x_detections %>% + select(-call_type_code) %>% + left_join(x_calltypes, by = c("unique_id", "species_code")) %>% + inner_join(themes_species, by = "species_code") %>% nest_by( + theme, unique_id, species_code, call_type_code, @@ -139,13 +223,12 @@ targets_external <- list( max_analysis_frequency_range_hz, analysis_sampling_rate_hz ) %>% - ungroup() %>% - left_join(themes_species, by = "species_code") + ungroup() stopifnot( - all(count(x, unique_id, species_code)$n == 1), - all(!is.na(x$theme)) + all(count(x_analyses, unique_id, species_code)$n == 1), + all(!is.na(x_analyses$theme)) ) - x + x_analyses }), tar_target(external_deployments, { # deployments with no detection results @@ -163,16 +246,31 @@ targets_external <- list( # by = "unique_id" # ) - external_analyses %>% - rowwise() %>% - mutate( - analysis_start_datetime = min(data$analysis_period_start_datetime), - analysis_start_date = as_date(analysis_start_datetime), - analysis_end_datetime = max(data$analysis_period_start_datetime), - analysis_end_date = as_date(analysis_end_datetime) + # compute start/end by theme (not species!) + x_analyses <- external_analyses %>% + # select(theme, unique_id, data) %>% + unnest(data) %>% + group_by( + theme, unique_id, + analysis_sampling_rate_hz, + qc_data = qc_processing, + call_type_code, + detection_method, + protocol_reference ) %>% - ungroup() %>% - select(theme, unique_id, analysis_sampling_rate_hz, qc_data = qc_processing, call_type_code, detection_method, protocol_reference, analysis_start_date, analysis_end_date) %>% + summarise( + analysis_start_date = as_date(min(analysis_period_start_datetime)), + analysis_end_date = as_date(max(analysis_period_start_datetime)), + .groups = "drop" + ) + stopifnot( + x_analyses %>% + add_count(theme, unique_id) %>% + filter(n > 1) %>% + nrow() == 0 + ) + + x <- x_analyses %>% left_join( external_metadata %>% select(-id, -filename, -row) %>% @@ -191,12 +289,25 @@ targets_external <- list( channel = as.character(channel), platform_type = case_when( platform_type == "BOTTOM-MOUNTED" ~ "mooring", + platform_type == "DRIFTING-BUOY" ~ "drifting_buoy", TRUE ~ platform_type ) ) %>% select(all_of(names(st_drop_geometry(internal$deployments)))) %>% - distinct() %>% + distinct() + + x_stationary <- x %>% + filter(deployment_type == "STATIONARY") %>% st_as_sf(coords = c("longitude", "latitude"), crs = 4326, remove = FALSE) + x_mobile <- x %>% + filter(deployment_type == "MOBILE") %>% + left_join( + external_tracks, + by = c("id" = "unique_id") + ) %>% + st_as_sf() + + bind_rows(x_stationary, x_mobile) }), tar_target(external_detections_raw, { external_analyses %>% @@ -218,8 +329,16 @@ targets_external <- list( ) ) }), - tar_target(external_detections, { + tar_target(external_deployments_types, { + external_deployments %>% + distinct(id, deployment_type) + }), + tar_target(external_detections_stationary, { + ids <- external_deployments_types %>% + filter(deployment_type == "STATIONARY") %>% + pull(id) analysis_periods <- external_analyses %>% + filter(unique_id %in% ids) %>% rowwise() %>% mutate( start = min(as_date(data$analysis_period_start_datetime)), @@ -230,6 +349,7 @@ targets_external <- list( select(-start, -end) %>% unnest(dates) x <- external_detections_raw %>% + filter(id %in% ids) %>% count(theme, id, species_code, date = as_date(datetime), presence) %>% pivot_wider(names_from = "presence", values_from = "n", values_fill = 0) %>% mutate( @@ -243,7 +363,7 @@ targets_external <- list( ) %>% select(-y, -m, -n, -na) analysis_periods %>% - left_join(x, by = c("theme", "id", "date", "species_code")) %>% + left_join(x, by = c("theme", "id", "date", "species_code")) %>% mutate( presence = coalesce(presence, "na"), species_code = case_when( @@ -255,20 +375,151 @@ targets_external <- list( species_code == "BLBW" ~ "Blainville's", species_code == "GEBW" ~ "Gervais'", species_code == "GOBW" ~ "Cuvier's", + species_code == "BWBB" ~ "Baird's", + species_code == "BWMS" ~ "Stejneger's", + species_code == "BWMC" ~ "Hubb's", + species_code == "BW43" ~ "Unid. 43 kHz Beaked Whale", + species_code == "BWC" ~ "Cross Seamount", species_code == "MEME" ~ "Unid. Mesoplodon", species_code == "NBWH" ~ "Northern Bottlenose", species_code == "SOBW" ~ "Sowerby's", # species_code == "UNDO" ~ "Unid. Dolphin", # species_code == "GRAM" ~ "Risso's Dolphin", + TRUE ~ species_code + ) + ) %>% + select(-species_code) + }), + tar_target(external_detections_mobile, { + ids <- external_deployments_types %>% + filter(deployment_type == "MOBILE") %>% + pull(id) + + # create approx functions to linearly interpolate latitude and longitude + x_tracks <- external_gpsdata %>% + clean_names() %>% + select(unique_id, datetime, latitude, longitude) %>% + nest_by(unique_id) %>% + mutate( + data = list({ + data %>% + group_by(datetime) %>% + summarise( + latitude = mean(latitude, na.rm = TRUE), + longitude = mean(longitude, na.rm = TRUE) + ) + }), + approx_lat = list(approxfun(data$datetime, data$latitude, rule = 2)), + approx_lon = list(approxfun(data$datetime, data$longitude, rule = 2)) + ) %>% + select(-data) + + # add coordinates for each detection + x_detections_coord <- external_detections_raw %>% + filter(id %in% ids) %>% + nest_by(id) %>% + left_join(x_tracks, by = c("id" = "unique_id")) %>% + mutate( + data = list({ + data %>% + mutate( + latitude = approx_lat(datetime), + longitude = approx_lon(datetime) + ) + }) + ) %>% + select(-starts_with("approx_")) %>% + unnest(data) %>% + ungroup() + + x_daily <- x_detections_coord %>% + nest_by(theme, id, species_code, date = as_date(datetime), .key = "locations") %>% + mutate( + presence = case_when( + any(locations$presence == "y") ~ "y", + any(locations$presence == "m") ~ "m", + any(locations$presence == "n") ~ "n", + any(locations$presence == "na") ~ "na", + TRUE ~ "na" + ), + locations = list({ + head(locations, 1) %>% + mutate(date = as_date(datetime)) %>% + filter(presence == "y") + }), + species_code = case_when( + theme == "beaked" ~ species_code, + theme == "dolphin" ~ species_code, TRUE ~ NA_character_ + ), + species = case_when( + species_code == "BLBW" ~ "Blainville's", + species_code == "GEBW" ~ "Gervais'", + species_code == "GOBW" ~ "Cuvier's", + species_code == "BWBB" ~ "Baird's", + species_code == "BWMS" ~ "Stejneger's", + species_code == "BWMC" ~ "Hubb's", + species_code == "BW43" ~ "Unid. 43 kHz Beaked Whale", + species_code == "BWC" ~ "Cross Seamount", + species_code == "MEME" ~ "Unid. Mesoplodon", + species_code == "NBWH" ~ "Northern Bottlenose", + species_code == "SOBW" ~ "Sowerby's", + # species_code == "UNDO" ~ "Unid. Dolphin", + # species_code == "GRAM" ~ "Risso's Dolphin", + TRUE ~ species_code ) ) %>% + ungroup() %>% select(-species_code) + + # fill missing dates by theme,id with non-detects + x_deployment_dates <- external_deployments %>% + semi_join(x_daily, by = c("theme", "id")) %>% + st_drop_geometry() %>% + transmute( + theme, id, + start = as_date(monitoring_start_datetime), + end = as_date(monitoring_end_datetime) + ) %>% + rowwise() %>% + mutate( + date = list(seq.Date(start, end, by = "day")) + ) %>% + select(-start, -end) %>% + unnest(date) %>% + distinct() + + x_daily_nondetect <- x_deployment_dates %>% + anti_join(x_daily, by = c("theme", "id", "date")) %>% + mutate( + presence = "n", + locations = list(NULL), + species = NA + ) + + x <- bind_rows( + x_daily, + x_daily_nondetect + ) %>% + arrange(theme, id, date) + + # no duplicate dates + stopifnot( + x %>% + add_count(theme, id, date, species) %>% + filter(n > 1) %>% + nrow() == 0 + ) + x + }), + tar_target(external_detections, { + bind_rows(external_detections_stationary, external_detections_mobile) }), tar_target(external, { stopifnot( nrow(external_metadata_errors) == 0, - nrow(external_detectiondata_errors) == 0 + nrow(external_detectiondata_errors) == 0, + nrow(external_gpsdata_errors) == 0 ) list( deployments = external_deployments, diff --git a/r/R/functions.R b/r/R/functions.R index bb26abb..82d85bb 100644 --- a/r/R/functions.R +++ b/r/R/functions.R @@ -169,10 +169,23 @@ load_external_submission <- function (id, root_dir, db_tables) { join_by = c("UNIQUE_ID" = "METADATA.UNIQUE_ID") ) + gpsdata <- load_submission_files( + id, + files = file.path(raw_dir, raw_files), + pattern = "*_GPSDATA_*", + rules = rules$gpsdata, + codes = codes, + parse = parse_external_gpsdata, + transform = transformers$gpsdata, + join_data = join_metadata, + join_by = c("UNIQUE_ID" = "METADATA.UNIQUE_ID") + ) + list( id = id, metadata = metadata, - detectiondata = detectiondata + detectiondata = detectiondata, + gpsdata = gpsdata ) } diff --git a/r/R/pacm.R b/r/R/pacm.R index e09aa68..be8004f 100644 --- a/r/R/pacm.R +++ b/r/R/pacm.R @@ -1,7 +1,7 @@ targets_pacm <- list( tar_target(pacm_dir, "data/pacm"), tar_target(pacm_themes, { - platform_types <- c("mooring", "buoy", "slocum", "towed") + platform_types <- c("mooring", "buoy", "drifting_buoy", "slocum", "towed") all_datasets <- list( internal, diff --git a/r/R/refs.R b/r/R/refs.R index d8efc07..8524a3c 100644 --- a/r/R/refs.R +++ b/r/R/refs.R @@ -45,7 +45,8 @@ targets_refs <- list( "kogia", "KOSP", "sperm", "PHMA", - "harbor", "PHPH" + "harbor", "PHPH", + "nbhf", "NBHF" ) }), tar_target(refs, { diff --git a/r/_targets.R b/r/_targets.R index dd7230c..c36c800 100644 --- a/r/_targets.R +++ b/r/_targets.R @@ -44,8 +44,8 @@ list( targets_towed, targets_nefsc_20230926, targets_nefsc_20230928, - targets_davis_20230901, - targets_davis_20231122, + # targets_davis_20230901, + # targets_davis_20231122, targets_internal, targets_external, diff --git a/r/cli/functions.R b/r/cli/functions.R index 8bf0bb3..1a176a5 100644 --- a/r/cli/functions.R +++ b/r/cli/functions.R @@ -536,6 +536,23 @@ parse_external_detectiondata <- function (x) { ) } +parse_external_gpsdata <- function (x) { + x %>% + mutate( + across( + c(DATETIME), + ymd_hms + ), + across( + c( + LATITUDE, + LONGITUDE + ), + parse_number + ) + ) +} + parse_internal_header <- function (x) { x %>% mutate( diff --git a/r/notes/20240321-si-workshop.R b/r/notes/20240321-si-workshop.R new file mode 100644 index 0000000..1a3665c --- /dev/null +++ b/r/notes/20240321-si-workshop.R @@ -0,0 +1,65 @@ +# summary stats for 2024 PAM SI workshop + +source("_targets.R") + +tar_load(pacm_themes) + +deployments <- pacm_themes %>% + filter(theme != "deployments") %>% + select(-detections) %>% + unnest(deployments) %>% + select(-geometry) %>% + ungroup() +detections <- pacm_themes %>% + filter(theme != "deployments") %>% + select(-deployments) %>% + unnest(detections) %>% + select(-locations) %>% + ungroup() +species <- detections %>% + mutate( + species = case_when( + is.na(species) & theme == "beaked" ~ NA_character_, + is.na(species) ~ theme, + TRUE ~ species + ) + ) %>% + filter(!is.na(species)) + +tabyl(deployments, data_poc_affiliation) + +tabyl(deployments, platform_type) + +tabyl(species, species) %>% nrow() + +deployments %>% + distinct(id, platform_type) %>% + nrow() + +detections %>% + nrow() + +detections %>% + tabyl(presence) %>% + adorn_percentages("col") + +summary(detections) + +detections %>% + mutate(year = year(date)) %>% + ggplot(aes(year)) + + geom_histogram(binwidth = 1) + +detections %>% + filter(presence == "y") %>% + mutate( + theme = str_to_title(theme), + theme = if_else(theme == "Narw", "NARW", theme) + ) %>% + ggplot(aes(date, fct_rev(fct_inorder(theme)))) + + geom_point(color = "orangered", alpha = 0.25, size = 5) + + scale_x_date(date_breaks = "2 years", date_labels = "%Y") + + labs(y = NULL, x = NULL) + + theme_bw() + + theme(text = element_text(size = 16)) + diff --git a/r/notes/20240606-SWFSC-SAEL_20240520.R b/r/notes/20240606-SWFSC-SAEL_20240520.R new file mode 100644 index 0000000..9469b8e --- /dev/null +++ b/r/notes/20240606-SWFSC-SAEL_20240520.R @@ -0,0 +1,23 @@ +# SWFSC-SAEL_20240520 + +source("_targets.R") + +external_dir <- "data/external" +db_tables <- read_rds(file.path(external_dir, "db-tables.rds")) +x <- load_external_submission( + id = "SWFSC-SAEL_20240520", + root_dir = external_dir, + db_tables = db_tables +) + +x$metadata %>% + filter(n_errors > 0) %>% + pull(filename) + + +# duplicate UNIQUE_IDs (different recorders): +# - SWFSC_NEPac-MBY_201608_Pascal_009 +# - SWFSC_NEPac-SND_201609_Pascal_024 +# - SWFSC_NEPac-CHI_201609_Pascal_026 +# - SWFSC_NEPac-CHI_201609_Pascal_030 + diff --git a/r/notes/20240801-SWFSC-SAEL_20240617.R b/r/notes/20240801-SWFSC-SAEL_20240617.R new file mode 100644 index 0000000..d956134 --- /dev/null +++ b/r/notes/20240801-SWFSC-SAEL_20240617.R @@ -0,0 +1,100 @@ +# SWFSC-SAEL_20240617 (replaces SWFSC-SAEL_20240520) + +source("_targets.R") + +external_dir <- "data/external" +db_tables <- read_rds(file.path(external_dir, "db-tables.rds")) +db_tables$species <- db_tables$species %>% + bind_rows( + tibble(SPECIES_CODE = c("BWBB", "BWMS", "BWMC", "BW43", "BWC")) + ) + +x <- load_external_submission( + id = "SWFSC-SAEL_20240617", + root_dir = external_dir, + db_tables = db_tables +) + +x$metadata %>% + filter(n_errors > 0) + +x$detectiondata %>% + filter(n_errors > 0) + +x$gpsdata %>% + filter(n_errors > 0) + +x$detectiondata %>% + select(filename, validation_errors) %>% + unnest(validation_errors) %>% + filter(name == "MAX_ANALYSIS_FREQUENCY_RANGE_HZ.out_of_range") %>% + left_join( + x$detectiondata %>% + select(filename, joined) %>% + unnest(joined), + by = c("filename", "row") + ) + +x$detectiondata %>% + select(filename, validation_errors) %>% + unnest(validation_errors) %>% + filter(name == "ANALYSIS_PERIOD_START_DATETIME.outside_monitoring_period") %>% + left_join( + x$detectiondata %>% + select(filename, joined) %>% + unnest(joined), + by = c("filename", "row") + ) %>% + view() + +x$detectiondata %>% + select(filename, validation_errors) %>% + unnest(validation_errors) %>% + filter(name %in% c("ANALYSIS_PERIOD_START_DATETIME.outside_monitoring_period", "ANALYSIS_PERIOD_END_DATETIME.outside_monitoring_period")) %>% + distinct(filename, row) %>% + mutate(row = row + 1) %>% + group_by(filename) %>% + summarise(row = str_c(row, collapse = ",")) + +x$detectiondata %>% + select(filename, validation_errors) %>% + unnest(validation_errors) %>% + filter(name %in% c("MAX_ANALYSIS_FREQUENCY_RANGE_HZ.out_of_range")) %>% + left_join( + x$detectiondata %>% + select(filename, joined) %>% + unnest(joined), + by = c("filename", "row") + ) %>% + tabyl(METADATA.SAMPLING_RATE_HZ, MAX_ANALYSIS_FREQUENCY_RANGE_HZ) + # view() + + +x$detectiondata %>% + select(filename, joined) %>% + unnest(joined) %>% + filter(DETECTION_SOFTWARE_NAME == "PAMGuard", MAX_ANALYSIS_FREQUENCY_RANGE_HZ == 288000) %>% + filter(METADATA.SAMPLING_RATE_HZ < 288000, METADATA.SAMPLING_RATE_HZ == 256000) %>% + distinct(UNIQUE_ID) %>% + pull(UNIQUE_ID) %>% + dput() + +x$detectiondata %>% + select(filename, joined) %>% + unnest(joined) %>% + filter( + DETECTION_SOFTWARE_NAME == "PAMGuard" & + MAX_ANALYSIS_FREQUENCY_RANGE_HZ == 288000 & + UNIQUE_ID %in% c("SWFSC_NEPac-BCN_201810_CCES_017", "SWFSC_NEPac-HUM_201807_CCES_004", + "SWFSC_NEPac-BCN_201608_Pascal_007", "SWFSC_NEPac-CHI_201608_Pascal_008", + "SWFSC_NEPac-COL_201608_Pascal_013", "SWFSC_NEPac-MBY_201609_Pascal_018", + "SWFSC_NEPac-MND_201608_Pascal_010", "SWFSC_NEPac-ORE_201608_Pascal_011", + "SWFSC_NEPac-PTA_201609_Pascal_017") + ) %>% + tabyl(METADATA.SAMPLING_RATE_HZ) + view() + +x$detectiondata %>% + select(filename, joined) %>% + unnest(joined) %>% + tabyl(CALL_TYPE_CODE, SPECIES_CODE) \ No newline at end of file diff --git a/r/notes/20240806-ORSTD_20240418.R b/r/notes/20240806-ORSTD_20240418.R new file mode 100644 index 0000000..e5443eb --- /dev/null +++ b/r/notes/20240806-ORSTD_20240418.R @@ -0,0 +1,100 @@ +# ORSTD_20240418 + +source("_targets.R") + +external_dir <- "data/external" +db_tables <- read_rds(file.path(external_dir, "db-tables.rds")) + +x <- load_external_submission( + id = "ORSTD_20240418", + root_dir = external_dir, + db_tables = db_tables +) + +x$metadata %>% + filter(n_errors > 0) + +x$detectiondata %>% + filter(n_errors > 0) + +x$gpsdata %>% + filter(n_errors > 0) + +x$detectiondata %>% + select(filename, validation_errors) %>% + unnest(validation_errors) %>% + tabyl(name) + # filter(name == "MAX_ANALYSIS_FREQUENCY_RANGE_HZ.out_of_range") %>% + # left_join( + # x$detectiondata %>% + # select(filename, joined) %>% + # unnest(joined), + # by = c("filename", "row") + # ) + +x$detectiondata$parsed[[1]] %>% + tabyl(CALL_TYPE_CODE, SPECIES_CODE, ACOUSTIC_PRESENCE) + +x$detectiondata$parsed[[1]] %>% + distinct(SPECIES_CODE, CALL_TYPE_CODE) %>% + anti_join(db_tables$call_type, by = c("SPECIES_CODE", "CALL_TYPE_CODE")) + +x$detectiondata %>% + select(filename, validation_errors) %>% + unnest(validation_errors) %>% + filter(name == "ANALYSIS_PERIOD_START_DATETIME.outside_monitoring_period") %>% + left_join( + x$detectiondata %>% + select(filename, joined) %>% + unnest(joined), + by = c("filename", "row") + ) %>% + view() + +x$detectiondata %>% + select(filename, validation_errors) %>% + unnest(validation_errors) %>% + filter(name %in% c("ANALYSIS_PERIOD_START_DATETIME.outside_monitoring_period", "ANALYSIS_PERIOD_END_DATETIME.outside_monitoring_period")) %>% + distinct(filename, row) %>% + mutate(row = row + 1) %>% + group_by(filename) %>% + summarise(row = str_c(row, collapse = ",")) + +x$detectiondata %>% + select(filename, validation_errors) %>% + unnest(validation_errors) %>% + filter(name %in% c("MAX_ANALYSIS_FREQUENCY_RANGE_HZ.out_of_range")) %>% + left_join( + x$detectiondata %>% + select(filename, joined) %>% + unnest(joined), + by = c("filename", "row") + ) %>% + tabyl(METADATA.SAMPLING_RATE_HZ, MAX_ANALYSIS_FREQUENCY_RANGE_HZ) + # view() + + +x$detectiondata %>% + select(filename, joined) %>% + unnest(joined) %>% + filter(DETECTION_SOFTWARE_NAME == "PAMGuard", MAX_ANALYSIS_FREQUENCY_RANGE_HZ == 288000) %>% + filter(METADATA.SAMPLING_RATE_HZ < 288000, METADATA.SAMPLING_RATE_HZ == 256000) %>% + distinct(UNIQUE_ID) %>% + pull(UNIQUE_ID) %>% + dput() + +x$detectiondata %>% + select(filename, joined) %>% + unnest(joined) %>% + filter( + DETECTION_SOFTWARE_NAME == "PAMGuard" & + MAX_ANALYSIS_FREQUENCY_RANGE_HZ == 288000 & + UNIQUE_ID %in% c("SWFSC_NEPac-BCN_201810_CCES_017", "SWFSC_NEPac-HUM_201807_CCES_004", + "SWFSC_NEPac-BCN_201608_Pascal_007", "SWFSC_NEPac-CHI_201608_Pascal_008", + "SWFSC_NEPac-COL_201608_Pascal_013", "SWFSC_NEPac-MBY_201609_Pascal_018", + "SWFSC_NEPac-MND_201608_Pascal_010", "SWFSC_NEPac-ORE_201608_Pascal_011", + "SWFSC_NEPac-PTA_201609_Pascal_017") + ) %>% + tabyl(METADATA.SAMPLING_RATE_HZ) + view() + \ No newline at end of file diff --git a/r/notes/20240815-SWFSC-SAEL_20240814.R b/r/notes/20240815-SWFSC-SAEL_20240814.R new file mode 100644 index 0000000..9567585 --- /dev/null +++ b/r/notes/20240815-SWFSC-SAEL_20240814.R @@ -0,0 +1,26 @@ +# SWFSC-SAEL_20240814 (replaces SWFSC-SAEL_20240617) + +source("_targets.R") + +external_dir <- "data/external" +db_tables <- read_rds(file.path(external_dir, "db-tables.rds")) +db_tables$species <- db_tables$species %>% + bind_rows( + tibble(SPECIES_CODE = c("BWBB", "BWMS", "BWMC", "BW43", "BWC", "NBHF")) + ) + +x <- load_external_submission( + id = "SWFSC-SAEL_20240814", + root_dir = external_dir, + db_tables = db_tables +) + +x$metadata %>% + filter(n_errors > 0) + +x$detectiondata %>% + filter(n_errors > 0) + +x$gpsdata %>% + filter(n_errors > 0) + diff --git a/src/components/Legend.vue b/src/components/Legend.vue index f185ccc..21b2de2 100644 --- a/src/components/Legend.vue +++ b/src/components/Legend.vue @@ -50,7 +50,7 @@ -
+

Stationary Platforms

@@ -122,16 +122,16 @@
-
-

Gliders

+
+

Mobile Platforms

- {{detectionTypes[0].label}} (Daily) + {{detectionTypes[0].label}} - {{detectionTypes[1].label}} (Daily) + {{detectionTypes[1].label}} @@ -144,7 +144,7 @@
-
+ @@ -187,15 +187,15 @@ export default { }, computed: { ...mapGetters(['deployments', 'theme']), - hasStation () { + hasStationary () { return this.deployments && this.deployments.some(d => d.properties.deployment_type === 'stationary') }, - hasGlider () { - return this.deployments && this.deployments.some(d => d.properties.platform_type === 'slocum' || d.properties.platform_type === 'wave') - }, - hasTowed () { - return this.deployments && this.deployments.some(d => d.properties.platform_type === 'towed') + hasMobile () { + return this.deployments && this.deployments.some(d => d.properties.deployment_type === 'mobile') }, + // hasTowed () { + // return this.deployments && this.deployments.some(d => d.properties.platform_type === 'towed') + // }, normalizeEffort: { get () { return this.$store.state.normalizeEffort diff --git a/src/components/dialogs/About.vue b/src/components/dialogs/About.vue index ddba692..377357d 100644 --- a/src/components/dialogs/About.vue +++ b/src/components/dialogs/About.vue @@ -86,6 +86,11 @@

Latest Updates

+
+ v1.1.9 | Aug 1, 2024 +
+

Fixed user-defined spatial filter when switching species. Added SWFSC-SAEL_20240814 dataset.

+
v1.1.8 | Mar 22, 2024
diff --git a/src/lib/constants.js b/src/lib/constants.js index ece6345..532b8a0 100644 --- a/src/lib/constants.js +++ b/src/lib/constants.js @@ -37,21 +37,25 @@ export const themes = [ label: 'Beaked Whale Species', showSpeciesFilter: true }, - { - id: 'kogia', - label: 'Kogia Species' - }, { id: 'sperm', label: 'Sperm Whale' }, + { + id: 'kogia', + label: 'Kogia Species' + }, { id: 'harbor', label: 'Harbor Porpoise' }, + { + id: 'nbhf', + label: 'Unidentified High-Frequency Species' + }, { id: 'dolphin', - label: 'Dolphin (Unidentified)' + label: 'Unidentified Dolphin' }, { id: 'risso', @@ -80,6 +84,10 @@ export const platformTypes = [ id: 'buoy', label: 'Surface Buoy' }, + { + id: 'drifting_buoy', + label: 'Drifting Buoy' + }, { id: 'slocum', label: 'Glider (Slocum)' diff --git a/src/lib/tour.js b/src/lib/tour.js index 7471e19..6db1f28 100644 --- a/src/lib/tour.js +++ b/src/lib/tour.js @@ -10,7 +10,7 @@ export default [ Detections are shown using different symbols for each type of monitoring platform:

Hover over a point to view a brief summary of that deployment. Click on a point or track line to view the complete metadata and a timeseries chart of daily detection results for the corresponding deployment.