Giter Site home page Giter Site logo

rfia's People

Contributors

badgley avatar graysonwhite avatar hunter-stanke avatar markfairbanks avatar whalend avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rfia's Issues

readFIA throws an error

The following code is throwing an error in version 0.2.4:

# download FIA data for CA, OR, and NV. Write to a local directory; or if it's 
# already been downloaded, just read it from the local 
fiadb = 
  if (!file.exists(here::here('02-data', '00-source', 'fia', 'CA_PLOT.csv'))){
    getFIA(states = c('CA', 'OR', 'NV'),
           dir = here::here('02-data',
                            '00-source',
                            'fia'))
  } else {
    readFIA(here::here('02-data',
                       '00-source',
                       'fia'))
    
  }

I'm getting the error message Error in rbindlist(inTables[names(inTables) == uniqueNames[i]]) : Class attribute on column 15 of item 3 does not match with column 15 of item 1.

Am I doing something wrong or is this a bug?

When using states = 'ENTIRE', inMemory = FALSE, estimates fail

After acquiring data and loading it for the entire USA, estimates fail including volume, biomass, etc.:

Get the entire USA

usa <- getFIA(states = 'ENTIRE', dir=dataDir, load = FALSE)

Load previously downloaded FIA data

usa <- readFIA(dir=dataDir, inMemory = FALSE, states = 'ENTIRE')

Get the volume over time

volume(usa)

fails:
Error in readFIA(dir = db$dir, common = db$common, tables = reqTables, :
Data unavailable for: ENTIRE . States not found in specified directory.

Failure with dev dtplyr

library(rFIA)

data(fiaRI)
fiaRI_mr <- clipFIA(fiaRI)

area(db = fiaRI_mr)
#> Error in `dplyr::select()`:
#> ! Can't subset columns that don't exist.
#> ✖ Column `fad_mean` doesn't exist.

Created on 2023-02-14 with reprex v2.0.2

This seems to be because aEst has column fad_mean_mean instead of fad_mean but I can't figure out where that's calculated to tell if it's a dtplyr bug or a rFIA bug.

FIA databases appear to be inaccessible

I am having this issue:
Saving to C:/Users/ssesnie/A_Sesnie/ztemp/rfia/. NOTE: modifying FIA tables in Excel may corrupt csv files.
trying URL 'https://apps.fs.usda.gov/fia/datamart/CSV/TX.zip'
Error in download.file(url, temp) :
cannot open URL 'https://apps.fs.usda.gov/fia/datamart/CSV/TX.zip'
In addition: Warning message:
In download.file(url, temp) :
cannot open URL 'https://apps.fs.usda.gov/fia/datamart/CSV/TX.zip': HTTP status was '404 Not Found'

I don't think it is a problem with rFIA. There is a message here indicating a problem at FIA:
https://apps.fs.usda.gov/fia/datamart/CSV/datamart_csv.html

I can reach out to FIA, if that is the best course of action.

Error when downloading tables for several states

Hi there,

I recently updated to the dev version so that I could download some new tables with the change to the URLs on the datamart, but I now get this error if I try to download data for more than one state. Here's an example:

> getFIA(states =  c("RI", "CT"),
+        dir = 'D:/Data/fia/rFIA_downloads/',
+        common = TRUE,
+        load = FALSE)
Saving to D:/Data/fia/rFIA_downloads/. NOTE: modifying FIA tables in Excel may corrupt csv files.
Error in if (states == "REF") { : the condition has length > 1

I think the error happens in line 441 here: b80e180

I think it could be fixed if you were to check if the length of states was >1, and then check if any of those states are "REF", and throw an error in that case.

It also looks like the "ENTIRE" option is broken, perhaps due to the datamart update. I get this error if I try it:

trying URL 'https://apps.fs.usda.gov/fia/datamart/CSV/ENTIRE_CSV.zip'
Error in download.file(url, temp, timeout = 3600) :
cannot open URL 'https://apps.fs.usda.gov/fia/datamart/CSV/ENTIRE_CSV.zip'
In addition: Warning messages:
1: In download.file(url, temp, timeout = 3600) :
downloaded length 0 != reported length 1245
2: In download.file(url, temp, timeout = 3600) :
cannot open URL 'https://apps.fs.usda.gov/fia/datamart/CSV/ENTIRE_CSV.zip': HTTP status was '404 Not Found'

Thanks for putting together such a useful package! Let me know if I can help troubleshoot.

mergeSmallStrata(): 'buf' not 'buff' to id intensified PNW strata

I found my way to your mergeSmallStrata function when looking for options to automatically merge small-n strata. I've been working with the PNW FIA data (SQLite dbs from the DataMart) and noticed this function's code currently uses the string 'buff' when trying to identify intensified strata. When looking at STRATUM_DESCR, I see 'buf' (one f) and 'int', but not 'buff'.

(Although I am not completely convinced 'buf|int' is sufficient to identify intensified strata: in the set of plots I am working with, the absence of 'buf|int' does not always correspond to plot.INTENSITY = 1. For example, STRATUMCD = 11 and EVALID = 531903.)

Issue with getFIA - url connects to 404 page

fia_states <- c('ID', 'MT', 'WY')
fia.dwnld <- getFIA(states = fia_states,
tables = c('PLOT','COND','SOILS_LAB','SOILS_SAMPLE_LOC'))

I am a very green beginner with rFIA, but cannot find any other online resources to help me with this issue. When I enter the code above, I get the warning message below:

Error in download.file(urls[n], temp, timeout = 3600) :
cannot open URL 'https://apps.fs.usda.gov/fia/datamart/CSV/REF_PLOT.zip'

In addition: Warning message:
In download.file(urls[n], temp, timeout = 3600) :
cannot open URL 'https://apps.fs.usda.gov/fia/datamart/CSV/REF_PLOT.zip': HTTP status was '404 Not Found'

rFIA::tpa() removes trees with no measured DIA

Many revisited mortality trees don't have DIA recorded (at least in western states), which leads tpa() to do some dramatic under-counting when type="all" or "dead". I can understand the reasoning behind this choice, especially when estimating anything other than TPA. One solution would be to include these trees in TPA estimates, and use PREVDIA (with a disclaimer) when necessary.

Possibly not a problem many people will run into, but thought it worth pointing out!

Thanks,
Daniel Perret

Difficulty using huc watersheds as polygons

Hello!

I am running into trouble using VT HUC_12_watershed polygons in a tpa function. The code runs, but outputs a table with 26 variables and no observations. The polygons are stored in a SpatialPolygonsDataFrame. Maybe they are too geographically small? My code (which is super straightforward) is below.

set wd

setwd("/Users/Liza/OneDrive - Dartmouth College/BigDataHydrology/Final_Project")

Clear environment

rm(list = ls())

Libraries

library(rFIA)
library(RSQLite)
library(data.table)
library(sf)
library(rgdal)
library(here)

READ FIA DATA

Downloaded from FIA datahub SQL file using fix from Github

And keep only most recent data from each plot

fiaVT = readFIA("/Users/Liza/OneDrive - Dartmouth College/BigDataHydrology/Final_Project/VT_FIA_data", common = TRUE)
fiaVT = fiaVT_recent <- clipFIA(fiaVT, mostRecent = TRUE)

GET WATERSHED POLY

Downloaded from https://geodata.vermont.gov/datasets/vt-subwatershed-boundaries-huc12/explore

huc12_vt <- readOGR(dsn = '/Users/Liza/Library/CloudStorage/OneDrive-DartmouthCollege/BigDataHydrology/Final_Project/Watershed_shapefiles/VT_Subwatershed_Boundaries_-HUC12', layer = 'VT_Subwatershed_Boundaries-_HUC12')

Calculate tpa for each watershed

tpaHUC <- tpa(fiaVT, polys = huc12_vt, returnSpatial = TRUE)

Summarizing by subplot gives wrong values

My colleague and I were going over some numbers that he generated using rFIA and grouping by SUBP. He compared those to values that I had scripted out by aggregating from TREE table that I pulled directly from FIADB. The data from the tree tables were both identical; the issue came when summarizing at the subplot level. rFIA values of TPA and total BA were too low when grouped by the subplot level. We determined that this is because, in rFIA, the TPA_UNADJ is not being multiplied by 4 to account for the smaller area in a subplot compared to the entire plot. This is a major problem for anyone using rFIA for subplot level aggregations who is unaware that the returned values should be multiplied by 4 to be correct.

I see 2 potential solutions - it could be either preventing aggregation at the subplot level, or altering the rFIA package so that when SUBP is selected as a grouping variable, TPA_UNADJ is multiplied by 4. There may be another solution that I’m not considering.

Thanks for addressing this.

-Erin Berryman (RMRS-FIA)

'invasive' function not finding INVASIVE_SUBPLOT_SPP table

I've pulled the FIAPNW.db (using the manual method mentioned in another thread) and am trying to use the 'invasive' function on a FIA database. I've used the readFIA function to pull the CSVs into the database. Originally I ran 'invasives' and it told me that several tables were not found.
I re-read the CSVs into the database, specifying each table that was missing. Now all tables are in the database. I ran 'invasives' again and this time only one table, 'INVASIVE_SUBPLOT_SPP', was not found. All the other tables seem to be fine now, and even this table is listed with the others in the database.
I've checked the spelling and it matches. Am I missing something? Or is there something different about this particular table?

setwd("D:/Project/") FIAWA_InvTables<-readFIA(dir='WA', states='WA', tables=c('INVASIVES_PNWRS', 'INVASIVE_PLOT_SPECIES_TBL', 'INVASIVE_SUBPLOT_SPP_TBL', 'PLOT', 'SUBP_COND', 'COND', 'POP_PLOT_STRATUM_ASSGN', 'POP_ESTN_UNIT', 'POP_EVAL', 'POP_STRATUM', 'POP_EVAL_TYP', 'POP_EVAL_GRP')) invasives_test<-invasive(FIAWA_InvTables, byPlot=T, returnSpatial=T)

Returns this error:
> invasives_test<-invasive(FIAWA_InvTables, byPlot=T, returnSpatial=T) Error in readRemoteHelper(x, db, remote, reqTables, nCores) : INVASIVE_SUBPLOT_SPP tables not found in object db.

Here's the view of the database.
image

Any insight would be much appreciated!

growMort function not recognizing all treeTypes

I am having an issue with the growMort() function returning error:

ct <- getFIA(states = 'MN', dir = '/path')
kl<-growMort(db = ct,
bySpecies = TRUE,
landType = 'timber',
treeType = 'live',
totals = TRUE)
returns:
Error: Can't subset columns that don't exist.
x Column SUBPTYP_GRM doesn't exist.

I am seeing the same error when trying treeType= 'dead'

However:
kl<-growMort(db = ct,
bySpecies = TRUE,
landType = 'timber',
treeType = 'all',
totals = TRUE)

completes. This also completes with 'gs'

df issue in udTreeDomain() within biomass()

Intro

Hi,
I was trying to run the biomass() function in reproducing some open scripts (run_assessment_areas.R) which use the rFIA library.

The error I get is not particularly insightful and I was wondering if biomass() + udTreeDomain() had beed tested yet following the recent release of .csv's from the DataMart? (potentially related issue no.35)

Many thanks in advance,
Harry

Error message in udTreeDomain()

udTreeDomain(db, treeDomain)

Error in `$<-.data.frame`(`*tmp*`, "tD", value = 1) : 
  replacement has 1 row, data has 0

The most similar error message I can find relates to df shape.

Reproducible Example and SystemInfo

I have attached a reproducible example in in my GoogleDrive. The original open script+.shp files are available from Zenodo but I have downloaded some FIA dummy data (first 1000rows only) for a single state due to Rstudio's memory limit on M1 Mac OS's.
For similar reasons I am trialling a single area within the state of ME which is as follows:

$assessment_area_id
[1] 10

$fortypcds
[1] 125 126 127

$supersection_name
[1] "Aroostook Hills and Lowlands"

$supersection_id
[1] 3

$postal_codes
[1] "ME"

The session info

R version 4.2.1 (2022-06-23)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Monterey 12.6

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib

locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rFIA_1.0.1   dplyr_1.0.10 rjson_0.2.21 rgdal_1.5-32 sp_1.5-0    

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.9         pillar_1.8.1       compiler_4.2.1     dtplyr_1.2.2       remotes_2.4.2      class_7.3-20       tools_4.2.1        bit_4.0.4          lifecycle_1.0.3    tibble_3.1.8      
[11] gtable_0.3.1       lattice_0.20-45    pkgconfig_2.0.3    rlang_1.0.6        cli_3.4.1          DBI_1.1.3          rstudioapi_0.14    parallel_4.2.1     e1071_1.7-12       withr_2.5.0       
[21] stringr_1.4.1      generics_0.1.3     vctrs_0.5.0        classInt_0.4-8     bit64_4.0.5        grid_4.2.1         tidyselect_1.2.0   glue_1.6.2         data.table_1.14.4  sf_1.0-8          
[31] R6_2.5.1           fansi_1.0.3        purrr_0.3.5        tidyr_1.2.1        ggplot2_3.3.6      magrittr_2.0.3     units_0.8-0        scales_1.2.1       colorspace_2.0-3   KernSmooth_2.23-20
[41] utf8_1.2.2         stringi_1.7.8      proxy_0.4-27       munsell_0.5.0   

readFIA issues

I am just getting back to rFIA so by no means an expert. in my R code:
db <- getFIA(states = 'ME')
writeFIA(db, dir = "./FIAData")

Getting saved FIA data

db <- readFIA(dir = "./FIAData/")

I have tried several versions of my readFIA call with no success, this is error message.....

Error in fread(paste(dir, files[n], sep = ""), showProgress = FALSE, integer64 = "double", :
File './FIAData/NA' does not exist or is non-readable. getwd()=='C:/Users/iprior/OneDrive - Seven Islands Land Co/3-Analytics/R/R_Scripts/rFIA'

It has written the data to the specified location, for whatever reason it will not load this saved data, any ideas?

I have tried this on local drives with the same result, a different error message...

writeFIA(db, dir = "C:/temp")
Saving to C:/temp/. NOTE: modifying FIA tables in Excel may corrupt csv files.

dbLoad <- readFIA("C:/temp")
Error in fread(paste(dir, files[n], sep = ""), showProgress = FALSE, integer64 = "double", :
File 'c:/temp/NA' does not exist or is non-readable. getwd()=='C:/Users/iprior/OneDrive - Seven Islands Land Co/3-Analytics/R/R_Scripts/rFIA'

I have read/write permissions on these folders. Any ideas?

Thanks!

polys produces error with new version of sf

Just a note for folks that may encounter this issues with rFIA version 0.2.2 or older.

New version of sf (version >= 0.9-2) causes rFIA (version <= 0.2.2) to fail when polys is specified. You will see an error message along the lines of:

 Error in checkForRemoteErrors(val) : 
  one node produced an error: st_crs(x) == st_crs(y) is not TRUE

This issues has been fixed in rFIA version 0.2.3 (currently available on GitHub). Thus a fresh install from GitHub (and from CRAN after June 1 2020) will take care of it:

devtools::install_github('hunter-stanke/rFIA')

Add support for growth, removals, and mortality on changing land bases

rFIA v3.0.0 and older does not support estimation of growth, removals, and/or mortality (GRM) on lands that have reverted from non-forest to forest or been converted from forest to non-forest between plot visits. That is, GRM estimates only include plots that were forested at initial visit and remain forested at remeasurement. As EVALIDator suggests, this may give a more "realistic" view of the change components in forests that remain in the forested land basis. However, it is often totals that are of interest (e.g., total removals including those arising from conversion), and our current implementation lacks support for this.

I'll work on adding support to growMort and vitalRates this week. Likely in the form of an additional logical argument in each function - I'd rather keep totals as a simple dplyr::select and not allow it to affect estimation, consistent with all other functions. Open to alternative ideas and suggestions for argument names. I'll update this thread once all is up and running.

growMort function won't run

Hello,

When I attempt to use the growMort function it runs for a while but then hits an error and tells me that it cannot find the variable P2PNTCNT_EU. When I look for this in the FIADB user guide I also cannot find it. Has it changed name and is still in the data in a different form, or is this function now fundamentally broken because of the absence of this variable. The data I am using comes from NC if that helps.

Cheers,

Louis

SEs for carbon

The standard errors produced for the total carbon estimates seem much too small (>0.00001), but I could be wrong. Just want to make sure I'm representing the data correctly.

Capture

car_ct_ag<-carbon(db, grpBy = c(COUNTYCD), polys = NULL, returnSpatial = FALSE,
byPool = TRUE, byComponent = FALSE, modelSnag = TRUE,
landType = "forest", method = "TI", lambda = NULL,
areaDomain = NULL, totals = TRUE, byPlot = FALSE,
nCores = 1)

#Looking at just total AGB for Addison County
car_ct_ag1<-car_ct_ag %>%
full_join(ctcodes, by = c ("COUNTYCD" = "Code")) %>%
filter(POOL == "AG_LIVE") %>%
filter(County == "Addison")

readFIA and getFIA error

I am trying to combine multiple states into one database. The getFIA function "getFIA(dir = "./Data", states=c("RI","ND"))" downloads the data fine, but when combining the tables it throws this error.

"Error in rbindlist(inTables[names(inTables) == uniqueNames[i]]) :
Item 42 has 52 columns, inconsistent with item 1 which has 72 columns. To fill missing columns use fill=TRUE."

It also happens in the same spot in the code for the readFIA function: readFIA(dir="./Data/")

I haven't been able to find the offending table that has inconsistent numbers of columns.
I am only using the 'common' tables.

area() estimation breaks for landType='water'

Hi Hunter,

I'm getting a bug in the land area estimation for water:

data("fiaRI")
area(fiaRI, landType='water')

yields:
Error in ifelse(COND_STATUS_CD == 3 | COND_STATUS_CD == 4) : argument "yes" is missing, with no default.

Same for landType='census water' and 'non-census-water'. 'forest' works, however.

I'm using the devtools version of the package, downloaded this am (4/12/2021).

sessionInfo() output is:

R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS  10.16

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] parallel  stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rFIA_0.3.2        tigris_1.0        sp_1.4-4          sf_0.9-8          data.table_1.14.0 doParallel_1.0.16 iterators_1.0.13  foreach_1.5.1    

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.6         dtplyr_1.1.0       pillar_1.5.1       compiler_4.0.2     class_7.3-17       tools_4.0.2        bit_4.0.4          uuid_0.1-4         gtable_0.3.0       lifecycle_1.0.0    tibble_3.1.0      
[12] lattice_0.20-41    pkgconfig_2.0.3    rlang_0.4.10       DBI_1.1.1          rgdal_1.5-18       yaml_2.2.1         e1071_1.7-6        stringr_1.4.0      dplyr_1.0.5        httr_1.4.2         rappdirs_0.3.1    
[23] generics_0.1.0     vctrs_0.3.7        bit64_4.0.5        classInt_0.4-3     grid_4.0.2         tidyselect_1.1.0   glue_1.4.2         R6_2.5.0           fansi_0.4.2        foreign_0.8-80     tidyr_1.1.3       
[34] ggplot2_3.3.3      purrr_0.3.4        magrittr_2.0.1     scales_1.1.1       codetools_0.2-18   ellipsis_0.3.1     units_0.7-1        maptools_1.0-2     assertthat_0.2.1   colorspace_2.0-0   KernSmooth_2.23-18
[45] utf8_1.2.1         stringi_1.5.3      proxy_0.4-25       munsell_0.5.0      crayon_1.4.1      

Thanks

getFIA with multiple states

When combining states, getFIA appears to have an issue.

Example 1:

fiaNE <- rFIA::getFIA(states=c("CT","ME","MA","NH","RI","VT"))

Error reported:

Error in rbindlist(inTables[names(inTables) == uniqueNames[i]]) : 
  Class attribute on column 17 of item 3 does not match with column 17 of item 1.

Example 2:

fiaMid <- rFIA::getFIA(states=c("DE","MD"))

Error reported:

Error in rbindlist(inTables[names(inTables) == uniqueNames[i]]) : 
  Class attribute on column 17 of item 2 does not match with column 17 of item 1.

It's odd, but it does appear that anything else I try to load after this failure appreciates the same error; even a simple getFIA for a single state that works fine under a new RStudio session will produce the error above if run after one of the examples above, like:

fiaDE <- rFIA::getFIA(states="DE")

Version info:

packageVersion("rFIA")
[1] ‘0.2.3’

Planning for release?

On the CRAN version of rFIA, I see a failure with dev dtplyr:

library(rFIA)
fiaRI_mr <- clipFIA(fiaRI)
area(db = fiaRI_mr)
#> Error in fifelse(sum(aDI > 0, na.rm = TRUE), 1, 0): Argument 'test' must be logical.

Created on 2021-10-15 by the reprex package (v2.0.1)

This is because dtplyr now translates ifelse() to data.table::fifelse(), which is stricter about the types of its arguments.

I don't see this error in the dev version, so I was wondering if you were planning to release soon? I don't want to break your package on CRAN by updating dtplyr.

Duplicated rows in PLOT table

Thanks for this package; it's really making the FIA data much more accessible!

I have a question about the PLOT table produced by getFIA and readFIA. I used getFIA() to pull FIA plots from CA, OR, and NV which fell within a large AOI polygon (the range of sugar pine). When I read in the .csv files with readFIA(), the PLOT table has what look like duplicate rows: Every column is identical except for the final 'prev', which has value 0 for one row and 1 for the other. From what I can tell, 'prev' is an internal column created by rFIA and not part of the original FIA database.

Am I correct in my belief that PLT_CN is the unique observation identifier for the PLOT table? Am I correct in assuming that there should only be one (unique) PLT_CN in the PLOT table, and that the duplicate rows are not intended behavior?

Here's my script which writes a PLOT.csv with duplicated-except-for-prev rows:

#  DEFINE AOI AND FETCH FIA DATA
#

#### setup #####################################################################

library(here)
library(rFIA)
library(tidyverse)
library(sf)
library(tmap)

# download FIA data for CA, OR, and NV. Write to a local directory.
#fia_all = 
#  getFIA(states = c('CA', 'OR', 'NV'),
#       dir = here::here('02-data',
#                        '00-source',
#                        'fia'))

# when re-running this script, just read the local version.
fia_all = 
  readFIA(here::here('02-data',
                     '00-source',
                     'fia'))

# pila range from Digital representation of "Atlas of United States Trees" by 
# Elbert L. Little, Jr.; digitized by Robert S. Thompson and accessed at 
# https://github.com/wpetry/USTreeAtlas. 
pila_range = 
  sf::st_read(here::here('02-data',
                       '00-source',
                       'ustreeatlas',
                       'pinulamb.shp')) %>%
  # the original crs, as described in the metadata for the digitized version
  sf::st_set_crs('+proj=longlat +datum=NAD27 +no_defs') %>%
  # the CRS of the FIA data
  sf::st_transform(crs = sf::st_crs('+proj=longlat +datum=WGS84 +no_defs'))


# clip FIA data to just the AOI
fia_aoi = 
  fia_all %>%
  rFIA::clipFIA(mostRecent = FALSE,
                mask = pila_range)

# save the clipped database locally
rFIA::writeFIA(fia_aoi,
               dir = here::here('02-data',
                                '01-preprocessed',
                                'fia'))````

Increased support for merchantable tree volume estimation?

I'm considering making some changes to rFIA that would substantially improve its capacity to estimate current tree volume. Right now, we can produce current tree volume estimates (i.e., net merchantable volume and sawlog volume) using the biomass function. However, I think it would be cleaner to simplify biomass to only produce tree biomass/carbon estimates and write a separate function that is focused exclusively on merchantable tree volume. I'd like to call it volume, but open to alternatives if this would cause conflicts with other commonly used packages - looks like spatstat and cluster also use it.

In developing the new function, I'm proposing that we expand the scope of volume variables to include net, sound, and gross bole volume (cu. ft.) and saw log volume (cu. ft. and MBF via International 1/4" rule). This would nearly match EVALIDator's current capacity.

Any strong feelings for or against the proposed changes? Of course the changes to biomass would be breaking, however I don't anticipate folks' workflows would have to be changed that much to account for it. Please let me know if that is not the case!

seemingly strange behavior from customPSE()

I think I'm seeing some odd behavior from customPSE() when making area:area ratio estimates using a spatial mask to define the areal estimation boundaries.  If I use a mask that crosses state boundaries, customPSE() seems to return a different estimate made from the CONDs in different states, rather than an estimate for the entire area.  This doesn't happen when I just calculate forested area using the area() function.  This also doesn't happen for all state boundaries, from what I can tell it's mainly for states in the SRS, and it doesn't seem to be related to year.  In this MRE there are different years associated with the two estimates returned from customPSE(), but in others instances the year has been the same. Apologies in advance if I'm doing something stupid. I'm using the devtools version of rFIA, which I reinstalled today to make sure its not a package versioning issue on my end.

MRE:

library(rFIA)
library(sf)
library(dplyr)

set.seed(54)

lon = c(-83, -82)
lat = c(38, 39)
Poly_Coord_df = data.frame(lon, lat)

poly = st_polygon(
  list(
    cbind(
      Poly_Coord_df$lon[c(1,2,2,1,1)], 
      Poly_Coord_df$lat[c(1,1,2,2,1)])
  )
) %>% st_sfc(crs=4326) %>% st_sf()


FIA <- readFIA('/Volumes/RESEARCH/rFIA/original_data', nCores=10, inMemory=T, states=c('WV','OH','KY')) 
fia <- clipFIA(FIA, mostRecent=T, mask=poly)

cl <- fia %>% area(landType='forest', condList=T, nCores=10) %>% 
  # generate dummy variable to use to estimate area with customPSE
  mutate(class = sample(0:1, size=n(), replace=T, prob=c(.6,.4)),
         # scale by prop_forest to estimate amount of forest land where class == 1
         class_scaled = class * PROP_FOREST)

prop_class <- customPSE(db = fia, x = cl, xVars = c(class_scaled), y = cl, yVars = c(PROP_FOREST)) 
prop_forest <- fia %>% area(landType='all', nCores = 1) 

prop_class
prop_forest

## make sure plots are located in different states
cl %>% inner_join(fia$PLOT) %>% pull(STATECD) %>% table()

spatstat ppp objects from FIA?

I'm intending to use ppp objects for spatial point pattern analysis, and one of the requirements is to be able to associate the observation window with the individual tree lists. Is there a current way to convert a set of FIA plots into ppp objects? This requires the tree x,y plus marks as well as the plot boundary as a polygon (I believe they are circular plots, right?)

readFIA feature wish

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.

Error in CARB_TOTAL_VAR calculations

Running carbon with the variance flag set to true seems to be producing incorrect estimates of CARB_TOTAL_VAR. In my own comparisons, it looks like CARB_TOTAL_VAR is always equal to CARB_ACRE_VAR.

Here is a minimal example:

library(rFIA)
riMR <- clipFIA(fiaRI)
carbonTotal <- carbon(riMR, variance=TRUE, totals = TRUE)
all(carbonTotals$CARB_TOTAL_VAR == carbonTotals$CARB_ACRE_VAR)

The final call evaluates as true for me.

I peeked at the code is it seems that caVar, as opposed to cVar is returned for CARB_TOTAL_VAR

rFIA/R/carbon.R

Line 399 in b1c0c3d

CARB_TOTAL_VAR = caVar,

Happy to open a pull request if this is indeed an error.

fa_mean doesn't exist

The area mean calculation seems to have changed or is throwing an error - any suggestions on how to fix it?

Error in dplyr::select():
! Can't subset columns that don't exist.
✖ Column fa_mean doesn't exist.

Reproducible code:

data(fiaRI)
fiaRI_mr <-clipFIA(fiaRI, mostRecent = T)
#does not work
tpaRI<- tpa(fiaRI_mr)
#works
#tpa(fiaRI_mr, byPlot=T)

If I change the tpa to include byPlot [ tpa(fiaRI_mr, byPlot=T) ] there is not an error.
I need both calculations. Thanks!

seedling function

I have encountered a problem with the seedling function.

seedling(fiaRI, bySpecies = TRUE, byPlot = TRUE)

Returns an error:

Error in checkForRemoteErrors(val) :
one node produced an error: Column COMMON_NAME is unknown

I tried this same call with a different database object (other states) and got the same result.

Using "real" plot coordinates

If we get approval to have access to the true FIA plot coordinates (not the fuzzed ones), is there a procedure to replace the fuzzed ones with the real ones?

vitalRates grpBy = SUBP error

I was exploring the vitalRates estimation and get an error when attempting to group by subplot:

vitalRates(fiaRI, landType = "forest", grpBy = SUBP, byPlot = TRUE, bySpecies = TRUE)

Error in checkForRemoteErrors(val) :
one node produced an error: Column name SUBP must not be duplicated.

growMort bySizeClass missing removed stems

When running growMort by size class at the plot level, I find that it is missing removed stems as compared to growMort at the plot level, not by size class. Comparing the previous and current statevars for the results run with size class included, it also appears that the only time the statevar changes is when there is a recruitment or mortality event - otherwise, previous and current are exactly the same. Comparing plots one to one with and without the bySizeClass parameter, the values do not match up. The code I have been running is as follows:

growMort(db, byPlot = TRUE, stateVar = 'BAA')
versus
growMort(db, byPlot = TRUE, bySizeClass = TRUE, stateVar = 'BAA')

I'm not sure if this is a known limitation or not, but it currently appears that aggregating by size class is providing erroneous results.

Error in `dplyr::select()`: Column `geom` doesn't exist.

I get the foll. error even though the spatial sf object wimi_cnty is valid.

wimi_gm = growMort(wimi_db, polys=wimi_cnty, returnSpatial=T, bySpecies=T, landType='forest', treeType = 'all', stateVar='TPA', nCores=4)

Error in dplyr::select():

! Can't subset columns that don't exist.
? Column geom doesn't exist.

Same error with carbon(), tpa() - HOWEVER, fsi() works without a problem!

wimi_fsi = fsi(wimi_db, polys=wimi_cnty, returnSpatial=T, bySpecies=T, landType='forest', treeType = 'live', totals=T, nCores=4)

WORKS!!!

names(wimi_cnty)
[1] "AREA" "PERIMETER" "US_CTY_" "US_CTY_ID" "STATE_FIPS"
[6] "CNTY_FIPS" "fips" "STATE_NAME" "CNTY_NAME" "SUB_REGION"
[11] "STAT_FLAG" "geom"

names(wimi_db)
[1] "COND" "COND_DWM_CALC"
[3] "INVASIVE_SUBPLOT_SPP" "PLOT"
[5] "POP_ESTN_UNIT" "POP_EVAL"
[7] "POP_EVAL_GRP" "POP_EVAL_TYP"
[9] "POP_PLOT_STRATUM_ASSGN" "POP_STRATUM"
[11] "SUBPLOT" "TREE"
[13] "TREE_GRM_COMPONENT" "TREE_GRM_MIDPT"

mostRecent=FALSE breaks when using remote database

Using rFIA v0.3.0, all estimator functions produce the following error when applying a non-most recent clip to a remote FIA Database.

library(rFIA)

## Download data and set up remote database
getFIA(states = 'RI', dir = tempdir())
db <- readFIA(inMemory=F,dir = tempdir())

## A non-most recent clip, this does nothing in this case
## But can be useful for exclusively spatial subsets
dbclip <- clipFIA(db,mostRecent=F)

## Using tpa here, but fails for all estimator functions
dbclip %>% seedling()

Error in if (matchEval) { : argument is of length zero

vitalRates() for states with no TREE_GRM_BEGIN or SUBP_COND_CHNG_MTRX

I'm working with FIA data from Idaho and would like to use vitalRates to calculate diameter growth. However, Idaho does not have values in the the TREE_GRM_BEGIN or SUBP_COND_CHNG_MTRX tables, throwing this error.

vital_rates <- vitalRates(db, bySpecies = TRUE)
Error in FUN(X[[i]], ...) : Tables TREE_GRM_BEGIN, SUBP_COND_CHNG_MTRX not found in object db.

Would there be a way to adjust for states that lack these tables? It looks like there are several other states that lack this data.

biomass() and standStruct() fail when using multi-state, remote FIADB object with specific evalids

I'm having some issues when running biomass() and standStruct() on a multi-state FIADB that is not loaded into memory, when also passing specific EVALIDS to clipFIA(). This test is using Alabama, and while its happened for several other states as well, I have not exhaustively tested every state.

From what I can tell this problem only occurs with the combination of 1) a multi-state FIADB (tested for 2 states and entire CONUS) 2) that FIADB not being loaded in memory, (using inMemory=F), and 3) passing specific EVALIDS to clipFIA() to enable estimates not using the most recent inventories.

When things break, this is the error message I get:

Error in `$<-.data.frame`(`*tmp*`, "prev", value = 0) : 
  replacement has 1 row, data has 0

Code used to produce said error:

rm(list=ls())

# devtools::install_github('hunter-stanke/rFIA')
library(rFIA)

# evalids for Alabama total volume and area: 2000 - 2012
ee <- c(10501, 11101, 10601, 10901, 10801, 11001, 10001, 10301, 10401, 10101, 11201, 10701, 10201)

# works
FIADB <- readFIA('/Volumes/RESEARCH/rFIA/original_data', inMemory=F, nCores=6, states='AL')
fiadb <- clipFIA(FIADB, mostRecent = T, nCores=6)
bio <- biomass(fiadb, grpBy = COUNTYCD, totals = T, variance = F, nCores = 6)
stst <- standStruct(fiadb, grpBy = COUNTYCD, totals = T, variance = F, nCores = 6)

# works
FIADB <- readFIA('/Volumes/RESEARCH/rFIA/original_data', inMemory=T, nCores=6, states='AL')
fiadb <- clipFIA(FIADB, mostRecent = T, nCores=6)
bio <- biomass(fiadb, grpBy = COUNTYCD, totals = T, variance = F, nCores = 6)
stst <- standStruct(fiadb, grpBy = COUNTYCD, totals = T, variance = F, nCores = 6)

# works
FIADB <- readFIA('/Volumes/RESEARCH/rFIA/original_data', inMemory=T, nCores=6, states=c('AL','GA'))
fiadb <- clipFIA(FIADB, mostRecent = T, nCores=6)
bio <- biomass(fiadb, grpBy = COUNTYCD, totals = T, variance = F, nCores = 6)
stst <- standStruct(fiadb, grpBy = COUNTYCD, totals = T, variance = F, nCores = 6)

# works
FIADB <- readFIA('/Volumes/RESEARCH/rFIA/original_data', inMemory=F, nCores=6)
fiadb <- clipFIA(FIADB, mostRecent = T, nCores=6)
bio <- biomass(fiadb, grpBy = COUNTYCD, totals = T, variance = F, nCores = 6)
stst <- standStruct(fiadb, grpBy = COUNTYCD, totals = T, variance = F, nCores = 6)

# works
FIADB <- readFIA('/Volumes/RESEARCH/rFIA/original_data', inMemory=F, nCores=6, states=c('AL','GA'))
fiadb <- clipFIA(FIADB, mostRecent = T, nCores=6)
bio <- biomass(fiadb, grpBy = COUNTYCD, totals = T, variance = F, nCores = 6)
stst <- standStruct(fiadb, grpBy = COUNTYCD, totals = T, variance = F, nCores = 6)



# breaks
FIADB <- readFIA('/Volumes/RESEARCH/rFIA/original_data', inMemory=F, nCores=6)
fiadb <- clipFIA(FIADB, mostRecent = FALSE, evalid = ee, nCores=6)
bio <- biomass(fiadb, grpBy = COUNTYCD, totals = T, variance = F, nCores = 6)
stst <- standStruct(fiadb, grpBy = COUNTYCD, totals = T, variance = F, nCores = 6)

# breaks
FIADB <- readFIA('/Volumes/RESEARCH/rFIA/original_data', inMemory=F, nCores=6, states=c('AL','GA'))
fiadb <- clipFIA(FIADB, mostRecent = FALSE, evalid = ee, nCores=6)
bio <- biomass(fiadb, grpBy = COUNTYCD, totals = T, variance = F, nCores = 6)
stst <- standStruct(fiadb, grpBy = COUNTYCD, totals = T, variance = F, nCores = 6)

Thank you!!

'DRYBIO_WDLD_SPP' and Column `CARBON_STANDING_DEAD` not found

I downloaded the Maine csv zip from the FIA website due to issues with getFIA. The example code on the rFIA website worked fine, but the biomass and carbon functions are returning errors.

For biomass:
Error in eval(jsub, SDenv, parent.frame()) :
object 'DRYBIO_WDLD_SPP' not found

For carbon:
! Can't subset columns that don't exist.
✖ Column CARBON_STANDING_DEAD doesn't exist.

I have not been able to identify where these variables can be found in the FIA datamart. Any help would be appreciated!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.