neuroscout/populate/convert.py
def convert_stimuli(converters, dataset_name=None, task_name=None):
    """ Convert stimuli to different modality using pliers.
        Args:
            converters - dictionary of converter names to parameters
            dataset_name - dataset name
            task_name - task name
        Output:
            list of db ids of converted stimuli
    """
    if dataset_name is None:
        return [convert_stimuli(
            converters, dataset.name, None)
                for dataset in Dataset.query.filter_by(active=True)]

    dataset = Dataset.query.filter_by(name=dataset_name).one()
    dataset_id = dataset.id

    print(f"Converting stimuli for dataset: {dataset.name}")

    converters = [Graph(n) for n in converters]

    # Load all active original stimuli for task
    stim_objects = Stimulus.query.filter_by(active=True, parent_id=None).join(
        RunStimulus).join(Run).join(Task)

    if task_name is not None:
        stim_objects = stim_objects.filter_by(name=task_name)

    stim_objects = stim_objects.join(Dataset).filter_by(name=dataset_name)

    total_new_stims = []
    # Extract new stimuli from original stimuli
    for stim in stim_objects:
        new_stims = []
        # Re-create new RS associations with newly created stims
        rs_orig = RunStimulus.query.filter_by(stimulus_id=stim.id).join(
            Run).join(Task).filter_by(name=task_name)
        loaded_stim = load_stims(stim.path)

        # Extract for each converter
        for graph in converters:
            results = []
            # Extract and flatten results (to a single unit)
            conv = graph.roots[0].transformer
            if conv._stim_matches_input_types(loaded_stim):
                cstim = graph.transform(loaded_stim, merge=False)
                if len(cstim) == 1:
                    cstim = cstim[0]
                params = str(conv.__dict__)
                name = conv.name
                try:  # Add iterable
                    results += cstim
                except TypeError:
                    if hasattr(cstim, 'elements'):
                        results += cstim.elements
                    else:
                        results.append(cstim)

                results = [res for res in results
                           if hasattr(res, 'data') and res.data != '']
                new_stims += create_new_stimuli(
                    dataset_id, task_name, results, rs_orig,
                    parent_id=stim.id,
                    transformer=name,
                    transformer_params=params)

        # De-activate previously generated stimuli from these converters.
        update = Stimulus.query.filter_by(parent_id=stim.id).filter(
            Stimulus.id.notin_(new_stims),
            Stimulus.converter_name == conv.name,
            Stimulus.converter_parameters == str(conv.__dict__))
        if update.count():
            update.update(dict(active=False), synchronize_session='fetch')
        db.session.commit()
        total_new_stims += new_stims

    return total_new_stims
 Convert stimuli to different modality using pliers.
        Args:
            converters - dictionary of converter names to parameters
            dataset_name - dataset name
            task_name - task name
        Output:
            list of db ids of converted stimuli
    
Convert stimuli to different modality using pliers.
Args:
converters - dictionary of converter names to parameters
dataset_name - dataset name
task_name - task name
Output:
list of db ids of converted stimuli
Convert stimuli to different modality using pliers . Args : converters - dictionary of converter names to parameters dataset_name - dataset name task_name - task name Output : list of db ids of converted stimuli
def convert_stimuli(converters, dataset_name=None, task_name=None):
    if dataset_name is None:
        return [convert_stimuli(
            converters, dataset.name, None)
                for dataset in Dataset.query.filter_by(active=True)]
    dataset = Dataset.query.filter_by(name=dataset_name).one()
    dataset_id = dataset.id
    print(f"Converting stimuli for dataset: {dataset.name}")
    converters = [Graph(n) for n in converters]
    stim_objects = Stimulus.query.filter_by(active=True, parent_id=None).join(
        RunStimulus).join(Run).join(Task)
    if task_name is not None:
        stim_objects = stim_objects.filter_by(name=task_name)
    stim_objects = stim_objects.join(Dataset).filter_by(name=dataset_name)
    total_new_stims = []
    for stim in stim_objects:
        new_stims = []
        rs_orig = RunStimulus.query.filter_by(stimulus_id=stim.id).join(
            Run).join(Task).filter_by(name=task_name)
        loaded_stim = load_stims(stim.path)
        for graph in converters:
            results = []
            conv = graph.roots[0].transformer
            if conv._stim_matches_input_types(loaded_stim):
                cstim = graph.transform(loaded_stim, merge=False)
                if len(cstim) == 1:
                    cstim = cstim[0]
                params = str(conv.__dict__)
                name = conv.name
                try:  
                    results += cstim
                except TypeError:
                    if hasattr(cstim, 'elements'):
                        results += cstim.elements
                    else:
                        results.append(cstim)
                results = [res for res in results
                           if hasattr(res, 'data') and res.data != '']
                new_stims += create_new_stimuli(
                    dataset_id, task_name, results, rs_orig,
                    parent_id=stim.id,
                    transformer=name,
                    transformer_params=params)
        update = Stimulus.query.filter_by(parent_id=stim.id).filter(
            Stimulus.id.notin_(new_stims),
            Stimulus.converter_name == conv.name,
            Stimulus.converter_parameters == str(conv.__dict__))
        if update.count():
            update.update(dict(active=False), synchronize_session='fetch')
        db.session.commit()
        total_new_stims += new_stims
    return total_new_stims
def convert_stimuli ( converters , dataset_name = None , task_name = None ) : if dataset_name is None : return [ convert_stimuli ( converters , dataset . name , None ) for dataset in Dataset . query . filter_by ( active = True ) ] dataset = Dataset . query . filter_by ( name = dataset_name ) . one ( ) dataset_id = dataset . id print ( f"Converting stimuli for dataset: {dataset.name}" ) converters = [ Graph ( n ) for n in converters ] stim_objects = Stimulus . query . filter_by ( active = True , parent_id = None ) . join ( RunStimulus ) . join ( Run ) . join ( Task ) if task_name is not None : stim_objects = stim_objects . filter_by ( name = task_name ) stim_objects = stim_objects . join ( Dataset ) . filter_by ( name = dataset_name ) total_new_stims = [ ] for stim in stim_objects : new_stims = [ ] rs_orig = RunStimulus . query . filter_by ( stimulus_id = stim . id ) . join ( Run ) . join ( Task ) . filter_by ( name = task_name ) loaded_stim = load_stims ( stim . path ) for graph in converters : results = [ ] conv = graph . roots [ 0 ] . transformer if conv . _stim_matches_input_types ( loaded_stim ) : cstim = graph . transform ( loaded_stim , merge = False ) if len ( cstim ) == 1 : cstim = cstim [ 0 ] params = str ( conv . __dict__ ) name = conv . name try : results += cstim except TypeError : if hasattr ( cstim , 'elements' ) : results += cstim . elements else : results . append ( cstim ) results = [ res for res in results if hasattr ( res , 'data' ) and res . data != '' ] new_stims += create_new_stimuli ( dataset_id , task_name , results , rs_orig , parent_id = stim . id , transformer = name , transformer_params = params ) update = Stimulus . query . filter_by ( parent_id = stim . id ) . filter ( Stimulus . id . notin_ ( new_stims ) , Stimulus . converter_name == conv . name , Stimulus . converter_parameters == str ( conv . __dict__ ) ) if update . count ( ) : update . update ( dict ( active = False ) , synchronize_session = 'fetch' ) db . session . commit ( ) total_new_stims += new_stims return total_new_stims
Convert stimuli to different modality using pliers.
Convert stimuli to different modality using pliers .
""" Convert stimuli to different modality using pliers.
        Args:
            converters - dictionary of converter names to parameters
            dataset_name - dataset name
            task_name - task name
        Output:
            list of db ids of converted stimuli
    """ # Load all active original stimuli for task # Extract new stimuli from original stimuli # Re-create new RS associations with newly created stims # Extract for each converter # Extract and flatten results (to a single unit) # Add iterable # De-activate previously generated stimuli from these converters.
converters
dataset_name
task_name