The module pygchem.emissions
provides an API for Harvard-NASA Emissions Component (HEMCO). Currently, it allows to read / write HEMCO configuration files and to browse or edit an existing configuration (or create a new configuration from scratch).
Note: this module is under active development and doesn't work yet with the last release of HEMCO.
In [2]:
from pygchem import emissions
We will use the following file as an example:
In [3]:
hemco_example_file = '../data/HEMCO_test'
The following line loads the setup detailled in that file:
In [4]:
hemco_setup = emissions.load_setup(hemco_example_file)
The HEMCO setup consists of several extensions (including the HEMCO Core extension), which may have one or several attached emission data fields. Each emission data field may, in turn, have one or several scale factor or mask data fields that will be applied to it.
Use the extensions
attribute to access to all extensions listed in the setup:
In [5]:
hemco_setup.extensions
Out[5]:
The extensions
attribute is a RecordList
object (see the pygchem.utils.data_structures
module). That object mainly behaves like a Python list, but it also allows to select extensions based on their properties, to remove selected extensions or to add new extensions.
Each item in the RecordList
is an EmmisionExt
object, which inherits from the Record
class.
Select one extension based on its name:
In [6]:
megan_ext = hemco_setup.extensions.select_item("MEGAN")
megan_ext
Out[6]:
Select one or several extensions based on other attributes:
In [7]:
selection = hemco_setup.extensions.select(enabled=False)
# get the names of the selected extensions
selection.keys
Out[7]:
Some parameters related to the previously selected extension:
In [8]:
megan_ext.name
Out[8]:
In [9]:
megan_ext.enabled
Out[9]:
In [10]:
megan_ext.eid # extension ID
Out[10]:
In [11]:
megan_ext.settings
Out[11]:
Get all base emission fields assigned to the extension:
In [12]:
megan_bef = megan_ext.base_emission_fields
print megan_bef
Get all extension data fields for this extension:
In [13]:
megan_df = megan_ext.extension_data
print megan_df
Get all base emission fields in the HEMCO configuration:
In [14]:
all_bef = hemco_setup.base_emission_fields
# get the names of the base emission fields
print all_bef.keys
In [19]:
bef = []
for ext in hemco_setup.extensions:
print ext
print ext.extension_data + ext.base_emission_fields
bef.extend(ext.base_emission_fields + ext.extension_data)
In [ ]: