Lookup Tables

Simulations tend to require a large quantity of data to run. vivarium provides the LookupTable abstraction to ensure that accurate data can be retrieved when it’s needed. It’s a callable object that takes in a population index and returns data specific to the individuals represented by that index. See the lookup concept note for more.

class vivarium.framework.lookup.table.LookupTable(component, data, name, value_columns, manager, population_view)[source]

A callable to produces values for a population index.

In vivarium simulations, the index is synonymous with the simulated population. The lookup system allows the user to provide different kinds of data and strategies for using that data. When the simulation is running, then, components can lookup parameter values based solely on the population index.

Notes

These should not be created directly. Use the lookup attribute on the Builder class during setup.

Parameters:
RESOURCE_TYPE = 'lookup_table'

The type of the resource.

property value_columns: list[str]

The name(s) of the column(s) in the data that will be returned by this lookup table.

population_view: PopulationView

PopulationView to use to get attributes for interpolation or categorization.

return_type: type[T]

The type of data returned by the lookup table (pd.Series or pd.DataFrame).

data: LookupTableData

The data this table will use to produce values.

key_columns: list[str]

Column names to be used as categorical parameters in Interpolation to select between interpolation functions.

parameter_columns: list[str]

Column names to be used as continuous parameters in Interpolation.

interpolation: Interpolation | None

Interpolation object to use when data is a DataFrame. Will be None if data is a scalar or list of scalars.

set_data(data)[source]

Set the data and associated attributes for the lookup table.

This method is called during initialization and when updating the data of the lookup table. It is responsible for validating and setting the data. If the data is a DataFrame, it also sets the key_columns and parameter_columns attributes and initializes the Interpolation object.

Return type:

None

Parameters:

data (SupportsFloat | Timedelta | timedelta | Timestamp | datetime | DataFrame | list[SupportsFloat | Timedelta | timedelta | Timestamp | datetime] | tuple[SupportsFloat | Timedelta | timedelta | Timestamp | datetime, ...] | Mapping[str, list[SupportsFloat | Timedelta | timedelta | Timestamp | datetime] | list[str]]) – The data this table will use to produce values. Can be a scalar, list of scalars, or a pandas DataFrame.

static get_name(component_name, table_name)[source]

Get the fully qualified name for a lookup table.

Return type:

str

Parameters:
  • component_name (str) – Name of the component the lookup table belongs to.

  • table_name (str) – Name of the lookup table.

Returns:

Fully qualified name for the lookup table.