Skip to content

Stop adding units to emitted data keys #166

@U8NWXD

Description

@U8NWXD

Currently, when we emit data that has a unit in the state hierarchy and format it as a timeseries, we put the unit into the key and strip the units from the value. For example, we might get:

{
    'external': {
        ('antibiotic', 'millimolar'): [1, 2, 3],
    }
}

This is not ideal. Instead, our plotting functions should know how to handle Quantity objects.

Here's where we do the unit conversion:

if isinstance(value, Quantity):
unit_key = (key, str(value.units))
if unit_key not in timeseries:
timeseries[unit_key] = []
timeseries[unit_key].append(value.magnitude)

And here's a trace of the calls in emitter.py that lead to the code above:

  • vivarium.library.dict_utils.value_in_embedded_dict()
  • vivarium.core.emitter.timeseries_from_data()
  • vivarium.core.emitter.Emitter.get_timeseries()

Note that addressing this will probably be a breaking API change since doing so will change our output format.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions