[ENH]: Rename 'table' to 'vector' in storage API #181
30 changed files with 381 additions and 326 deletions
|
|
@ -49,4 +49,8 @@ API changes
|
||||||
~~~~~~~~~~~
|
~~~~~~~~~~~
|
||||||
|
|
||||||
- Add ``confounds_format`` parameter to :class:`junifer.datagrabber.PatternDataGrabber` constructor for
|
- Add ``confounds_format`` parameter to :class:`junifer.datagrabber.PatternDataGrabber` constructor for
|
||||||
improved handling of confounds specified via ``BOLD_confounds`` data type (:gh:`158` by `Synchon Mandal`_).
|
improved handling of confounds specified via ``BOLD_confounds`` data type (:gh:`158` by `Synchon Mandal`_).
|
||||||
|
|
||||||
|
- Rename ``store_table()`` to ``store_vector()`` for storage-like objects and adapt marker-like objects to
|
||||||
|
use ``"vector"`` in place of ``"table"`` for storage. Also, improve the logic of storing vectors
|
||||||
|
(:gh:`181` by `Synchon Mandal`_).
|
||||||
|
|
@ -15,10 +15,10 @@ that object else they are kept in memory.
|
||||||
Storage is meant to be used inside the datagrabber context but you can operate on them outside the context as long
|
Storage is meant to be used inside the datagrabber context but you can operate on them outside the context as long
|
||||||
as the processed data is in the memory and the Python runtime has not garbage-collected it.
|
as the processed data is in the memory and the Python runtime has not garbage-collected it.
|
||||||
|
|
||||||
The :ref:`Markers <marker>` are responsible for defining what *storage kind* (``matrix``, ``table``, ``timeseries``)
|
The :ref:`Markers <marker>` are responsible for defining what *storage kind* (``matrix``, ``vector``, ``timeseries``)
|
||||||
they support for which :ref:`data type <data_types>` by overriding its ``store`` method. The storage object in turn
|
they support for which :ref:`data type <data_types>` by overriding its ``store`` method. The storage object in turn
|
||||||
declares and provides implementation for specific *storage kind*. For example, :class:`junifer.storage.SQLiteFeatureStorage`
|
declares and provides implementation for specific *storage kind*. For example, :class:`junifer.storage.SQLiteFeatureStorage`
|
||||||
supports saving ``matrix``, ``table`` and ``timeseries`` via ``store_matrix``, ``store_table`` and ``store_timeseries``
|
supports saving ``matrix``, ``vector`` and ``timeseries`` via ``store_matrix``, ``store_vector`` and ``store_timeseries``
|
||||||
methods respectively.
|
methods respectively.
|
||||||
|
|
||||||
For storage interfaces not supported by junifer yet, you can either make your own ``Storage`` by providing a concrete
|
For storage interfaces not supported by junifer yet, you can either make your own ``Storage`` by providing a concrete
|
||||||
|
|
@ -42,15 +42,15 @@ Currently supported storage types
|
||||||
- A 2D matrix with row and column names
|
- A 2D matrix with row and column names
|
||||||
- ``col_names``, ``row_names``, ``matrix_kind``, ``diagonal``
|
- ``col_names``, ``row_names``, ``matrix_kind``, ``diagonal``
|
||||||
- :meth:`junifer.storage.BaseFeatureStorage.store_matrix`
|
- :meth:`junifer.storage.BaseFeatureStorage.store_matrix`
|
||||||
* - ``table``
|
* - ``vector``
|
||||||
- A vector of values with column names
|
- A vector of values with column names
|
||||||
- ``columns``, ``row_names``
|
- ``columns``, ``row_names``
|
||||||
- :meth:`junifer.storage.BaseFeatureStorage.store_table`
|
- :meth:`junifer.storage.BaseFeatureStorage.store_vector`
|
||||||
* - ``timeseries``
|
* - ``timeseries``
|
||||||
- A 2D matrix of values with column names
|
- A 2D matrix of values with column names
|
||||||
- ``columns``, ``row_names``
|
- ``columns``, ``row_names``
|
||||||
- :meth:`junifer.storage.BaseFeatureStorage.store_timeseries`
|
- :meth:`junifer.storage.BaseFeatureStorage.store_timeseries`
|
||||||
|
|
||||||
.. _storage_interfaces:
|
.. _storage_interfaces:
|
||||||
|
|
||||||
Currently supported storage interfaces
|
Currently supported storage interfaces
|
||||||
|
|
|
||||||
|
|
@ -7,24 +7,23 @@ from pathlib import Path
|
||||||
from typing import (
|
from typing import (
|
||||||
TYPE_CHECKING,
|
TYPE_CHECKING,
|
||||||
Any,
|
Any,
|
||||||
|
Callable,
|
||||||
Dict,
|
Dict,
|
||||||
List,
|
List,
|
||||||
Optional,
|
Optional,
|
||||||
Tuple,
|
Tuple,
|
||||||
Union,
|
Union,
|
||||||
Callable,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
import numpy as np
|
|
||||||
|
|
||||||
import nibabel as nib
|
import nibabel as nib
|
||||||
from nilearn.masking import (
|
import numpy as np
|
||||||
compute_brain_mask,
|
|
||||||
compute_background_mask,
|
|
||||||
compute_epi_mask,
|
|
||||||
)
|
|
||||||
from nilearn.datasets import fetch_icbm152_brain_gm_mask
|
from nilearn.datasets import fetch_icbm152_brain_gm_mask
|
||||||
from nilearn.image import resample_to_img
|
from nilearn.image import resample_to_img
|
||||||
|
from nilearn.masking import (
|
||||||
|
compute_background_mask,
|
||||||
|
compute_brain_mask,
|
||||||
|
compute_epi_mask,
|
||||||
|
)
|
||||||
|
|
||||||
from ..utils.logging import logger, raise_error
|
from ..utils.logging import logger, raise_error
|
||||||
from .utils import closest_resolution
|
from .utils import closest_resolution
|
||||||
|
|
|
||||||
|
|
@ -5,33 +5,27 @@
|
||||||
# Synchon Mandal <s.mandal@fz-juelich.de>
|
# Synchon Mandal <s.mandal@fz-juelich.de>
|
||||||
# License: AGPL
|
# License: AGPL
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
from typing import Callable, Dict, Union
|
from typing import Callable, Dict, Union
|
||||||
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from numpy.testing import (
|
from nilearn.datasets import fetch_icbm152_brain_gm_mask
|
||||||
assert_array_almost_equal,
|
|
||||||
assert_array_equal,
|
|
||||||
)
|
|
||||||
|
|
||||||
from nilearn.image import resample_to_img
|
from nilearn.image import resample_to_img
|
||||||
from nilearn.masking import (
|
from nilearn.masking import (
|
||||||
compute_brain_mask,
|
|
||||||
compute_background_mask,
|
compute_background_mask,
|
||||||
|
compute_brain_mask,
|
||||||
compute_epi_mask,
|
compute_epi_mask,
|
||||||
)
|
)
|
||||||
from nilearn.datasets import fetch_icbm152_brain_gm_mask
|
from numpy.testing import assert_array_almost_equal, assert_array_equal
|
||||||
|
|
||||||
from junifer.data.masks import (
|
from junifer.data.masks import (
|
||||||
|
_available_masks,
|
||||||
_load_vickery_patil_mask,
|
_load_vickery_patil_mask,
|
||||||
|
get_mask,
|
||||||
list_masks,
|
list_masks,
|
||||||
load_mask,
|
load_mask,
|
||||||
register_mask,
|
register_mask,
|
||||||
get_mask,
|
|
||||||
_available_masks,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
from junifer.datareader import DefaultDataReader
|
from junifer.datareader import DefaultDataReader
|
||||||
from junifer.testing.datagrabbers import (
|
from junifer.testing.datagrabbers import (
|
||||||
OasisVBMTestingDatagrabber,
|
OasisVBMTestingDatagrabber,
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,11 @@
|
||||||
# Authors: Synchon Mandal <s.mandal@fz-juelich.de>
|
# Authors: Synchon Mandal <s.mandal@fz-juelich.de>
|
||||||
# License: AGPL
|
# License: AGPL
|
||||||
|
|
||||||
from typing import Optional, Iterable
|
from typing import Iterable, Optional
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from junifer.datagrabber.hcp import DataladHCP1200, HCP1200
|
from junifer.datagrabber.hcp import HCP1200, DataladHCP1200
|
||||||
from junifer.utils import configure_logging
|
from junifer.utils import configure_logging
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -332,9 +332,7 @@ def test_hcp1200_datagrabber_elements(
|
||||||
)
|
)
|
||||||
with dg:
|
with dg:
|
||||||
# Get all elements
|
# Get all elements
|
||||||
expected_subjects = [
|
expected_subjects = [f"sub-{x:02d}" for x in range(1, 10)]
|
||||||
f"sub-{x:02d}" for x in range(1, 10)
|
|
||||||
]
|
|
||||||
found_subjects = []
|
found_subjects = []
|
||||||
all_elements = dg.get_elements()
|
all_elements = dg.get_elements()
|
||||||
# Check only specified task and phase encoding are found
|
# Check only specified task and phase encoding are found
|
||||||
|
|
|
||||||
|
|
@ -110,8 +110,7 @@ class RSSETSMarker(BaseMarker):
|
||||||
keys:
|
keys:
|
||||||
|
|
||||||
* ``data`` : the actual computed values as a numpy.ndarray
|
* ``data`` : the actual computed values as a numpy.ndarray
|
||||||
* ``columns`` : the column labels for the computed values as a list
|
* ``col_names`` : the column labels for the computed values as list
|
||||||
* ``row_names`` (if more than one row is present in data): "scan"
|
|
||||||
|
|
||||||
References
|
References
|
||||||
----------
|
----------
|
||||||
|
|
@ -135,5 +134,5 @@ class RSSETSMarker(BaseMarker):
|
||||||
# Compute the RSS
|
# Compute the RSS
|
||||||
out["data"] = np.sum(edge_ts**2, 1) ** 0.5
|
out["data"] = np.sum(edge_ts**2, 1) ** 0.5
|
||||||
# Set correct column label
|
# Set correct column label
|
||||||
out["columns"] = ["root_sum_of_squares_ets"]
|
out["col_names"] = ["root_sum_of_squares_ets"]
|
||||||
return out
|
return out
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ class AmplitudeLowFrequencyFluctuationBase(BaseMarker):
|
||||||
The storage type output by the marker.
|
The storage type output by the marker.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return "table"
|
return "vector"
|
||||||
|
|
||||||
def compute(
|
def compute(
|
||||||
self,
|
self,
|
||||||
|
|
@ -132,8 +132,7 @@ class AmplitudeLowFrequencyFluctuationBase(BaseMarker):
|
||||||
with this as a parameter. The dictionary has the following keys:
|
with this as a parameter. The dictionary has the following keys:
|
||||||
|
|
||||||
* ``data`` : the actual computed values as a numpy.ndarray
|
* ``data`` : the actual computed values as a numpy.ndarray
|
||||||
* ``columns`` : the column labels for the computed values as a list
|
* ``col_names`` : the column labels for the computed values as list
|
||||||
* ``row_names`` (if more than one row is present in data): "scan"
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if self.use_afni is None:
|
if self.use_afni is None:
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@ class AmplitudeLowFrequencyFluctuationParcels(
|
||||||
keys:
|
keys:
|
||||||
|
|
||||||
* ``data`` : the actual computed values as a numpy.ndarray
|
* ``data`` : the actual computed values as a numpy.ndarray
|
||||||
* ``columns`` : the column labels for the computed values as a list
|
* ``col_names`` : the column labels for the computed values as list
|
||||||
|
|
||||||
"""
|
"""
|
||||||
pa = ParcelAggregation(
|
pa = ParcelAggregation(
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,7 @@ class AmplitudeLowFrequencyFluctuationSpheres(
|
||||||
keys:
|
keys:
|
||||||
|
|
||||||
* ``data`` : the actual computed values as a numpy.ndarray
|
* ``data`` : the actual computed values as a numpy.ndarray
|
||||||
* ``columns`` : the column labels for the computed values as a list
|
* ``col_names`` : the column labels for the computed values as list
|
||||||
|
|
||||||
"""
|
"""
|
||||||
pa = SphereAggregation(
|
pa = SphereAggregation(
|
||||||
|
|
|
||||||
|
|
@ -150,6 +150,6 @@ class CrossParcellationFC(BaseMarker):
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"data": result,
|
"data": result,
|
||||||
"col_names": parcellation_one_dict["columns"],
|
"col_names": parcellation_one_dict["col_names"],
|
||||||
"row_names": parcellation_two_dict["columns"],
|
"row_names": parcellation_two_dict["col_names"],
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,7 @@ class EdgeCentricFCParcels(FunctionalConnectivityBase):
|
||||||
|
|
||||||
bold_aggregated = parcel_aggregation.compute(input)
|
bold_aggregated = parcel_aggregation.compute(input)
|
||||||
ets, edge_names = _ets(
|
ets, edge_names = _ets(
|
||||||
bold_aggregated["data"], bold_aggregated["columns"]
|
bold_aggregated["data"], bold_aggregated["col_names"]
|
||||||
)
|
)
|
||||||
|
|
||||||
return dict(data=ets, columns=edge_names)
|
return {"data": ets, "col_names": edge_names}
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ class EdgeCentricFCSpheres(FunctionalConnectivityBase):
|
||||||
)
|
)
|
||||||
bold_aggregated = sphere_aggregation.compute(input)
|
bold_aggregated = sphere_aggregation.compute(input)
|
||||||
ets, edge_names = _ets(
|
ets, edge_names = _ets(
|
||||||
bold_aggregated["data"], bold_aggregated["columns"]
|
bold_aggregated["data"], bold_aggregated["col_names"]
|
||||||
)
|
)
|
||||||
|
|
||||||
return dict(data=ets, columns=edge_names)
|
return {"data": ets, "col_names": edge_names}
|
||||||
|
|
|
||||||
|
|
@ -143,7 +143,7 @@ class FunctionalConnectivityBase(BaseMarker):
|
||||||
out = {}
|
out = {}
|
||||||
out["data"] = connectivity.fit_transform([aggregation["data"]])[0]
|
out["data"] = connectivity.fit_transform([aggregation["data"]])[0]
|
||||||
# Create column names
|
# Create column names
|
||||||
out["row_names"] = aggregation["columns"]
|
out["row_names"] = aggregation["col_names"]
|
||||||
out["col_names"] = aggregation["columns"]
|
out["col_names"] = aggregation["col_names"]
|
||||||
out["matrix_kind"] = "tril"
|
out["matrix_kind"] = "tril"
|
||||||
return out
|
return out
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ class ParcelAggregation(BaseMarker):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if input_type in ["VBM_GM", "VBM_WM", "fALFF", "GCOR", "LCOR"]:
|
if input_type in ["VBM_GM", "VBM_WM", "fALFF", "GCOR", "LCOR"]:
|
||||||
return "table"
|
return "vector"
|
||||||
elif input_type == "BOLD":
|
elif input_type == "BOLD":
|
||||||
return "timeseries"
|
return "timeseries"
|
||||||
else:
|
else:
|
||||||
|
|
@ -123,7 +123,7 @@ class ParcelAggregation(BaseMarker):
|
||||||
with this as a parameter. The dictionary has the following keys:
|
with this as a parameter. The dictionary has the following keys:
|
||||||
|
|
||||||
* ``data`` : the actual computed values as a numpy.ndarray
|
* ``data`` : the actual computed values as a numpy.ndarray
|
||||||
* ``columns`` : the column labels for the computed values as a list
|
* ``col_names`` : the column labels for the computed values as list
|
||||||
|
|
||||||
"""
|
"""
|
||||||
t_input_img = input["data"]
|
t_input_img = input["data"]
|
||||||
|
|
@ -218,5 +218,5 @@ class ParcelAggregation(BaseMarker):
|
||||||
out_labels.append(labels[t_v - 1])
|
out_labels.append(labels[t_v - 1])
|
||||||
|
|
||||||
out_values = np.array(out_values).T
|
out_values = np.array(out_values).T
|
||||||
out = {"data": out_values, "columns": out_labels}
|
out = {"data": out_values, "col_names": out_labels}
|
||||||
return out
|
return out
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ class ReHoBase(BaseMarker):
|
||||||
The storage type output by the marker.
|
The storage type output by the marker.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return "table"
|
return "vector"
|
||||||
|
|
||||||
def compute_reho_map(
|
def compute_reho_map(
|
||||||
self,
|
self,
|
||||||
|
|
|
||||||
|
|
@ -122,8 +122,7 @@ class ReHoParcels(ReHoBase):
|
||||||
keys:
|
keys:
|
||||||
|
|
||||||
* ``data`` : the actual computed values as a 1D numpy.ndarray
|
* ``data`` : the actual computed values as a 1D numpy.ndarray
|
||||||
* ``columns`` : the column labels for the parcels as a list
|
* ``col_names`` : the column labels for the parcels as a list
|
||||||
* ``row_names`` : ``None``
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
logger.info("Calculating ReHo for parcels.")
|
logger.info("Calculating ReHo for parcels.")
|
||||||
|
|
|
||||||
|
|
@ -129,8 +129,7 @@ class ReHoSpheres(ReHoBase):
|
||||||
keys:
|
keys:
|
||||||
|
|
||||||
* ``data`` : the actual computed values as a 1D numpy.ndarray
|
* ``data`` : the actual computed values as a 1D numpy.ndarray
|
||||||
* ``columns`` : the column labels for the spheres as a list
|
* ``col_names`` : the column labels for the spheres as a list
|
||||||
* ``rows_col_name`` : ``None``
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
logger.info("Calculating ReHo for spheres.")
|
logger.info("Calculating ReHo for spheres.")
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ def test_reho_parcels_computation() -> None:
|
||||||
reho_parcels_output_bold = reho_parcels_output["BOLD"]
|
reho_parcels_output_bold = reho_parcels_output["BOLD"]
|
||||||
# Assert BOLD output keys
|
# Assert BOLD output keys
|
||||||
assert "data" in reho_parcels_output_bold
|
assert "data" in reho_parcels_output_bold
|
||||||
assert "columns" in reho_parcels_output_bold
|
assert "col_names" in reho_parcels_output_bold
|
||||||
|
|
||||||
reho_parcels_output_bold_data = reho_parcels_output_bold["data"]
|
reho_parcels_output_bold_data = reho_parcels_output_bold["data"]
|
||||||
# Assert BOLD output data dimension
|
# Assert BOLD output data dimension
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ def test_reho_spheres_computation() -> None:
|
||||||
reho_spheres_output_bold = reho_spheres_output["BOLD"]
|
reho_spheres_output_bold = reho_spheres_output["BOLD"]
|
||||||
# Assert BOLD output keys
|
# Assert BOLD output keys
|
||||||
assert "data" in reho_spheres_output_bold
|
assert "data" in reho_spheres_output_bold
|
||||||
assert "columns" in reho_spheres_output_bold
|
assert "col_names" in reho_spheres_output_bold
|
||||||
|
|
||||||
reho_spheres_output_bold_data = reho_spheres_output_bold["data"]
|
reho_spheres_output_bold_data = reho_spheres_output_bold["data"]
|
||||||
# Assert BOLD output data dimension
|
# Assert BOLD output data dimension
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
from typing import Any, Dict, List, Optional, Union
|
from typing import Any, Dict, List, Optional, Union
|
||||||
|
|
||||||
from ..api.decorators import register_marker
|
from ..api.decorators import register_marker
|
||||||
from ..data import load_coordinates, get_mask
|
from ..data import get_mask, load_coordinates
|
||||||
from ..external.nilearn import JuniferNiftiSpheresMasker
|
from ..external.nilearn import JuniferNiftiSpheresMasker
|
||||||
from ..stats import get_aggfunc_by_name
|
from ..stats import get_aggfunc_by_name
|
||||||
from ..utils import logger
|
from ..utils import logger
|
||||||
|
|
@ -94,7 +94,7 @@ class SphereAggregation(BaseMarker):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if input_type in ["VBM_GM", "VBM_WM", "fALFF", "GCOR", "LCOR"]:
|
if input_type in ["VBM_GM", "VBM_WM", "fALFF", "GCOR", "LCOR"]:
|
||||||
return "table"
|
return "vector"
|
||||||
elif input_type == "BOLD":
|
elif input_type == "BOLD":
|
||||||
return "timeseries"
|
return "timeseries"
|
||||||
else:
|
else:
|
||||||
|
|
@ -126,7 +126,7 @@ class SphereAggregation(BaseMarker):
|
||||||
with this as a parameter. The dictionary has the following keys:
|
with this as a parameter. The dictionary has the following keys:
|
||||||
|
|
||||||
* ``data`` : the actual computed values as a numpy.ndarray
|
* ``data`` : the actual computed values as a numpy.ndarray
|
||||||
* ``columns`` : the column labels for the computed values as a list
|
* ``col_names`` : the column labels for the computed values as list
|
||||||
|
|
||||||
"""
|
"""
|
||||||
t_input_img = input["data"]
|
t_input_img = input["data"]
|
||||||
|
|
@ -151,5 +151,5 @@ class SphereAggregation(BaseMarker):
|
||||||
# Fit and transform the marker on the data
|
# Fit and transform the marker on the data
|
||||||
out_values = masker.fit_transform(t_input_img)
|
out_values = masker.fit_transform(t_input_img)
|
||||||
# Format the output
|
# Format the output
|
||||||
out = {"data": out_values, "columns": out_labels}
|
out = {"data": out_values, "col_names": out_labels}
|
||||||
return out
|
return out
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue