From 6aa9ff5a47098affac0d22c234ca1411fcc4277b Mon Sep 17 00:00:00 2001 From: cprovins Date: Mon, 26 Apr 2021 13:23:31 +0200 Subject: [PATCH 1/3] enh : Add regression to the mean model Naive implementation of the AverageDWModel proposed in the nipreps-book. #41 --- eddymotion/model.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/eddymotion/model.py b/eddymotion/model.py index 83b0801c..ef930206 100644 --- a/eddymotion/model.py +++ b/eddymotion/model.py @@ -90,6 +90,22 @@ def predict(self, gradient, **kwargs): """Return the *b=0* map.""" return self._S0 +class AverageDWModel: + """A trivial model that returns an average map.""" + + __slots__ = ("_data",) + + def __init__(self, gtab, **kwargs): + """Implement object initialization.""" + return # do nothing at initialization time + + def fit(self, data, **kwargs): + """Calculate the average.""" + self._data = data.mean(-1) + + def predict(self, gradient, **kwargs): + """Return the average map.""" + return self._data class DTIModel: """A wrapper of :obj:`dipy.reconst.dti.TensorModel.""" From 6caff36207353fab970b63620b4e51bc848481d7 Mon Sep 17 00:00:00 2001 From: cprovins Date: Mon, 26 Apr 2021 15:25:49 +0200 Subject: [PATCH 2/3] STY : Correction of syntax Correct for the syntax issues suggested by the PEP8 bot #50 --- eddymotion/model.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/eddymotion/model.py b/eddymotion/model.py index ef930206..9ce83233 100644 --- a/eddymotion/model.py +++ b/eddymotion/model.py @@ -90,6 +90,7 @@ def predict(self, gradient, **kwargs): """Return the *b=0* map.""" return self._S0 + class AverageDWModel: """A trivial model that returns an average map.""" @@ -101,12 +102,13 @@ def __init__(self, gtab, **kwargs): def fit(self, data, **kwargs): """Calculate the average.""" - self._data = data.mean(-1) + self._data = data.mean(-1) def predict(self, gradient, **kwargs): """Return the average map.""" return self._data + class DTIModel: """A wrapper of :obj:`dipy.reconst.dti.TensorModel.""" From 9431be07d127d451f0b81aca81f6fd6e1360eb68 Mon Sep 17 00:00:00 2001 From: Oscar Esteban Date: Mon, 10 May 2021 14:43:37 +0200 Subject: [PATCH 3/3] Apply suggestions from code review Close #41 --- eddymotion/model.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/eddymotion/model.py b/eddymotion/model.py index 9ce83233..a22ce278 100644 --- a/eddymotion/model.py +++ b/eddymotion/model.py @@ -94,15 +94,15 @@ def predict(self, gradient, **kwargs): class AverageDWModel: """A trivial model that returns an average map.""" - __slots__ = ("_data",) + __slots__ = ("_data", "_gtab") def __init__(self, gtab, **kwargs): """Implement object initialization.""" - return # do nothing at initialization time + self._gtab = gtab def fit(self, data, **kwargs): """Calculate the average.""" - self._data = data.mean(-1) + self._data = data[..., self._gtab[..., 3] > 50].mean(-1) def predict(self, gradient, **kwargs): """Return the average map."""