Skip to content

Commit

Permalink
BF: Set the superclass fit_method param value to the one provided
Browse files Browse the repository at this point in the history
Set the superclass initialization method `fit_method` parameter value to
the one provided to the child's initialization method.

Add a test to check that the fit method matches the model instance fit
method.
  • Loading branch information
jhlegarreta committed Aug 28, 2024
1 parent 2a87689 commit 8ffea7f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion dipy/reconst/dki_micro.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,9 @@ def __init__(self, gtab, fit_method="WLS", *args, **kwargs):
----------
.. footbibliography::
"""
DiffusionKurtosisModel.__init__(self, gtab, fit_method="WLS", *args, **kwargs)
DiffusionKurtosisModel.__init__(
self, gtab, fit_method=fit_method, *args, **kwargs
)

def fit(self, data, mask=None, sphere="repulsion100", gtol=1e-2, awf_only=False):
"""Fit method of the Diffusion Kurtosis Microstructural Model
Expand Down
18 changes: 18 additions & 0 deletions dipy/reconst/tests/test_dki_micro.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@
assert_array_almost_equal,
assert_raises,
)
import pytest

from dipy.core.gradients import gradient_table
from dipy.data import default_sphere, get_fnames, get_sphere
from dipy.io.gradients import read_bvals_bvecs
from dipy.reconst.dki import common_fit_methods
import dipy.reconst.dki_micro as dki_micro
from dipy.reconst.dti import eig_from_lo_tri
from dipy.sims.voxel import _check_directions, multi_tensor, multi_tensor_dki
from dipy.utils.optpkg import optional_package

cvxpy, have_cvxpy, _ = optional_package("cvxpy", min_version="1.4.1")
needs_cvxpy = pytest.mark.skipif(not have_cvxpy, reason="Requires CVXPY")

gtab_2s, DWIsim, DWIsim_all_taylor = None, None, None
FIE, RDI, ADI, ADE, Tor, RDE = None, None, None, None, None, None
Expand Down Expand Up @@ -91,6 +97,18 @@ def teardown_module():
FIE, RDI, ADI, ADE, Tor, RDE = None, None, None, None, None, None


@needs_cvxpy
def test_fit_selection():
for model in [
dki_micro.KurtosisMicrostructureModel,
dki_micro.DiffusionKurtosisModel,
]:
for name, method in common_fit_methods.items():
model_instance = model(gtab_2s, fit_method=name)

assert model_instance.fit_method == method


def test_single_fiber_model():
# single fiber simulate (which is the assumption of our model)
fie = 0.49
Expand Down

0 comments on commit 8ffea7f

Please sign in to comment.