Skip to content

Commit

Permalink
Bug fixes for variable calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
acrunyon committed Jan 19, 2023
1 parent c429b75 commit 59b82bb
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Code/Metric-development/vic/MAMSON.SWE.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ for (G in 1:length(GCMs)){


fut <- aggregate(fut_var_stars, by = by_t, FUN = function(x) mean(x)) # Doesn't work in lat/long. Must be projected. Removes units from tmax. Also aggregates to a lower resolution.
fut <- fut[,1:31,,]
fut <- fut[,1:length(future.period),,]
fut1 <- split(fut, "time")

df<-data.frame(year=future.period,mean=NA)
Expand All @@ -109,7 +109,7 @@ for (G in 1:length(GCMs)){
DF<-rbind(DF,df)


mean_hist <- st_apply(hist, c("x", "y"), mean) # find mean
# mean_hist <- st_apply(hist, c("x", "y"), mean) # find mean
mean_fut <- st_apply(fut, c("x", "y"), mean)
delta <- mean_fut - mean_grid
saveRDS(delta, file = paste(data.dir,paste(var,gcm,rcp,sep="_"),sep="/"))
Expand Down
8 changes: 4 additions & 4 deletions Code/Metric-development/vic/SWE.precip.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ DF = data.frame()
s <- aggregate(var_swe, by = by_t, FUN = function(x) max(x)) #Don't need to divide by #yrs b/c by year
s1 <- split(s, "time")

ratio1 <- s1[1:37,,]/p1[1:37,,]
ratio <- s[,1:37,,]/p[,1:37,,]
ratio1 <- s1[1:length(daymet.period),,]/p1[1:length(daymet.period),,]
ratio <- s[,1:length(daymet.period),,]/p[,1:length(daymet.period),,]


df<-data.frame(year=daymet.period,mean=NA)
Expand Down Expand Up @@ -117,8 +117,8 @@ for (G in 1:length(GCMs)){
s <- aggregate(var_swe, by = by_t, FUN = function(x) max(x)) #Don't need to divide by #yrs b/c by year
s1 <- split(s, "time")

ratio1 <- s1[1:31,,]/p1[1:31,,]
ratio <- s[,1:31,,]/p[,1:31,,]
ratio1 <- s1[1:length(future.period),,]/p1[1:length(future.period),,]
ratio <- s[,1:length(future.period),,]/p[,1:length(future.period),,]
mean_fut<-st_apply(ratio, c("x", "y"), mean)

df<-data.frame(year=future.period,mean=NA)
Expand Down
4 changes: 2 additions & 2 deletions Code/Metric-development/vic/max.SWE.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ for (G in 1:length(GCMs)){

by_t = "1 year"
hist <- aggregate(hist_var_stars, by = by_t, FUN = function(x) max(x)) #Don't need to divide by #yrs b/c by year
hist <- hist[,2:51,,]
hist <- hist[,1:length(historical.period),,]
# hist1 <- split(hist, "time")
#
#
Expand All @@ -96,7 +96,7 @@ for (G in 1:length(GCMs)){


fut <- aggregate(fut_var_stars, by = by_t, FUN = function(x) max(x)) # Doesn't work in lat/long. Must be projected. Removes units from tmax. Also aggregates to a lower resolution.
fut <- fut[,2:32,,]
fut <- fut[,1:length(future.period),,]
fut1 <- split(fut, "time")

df<-data.frame(year=future.period,mean=NA)
Expand Down
4 changes: 2 additions & 2 deletions Code/Metric-development/vic/soil.temp.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ for (G in 1:length(GCMs)){

by_t = "1 year"
hist <- aggregate(hist_var_stars, by = by_t, FUN = function(x) mean(x)) #Don't need to divide by #yrs b/c by year
hist <- hist[,2:51,,]
hist <- hist[,1:length(historical.period),,]
# hist1 <- split(hist, "time")
#
#
Expand All @@ -95,7 +95,7 @@ for (G in 1:length(GCMs)){


fut <- aggregate(fut_var_stars, by = by_t, FUN = function(x) mean(x)) # Doesn't work in lat/long. Must be projected. Removes units from tmax. Also aggregates to a lower resolution.
fut <- fut[,2:32,,]
fut <- fut[,1:length(future.period),,]
fut1 <- split(fut, "time")

df<-data.frame(year=future.period,mean=NA)
Expand Down
4 changes: 2 additions & 2 deletions Code/Metric-development/vic/water.balance.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ for (G in 1:length(GCMs)){

by_t = "1 year"
hist <- aggregate(hist_var_stars, by = by_t, FUN = function(x) sum(x)) #Don't need to divide by #yrs b/c by year
hist <- hist[,2:51,,]
hist <- hist[,1:length(historical.period),,]
# hist1 <- split(hist, "time")
#
#
Expand All @@ -97,7 +97,7 @@ for (G in 1:length(GCMs)){


fut <- aggregate(fut_var_stars, by = by_t, FUN = function(x) sum(x)) # Doesn't work in lat/long. Must be projected. Removes units from tmax. Also aggregates to a lower resolution.
fut <- fut[,2:32,,]
fut <- fut[,1:length(future.period),,]
fut1 <- split(fut, "time")

df<-data.frame(year=future.period,mean=NA)
Expand Down
2 changes: 1 addition & 1 deletion Code/example-scripts/metric_test_code.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test <- readRDS("C:/Users/achildress/Documents/wrst_temp/Data/WRST_simple/inmcm4


ggplot() + # Resolution is course
geom_stars(data = hist1[7,], alpha = 0.8) +
geom_stars(data = mean_grid, alpha = 0.8) +
# facet_wrap("time") +
# scale_fill_viridis() +
#coord_equal() +
Expand Down
4 changes: 2 additions & 2 deletions Variable_calculations.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ source(here::here("Code", "Metric-development", "vic","soil.temp.R"),echo = FALS
```{r Create daily variables, results=hide, eval=TRUE}
gc()
memory.limit(60000)
source(here::here("Code", "Metric-development", "met","met-daily-stars_by_year.R"),echo = FALSE)
source(here::here("Code", "Metric-development", "met","met-daily-stars_by_year.R"),echo = FALSE) #Takes ~1 hrs to run
source(here::here("Code", "Metric-development", "vic","SWE-runoff-Pr99.R"),echo = FALSE)
source(here::here("Code", "Metric-development", "met","Pr99v2.R"),echo = FALSE)
source(here::here("Code", "Metric-development","daily-all-geographies.R"),echo = FALSE,eval=FALSE)
# source(here::here("Code", "Metric-development","daily-all-geographies.R"),echo = FALSE,eval=FALSE)
```

0 comments on commit 59b82bb

Please sign in to comment.