NCC-CNC / wtw-data-prep

Scripts to prepare data for Where To Work tool
0 stars 0 forks source link

06_generate_rij #18

Closed DanWismer closed 1 year ago

DanWismer commented 1 year ago

An optional script that creates rij matrix of the layers in the Tiffs folder and saves them as .rds file. This will be handy for a Resilience Index work flow that can quickly summarize layers that intersect a WTW site selection output.

edwardsmarc commented 1 year ago

Nice idea @DanWismer. Unless you've already got the code, I can take this one to improve my matrix skills. Maybe I'll create a PR so you can review it?

DanWismer commented 1 year ago

Thanks Marc, that would be great if you could tackle this!

You can give this a try:

library(terra)
library(prioritizr)

# wtw planning units
pu <- rast(PU.tif)

# list of tiffs
tiffs <- list.files("Tiffs",  pattern = ".tif$", full.names = TRUE)

# sparse matrix
rij <- rij_matrix(pu,  rast(tiffs))

# save as rds
saveRDS(rij, "rij.rds", compress = TRUE)

Instead of one .rds maybe it would be good to split it up into a couple. For example by grouped theme, weights and includes/excludes. We can save the output(s) in another folder called RIJ?

With those sparse matrix built and saved, it will make it easier to do post WTW analysis.

DanWismer commented 1 year ago

We could do something like this to parse out the lists of rasters in the Tiffs folder:

# list of ECCC SAR tifs
tiffs <- list.files(tiffs_path,  pattern = "^T_ECCC_SAR.*\\.tif$", full.names = TRUE)