예제 #1
0
 def beams(self):
     if self._loaded:
         bl = self._blist
         del self._blist
         return bl
     bl = [tfb.tfbeam_from_file(f, **self._b_kwargs) for f in self._blist]
     self.__beam_sanity_check(bl)
     del self._blist
     return bl
예제 #2
0
def perform_activation_ttest(dir=None, ptr=None):
    if dir is not None:
        glob_str = os.path.join(dir, "s_beam*spatnorm*mat")
        mat_files = glob.glob(glob_str)
        # get all beams in dir, with subject and condition labels for each beam
        beam_list = [tfbeam_from_file(mfile, fixed_comparison="F dB") for mfile in mat_files]
        subj_labels = range(1, len(beam_list) + 1)
        cond_labels = [1] * len(subj_labels)

        a_comp = bstat.BeamActivationAverager(beam_list, subj_labels, cond_labels)
    elif ptr is not None:
        a_comp = bstat.BeamActivationAverager.from_matlab_ptr_file(ptr, ratio_type="F dB")

    # do an activation test on condition 1
    one_samp_t = bstat.SnPMOneSampT(a_comp, 1, 0, force_half_perms=True)
    s_res = one_samp_t.test()
    return s_res, one_samp_t.avg_beams[0]
예제 #3
0
def _main(mode='real'):
    condition_1_spec = [
    ('subj1', '/Users/mike/workywork/nutmeg-py/data/meg_6subj2cond/sub1/s_beamtf_listenfirst75Lhemi_firlsbp200_bf_SAM_all_spatnorm.mat'),
    ('subj2', '/Users/mike/workywork/nutmeg-py/data/meg_6subj2cond/sub2/s_beamtf_listenfirst75Lhemi_firlsbp200_bf_SAM_all_spatnorm.mat'),
    ('subj3', '/Users/mike/workywork/nutmeg-py/data/meg_6subj2cond/sub3/s_beamtf_listenfirst75Lhemi_firlsbp200_bf_SAM_all_spatnorm.mat'),
    ('subj4', '/Users/mike/workywork/nutmeg-py/data/meg_6subj2cond/sub4/s_beamtf_listenfirst75Lhemi_firlsbp200_bf_SAM_all_spatnorm.mat'),
    ('subj5', '/Users/mike/workywork/nutmeg-py/data/meg_6subj2cond/sub5/s_beamtf_listenfirst75Lhemi_firlsbp200_bf_SAM_all_spatnorm.mat'),
    ('subj6', '/Users/mike/workywork/nutmeg-py/data/meg_6subj2cond/sub6/s_beamtf_listenfirst75Lhemi_firlsbp200_bf_SAM_all_spatnorm.mat'),
    ]
    condition_2_spec = [
    ('subj1', '/Users/mike/workywork/nutmeg-py/data/meg_6subj2cond/sub1/s_beamtf_speakfirst75Lhemi_firlsbp200_bf_SAM_all_spatnorm.mat'),
    ('subj2', '/Users/mike/workywork/nutmeg-py/data/meg_6subj2cond/sub2/s_beamtf_speakfirst75Lhemi_firlsbp200_bf_SAM_all_spatnorm.mat'),
    ('subj3', '/Users/mike/workywork/nutmeg-py/data/meg_6subj2cond/sub3/s_beamtf_speakfirst75Lhemi_firlsbp200_bf_SAM_all_spatnorm.mat'),
    ('subj4', '/Users/mike/workywork/nutmeg-py/data/meg_6subj2cond/sub4/s_beamtf_speakfirst75Lhemi_firlsbp200_bf_SAM_all_spatnorm.mat'),
    ('subj5', '/Users/mike/workywork/nutmeg-py/data/meg_6subj2cond/sub5/s_beamtf_speakfirst75Lhemi_firlsbp200_bf_SAM_all_spatnorm.mat'),
    ('subj6', '/Users/mike/workywork/nutmeg-py/data/meg_6subj2cond/sub6/s_beamtf_speakfirst75Lhemi_firlsbp200_bf_SAM_all_spatnorm.mat'),
    ]
    if mode=='real':
        c1 = Condition(subjs=[Subject(name=nm, fpath=fp)
                              for nm, fp in condition_1_spec],
                       cname='listen_first')
        c2 = Condition(subjs=[Subject(name=nm, fpath=fp)
                              for nm, fp in condition_2_spec],
                       cname='speak_first')
        demo = ListOfConditions(conditions=[c1, c2])
        return demo
    elif mode=='synth_contrast':
        from nutmeg.stats.tests import synth_activations
        n_subjs = 6
        def save_beams(bl, sl, cl):
            pl = []
            for b, s, c in zip(bl, sl, cl):
                p = 'synth_beam_s%d_c%d'%(s, c)
                pl.append(os.path.abspath(p)+'.npy')
                b.save(p)
            return pl
        beam = tfbeam.tfbeam_from_file(condition_1_spec[0][1],
                                       fixed_comparison='F dB')
        c1b = synth_activations.synthetic_gaussian_activity_like(
            beam, n_beams=n_subjs,
            tf_pts=[ (t,1) for t in xrange(4,13) ],
            locs = ( (-20,-30,-30), (-15,3,15), (-18,15,0) ),
            size=14.,
            mode='activation'
            )
        c1_subjs = range(1,n_subjs+1)
        c1_labels = [1] * n_subjs
        c1_paths = save_beams(c1b, c1_subjs, c1_labels)

        c2b = synth_activations.synthetic_gaussian_activity_like(
            beam, n_beams=n_subjs,
            tf_pts=[ (t,1) for t in xrange(4,13) ],
            locs = ( (-20,-30,-30), (-15,3,15), (-18,15,0) ),
            size=14.,
            mode='activation', pval=.1
            )
        c2_subjs = range(1,n_subjs+1)
        c2_labels = [2] * n_subjs
        c2_paths = save_beams(c2b, c2_subjs, c2_labels)

        c3b = synth_activations.synthetic_gaussian_activity_like(
            beam, n_beams=n_subjs, mode='activation',
            tf_pts=[ (t,1) for t in xrange(4,13) ],
            locs = ( (-20,-30,-30), (-15,3,15), (-18,15,0) ),
            size=14.            
            )
        c3_subjs = range(1,n_subjs+1)
        c3_labels = [3] * n_subjs
        c3_paths = save_beams(c3b, c3_subjs, c3_labels)
        
        c4b = synth_activations.synthetic_gaussian_activity_like(
            beam, n_beams=n_subjs, mode='activation', pval=.6,
            tf_pts=[ (t,1) for t in xrange(4,13) ],
            locs = ( (-20,-30,-30), (-15,3,15), (-18,15,0) ),
            size=14.            
            )
        c4_subjs = range(1,n_subjs+1)
        c4_labels = [4] * n_subjs
        c4_paths = save_beams(c4b, c4_subjs, c4_labels)

        conds = [ Condition(subjs=[Subject(name=str(nm), fpath=fp)
                                   for nm, fp in zip(subjs, paths)],
                            name=cname)
                  for subjs, paths, cname in zip( [c1_subjs, c2_subjs,
                                                   c3_subjs, c4_subjs],
                                                  [c1_paths, c2_paths,
                                                   c3_paths, c4_paths],
                                                  ['1', '2', '3', '4'] ) ]
        demo = ListOfConditions(conditions=conds)
        
        return demo