Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: consistent use of DataReader #227

Merged
merged 7 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changes/newsfragments/227.enh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Adopt ``DataReader`` consistently throughout codebase to match with the documentation by `Synchon Mandal`_
2 changes: 1 addition & 1 deletion docs/understanding/data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ step only contains information about the datagrabber used.

The :ref:`Data Reader <datareader>` step adds the ``data`` second-level key
which is the actual data loaded into memory. The ``meta`` key in this step
adds information about the datareader used to read the data.
adds information about the DataReader used to read the data.

.. code-block:: python

Expand Down
2 changes: 1 addition & 1 deletion docs/understanding/datareader.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ files in junifer. It reads the value of the key ``path`` for each
them into memory. After reading the data into memory, it adds the key ``data``
to the same level as ``path`` and the value is the actual data in the memory.

Datareaders are meant to be used inside the datagrabber context but you can
DataReaders are meant to be used inside the datagrabber context but you can
operate on them outside the context as long as the actual data is in the memory
and the Python runtime has not garbage-collected it.

Expand Down
6 changes: 3 additions & 3 deletions docs/using/codeless.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ Data Reader
^^^^^^^^^^^

As mentioned before, this section is entirely optional, as junifer only provides
one data reader (:class:`.DefaultDataReader`), which is the default in case the
one DataReader (:class:`.DefaultDataReader`), which is the default in case the
section is not specified.

In any case, the syntax of the section is the same as for the ``datagrabber``
section, using the ``kind`` key to specify the datareader to use, and additional
keys to pass parameters to the datareader:
section, using the ``kind`` key to specify the DataReader to use, and additional
keys to pass parameters to the DataReader constructor:

.. code-block:: yaml

Expand Down
10 changes: 7 additions & 3 deletions junifer/api/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,24 @@ def register_datagrabber(klass: Type) -> Type:


def register_datareader(klass: Type) -> Type:
"""Datareader registration decorator.
"""Register DataReader.

Registers the datareader so it can be used by name.
Registers the DataReader so it can be used by name.

Parameters
----------
klass: class
The class of the datareader to register.
The class of the DataReader to register.

Returns
-------
klass: class
The unmodified input class.

Notes
-----
It should only be used as a decorator.

"""
register(
step="datareader",
Expand Down
5 changes: 3 additions & 2 deletions junifer/datareader/default.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Provide class for default data reader."""
"""Provide concrete implementation for default DataReader."""

# Authors: Federico Raimondo <f.raimondo@fz-juelich.de>
# Synchon Mandal <s.mandal@fz-juelich.de>
Expand Down Expand Up @@ -32,7 +32,7 @@

@register_datareader
class DefaultDataReader(PipelineStepMixin, UpdateMetaMixin):
"""Mixin class for default data reader."""
"""Concrete implementation for common data reading."""

def validate_input(self, input: List[str]) -> List[str]:
"""Validate input.
Expand All @@ -48,6 +48,7 @@ def validate_input(self, input: List[str]) -> List[str]:
list of str
The actual elements of the input that will be processed by this
pipeline step.

"""
# Nothing to validate, any input is fine
return input
Expand Down
22 changes: 11 additions & 11 deletions junifer/datareader/tests/test_default_reader.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Provide tests for default data reader."""
"""Provide tests for DefaultDataReader."""

# Authors: Federico Raimondo <f.raimondo@fz-juelich.de>
# Synchon Mandal <s.mandal@fz-juelich.de>
Expand All @@ -19,8 +19,8 @@
@pytest.mark.parametrize(
"type_", [["T1w", "BOLD", "T2", "dwi"], [], ["whatever"]]
)
def test_validation(type_) -> None:
"""Test validating input/output.
def test_DefaultDataReader_validation(type_) -> None:
"""Test DefaultDataReader validating input/output.

Parameters
----------
Expand All @@ -34,8 +34,8 @@ def test_validation(type_) -> None:
assert reader.validate(type_) == type_


def test_meta() -> None:
"""Test reader metadata."""
def test_DefaultDataReader_meta() -> None:
"""Test DefaultDataReader metadata."""
reader = DefaultDataReader()

nib_data_path = Path(nib_testing.data_path)
Expand All @@ -52,8 +52,8 @@ def test_meta() -> None:
@pytest.mark.parametrize(
"fname", ["example4d.nii.gz", "reoriented_anat_moved.nii"]
)
def test_read_nifti(fname: str) -> None:
"""Test reading NIFTI files.
def test_DefaultDataReader_nifti(fname: str) -> None:
"""Test DefaultDataReader reading NIfTI files.

Parameters
----------
Expand Down Expand Up @@ -85,8 +85,8 @@ def test_read_nifti(fname: str) -> None:
assert output["BOLD"]["path"] == output2["BOLD"]["path"]


def test_read_unknown() -> None:
"""Test (not) reading unknown files."""
def test_DefaultDataReader_unknown() -> None:
"""Test DefaultDataReader (not) reading unknown files."""
reader = DefaultDataReader()
nib_data_path = Path(nib_testing.data_path)

Expand Down Expand Up @@ -115,8 +115,8 @@ def test_read_unknown() -> None:
reader.fit_transform(input)


def test_read_csv(tmp_path: Path) -> None:
"""Test reading CSV files.
def test_DefaultDataReader_csv(tmp_path: Path) -> None:
"""Test DefaultDataReader reading CSV files.

Parameters
----------
Expand Down
4 changes: 2 additions & 2 deletions junifer/markers/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class MarkerCollection:
----------
markers : list of marker-like
The markers to compute.
datareader : datareader-like, optional
The datareader to use (default None).
datareader : DataReader-like object, optional
The DataReader to use (default None).
preprocessing : preprocessing-like, optional
The preprocessing steps to apply.
storage : storage-like, optional
Expand Down