From 837b50b40f5137bed2fc9b8d353f7b623574aabe Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Tue, 16 May 2023 15:45:12 +0200 Subject: [PATCH 1/7] docs: use DataReader consistently in data.rst --- docs/understanding/data.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/understanding/data.rst b/docs/understanding/data.rst index 2961ab107e..e5f939e0a7 100644 --- a/docs/understanding/data.rst +++ b/docs/understanding/data.rst @@ -39,7 +39,7 @@ step only contains information about the datagrabber used. The :ref:`Data Reader ` 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 From 853944024993e60a54b82af8d96426a3c3383b96 Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Tue, 16 May 2023 15:45:34 +0200 Subject: [PATCH 2/7] docs: use DataReader consistently in datareader.rst --- docs/understanding/datareader.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/understanding/datareader.rst b/docs/understanding/datareader.rst index 87b8c31a53..52679ebd12 100644 --- a/docs/understanding/datareader.rst +++ b/docs/understanding/datareader.rst @@ -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. From 340276fe7c78dd1367327d678b5c3ec0a3c43bde Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Tue, 16 May 2023 15:45:52 +0200 Subject: [PATCH 3/7] docs: use DataReader consistently in codeless.rst --- docs/using/codeless.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/using/codeless.rst b/docs/using/codeless.rst index f053209bab..0b3601793b 100644 --- a/docs/using/codeless.rst +++ b/docs/using/codeless.rst @@ -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 From 14125ff853734a1af14ab93b1c9d9e8466b90f55 Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Tue, 16 May 2023 15:46:21 +0200 Subject: [PATCH 4/7] chore: use DataReader consistently and update docstring for register_datareader() --- junifer/api/decorators.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/junifer/api/decorators.py b/junifer/api/decorators.py index 87ea51f89e..28969d93e9 100644 --- a/junifer/api/decorators.py +++ b/junifer/api/decorators.py @@ -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", From 9e30c5c3a0b4ffd6ec95c29daea6e3fdccd6559c Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Tue, 16 May 2023 15:47:05 +0200 Subject: [PATCH 5/7] chore: use DataReader consistently in MarkerCollection docstring --- junifer/markers/collection.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/junifer/markers/collection.py b/junifer/markers/collection.py index d45c132595..0f97311fba 100644 --- a/junifer/markers/collection.py +++ b/junifer/markers/collection.py @@ -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 From b9c78cc6b005dc4b75efa3060b72d3c7a9889e5a Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Tue, 16 May 2023 15:50:43 +0200 Subject: [PATCH 6/7] chore: add changelog 227.enh --- docs/changes/newsfragments/227.enh | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/changes/newsfragments/227.enh diff --git a/docs/changes/newsfragments/227.enh b/docs/changes/newsfragments/227.enh new file mode 100644 index 0000000000..51e1b7bc10 --- /dev/null +++ b/docs/changes/newsfragments/227.enh @@ -0,0 +1 @@ +Adopt ``DataReader`` consistently throughout codebase to match with the documentation by `Synchon Mandal`_ \ No newline at end of file From ef739b5778d09012571f6007cf52c9b308d81387 Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Tue, 16 May 2023 16:09:21 +0200 Subject: [PATCH 7/7] chore: use DataReader consistently in default and tests and general improvements --- junifer/datareader/default.py | 5 +++-- .../datareader/tests/test_default_reader.py | 22 +++++++++---------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/junifer/datareader/default.py b/junifer/datareader/default.py index 52352dec21..2956e3aecf 100644 --- a/junifer/datareader/default.py +++ b/junifer/datareader/default.py @@ -1,4 +1,4 @@ -"""Provide class for default data reader.""" +"""Provide concrete implementation for default DataReader.""" # Authors: Federico Raimondo # Synchon Mandal @@ -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. @@ -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 diff --git a/junifer/datareader/tests/test_default_reader.py b/junifer/datareader/tests/test_default_reader.py index 46c31f8721..b815220140 100644 --- a/junifer/datareader/tests/test_default_reader.py +++ b/junifer/datareader/tests/test_default_reader.py @@ -1,4 +1,4 @@ -"""Provide tests for default data reader.""" +"""Provide tests for DefaultDataReader.""" # Authors: Federico Raimondo # Synchon Mandal @@ -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 ---------- @@ -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) @@ -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 ---------- @@ -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) @@ -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 ----------