Data Reader¶
Low-level data reading utilities for FIA databases.
Overview¶
The FIADataReader provides optimized reading capabilities with backend abstraction for DuckDB and SQLite databases.
from pyfia import FIADataReader
reader = FIADataReader("georgia.duckdb")
schema = reader.get_table_schema("TREE")
data = reader.read_table("TREE", columns=["CN", "DIA", "SPCD"])
Class Reference¶
FIADataReader
¶
Optimized reader for FIA databases.
This class provides efficient methods for reading FIA data with: - Support for both DuckDB and SQLite backends - Lazy evaluation for memory efficiency - Column selection to minimize data transfer - Type-aware schema handling for FIA's VARCHAR CN fields - Automatic database type detection
Initialize data reader.
| PARAMETER | DESCRIPTION |
|---|---|
db_path
|
Path to FIA database (DuckDB or SQLite).
TYPE:
|
engine
|
Database engine ('duckdb' or 'sqlite'). If None, auto-detect.
TYPE:
|
**backend_kwargs
|
Additional backend-specific options: - For DuckDB: read_only, memory_limit, threads - For SQLite: timeout, check_same_thread
DEFAULT:
|
Source code in src/pyfia/core/data_reader.py
get_table_schema
¶
Get schema information for a table.
| PARAMETER | DESCRIPTION |
|---|---|
table_name
|
Name of the table.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict of str to str
|
Dictionary mapping column names to SQL types. |
Source code in src/pyfia/core/data_reader.py
read_table
¶
read_table(table_name: str, columns: Optional[List[str]] = None, where: Optional[str] = None, lazy: bool = True) -> Union[DataFrame, LazyFrame]
Read a table from the FIA database.
| PARAMETER | DESCRIPTION |
|---|---|
table_name
|
Name of the table to read.
TYPE:
|
columns
|
Optional list of columns to select.
TYPE:
|
where
|
Optional WHERE clause (without 'WHERE' keyword).
TYPE:
|
lazy
|
If True, return LazyFrame; if False, return DataFrame.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame or LazyFrame
|
Polars DataFrame or LazyFrame. |
Source code in src/pyfia/core/data_reader.py
read_plot_data
¶
Read PLOT data filtered by EVALID.
| PARAMETER | DESCRIPTION |
|---|---|
evalid
|
List of EVALID values to filter by.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
DataFrame with plot data. |
Source code in src/pyfia/core/data_reader.py
read_tree_data
¶
Read TREE data for specified plots.
| PARAMETER | DESCRIPTION |
|---|---|
plot_cns
|
List of plot CNs to get trees for.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
DataFrame with tree data. |
Source code in src/pyfia/core/data_reader.py
read_cond_data
¶
Read COND data for specified plots.
| PARAMETER | DESCRIPTION |
|---|---|
plot_cns
|
List of plot CNs to get conditions for.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
DataFrame with condition data. |
Source code in src/pyfia/core/data_reader.py
read_pop_tables
¶
Read population estimation tables for specified EVALIDs.
| PARAMETER | DESCRIPTION |
|---|---|
evalid
|
List of EVALID values.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict of str to pl.DataFrame
|
Dictionary with population tables. |
Source code in src/pyfia/core/data_reader.py
read_evalid_data
¶
Read all data for specified EVALID(s).
This is the main method for loading a complete set of FIA data filtered by evaluation ID.
| PARAMETER | DESCRIPTION |
|---|---|
evalid
|
Single EVALID or list of EVALIDs.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict of str to pl.DataFrame
|
Dictionary with all relevant tables. |