hunter-stanke / rFIA

rFIA
https://rfia.netlify.com/
47 stars 23 forks source link

readFIA feature wish #5

Closed djj4tree closed 4 years ago

djj4tree commented 4 years ago

Would it be possible to add a 'states =' argument to the readFIA function? This way the user can define which states they want to load in if they have several downloaded but only want to use a subset. I think this would be beneficial for folks wanting to do regional analyses.

hunter-stanke commented 4 years ago

Definitely possible. Would be nice if data didn't need to be duplicated on disk just for the read. I will get something put together later this week and let you know when it's up.

hunter-stanke commented 4 years ago

Just updated readFIA, a fresh install from Github and you should be good to go. Note that readFIA now includes the states argument, which allows the user to read in selected states from a common directory. For example, if you downloaded all states in the Northeast and stored the data together for regional analysis, but for now only want to read in MA, simply specify states = 'MA'

Here is an example:

## Set up a directory to store data
d <- 'my/test/directory/'

## Store RI, MA, and CT in same directory
getFIA(c('CT', 'RI', 'MA'), dir = d)

## Read CT only
ct <- readFIA(d, states = 'CT')
summary(ct)
---- FIA Database Object ----- 
Reporting Years:  1985 1998 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 
States:           CONNECTICUT 
Total Plots:      1813 
Memory Used:      77.3 Mb 
Tables:           COND COND_DWM_CALC INVASIVE_SUBPLOT_SPP PLOT POP_ESTN_UNIT POP_EVAL POP_EVAL_GRP POP_EVAL_TYP POP_PLOT_STRATUM_ASSGN POP_STRATUM SEEDLING SUBP_COND SUBP_COND_CHNG_MTRX SUBPLOT SURVEY TREE TREE_GRM_BEGIN TREE_GRM_COMPONENT TREE_GRM_MIDPT

## Read RI only
ri <- readFIA(d, states = 'RI')
summary(ri)
---- FIA Database Object ----- 
Reporting Years:  1985 1998 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 
States:           RHODE ISLAND 
Total Plots:      769 
Memory Used:      32 Mb 
Tables:           COND COND_DWM_CALC INVASIVE_SUBPLOT_SPP PLOT POP_ESTN_UNIT POP_EVAL POP_EVAL_GRP POP_EVAL_TYP POP_PLOT_STRATUM_ASSGN POP_STRATUM SEEDLING SUBP_COND SUBP_COND_CHNG_MTRX SUBPLOT SURVEY TREE TREE_GRM_BEGIN TREE_GRM_COMPONENT TREE_GRM_MIDPT

## Read in RI & CT, but not MA
ri_ct <- readFIA(d, states = c('RI', 'CT'))
summary(ri_ct)
---- FIA Database Object ----- 
Reporting Years:  1985 1998 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 
States:           CONNECTICUT RHODE ISLAND 
Total Plots:      2582 
Memory Used:      109.1 Mb 
Tables:           COND COND_DWM_CALC INVASIVE_SUBPLOT_SPP PLOT POP_ESTN_UNIT POP_EVAL POP_EVAL_GRP POP_EVAL_TYP POP_PLOT_STRATUM_ASSGN POP_STRATUM SEEDLING SUBP_COND SUBP_COND_CHNG_MTRX SUBPLOT SURVEY TREE TREE_GRM_BEGIN TREE_GRM_COMPONENT TREE_GRM_MIDPT

## Read in all states in the directory
allStates <- readFIA(d)
summary(allStates)
---- FIA Database Object ----- 
Reporting Years:  1985 1998 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 
States:           CONNECTICUT MASSACHUSETTS RHODE ISLAND 
Total Plots:      5497 
Memory Used:      257.1 Mb 
Tables:           COND COND_DWM_CALC INVASIVE_SUBPLOT_SPP PLOT POP_ESTN_UNIT POP_EVAL POP_EVAL_GRP POP_EVAL_TYP POP_PLOT_STRATUM_ASSGN POP_STRATUM SEEDLING SUBP_COND SUBP_COND_CHNG_MTRX SUBPLOT SURVEY TREE TREE_GRM_BEGIN TREE_GRM_COMPONENT TREE_GRM_MIDPT
djj4tree commented 4 years ago

This is awesome. Thanks Hunter!

hunter-stanke commented 4 years ago

Anytime!