-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.Rhistory
512 lines (512 loc) · 23.6 KB
/
.Rhistory
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
505
506
507
508
509
510
511
512
recovery_rate = median(recovery_rate, na.rm = TRUE),
yield_ppm = median(yield_ppm, na.rm = TRUE))
filtered_commodity_country <- filtered_commodity_join %>% filter(GID_0 == country) %>% summarise(geom = st_union(geom))
filtered_commodity_country$commodity <- commodity
filtered_commodity_country$GID_0 <- country
filtered_commodity_country <- filtered_commodity_country %>%
cross_join(filtered_commodity_country_summaryfacility)%>%
cross_join(filtered_commodity_country_summaryamounts)
View(filtered_commodity_country)
print(j)
country <- countries[j]
filtered_commodity_country <- filtered_commodity_join %>% filter(GID_0 == country)
filtered_commodity_country_summaryfacility <- filtered_commodity_country %>%
st_drop_geometry() %>%
group_by(facility_type) %>%
summarise(count = n()) %>%
pivot_wider(names_from = facility_type, values_from = count)
filtered_commodity_country_summaryamounts <- filtered_commodity_country %>%
st_drop_geometry() %>%
summarise(value_tonnes = sum(value_tonnes, na.rm = TRUE),
grade_ppm = median(grade_ppm, na.rm = TRUE),
recovery_rate = median(recovery_rate, na.rm = TRUE),
yield_ppm = median(yield_ppm, na.rm = TRUE))
filtered_commodity_country <- filtered_commodity_join %>% filter(GID_0 == country) %>% summarise(geom = st_union(geom))
filtered_commodity_country$commodity <- commodity
filtered_commodity_country$GID_0 <- country
filtered_commodity_country <- filtered_commodity_country %>%
cross_join(filtered_commodity_country_summaryfacility)%>%
cross_join(filtered_commodity_country_summaryamounts)
country_output_list_shapefile[[j]] <- filtered_commodity_country
View(filtered_commodity_country)
for(j in 1:length(countries)){
print(j)
country <- countries[j]
filtered_commodity_country <- filtered_commodity_join %>% filter(GID_0 == country)
filtered_commodity_country_summaryfacility <- filtered_commodity_country %>%
st_drop_geometry() %>%
group_by(facility_type) %>%
summarise(count = n()) %>%
pivot_wider(names_from = facility_type, values_from = count)
filtered_commodity_country_summaryamounts <- filtered_commodity_country %>%
st_drop_geometry() %>%
summarise(value_tonnes = sum(value_tonnes, na.rm = TRUE),
grade_ppm = median(grade_ppm, na.rm = TRUE),
recovery_rate = median(recovery_rate, na.rm = TRUE),
yield_ppm = median(yield_ppm, na.rm = TRUE))
filtered_commodity_country <- filtered_commodity_join %>% filter(GID_0 == country) %>% summarise(geom = st_union(geom))
filtered_commodity_country$commodity <- commodity
filtered_commodity_country$GID_0 <- country
filtered_commodity_country <- filtered_commodity_country %>%
cross_join(filtered_commodity_country_summaryfacility)%>%
cross_join(filtered_commodity_country_summaryamounts)
country_output_list_shapefile[[j]] <- filtered_commodity_country
}
country_output_list_shapefile_bind <- do.call(bind_rows, country_output_list_shapefile)
View(country_output_list_shapefile_bind)
filtered_commodity <- input_sites_buffer %>%
filter(primary_commodity == commodity | str_detect(commodities_products, regex(commodity, ignore_case = TRUE)))
View(filtered_commodity)
names(country_output_list_shapefile_bind)
country_output_list_shapefile_bind <- country_output_list_shapefile_bind %>%
select(commodity, GID_0, value_tonnes, grade_ppm, recovery_rate, yield_ppm, everything())
View(country_output_list_shapefile_bind)
commodities_products <- c(commodities, products)
commodities_and_products <- c(commodities, products)
commodities_and_products <- c(commodities, products)
rm(commodities_products)
commodities_and_products
i = 11
print(i)
commodity <- commodities_and_products[i]
# filter data so that we just have records where it is the primary commodity or in the main products
filtered_commodity <- input_sites_buffer %>%
filter(primary_commodity == commodity | str_detect(commodities_products, regex(commodity, ignore_case = TRUE)))
View(filtered_commodity)
# remove those that have ended production
filtered_commodity <- filtered_commodity %>% filter(is.na(production_end))
# filter commodity production
commodity_values_filter <- commodity_values_max %>%
filter(str_detect(material_name, regex(commodity, ignore_case = TRUE))) %>%
group_by(facility_id) %>%
summarise(value_tonnes = sum(value_tonnes, na.rm = TRUE),
grade_ppm = max(grade_ppm, na.rm = TRUE),
recovery_rate = max(recovery_rate, na.rm = TRUE),
yield_ppm = max(yield_ppm, na.rm = TRUE))%>%
mutate(across(everything(), ~ replace(., . == -Inf, NA)))
View(commodity_values_filter)
# join
filtered_commodity_join <- filtered_commodity %>% left_join(commodity_values_filter)
View(filtered_commodity_join)
View(filtered_commodity_join)
# read in main commodities
commodities <- c("Copper", "Iron", "Coal", "Gold", "Nickel", "Aluminium", "Silver", "Zinc", "Other (poly)-metallic")
products <- c("Cobalt", "Diamonds", "Lead", "Lithium", "Manganese", "Palladium", "Steel", "Tin")
commodities_and_products <- c(commodities, products)
countries <- input_sites_buffer %>% st_drop_geometry() %>% select(GID_0) %>% unique() %>% unlist() %>% unname()
# read in main commodities and Products that we are interested in
commodities <- c("Copper", "Iron", "Coal", "Gold", "Nickel", "Aluminium", "Silver", "Zinc", "Other (poly)-metallic")
products <- c("Cobalt", "Diamonds", "Lead", "Lithium", "Manganese", "Palladium", "Steel", "Tin")
commodities_and_products <- c(commodities, products)
# get commodity/country combinations and create list of shapefiles
output_list <- list()
country_output_list_shapefile_bind
# get commodity/country combinations and create list of shapefiles
output_list <- list()
# loop through
for(i in 1:length(commodities_products)){
print(i)
commodity <- commodities_and_products[i]
# filter data so that we just have records where it is the primary commodity or in the main products
filtered_commodity <- input_sites_buffer %>%
filter(primary_commodity == commodity | str_detect(commodities_products, regex(commodity, ignore_case = TRUE)))
# remove those that have ended production
filtered_commodity <- filtered_commodity %>% filter(is.na(production_end))
# filter commodity production
commodity_values_filter <- commodity_values_max %>%
filter(str_detect(material_name, regex(commodity, ignore_case = TRUE))) %>%
group_by(facility_id) %>%
summarise(value_tonnes = sum(value_tonnes, na.rm = TRUE),
grade_ppm = max(grade_ppm, na.rm = TRUE),
recovery_rate = max(recovery_rate, na.rm = TRUE),
yield_ppm = max(yield_ppm, na.rm = TRUE))%>%
mutate(across(everything(), ~ replace(., . == -Inf, NA)))
# join
filtered_commodity_join <- filtered_commodity %>% left_join(commodity_values_filter)
# get countries
countries <- filtered_commodity %>% st_drop_geometry() %>% select(GID_0) %>% unique() %>% unlist() %>% unname()
country_output_list_shapefile <- list()
for(j in 1:length(countries)){
print(j)
country <- countries[j]
filtered_commodity_country <- filtered_commodity_join %>% filter(GID_0 == country)
filtered_commodity_country_summaryfacility <- filtered_commodity_country %>%
st_drop_geometry() %>%
group_by(facility_type) %>%
summarise(count = n()) %>%
pivot_wider(names_from = facility_type, values_from = count)
filtered_commodity_country_summaryamounts <- filtered_commodity_country %>%
st_drop_geometry() %>%
summarise(value_tonnes = sum(value_tonnes, na.rm = TRUE),
grade_ppm = median(grade_ppm, na.rm = TRUE),
recovery_rate = median(recovery_rate, na.rm = TRUE),
yield_ppm = median(yield_ppm, na.rm = TRUE))
filtered_commodity_country <- filtered_commodity_join %>% filter(GID_0 == country) %>% summarise(geom = st_union(geom))
filtered_commodity_country$commodity <- commodity
filtered_commodity_country$GID_0 <- country
filtered_commodity_country <- filtered_commodity_country %>%
cross_join(filtered_commodity_country_summaryfacility)%>%
cross_join(filtered_commodity_country_summaryamounts)
country_output_list_shapefile[[j]] <- filtered_commodity_country
}
# bind list together
country_output_list_shapefile_bind <- do.call(bind_rows, country_output_list_shapefile)
# select order of columns
country_output_list_shapefile_bind <- country_output_list_shapefile_bind %>%
select(commodity, GID_0, value_tonnes, grade_ppm, recovery_rate, yield_ppm, everything())
# add to list
output_list[[i]] <- country_output_list_shapefile_bind
}
# loop through
for(i in 1:length(commodities_and_products)){
print(i)
commodity <- commodities_and_products[i]
# filter data so that we just have records where it is the primary commodity or in the main products
filtered_commodity <- input_sites_buffer %>%
filter(primary_commodity == commodity | str_detect(commodities_products, regex(commodity, ignore_case = TRUE)))
# remove those that have ended production
filtered_commodity <- filtered_commodity %>% filter(is.na(production_end))
# filter commodity production
commodity_values_filter <- commodity_values_max %>%
filter(str_detect(material_name, regex(commodity, ignore_case = TRUE))) %>%
group_by(facility_id) %>%
summarise(value_tonnes = sum(value_tonnes, na.rm = TRUE),
grade_ppm = max(grade_ppm, na.rm = TRUE),
recovery_rate = max(recovery_rate, na.rm = TRUE),
yield_ppm = max(yield_ppm, na.rm = TRUE))%>%
mutate(across(everything(), ~ replace(., . == -Inf, NA)))
# join
filtered_commodity_join <- filtered_commodity %>% left_join(commodity_values_filter)
# get countries
countries <- filtered_commodity %>% st_drop_geometry() %>% select(GID_0) %>% unique() %>% unlist() %>% unname()
country_output_list_shapefile <- list()
for(j in 1:length(countries)){
print(j)
country <- countries[j]
filtered_commodity_country <- filtered_commodity_join %>% filter(GID_0 == country)
filtered_commodity_country_summaryfacility <- filtered_commodity_country %>%
st_drop_geometry() %>%
group_by(facility_type) %>%
summarise(count = n()) %>%
pivot_wider(names_from = facility_type, values_from = count)
filtered_commodity_country_summaryamounts <- filtered_commodity_country %>%
st_drop_geometry() %>%
summarise(value_tonnes = sum(value_tonnes, na.rm = TRUE),
grade_ppm = median(grade_ppm, na.rm = TRUE),
recovery_rate = median(recovery_rate, na.rm = TRUE),
yield_ppm = median(yield_ppm, na.rm = TRUE))
filtered_commodity_country <- filtered_commodity_join %>% filter(GID_0 == country) %>% summarise(geom = st_union(geom))
filtered_commodity_country$commodity <- commodity
filtered_commodity_country$GID_0 <- country
filtered_commodity_country <- filtered_commodity_country %>%
cross_join(filtered_commodity_country_summaryfacility)%>%
cross_join(filtered_commodity_country_summaryamounts)
country_output_list_shapefile[[j]] <- filtered_commodity_country
}
# bind list together
country_output_list_shapefile_bind <- do.call(bind_rows, country_output_list_shapefile)
# select order of columns
country_output_list_shapefile_bind <- country_output_list_shapefile_bind %>%
select(commodity, GID_0, value_tonnes, grade_ppm, recovery_rate, yield_ppm, everything())
# add to list
output_list[[i]] <- country_output_list_shapefile_bind
}
# bind all together
output_sf <- do.call(bind_rows, output_list)
View(output_sf)
# write to file
st_write(output_sf, new_geopackage_file, layer = "Mines_Country_Commodity_Shapefile", driver = "GPKG", delete_layer = TRUE)
# read in data
input_locations <- st_read(new_geopackage_file, layer = "Mines_Country_Commodity_Shapefile")
# read in rasters for main extract
brisk_raster_files <- list.files(paste0(github_filepath, "BRiSK/Prep/Rasters"),
pattern = "*.tif$",
full.names = TRUE)
# readin the biome rasters
biome_raster_files <- list.files(paste0(github_filepath, "BRiSK/Prep/Rasters/IUCN_Typology_Biomes"),
pattern = "*.tif$",
full.names = TRUE)
# read in rasters
brisk_rasters <- brisk_raster_files %>%
lapply(rast) %>%
print()
biome_rasters <- biome_raster_files %>%
lapply(rast) %>%
print()
# stack
brisk_stack <- rast(brisk_rasters)
names(brisk_stack)
biome_stack <- rast(biome_rasters)
names(biome_stack)
# extract
brisk_extract <- exact_extract(brisk_stack, input_locations, c('max', 'mean', 'quantile', 'sum'), quantiles = c(0.8),
progress = TRUE, append_cols = ID_cols, full_colnames = TRUE)
# set ID cols
input_locations <- input_locations %>%
rownames_to_column()
names(input_locations)
ID_cols <- c("rowname", "commodity", "GID_0")
# read in rasters for main extract
brisk_raster_files <- list.files(paste0(github_filepath, "BRiSK/Prep/Rasters"),
pattern = "*.tif$",
full.names = TRUE)
# readin the biome rasters
biome_raster_files <- list.files(paste0(github_filepath, "BRiSK/Prep/Rasters/IUCN_Typology_Biomes"),
pattern = "*.tif$",
full.names = TRUE)
# read in rasters
brisk_rasters <- brisk_raster_files %>%
lapply(rast) %>%
print()
biome_rasters <- biome_raster_files %>%
lapply(rast) %>%
print()
# stack
brisk_stack <- rast(brisk_rasters)
names(brisk_stack)
biome_stack <- rast(biome_rasters)
names(biome_stack)
# extract
brisk_extract <- exact_extract(brisk_stack, input_locations, c('max', 'mean', 'quantile', 'sum'), quantiles = c(0.8),
progress = TRUE, append_cols = ID_cols, full_colnames = TRUE)
input_locations
View(input_locations)
input_locations <- input_locations[st_geometry_type(input_locations) %in% c("POLYGON", "MULTIPOLYGON"), ]
# read in data
input_locations <- st_read(new_geopackage_file, layer = "Mines_Country_Commodity_Shapefile")
input_locations <- input_locations[st_geometry_type(input_locations) %in% c("POLYGON", "MULTIPOLYGON"), ]
# set ID cols
input_locations <- input_locations %>%
rownames_to_column()
ID_cols <- c("rowname", "commodity", "GID_0")
# read in rasters for main extract
brisk_raster_files <- list.files(paste0(github_filepath, "BRiSK/Prep/Rasters"),
pattern = "*.tif$",
full.names = TRUE)
# readin the biome rasters
biome_raster_files <- list.files(paste0(github_filepath, "BRiSK/Prep/Rasters/IUCN_Typology_Biomes"),
pattern = "*.tif$",
full.names = TRUE)
# read in rasters
brisk_rasters <- brisk_raster_files %>%
lapply(rast) %>%
print()
biome_rasters <- biome_raster_files %>%
lapply(rast) %>%
print()
# stack
brisk_stack <- rast(brisk_rasters)
names(brisk_stack)
biome_stack <- rast(biome_rasters)
names(biome_stack)
# extract
brisk_extract <- exact_extract(brisk_stack, input_locations, c('max', 'mean', 'quantile', 'sum'), quantiles = c(0.8),
progress = TRUE, append_cols = ID_cols, full_colnames = TRUE)
View(brisk_extract)
coverage_biomes <- exact_extract(biome_stack, input_locations, 'sum', quantiles = c(0.8),
progress = TRUE, append_cols = ID_cols, full_colnames = TRUE)
potential_biomes <- coverage_biomes %>%
pivot_longer(-c(ID_cols)) %>%
filter(value > 0)
potential_biomes_all <- potential_biomes %>%
ungroup() %>%
select(-value) %>%
unique() %>%
group_by_at(ID_cols) %>%
mutate(Biomes = paste0(name, collapse = "|")) %>%
select(all_of(ID_cols), Biomes) %>%
unique()
potential_biomes_max <- potential_biomes %>%
group_by_at(c(ID_cols,"name")) %>%
summarise(total = sum(value)) %>%
slice_max(total, with_ties = FALSE) %>%
select(-total) %>%
rename(Main_Biome = name) %>%
left_join(potential_biomes_all)
# join back
brisk_extract <- potential_biomes_max %>% left_join(brisk_extract)
View(potential_biomes_max)
View(coverage_biomes)
potential_biomes <- coverage_biomes %>%
pivot_longer(-c(ID_cols)) %>%
filter(value > 0)
coverage_biomes <- exact_extract(biome_stack, input_locations, 'sum', quantiles = c(0.8),
progress = TRUE, append_cols = ID_cols, full_colnames = TRUE)
# sumarise biomes
names(coverage_biomes) <- gsub("sum.", "", names(coverage_biomes))
potential_biomes <- coverage_biomes %>%
pivot_longer(-c(ID_cols)) %>%
filter(value > 0)
potential_biomes_all <- potential_biomes %>%
ungroup() %>%
select(-value) %>%
unique() %>%
group_by_at(ID_cols) %>%
mutate(Biomes = paste0(name, collapse = "|")) %>%
select(all_of(ID_cols), Biomes) %>%
unique()
potential_biomes_max <- potential_biomes %>%
group_by_at(c(ID_cols,"name")) %>%
summarise(total = sum(value)) %>%
slice_max(total, with_ties = FALSE) %>%
select(-total) %>%
rename(Main_Biome = name) %>%
left_join(potential_biomes_all)
# join back
brisk_extract <- potential_biomes_max %>% left_join(brisk_extract)
View(brisk_extract)
# extract
brisk_extract <- exact_extract(brisk_stack, input_locations, c('max', 'mean', 'quantile', 'sum'), quantiles = c(0.8),
progress = TRUE, append_cols = ID_cols, full_colnames = TRUE)
coverage_biomes <- exact_extract(biome_stack, input_locations, 'sum', quantiles = c(0.8),
progress = TRUE, append_cols = ID_cols, full_colnames = TRUE)
# sumarise biomes
names(coverage_biomes) <- gsub("sum.", "", names(coverage_biomes))
View(coverage_biomes)
potential_biomes <- coverage_biomes %>%
pivot_longer(-c(ID_cols)) %>%
filter(value > 0)
potential_biomes_all <- potential_biomes %>%
ungroup() %>%
select(-value) %>%
unique() %>%
group_by_at(ID_cols) %>%
mutate(Biomes = paste0(name, collapse = "|")) %>%
select(all_of(ID_cols), Biomes) %>%
unique()
potential_biomes_max <- potential_biomes %>%
group_by_at(c(ID_cols,"name")) %>%
summarise(total = sum(value)) %>%
slice_max(total, with_ties = FALSE) %>%
select(-total) %>%
rename(Main_Biome = name) %>%
left_join(potential_biomes_all)
# join back
brisk_extract <- potential_biomes_max %>% left_join(brisk_extract)
View(brisk_extract)
# Convert results to data frames if needed
output_results <- input_locations %>% left_join(brisk_extract)
output_results_df <- output_results %>% st_drop_geometry()
write_csv(output_results_df, paste0(path, "Mined_Commodities_Regional_BRiSK_Extract.csv"), na = "")
st_write(output_sf, new_geopackage_file, layer = "Mined_Commodities_Regional_BRiSK_Extract", driver = "GPKG", delete_layer = TRUE)
# calculate category scores
# classify based on mean
reclass_category <- function(x) {ifelse(x <= 1.5, 1,
ifelse(x <= 2.5, 2,
ifelse(x <= 3.5, 3,
ifelse(x <= 4.5, 4,
ifelse(x > 4.5, 5, NA)))))}
output_results_df <- output_results_df %>%
mutate(CATEGORY_Area_Importance_Frameworks = reclass_category(mean.Framework_PAs_KBA),
CATEGORY_Threatened_Species = reclass_category(mean.SpeciesCR)) %>%
mutate(CATEGORY_STAR_T = reclass_category(mean.STARtCategory),
CATEGORY_STAR_R = reclass_category(mean.STARrCategory),
CATEGORY_STAR_T_Amphibians = reclass_category(mean.STARtAmphibiansCategory),
CATEGORY_STAR_R_Amphibians = reclass_category(mean.STARrAmphibiansCategory),
CATEGORY_STAR_Marine = reclass_category(mean.STARmarineCategory)) %>%
mutate(CATEGORY_STAR_Overall = pmax(CATEGORY_STAR_T, CATEGORY_STAR_Marine, na.rm = TRUE))%>%
mutate(CATEGORY_STAR_Overall= replace_na(CATEGORY_STAR_Overall, 1))%>%
mutate(CATEGORY_STAR_T= replace_na(CATEGORY_STAR_T, 1))%>%
mutate(CATEGORY_STAR_R= replace_na(CATEGORY_STAR_R, 1))%>%
mutate(CATEGORY_STAR_Marine= replace_na(CATEGORY_STAR_Marine, 1))%>%
mutate(CATEGORY_Marine_Habitats = reclass_category(mean.MarineHabitats)) %>%
mutate(CATEGORY_Marine_Habitats = replace_na(CATEGORY_Marine_Habitats, 1))%>%
mutate(CATEGORY_SBTN = reclass_category(mean.NaturalLands_Reclass)) %>%
mutate(CATEGORY_connectivity = reclass_category(mean.MammalConnectivity)) %>%
mutate(CATEGORY_intactness = reclass_category(mean.EcoregionIntactness)) %>%
mutate(CATEGORY_FLII = reclass_category(mean.FLII)) %>%
mutate(CATEGORY_river_fragmentation = reclass_category(mean.RiverFragmentation)) %>%
mutate(CATEGORY_cropland_expansion = reclass_category(mean.CroplandExpansion)) %>%
mutate(CATEGORY_Water_bws = reclass_category(mean.Water_bws),
CATEGORY_Water_bws_future = reclass_category(mean.Water_bws_future),
CATEGORY_Water_bwd = reclass_category(mean.Water_bwd),
CATEGORY_Water_bwd_future = reclass_category(mean.Water_bwd_future),
CATEGORY_Water_rfr = reclass_category(mean.Water_rfr),
CATEGORY_Water_cfr = reclass_category(mean.Water_cfr),
CATEGORY_Water_drr = reclass_category(mean.Water_drr),
CATEGORY_Water_cep = reclass_category(mean.Water_cep),
CATEGORY_Water_pgp = reclass_category(mean.Water_pgp),
CATEGORY_Water_FQT = reclass_category(mean.Water_FQT))%>%
mutate(CATEGORY_Forest_Loss = reclass_category(mean.ForestLoss_Reclass)) %>%
mutate(CATEGORY_Overall_CNA = reclass_category(mean.CriticalNaturalAssets))%>%
mutate(CATEGORY_Local_CNA = reclass_category(mean.LocalCNA)) %>%
mutate(CATEGORY_Global_CNA = reclass_category(mean.GlobalCNA)) %>%
rename(EBSA_Area_km2 = sum.EBSA_Prop,
IMMA_Area_km2 = sum.IMMA_Prop,
corals_km2 = sum.CoralReefs_Prop,
seagrass_km2 = sum.Seagrass_Prop,
mangroves_km2 = sum.Mangroves_Prop,
tidal_wetland_km2 = sum.TidalWetlands_Prop,
cold_water_corals_km2 = sum.ColdWaterCorals_Prop,
seamounts_km2 = sum.Seamounts_Prop)%>%
mutate(across(ends_with("_km2"), ~ . * 25))
# select the columns that are needed to go with BRiSK outputs
column_names <- fread("C:/Users/JoeTurner/Documents/GitHub/BRiSK/Prep/Tables/BRiSK_Column_Names_Region_v2.csv", na.strings = "")
columns_to_select <- column_names %>% select(Region_Names) %>% drop_na() %>% unlist() %>% unname()
renanmed_names <- column_names %>% select(Region_Names,Renamed_Names) %>% drop_na() %>% select(Renamed_Names) %>% unlist() %>% unname()
github_filepath
# select the columns that are needed to go with BRiSK outputs
column_names <- fread(paste0(github_filepath, "/BRiSK/Prep/Tables/BRiSK_Column_Names_Region_v2.csv"), na.strings = "")
columns_to_select <- column_names %>% select(Region_Names) %>% drop_na() %>% unlist() %>% unname()
renanmed_names <- column_names %>% select(Region_Names,Renamed_Names) %>% drop_na() %>% select(Renamed_Names) %>% unlist() %>% unname()
# rename columns
output_results_df_select <- output_results_df %>%
select(crop_country, country, crop, all_of(columns_to_select)) %>%
rename(GID_0 = country)
names(st_drop_geometry(input_locations))
# rename columns
output_results_df_select <- output_results_df %>%
select(names(st_drop_geometry(input_locations)), all_of(columns_to_select)) %>%
rename(GID_0 = country)
# select the columns that are needed to go with BRiSK outputs
column_names <- fread(paste0(github_filepath, "/BRiSK/Prep/Tables/BRiSK_Column_Names_Region_v2.csv"), na.strings = "")
columns_to_select <- column_names %>% select(Region_Names) %>% drop_na() %>% unlist() %>% unname()
renanmed_names <- column_names %>% select(Region_Names,Renamed_Names) %>% drop_na() %>% select(Renamed_Names) %>% unlist() %>% unname()
columns_to_select
names(st_drop_geometry(input_locations))
# rename columns
output_results_df_select <- output_results_df %>%
select(names(st_drop_geometry(input_locations)), all_of(columns_to_select))
View(output_results_df_select)
output_results_df_renamed <- output_results_df_select
names(output_results_df_renamed) <- c(names(st_drop_geometry(input_locations)), renanmed_names)
# write to file
write_csv(output_results_df_select, "C:/Users/JoeTurner/Documents/GitHub/BRiSK/Regional_Outputs/FinePrintMines_RegionalBRiSK_extracts_20241116.csv", na = "")
write_csv(output_results_df_renamed, "C:/Users/JoeTurner/Documents/GitHub/BRiSK/Regional_Outputs/FinePrintMines_RegionalBRiSK_extracts_renamed_20241116.csv", na = "")
View(output_results_df_select)
setwd("C:/Users/JoeTurner/Documents/GitHub/cv")
# Knit the HTML version
rmarkdown::render("cv_turner.rmd",
params = list(pdf_mode = FALSE),
output_file = "cv.html")
# Knit the PDF version to temporary html location
tmp_html_cv_loc <- fs::file_temp(ext = ".html")
rmarkdown::render("cv_turner.rmd",
params = list(pdf_mode = TRUE),
output_file = tmp_html_cv_loc)
# Convert to PDF using Pagedown
pagedown::find_chrome()
pagedown::chrome_print(input = "C:/temp/Rtmpo77fFw/file9f4c41c24084.html",
output = "cv_turner.pdf")
pagedown::chrome_print(input = "C:/Users/JoeTurner/Documents/GitHub/cv/cv_turner.html",
output = "cv_turner.pdf")
setwd("C:/Users/JoeTurner/Documents/GitHub/cv")
# Knit the HTML version
rmarkdown::render("cv_turner.rmd",
params = list(pdf_mode = FALSE),
output_file = "cv.html")
# Knit the PDF version to temporary html location
tmp_html_cv_loc <- fs::file_temp(ext = ".html")
rmarkdown::render("cv_turner.rmd",
params = list(pdf_mode = TRUE),
output_file = tmp_html_cv_loc)
setwd("C:/Users/JoeTurner/Documents/GitHub/cv")
# Knit the HTML version
rmarkdown::render("cv_turner.rmd",
params = list(pdf_mode = FALSE),
output_file = "cv.html")
# Knit the PDF version to temporary html location
tmp_html_cv_loc <- fs::file_temp(ext = ".html")
rmarkdown::render("cv_turner.rmd",
params = list(pdf_mode = TRUE),
output_file = tmp_html_cv_loc)