Reference Table Utilities¶
Functions to join descriptive names to estimation results.
Auto-Enhancement¶
PyFIA automatically adds descriptive names for common grouping columns:
| Grouping Column | Auto-Added Column |
|---|---|
FORTYPCD |
FOREST_TYPE_GROUP |
OWNGRPCD |
OWNERSHIP_GROUP |
import pyfia
db = pyfia.FIA("georgia.duckdb")
db.clip_by_state("GA")
# Forest type names added automatically!
result = pyfia.area(db, grp_by="FORTYPCD")
print(result.columns)
# ['YEAR', 'FORTYPCD', 'FOREST_TYPE_GROUP', 'AREA', ...]
# Ownership names added automatically!
result = pyfia.volume(db, grp_by="OWNGRPCD")
print(result.columns)
# ['YEAR', 'OWNGRPCD', 'OWNERSHIP_GROUP', 'VOLCFNET_TOTAL', ...]
Manual Reference Table Joins¶
For columns that aren't auto-enhanced (like species), use these functions:
# Get volume by species
result = pyfia.volume(db, grp_by="SPCD")
# Add species names manually
result = pyfia.join_species_names(result, db)
print(result)
Functions¶
join_species_names¶
Add common and scientific species names.
join_species_names
¶
join_species_names(data: DataFrame, db: Union[str, FIA], species_col: str = 'SPCD', common_name_col: str = 'COMMON_NAME', scientific_name_col: Optional[str] = 'SCIENTIFIC_NAME', include_scientific: bool = False) -> DataFrame
Join species names from REF_SPECIES table.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
DataFrame containing species codes
TYPE:
|
db
|
FIA database object or path to database
TYPE:
|
species_col
|
Column name containing species codes
TYPE:
|
common_name_col
|
Name for the joined common name column
TYPE:
|
scientific_name_col
|
Name for the joined scientific name column
TYPE:
|
include_scientific
|
Whether to include scientific names
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
Original data with species names added |
Examples:
Source code in src/pyfia/utils/reference_tables.py
Example:
# Basic usage
result = pyfia.join_species_names(volume_data, db)
# Include scientific name
result = pyfia.join_species_names(
volume_data,
db,
include_scientific=True
)
join_forest_type_names¶
Add forest type group names.
join_forest_type_names
¶
join_forest_type_names(data: DataFrame, db: Union[str, FIA], forest_type_col: str = 'FORTYPCD', name_col: str = 'FOREST_TYPE_NAME') -> DataFrame
Join forest type names from REF_FOREST_TYPE table.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
DataFrame containing forest type codes
TYPE:
|
db
|
FIA database object or path to database
TYPE:
|
forest_type_col
|
Column name containing forest type codes
TYPE:
|
name_col
|
Name for the joined forest type name column
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
Original data with forest type names added |
Examples:
>>> results = area(db, grp_by=['FORTYPCD'], totals=True)
>>> results_with_names = join_forest_type_names(results, db)
Source code in src/pyfia/utils/reference_tables.py
Example:
area_by_type = pyfia.area(db, grp_by="FORTYPGRPCD")
result = pyfia.join_forest_type_names(area_by_type, db)
print(result)
join_state_names¶
Add state names and abbreviations.
join_state_names
¶
join_state_names(data: DataFrame, db: Union[str, FIA], state_col: str = 'STATECD', state_name_col: str = 'STATE_NAME', state_abbr_col: Optional[str] = 'STATE_ABBR', include_abbr: bool = True) -> DataFrame
Join state names and abbreviations from REF_STATE.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
DataFrame containing state codes
TYPE:
|
db
|
FIA database object or path to database
TYPE:
|
state_col
|
Column name containing state codes
TYPE:
|
state_name_col
|
Name for the joined state name column
TYPE:
|
state_abbr_col
|
Name for the joined state abbreviation column
TYPE:
|
include_abbr
|
Whether to include state abbreviations
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
Original data with state names added |
Source code in src/pyfia/utils/reference_tables.py
Example:
volume_by_state = pyfia.volume(db, grp_by="STATECD")
result = pyfia.join_state_names(volume_by_state, db)
print(result)
join_multiple_references¶
Join multiple reference tables at once.
join_multiple_references
¶
join_multiple_references(data: DataFrame, db: Union[str, FIA], forest_type: bool = False, species: bool = False, state: bool = False, **kwargs) -> DataFrame
Join multiple reference tables at once.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
DataFrame to join reference tables to
TYPE:
|
db
|
FIA database object or path to database
TYPE:
|
forest_type
|
Whether to join forest type names
TYPE:
|
species
|
Whether to join species names
TYPE:
|
state
|
Whether to join state names
TYPE:
|
**kwargs
|
Additional arguments passed to individual join functions
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
Data with requested reference tables joined |
Examples:
>>> results = area(db, grp_by=['STATECD', 'FORTYPCD'], totals=True)
>>> results_with_names = join_multiple_references(
... results, db,
... forest_type=True,
... state=True
... )
Source code in src/pyfia/utils/reference_tables.py
Example:
# Add both species and forest type names
result = pyfia.join_multiple_references(
data,
db,
tables=["species", "forest_type"]
)
Available Reference Tables¶
| Code Column | Reference Table | Name Column |
|---|---|---|
SPCD |
REF_SPECIES |
Common name, Scientific name |
FORTYPCD |
REF_FOREST_TYPE |
Forest type name |
FORTYPGRPCD |
REF_FOREST_TYPE_GROUP |
Forest type group name |
STATECD |
REF_STATE |
State name, abbreviation |
OWNGRPCD |
REF_OWNGRPCD |
Ownership group name |