UCL / TLOmodel

Epidemiology modelling framework for the Thanzi la Onse project
https://www.tlomodel.org/
MIT License
13 stars 5 forks source link

Adding script for generating table of parameters #1422

Closed matt-graham closed 2 months ago

matt-graham commented 4 months ago

Work in progress but should resolve #1419

Script can be run from root of respository with

python docs/tlo_parameters.py resources parameters.md

with this generating a Markdown output parameters.md which can be converted to HTML with

pandoc -s parameters.md -o parameters.html --css pandoc.css --self-contained

using CSS from https://gist.github.com/killercup/5917178

I'll hopefully be able to get this to also output reStructuredText to allow running as part of the documentation build and including on the website.

tbhallett commented 2 months ago

I've made an edit to make the pagination more manageable (by excluding two parameters, which are really just datasets). Also, excluded the Wasting module that has no parameters.

Subject: [PATCH] exclude wasting and exclude certain parameters
---
Index: docs/tlo_parameters.py
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/docs/tlo_parameters.py b/docs/tlo_parameters.py
--- a/docs/tlo_parameters.py    (revision de44e443565ff02dfd836db4a40e101a792866e2)
+++ b/docs/tlo_parameters.py    (revision 8b315ded68f4bd4bcdaa8f1c6a152f1cfb696886)
@@ -73,6 +73,7 @@
     modules: Iterable[Module],
     overriden_parameters: dict[str, dict[str, ParameterValue]],
     excluded_modules: set[str],
+    excluded_parameters: dict[str, str],
     max_inline_parameter_length: int = 10,
 ) -> tuple[ModuleParameterTablesDict, ModuleStructuredParametersDict]:
     module_parameter_tables = {}
@@ -83,6 +84,8 @@
         parameter_records = []
         module_structured_parameters[module.name] = {}
         for parameter_name, parameter in module.PARAMETERS.items():
+            if parameter_name in excluded_parameters.get(module.name, set()):
+                continue
             if (
                 module.name in overriden_parameters
                 and parameter_name in overriden_parameters[module.name]
@@ -225,7 +228,9 @@
     status_quo_parameters = get_parameters_for_status_quo()
     simulation.register(*fullmodel.fullmodel(args.resource_file_path))
     module_parameter_tables, module_structured_parameters = get_parameter_tables(
-        simulation.modules.values(), status_quo_parameters, {"HealthBurden"}
+        simulation.modules.values(), status_quo_parameters, {"HealthBurden", "Wasting"},
+        {"Demography": "gbd_causes_of_death_data",
+         "Tb": "who_incidence_estimates"}
     )
     write_parameters_markdown_file(
         args.output_file_path, module_parameter_tables, module_structured_parameters
matt-graham commented 2 months ago

Thanks @tbhallett - I've applied the patch you suggested and also now updated to allow outputting a reStructuredText file as well as Markdown to allow inclusion in our docs, and updated the docs build to automatically generate this page.

tbhallett commented 2 months ago

Thanks @matt-graham -- that's brilliant and very timely. It will be great to have this on the website.

matt-graham commented 2 months ago

@tbhallett just to check are you happy for this to be merged in? Know that you already approved but as I made a few subsequent changes after that wanted to make sure!

tbhallett commented 2 months ago

Yes please do merge in. Thanks again. And, if you can, please could you also regenerate the website so that it appears there?