Subject validator¶
SubjectMetadata
¶
Bases: BaseModel
Data model for participant demographic information.
Handles the conversion of human-readable strings into BIDS-compliant integers and calculates a surrogate birthday required for MNE internal age calculations.
Attributes:
| Name | Type | Description |
|---|---|---|
age |
PositiveInt
|
Participant age in years. |
sex |
Literal[0, 1, 2]
|
Participant biological sex (0=Unknown, 1=Male, 2=Female). |
hand |
Literal[1, 2, 3]
|
Participant handedness (1=Left, 2=Right, 3=Ambidextrous). Aliased as 'handedness' in input data. |
meas_date |
datetime
|
The date of the recording. Defaults to the current UTC date. |
Source code in src/rs_bidsify/validation/subject.py
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 | |
birthday
property
¶
Calculate a surrogate birthday based on age and measurement date.
MNE requires a 'birthday' field to store age in its internal subject_info structure. This computes a date exactly 'age' years prior to the recording date to satisfy this requirement.
Returns:
| Type | Description |
|---|---|
date
|
The calculated surrogate birth date. |
from_dataframe(recording, df, mapping)
classmethod
¶
Initialize the model using a row from a pandas DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
recording
|
RecordingMetadata
|
Metadata for the current recording session, used to find the participant ID index. |
required |
df
|
DataFrame
|
The dataframe containing demographic data. |
required |
mapping
|
dict[str, Any]
|
Dictionaries defining string-to-int mappings for sex and hand. |
required |
Returns:
| Type | Description |
|---|---|
SubjectMetadata
|
A validated instance of the model. |
Source code in src/rs_bidsify/validation/subject.py
map_string_to_int(value, info)
classmethod
¶
Convert sex and handedness strings to BIDS-compliant integers.
Uses a mapping dictionary provided via the Pydantic validation context to translate descriptive strings (e.g., 'female', 'right') into their standardized integer representations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
The raw input value, typically a string from a spreadsheet. |
required |
info
|
ValidationInfo
|
Pydantic validation metadata containing the mapping context. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The mapped integer value if a string was provided, or the original value if already numeric. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input string does not exist in the provided mapping dictionaries. |
Source code in src/rs_bidsify/validation/subject.py
subject_info_dump()
¶
Generate a dictionary formatted for MNE's info['subject_info'].
Extracts the subset of fields compatible with the MNE-Python subject information schema.
Returns:
| Type | Description |
|---|---|
dict
|
A dictionary containing 'sex', 'hand', and 'birthday'. |