neuroscout/populate/convert.py
def predictor_to_text_stim(predictor_id, task_name, transformer='reading',
                           params=None):
    """ Convert Predictors that were ingested from the original dataset's
    event files into a Stimulus. This is useful for Predictors which are
    speech or reading transcripts with word specific onsets and durations """

    predictor = Predictor.query.filter_by(id=predictor_id).one()
    dataset_id = predictor.dataset_id

    rst = namedtuple('RunStimulus', ['onset', 'duration', 'run_id'])

    if params is None:
        params = {}

    for pr in predictor.predictor_run:
        pes = PredictorEvent.query.filter_by(
            run_id=pr.run_id, predictor_id=predictor_id)

        # Uniquify
        pes = [(pe.value, pe.onset, pe.duration) for pe in pes]
        pes = set(pes)

        # Calculate run duration
        duration = Run.query.filter_by(id=pr.run_id).one().duration

        # Create new stimuli
        new_stims = [
            TextStim(text=pe[0], onset=pe[1],
                     duration=pe[2])
            for pe in pes]

        # Complete transcript stimulus stand in
        transcript_stim = ComplexTextStim(
            elements=new_stims)
        transcript_stim.name = 'FULL_TRANSCRIPT'

        new_stims.append(transcript_stim)

        onset = 0

        # Duration is the max onset + that duration
        duration = max([pe[1] for pe in pes])
        duration += [pe[2] for pe in pes if pe[1] == duration][0]

        rs = rst(onset=onset, duration=duration, run_id=pr.run_id)

        params['onset'] = onset
        params['duration'] = duration

        create_new_stimuli(
            dataset_id, task_name, new_stims, [rs],
            transformer=transformer, transformer_params=params,
            delete_old=False)
 Convert Predictors that were ingested from the original dataset's
    event files into a Stimulus. This is useful for Predictors which are
    speech or reading transcripts with word specific onsets and durations 
Convert Predictors that were ingested from the original dataset's
event files into a Stimulus. This is useful for Predictors which are
speech or reading transcripts with word specific onsets and durations
Convert Predictors that were ingested from the original dataset ' s event files into a Stimulus . This is useful for Predictors which are speech or reading transcripts with word specific onsets and durations
def predictor_to_text_stim(predictor_id, task_name, transformer='reading',
                           params=None):
    predictor = Predictor.query.filter_by(id=predictor_id).one()
    dataset_id = predictor.dataset_id
    rst = namedtuple('RunStimulus', ['onset', 'duration', 'run_id'])
    if params is None:
        params = {}
    for pr in predictor.predictor_run:
        pes = PredictorEvent.query.filter_by(
            run_id=pr.run_id, predictor_id=predictor_id)
        pes = [(pe.value, pe.onset, pe.duration) for pe in pes]
        pes = set(pes)
        duration = Run.query.filter_by(id=pr.run_id).one().duration
        new_stims = [
            TextStim(text=pe[0], onset=pe[1],
                     duration=pe[2])
            for pe in pes]
        transcript_stim = ComplexTextStim(
            elements=new_stims)
        transcript_stim.name = 'FULL_TRANSCRIPT'
        new_stims.append(transcript_stim)
        onset = 0
        duration = max([pe[1] for pe in pes])
        duration += [pe[2] for pe in pes if pe[1] == duration][0]
        rs = rst(onset=onset, duration=duration, run_id=pr.run_id)
        params['onset'] = onset
        params['duration'] = duration
        create_new_stimuli(
            dataset_id, task_name, new_stims, [rs],
            transformer=transformer, transformer_params=params,
            delete_old=False)
def predictor_to_text_stim ( predictor_id , task_name , transformer = 'reading' , params = None ) : predictor = Predictor . query . filter_by ( id = predictor_id ) . one ( ) dataset_id = predictor . dataset_id rst = namedtuple ( 'RunStimulus' , [ 'onset' , 'duration' , 'run_id' ] ) if params is None : params = { } for pr in predictor . predictor_run : pes = PredictorEvent . query . filter_by ( run_id = pr . run_id , predictor_id = predictor_id ) pes = [ ( pe . value , pe . onset , pe . duration ) for pe in pes ] pes = set ( pes ) duration = Run . query . filter_by ( id = pr . run_id ) . one ( ) . duration new_stims = [ TextStim ( text = pe [ 0 ] , onset = pe [ 1 ] , duration = pe [ 2 ] ) for pe in pes ] transcript_stim = ComplexTextStim ( elements = new_stims ) transcript_stim . name = 'FULL_TRANSCRIPT' new_stims . append ( transcript_stim ) onset = 0 duration = max ( [ pe [ 1 ] for pe in pes ] ) duration += [ pe [ 2 ] for pe in pes if pe [ 1 ] == duration ] [ 0 ] rs = rst ( onset = onset , duration = duration , run_id = pr . run_id ) params [ 'onset' ] = onset params [ 'duration' ] = duration create_new_stimuli ( dataset_id , task_name , new_stims , [ rs ] , transformer = transformer , transformer_params = params , delete_old = False )
Convert Predictors that were ingested from the original dataset's
event files into a Stimulus.
Convert Predictors that were ingested from the original dataset ' s event files into a Stimulus .
""" Convert Predictors that were ingested from the original dataset's
    event files into a Stimulus. This is useful for Predictors which are
    speech or reading transcripts with word specific onsets and durations """ # Uniquify # Calculate run duration # Create new stimuli # Complete transcript stimulus stand in # Duration is the max onset + that duration
predictor_id
task_name
transformer
params