I'm trying to figure out how to use injectables, such as "year", in orca columns. Specifically, I'd like to define a variable determining the age of buildings, i.e. the variable needs to have an access to the simulation year. Year is defined in urbansim_defaults/datasources.py as:
@orca.injectable('year')
def year(iter_var):
return iter_var
Our age variable uses it as follows:
@orca.column('buildings', 'age', cache=True, cache_scope='iteration')
def age(buildings, year):
year_built = buildings.year_built
year_built[buildings.has_valid_age_built==0] = np.nan
return np.maximum(0, year - year_built)
This works in an estimation setting. However, in a simulation setting orca throws an error complaining about iter_var, see below. The error appears even if the age variable is not used. If I comment out this column definition, the simulation works. What am I doing wrong?
Error:
Traceback (most recent call last):
File "simulate.py", line 22, in <module>
], iter_vars=[2015], data_out="simresult.h5")
File "/Users/hana/udst/orca/orca/orca.py", line 1912, in run
write_tables(data_out, out_base_tables, 'base')
File "/Users/hana/udst/orca/orca/orca.py", line 1855, in write_tables
store[key_template.format(t.name)] = t.to_frame()
File "/Users/hana/udst/orca/orca/orca.py", line 229, in to_frame
df[name] = col()
File "/Users/hana/udst/orca/orca/orca.py", line 632, in __call__
expressions=self._argspec.defaults)
File "/Users/hana/udst/orca/orca/orca.py", line 952, in _collect_variables
variables[label] = thing()
File "/Users/hana/udst/orca/orca/orca.py", line 747, in __call__
expressions=self._argspec.defaults)
File "/Users/hana/udst/orca/orca/orca.py", line 949, in _collect_variables
thing = all_variables[expression]
KeyError: 'iter_var'