-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtargets_preprocessing.R
More file actions
executable file
·125 lines (106 loc) · 3.22 KB
/
targets_preprocessing.R
File metadata and controls
executable file
·125 lines (106 loc) · 3.22 KB
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
# _targets.R
library(targets)
library(tarchetypes)
library(geotargets)
# Load packages required by your functions
tar_option_set(
packages = c("sf", "dplyr", "tigris", "targets")
)
# Source the functions (which we will also rename)
source("functions/preprocessingFunction.R")
# Define the pipeline
list(
# State and County Processing ---------------------------------------------
# Target 1: Download the raw data as an R object
tar_target(
name = rawStatesData,
command = downloadRawStates()
),
# Target 2: Process the raw data to get an R object for the lower 48
# This target depends on the `rawStatesData` target
tar_target(
name = lower48Data,
command = processLower48(rawStatesData)
),
# Target 3: Save the raw data object to a file
# This depends on `rawStatesData`
tar_target(
name = rawStatesFile,
command = saveGeopackageSF(rawStatesData, "data/raw/us/allStates.gpkg"),
format = "file"
),?
# Target 4: Save the processed data object to a file
# This depends on `lower48Data`
tar_target(
name = lower48File,
command = saveGeopackageSF(lower48Data, "data/derived/us/lower48.gpkg"),
format = "file"
),
# 5. Download all US counties from tigris
tar_target(
name = tigrisCountiesData, # Renamed for clarity
command = downloadTigrisCounties() # Changed function call
),
# 6. Filter counties to only those in the lower 48
tar_target(
name = lower48CountiesData,
command = filterCountiesToLower48(tigrisCountiesData, lower48Data) # Uses new tigris data
),
# 7. Save the filtered counties to a file
tar_target(
name = lower48CountiesFile,
command = saveGeopackageSF(lower48CountiesData, "data/derived/us/lower48_counties.gpkg"),
format = "file"
),
#8. bounding box of the lower 48
tar_target(
name = extent48,
command = lower48Extent(lower48Data),
),
#9. export the extent
tar_target(
name = extent48File,
command = saveGeopackageSF(extent48, "data/derived/us/extent48.gpkg"),
format = "file"
),
# MLRA processing ---------------------------------------------------------
# process MLRA data
tar_target(
name = mlraPath,
command = {"data/raw/mlra/MLRA_52_2022/MLRA_52.shp"},
format = "file"
),
tar_target(
name = lower48MLRA,
command = processMLRA(mlraPath, extent48)
),
# # 7. Save the filtered counties to a file
tar_target(
name = lower48MLRAFile,
command = saveGeopackageSF(lower48MLRA, "data/derived/mlra/lower48MLRA.gpkg"),
format = "file"
),
# 8. generate the lrr
tar_target(
name =lrr48,
command = generateLRR(lower48MLRA = lower48MLRA)
),
# 9. export the dataset
tar_target(
name = lower48LRRFile,
command = saveGeopackageSF(lrr48, "data/derived/mlra/lower48LRR.gpkg"),
format = "file"
),
# developing sample grids ---------------------------------------------------------
# 10. 100km grid in AEA
tar_target(
name = grid100ARA,
command = buildAGrid(extent_object = extent48, cell_size = 100000)
),
# 11. export the 100km AEA dataset
tar_target(
name = grid100ARAFile,
command = saveGeopackageSF(grid100ARA, "data/derived/grids/grid100km_aea.gpkg"),
format = "file"
)
)