@@ -14,7 +14,7 @@ Most of the functionality of a ``junifer`` Marker has been taken care by the
1414:class: `.BaseMarker ` class. Thus, only a few methods and class attributes are
1515required:
1616
17- #. `` __init__ ``: The initialisation method, where the Marker is configured .
17+ #. (optional) `` validate_marker_params ``: The method to perform logical validation of parameters (if required) .
1818#. ``compute ``: The method that given the data, computes the Marker.
1919
2020As an example, we will develop a ``ParcelMean `` Marker, a Marker that first
@@ -29,23 +29,23 @@ Step 1: Configure input and output
2929This step is quite simple: we need to define the input and output of the Marker.
3030Based on the current :ref: `data types <data_types >`, we can have ``BOLD ``,
3131``VBM_WM `` and ``VBM_GM `` as valid inputs. The output of the Marker depends on
32- the input. For ``BOLD ``, it will be ``timeseries ``, while for the rest of the
33- inputs, it will be ``vector ``. Thus, we have a class attribute like so:
32+ the input. For ``BOLD ``, it will be ``Timeseries ``, while for the rest of the
33+ inputs, it will be ``Vector ``. Thus, we have a class attribute like so:
3434
3535.. code-block :: python
3636
3737 # NOTE : data type -> feature -> storage type
3838 # You can have multiple features for one data type,
3939 # each feature having same or different storage type
4040 _MARKER_INOUT_MAPPINGS = {
41- " BOLD" : {
42- " parcel_mean" : " timeseries " ,
41+ DataType. BOLD : {
42+ " parcel_mean" : StorageType.Timeseries ,
4343 },
44- " VBM_WM" : {
45- " parcel_mean" : " vector " ,
44+ DataType. VBM_WM : {
45+ " parcel_mean" : StorageType.Vector ,
4646 },
47- " VBM_GM" : {
48- " parcel_mean" : " vector " ,
47+ DataType. VBM_GM : {
48+ " parcel_mean" : StorageType.Vector ,
4949 },
5050 }
5151
@@ -57,13 +57,11 @@ Step 2: Initialise the Marker
5757In this step we need to define the parameters of the Marker the user can provide
5858to configure how the Marker will behave.
5959
60- The parameters of the Marker are defined in the `` __init__ `` method . The
61- :class: `.BaseMarker ` class requires two optional parameters:
60+ The parameters of the Marker are defined as class attributes . The
61+ :class: `.BaseMarker ` class defines two optional parameters:
6262
63- 1. ``name ``: the name of the Marker. This is used to identify the Marker in the
64- configuration file.
65- 2. ``on ``: a list or string with the data types that the Marker will be applied
66- to.
63+ 1. ``name ``: the name of the Marker. This is used to identify the Marker in the configuration file.
64+ 2. ``on ``: a list of :enum: `.DataType ` with the data types that the Marker will be applied to.
6765
6866.. attention ::
6967
@@ -72,18 +70,11 @@ The parameters of the Marker are defined in the ``__init__`` method. The
7270 JSON format, and JSON only supports these types.
7371
7472In this example, only parameter required for the computation is the name of the
75- parcellation to use. Thus, we can define the `` __init__ `` method as follows:
73+ parcellation to use. Thus, we can define as follows:
7674
7775.. code-block :: python
7876
79- def __init__ (
80- self ,
81- parcellation : str ,
82- on : str | list[str ] | None = None ,
83- name : str | None = None ,
84- ) -> None :
85- self .parcellation = parcellation
86- super ().__init__ (on = on, name = name)
77+ parcellation: str
8778
8879 .. caution ::
8980
@@ -121,7 +112,7 @@ and the values would be a dictionary of storage type specific key-value pairs.
121112
122113 To simplify the ``store `` method, define keys of the dictionary based on the
123114 corresponding store functions in the :ref: `storage types <storage_types >`.
124- For example, if the output is a ``vector ``, the keys of the dictionary should
115+ For example, if the output is a ``Vector ``, the keys of the dictionary should
125116 be ``data `` and ``col_names ``.
126117
127118.. code-block :: python
@@ -142,7 +133,7 @@ and the values would be a dictionary of storage type specific key-value pairs.
142133
143134 # Get the parcellation tailored for the target
144135 t_parcellation, t_labels, _ = get_parcellation(
145- name = self .parcellation_name ,
136+ name = self .parcellation ,
146137 target_data = input ,
147138 extra_input = extra_input,
148139 )
@@ -195,7 +186,9 @@ Finally, we need to register the Marker using the ``@register_marker`` decorator
195186
196187 from junifer.api.decorators import register_marker
197188 from junifer.data import get_parcellation
189+ from junifer.datagrabber import DataType
198190 from junifer.markers import BaseMarker
191+ from junifer.storage import StorageType
199192 from junifer.typing import Dependencies, MarkerInOutMappings
200193 from nilearn.maskers import NiftiLabelsMasker
201194
@@ -206,25 +199,18 @@ Finally, we need to register the Marker using the ``@register_marker`` decorator
206199 _DEPENDENCIES : ClassVar[Dependencies] = {" nilearn" , " numpy" }
207200
208201 _MARKER_INOUT_MAPPINGS : ClassVar[MarkerInOutMappings] = {
209- " BOLD" : {
210- " parcel_mean" : " timeseries " ,
202+ DataType. BOLD : {
203+ " parcel_mean" : StorageType.Timeseries ,
211204 },
212- " VBM_WM" : {
213- " parcel_mean" : " vector " ,
205+ DataType. VBM_WM : {
206+ " parcel_mean" : StorageType.Vector ,
214207 },
215- " VBM_GM" : {
216- " parcel_mean" : " vector " ,
208+ DataType. VBM_GM : {
209+ " parcel_mean" : StorageType.Vector ,
217210 },
218211 }
219212
220- def __init__ (
221- self ,
222- parcellation : str ,
223- on : str | list[str ] | None = None ,
224- name : str | None = None ,
225- ) -> None :
226- self .parcellation = parcellation
227- super ().__init__ (on = on, name = name)
213+ parcellation: str
228214
229215 def compute (
230216 self ,
@@ -236,7 +222,7 @@ Finally, we need to register the Marker using the ``@register_marker`` decorator
236222
237223 # Get the parcellation tailored for the target
238224 t_parcellation, t_labels, _ = get_parcellation(
239- name = self .parcellation_name ,
225+ name = self .parcellation ,
240226 target_data = input ,
241227 extra_input = extra_input,
242228 )
@@ -280,9 +266,13 @@ Template for a custom Marker
280266 # TODO : add the input-output mappings
281267 _MARKER_INOUT_MAPPINGS = {}
282268
283- def __init__ (self , on = None , name = None ):
284- # TODO : add marker-specific parameters
285- super ().__init__ (on = on, name = name)
269+ # TODO : define marker-specific parameters
270+
271+ # optional
272+ def validate_marker_params (self ):
273+ # TODO : add validation logic for marker parameters
274+ pass
286275
287276 def compute (self , input , extra_input ):
288277 # TODO : compute the marker and create the output dictionary
278+ return {}
0 commit comments