Emissions: HEMCO Python API

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

Loading a configuration from file

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)

Browsing the configuration setup

Browsing through the configuration tree

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]:
Record list of 12 EmissionExt:
KeyEmissionExt
0CoreEmissionExt(name=Core, enabled=True, base_emission_fields=<RecordList(304 EmissionBase, keys=['GEIA_ALK4', 'GEIA_ACET', 'GEIA_PRPE', 'GEIA_MEK', 'GEIA_NH3_ANTH', 'GEIA_NH3_BIOF', 'GEIA_NH3_NATU', ... , 'GFED3_CH4_WDL'])>, extension_data=<RecordList(0 EmissionBase, keys=[])>, species=None, settings={}, eid=0)
1CustomEmissionExt(name=Custom, enabled=False, base_emission_fields=<RecordList(0 EmissionBase, keys=[])>, extension_data=<RecordList(0 EmissionBase, keys=[])>, species=[], settings={}, eid=100)
2SeaFluxEmissionExt(name=SeaFlux, enabled=True, base_emission_fields=<RecordList(0 EmissionBase, keys=[])>, extension_data=<RecordList(3 EmissionBase, keys=['CH3I_SEAWATER', 'DMS_SEAWATER', 'ACET_SEAWATER'])>, species=['CH3I', 'DMS', 'ACET'], settings={}, eid=101)
3ParaNOxEmissionExt(name=ParaNOx, enabled=True, base_emission_fields=<RecordList(0 EmissionBase, keys=[])>, extension_data=<RecordList(3 EmissionBase, keys=['ICOADS_SHIP_NO', 'EDGAR_SHIP_NO', 'EMEP_SHIP_NO'])>, species=['NO', 'NO2', 'O3', 'HNO3'], settings={}, eid=102)
4LightNOxEmissionExt(name=LightNOx, enabled=True, base_emission_fields=<RecordList(0 EmissionBase, keys=[])>, extension_data=<RecordList(1 EmissionBase, keys=['LIGHTNOX_REDIST'])>, species=['NO'], settings={'CDF table': '/home/ckeller/data/emis/LIGHTNOX/light_dist.ott2010.dat'}, eid=103)
5SoilNOxEmissionExt(name=SoilNOx, enabled=True, base_emission_fields=<RecordList(0 EmissionBase, keys=[])>, extension_data=<RecordList(31 EmissionBase, keys=['SOILNOX_PFACT', 'SOILNOX_DRYPER', 'SOILNOX_GWET', 'SOILNOX_DEPRES', 'SOILNOX_FERT', 'SOILNOX_LANDK1', 'SOILNOX_LANDK2', ... , 'SOILNOX_NONARID'])>, species=['NO'], settings={'Use fertilizer NOx': True}, eid=104)
6DustDeadEmissionExt(name=DustDead, enabled=True, base_emission_fields=<RecordList(0 EmissionBase, keys=[])>, extension_data=<RecordList(8 EmissionBase, keys=['DEAD_EF_GEO', 'DEAD_LF_DRY', 'DEAD_MF_CACO3', 'DEAD_MF_CLY', 'DEAD_MF_SND', 'DEAD_SFC_TYP', 'DEAD_GOC_SRC', 'DEAD_VAI'])>, species=['DST1', 'DST2', 'DST3', 'DST4'], settings={}, eid=105)
7DustGinouxEmissionExt(name=DustGinoux, enabled=False, base_emission_fields=<RecordList(0 EmissionBase, keys=[])>, extension_data=<RecordList(3 EmissionBase, keys=['GINOUX_SAND', 'GINOUX_SILT', 'GINOUX_CLAY'])>, species=['DST1', 'DST2', 'DST3', 'DST4'], settings={}, eid=106)
8SeaSaltEmissionExt(name=SeaSalt, enabled=True, base_emission_fields=<RecordList(0 EmissionBase, keys=[])>, extension_data=<RecordList(0 EmissionBase, keys=[])>, species=['SALA', 'SALC', 'Br2'], settings={'SALA upper radius': 0.5, 'SALA lower radius': 0.01, 'SALC upper radius': 8.0, 'Emit Br2': True, 'Br2 scaling': 1.0, 'SALC lower radius': 0.5}, eid=107)
9MEGANEmissionExt(name=MEGAN, enabled=True, base_emission_fields=<RecordList(0 EmissionBase, keys=[])>, extension_data=<RecordList(2 EmissionBase, keys=['MEGAN_AEF_ISOP', 'MEGAN_AEF_ACET'])>, species=['ISOP', 'ACET', 'PRPE', 'C2H4'], settings={'PECCA model': True, 'Isoprene scaling': 1.0}, eid=108)
10MEGAN_MonoEmissionExt(name=MEGAN_Mono, enabled=True, base_emission_fields=<RecordList(0 EmissionBase, keys=[])>, extension_data=<RecordList(9 EmissionBase, keys=['MEGAN_AEF_MONOT', 'MEGAN_AEF_MBO', 'MEGAN_AEF_APINE', 'MEGAN_AEF_BPINE', 'MEGAN_AEF_LIMON', 'MEGAN_AEF_SABIN', 'MEGAN_AEF_MYRCN', ... , 'MEGAN_AEF_OCIMN'])>, species=['MONX', 'OCPI', 'CO'], settings={}, eid=109)
11MEGAN_SOAEmissionExt(name=MEGAN_SOA, enabled=False, base_emission_fields=<RecordList(0 EmissionBase, keys=[])>, extension_data=<RecordList(1 EmissionBase, keys=['MEGAN_ORVC'])>, species=['ALPH', 'LIMO', 'ALCO'], settings={}, eid=110)

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]:
EmissionExt(name=MEGAN, enabled=True, base_emission_fields=<RecordList(0 EmissionBase, keys=[])>, extension_data=<RecordList(2 EmissionBase, keys=['MEGAN_AEF_ISOP', 'MEGAN_AEF_ACET'])>, species=['ISOP', 'ACET', 'PRPE', 'C2H4'], settings={'PECCA model': True, 'Isoprene scaling': 1.0}, eid=108)

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]:
['Custom', 'DustGinoux', 'MEGAN_SOA']

Some parameters related to the previously selected extension:


In [8]:
megan_ext.name


Out[8]:
'MEGAN'

In [9]:
megan_ext.enabled


Out[9]:
True

In [10]:
megan_ext.eid   # extension ID


Out[10]:
108

In [11]:
megan_ext.settings


Out[11]:
{'Isoprene scaling': 1.0, 'PECCA model': True}

Get all base emission fields assigned to the extension:


In [12]:
megan_bef = megan_ext.base_emission_fields
print megan_bef


Record list of 0 EmissionBase:

Get all extension data fields for this extension:


In [13]:
megan_df = megan_ext.extension_data
print megan_df


Record list of 2 EmissionBase:
0 | MEGAN_AEF_ISOP: EmissionBase(name=MEGAN_AEF_ISOP, filename=/home/ckeller/data/emis/MEGAN/nc/MEGANv2.1_AEF.geos.1x1.nc, var_name=AEF_ISOPRENE, ndim=2, units=kgC/m2/s, timeslicer=1985/1/1/0, species=ISOP, category=1, hierarchy=1, datafield=None, scale_factors=<RecordList(0 EmissionScale or EmssionMask, keys=[])>)
1 | MEGAN_AEF_ACET: EmissionBase(name=MEGAN_AEF_ACET, filename=/home/ckeller/data/emis/MEGAN/nc/MEGANv2.1_AEF.geos.1x1.nc, var_name=AEF_ACETONE, ndim=2, units=kgC/m2/s, timeslicer=1985/1/1/0, species=ACET, category=1, hierarchy=1, datafield=None, scale_factors=<RecordList(0 EmissionScale or EmssionMask, keys=[])>)

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


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-14-48eb1caea42a> in <module>()
----> 1 all_bef = hemco_setup.base_emission_fields
      2 
      3 # get the names of the base emission fields
      4 print all_bef.keys

/home/bovy/GitRepos/PyGChem/pygchem/emissions.pyc in base_emission_fields(self)
    288         bef = []
    289         for ext in self.extensions:
--> 290             bef.extend(ext.base_emission_fields + ext.extension_data)
    291         return RecordList(bef, ref_classes=EmissionBase, read_only=True,
    292                           key_attr='name')

TypeError: 'NoneType' object is not iterable

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)


EmissionExt(name=Core, enabled=True, base_emission_fields=<RecordList(304 EmissionBase, keys=['GEIA_ALK4', 'GEIA_ACET', 'GEIA_PRPE', 'GEIA_MEK', 'GEIA_NH3_ANTH', 'GEIA_NH3_BIOF', 'GEIA_NH3_NATU', ... , 'GFED3_CH4_WDL'])>, extension_data=<RecordList(0 EmissionBase, keys=[])>, species=None, settings={}, eid=0)
None
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-19-a9515ef37a30> in <module>()
      3     print ext
      4     print ext.extension_data + ext.base_emission_fields
----> 5     bef.extend(ext.base_emission_fields + ext.extension_data)

TypeError: 'NoneType' object is not iterable

In [ ]: