knitr::opts_chunk$set(echo = TRUE) library(R.matlab) library(tidyverse) library(sf)
mat <- readMat('../../snow-wna/data/snow.mat')
mat
mat$snow
mat$snow %>% dim
115 * 1597
mat$snow[1,1,1]$X %>% as.matrix %>% as_tibble %>% mutate(time = 1:n()) %>%pivot_longer(-time) %>% ggplot(aes(time, value, group = name)) + geom_line(alpha = .1)
mat$snow[[1,1,1]] %>% as_tibble mat$snow[[7,1,1]] %>% c
mat$snow[[]] %>% as
mat$snow[7:9,1,1] %>% map_dfc(c)
dat <- mat$snow[c(2:6,10),1,1] %>% map_dfc(unlist) %>% mutate(id = str_sub(id, 1, -2), HUC = str_sub(HUC, 1, -2)) %>% bind_cols(map_dfc(mat$snow[7:9,1,1], c)) %>% st_as_sf(coords = c('lon', 'lat'), crs = 4326) plot(dat)
years <- c(mat$snow[[11,1,1]])
swe <- mat$snow[[1,1,1]][,-1597] # the last column is a blank duplicated one swe[is.nan(swe)] <- NA swe_dat <- swe %>% `rownames<-`(years) %>% `colnames<-`(dat$name) %>% as_tibble(rownames = 'year') %>% mutate(year = as.numeric(year))
colSums(swe, na.rm = TRUE)
swe %>% t %>% duplicated swe_dat %>% select(where(function(x){sum(x, na.rm = TRUE) != 0})) %>% select(-year) %>% t %>% duplicated() %>% sum
swe[,-1597]
load the cluster excel file
library(readxl) map_dfr(1:3, ~read_excel('../../snow-wna/Cluster_memberships.xlsx', sheet = .), .id = 'cluster')
so A) it looks like these clusters are for the tree ring data not the snow course data (duh, I guess) and b) the tree ring data don't have the raw site names attached. I'll have to try joining by coordinates.
clusters <- map_dfr(1:3, ~read_excel('../../snow-wna/Cluster_memberships.xlsx', sheet = .), .id = 'cluster') clusters
so the above duplicated several rows, which means that there are rows in the clusters that have multiple matches in the coords
dat
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.