5 Climate
5.1 1. Import AOI Data
download.file(
url = "https://data.hydrosheds.org/file/HydroBASINS/customized_with_lakes/hybas_lake_na_lev06_v1c.zip",
destfile = "../assets/SHP/watersheds_na_l6.zip",
mode = "wb"
)
unzip(
zipfile = "../assets/SHP/watersheds_na_l6.zip",
exdir = "../assets/SHP/"
)
xy = "49.95,-119.43"
watersheds = sf::st_read("../assets/SHP/watersheds_na_l6/hybas_lake_na_lev06_v1c.shp")
aoi_xy = sf::st_read("../assets/SHP/aoi_xy.shp")
aoi = watersheds |> sf::st_intersection(aoi_xy)
sf::st_write(aoi, "../assets/SHP/aoi_watershed.shp")
tmap::tmap_mode("view")
tmap::tm_shape(aoi) + tmap::tm_borders(col="purple", lwd=2) +
tmap::tm_scalebar(position=c("RIGHT", "BOTTOM"), text.size = .5) +
tmap::tm_title("AOI Waterhsed", size=.8) 5.2 2. Import DEM Data
Note: More efficient conditioning algorithms available with RichDEM library 1
# z = 12: 1-Arc Second
# z = 11: 3-Arc Second
# z = 10: 5-Arc Second
#Download and process DEM
dem = elevatr::get_elev_raster(aoi, z=10,clip="locations")|>
terra::rast() |>
terra::crop(terra::vect(aoi)) |>
flowdem::breach() |>
flowdem::fill(epsilon=T)
raster::writeRaster(dem, "../assets/TIF/dem_5arc_condt_kelowna.tif", overwrite=T)5.3 3. Import Climate Data
Climate data, a fundamental input for wildfire weather calculations, is sourced from Environment and Climate Change Canada using the weathercan package. This approach replaces the manual data sourcing from platforms with reproducible, verifiable solution. The workflow begins by searching for all weather stations within a specified radius of the AOI. Hourly data for these stations is downloaded for the defined date range and then aggregated to a single mean value for each station for the target period. The cleaned, point-based spatial data is converted into continuous raster layers for each input variable, which are derived using Inverse Distance Weighting (IDW) method via a gstat model and the terra::interpolate function. The resulting outputs of mean daily temperature, precipitation, relative humidity, and wind speed are then masked to the AOI and saved for use in the next stages of the analysis.
# Search weather stations
stations_100km = weathercan::stations_search(
coords = c(49.95,-119.43),
interval= "day",
dist = 100)
# Parse by station
stations_ids_unique <- stations_100km |>
dplyr::pull(station_id) |> unique()
# Download data for all selected stations
climate_tbl <- weathercan::weather_dl(
station_ids = stations_ids_unique,
start = "2021-06-01",
end = "2021-10-01",
interval = "hour") # relative humidity in hourly only
# Aggregate by station
aggregated_data <- climate_tbl |>
dplyr::group_by(station_id, lat, lon) |>
dplyr::summarise(
mean_temp = mean(temp, na.rm = TRUE),
mean_prec = mean(prec_amt, na.rm = TRUE),
mean_rh = mean(rel_hum, na.rm = TRUE),
mean_ws = mean(wind_spd, na.rm = TRUE)
) |>
dplyr::ungroup()
# Convert to spatial and filter missing stations
climate_sf <- aggregated_data |>
dplyr::filter(
!is.nan(mean_temp),
!is.nan(mean_prec),
!is.nan(mean_rh),
!is.nan(mean_ws)
) |>
sf::st_as_sf(
coords = c("lon", "lat"),
crs = 4326
) |>
sf::st_transform("EPSG:3857")
# Derive raster template to interpolate on top of
raster_template <- terra::rast("../assets/TIF/elevation.tif")
# Derive function to handle `sf` weather station data
interpolate_stations <- function(model, x, crs, ...) {
v <- st_as_sf(x, coords = c("x", "y"), crs = crs)
p <- predict(model, v, ...)
as.data.frame(p)[, 1:2]
}
# Create Inverse Distance Weighting models using gstat.pkg
temp_idw <- gstat(
formula = mean_temp ~ 1,
locations = climate_sf,
nmax = 8,
set = list(idp = 2.0)
)
prec_idw <- gstat(
formula = mean_prec ~ 1,
locations = climate_sf,
nmax = 8,
set = list(idp = 2.0)
)
rh_idw <- gstat(
formula = mean_rh ~ 1,
locations = climate_sf,
nmax = 8,
set = list(idp = 2.0)
)
ws_idw <- gstat(
formula = mean_ws ~ 1,
locations = climate_sf,
nmax = 8,
set = list(idp = 2.0)
)
# Spatially interpolate using terra.pkg
temp_rast <- terra::interpolate(
object = raster_template,
model = temp_idw,
fun = interpolate_stations,
crs = "EPSG:3857",
debug.level = 0
)
prec_rast <- terra::interpolate(
object = raster_template,
model = prec_idw,
fun = interpolate_stations,
crs = "EPSG:3857",
debug.level = 0
)
rh_rast <- terra::interpolate(
object = raster_template,
model = rh_idw,
fun = interpolate_stations,
crs = "EPSG:3857",
debug.level = 0
)
ws_rast <- terra::interpolate(
object = raster_template,
model = ws_idw,
fun = interpolate_stations,
crs = "EPSG:3857",
debug.level = 0
)
# Tidy, save, and visualize
temp = terra::mask(temp_rast, terra::vect(sf::st_transform(aoi, "EPSG:3857")))
prec = terra::mask(prec_rast, terra::vect(sf::st_transform(aoi, "EPSG:3857")))
rh = terra::mask(rh_rast, terra::vect(sf::st_transform(aoi, "EPSG:3857")))
ws = terra::mask(ws_rast, terra::vect(sf::st_transform(aoi, "EPSG:3857")))
terra::writeRaster(temp, "../assets/TIF/temp.tif", overwrite=T)
terra::writeRaster(prec, "../assets/TIF/prec.tif", overwrite=T)
terra::writeRaster(rh, "../assets/TIF/rh.tif", overwrite=T)
terra::writeRaster(ws, "../assets/TIF/ws.tif", overwrite=T)5.4 4. Render Maps
tmap::tmap_mode("plot")
tmap::tm_shape(temp)+ tm_raster(style= "cont",
title="Mean Daily Temperature (°C 2m AGL)", palette="Oranges")+
tmap::tm_shape(aoi)+ tm_borders(col="purple", lwd = 2) +
tmap::tm_compass(color.dark="gray60",text.color="gray60",position=c("RIGHT","top"))+
tmap::tm_graticules(lines=T,labels.rot=c(0,90),lwd=0.2) +
tmap::tm_scale_bar(c(0, 10, 20, 40), position = c("RIGHT", "BOTTOM"), text.size = .5) -> tm1
tmap::tm_shape(prec)+ tm_raster(style= "cont",
title="Mean Daily Precipitation (mm^3/day)", palette="Oranges") +
tmap::tm_shape(aoi)+ tm_borders(col="purple", lwd = 2) +
tmap::tm_compass(color.dark="gray60",text.color="gray60",position=c("RIGHT","top"))+
tmap::tm_graticules(lines=T,labels.rot=c(0,90),lwd=0.2) +
tmap::tm_scale_bar(c(0, 10, 20, 40), position = c("RIGHT", "BOTTOM"), text.size = .5) -> tm2
tmap::tm_shape(rh)+ tm_raster(style= "cont",
title="Relative Humidity (NCDC 2m AGL)", palette="Oranges") +
tmap::tm_shape(aoi)+ tm_borders(col="purple", lwd = 2) +
tmap::tm_compass(color.dark="gray60",text.color="gray60",position=c("RIGHT","top"))+
tmap::tm_graticules(lines=T,labels.rot=c(0,90),lwd=0.2) +
tmap::tm_scale_bar(c(0, 10, 20, 40), position = c("RIGHT", "BOTTOM"), text.size = .5) -> tm3
tmap::tm_shape(ws)+ tm_raster(style= "cont",
title="Wind Speed (m/s 10m AGL)", palette="Oranges") +
tmap::tm_shape(aoi)+ tm_borders(col="purple", lwd = 2) +
tmap::tm_compass(color.dark="gray60",text.color="gray60",position=c("RIGHT","top"))+
tmap::tm_graticules(lines=T,labels.rot=c(0,90),lwd=0.2) +
tmap::tm_scale_bar(c(0, 10, 20, 40), position = c("RIGHT", "BOTTOM"), text.size = .5) -> tm4
tmap::tmap_arrange(tm1, tm2, tm3, tm4, nrow=2)![]() |
![]() |
![]() |
![]() |
Runtime Log
devtools::session_info()
## ─ Session info ───────────────────────────────────────────
## setting value
## version R version 4.3.0 (2023-04-21)
## os macOS 15.7.1
## system aarch64, darwin20
## ui X11
## language (EN)
## collate en_US.UTF-8
## ctype en_US.UTF-8
## tz America/Vancouver
## date 2025-11-03
## pandoc 3.8 @ /opt/local/bin/ (via rmarkdown)
## quarto 1.7.33 @ /usr/local/bin/quarto
##
## ─ Packages ───────────────────────────────────────────────
## package * version date (UTC) lib source
## abind 1.4-8 2024-09-12 [1] CRAN (R 4.3.3)
## backports 1.5.0 2024-05-23 [1] CRAN (R 4.3.3)
## base64enc 0.1-3 2015-07-28 [1] CRAN (R 4.3.3)
## bibtex * 0.5.1 2023-01-26 [1] CRAN (R 4.3.3)
## brew 1.0-10 2023-12-16 [1] CRAN (R 4.3.3)
## bslib 0.9.0 2025-01-30 [1] CRAN (R 4.3.3)
## cachem 1.1.0 2024-05-16 [1] CRAN (R 4.3.3)
## cartogram 0.3.0 2023-05-26 [1] CRAN (R 4.3.0)
## cffdrs * 1.9.2 2025-08-22 [1] CRAN (R 4.3.0)
## chromote * 0.5.1 2025-04-24 [1] CRAN (R 4.3.3)
## class 7.3-23 2025-01-01 [1] CRAN (R 4.3.3)
## classInt 0.4-11 2025-01-08 [1] CRAN (R 4.3.3)
## cli 3.6.5 2025-04-23 [1] CRAN (R 4.3.3)
## codetools 0.2-20 2024-03-31 [1] CRAN (R 4.3.1)
## colorspace 2.1-1 2024-07-26 [1] CRAN (R 4.3.3)
## cols4all * 0.9 2025-08-28 [1] CRAN (R 4.3.0)
## coro 1.1.0 2024-11-05 [1] CRAN (R 4.3.3)
## crosstalk 1.2.2 2025-08-26 [1] CRAN (R 4.3.0)
## curl * 7.0.0 2025-08-19 [1] CRAN (R 4.3.0)
## data.table 1.17.8 2025-07-10 [1] CRAN (R 4.3.3)
## DBI 1.2.3 2024-06-02 [1] CRAN (R 4.3.3)
## deldir 2.0-4 2024-02-28 [1] CRAN (R 4.3.3)
## devtools * 2.4.5 2022-10-11 [1] CRAN (R 4.3.0)
## dichromat 2.0-0.1 2022-05-02 [1] CRAN (R 4.3.3)
## digest 0.6.37 2024-08-19 [1] CRAN (R 4.3.3)
## doParallel 1.0.17 2022-02-07 [1] CRAN (R 4.3.3)
## dplyr * 1.1.4 2023-11-17 [1] CRAN (R 4.3.1)
## e1071 1.7-16 2024-09-16 [1] CRAN (R 4.3.3)
## elevatr * 0.99.0 2023-09-12 [1] CRAN (R 4.3.0)
## ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.3.3)
## ellmer * 0.2.1 2025-06-03 [1] CRAN (R 4.3.3)
## evaluate 1.0.5 2025-08-27 [1] CRAN (R 4.3.0)
## farver 2.1.2 2024-05-13 [1] CRAN (R 4.3.3)
## fastmap 1.2.0 2024-05-15 [1] CRAN (R 4.3.3)
## FNN 1.1.4.1 2024-09-22 [1] CRAN (R 4.3.3)
## foreach 1.5.2 2022-02-02 [1] CRAN (R 4.3.3)
## fs 1.6.6 2025-04-12 [1] CRAN (R 4.3.3)
## generics 0.1.4 2025-05-09 [1] CRAN (R 4.3.3)
## geonetwork * 0.6.0 2025-07-23 [1] CRAN (R 4.3.0)
## ggplot2 * 3.5.2 2025-04-09 [1] CRAN (R 4.3.3)
## glue 1.8.0 2024-09-30 [1] CRAN (R 4.3.3)
## gstat * 2.1-4 2025-07-10 [1] CRAN (R 4.3.3)
## gtable 0.3.6 2024-10-25 [1] CRAN (R 4.3.3)
## hexbin 1.28.5 2024-11-13 [1] CRAN (R 4.3.3)
## htmltools * 0.5.8.1 2024-04-04 [1] CRAN (R 4.3.3)
## htmlwidgets 1.6.4 2023-12-06 [1] CRAN (R 4.3.1)
## httpuv 1.6.16 2025-04-16 [1] CRAN (R 4.3.3)
## httr2 * 1.2.1 2025-07-22 [1] CRAN (R 4.3.0)
## igraph 2.1.4 2025-01-23 [1] CRAN (R 4.3.3)
## interp 1.1-6 2024-01-26 [1] CRAN (R 4.3.3)
## intervals 0.15.5 2024-08-23 [1] CRAN (R 4.3.3)
## iterators 1.0.14 2022-02-05 [1] CRAN (R 4.3.3)
## janitor * 2.2.1 2024-12-22 [1] CRAN (R 4.3.3)
## jpeg 0.1-11 2025-03-21 [1] CRAN (R 4.3.3)
## jquerylib 0.1.4 2021-04-26 [1] CRAN (R 4.3.3)
## jsonlite 2.0.0 2025-03-27 [1] CRAN (R 4.3.3)
## kableExtra * 1.4.0 2024-01-24 [1] CRAN (R 4.3.1)
## KernSmooth 2.23-26 2025-01-01 [1] CRAN (R 4.3.3)
## knitr * 1.50 2025-03-16 [1] CRAN (R 4.3.3)
## later 1.4.4 2025-08-27 [1] CRAN (R 4.3.0)
## lattice * 0.22-7 2025-04-02 [1] CRAN (R 4.3.3)
## latticeExtra 0.6-30 2022-07-04 [1] CRAN (R 4.3.3)
## leafem 0.2.5 2025-08-28 [1] CRAN (R 4.3.0)
## leaflegend 1.2.1 2024-05-09 [1] CRAN (R 4.3.3)
## leaflet 2.2.2 2024-03-26 [1] CRAN (R 4.3.1)
## leaflet.providers 2.0.0 2023-10-17 [1] CRAN (R 4.3.3)
## leafpop 0.1.0 2021-05-22 [1] CRAN (R 4.3.0)
## leafsync 0.1.0 2019-03-05 [1] CRAN (R 4.3.0)
## lifecycle 1.0.4 2023-11-07 [1] CRAN (R 4.3.3)
## logger 0.4.0 2024-10-22 [1] CRAN (R 4.3.3)
## lubridate 1.9.4 2024-12-08 [1] CRAN (R 4.3.3)
## lutz * 0.3.2 2023-10-17 [1] CRAN (R 4.3.3)
## lwgeom 0.2-14 2024-02-21 [1] CRAN (R 4.3.1)
## magrittr 2.0.4 2025-09-12 [1] CRAN (R 4.3.0)
## mapedit * 0.7.0 2025-04-20 [1] CRAN (R 4.3.3)
## maptiles 0.10.0 2025-05-07 [1] CRAN (R 4.3.3)
## mapview * 2.11.2 2023-10-13 [1] CRAN (R 4.3.1)
## memoise 2.0.1 2021-11-26 [1] CRAN (R 4.3.3)
## microbenchmark 1.5.0 2024-09-04 [1] CRAN (R 4.3.3)
## mime 0.13 2025-03-17 [1] CRAN (R 4.3.3)
## miniUI 0.1.2 2025-04-17 [1] CRAN (R 4.3.3)
## ncdf4 * 1.24 2025-03-25 [1] CRAN (R 4.3.3)
## OpenStreetMap * 0.4.0 2023-10-12 [1] CRAN (R 4.3.1)
## openxlsx * 4.2.8 2025-01-25 [1] CRAN (R 4.3.3)
## osmdata * 0.2.5 2023-08-14 [1] CRAN (R 4.3.0)
## packcircles 0.3.7 2024-11-21 [1] CRAN (R 4.3.3)
## pacman 0.5.1 2019-03-11 [1] CRAN (R 4.3.3)
## pandoc * 0.2.0 2023-08-24 [1] CRAN (R 4.3.3)
## pandocfilters * 0.1-6 2022-08-11 [1] CRAN (R 4.3.3)
## pillar 1.11.0 2025-07-04 [1] CRAN (R 4.3.3)
## pkgbuild 1.4.8 2025-05-26 [1] CRAN (R 4.3.3)
## pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.3.3)
## pkgload 1.4.0 2024-06-28 [1] CRAN (R 4.3.3)
## plyr 1.8.9 2023-10-02 [1] CRAN (R 4.3.3)
## png 0.1-8 2022-11-29 [1] CRAN (R 4.3.3)
## processx 3.8.6 2025-02-21 [1] CRAN (R 4.3.3)
## profvis 0.4.0 2024-09-20 [1] CRAN (R 4.3.3)
## progressr 0.15.1 2024-11-22 [1] CRAN (R 4.3.3)
## PROJ * 0.6.0 2025-04-03 [1] CRAN (R 4.3.3)
## proj4 1.0-15 2025-03-21 [1] CRAN (R 4.3.3)
## promises 1.3.3 2025-05-29 [1] CRAN (R 4.3.3)
## proxy 0.4-27 2022-06-09 [1] CRAN (R 4.3.3)
## ps 1.9.1 2025-04-12 [1] CRAN (R 4.3.3)
## purrr 1.1.0 2025-07-10 [1] CRAN (R 4.3.0)
## R6 2.6.1 2025-02-15 [1] CRAN (R 4.3.3)
## rappdirs 0.3.3 2021-01-31 [1] CRAN (R 4.3.3)
## raster * 3.6-32 2025-03-28 [1] CRAN (R 4.3.3)
## rasterVis * 0.51.6 2023-11-01 [1] CRAN (R 4.3.3)
## RColorBrewer 1.1-3 2022-04-03 [1] CRAN (R 4.3.3)
## Rcpp 1.1.0 2025-07-02 [1] CRAN (R 4.3.3)
## remotes 2.5.0 2024-03-17 [1] CRAN (R 4.3.3)
## renv * 1.1.5 2025-07-24 [1] CRAN (R 4.3.0)
## reproj * 0.7.0 2024-06-11 [1] CRAN (R 4.3.3)
## rJava 1.0-11 2024-01-26 [1] CRAN (R 4.3.3)
## rlang 1.1.6 2025-04-11 [1] CRAN (R 4.3.3)
## rmapshaper * 0.5.0 2023-04-11 [1] CRAN (R 4.3.0)
## rmarkdown * 2.29 2024-11-04 [1] CRAN (R 4.3.3)
## rstudioapi 0.17.1 2024-10-22 [1] CRAN (R 4.3.3)
## s2 1.1.9 2025-05-23 [1] CRAN (R 4.3.3)
## S7 0.2.0 2024-11-07 [1] CRAN (R 4.3.3)
## sass 0.4.10 2025-04-11 [1] CRAN (R 4.3.3)
## satellite 1.0.6 2025-08-21 [1] CRAN (R 4.3.0)
## scales 1.4.0 2025-04-24 [1] CRAN (R 4.3.3)
## sessioninfo 1.2.3 2025-02-05 [1] CRAN (R 4.3.3)
## sf * 1.0-22 2025-08-25 [1] Github (r-spatial/sf@3660edf)
## shiny 1.11.1 2025-07-03 [1] CRAN (R 4.3.3)
## shinyWidgets 0.9.0 2025-02-21 [1] CRAN (R 4.3.3)
## snakecase 0.11.1 2023-08-27 [1] CRAN (R 4.3.0)
## sp * 2.2-0 2025-02-01 [1] CRAN (R 4.3.3)
## spacesXYZ 1.6-0 2025-06-06 [1] CRAN (R 4.3.3)
## spacetime 1.3-3 2025-02-13 [1] CRAN (R 4.3.3)
## stars 0.6-8 2025-02-01 [1] CRAN (R 4.3.3)
## stringi 1.8.7 2025-03-27 [1] CRAN (R 4.3.3)
## stringr 1.5.2 2025-09-08 [1] CRAN (R 4.3.0)
## svglite 2.2.1 2025-05-12 [1] CRAN (R 4.3.3)
## systemfonts 1.2.3 2025-04-30 [1] CRAN (R 4.3.3)
## terra * 1.8-60 2025-07-21 [1] CRAN (R 4.3.0)
## textshaping 1.0.3 2025-09-02 [1] CRAN (R 4.3.0)
## tibble 3.3.0 2025-06-08 [1] CRAN (R 4.3.3)
## tidyselect 1.2.1 2024-03-11 [1] CRAN (R 4.3.1)
## timechange 0.3.0 2024-01-18 [1] CRAN (R 4.3.3)
## tinytex * 0.57 2025-04-15 [1] CRAN (R 4.3.3)
## tmap * 4.1 2025-05-12 [1] CRAN (R 4.3.3)
## tmap.cartogram * 0.2 2025-05-14 [1] CRAN (R 4.3.3)
## tmap.glyphs * 0.1 2025-05-30 [1] CRAN (R 4.3.3)
## tmap.networks * 0.1 2025-05-30 [1] CRAN (R 4.3.3)
## tmaptools * 3.2 2025-01-13 [1] CRAN (R 4.3.3)
## units 0.8-7 2025-03-11 [1] CRAN (R 4.3.3)
## urlchecker 1.0.1 2021-11-30 [1] CRAN (R 4.3.3)
## useful * 1.2.6.1 2023-10-24 [1] CRAN (R 4.3.1)
## usethis * 3.1.0 2024-11-26 [1] CRAN (R 4.3.3)
## uuid 1.2-1 2024-07-29 [1] CRAN (R 4.3.3)
## V8 6.0.4 2025-06-04 [1] CRAN (R 4.3.3)
## vctrs 0.6.5 2023-12-01 [1] CRAN (R 4.3.3)
## viridisLite 0.4.2 2023-05-02 [1] CRAN (R 4.3.3)
## weathercan * 0.7.5 2025-08-26 [1] https://ropensci.r-universe.dev (R 4.3.0)
## websocket 1.4.4 2025-04-10 [1] CRAN (R 4.3.3)
## withr 3.0.2 2024-10-28 [1] CRAN (R 4.3.3)
## wk 0.9.4 2024-10-11 [1] CRAN (R 4.3.3)
## xfun 0.53 2025-08-19 [1] CRAN (R 4.3.0)
## XML 3.99-0.18 2025-01-01 [1] CRAN (R 4.3.3)
## xml2 1.4.0 2025-08-20 [1] CRAN (R 4.3.0)
## xtable 1.8-4 2019-04-21 [1] CRAN (R 4.3.3)
## xts 0.14.1 2024-10-15 [1] CRAN (R 4.3.3)
## yaml 2.3.10 2024-07-26 [1] CRAN (R 4.3.3)
## zip 2.3.3 2025-05-13 [1] CRAN (R 4.3.3)
## zoo 1.8-14 2025-04-10 [1] CRAN (R 4.3.3)
##
## [1] /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library
## * ── Packages attached to the search path.
##
## ──────────────────────────────────────────────────────────Breach-fill algorithm by Lindsay’s paper (2016) “Efficient hybrid breaching-filling sink removal methods for flow path enforcement in digital elevation models: Efficient Hybrid Sink Removal Methods for Flow Path Enforcement: (Hydrological Processes 30, 846–857. doi:10.1002/hyp.10648) ->
flowdem::comp_breach_lindsay2016(dem)↩︎



