dsegerss/pyAirviro — pull request #6 by mjakob (2014-02-12 07:31:11+00:00)
Title: Resolve emission sources for dispersion calculations

The pull request introduces **sourceResolve** - a script to resolve emission sources before they can be used in dispersion calculations. For usage and information about the options, run sourceResolve -h.

The script is a front-end for a new sub-package, **pyAirviro.resolvers**, that contains a framework for defining new resolvers. This framework is centered around a Resolver class. A resolver should derive from **BaseResolver** and implement the abstract method **resolve()**. This method takes a single source and should prepare it for emission calculations. If successful, the method should return the resolved source.

A resolver should be registered in the **pyAirviro.resolvers** entry group, which automatically makes it a sub-command of the *sourceResolve* tool. If the resolver needs any command line arguments, the **populate_argument_parser()** class method can be used. It receives the sub-command argument parser as its single argument.

Finally, *BaseResolver* has a **prepare_target_edb()** method that receives the target edb for the resolved sources. If this edb needs to be prepared in some way, this is the place to do it.

A more refined **TemplateResolver** class is also available. It uses a template edb to fill in any missing parameters of the sources to be resolved. To find a template for each source, it uses sub-classes of **BaseIndexer** in the **pyAirviro.resolvers.indexers** module. One indexer is implemented, **StatCode5Indexer**, that uses the hierarchical StatCode 5 system to match sources.

By default, sub-classes of *TemplateResolver* check all parameters (ALOB and activity variables) of the template class to make sure they are set on the target source. If not, it copies the template value. If this simple algorithm is not enough, custom *getters* can be defined on the resolver. If for instance the *build_year* ALOB parameter needs some custom logic when the target value is missing, a method *get_alob__build_year()* can be implemented. This method receives the target source and the corresponding parameter value of the template source. The template source itself is available in the *self.template* attribute. If the calculated parameter value depends on another parameter value, the **depends()** decorator can be used to make sure that this value is resolved before the current one.

One *TemplateResolver* is implemented in this pull request: **TUR2013**. This resolver prepare ship emission sources for emission and dispersion calculations for the project in Turkey, 2013.