pyfia.core.fia
Core FIA database class and functionality for pyFIA.
This module provides the main FIA class that handles database connections,
EVALID-based filtering, and common FIA data operations.
Functions
resolve_eval_typ_codes
eval_type token to its FIA EVAL_TYP code(s).
Accepts both friendly tokens ("VOL", "GRM", "GROW" …) and raw
EVAL_TYP codes ("EXPVOL" …). "GRM" expands to the full
growth/removal/mortality family.
Args:
eval_type: Evaluation type token or rawEVAL_TYPcode (case-insensitive).
- One or more
EVAL_TYPcodes to match againstPOP_EVAL_TYP.
Classes
FIA
Main FIA database class for working with Forest Inventory and Analysis data.
This class provides methods for loading FIA data from DuckDB databases,
filtering by EVALID, and preparing data for estimation functions.
Attributes:
db_path: Path to the DuckDB database or MotherDuck connection string.tables: Loaded FIA tables as lazy frames.evalid: Active EVALID filter.most_recent: Whether to use most recent evaluations.
from_download
states: State abbreviations (e.g., ‘GA’, ‘NC’) or ‘REF’ for reference tables. Supports multiple states: [‘GA’, ‘FL’, ‘SC’]dir: Directory to save downloaded data. Defaults to ~/.pyfia/data/common: If True, download only tables required for pyFIA functions.tables: Specific tables to download. Overridescommonparameter.force: If True, re-download even if files exist locally.show_progress: Show download progress bars.
- Connected FIA database instance.
Download and open Georgia data
db = FIA.from_download(“GA”) db.clip_most_recent() result = db.area()Download multiple states
db = FIA.from_download([“GA”, “FL”, “SC”])
query
sql: SQL SELECT query to execute.
- Query results as a Polars DataFrame.
with FIA(“data/georgia.duckdb”) as db: … result = db.query(“SELECT FORTYPCD, COUNT(*) as n FROM COND GROUP BY FORTYPCD”)
load_table
table_name: Name of the FIA table to load (e.g., ‘PLOT’, ‘TREE’, ‘COND’).columns: Columns to load. Loads all columns if None.where: Additional SQL WHERE clause to apply (without ‘WHERE’ keyword). Used for database-side filtering to reduce memory usage.
- Polars LazyFrame of the requested table.
find_evalid
most_recent: If True, return only most recent evaluations per state.state: State FIPS code(s) to filter by.year: End inventory year(s) to filter by.eval_type: Evaluation type token. One of ‘ALL’, ‘VOL’, ‘GRM’, ‘GROW’, ‘MORT’, ‘REMV’, ‘CHNG’, ‘DWM’, ‘REGEN’, ‘INV’, ‘CURR’, or a raw EVAL_TYP code (e.g. ‘EXPVOL’). ‘GRM’ is an alias for the growth/removal/ mortality family. Unknown tokens raise ValueError.
- EVALID values matching the specified criteria.
clip_by_evalid
evalid: Single EVALID or list of EVALIDs to filter by.
- Self for method chaining.
clip_by_state
- Setting a state filter for direct table queries
- Finding appropriate EVALIDs for the state(s)
- Combining both filters for optimal performance
state: Single state FIPS code or list of codes.most_recent: If True, use only most recent evaluations.eval_type: Evaluation type to use. Default ‘ALL’ for EXPALL which is appropriate for area estimation. Use None to get all types.
- Self for method chaining.
clip_most_recent
eval_type: Evaluation type token. ‘VOL’ for volume/biomass/TPA/area; ‘GRM’ for growth, removals, and mortality together (or the component-specific ‘GROW’, ‘MORT’, ‘REMV’); ‘CHNG’ for change. See find_evalid for the full list of accepted tokens.
- Self for method chaining.
clip_by_polygon
polygon: Path to spatial file containing polygon(s). Supported formats:- Shapefile (.shp)
- GeoJSON (.geojson, .json)
- GeoPackage (.gpkg)
- GeoParquet (.parquet with geometry)
- Any format supported by GDAL/OGR
predicate: Spatial predicate for filtering:- ‘intersects’: Plots that intersect the polygon (recommended)
- ‘within’: Plots completely within the polygon
- Self for method chaining.
with FIA(“southeast.duckdb”) as db: … db.clip_by_state(37) # North Carolina … db.clip_by_polygon(“my_region.geojson”) … result = db.tpa()Using a shapefile
with FIA(“data.duckdb”) as db: … db.clip_by_polygon(“counties.shp”) … result = db.area()
intersect_polygons
polygon: Path to spatial file containing polygon(s). Supported formats:- Shapefile (.shp)
- GeoJSON (.geojson, .json)
- GeoPackage (.gpkg)
- GeoParquet (.parquet with geometry)
- Any format supported by GDAL/OGR
attributes: Polygon attribute columns to add to plots. These columns must exist in the polygon file and will be available for grp_by.
- Self for method chaining.
with FIA(“southeast.duckdb”) as db: … db.clip_by_state(37) # North Carolina … db.intersect_polygons(“counties.shp”, attributes=[“NAME”, “FIPS”]) … # Group TPA estimates by county … result = tpa(db, grp_by=[“NAME”])Use multiple attributes for grouping
with FIA(“data.duckdb”) as db: … db.intersect_polygons(“regions.geojson”, [“REGION”, “DISTRICT”]) … result = area(db, grp_by=[“REGION”, “DISTRICT”])
get_plots
columns: Columns to return. Returns all columns if None.
- Filtered PLOT dataframe.
get_trees
columns: Columns to return. Returns all columns if None.
- Filtered TREE dataframe.
get_conditions
columns: Columns to return. Returns all columns if None.
- Filtered COND dataframe.
prepare_estimation_data
include_trees: Whether to include the TREE table. Set to False for area estimation which doesn’t need tree data (saves significant memory on constrained environments).
- Dictionary with filtered dataframes for estimation containing: ‘plot’, ‘tree’, ‘cond’, ‘pop_plot_stratum_assgn’, ‘pop_stratum’, ‘pop_estn_unit’. If include_trees=False, ‘tree’ will be an empty DataFrame.
tpa
biomass
volume
mortality
area
growth
removals
area_change
MotherDuckFIA
FIA database class for MotherDuck cloud-based access.
This class provides the same interface as FIA but connects to MotherDuck
instead of a local DuckDB file. MotherDuck is a serverless cloud data
warehouse built on DuckDB.
Attributes:
database: Name of the MotherDuck database (e.g., ‘fia_ga’)motherduck_token: MotherDuck authentication token
Methods:from pyfia import MotherDuckFIA db = MotherDuckFIA(“fia_ga”, motherduck_token=“your_token”) db.clip_most_recent() result = db.area()Use with context manager
with MotherDuckFIA(“fia_nc”, motherduck_token=“token”) as db: … db.clip_most_recent() … print(db.area())