Return to WFEIS Home

Processing Flowcharts

Emissions API

_images/core_diagram_web.png

Ag-NEI API

_images/core_diagram_web_agnei.png

Module documentation

FCCS

The FCCS package handles the interaction with and manipulation of fuels dataFuel Characteristics Classification System (FCCS) data.

fccs.models

Models for all fuels-related tables.

Note

These models are generally but not exclusively related to Fuel Characteristic Classification System (FCCS) source data.

These models can be categorized into one of two groups:

Category Description
Fuelbed descriptions Tabular data indicating type, loadings, and consumption information for a set of fuelbed IDs. Any model with Fuelbeds in the class name is included in this category.
Spatial fuels layers Spatially defined fuels data (either in vector- Polygons - or raster format). These spatial layers contain fuelbed ID information relating to the fuelbed descriptions tables described above.
class fccs.models.CDLPolygons1kmAbstract(*args, **kwargs)

Bases: fccs.models.FuelsPolygonsAbstract

CDL Polygons parent model used as a base model class. This class does not create a database table. All fields are passed to child classes. The abstract value sets this in the Meta subclass. Fields in the abstract base class cannot have the same name as those in a child class (Django will raise an exception)

Attribute Description
agcode 13-digit ag-code indicating the proportional makeup of each 1-km gridcell
geom Polygon geometry with srid as a field option (required)
class Meta

Meta or non-field options.

class fccs.models.CDLPolygons1km_2010_masked(*args, **kwargs)

Bases: fccs.models.CDLPolygons1kmAbstract

1-km CDL agricultural fuelbeds layer w/ cropmask applied.

class fccs.models.FccsPolygons1kmGaps(*args, **kwargs)

Bases: fccs.models.FccsPolygonsAbstract

Vectorized FCCS polygons with gaps (transformed following conversion from raster) Child model class of FccsPolygons1kmAbstract.

class fccs.models.FccsPolygons1km_modisenhanced(*args, **kwargs)

Bases: fccs.models.FccsPolygons1km_modisenhancedAbstract

1km MODIS-enhanced FCCS vector layer, developed by USFS.

class fccs.models.FccsPolygons1km_modisenhancedAbstract(*args, **kwargs)

Bases: fccs.models.FuelsPolygonsAbstract

FCCS Polygons parent model used as a base model class. This class does not create a database table. All fields are passed to child classes. The abstract value sets this in the Meta subclass. Fields in the abstract base class cannot have the same name as those in a child class (Django will raise an exception)

Attribute Description
id Primary key ID
fuelbed_id Fuelbed ID (foreign key link to FuelbedsModisEnhanced) (many-to-one)
geom Polygon geometry with srid as a field option (required)
class Meta

Meta or non-field options.

class fccs.models.FccsPolygons1km_modisenhanced_dummy(*args, **kwargs)

Bases: fccs.models.FccsPolygons1km_modisenhancedAbstract

Empty dummy table for use in generating empty queryset template when calculating agricultural emissions but not natural emissions.

class fccs.models.FccsPolygons1km_modisenhanced_masked(*args, **kwargs)

Bases: fccs.models.FccsPolygons1km_modisenhancedAbstract

1km MODIS-enhanced FCCS vector layer, with crop mask applied. For use in combination with the CDLtiledraster1kmupscale dataset (which also should have cropmask applied)

class fccs.models.FccsPolygonsAbstract(*args, **kwargs)

Bases: fccs.models.FuelsPolygonsAbstract

FCCS Polygons parent model used as a base model class. This class does not create a database table. All fields are passed to child classes. The abstract value sets this in the Meta subclass. Fields in the abstract base class cannot have the same name as those in a child class (Django will raise an exception)

Attribute Description
fccs_id FCCS code of the polygon region (many-to-one)
ecoregion Ecoregion ID (many-to-one)
source_fb Fuelbed data source (many-to-one)
geom Polygon geometry with srid as a field option (required)
class Meta

Meta or non-field options.

class fccs.models.FccsRaster1km(*args, **kwargs)

Bases: fccs.models.RasterAbstract

1km FCCS raster layer model, based on 2010 data.

class fccs.models.FccsRaster1km_modisenhanced(*args, **kwargs)

Bases: fccs.models.RasterAbstract

1km MODIS-enhanced FCCS raster layer model.

class fccs.models.Fuelbeds(*args, **kwargs)

Bases: fccs.models.FuelbedsFccsAbstract

FCCS Fuelbeds table model linking individual data source files to the appropriate data model

Attribute Description
id FCCS ID number (primary key)
name FCCS name
description FCCS description
epa_scc_code EPA source classification code [text]
canopy_consumption_pct Pre-calculated canopy consumption percentage, based on FCCS crown fire attributes
class fccs.models.FuelbedsCDL(*args, **kwargs)

Bases: django.db.models.base.Model

CDL fuelbeds table model that provides loadings/consumption/emissions factor values used to calculate emissions for the agricultural fuelbeds

Attribute Description
id CDL/FCCS ID number (foreign key on Fuelbeds ID)
name Ag fuelbed name
fuel_available_total_tons_ac Total available fuel loadings (tons/acre)
combustion_completeness Combustion completeness (proportion)
voc Volatile organic carbon
ef_co2_lbs_t CO2 emissions factor (lbs/tons consumed)
ef_co_lbs_t CO emissions factor (lbs/tons consumed)
ef_ch4_lbs_t CH4 emissions factor (lbs/tons consumed)
ef_no2_lbs_t NO2 emissions factor (lbs/tons consumed)
ef_so2_lbs_t SO2 emissions factor (lbs/tons consumed)
ef_pm25_lbs_t PM2.5 emissions factor (lbs/tons consumed)
ef_pm10_lbs_t PM10 emissions factor (lbs/tons consumed)
class fccs.models.FuelbedsFccsAbstract(*args, **kwargs)

Bases: django.db.models.base.Model

FCCS Fuelbeds abstract model shared by any fuelbeds model that uses FCCS as its base

Attribute Description
id Fuelbed ID number
total_aboveground_fuel_loadings Total aboveground fuel loadings (tons/ac)
fuel_available_total Available fuel, total (tons/ac)
fuel_available_canopy Available fuel, canopy (tons/ac)
fuel_available_shrub Available fuel, shrub (tons/ac)
fuel_available_nonwoody Available fuel, nonwoody (tons/ac)
fuel_available_llm Available fuel, litter-lichen-moss (tons/ac)
fuel_available_ground Available fuel, ground (tons/ac)
fuel_available_woody Available fuel, woody (tons/ac)
class Meta

Meta or non-field options.

class fccs.models.FuelbedsModisEnhanced(*args, **kwargs)

Bases: fccs.models.FuelbedsFccsAbstract

MODIS-enhanced FCCS fuelbeds table linking individual data source files to the appropriate data model

Attribute Description
id Fuelbed ID number (primary key) NOT the FCCS ID
fccs_id FCCS fuelbed ID number (foreign key)
modis_canopy_cover Percentage of canopy cover as determined by MODIS
lifeform Indicator of fuel life form (tree, shrub, nonwoody)
class fccs.models.FuelsPolygonsAbstract(*args, **kwargs)

Bases: django.db.models.base.Model

Abstract model for all models representing fuels in vector polygon format

class Meta

Meta or non-field options.

FuelsPolygonsAbstract.ewkt()

Returns object in EWKT

FuelsPolygonsAbstract.json()

Returns object in JSON

FuelsPolygonsAbstract.kml()

Returns object in KML

class fccs.models.RasterAbstract(*args, **kwargs)

Bases: django.db.models.base.Model

Base model class for all tiled raster datasets.

Attribute Description
rid raster tile ID (primary key)
rast raster data (will set to text since geodjango does not support raster types yet...)
filename location on MTRI’s network where raster tile originated (text)

Fire

The Fire package handles interaction with burn area data. It is also responsible for taking user input from the WFEIS calculator form, running the necessary models, and displaying results. This is handled by fire.views.display_consume().

fire.models

Models for all burn area related tables. Model fields are listed as attributes with the actual column name listed in parenthesis.

class fire.models.BurnedAreaAbstract(*args, **kwargs)

Bases: django.db.models.base.Model

Abstract base class for all burned area data models.

Attribute Description
id (integer) serial primary key
date (date) date the geometry is valid for
fuelbed_ecoregion (char) Consume ecoregion (western, southern, or boreal) associated with the geom
fuel_moisture_1000hr_pct (integer) 1000-hour fuel moisture (pct), derived from interpolated RAWS data
fuel_moisture_duff_pct (integer) Duff fuel moisture (pct), derived from interpolated RAWS data
geom (geom) WKB fire burn area geometry
class fire.models.BurnedAreaDBBAP(*args, **kwargs)

Bases: fire.models.BurnedAreaAbstract

Model for burned areas from the MODIS DBBAP MCD64A1 dataset

class fire.models.BurnedAreaLandsatDaily(*args, **kwargs)

Bases: fire.models.BurnedAreaAbstract

Model for burned areas from the Landsat daily dataset -MODIS Active Fire (MCD14ML) point detections interpolated w/in MTBS burn perimeters

Attribute Description
mtbs_id (integer) foreign key referencing BurnedAreaMTBS id
fire_name (char) MTBS fire name, not unique
class fire.models.BurnedAreaMTBS(*args, **kwargs)

Bases: fire.models.BurnedAreaAbstract

Model for burned area from the MTBS dataset.

Attribute Description
fire_code (char) MTBS Fire Code, unique
fire_name (char) MTBS Fire Name, not unique
class fire.models.BurnedAreaSmartfireNEI(*args, **kwargs)

Bases: fire.models.BurnedAreaAbstract

Dataset represents 2011 Smartfire burned area produced for NEI

Attribute Description
fire_name (text) from the “display_na” field of the Smartfire 2011 NEI download

fire.views

This module is a collection of Django views related to fire burn areas, as well as supporting functions needed to obtain data and subsequently process it according to the users request.

fire.views.get_burned_area_fccs_intersection(fuels_model_key, ba_model_key, grid=None, ba_date=None, ba_date_range=None, ba_name=None, bbox_wkt=None, ba_pks=None, roi=None, is_cmaq=False, scc=None, is_none_canopy_consumption_pct=False, emistype=None)

Get a set of polygons that are an intersection of the burned area and the FCCS polygons

Parameters:
  • fuels_model_key – string defining the key identifier for the fuelbed model
  • ba_model_key – string defining the burned area model key
  • grid – GridPostGis object. note: table must be created before passing to method
  • ba_date – a datetime.date used to filter the burned area dataset
  • ba_date_range – a 2-element list with the first entry being the min date and second element corresponding to the max date
  • ba_name – burned area string matching the name field
  • bbox_wkt – WKT Polygon string used as a bounding box for the intersection
  • ba_pks – sequence of integers defining the burned area polygon unique ids to use in the intersection.
  • roi – tuple where the first value is Django data model to use as an ROI from roi.models. the second value is the selection key used to pick a value. consult the respective model for information on constructing this selection key.
  • is_cmaq – set to True to extract the queryset for a CMAQ input file. The underlying query for CMAQ data is different than the standard WFEIS query.
  • is_none_canopy_consumption_pct – set to True to use the pre-calculated canopy consumption pct values based on FCCS ID (pulled from the fccs_fuelbeds table in the pg database)
  • scc – set to to a valid SCC code to perform an additional filter on that code (only FCCS polygons with that SCC code will be included)
Returns:

GeoQuerySetWfeis object

fire.views.process_emissions_request(request, **kwds)

Process emissions calculations and output via the indicated file extension. This is the meat wrapper.

Parameters:
  • request – HTML Request (automatically passed by django through urls.py)
  • burnedarea_datasource – (string) which data source to pull data from. Choices include: ‘’mtbs’,’mcd45a1’,’dbbap’,’fire_progression’.
  • eRegion – The ecoregion, such as western or eastern
  • oneKFM – 1000 hr fuel moisture parameter
  • DuffFM – Duff layer fuel moisture
  • CanPerCons – Percent of the canopy consumed
  • PerBlack – Percent black
  • combstage – combustion stage
  • fileExt – The type of output file, kml or shp
Returns:

HTTP response dependent upon the output file extension

Main

The main package contains a series of views that are used to render various parts of the outward-facing components of WFEIS, including the calculator.

main.views

Houses the main Django views directly visible to the user.

main.views.calculate_emissions(request)

Calculator handler for the ExtJS interface. Rewrites HTTP request in WFEIS-readable format.

Accepted request parameters:
ba_source start_date end_date north east south west ecoregion province partnership fire_name scc include_agricultural include_natural use_defaults fm_1000hr fm_duff canopy_consumption shrub_blackened combustion_stage stratum emission_species output_units output_format gridres
main.views.display_about(request)

Displays the WFEIS project about page

Parameters:request – The HTML request
main.views.display_api(request)

Displays the WFEIS project help page

Parameters:request – The HTML request
main.views.display_calculator_ui(request)

Display the WFEIS Calculator Page

main.views.display_contacts(request)

Displays the WFEIS project contacts page

Parameters:request – The HTML request
main.views.display_ecoregion_summaries(request)

Displays the ecoregion summaries page

Parameters:request – The HTML request
main.views.display_examples(request)

Displays a table of URL links that gives examples of using WFEIS

Parameters:request – The HTML request
main.views.display_fuelsmap(request)

Displays the WFEIS Fuels Map page

Parameters:request – The HTML request
main.views.display_help(request)

Displays the WFEIS project help page

Parameters:request – The HTML request

Displays the WFEIS project links page

Parameters:request – The HTML request
main.views.display_projout(request)

Displays the WFEIS project outputs page

Parameters:request – The HTML request
main.views.help_json(request)

Returns requested help text.

There are 5 subsections to the calculator form, each of which has its own help text. This method accepts an html request and returns the appropriate help text provided the request is valid.

Parameters:request – html request for help text
Returns:Http response containing the help text
main.views.index(request)

Displays list of links that can be used for viewing the data

This renders the homepage for the django site.

Parameters:request – The HTML request
main.views.return_mtbs_fire_names(request, rid=None)

Returns a JSON representation of the MTBS fires available

main.views.versions(request)

Display the version of Django used

Pgsql

The pgsql package implements functionality related to geospatial database operations, including intersections and capturing of results as WFEIS-friendly objects.

pgsql.grid

class pgsql.grid.GridPostGis(envelope, resolution, temp=False, pk=True, points=False)

Bases: object

Generates SQL for a PostGiS grid.

Parameters:
  • envelope – (GEOGeometry.Polygon) the box over which to generate the grid. must include an SRID.
  • resolution – (float) resolution in units relative to envelope.
  • temp – (bool,T) set to False to create the table as permanent as opposed to temporary.
  • pk – (bool,F) set to True to add a primary key constraint to the table using the class property UID as the identifier.
  • points – (bool,F)set to True to return a point grid.

pgsql.queryset

pgsql.queryset.create_queryset(query, none_types=None)

Executes SQLAlchemy query and converts result to a GeoQuerySetWfeis object.

Parameters:
  • query – SQLAlchemy query object
  • none_types – Type mapping dictionary to use for fields that may have missing data
Returns:

GeoQuerySetWfeis object

pgsql.intersection.intersection

class pgsql.intersection.intersection.AreaIntersection(simple_intersection, is_raster=False, scale=1000000.0, label='area_km2', transform_srid=2163)

Bases: object

Adds polygon area field and aggregates SQLAlchemy query object by input value.

Parameters:
  • simple_intersection – SimpleIntersection object
  • is_raster – (bool,F) indicates whether fuels data was raster-based
  • scale – (float,1e6) indicates scale to divide default area values (m) by
  • label – (char) name for the added area field
  • transform_srid – (integer) SRID to transform geometry to for area calculation
query(session)
Returns:SQLAlchemy query
class pgsql.intersection.intersection.ExtractFips(simple_intersection, csql)

Bases: object

Modifies SQLAlchemy query to include County FIPS values using spatial intersection.

Parameters:
  • simple_intersection – SimpleIntersection object
  • csql – The SQLAlchemy model of the CountyFips table
query(session)
Returns:SQLAlchemy query
class pgsql.intersection.intersection.IntersectionTable(Model, filters=None, keep=None, pk=None, empty=False, centroid=False)

Bases: object

Object collects metadata on intersection objects.

Parameters:
  • Model – (DeclarativeMeta)
  • filters – list of filters to convert to sqlalchemy filters.
  • keep – list of fields to keep through the intersection. these will be used as grouping columns.
  • pk – the primary key field if the primary key field is not ‘id’
  • empty – set to True to use the table in the geometric intersection but maintain none of its fields during grouping. keep must be set to None in this case.
  • centroid – set to True to include the X and Y centroids of the polygons.
class pgsql.intersection.intersection.RasterIntersection(simple_intersection, raster_intersection_table, resolution, fuelbed_id_field, Fb=None, Fe=None, srid=4326, scc=False)

Bases: object

Intersects a set of vectors with a raster fuels layer

Parameters:
  • simple_intersection – SimpleIntersection object
  • raster_intersection_table – The Django raster model to use
  • resolution – The resolution of the Django raster model
  • fuelbed_id_field – The fuelbed_id_field associated with the raster model
  • Fb – The FCCS fuelbed table model
  • Fe – The MODIS-enhanced FCCS fuelbed table model
  • srid – The SRID of the raster model
  • scc – (bool,F) SCC filter indicator
query(session)
Returns:SQLAlchemy query
class pgsql.intersection.intersection.SimpleIntersection(*args, **kwds)

Bases: object

Defines a simple spatial intersection of two or more models.

Parameters:
  • object – IntersectionTable object composed of models to intersect
  • bbox_ewkt – EWKT string defining the intersection bounding box/polygon

Reports

The reports package includes modules that generate reports based on WFEIS output and format them according to the desired response type.

class reports.base.AgNEIReport(qs=None, efs=None, units={'area_units': 'ac', 'mass_units': 'lbs'}, static_parms={'print': False, 'combustion stage': 'total', 'include both natural and agricultural': False, 'stratum': 'total'}, csv_first_columns=['fccs_id'])

Bases: reports.base.EmissionsReport

WFEIS emissions modeling report object for the AgNEI API.

class reports.base.EmissionsReport(qs=None, efs=None, units={'area_units': 'ac', 'mass_units': 'lbs'}, static_parms={'print': False, 'combustion stage': 'total', 'include both natural and agricultural': False, 'stratum': 'total'}, csv_first_columns=['fccs_id'])

Bases: reports.base.Report

WFEIS emissions modeling report object for the Emissions API.

Parameters:
  • qs – Django QuerySet holding results
  • efs – (list) list of emissions to be reported
  • units – (dict) dictionary indicating mass and area units of the results
  • static_parms – (dict) dictionary specifying results filters
  • csv_first_columns – (list) list of columns that should start the output table
class reports.base.Report(reportdata=None, meta=None, banner=True)

Bases: object

ROI

This package provides data models for regions of interest (such as states, counties, and ecoregions) that are used for spatial filtering operations.

roi.models

class roi.models.CecEcoregions(*args, **kwargs)

Bases: roi.models.RoiBase

Table model for CEC ecoregions ROI

Attribute Description
level1 (char) Level 1 ecoregion ID
level2 (char) Level 2 ecoregion ID
level3 (char) Level 3 ecoregion ID
name (char) CEC ecoregion description
geom (geom) multipolygon geom
classmethod get_filter(Model, key, db)
class roi.models.CountyFips(*args, **kwargs)

Bases: roi.models.RoiBase

County FIPS table model

Attribute Description
name (char) county name
fips (int) FIPS code
geom (geom) multipolygon geom
class roi.models.EpaAirPartnerships(*args, **kwargs)

Bases: roi.models.RoiBase

Table model for EPA Air Partnerships ROI

Attribute Description
stateprovince (char) foreign key on StateProvince
abbrev (char) partnership abbreviation
name (char) partnership name
classmethod get_filter(Model, key, db)
class roi.models.RoiBase(*args, **kwargs)

Bases: django.db.models.base.Model

Superclass for ROI data models.

classmethod get_intersection_table(db, key)
Returns:IntersectionTable object.
class roi.models.StateProvince(*args, **kwargs)

Bases: roi.models.RoiBase

Table model for US State and Canadian Province ROI

Attribute Description
country (char) country name
abbrev (char) abbreviation
name (char) long name
geom (geom) multipolygon geom
classmethod get_filter(Model, key, db)
key (str) – string used to select the correct boundary in the format: <country>-<ABBREV> usa-CA canada-QC mexico-FX04

Util

This package provides utility functions for processing emissions modeling QuerySets and generating properly formatted outputs.

util.consumewfeis

util.responders

util.custom_manager

class util.custom_manager.GeoManagerWfeis

Overrides GeoManager to return custom GeoQuerySets.

class util.custom_manager.GeoQuerySetWfeis(*args, **kwargs)

Customized GeoQuerySet implementing WFEIS-specific functionality.

add_field(field, values)

Add a field to the QuerySet.

Arguments:
field: (Field) Django field objects from models. be certain to provide
the name keyword or the field will be...nameless. i.e. my_field = models.IntegerField(name=’my_field’)
values: (seq) values to insert into the objects. there must be an entry
for each object in the QuerySet. i.e. [4,10,12]
add_foreign(fkey, fmodel, *args, **kwargs)

Add attributes defined in args to the QuerySet using the foreign key fkey. This function has no logic to automatically rename fields if the field name already exists in the QuerySet.

ewkt()

Convert a GeoQuerySet to EWKT.

extent()

Return the extent of the GeoQuerySet. tup = extent()

Returns:
get_extent_geosgeometry()

Return a GEOSGeometry Polygon object using the exent of the Queryset.

get_field(value)

Return a field with name matching value.

netcdf(grid, type, **kwargs)

str = netcdf(GridPostGis grid, str type

Convert a queryset to a netcdf file.

grid

The grid intersected with the queryset. if a queryset has not been intersected with a grid object, it cannot be converted to a queryset.

type

The type of netcdf to create. This determines the variable type to add to the netcdf. the two available variable types are ‘consumption’ and ‘emissions’. additional variable classes can be declared in responders.netcdf.

Returns:path to the output dataset
rename_field(old_name, new_name)

Rename a field (only works with pseudo/detached querysets.

shp(path=None)

Convert to shapefile and return an HttpResponse.

values(*args, **kwargs)

Return a list of dictionaries. If the _pseudo flag is False, it calls the superclass values method.

args

(str) field names to return. i.e. ‘gridcode’,’fire_name’

flat

(bool) collapse the dictionary to have one key for the list of values. default is False.

Returns:List of dictionaries
values_list(field_name, flat=False)

This is compliant with the superclass Django function.