Skip to content

Commit

Permalink
Refactored ModelProperty. (#914)
Browse files Browse the repository at this point in the history
* Refactored ModelProperty

Markdown printing of Model has been changed
- Beautification is left for followup PR
- Further refactoring (and introspection) detailed in issue #917 

Co-authored-by: Sebastian Weigand <[email protected]>
  • Loading branch information
joernweissenborn and s-weigand authored Nov 29, 2021
1 parent 979643a commit 88111bb
Show file tree
Hide file tree
Showing 13 changed files with 689 additions and 262 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ repos:
args:
- "--select=D,DAR"
name: "flake8 lint docstrings"
files: "^glotaran/(plugin_system|utils|deprecation|testing|parameter|project)"
files: "^glotaran/(plugin_system|utils|deprecation|testing|parameter|project|model/property.py)"
exclude: "docs|tests?/"
additional_dependencies: [flake8-docstrings, darglint==1.8.0]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.910-1
hooks:
- id: mypy
files: "^glotaran/(plugin_system|utils|deprecation|testing|parameter|project)"
files: "^glotaran/(plugin_system|utils|deprecation|testing|parameter|project|model/property.py)"
exclude: "docs"
additional_dependencies: [types-all]

Expand Down
38 changes: 21 additions & 17 deletions glotaran/builtin/io/yml/test/test_model_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_dataset(model):
assert dataset.megacomplex == ["cmplx1"]
assert dataset.initial_concentration == "inputD1"
assert dataset.irf == "irf1"
assert dataset.scale == 1
assert dataset.scale.full_label == "1"

assert "dataset2" in model.dataset
dataset = model.dataset["dataset2"]
Expand All @@ -55,7 +55,7 @@ def test_dataset(model):
assert dataset.megacomplex == ["cmplx2"]
assert dataset.initial_concentration == "inputD2"
assert dataset.irf == "irf2"
assert dataset.scale == 2
assert dataset.scale.full_label == "2"
assert dataset.spectral_axis_scale == 1e7
assert dataset.spectral_axis_inverted

Expand Down Expand Up @@ -83,7 +83,7 @@ def test_penalties(model):
assert eac.source_intervals == [[670, 810]]
assert eac.target == "s2"
assert eac.target_intervals == [[670, 810]]
assert eac.parameter == 55
assert eac.parameter.full_label == "55"
assert eac.weight == 0.0016


Expand All @@ -108,7 +108,7 @@ def test_initial_concentration(model):
assert initial_concentration.compartments == ["s1", "s2", "s3"]
assert isinstance(initial_concentration, InitialConcentration)
assert initial_concentration.label == label
assert initial_concentration.parameters == [1, 2, 3]
assert [p.full_label for p in initial_concentration.parameters] == ["1", "2", "3"]


def test_irf(model):
Expand All @@ -120,17 +120,18 @@ def test_irf(model):
irf = model.irf[label]
assert isinstance(irf, IrfMultiGaussian)
assert irf.label == label
want = [1] if i == 1 else [1, 2]
assert irf.center == want
want = [2] if i == 1 else [3, 4]
assert irf.width == want
want = [3] if i == 1 else [5, 6]
want = ["1"] if i == 1 else ["1", "2"]
assert [p.full_label for p in irf.center] == want
want = ["2"] if i == 1 else ["3", "4"]
assert [p.full_label for p in irf.width] == want

if i == 2:
assert irf.center_dispersion_coefficients == want
want = [7, 8]
assert irf.width_dispersion_coefficients == want
want = [9]
assert irf.scale == want
want = ["3"] if i == 1 else ["5", "6"]
assert [p.full_label for p in irf.center_dispersion_coefficients] == want
want = ["7", "8"]
assert [p.full_label for p in irf.width_dispersion_coefficients] == want
want = ["9"]
assert [p.full_label for p in irf.scale] == want
assert irf.normalize == (i == 1)

if i == 2:
Expand All @@ -144,10 +145,13 @@ def test_irf(model):
def test_k_matrices(model):
assert "km1" in model.k_matrix
parameter = ParameterGroup.from_list([1, 2, 3, 4, 5, 6, 7])
print(model.k_matrix["km1"].fill(model, parameter).matrix)
reduced = model.k_matrix["km1"].fill(model, parameter).reduced(["s1", "s2", "s3", "s4"])
assert np.array_equal(
reduced, np.asarray([[1, 3, 5, 7], [2, 0, 0, 0], [4, 0, 0, 0], [6, 0, 0, 0]])
)
print(parameter)
print(reduced)
wanted = np.asarray([[1, 3, 5, 7], [2, 0, 0, 0], [4, 0, 0, 0], [6, 0, 0, 0]])
print(wanted)
assert np.array_equal(reduced, wanted)


def test_weight(model):
Expand Down
4 changes: 2 additions & 2 deletions glotaran/builtin/io/yml/test/test_model_spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ dataset:

irf:
irf1:
type: gaussian
type: multi-gaussian
center: [1]
width: [2]
irf2:
type: spectral-gaussian
type: spectral-multi-gaussian
center: [1, 2]
width: [3, 4]
scale: [9]
Expand Down
Loading

0 comments on commit 88111bb

Please sign in to comment.