Skip to content

Module dcm2bids.participant⚓︎

Participant class

View Source
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# -*- coding: utf-8 -*-

"""Participant class"""

from os.path import join as opj

from dcm2bids.utils.utils import DEFAULT

class Participant(object):

    """ Class representing a participant

    Args:

        name (str): Label of your participant

        session (str): Optional label of a session

    """

    def __init__(self, name, session=DEFAULT.session):

        self._name = ""

        self._session = ""

        self.name = name

        self.session = session

    @property

    def name(self):

        """

        Returns:

            A string 'sub-<subject_label>'

        """

        return self._name

    @name.setter

    def name(self, name):

        """ Prepend 'sub-' if necessary"""

        if name.startswith("sub-"):

            self._name = name

        else:

            self._name = "sub-" + name

        if not self._name.replace('sub-', '').isalnum():

            raise NameError(f"Participant '{self._name.replace('sub-', '')}' "

                            "should contains only alphanumeric characters.")

    @property

    def session(self):

        """

        Returns:

            A string 'ses-<session_label>'

        """

        return self._session

    @session.setter

    def session(self, session):

        """ Prepend 'ses-' if necessary"""

        if session.strip() == "":

            self._session = ""

        elif session.startswith("ses-"):

            self._session = session

        else:

            self._session = "ses-" + session

        if not self._session.replace('ses-', '').isalnum() and self._session:

            raise NameError(f"Session '{self._session.replace('ses-', '')}' "

                            "should contains only alphanumeric characters.")

    @property

    def directory(self):

        """ The directory of the participant

        Returns:

            A path 'sub-<subject_label>' or

            'sub-<subject_label>/ses-<session_label>'

        """

        if self.hasSession():

            return opj(self.name, self.session)

        else:

            return self.name

    @property

    def prefix(self):

        """ The prefix to build filenames

        Returns:

            A string 'sub-<subject_label>' or

            'sub-<subject_label>_ses-<session_label>'

        """

        if self.hasSession():

            return self.name + "_" + self.session

        else:

            return self.name

    def hasSession(self):

        """ Check if a session is set

        Returns:

            Boolean

        """

        return self.session.strip() != DEFAULT.session

Classes⚓︎

Participant⚓︎

1
2
3
4
class Participant(
    name,
    session=''
)

Class representing a participant

Attributes⚓︎

Name Type Description Default
name str Label of your participant None
session str Optional label of a session None
View Source
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
class Participant(object):

    """ Class representing a participant

    Args:

        name (str): Label of your participant

        session (str): Optional label of a session

    """

    def __init__(self, name, session=DEFAULT.session):

        self._name = ""

        self._session = ""

        self.name = name

        self.session = session

    @property

    def name(self):

        """

        Returns:

            A string 'sub-<subject_label>'

        """

        return self._name

    @name.setter

    def name(self, name):

        """ Prepend 'sub-' if necessary"""

        if name.startswith("sub-"):

            self._name = name

        else:

            self._name = "sub-" + name

        if not self._name.replace('sub-', '').isalnum():

            raise NameError(f"Participant '{self._name.replace('sub-', '')}' "

                            "should contains only alphanumeric characters.")

    @property

    def session(self):

        """

        Returns:

            A string 'ses-<session_label>'

        """

        return self._session

    @session.setter

    def session(self, session):

        """ Prepend 'ses-' if necessary"""

        if session.strip() == "":

            self._session = ""

        elif session.startswith("ses-"):

            self._session = session

        else:

            self._session = "ses-" + session

        if not self._session.replace('ses-', '').isalnum() and self._session:

            raise NameError(f"Session '{self._session.replace('ses-', '')}' "

                            "should contains only alphanumeric characters.")

    @property

    def directory(self):

        """ The directory of the participant

        Returns:

            A path 'sub-<subject_label>' or

            'sub-<subject_label>/ses-<session_label>'

        """

        if self.hasSession():

            return opj(self.name, self.session)

        else:

            return self.name

    @property

    def prefix(self):

        """ The prefix to build filenames

        Returns:

            A string 'sub-<subject_label>' or

            'sub-<subject_label>_ses-<session_label>'

        """

        if self.hasSession():

            return self.name + "_" + self.session

        else:

            return self.name

    def hasSession(self):

        """ Check if a session is set

        Returns:

            Boolean

        """

        return self.session.strip() != DEFAULT.session

Instance variables⚓︎

1
directory

The directory of the participant

1
name
1
prefix

The prefix to build filenames

1
session

Methods⚓︎

hasSession⚓︎

1
2
3
def hasSession(
    self
)

Check if a session is set

Returns:

Type Description
None Boolean
View Source
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
    def hasSession(self):

        """ Check if a session is set

        Returns:

            Boolean

        """

        return self.session.strip() != DEFAULT.session

Last update: 2024-07-23
Created: 2024-07-23