A new attribute name can be declared and initialized using an assignment statement:
lnpop = ln(urbansim.gridcell.population)
This is treated as an expression, which can occur in the list of expressions given to compute_variables or in an aliases.py file (see below). The value of the new alias is returned as the value of the expression if it's the last item on the list of variables and expressions.
It is convenient, and often more efficient, to gather all the expressions and aliases for a particular package and dataset into one place. The optional aliases.py file supports this. This file should define a single variable aliases to be a list of expressions, each of which should define an alias. This file is then placed in the same directory as variables for that package and dataset. For example, to define aliases relevant to urbansim.gridcell, put an aliases.py file into the urbansim.gridcell directory. These aliases can then be referred to using the fully-qualified name of the alias. When finding a variable referenced by a fully-qualified name, the system first searches the aliases file (if present), and then the variable definitions in the appropriate directory.
As an example, the directory opus_core.test_agent contains one variable definition, for the variable income_times_2. (This directory and variable are used for unit tests for opus_core.) The file aliases.py in that same directory contains the following:
aliases = [
'income_times_5 = 5*opus_core.test_agent.income',
'income_times_10 = 5*opus_core.test_agent.income_times_2'
]
The first alias refers to a primary attribute (test_agent.income), and the second to the variable. These aliases can then be referred to using a fully-qualified name, in exactly the same way as a variable, for example
opus_core.test_agent.income_times_5.
See the unit tests in opus_core.variables.expression_tests.aliases_file for examples of using these aliases.