Skip to content

Commit

Permalink
Added new episodic filter that examines the top 10 peaks each year an…
Browse files Browse the repository at this point in the history
…d determines if they occur in winter, and what the mean SpC is vs the overall mean

Changed two of the filters
min_perc_peaks_winter -> 0.35
min_perc_winter_higher -> 0.65
  • Loading branch information
hdugan committed May 2, 2024
1 parent ae8b347 commit 6d0d10c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
6 changes: 3 additions & 3 deletions 4_EpisodicSalinization.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ p4_targets <- list(
# our criteria for exhibiting "episodic" patterns in winter.
tar_target(p4_ts_sc_peak_summary,
summarize_salt_peaks(p4_ts_sc_peaks,
min_perc_peaks_winter = 0.40,
min_perc_diff = 0.10,
min_perc_winter_higher = 0.75)),
min_perc_peaks_winter = 0.35,
# min_perc_diff = 0.10,
min_perc_winter_higher = 0.65)),
tar_target(p4_episodic_sites, filter(p4_ts_sc_peak_summary, is_salt_site)$site_no)

)
22 changes: 21 additions & 1 deletion 4_EpisodicSalinization/src/summarize_sc_peaks.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,23 @@ summarize_salt_peaks <- function(ts_peak_data, winter_months = c(12,1,2,3),
mutate(perc_winter_max_higher = n_winter_higher / n_years) %>%
select(site_no, perc_winter_max_higher)

# Calculate of the 10 largest peaks each winter, how many occur in winter ('winterPeaks)
# Also calculate the different between the peakSpc and the mean Spc
salt_peaks = ts_peak_data %>%
mutate(is_winter = month(dateTime) %in% winter_months) %>%
group_by(site_no, year = year(dateTime)) %>%
mutate(winterSum = sum(is_winter)) %>%
filter(winterSum > 60) %>% # need sufficient winter data (>60 days)
arrange(desc(SpecCond)) %>%
slice(1:10) %>%
summarise(winterPeaks = sum(is_winter), peakSpc = mean(SpecCond, na.rm = TRUE)) %>%
left_join(ts_peak_data %>% group_by(site_no, year = year(dateTime)) %>%
summarise(meanSpc = mean(SpecCond, na.rm = TRUE))) %>%
group_by(site_no) %>%
summarise_all(mean) %>%
select(-year)


salt_sites_info <- ts_peak_data %>%
# Create a winter flag - if month in (12,1,2,3)
mutate(is_winter = month(dateTime) %in% winter_months) %>%
Expand Down Expand Up @@ -86,11 +103,14 @@ summarize_salt_peaks <- function(ts_peak_data, winter_months = c(12,1,2,3),
salt_sites_info %>%
# Join in the data about winter maximums
left_join(salt_sites_max_info, by = 'site_no') %>%
left_join(salt_peaks, by = 'site_no') %>%
mutate(is_salt_site =
# More than `min_perc_peaks_winter` percent of global peaks must occur in winter
peaks_perc_winterYes > min_perc_peaks_winter &
# The non-winter and winter mean SpC must be more than `min_perc_diff` percent different
sc_perc_diff > min_perc_diff &
# sc_perc_diff > min_perc_diff &
winterPeaks > 6 &
peakSpc >= 200 + meanSpc &
# Maximum annual SpC should occur in winter more than `` percent of the years
perc_winter_max_higher > min_perc_winter_higher)

Expand Down
4 changes: 3 additions & 1 deletion 6_DefineCharacteristics/src/apply_randomforest.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ apply_randomforest <- function(site_attr_data, mtry = NULL, ntree = NULL, seed =
if(is.null(mtry)) mtry <- floor(sqrt(ncol(site_attr_data) - 1))

set.seed(seed)
randomForest(
rfMod = randomForest(
site_category_fact ~ .,
data = site_attr_data,
mtry = mtry,
importance = TRUE)

return(rfMod)

}

#' @title Tune random forest hyperparameters
Expand Down

0 comments on commit 6d0d10c

Please sign in to comment.