all_fr = np.zeros((np.shape(bfr_cue)[0],np.shape(bfr_cue)[1],2*(bfr_bins+aft_bins)),dtype=np.float32)
        
        all_fr[:,:,0:bfr_bins] = bfr_cue
        all_fr[:,:,bfr_bins:bfr_bins+aft_bins] = aft_cue
        all_fr[:,:,bfr_bins+aft_bins:2*bfr_bins+aft_bins] = bfr_result
        all_fr[:,:,2*bfr_bins+aft_bins:2*bfr_bins+2*aft_bins] = aft_result
        
        all_avg,all_bal = sort_and_avg(all_fr,sort_dict)
        del all_fr
        [bal_cond,N,R,P,D,T] = np.shape(all_bal)
	print 'N= %s, R= %s, P= %s, D= %s, T= %s, bal_cond= %s' %(N,R,P,D,T,bal_cond)

        join_comb = {'dt':['d','dt'],'pt':['p','pt'],'pdt':['pd','pdt'],'rt':['r','rt'],'rpt':['rp','rpt'],'rdt':['rd','rdt'],'rpdt':['rpd','rpdt']}

	######### from test ########
	dpca = dPCA.dPCA(labels='rpdt',regularizer='auto',n_components = 15,join=join_comb)
	dpca.protect = ['t']
	Z = dpca.fit_transform(all_avg,all_bal)
        if not do_sig_analysis:
                del all_bal
	explained_var = dpca.explained_variance_ratio_	

	bins = np.arange(T)

	#PARAM
	components_plot = 4 #even for now, number of subplots per plot (3 plots for now).
	my_ticks = ['-0.5','0','0.5','-0.5','0','0.5','1.0']
	
	tot_bins = (bfr_bins+aft_bins)*2
	my_ticks_num = np.arange(0,tot_bins*7/6,tot_bins/6)
	
    all_fr = np.zeros((np.shape(bfr_cue)[0], np.shape(bfr_cue)[1],
                       2 * (bfr_bins + aft_bins)))
    all_fr[:, :, 0:bfr_bins] = bfr_cue
    all_fr[:, :, bfr_bins:bfr_bins + aft_bins] = aft_cue
    all_fr[:, :, bfr_bins + aft_bins:2 * bfr_bins + aft_bins] = bfr_result
    all_fr[:, :,
           2 * bfr_bins + aft_bins:2 * (bfr_bins + aft_bins)] = aft_result

    all_avg, all_bal = sort_and_avg(all_fr, sort_dict)
    [bal_cond, N, S, R, T] = np.shape(all_bal)

    print 'N= %s, S= %s, R= %s, T= %s, bal_cond= %s' % (N, S, R, T, bal_cond)

    ######### from test ########
    dpca = dPCA.dPCA(labels='sdt', regularizer='auto', n_components=5)
    dpca.protect = ['t']
    Z = dpca.fit_transform(all_avg, all_bal)
    explained_var = dpca.explained_variance_ratio_

    bins = np.arange(T)

    # Z has keys ['sdt', 'd', 'st', 's', 't', 'dt', 'sd']
    #each key of shape [n_components,S,R,T]

    #PARAM
    components_plot = 3

    my_ticks = ['-0.5', '0', '0.5', '-0.5', '0', '0.5', '1.0']
    tot_bins = (bfr_bins + aft_bins) * 2
    my_ticks_num = np.arange(0, tot_bins * 7 / 6, tot_bins / 6)