-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from EcosystemEcologyLab/read-tiles-better
Deal with tiles more efficiently
- Loading branch information
Showing
20 changed files
with
290 additions
and
266 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
#re-project and crop shapefiles to AZ | ||
#generic re-project and crop shapefiles to AZ | ||
read_az_landuse <- function(landuse_file, az) { | ||
terra::vect(landuse_file) |> | ||
terra::project(az) |> terra::crop(az) | ||
} | ||
terra::project(az) |> | ||
terra::crop(az) | ||
} | ||
|
||
#for wilderness, subset to just national wilderness | ||
read_az_wilderness <- function(file, az) { | ||
wilderness <- terra::vect(file) | ||
wilderness[wilderness$AREATYPE == "NATIONAL WILDERNESS AREA"] |> | ||
terra::project(az) |> | ||
terra::crop(az) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,26 @@ | ||
summarize_slopes <- function(raster, sub_vect) { | ||
raster_name <- deparse(substitute(raster)) | ||
sub_vect_name <- deparse(substitute(sub_vect)) | ||
sub_vect <- terra::project(sub_vect, raster) | ||
raster <- terra::mask(raster, sub_vect) | ||
raster <- raster[["slope"]] #only use coef layer, not p-value layer | ||
sub_vect <- | ||
terra::project(sub_vect, raster) |> | ||
sf::st_as_sf() |> | ||
sf::st_combine() #converts to single multipolygon so only one row of summary stats per subset x product | ||
|
||
as.data.frame(raster, na.rm = TRUE) |> | ||
dplyr::summarize( | ||
mean = mean(slope), | ||
sd = sd(slope), | ||
min = min(slope), | ||
max = max(slope), | ||
median = median(slope), | ||
q.025 = quantile(slope, 0.025), | ||
q.1 = quantile(slope, 0.1), | ||
q.25 = quantile(slope, 0.25), | ||
q.75 = quantile(slope, 0.75), | ||
q.9 = quantile(slope, 0.9), | ||
q.975 = quantile(slope, 0.975), | ||
n = n() | ||
) |> | ||
mutate(subset = sub_vect_name, product = raster_name, .before = mean) | ||
exactextractr::exact_extract( | ||
raster, sub_vect, fun = c( | ||
"count", | ||
"min", | ||
"max", | ||
"mean", | ||
"stdev", | ||
"median", | ||
"quantile" | ||
), | ||
quantiles = c(0.025, 0.1, 0.25, 0.75, 0.9, 0.975) | ||
) |> | ||
#fix mangled quantile column names | ||
dplyr::rename(q02.5 = q02, q97.5 = q97) |> | ||
dplyr::mutate(subset = sub_vect_name, product = raster_name, .before = 1) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#wrapper around readr::write_csv that returns the file path so it works with tar_file() | ||
tar_write_csv <- function(x, file, ...) { | ||
fs::dir_create(fs::path_dir(file)) | ||
readr::write_csv(x, file) | ||
file | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.