You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add section to lookup.rst about configuring source via component (#694)
* Add section to lookup.rst about configuring source via component
* add blank line
* adjustments for feedback
* add nitpick exceptions
* update references and backticks
* update method references
* remove nitpick exceptions
* fix model spec file link
* add backticks for listeners, add logger ref
* fix ref to artifactmanager
* add ref to pop view
* add note about data sources in config defaults
* changelog
* update class reference
* add links
* fix link formatting
* Update CHANGELOG date for version 3.6.4
A string of the form ``"self::method_name"`` that references a method on
216
+
the component itself. The method should accept a ``builder`` argument and
217
+
return the data. This is primarily for use in
218
+
:ref:`model specification YAML files <model_specification_concept>` where
219
+
direct method references are not possible.
220
+
221
+
**External function reference (string with** ``module.path::`` **):**
222
+
A string of the form ``"module.path::function_name"`` that references a
223
+
function in another module. The function should accept a ``builder``
224
+
argument and return the data. This is primarily for use in
225
+
:ref:`model specification YAML files <model_specification_concept>` where
226
+
direct method references are not possible.
227
+
228
+
229
+
230
+
Column Detection
231
+
^^^^^^^^^^^^^^^^
232
+
233
+
When building a lookup table from a :class:`pandas.DataFrame` using ``data_sources``,
234
+
the component automatically determines key columns, parameter columns, and value columns
235
+
based on the data structure:
236
+
237
+
- **Value columns** are assumed by the structure of the artifact to be ``["value"]``. In principle,
238
+
this could be configured by implementing a custom :class:`~vivarium.framework.artifact.manager.ArtifactManager`.
239
+
- **Parameter columns** are detected by finding columns ending in ``_start``
240
+
that have corresponding ``_end`` columns (e.g., ``age_start``/``age_end``).
241
+
- **Key columns** are all remaining columns that are neither value columns
242
+
nor parameter bin edge columns.
243
+
244
+
See the `Construction Parameters`_ section for definitions of these
245
+
column types.
246
+
247
+
Example: Writing a Component with Data Sources
248
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
249
+
250
+
A more complete example is reproduced from the `Mortality <https://vivarium.readthedocs.io/projects/vivarium-public-health/en/latest/api_reference/population/mortality.html>`_ component in `vivarium_public_health <https://vivarium.readthedocs.io/projects/vivarium-public-health/en/latest/>`_:
The automatic ``data_sources`` mechanism works well for straightforward cases,
297
+
but some situations require overriding the :meth:`~vivarium.component.Component.build_all_lookup_tables` method:
298
+
299
+
**Non-standard value columns:**
300
+
The component defaults to ``["value"]`` as the value column name. If your
301
+
data has differently named value columns or multiple value columns, you
302
+
must call :meth:`~vivarium.component.Component.build_lookup_table` directly with explicit
303
+
``value_columns``.
304
+
305
+
**Complex data transformations:**
306
+
When data requires transformation before building tables (e.g., pivoting,
307
+
computing derived parameters, combining multiple data sources), override
308
+
:meth:`~vivarium.component.Component.build_all_lookup_tables` to perform the transformation first.
309
+
310
+
**Delegation to sub-components:**
311
+
When lookup tables should be built by sub-components rather than the
312
+
parent component, override :meth:`~vivarium.component.Component.build_all_lookup_tables` to skip the
313
+
default behavior.
314
+
315
+
Examples of these patterns can be found in `vivarium_public_health <https://vivarium.readthedocs.io/projects/vivarium-public-health/en/latest/>`_:
316
+
317
+
- `RateTransition <https://vivarium.readthedocs.io/projects/vivarium-public-health/en/latest/api_reference/disease/transition.html>`_ and `DiseaseState <https://vivarium.readthedocs.io/projects/vivarium-public-health/en/latest/api_reference/disease/state.html>`_ in `vivarium_public_health.disease <https://vivarium.readthedocs.io/projects/vivarium-public-health/en/latest/api_reference/disease/>`_
318
+
demonstrate the basic ``data_sources`` pattern with various data source types.
319
+
- ``Risk`` in ``vivarium_public_health.risks`` overrides :meth:`~vivarium.component.Component.build_all_lookup_tables`
320
+
to delegate table construction to its exposure distribution sub-component.
321
+
322
+
Using the Lookup Interface Directly
323
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
324
+
325
+
For cases not covered by ``data_sources``, or when working in an interactive
326
+
context, you can build lookup tables directly using the builder's lookup
327
+
interface.
328
+
145
329
Example Usage
146
330
~~~~~~~~~~~~~
147
331
148
332
The following is an example of creating and calling a lookup table in an
149
-
:ref:`interactive setting <interactive_tutorial>` using the data above. The
150
-
interface and process are the same when integrating a lookup table into a
151
-
:term:`component <Component>`, which is primarily how they are used. Assuming
152
-
you have a valid simulation object named ``sim`` and the data from the above
153
-
table in a :class:`pandas.DataFrame` named ``data``, you can construct a
154
-
lookup table in the following way, using the interface from the builder.
333
+
:ref:`interactive setting <interactive_tutorial>` using the data from
334
+
`Construction Parameters`_ above. The interface and process are the same when
335
+
integrating a lookup table into a :term:`component <Component>`, which is primarily
336
+
how they are used. Assuming you have a valid simulation object named ``sim`` and
337
+
the data from the above table in a :class:`pandas.DataFrame` named ``data``, you
338
+
can construct a lookup table in the following way, using the interface from the builder.
0 commit comments