Skip to content

Commit

Permalink
🩹 Fix and re-enable IRF Dispersion Test (#786)
Browse files Browse the repository at this point in the history
* Fix and re-enable IRF Dispersion Test

Improve the tests in test_spectral_irf
Added NoDispersion test
Re-enable IrfDispersion tests on the CI (de-Volkswagen the tests)
Improve assignment of center_dispersion to result dataset

* Rename center_dispersion to irf_center_location in result

The name irf_center_location in the results describes more clearly what the variable holds.
Deprecated irf model item center_dispersion  for center_dispersion_coefficients
Deprecated irf model item width_dispersion  for width_dispersion_coefficients
  • Loading branch information
jsnel authored Aug 26, 2021
1 parent a6a5a51 commit b281799
Show file tree
Hide file tree
Showing 8 changed files with 223 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI_CD_actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ jobs:
run: pip freeze
- name: Run tests
run: |
pytest --cov=./ --cov-report term --cov-report xml --cov-config pyproject.toml -k 'not IrfDispersion' glotaran
pytest --cov=./ --cov-report term --cov-report xml --cov-config pyproject.toml glotaran
- name: Codecov Upload
uses: codecov/codecov-action@v2
Expand Down
4 changes: 2 additions & 2 deletions glotaran/builtin/io/yml/test/test_model_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ def test_irf(model):
assert irf.width == want
want = [3] if i == 1 else [5, 6]
if i == 2:
assert irf.center_dispersion == want
assert irf.center_dispersion_coefficients == want
want = [7, 8]
assert irf.width_dispersion == want
assert irf.width_dispersion_coefficients == want
want = [9]
assert irf.scale == want
assert irf.normalize == (i == 1)
Expand Down
35 changes: 17 additions & 18 deletions glotaran/builtin/io/yml/test/test_model_spec.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
default-megacomplex: decay


dataset:
dataset1:
megacomplex: [cmplx1]
Expand All @@ -23,36 +22,36 @@ irf:
irf2:
type: spectral-gaussian
center: [1, 2]
width: [3,4]
width: [3, 4]
scale: [9]
normalize: false
backsweep: true
backsweep_period: 55
dispersion_center: 55
center_dispersion: [5,6]
width_dispersion: [7,8]
center_dispersion_coefficients: [5, 6]
width_dispersion_coefficients: [7, 8]
model_dispersion_with_wavenumber: true

initial_concentration:
inputD1:
compartments: [s1,s2,s3]
parameters: [1,2,3]
compartments: [s1, s2, s3]
parameters: [1, 2, 3]
inputD2:
compartments: [s1,s2,s3]
parameters: [1,2,3]
compartments: [s1, s2, s3]
parameters: [1, 2, 3]

# Convention matrix notation column = source, row = target compartment
# (2,1) means from 1 to 2
k_matrix:
km1:
matrix:
(s1, s1): '1'
(s2, s1): '2'
(s1, s2): '3'
(s3, s1): '4'
(s1, s3): '5'
(s4, s1): '6'
(s1, s4): '7'
(s1, s1): "1"
(s2, s1): "2"
(s1, s2): "3"
(s3, s1): "4"
(s1, s3): "5"
(s4, s1): "6"
(s1, s4): "7"

shape:
shape1:
Expand All @@ -63,9 +62,9 @@ shape:

megacomplex:
cmplx1:
k_matrix: [km1] # A megacomplex has one or more k-matrices
k_matrix: [km1] # A megacomplex has one or more k-matrices
cmplx2:
k_matrix: [km2]
k_matrix: [km2]
cmplx3:
type: "spectral"
shape:
Expand Down Expand Up @@ -97,7 +96,7 @@ relations:
- source: s1
target: s2
parameter: 8
interval: [[1,100], [2,200]]
interval: [[1, 100], [2, 200]]

weights:
- datasets: [d1, d2]
Expand Down
28 changes: 14 additions & 14 deletions glotaran/builtin/megacomplexes/decay/irf.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ class IrfMultiGaussian:
one or more center of the irf as parameter indices
width:
one or more widths of the gaussian as parameter index
center_dispersion:
center_dispersion_coefficients:
polynomial coefficients for the dispersion of the
center as list of parameter indices. None for no dispersion.
width_dispersion:
width_dispersion_coefficients:
polynomial coefficients for the dispersion of the
width as parameter indices. None for no dispersion.
Expand Down Expand Up @@ -124,8 +124,8 @@ class IrfGaussian(IrfMultiGaussian):
@model_item(
properties={
"dispersion_center": {"type": Parameter, "allow_none": True},
"center_dispersion": {"type": List[Parameter], "default": []},
"width_dispersion": {"type": List[Parameter], "default": []},
"center_dispersion_coefficients": {"type": List[Parameter], "default": []},
"width_dispersion_coefficients": {"type": List[Parameter], "default": []},
"model_dispersion_with_wavenumber": {"type": bool, "default": False},
},
has_type=True,
Expand All @@ -149,12 +149,12 @@ class IrfSpectralMultiGaussian(IrfMultiGaussian):
one or more center of the irf as parameter indices
width:
one or more widths of the gaussian as parameter index
center_dispersion:
polynomial coefficients for the dispersion of the
center as list of parameter indices. None for no dispersion.
width_dispersion:
polynomial coefficients for the dispersion of the
width as parameter indices. None for no dispersion.
center_dispersion_coefficients:
list of parameters with polynomial coefficients describing
the dispersion of the irf center location. None for no dispersion.
width_dispersion_coefficients:
list of parameters with polynomial coefficients describing
the dispersion of the width of the irf. None for no dispersion.
"""

Expand All @@ -173,16 +173,16 @@ def parameter(self, global_index: int, global_axis: np.ndarray):
else (index - self.dispersion_center) / 100
)

if len(self.center_dispersion) != 0:
if len(self.center_dispersion_coefficients) != 0:
if self.dispersion_center is None:
raise ModelError(f"No dispersion center defined for irf '{self.label}'")
for i, disp in enumerate(self.center_dispersion):
for i, disp in enumerate(self.center_dispersion_coefficients):
centers += disp * np.power(dist, i + 1)

if len(self.width_dispersion) != 0:
if len(self.width_dispersion_coefficients) != 0:
if self.dispersion_center is None:
raise ModelError(f"No dispersion center defined for irf '{self.label}'")
for i, disp in enumerate(self.width_dispersion):
for i, disp in enumerate(self.width_dispersion_coefficients):
widths = widths + disp * np.power(dist, i + 1)

return centers, widths, scale, shift, backsweep, backsweep_period
Expand Down
Loading

0 comments on commit b281799

Please sign in to comment.