-
Notifications
You must be signed in to change notification settings - Fork 0
/
wind_maps.R
504 lines (417 loc) · 21.6 KB
/
wind_maps.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
################################################################################
# TITLE: wind_maps
# DESCRIPTION: Create maps showing simulation wind farm locations
#
# AUTHOR: Jessica Van Os (adapted from Taylor Pawlenchuk, 2022)
# CONTACT: [email protected]
# CREATED: March 2024
#
# NOTES: Make sure the project file is open first or "here" commands wont work right.
# Before running, create folder called "Data Files" inside project directory and populate it with
# any data you want to access.
################################################################################
################################################################################
## LOAD REQUIRED PACKAGES AND SOURCE FUNCTIONS
################################################################################
{ # Must load the here package in order to make sure internal project directories work
library(here)
# Import functions from other R files, take from the functions folder in R project
source(here('Functions','Other_Functions.R')) # Other functions used in plotting functions
source(here('Functions','Group_PlotSave.R')) # Saving functions import
# Packages required
packs_to_load = c("terra","sf","ggplot2","ggpubr","cowplot","tidyverse","dplyr",
"lubridate","readxl","colorRamps","scales",'raster',
"ggmap","sp","geodata",'ggspatial','dplyr','nasapower','grid','gridExtra','showtext')
# Function to check for packages, install if not present, and load
packs_check(packs_to_load)
}
{
font_add(family="Times",regular="times.ttf")
font_add(family="times_bf", regular = "timesbd.ttf")
font_add("times_it", regular = "/path/to/your/fonts/timesi.ttf")
Plot_Text <- "Times"
Plot_Text_bf <- "times_bf"
Plot_Text_it <- "times_it"
GenTextSz <-12
}
################################################################################
# LOAD DATA
# Wind Speeds: Canada Wind Atlas
# http://www.windatlas.ca/nav-en.php?no=46&field=EU&height=80&season=ANU
#
# Wind farm names and locations: input excel
################################################################################
wind_profile <- readRDS(here("Data Files","Wind Data","WindAtlas_Data00_0.05"))
colnames(wind_profile) <- c('Latitude', 'Longitude', 'Wind')
wind_Aurora <- read_excel(here("Data Files","Wind Data","Aurora_Wind.xlsx"))
solar_Aurora <- read_excel(here("Data Files","Wind Data","Aurora_Solar.xlsx"))
# New options
new_prj <- wind_Aurora %>%
filter(Status %in% c("Potential","NR_queue","NR_built"))
# Existing and Construction
existing_prj = wind_Aurora %>%
filter(Status %in% c("Active","Queue"))
# Add major cities to map
city_data <- data.frame(
city = c("Edmonton","Calgary","Red Deer","Lethbridge",
"Grand Prairie","Fort McMurray","Pincher Creek","Medicine Hat"),
lon = c(-113.295776,-113.827866,-113.8115,-112.8451,-118.7885,-111.3790,-113.9440,-110.7032),
lat = c(53.541252, 51.046898,52.2690,49.6956,55.1707,56.7266,49.4849,50.0290)
)
################################################################################
# GET MAP
################################################################################
# Map or world bounds.Level 1 shows provincial bounds. Level 2 is electoral bounds
can_level1 = geodata::gadm("Canada", path=here("Data Files","Wind Data"),level = 1, version="latest")
can_level2 = geodata::gadm("Canada", path=here("Data Files","Wind Data"),level = 2, version="latest")
#alberta_level1 = can_level1[which(can_level1$NAME_1 == "Alberta"),]
# Stretch to to more realistic shape
WGS84 <- rast(crs="+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
canada_level1_ellipsoid = project(can_level1, WGS84)
canada_level2_ellipsoid = project(can_level2, WGS84)
# Get AB!
alberta_ellip1 = canada_level1_ellipsoid[which(canada_level1_ellipsoid$NAME_1 == "Alberta"),]
AB_sf1 = st_as_sf(alberta_ellip1)
alberta_ellip2 = canada_level2_ellipsoid[which(canada_level2_ellipsoid$NAME_1 == "Alberta"),]
AB_sf2 = st_as_sf(alberta_ellip2)
# Coordinated from object
alberta_coordinates1 = data.frame(st_coordinates(AB_sf1)[,1:2])
alberta_coordinates2 = data.frame(st_coordinates(AB_sf2)[,1:2])
################################################################################
# WIND SPEED MAP
################################################################################
wind_map <- ggplot() +
geom_raster(data = wind_profile,
aes(x = Longitude, y = Latitude, fill = Wind)) +
geom_sf(data = AB_sf1,
aes(group = NAME_1),
fill = "transparent", colour = "black") +
# https://colorspace.r-forge.r-project.org/reference/rainbow_hcl.html
scale_fill_gradientn(#colours = colorspace::rainbow_hcl(100),
#colours = colorspace::diverging_hcl(100,"Cork"),
#colours = colorspace::sequential_hcl(100,"Mako"),
colours = matlab.like(100),
# colors = colorspace::diverging_hcl(100,"Blue-yellow 2"),
limits=c(3,11),oob=squish,
breaks=c(3,5,7,9,11),
labels=c("<3"," 5"," 7"," 9","<11"),
name = "Wind speed\nat 80m height \n(m/s)") +
geom_point(data = city_data, aes(x = lon, y = lat), color = "black", size = 0.5) +
geom_text(data = city_data, aes(x = lon, y = lat, label = city), vjust = -0.5,size=2) +
theme(panel.background = element_rect(fill = "transparent"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
plot.background = element_rect(fill = "transparent", color = NA),
axis.title = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank(),
legend.background = element_rect(fill = "transparent"),
#legend.key.height = unit(2,'cm'),
legend.box.background = element_rect(fill = "transparent", color = "transparent"),
legend.text = element_text(),
plot.title = element_text(hjust=0.5),
legend.title = element_text(hjust=0.5)) +
labs(title="Mean Wind Speed")
################################################################################
# ACTIVE FARMS
################################################################################
# Filter the data
wind_active <- existing_prj %>%
mutate(Type = if_else(Status == "Queue","Under Construction",
if_else(Status == "Active",Status,"Other")))
# Plot
Exist_WindMap<- ggplot()+
geom_raster(data = wind_profile,
aes(x = Longitude, y = Latitude, fill = Wind)) +
geom_sf(data = AB_sf1,
aes(group = NAME_1),
fill = "transparent", colour = "black") +
scale_fill_gradientn(#colours = colorspace::rainbow_hcl(100),
#colours = colorspace::diverging_hcl(100,"Cork"),
#colours = colorspace::sequential_hcl(100,"Mako"),
colours = matlab.like(100),
# colors = colorspace::diverging_hcl(100,"Blue-yellow 2"),
limits=c(3,11),oob=squish,
breaks=c(3,5,7,9,11),
labels=c("<3"," 5"," 7"," 9","<11"),
name = "Wind speed at\n 80m height (m/s)") +
geom_point(data = wind_active,
aes(x= Longitude, y = Latitude, shape = Type,
#color = Type
),
size = 1.5, color = '#767171') +
scale_shape_manual("Wind Farms",
values = c("Under Construction"=15,
"Active"=17)) +
# scale_color_manual("Wind Farms",
# values = c("Under Construction"='#767171',"Active"= '#767171')) +
geom_point(data = city_data, aes(x = lon, y = lat), color = "black", size = 1,shape=18) +
geom_text(data = city_data, aes(x = lon, y = lat, label = city), vjust = -0.5,size=3) +
guides(
shape = guide_legend(order = 1),
fill = guide_colorbar(order = 2)
) +
ggtitle("Mean Annual Wind Speeds") +
theme(panel.background = element_rect(fill = "transparent"),
text = element_text(size=GenTextSz),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.line = element_blank(),
axis.title = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank(),
plot.background = element_rect(fill = "transparent", color = NA),
plot.title = element_text(hjust = 0.5),
#legend.key.height = (unit(2,'cm')),
legend.text = element_text(),
legend.title = element_text(),
legend.background = element_rect(fill = "transparent"),
legend.key=element_rect(fill = "transparent"),
rect = element_rect(fill="transparent"))
################################################################################
# AURORA OPTIONS
################################################################################
# Filter for included only
wind_new <- new_prj %>%
filter(Included == "Yes") %>%
mutate(Type = if_else(Status == "Potential","Potential Site",
if_else(Status == "NR_built","Based on Existing",
if_else(Status == "NR_queue","Based on Queue","Other"))),
`Max Capacity` = Capacity_NR*`Overall Max`)
wind_txt <- 14
# Plot
Aurora_WindMap <- ggplot() +
geom_raster(data = wind_profile,
aes(x = Longitude, y = Latitude, fill = Wind)) +
geom_sf(data = AB_sf1,
#linewidth=1,
size=1,
aes(group = NAME_1),
fill = "transparent", colour = "black") +
scale_fill_gradientn( #colors = colorspace::diverging_hcl(100,"Blue-yellow 2"),
colours = colorspace::diverging_hcl(100,"Cork"),
#colours = matlab.like(100),
limits=c(3,11),oob=squish,
breaks=c(3,5,7,9,11),
labels=c("<3"," 5"," 7"," 9","<11"),
# colors = colorspace::diverging_hcl(100,"Blue-red 2"),
# limits=c(2.5,10.5),
# breaks=seq(2,10,by=2),
name = "Mean annual speed at 80m (m/s)"
) +
geom_point(data = city_data, aes(x = lon, y = lat), color = "black", size = 0.5) +
geom_text(data = city_data, aes(x = lon, y = lat, label = city), vjust = -0.5,size=3) +
geom_point(data = wind_new,
aes(x= Longitude, y = Latitude, size = `Max Capacity`, color = Type),
shape = 16) +
geom_point(data = wind_new,
aes(x= Longitude, y = Latitude, size = `Max Capacity`),colour="black",
shape=1) +
scale_color_manual("New Plant Source",
values = c("Potential Site"='#262626',
"Based on Existing"='#6e6e6e',
"Based on Queue"="#c6c6c6")
) +
scale_size(breaks=c(1600,2000,4000),range=c(4,7)) +
guides(color = guide_legend(override.aes = list(size = 5), order = 1),
size = guide_legend(order = 2)
) +
#ggtitle("Model New Wind Options") +
theme(panel.background = element_rect(fill = "transparent"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.title = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank(),
plot.background = element_rect(fill = "transparent", color = NA),
plot.title = element_text(hjust = 0.5, vjust=-5,size=16),
#legend.key.height = (unit(2,'cm')),
legend.text = element_text(size=wind_txt),
legend.title = element_text(size=wind_txt),
legend.background = element_rect(fill = "transparent"),
legend.key=element_rect(fill = "transparent"),
rect = element_rect(fill="transparent"))
################################################################################
# AURORA OPTIONS WITH EXISTING
################################################################################
# Filter for included only
wind_new_exist <- wind_Aurora %>%
rename(Capacity_plot=Capacity_NR)%>%
mutate(Included = replace_na(Included,"Exists"),
Capacity_plot = if_else(is.na(Capacity_plot),Capacity,Capacity_plot))%>%
filter(Included != "No",
Status != "Active_nonAESO") %>%
mutate(Type = if_else(Status == "Potential","New Potential",
if_else(Status == "NR_built","New Existing",
if_else(Status == "NR_queue","New Queue",
if_else(Status == "Active","Existing",
if_else(Status == "Queue","Upcoming Exogenous","Other"))))))
wind_new_exist$Type <- factor(wind_new_exist$Type,levels=c("Existing","New Existing","New Queue","New Potential","Upcoming Exogenous"))
wind_new_exist <- wind_new_exist%>%
arrange(Type)
wind_txt <- 14
# Plot
All_WindMap <- ggplot() +
geom_raster(data = wind_profile,
aes(x = Longitude, y = Latitude, fill = Wind),alpha=0.5) +
scale_fill_gradientn(
colours = alpha(matlab.like(100),alpha=0.5),
limits=c(3,11),oob=squish,
breaks=c(3,5,7,9,11),
labels=c("<3"," 5"," 7"," 9","<11"),
name = "Mean annual speed at 80m (m/s)") +
geom_sf(data = AB_sf1,
linewidth=1,
size=1,
aes(group = NAME_1),
fill = "transparent", colour = "black") +
geom_point(data = city_data, aes(x = lon, y = lat), color = "black", size = 0.5) +
geom_text(data = city_data, aes(x = lon, y = lat, label = city), vjust = -0.5,size=2.5) +
geom_point(data = wind_new_exist,
aes(x = Longitude, y = Latitude, color = Type, shape = Type,size=Type),
#size = 3
) +
scale_color_manual("Wind Plants",
values = c("New Potential"='#203764',
"New Existing"='#4472C4',
"New Queue"='#8EA9DB',
"Existing"='#252323',
"Upcoming Exogenous"="#767171") ) +
scale_shape_manual("Wind Plants",
values = c("New Potential"=16,
"New Existing"=16,
"New Queue"=16,
"Existing"=18,
"Upcoming Exogenous"=18)) +
scale_size_manual("Wind Plants",
values = c("New Potential"=4,
"New Existing"=4,
"New Queue"=4,
"Existing"=3,
"Upcoming Exogenous"=3)) +
theme(panel.background = element_rect(fill = "transparent"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.title = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank(),
plot.background = element_rect(fill = "transparent", color = NA),
plot.title = element_blank(),
#legend.key.height = (unit(2,'cm')),
legend.text = element_text(size=wind_txt),
legend.title = element_text(size=wind_txt),
legend.background = element_rect(fill = "transparent"),
legend.key=element_rect(fill = "transparent"),
rect = element_rect(fill="transparent"))
################################################################################
# AURORA BUILDS
################################################################################
# List of farms built
################################################################################
# SOLAR DATA (not done)
# SOURCE: https://open.alberta.ca/opendata/gda-dde6ad60-dd08-4f21-bbda-7934c8cbdf1f
# 1971-2000 solar solar radiation, in megajoules per square metre (MJ/m2)
#
# Original Coordinate System: raster::projection(solar_raster)
################################################################################
# Read the downloaded TIF file
solar_raster <- lapply(here("Data Files","Alberta Data","TIF","Annual Solar Radiation 1971-2000.tif"), raster)[[1]]
# Apply new coordinate system
solar_raster2 = projectRaster(solar_raster,crs=WGS84)
# Convert to data frame
solar_df <- as.data.frame(solar_raster2, xy = TRUE) %>%
rename(Ann_Rad = "Annual.Solar.Radiation.1971.2000") %>%
filter(!is.na(Ann_Rad))
# Filter the data
solar_active <- solar_Aurora %>%
mutate(Type = if_else(Status == "Queue","Under Construction",
if_else(Status == "Active",Status,"Other")))
# Plot with ggplot2
solar_map <-ggplot() +
geom_raster(data = solar_df,
aes(x = x, y = y, fill = Ann_Rad)) +
geom_sf(data = AB_sf1,
aes(group = NAME_1),
fill = "transparent", colour = "black") +
# https://colorspace.r-forge.r-project.org/reference/rainbow_hcl.html
scale_fill_gradientn(#colours = matlab.like(100),
#colours = colorspace::diverging_hcl(100,"Vik"),
colours = colorspace::sequential_hcl(100,"Lajolla"),
limits=c(3500,5500),oob=squish,
breaks=c(3500,4000,4500,5000,5500),
name = expression(atop("Solar Radiation",paste("(MJ/m"^2,")"))),
labels=c("<3500"," 4000"," 4500"," 5000","<5500")) +
# scale_color_manual("Solar Farms",
# values = c("Under Construction"='#767171',"Active"= '#767171')) +
geom_point(data = city_data, aes(x = lon, y = lat), color = "black", size = 1) +
geom_text(data = city_data, aes(x = lon, y = lat, label = city), vjust = -0.5,size=3) +
theme(panel.background = element_rect(fill = "transparent"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
plot.background = element_rect(fill = "transparent", color = NA),
axis.title = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank(),
legend.background = element_rect(fill = "transparent"),
#legend.key.height = unit(2,'cm'),
legend.box.background = element_rect(fill = "transparent", color = "transparent"),
legend.text = element_text(),
plot.title = element_text(hjust=0.5),
legend.title.align = 0,
legend.title = element_text()) +
labs(title="Annual Solar Radiation")
# Plot with ggplot2
solar_map_exist <-ggplot() +
geom_raster(data = solar_df,
aes(x = x, y = y, fill = Ann_Rad)) +
geom_sf(data = AB_sf1,
aes(group = NAME_1),
fill = "transparent", colour = "black") +
# https://colorspace.r-forge.r-project.org/reference/rainbow_hcl.html
scale_fill_gradientn(#colours = matlab.like(100),
#colours = colorspace::diverging_hcl(100,"Vik"),
colours = colorspace::sequential_hcl(100,"Lajolla"),
limits=c(3500,5500),oob=squish,
breaks=c(3500,4000,4500,5000,5500),
name = expression("Solar Radiation (MJ/m"^2*")"),
labels=c("<3500"," 4000"," 4500"," 5000","<5500")) +
geom_point(data = solar_active,
aes(x= Longitude, y = Latitude, shape = Type,
#color = Type
),
size = 1.5,color='#767171') +
scale_shape_manual("Solar Farms",
values = c("Under Construction"=15,
"Active"=17)) +
# scale_color_manual("Solar Farms",
# values = c("Under Construction"='#767171',"Active"= '#767171')) +
geom_point(data = city_data, aes(x = lon, y = lat), color = "black", size = 1,shape=18) +
geom_text(data = city_data, aes(x = lon, y = lat, label = city), vjust = -0.5,size=3) +
theme(panel.background = element_rect(fill = "transparent"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
plot.background = element_rect(fill = "transparent", color = NA),
axis.title = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank(),
axis.line = element_blank(),
legend.background = element_rect(fill = "transparent"),
#legend.key.height = unit(2,'cm'),
legend.box.background = element_rect(fill = "transparent", color = "transparent"),
legend.text = element_text(),
plot.title = element_text(hjust=0.5),
text = element_text(size=GenTextSz),
legend.title = element_text(hjust = 0)) +
labs(title="Annual Solar Radiation")
################################################################################
# SAVE EM!
################################################################################
combine_map <- plot_grid(wind_map,solar_map, ncol=2, align="hv", axis = "t", rel_heights = c(1,1))
combine_map_prj <- plot_grid(Exist_WindMap,solar_map_exist, ncol=2, align="hv", axis = "t", rel_heights = c(1,1))
# + theme_set(theme_cowplot(font_size=8))
plot(combine_map)
GGSave_Loc_custom("Wind Maps","Wind and Solar Resource4",combine_map,12,14)
GGSave_Loc_custom("Wind Maps","Wind and Solar Resource with projs",combine_map_prj,12,14)
GGSave_Loc_custom("Wind Maps","New Wind Options Update",Aurora_WindMap,8,12)
GGSave_Loc_custom("Wind Maps","Existing Wind",Exist_WindMap,8,12)
GGSave_Loc_custom("Wind Maps","All Wind",All_WindMap,8,12)