Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🩹 Fix 'dataset_groups' not shown in model markdown #906

Merged
merged 2 commits into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions glotaran/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,15 @@ def markdown(
string += ", ".join(self._megacomplex_types)
string += "\n\n"

string += f"{base_heading}# Dataset Groups\n\n"
for group_name, group in self.dataset_group_models.items():
string += f"* **{group_name}**:\n"
string += f" * *Label*: {group_name}\n"
for item_name, item_value in asdict(group).items():
string += f" * *{item_name}*: {item_value}\n"

string += "\n"

for name in self.model_items:
items = getattr(self, name)
if not items:
Expand Down
75 changes: 75 additions & 0 deletions glotaran/model/test/test_model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from math import inf
from math import nan
from textwrap import dedent
from typing import Dict
from typing import List
from typing import Tuple
Expand All @@ -22,6 +23,7 @@
from glotaran.model.weight import Weight
from glotaran.parameter import Parameter
from glotaran.parameter import ParameterGroup
from glotaran.testing.model_generators import SimpleModelGenerator


@model_item(
Expand Down Expand Up @@ -485,3 +487,76 @@ def test_only_constraint():
assert not oc2.applies(650)
assert oc2.applies(701)
assert oc2.target == "spectra2"


def test_model_markdown():
"""Full markdown string is as expected."""
model = SimpleModelGenerator(
rates=[501e-3, 202e-4, 105e-5, {"non-negative": True}],
irf={"center": 1.3, "width": 7.8},
k_matrix="sequential",
)
expected = dedent(
"""\
# Model

_Megacomplex Types_: decay

## Dataset Groups

* **default**:
* *Label*: default
* *residual_function*: variable_projection
* *link_clp*: None

## K Matrix

* **k1**:
* *Label*: k1
* *Matrix*:
* *('s2', 's1')*: rates.1: **5.01000e-01** *(StdErr: 0e+00)*
* *('s3', 's2')*: rates.2: **2.02000e-02** *(StdErr: 0e+00)*
* *('s3', 's3')*: rates.3: **1.05000e-03** *(StdErr: 0e+00)*


## Initial Concentration

* **j1**:
* *Label*: j1
* *Compartments*: ['s1', 's2', 's3']
* *Parameters*: [inputs.1: **1.00000e+00** *(fixed)*, inputs.0: **0.00000e+00** *(fixed)*, inputs.0: **0.00000e+00** *(fixed)*]
* *Exclude From Normalize*: []

## Irf

* **irf1** (multi-gaussian):
* *Label*: irf1
* *Type*: multi-gaussian
* *Center*: [irf.center: **1.30000e+00** *(StdErr: 0e+00)*]
* *Width*: [irf.width: **7.80000e+00** *(StdErr: 0e+00)*]
* *Normalize*: True
* *Backsweep*: False

## Megacomplex

* **mc1** (None):
* *Label*: mc1
* *Dimension*: time
* *K Matrix*: ['k1']

## Dataset

* **dataset1**:
* *Label*: dataset1
* *Group*: default
* *Megacomplex*: ['mc1']
* *Initial Concentration*: j1
* *Irf*: irf1

""" # noqa: E501
)

# Preprocessing to remove trailing whitespace after '* *Matrix*:'
result = "\n".join([line.rstrip(" ") for line in str(model.markdown()).split("\n")])

assert result == expected