Project

General

Profile

1 7708 aaronmk
# This script was written by Jes Coyle to filter out unwanted FIA plots for eastern states.
2
3
4
5
6
7
8
9
#########################################################
10
11
### Functions
12
13
14
15
# A function that creates a unique identifier for a plot
16
17
make.plotid = function(x){
18
19
	paste(x$STATECD, x$COUNTYCD, x$PLOT, sep = '_')
20
21
}
22
23
24
25
# A function that creates a unique identifier for a plot in a particular year
26
27
make.yrplotid = function(x){
28
29
	paste(x$INVYR, x$STATECD, x$COUNTYCD, x$PLOT, sep = '_')
30
31
}
32
33
34
35
36
37
38
39
#########################################################
40
41
### Read in Data
42
43
44
45
setwd('/gpfs/nfs/share/ftp/priv/priv/Groups/DBDGS/FIA/RawData')
46
47
48
49
50
51
#########################################################
52
53
### Code
54
55
56
57
states = c('AL', 'AR', 'CT', 'DE', 'FL', 'GA', 'IA', 'IL', 'IN', 'KY', 'LA', 'MA', 'MD', 'ME', 'MI', 'MN', 'MO', 'MS', 'NC', 'NH',
58
59
	'NJ', 'NY', 'OH', 'PA', 'RI', 'SC', 'TN', 'VA','VT', 'WI', 'WV')
60
61
62
63
64
65
# Make data frames to hold combined data
66
67
68
69
trees = c()
70
71
plots = c()
72
73
subps = c()
74
75
conds = c()
76
77
seeds = c()
78
79
80
81
82
83
84
85
for(i in states){
86
87
88
89
90
91
COND.table = read.csv(paste('./Conditions/',i,'_COND.CSV',sep = ''))
92
93
94
95
PLOT.table = read.csv(paste('./Plots/',i,'_PLOT.CSV',sep = ''))
96
97
98
99
TREE.table = read.csv(paste('./Trees/',i,'_TREE.CSV',sep = ''))
100
101
102
103
SUBP.table = read.csv(paste('./Subplots/',i,'_SUBPLOT.CSV',sep = ''))
104
105
106
107
SEED.table = read.csv(paste('./Seedlings/',i,'_SEEDLING.CSV',sep = ''))
108
109
110
111
112
113
COND.table$plot.id = make.plotid(COND.table)
114
115
COND.table$yrplot.id = make.yrplotid(COND.table)
116
117
PLOT.table$plot.id = make.plotid(PLOT.table)
118
119
PLOT.table$yrplot.id = make.yrplotid(PLOT.table)
120
121
TREE.table$plot.id = make.plotid(TREE.table)
122
123
TREE.table$yrplot.id = make.yrplotid(TREE.table)
124
125
SUBP.table$plot.id = make.plotid(SUBP.table)
126
127
SUBP.table$yrplot.id = make.yrplotid(SUBP.table)
128
129
SEED.table$plot.id = make.plotid(SEED.table)
130
131
SEED.table$yrplot.id = make.yrplotid(SEED.table)
132
133
134
135
### Subset based on condition table ###
136
137
138
139
## Find all plots that have a non forest land condition in any survey year
140
141
142
143
# A list of plots with a non-forest condition on them
144
145
non.forest.conds = subset(COND.table, COND_STATUS_CD!=1)$yrplot.id
146
147
148
149
# Restrict further analysis of conditions to conditions that are forested (because unforested conditions have missing values for variables)
150
151
cond1 = subset(COND.table, COND_STATUS_CD==1)
152
153
154
155
## Find all plots that have artificial regeneration
156
157
art.regen.conds = subset(cond1, STDORGCD == 1)$yrplot.id
158
159
160
161
## Find plots with evidence of human disturbance
162
163
human.conds = subset(cond1, (DSTRBCD1==80)|(DSTRBCD2==80)|(DSTRBCD3==80)|(TRTCD1!=0)|(TRTCD2!=0)|(TRTCD3!=0))$yrplot.id
164
165
166
167
## Remove all plots that are on the lists to exclude from the plots table
168
169
170
171
bad.plots = unique(c(non.forest.conds, art.regen.conds, human.conds))
172
173
174
175
plots1 = PLOT.table[!(PLOT.table$yrplot.id %in% bad.plots),]
176
177
178
179
180
181
### Subset based on plot table ###
182
183
184
185
## Only use plots with national design
186
187
188
189
plots2 = subset(plots1, DESIGNCD %in% c(1,115,311,312,313,314))
190
191
192
193
## Only use sampled plots
194
195
196
197
plots3 = subset(plots2, PLOT_STATUS_CD==1)
198
199
200
201
## Remove botched plot files
202
203
204
205
plots4 = subset(plots3, QA_STATUS != 5)
206
207
208
209
## Only use plots that were visited in the field
210
211
212
213
plots5 = subset(plots4, SAMP_METHOD_CD==1)
214
215
216
217
## Remove plots that were sampled using a macroplot
218
219
220
221
plots6 = subset(plots5, is.na(MACRO_BREAKPOINT_DIA))
222
223
224
225
226
227
### Update all table to have the same plots ###
228
229
230
231
good.plots = unique(plots6$yrplot.id)
232
233
234
235
these.conds = COND.table[COND.table$yrplot.id %in% good.plots,]
236
237
these.subps = SUBP.table[SUBP.table$yrplot.id %in% good.plots,]
238
239
these.seeds = SEED.table[SEED.table$yrplot.id %in% good.plots,]
240
241
these.trees = TREE.table[TREE.table$yrplot.id %in% good.plots,]
242
243
244
245
246
247
trees = rbind(trees, these.trees)
248
249
plots = rbind(plots, plots6)
250
251
conds = rbind(conds, these.conds)
252
253
subps = rbind(subps, these.subps)
254
255
seeds = rbind(seeds, these.seeds)
256
257
258
259
260
261
}#closes for loop
262
263
264
265
266
267
setwd('../Parsed_Data')
268
269
270
271
272
273
save("trees","plots","subps","conds","seeds","states", file=paste('FIA_east_parsed_',Sys.Date(),'.Rdata',sep=''))
274
275
276
277
write.csv(trees, paste('FIA_east_parsed_',Sys.Date(),'_tree.csv',sep=''), row.names=F )
278
279
280
281
write.csv(plots, paste('FIA_east_parsed_',Sys.Date(),'_plot.csv',sep=''), row.names=F )
282
283
284
285
write.csv(subps, paste('FIA_east_parsed_',Sys.Date(),'_subp.csv',sep=''), row.names=F )
286
287
288
289
write.csv(conds, paste('FIA_east_parsed_',Sys.Date(),'_cond.csv',sep=''), row.names=F )
290
291
292
293
write.csv(seeds, paste('FIA_east_parsed_',Sys.Date(),'_seedling.csv',sep=''), row.names=F )
294
295
296
297
298
299
300
301
subps = subps[,c('plot.id','yrplot.id','STATECD','COUNTYCD',
302
303
		'PLOT','INVYR','SUBP','SUBPCOND','SLOPE','ASPECT',
304
305
		'SUBP_STATUS_CD')]
306
307
plots = plots[,c('plot.id','yrplot.id','STATECD','COUNTYCD',
308
309
		'PLOT','INVYR','MEASYEAR','LAT','LON','ELEV',
310
311
		'ECOSUBCD','RDDISTCD','MANUAL')]
312
313
314
315
conds = conds[,c('plot.id','yrplot.id','STATECD','COUNTYCD',
316
317
		'PLOT','INVYR','CONDID','PHYSCLCD','FLDTYPCD',
318
319
		'STDAGE','FLDSZCD','DSTRBCD1','DSTRBCD2','DSTRBCD3')]
320
321
322
323
trees = trees[,c('plot.id','yrplot.id','STATECD','COUNTYCD',
324
325
		'PLOT','INVYR','SUBP','STATUSCD','SPCD','DIA','DIAHTCD','HT',
326
327
		'ACTUALHT','CCLCD','CPOSCD')]
328
329
330
331
seeds = seeds[,c('plot.id','yrplot.id','STATECD','COUNTYCD',
332
333
		'PLOT','INVYR', 'SUBP', 'CONDID', 'SPCD','TREECOUNT','TREECOUNT_CALC')]
334
335
336
337
### Remove bad subplot numbers
338
339
340
341
trees = subset(trees, SUBP<=4)
342
343
344
345
### Remove dead trees
346
347
348
349
trees = subset(trees, STATUSCD == 1)
350
351
352
353
354
355
save("trees","plots","subps","conds","seeds","states", file=paste('FIA_DBDGS_',Sys.Date(),'.Rdata',sep=''))
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