Skip to content

Commit

Permalink
data: add NEFSC-20230928 (harbor, dolphin)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwalkernoaa committed Sep 29, 2023
1 parent 729df46 commit e7efeaf
Show file tree
Hide file tree
Showing 5 changed files with 198 additions and 3 deletions.
6 changes: 4 additions & 2 deletions r/R/internal.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ targets_internal <- list(
towed$deployments,
moored$deployments,
glider$deployments,
nefsc_20230926$deployments
nefsc_20230926$deployments,
nefsc_20230928$deployments
)
detections <- bind_rows(
towed$detections,
moored$detections,
glider$detections,
nefsc_20230926$detections
nefsc_20230926$detections,
nefsc_20230928$detections
)
list(
deployments = deployments,
Expand Down
186 changes: 186 additions & 0 deletions r/R/internal/nefsc-20230928.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
# harbor porpoise, dolphins at moorings

targets_nefsc_20230928 <- list(
tar_target(nefsc_20230928_metadata_file, "data/internal/NEFSC_20230928/NEFSC_2023-09-28_METADATA.csv", format = "file"),
tar_target(nefsc_20230928_metadata, {
x <- read_csv(nefsc_20230928_metadata_file, col_types = cols(.default = col_character())) %>%
remove_empty(which = "rows") %>%
clean_names()

x %>%
crossing(theme = c("harbor", "dolphin")) %>%
transmute(
theme,
id = case_when(
unique_id == "NEFSC_MA-RI_202110_NS01_FPO" ~ "NEFSC_MA-RI_202110_NS01_FPOD",
TRUE ~ unique_id
),
project,
site_id,
latitude = parse_number(latitude),
longitude = parse_number(longitude),

monitoring_start_datetime = ymd_hms(monitoring_start_datetime),
monitoring_end_datetime = ymd_hms(monitoring_end_datetime),

platform_type = tolower(platform_type),
platform_id = NA_character_,

water_depth_meters = parse_number(water_depth_meters),
recorder_depth_meters = parse_number(recorder_depth_meters),
instrument_type,
instrument_id,
sampling_rate_hz = parse_number(sampling_rate_hz),
soundfiles_timezone,
duty_cycle_seconds = NA_character_,
channel,

data_poc_name,
data_poc_affiliation,
data_poc_email,

submitter_name,
submitter_affiliation,
submitter_email,
submission_date = mdy(submission_date)

# species specific
# detection_method,
# protocol_reference,
# call_type,
# analyzed
# qc_data
)
}),
tar_target(nefsc_20230928_deployments, {
x <- nefsc_20230928_detections_raw %>%
distinct(
theme,
id = unique_id,
analysis_sampling_rate_hz = parse_number(analysis_sampling_rate_hz),
detection_method,
protocol_reference,
call_type = call_type_code,
qc_data = qc_processing
) %>%
mutate(analyzed = TRUE)

# metadata includes three deployments with no detections
# nefsc_20230928_metadata %>%
# anti_join(x, by = c("theme", "id")) %>%
# distinct(id)

stopifnot(all(x$id %in% nefsc_20230928_metadata$id))

nefsc_20230928_metadata %>%
inner_join(x, by = c("theme", "id"))
}),
tar_target(nefsc_20230928_detections_harbor_file, "data/internal/NEFSC_20230928/NEFSC_2023-09-28_HarborPorpoise_DETECTIONS.csv", format = "file"),
tar_target(nefsc_20230928_detections_harbor_raw, {
read_csv(nefsc_20230928_detections_harbor_file, col_types = cols(.default = col_character())) %>%
remove_empty(which = "rows") %>%
clean_names() %>%
distinct()
}),
tar_target(nefsc_20230928_detections_dolphin_file, "data/internal/NEFSC_20230928/NEFSC_2023-09-28_Dolphin_DETECTIONS.csv", format = "file"),
tar_target(nefsc_20230928_detections_dolphin_raw, {
read_csv(nefsc_20230928_detections_dolphin_file, col_types = cols(.default = col_character())) %>%
remove_empty(which = "rows") %>%
clean_names() %>%
distinct()
}),
tar_target(nefsc_20230928_detections_raw, {
bind_rows(
harbor = nefsc_20230928_detections_harbor_raw,
dolphin = nefsc_20230928_detections_dolphin_raw,
.id = "theme"
) %>%
mutate(unique_id = str_replace(unique_id, "FPOD_Min_FPOD", "FPOD"))
}),
tar_target(nefsc_20230928_detections, {
nefsc_20230928_detections_raw %>%
transmute(
theme,
id = unique_id,
species = NA_character_,
date = as_date(ymd_hms(analysis_period_start_datetime)),
presence = fct_recode(acoustic_presence, y = "D", n = "N")
) %>%
arrange(theme, id, date)
}),
tar_target(nefsc_20230928, {
detections <- nefsc_20230928_detections %>%
mutate(
locations = map(theme, ~ NULL)
)

analysis_periods <- detections %>%
group_by(id) %>%
summarise(
analysis_start_date = min(date),
analysis_end_date = max(date),
.groups = "drop"
)

deployments_analysis <- nefsc_20230928_deployments %>%
filter(!is.na(latitude), analyzed) %>%
left_join(analysis_periods, by = "id")

# qaqc: analysis period ---------------------------------------------------
#
# deployments_analysis %>%
# transmute(
# id,
# monitoring_start_date = as_date(monitoring_start_datetime),
# monitoring_end_date = as_date(monitoring_end_datetime),
# monitoring_n_days = as.numeric(monitoring_end_date - monitoring_start_date + 1),
# analysis_start_date,
# analysis_end_date,
# analysis_n_days = as.numeric(analysis_end_date - analysis_start_date + 1),
# delta_days = monitoring_n_days - analysis_n_days
# ) %>%
# left_join(
# count(detections, id, name = "n_detections"),
# by = "id"
# ) %>%
# view()

# summary -----------------------------------------------------------------

tabyl(detections, theme, presence)

# deployments geom --------------------------------------------------------

# no missing id, latitude, longitude
stopifnot(
all(
deployments_analysis %>%
distinct(id, latitude, longitude) %>%
complete.cases()
)
)

deployments_sf <- deployments_analysis %>%
bind_rows(filter(nefsc_20230928_deployments, !analyzed, !is.na(latitude))) %>%
distinct(id, latitude, longitude) %>%
st_as_sf(coords = c("longitude", "latitude"), crs = 4326)

mapview::mapview(deployments_sf, legend = FALSE)

deployments <- deployments_sf %>%
left_join(
deployments_analysis %>%
bind_rows(filter(nefsc_20230928_deployments, !analyzed, !is.na(latitude))),
by = "id"
) %>%
mutate(deployment_type = "stationary") %>%
relocate(deployment_type, geometry, .after = last_col())

# export ------------------------------------------------------------------

list(
deployments = deployments,
detections = detections
)
})
)
4 changes: 3 additions & 1 deletion r/R/pacm.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ targets_pacm <- list(
"Song & Social" = "HWMIX",
"Pulse Train" = "MWPT",
"Narrow band high frequency click" = "NBHF CLICKS",
"Narrow band high frequency click" = "NBHF",
"Usual click" = "SPUSC",
"30-80Hz downsweep" = "SWDS",
"Upcall" = "UPCALL"
"Upcall" = "UPCALL",
"Dolphin clicks" = "ODCLICK",
)
)
detections_all <- map_df(all_datasets, ~ .x$detections)
Expand Down
1 change: 1 addition & 0 deletions r/_targets.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ list(
targets_towed_detections,
targets_towed,
targets_nefsc_20230926,
targets_nefsc_20230928,
targets_internal,

targets_external,
Expand Down
4 changes: 4 additions & 0 deletions src/lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ export const themes = [
id: 'harbor',
label: 'Harbor Porpoise'
},
{
id: 'dolphin',
label: 'Dolphin (Unidentified)'
},
{
divider: true
},
Expand Down

0 comments on commit e7efeaf

Please sign in to comment.