Skip to content

Commit

Permalink
Corrected for use of mean
Browse files Browse the repository at this point in the history
  • Loading branch information
silasprincipe committed Mar 4, 2024
1 parent 2517ed3 commit af9a707
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
10 changes: 8 additions & 2 deletions codes/analysis_mhw_glorys.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ library(furrr)
# Settings
outdir <- "results/mhw/"
fs::dir_create(outdir)
set.seed(2024)


# Load data ----
Expand Down Expand Up @@ -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,]

Expand All @@ -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)
Expand All @@ -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
3 changes: 1 addition & 2 deletions codes/analysis_occurrence_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion codes/analysis_sst_species.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit af9a707

Please sign in to comment.