""" A BIDS tabular file including its associated sidecar. """importosimportjsonfromhed.models.tabular_inputimportTabularInputfromhed.tools.bids.bids_fileimportBidsFilefromhed.tools.bids.bids_sidecar_fileimportBidsSidecarFile
[docs]classBidsTabularFile(BidsFile):""" A BIDS tabular file including its associated sidecar. """
[docs]def__init__(self,file_path):""" Constructor for a BIDS tabular file. Parameters: file_path (str): Path of the tabular file. """super().__init__(file_path)self.sidecar=None
[docs]defset_contents(self,content_info=None,overwrite=False):""" Set the contents of this tabular file (a TabularInput object). It's sidecar should already be set. Parameters: content_info (None): This always uses the internal file_path to create the contents. overwrite(bool): If False (The Default), do not overwrite existing contents if any. """ifself._contentsandnotoverwrite:returnifself.sidecar:self._contents=TabularInput(file=self.file_path,sidecar=self.sidecar,name=os.path.realpath(self.file_path))else:self._contents=TabularInput(file=self.file_path,name=os.path.realpath(self.file_path))columns=self._contents.columnsif'HED'incolumnsor'HED_assembled'incolumns:self.has_hed=Trueelifself.sidecar:self.has_hed=BidsSidecarFile.is_hed(self.sidecar.loaded_dict)
[docs]defset_sidecar(self,sidecar):""" Set the sidecar for this tabular file. Parameters: sidecar (Sidecar): The sidecar for this tabular file. """self.sidecar=sidecar