Project

General

Profile

1
# This script was written by Jes Coyle to filter out unwanted FIA plots for eastern states.
2

    
3
  
4

    
5
#########################################################
6
### Functions
7

    
8
# A function that creates a unique identifier for a plot
9
make.plotid = function(x){
10
	paste(x$STATECD, x$COUNTYCD, x$PLOT, sep = '_')
11
}
12

    
13
# A function that creates a unique identifier for a plot in a particular year
14
make.yrplotid = function(x){
15
	paste(x$INVYR, x$STATECD, x$COUNTYCD, x$PLOT, sep = '_')
16
}
17

    
18

    
19

    
20
#########################################################
21
### Read in Data
22

    
23
setwd('/gpfs/nfs/share/ftp/priv/priv/Groups/DBDGS/FIA/RawData')
24

    
25

    
26
#########################################################
27
### Code
28

    
29
states = c('AL', 'AR', 'CT', 'DE', 'FL', 'GA', 'IA', 'IL', 'IN', 'KY', 'LA', 'MA', 'MD', 'ME', 'MI', 'MN', 'MO', 'MS', 'NC', 'NH', 
30
	'NJ', 'NY', 'OH', 'PA', 'RI', 'SC', 'TN', 'VA','VT', 'WI', 'WV')
31

    
32

    
33
# Make data frames to hold combined data
34

    
35
trees = c()
36
plots = c()
37
subps = c()
38
conds = c()
39
seeds = c()
40

    
41

    
42

    
43
for(i in states){
44

    
45

    
46
COND.table = read.csv(paste('./Conditions/',i,'_COND.CSV',sep = ''))
47

    
48
PLOT.table = read.csv(paste('./Plots/',i,'_PLOT.CSV',sep = ''))
49

    
50
TREE.table = read.csv(paste('./Trees/',i,'_TREE.CSV',sep = ''))
51

    
52
SUBP.table = read.csv(paste('./Subplots/',i,'_SUBPLOT.CSV',sep = ''))
53

    
54
SEED.table = read.csv(paste('./Seedlings/',i,'_SEEDLING.CSV',sep = ''))
55

    
56

    
57
COND.table$plot.id = make.plotid(COND.table)
58
COND.table$yrplot.id = make.yrplotid(COND.table)
59
PLOT.table$plot.id = make.plotid(PLOT.table)
60
PLOT.table$yrplot.id = make.yrplotid(PLOT.table)
61
TREE.table$plot.id = make.plotid(TREE.table)
62
TREE.table$yrplot.id = make.yrplotid(TREE.table)
63
SUBP.table$plot.id = make.plotid(SUBP.table)
64
SUBP.table$yrplot.id = make.yrplotid(SUBP.table)
65
SEED.table$plot.id = make.plotid(SEED.table)
66
SEED.table$yrplot.id = make.yrplotid(SEED.table)
67

    
68
### Subset based on condition table ###
69

    
70
## Find all plots that have a non forest land condition in any survey year
71

    
72
# A list of plots with a non-forest condition on them
73
non.forest.conds = subset(COND.table, COND_STATUS_CD!=1)$yrplot.id
74

    
75
# Restrict further analysis of conditions to conditions that are forested (because unforested conditions have missing values for variables)
76
cond1 = subset(COND.table, COND_STATUS_CD==1)
77

    
78
## Find all plots that have artificial regeneration 
79
art.regen.conds = subset(cond1, STDORGCD == 1)$yrplot.id
80

    
81
## Find plots with evidence of human disturbance 
82
human.conds = subset(cond1, (DSTRBCD1==80)|(DSTRBCD2==80)|(DSTRBCD3==80)|(TRTCD1!=0)|(TRTCD2!=0)|(TRTCD3!=0))$yrplot.id
83

    
84
## Remove all plots that are on the lists to exclude from the plots table
85

    
86
bad.plots = unique(c(non.forest.conds, art.regen.conds, human.conds))
87

    
88
plots1 = PLOT.table[!(PLOT.table$yrplot.id %in% bad.plots),]
89

    
90

    
91
### Subset based on plot table ###
92

    
93
## Only use plots with national design
94

    
95
plots2 = subset(plots1, DESIGNCD %in% c(1,115,311,312,313,314))
96

    
97
## Only use sampled plots
98

    
99
plots3 = subset(plots2, PLOT_STATUS_CD==1)
100

    
101
## Remove botched plot files
102

    
103
plots4 = subset(plots3, QA_STATUS != 5)
104

    
105
## Only use plots that were visited in the field
106

    
107
plots5 = subset(plots4, SAMP_METHOD_CD==1)
108

    
109
## Remove plots that were sampled using a macroplot
110

    
111
plots6 = subset(plots5, is.na(MACRO_BREAKPOINT_DIA))
112

    
113

    
114
### Update all table to have the same plots ###
115

    
116
good.plots = unique(plots6$yrplot.id)
117

    
118
these.conds = COND.table[COND.table$yrplot.id %in% good.plots,]
119
these.subps = SUBP.table[SUBP.table$yrplot.id %in% good.plots,]
120
these.seeds = SEED.table[SEED.table$yrplot.id %in% good.plots,]
121
these.trees = TREE.table[TREE.table$yrplot.id %in% good.plots,]
122

    
123

    
124
trees = rbind(trees, these.trees)
125
plots = rbind(plots, plots6)
126
conds = rbind(conds, these.conds)
127
subps = rbind(subps, these.subps)
128
seeds = rbind(seeds, these.seeds)
129

    
130

    
131
}#closes for loop
132

    
133

    
134
setwd('../Parsed_Data')
135

    
136

    
137
save("trees","plots","subps","conds","seeds","states", file=paste('FIA_east_parsed_',Sys.Date(),'.Rdata',sep=''))
138

    
139
write.csv(trees, paste('FIA_east_parsed_',Sys.Date(),'_tree.csv',sep=''), row.names=F )
140

    
141
write.csv(plots, paste('FIA_east_parsed_',Sys.Date(),'_plot.csv',sep=''), row.names=F )
142

    
143
write.csv(subps, paste('FIA_east_parsed_',Sys.Date(),'_subp.csv',sep=''), row.names=F )
144

    
145
write.csv(conds, paste('FIA_east_parsed_',Sys.Date(),'_cond.csv',sep=''), row.names=F )
146

    
147
write.csv(seeds, paste('FIA_east_parsed_',Sys.Date(),'_seedling.csv',sep=''), row.names=F )
148

    
149

    
150

    
151
subps = subps[,c('plot.id','yrplot.id','STATECD','COUNTYCD',
152
		'PLOT','INVYR','SUBP','SUBPCOND','SLOPE','ASPECT',
153
		'SUBP_STATUS_CD')]
154
plots = plots[,c('plot.id','yrplot.id','STATECD','COUNTYCD',
155
		'PLOT','INVYR','MEASYEAR','LAT','LON','ELEV',
156
		'ECOSUBCD','RDDISTCD','MANUAL')]
157

    
158
conds = conds[,c('plot.id','yrplot.id','STATECD','COUNTYCD',
159
		'PLOT','INVYR','CONDID','PHYSCLCD','FLDTYPCD',
160
		'STDAGE','FLDSZCD','DSTRBCD1','DSTRBCD2','DSTRBCD3')]
161

    
162
trees = trees[,c('plot.id','yrplot.id','STATECD','COUNTYCD',
163
		'PLOT','INVYR','SUBP','STATUSCD','SPCD','DIA','DIAHTCD','HT',
164
		'ACTUALHT','CCLCD','CPOSCD')]
165

    
166
seeds = seeds[,c('plot.id','yrplot.id','STATECD','COUNTYCD',
167
		'PLOT','INVYR', 'SUBP', 'CONDID', 'SPCD','TREECOUNT','TREECOUNT_CALC')]
168

    
169
### Remove bad subplot numbers
170

    
171
trees = subset(trees, SUBP<=4)
172

    
173
### Remove dead trees
174

    
175
trees = subset(trees, STATUSCD == 1)
176

    
177

    
178
save("trees","plots","subps","conds","seeds","states", file=paste('FIA_DBDGS_',Sys.Date(),'.Rdata',sep=''))
179

    
180

    
181

    
182

    
183

    
184

    
185

    
186

    
187

    
188

    
189

    
190

    
191

    
192

    
193

    
194

    
195

    
(63-63/63)