-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_data_parsing.R
57 lines (42 loc) · 1.46 KB
/
test_data_parsing.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
library(ggplot2)
library(raster)
library(rnaturalearth)
library(terra)
library(tidyterra)
library(patchwork)
library(sf)
library(targets)
theme_set(theme_void())
getmean <- function(raster, time) {
# Extract the raster layer at the specified time
layer <- raster[[time]]
# Calculate the average value of all cells in the layer
avg <- global(layer, fun = mean, na.rm = TRUE)
# Return the average value
return(avg)
}
# Future
url_future <- "https://dd.weather.gc.ca/climate/cmip5/netcdf/scenarios/RCP2.6/monthly_ens/absolute/CMIP5_rcp2.6_monthly_abs_latlon1x1_TEMP_pctl50_P1M.nc" # nolint
# Historical
url_hist <- "https://dd.weather.gc.ca/climate/cmip5/netcdf/historical/monthly_ens/absolute/CMIP5_hist_monthly_abs_latlon1x1_TEMP_pctl50_P1M.nc" # nolint
download.file(url_future, dest = "future.ncdf", method = "wget")
download.file(url_hist, dest = "hist.ncdf", method = "wget")
# Make raster objects
tas_future <- rast("future.ncdf")
tas_hist <- rast("hist.ncdf")
# Load ON Census regions
on <- tar_read(raw_geom_data_on) %>%
st_as_sf() %>%
st_transform(crs = crs(tas_hist))
brantford <- on %>% filter(Region.Name == "Brantford (CY)")
# Crop tas_future around dundas
tk <- crop(tas_future, brantford)
tas_future_brantford <- mask(tk, brantford)
# Plot
ggplot(brantford) +
geom_spatraster(data = tas_future_brantford[[20]]) +
scale_fill_whitebox_c(
palette = "muted",
labels = scales::label_number(suffix = "º")
) +
geom_spatvector(fill = NA)