next up previous index
Next: Attribute Names Up: Datasets Previous: Loading Attributes   Index

Computing Variables

Datasets automatically compute each variable when, and only when, needed. This mechanism uses the dependency information from each variable which gives an information about what variables this variable depends on. Additionally, it is checked if variable's dependent variables have changed (versioning mechanism). The computation is invoked by the dataset method compute_variables() which computes each of the given variables if either (a) this variable has not been computed before, or (b) the inputs to this variable (the values of variables upon which this variable depends) have changed since the last computation. Thus, invoking compute_variables() on a single variable may either result in no more computation, or have a ripple effect of computing many variables upon which this one variable depends. Lazily computing variables both helps minimize the computational load as well as eliminating the need to worry about when variables are computed: it will happen when, and only when, it is needed.

The method compute_variables() takes as an arguments a list of variable names to be computed and an object of class Resources which is a dictionary with all objects and arguments the variable (and its dependent variables) need for the computation.

As mentioned before, datasets automatically load each attribute into memory when, and only when, the data for that attribute is needed. This is done either as a side-effect of the compute_variables(), or via get_attribute(). If the attribute is defined by a variable, you must first use the compute_variables() method to force that variable to compute its values for every member of the dataset.


next up previous index
Next: Attribute Names Up: Datasets Previous: Loading Attributes   Index
info (at) urbansim.org