neuroscout/populate/annotate.py
def load(self, variable):
        """" Load and annotate a BIDSVariable
        Args:
            res - BIDSVariableCollection object
        Returns a dictionary of annotated features
        """
        if self.include is not None and variable.name not in self.include:
            return None
        if self.exclude is not None and variable.name in self.exclude:
            return None

        annotated = {}
        annotated['original_name'] = variable.name
        annotated['source'] = variable.source

        for pattern, attr in self.schema.items():
            if re.compile(pattern).match(variable.name):
                annotated['name'] = re.sub(
                    pattern, attr.pop('name'), variable.name) \
                    if 'name' in attr else variable.name
                annotated['description'] = re.sub(
                    pattern, attr.pop('description'), variable.name) \
                    if 'description' in attr else None
                annotated.update(**attr)  # Add any additional attributes
                break
        else:
            annotated['name'] = variable.name
            if self.add_all is False:
                return None

        # If SparseVariable
        if hasattr(variable, 'onset'):
            onsets = variable.onset.tolist()
            durations = variable.duration.tolist()
            values = variable.values.values.tolist()

        # If Dense, resample, and sparsify
        else:
            TR = variable.sampling_rate / 2 if self.TR is None else self.TR
            variable = variable.resample(1 / TR)

            onsets = np.arange(
                0, len(variable.values) * self.TR, self.TR).tolist()
            durations = [(self.TR)] * len(variable.values)
            values = variable.values[variable.name].values.tolist()

        events = []
        for i, onset in enumerate(onsets):
            try:
                events.append(
                    {
                        'onset': onset,
                        'duration': durations[i],
                        'value': values[i]
                    }
                )
            except IndexError:
                if len(onsets) - len(values) == 1:
                    pass
                else:
                    raise IndexError

        return annotated, events
 Load and annotate a BIDSVariable
        Args:
            res - BIDSVariableCollection object
        Returns a dictionary of annotated features
        
Load and annotate a BIDSVariable
Args:
res - BIDSVariableCollection object
Returns a dictionary of annotated features
Load and annotate a BIDSVariable Args : res - BIDSVariableCollection object Returns a dictionary of annotated features
def load(self, variable):
        if self.include is not None and variable.name not in self.include:
            return None
        if self.exclude is not None and variable.name in self.exclude:
            return None
        annotated = {}
        annotated['original_name'] = variable.name
        annotated['source'] = variable.source
        for pattern, attr in self.schema.items():
            if re.compile(pattern).match(variable.name):
                annotated['name'] = re.sub(
                    pattern, attr.pop('name'), variable.name) \
                    if 'name' in attr else variable.name
                annotated['description'] = re.sub(
                    pattern, attr.pop('description'), variable.name) \
                    if 'description' in attr else None
                annotated.update(**attr)  
                break
        else:
            annotated['name'] = variable.name
            if self.add_all is False:
                return None
        if hasattr(variable, 'onset'):
            onsets = variable.onset.tolist()
            durations = variable.duration.tolist()
            values = variable.values.values.tolist()
        else:
            TR = variable.sampling_rate / 2 if self.TR is None else self.TR
            variable = variable.resample(1 / TR)
            onsets = np.arange(
                0, len(variable.values) * self.TR, self.TR).tolist()
            durations = [(self.TR)] * len(variable.values)
            values = variable.values[variable.name].values.tolist()
        events = []
        for i, onset in enumerate(onsets):
            try:
                events.append(
                    {
                        'onset': onset,
                        'duration': durations[i],
                        'value': values[i]
                    }
                )
            except IndexError:
                if len(onsets) - len(values) == 1:
                    pass
                else:
                    raise IndexError
        return annotated, events
def load ( self , variable ) : if self . include is not None and variable . name not in self . include : return None if self . exclude is not None and variable . name in self . exclude : return None annotated = { } annotated [ 'original_name' ] = variable . name annotated [ 'source' ] = variable . source for pattern , attr in self . schema . items ( ) : if re . compile ( pattern ) . match ( variable . name ) : annotated [ 'name' ] = re . sub ( pattern , attr . pop ( 'name' ) , variable . name ) if 'name' in attr else variable . name annotated [ 'description' ] = re . sub ( pattern , attr . pop ( 'description' ) , variable . name ) if 'description' in attr else None annotated . update ( ** attr ) break else : annotated [ 'name' ] = variable . name if self . add_all is False : return None if hasattr ( variable , 'onset' ) : onsets = variable . onset . tolist ( ) durations = variable . duration . tolist ( ) values = variable . values . values . tolist ( ) else : TR = variable . sampling_rate / 2 if self . TR is None else self . TR variable = variable . resample ( 1 / TR ) onsets = np . arange ( 0 , len ( variable . values ) * self . TR , self . TR ) . tolist ( ) durations = [ ( self . TR ) ] * len ( variable . values ) values = variable . values [ variable . name ] . values . tolist ( ) events = [ ] for i , onset in enumerate ( onsets ) : try : events . append ( { 'onset' : onset , 'duration' : durations [ i ] , 'value' : values [ i ] } ) except IndexError : if len ( onsets ) - len ( values ) == 1 : pass else : raise IndexError return annotated , events
Load and annotate a BIDSVariable
Args:
res - BIDSVariableCollection object
Returns a dictionary of annotated features
Load and annotate a BIDSVariable Args : res - BIDSVariableCollection object Returns a dictionary of annotated features
"""" Load and annotate a BIDSVariable
        Args:
            res - BIDSVariableCollection object
        Returns a dictionary of annotated features
        """ # Add any additional attributes # If SparseVariable # If Dense, resample, and sparsify
self
variable