diff --git a/mapca/__init__.py b/mapca/__init__.py index ca9ab42..9438a3a 100644 --- a/mapca/__init__.py +++ b/mapca/__init__.py @@ -3,9 +3,9 @@ GIFT. """ -from .due import due, Doi from ._version import get_versions -from .mapca import ma_pca +from .due import Doi, due +from .mapca import MovingAveragePCA, ma_pca __version__ = get_versions()["version"] @@ -16,6 +16,7 @@ __all__ = [ "ma_pca", + "MovingAveragePCA", "__version__", ] diff --git a/mapca/mapca.py b/mapca/mapca.py index 2115cab..6b17ed2 100644 --- a/mapca/mapca.py +++ b/mapca/mapca.py @@ -254,19 +254,35 @@ def _fit(self, img, mask): itc = np.row_stack([self.aic_, self.kic_, self.mdl_]) + dlap = np.diff(itc, axis=1) + + # AIC + a_aic = np.where(dlap[0, :] > 0)[0] + 1 + if a_aic.size == 0: + self.n_aic_ = itc[0, :].shape[0] + else: + self.n_aic_ = a_aic[0] + + # KIC + a_kic = np.where(dlap[1, :] > 0)[0] + 1 + if a_kic.size == 0: + self.n_kic_ = itc[1, :].shape[0] + else: + self.n_kic_ = a_kic[0] + + # MDL + a_mdl = np.where(dlap[2, :] > 0)[0] + 1 + if a_mdl.size == 0: + self.n_mdl_ = itc[2, :].shape[0] + else: + self.n_mdl_ = a_mdl[0] + if self.criterion == "aic": - criteria_idx = 0 + n_components = self.n_aic_ elif self.criterion == "kic": - criteria_idx = 1 + n_components = self.n_kic_ elif self.criterion == "mdl": - criteria_idx = 2 - - dlap = np.diff(itc[criteria_idx, :]) - a = np.where(dlap > 0)[0] + 1 # Plus 1 to - if a.size == 0: - n_components = itc[criteria_idx, :].shape[0] - else: - n_components = a[0] + n_components = self.n_mdl_ LGR.info("Estimated number of components is %d" % n_components)