# This script was written by Jes Coyle to filter out unwanted FIA plots for eastern states. ######################################################### ### Functions # A function that creates a unique identifier for a plot make.plotid = function(x){ paste(x$STATECD, x$COUNTYCD, x$PLOT, sep = '_') } # A function that creates a unique identifier for a plot in a particular year make.yrplotid = function(x){ paste(x$INVYR, x$STATECD, x$COUNTYCD, x$PLOT, sep = '_') } ######################################################### ### Read in Data setwd('/gpfs/nfs/share/ftp/priv/priv/Groups/DBDGS/FIA/RawData') ######################################################### ### Code states = c('AL', 'AR', 'CT', 'DE', 'FL', 'GA', 'IA', 'IL', 'IN', 'KY', 'LA', 'MA', 'MD', 'ME', 'MI', 'MN', 'MO', 'MS', 'NC', 'NH', 'NJ', 'NY', 'OH', 'PA', 'RI', 'SC', 'TN', 'VA','VT', 'WI', 'WV') # Make data frames to hold combined data trees = c() plots = c() subps = c() conds = c() seeds = c() for(i in states){ COND.table = read.csv(paste('./Conditions/',i,'_COND.CSV',sep = '')) PLOT.table = read.csv(paste('./Plots/',i,'_PLOT.CSV',sep = '')) TREE.table = read.csv(paste('./Trees/',i,'_TREE.CSV',sep = '')) SUBP.table = read.csv(paste('./Subplots/',i,'_SUBPLOT.CSV',sep = '')) SEED.table = read.csv(paste('./Seedlings/',i,'_SEEDLING.CSV',sep = '')) COND.table$plot.id = make.plotid(COND.table) COND.table$yrplot.id = make.yrplotid(COND.table) PLOT.table$plot.id = make.plotid(PLOT.table) PLOT.table$yrplot.id = make.yrplotid(PLOT.table) TREE.table$plot.id = make.plotid(TREE.table) TREE.table$yrplot.id = make.yrplotid(TREE.table) SUBP.table$plot.id = make.plotid(SUBP.table) SUBP.table$yrplot.id = make.yrplotid(SUBP.table) SEED.table$plot.id = make.plotid(SEED.table) SEED.table$yrplot.id = make.yrplotid(SEED.table) ### Subset based on condition table ### ## Find all plots that have a non forest land condition in any survey year # A list of plots with a non-forest condition on them non.forest.conds = subset(COND.table, COND_STATUS_CD!=1)$yrplot.id # Restrict further analysis of conditions to conditions that are forested (because unforested conditions have missing values for variables) cond1 = subset(COND.table, COND_STATUS_CD==1) ## Find all plots that have artificial regeneration art.regen.conds = subset(cond1, STDORGCD == 1)$yrplot.id ## Find plots with evidence of human disturbance human.conds = subset(cond1, (DSTRBCD1==80)|(DSTRBCD2==80)|(DSTRBCD3==80)|(TRTCD1!=0)|(TRTCD2!=0)|(TRTCD3!=0))$yrplot.id ## Remove all plots that are on the lists to exclude from the plots table bad.plots = unique(c(non.forest.conds, art.regen.conds, human.conds)) plots1 = PLOT.table[!(PLOT.table$yrplot.id %in% bad.plots),] ### Subset based on plot table ### ## Only use plots with national design plots2 = subset(plots1, DESIGNCD %in% c(1,115,311,312,313,314)) ## Only use sampled plots plots3 = subset(plots2, PLOT_STATUS_CD==1) ## Remove botched plot files plots4 = subset(plots3, QA_STATUS != 5) ## Only use plots that were visited in the field plots5 = subset(plots4, SAMP_METHOD_CD==1) ## Remove plots that were sampled using a macroplot plots6 = subset(plots5, is.na(MACRO_BREAKPOINT_DIA)) ### Update all table to have the same plots ### good.plots = unique(plots6$yrplot.id) these.conds = COND.table[COND.table$yrplot.id %in% good.plots,] these.subps = SUBP.table[SUBP.table$yrplot.id %in% good.plots,] these.seeds = SEED.table[SEED.table$yrplot.id %in% good.plots,] these.trees = TREE.table[TREE.table$yrplot.id %in% good.plots,] trees = rbind(trees, these.trees) plots = rbind(plots, plots6) conds = rbind(conds, these.conds) subps = rbind(subps, these.subps) seeds = rbind(seeds, these.seeds) }#closes for loop setwd('../Parsed_Data') save("trees","plots","subps","conds","seeds","states", file=paste('FIA_east_parsed_',Sys.Date(),'.Rdata',sep='')) write.csv(trees, paste('FIA_east_parsed_',Sys.Date(),'_tree.csv',sep=''), row.names=F ) write.csv(plots, paste('FIA_east_parsed_',Sys.Date(),'_plot.csv',sep=''), row.names=F ) write.csv(subps, paste('FIA_east_parsed_',Sys.Date(),'_subp.csv',sep=''), row.names=F ) write.csv(conds, paste('FIA_east_parsed_',Sys.Date(),'_cond.csv',sep=''), row.names=F ) write.csv(seeds, paste('FIA_east_parsed_',Sys.Date(),'_seedling.csv',sep=''), row.names=F ) subps = subps[,c('plot.id','yrplot.id','STATECD','COUNTYCD', 'PLOT','INVYR','SUBP','SUBPCOND','SLOPE','ASPECT', 'SUBP_STATUS_CD')] plots = plots[,c('plot.id','yrplot.id','STATECD','COUNTYCD', 'PLOT','INVYR','MEASYEAR','LAT','LON','ELEV', 'ECOSUBCD','RDDISTCD','MANUAL')] conds = conds[,c('plot.id','yrplot.id','STATECD','COUNTYCD', 'PLOT','INVYR','CONDID','PHYSCLCD','FLDTYPCD', 'STDAGE','FLDSZCD','DSTRBCD1','DSTRBCD2','DSTRBCD3')] trees = trees[,c('plot.id','yrplot.id','STATECD','COUNTYCD', 'PLOT','INVYR','SUBP','STATUSCD','SPCD','DIA','DIAHTCD','HT', 'ACTUALHT','CCLCD','CPOSCD')] seeds = seeds[,c('plot.id','yrplot.id','STATECD','COUNTYCD', 'PLOT','INVYR', 'SUBP', 'CONDID', 'SPCD','TREECOUNT','TREECOUNT_CALC')] ### Remove bad subplot numbers trees = subset(trees, SUBP<=4) ### Remove dead trees trees = subset(trees, STATUSCD == 1) save("trees","plots","subps","conds","seeds","states", file=paste('FIA_DBDGS_',Sys.Date(),'.Rdata',sep=''))