""" The contents of a BIDS dataset. """importosfromhed.schema.hed_schemaimportHedSchemafromhed.schema.hed_schema_groupimportHedSchemaGroupfromhed.tools.bids.bids_file_groupimportBidsFileGroupfromhed.tools.bidsimportbids_utilfromhed.tools.utilimportio_util
[docs]classBidsDataset:""" A BIDS dataset representation primarily focused on HED evaluation. Attributes: root_path (str): Real root path of the BIDS dataset. schema (HedSchema or HedSchemaGroup): The schema used for evaluation. file_groups (dict): A dictionary of BidsFileGroup objects with a given file suffix. """
[docs]def__init__(self,root_path,schema=None,suffixes=['events','participants'],exclude_dirs=['sourcedata','derivatives','code','stimuli']):""" Constructor for a BIDS dataset. Parameters: root_path (str): Root path of the BIDS dataset. schema (HedSchema or HedSchemaGroup): A schema that overrides the one specified in dataset. suffixes (list or None): File name suffixes of items to include. If None or empty, then ['_events', 'participants'] is assumed. exclude_dirs=['sourcedata', 'derivatives', 'code', 'phenotype']: """self.root_path=os.path.realpath(root_path)ifschema:self.schema=schemaelse:self.schema=bids_util.get_schema_from_description(self.root_path)self.exclude_dirs=exclude_dirsself.suffixes=suffixesself.file_groups=self._set_file_groups()self.bad_files=[]
[docs]defget_file_group(self,suffix):""" Return the file group of files with the specified suffix. Parameters: suffix (str): Suffix of the BidsFileGroup to be returned. Returns: Union[BidsFileGroup, None]: The requested tabular group. """returnself.file_groups.get(suffix,None)
[docs]defvalidate(self,check_for_warnings=False,schema=None):""" Validate the dataset. Parameters: check_for_warnings (bool): If True, check for warnings. schema (HedSchema or HedSchemaGroup or None): The schema used for validation. Returns: list: List of issues encountered during validation. Each issue is a dictionary. """issues=[]ifschema:this_schema=schemaelifself.schema:this_schema=self.schemaelse:return[{"code":"SCHEMA_LOAD_FAILED","message":"BIDS dataset_description.json has invalid HEDVersion and passed schema was invalid}"}]forsuffix,groupinself.file_groups.items():ifgroup.has_hed:issues+=group.validate(this_schema,check_for_warnings=check_for_warnings)returnissues
[docs]defget_summary(self):""" Return an abbreviated summary of the dataset. """summary={"dataset":self.root_path,"hed_schema_versions":self.schema.get_schema_versions(),"file_group_types":f"{str(list(self.file_groups.keys()))}"}returnsummary