= CohortSelector() cs
Cohort selector
Select participants based on any field.
CohortSelector
CohortSelector (base_path:str='nbs/examples/', cohort:str=None, errors:str='warn', **kwargs)
*Class for selecting a subset of a cohort’s data based on a query.
Args:
base_path (str, optional): Base path of the datasets. Defaults to DATASETS_PATH.
cohort (str, optional): Name of the cohort. Defaults to COHORT.
errors (str, optional): Error action. Defaults to ERROR_ACTION.
**kwargs: Additional keyword arguments.
Attributes:
cohort (str): Name of the cohort.
base_path (str): Base path of the datasets.
errors (str): Error action.
kwargs: Additional keyword arguments.
ml (MetaLoader): MetaLoader object for loading metadata and data.*
You may use the CohortSelector
to select participants based on any fields. The selector will return a DataFrame with the selected sub-cohort, along with the fields that were used in the query.
For example, the following query selects participants who have moderate obstructive sleep apnea (AHI > 15) based on recordings of at least 4 hours of sleep.
'15 < ahi < 20 & total_sleep_time > 4*3600') cs.select(
ahi | total_sleep_time | ||||
---|---|---|---|---|---|
participant_id | cohort | research_stage | array_index | ||
9 | 10k | 02_00_visit | 2 | 18.39 | 23748.0 |
15 | 10k | 00_00_visit | 0 | 19.54 | 19230.0 |
30 | 10k | 00_00_visit | 0 | 18.52 | 25111.0 |
42 | 10k | 00_00_visit | 1 | 17.84 | 24966.0 |
49 | 10k | 02_00_visit | 0 | 17.58 | 21980.0 |
... | ... | ... | ... | ... | ... |
902 | 10k | 02_00_visit | 2 | 19.78 | 24162.0 |
914 | 10k | 02_00_visit | 2 | 17.54 | 26479.0 |
936 | 10k | 00_00_visit | 1 | 17.43 | 20865.0 |
941 | 10k | 00_00_visit | 0 | 17.82 | 17606.0 |
965 | 10k | 00_00_visit | 2 | 15.38 | 24390.0 |
77 rows × 2 columns
You may also use the selector to filter on dates. Here we filter on dates of image collection in the fundus imaging dataset.
In addition, we may load additional fields that are not part of the query.
'fundus/collection_date > "2022-01-01"', add_fields='fundus_image_left') cs.select(
fundus_image_left | collection_date | ||||
---|---|---|---|---|---|
participant_id | cohort | research_stage | array_index | ||
0 | 10k | 00_00_visit | 0 | /path/to/file | 2022-11-16 |
1 | 10k | 00_00_visit | 0 | /path/to/file | 2022-06-30 |
3 | 10k | 00_00_visit | 0 | /path/to/file | 2022-04-26 |