Skip to content

Commit

Permalink
Merge pull request #39 from EvolEcolGroup/speed
Browse files Browse the repository at this point in the history
speed up region_* when cropping
  • Loading branch information
dramanica authored Sep 8, 2023
2 parents d523192 + bfb8933 commit a56c6fa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
14 changes: 8 additions & 6 deletions R/region_series.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ region_series <-
time_steps = times)
}
var_brick <- terra::rast(this_file, subds = this_var_nc)

# subset to time steps
if (!is.null(time_bp)){
var_brick <- terra::subset(var_brick, subset = time_index)
}

# subset extent
if (!is.null(ext)){
var_brick <- terra::crop(var_brick, ext)
Expand All @@ -108,12 +114,8 @@ region_series <-
var_brick <- terra::crop(var_brick, crop)
}

if (!is.null(time_bp)){
climate_spatrasters[[this_var]] <- terra::subset(var_brick,
subset = time_index)
} else {
climate_spatrasters[[this_var]] <- var_brick
}
climate_spatrasters[[this_var]] <- var_brick

varnames(climate_spatrasters[[this_var]]) <- this_var
names(climate_spatrasters[[this_var]]) <- paste(this_var,
time_bp(climate_spatrasters[[this_var]]),
Expand Down
18 changes: 18 additions & 0 deletions data-raw/benchmark/benchmark.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
library("pastclim")
library("tidysdm")
date <- seq(-600000,-620000,-4000)
tic("start")
climate <- region_series(time_bp=date,
bio_variables=c("bio05","bio06"),
dataset="Krapp2021",
crop=region_outline$Europe)
toc()


tic("start")
date <- -600000
climate <- region_slice(time_bp=date,
bio_variables=c("bio05","bio06"),
dataset="Krapp2021",
crop=region_outline$Europe)
toc()

0 comments on commit a56c6fa

Please sign in to comment.