next up previous index
Next: Invoking Computation Up: Variable Concept Previous: Variable Concept   Index


Dataset Pool

When computing variable values, Opus may need to access datasets used by dependent variables, such as the urbansim_constant dataset required by is_in_wetland, above. These datasets are provided by the dataset_pool object passed into the variable's compute method. This object is an instance of the DatasetPool class (see Section 22.7.1). It is responsible for keeping a set of datasets for use when computing variables. If the requested dataset is in the pool already, it is returned directly, otherwise it tries to find it in the given storage.

In order to find the appropriate dataset class for the requested dataset, the dataset pool object searches the datasets directories of the Opus packages in package_order. The first one to contain the appropriately named module and class is used. For instance, using the storage object created on page [*], for the definition:

>>> from opus_core.dataset_pool import DatasetPool
>>> dataset_pool = DatasetPool(package_order=['urbansim', 'opus_core'],
                               storage=storage)
if dataset_pool is asked for the ``household'' dataset, and does not already have one in its pool, it will look in the storage. In order to create the corresponding dataset classes it searches for a file household_dataset.py (containing the class HouseholdDataset) first in urbansim/datasets and then in opus_core/datasets. The first one found will be used.
>>> dataset_pool.datasets_in_pool()
{}
>>> hs = dataset_pool.get_dataset("household")
>>> dataset_pool.datasets_in_pool()
{'household': <urbansim.datasets.household_dataset.HouseholdDataset object
                                                               at 0x197c2f70>}
>>> hs.size()
10
If the dataset pool is asked for urbansim_constant and `urbansim' is included in package_order, it will use some urbansim specific constants defined in urbansim/constants.py (in addition to user defined constants found on storage).

For the purpose of this example, we set the required constant by:

>>> constant = dataset_pool.get_dataset("urbansim_constant")
>>> constant["percent_coverage_threshold"] = 50


next up previous index
Next: Invoking Computation Up: Variable Concept Previous: Variable Concept   Index
info (at) urbansim.org