From af9a707ae0ef3a1b25717b382269b147dee4d458 Mon Sep 17 00:00:00 2001 From: silasprincipe <53846571+silasprincipe@users.noreply.github.com> Date: Mon, 4 Mar 2024 22:02:28 +0100 Subject: [PATCH] Corrected for use of mean --- codes/analysis_mhw_glorys.R | 10 ++++++++-- codes/analysis_occurrence_data.R | 3 +-- codes/analysis_sst_species.R | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/codes/analysis_mhw_glorys.R b/codes/analysis_mhw_glorys.R index 4263901..04a98ce 100644 --- a/codes/analysis_mhw_glorys.R +++ b/codes/analysis_mhw_glorys.R @@ -19,6 +19,7 @@ library(furrr) # Settings outdir <- "results/mhw/" fs::dir_create(outdir) +set.seed(2024) # Load data ---- @@ -66,7 +67,7 @@ plan(multisession, workers = 4) retrieve_mhw <- function(id) { - depth_val <- 0 + depth_val <- 0 # To try other depths change here mhs_sel <- mhs_info[mhs_info$area == id,] @@ -90,6 +91,11 @@ retrieve_mhw <- function(id) { valid_cells <- as.data.frame(tvar[[1]], cell = T, xy = T)[,1:3] + if (nrow(valid_cells) > 2000) { + sa <- sample(1:nrow(valid_cells), 2000) + valid_cells <- valid_cells[sa,] + } + for (i in 1:nrow(valid_cells)) { wdf <- unname(unlist(tvar[valid_cells$cell[i]])) wdf <- data.frame(t = dates, temp = wdf) @@ -115,6 +121,6 @@ retrieve_mhw <- function(id) { } -future_map(unique(all_sites_filt$area), retrieve_mhw, .progress = T) +future_map(unique(all_sites_filt$area), retrieve_mhw, .progress = T, .options = furrr_options(seed = T)) ### END \ No newline at end of file diff --git a/codes/analysis_occurrence_data.R b/codes/analysis_occurrence_data.R index 9e4c94a..06ae69f 100644 --- a/codes/analysis_occurrence_data.R +++ b/codes/analysis_occurrence_data.R @@ -21,13 +21,12 @@ speciestherm<-read_parquet("results/species_tsummaries.parquet") speciesthermdt<-data.table(speciestherm) -speciesthermsst<-speciesthermdt[depth=="depthsurf" & variant=="max",,] +speciesthermsst<-speciesthermdt[depth=="depthsurf" & variant=="mean",,] speciesthermsstc<-dcast(speciesthermdt,species~metric,value.var = "value",fun=mean) ## Site by species occurrence table speciesthermsite<-read_parquet("results/tsummaries_aggregated.parquet") -speciesthermsite$where[is.na(speciesthermsite$where)] <- "Both" # correct NA that should be both speciesthermsitedt<-data.table(speciesthermsite) diff --git a/codes/analysis_sst_species.R b/codes/analysis_sst_species.R index 354805c..1872273 100644 --- a/codes/analysis_sst_species.R +++ b/codes/analysis_sst_species.R @@ -20,7 +20,7 @@ temp_sp <- open_dataset("results/species_tsummaries.parquet") temp_sp_filt <- temp_sp %>% filter(depth == "depthsurf") %>% - filter(variant == "max") %>% + filter(variant == "mean") %>% collect() # Temperature on sites