コード例 #1
0
def plot_values(X, Y, suffix):
    output_filename = constants.CHARTS_FOLDER_NAME + constants.DATASET + '_' + suffix

    
    if constants.DATASET=='etoro':
        yfactor = 1.0 #100000
        Y = [y*yfactor for y in Y]
    
    
    pylab.figure(figsize=(7.5, 7))

    pylab.rcParams.update({'font.size': 20})

    pylab.scatter(X, Y)

    pylab.axis(get_bounds(X, Y, False))
    
    pylab.xlabel('Day')
    if constants.DATASET=='etoro':
        pylab.ylabel('Change (*10^' + str(int(math.log10(yfactor))) + ')')
    else:
        pylab.ylabel('Change')
    

    pylab.tight_layout()

    pylab.savefig(output_filename + '.pdf')
コード例 #2
0
ファイル: parse.py プロジェクト: tomasra/ga_sandbox
def param_set_averages_plot(results):
    averages_ocr = [
        a[1] for a in sorted(
            param_set_averages(results, metric='ocr').items(),
            key=lambda x: int(x[0].split('-')[1]))
    ]
    averages_q = [
        a[1] for a in sorted(
            param_set_averages(results, metric='q').items(),
            key=lambda x: int(x[0].split('-')[1]))
    ]
    averages_mse = [
        a[1] for a in sorted(
            param_set_averages(results, metric='mse').items(),
            key=lambda x: int(x[0].split('-')[1]))
    ]
    fig = plt.figure(figsize=(6, 4))
    # plt.tight_layout()
    plt.plot(averages_ocr, label='OCR', linewidth=2.0)
    plt.plot(averages_q, label='Q', linewidth=2.0)
    plt.plot(averages_mse, label='MSE', linewidth=2.0)
    plt.ylim([0, 1])
    plt.xlabel(u'Paslėptų neuronų skaičius')
    plt.ylabel(u'Vidurinė Q įverčio pokyčio reikšmė')
    plt.grid(True)
    plt.tight_layout()
    plt.legend(loc='lower right')
    plt.show()
コード例 #3
0
def plot_sphere_x( s, fname ):
  """ put plot of ionization fractions from sphere `s` into fname """

  plt.figure()
  s.Edges.units = 'kpc'
  s.r_c.units = 'kpc'
  xx = s.r_c
  L = s.Edges[-1]

  plt.plot( xx, np.log10( s.xHe1 ),
            color='green', ls='-', label = r'$x_{\rm HeI}$' )
  plt.plot( xx, np.log10( s.xHe2 ),
            color='green', ls='--', label = r'$x_{\rm HeII}$' )
  plt.plot( xx, np.log10( s.xHe3 ),
            color='green', ls=':', label = r'$x_{\rm HeIII}$' )

  plt.plot( xx, np.log10( s.xH1 ),
            color='red', ls='-', label = r'$x_{\rm HI}$' )
  plt.plot( xx, np.log10( s.xH2 ),
            color='red', ls='--', label = r'$x_{\rm HII}$' )

  plt.xlim( -L/20, L+L/20 )
  plt.xlabel( 'r_c [kpc]' )

  plt.ylim( -4.5, 0.2 )
  plt.ylabel( 'log 10 ( x )' )

  plt.grid()
  plt.legend(loc='best', ncol=2)
  plt.tight_layout()
  plt.savefig( 'doc/img/x_' + fname )
コード例 #4
0
ファイル: plotting_utils.py プロジェクト: JDReutt/BayesDB
def _create_histogram(M_c, data, columns, mc_col_indices, filename):
    dir = S.path.web_resources_data_dir
    full_filename = os.path.join(dir, filename)
    num_rows = data.shape[0]
    num_cols = data.shape[1]

    p.figure()
    # col_i goes from 0 to number of predicted columns
    # mc_col_idx is the original column's index in M_c
    for col_i in range(num_cols):
        mc_col_idx = mc_col_indices[col_i]
        data_i = data[:, col_i]
        ax = p.subplot(1, num_cols, col_i, title=columns[col_i])
        if M_c['column_metadata'][mc_col_idx]['modeltype'] == 'normal_inverse_gamma':
            p.hist(data_i, orientation='horizontal')
        else:
            str_data = [du.convert_code_to_value(M_c, mc_col_idx, code) for code in data_i]
            unique_labels = list(set(str_data))
            np_str_data = np.array(str_data)
            counts = []
            for label in unique_labels:
                counts.append(sum(np_str_data == label))
            num_vals = len(M_c['column_metadata'][mc_col_idx]['code_to_value'])
            rects = p.barh(range(num_vals), counts)
            heights = np.array([rect.get_height() for rect in rects])
            ax.set_yticks(np.arange(num_vals) + heights/2)
            ax.set_yticklabels(unique_labels)

    p.tight_layout()
    p.savefig(full_filename)
コード例 #5
0
def plot_Barycenter(dataset_name, feat, unfeat, repo):

    if dataset_name==MNIST:
        _, _, test=get_data(dataset_name, repo, labels=True)
        xtest1,_,_, labels,_=test
    else:
        _, _, test=get_data(dataset_name, repo, labels=False)
        xtest1,_,_ =test
        labels=np.zeros((len(xtest1),))
    # get labels
    def bary_wdl2(index): return _bary_wdl2(index, xtest1, feat, unfeat)
    
    n=xtest1.shape[-1]
    
    num_class = (int)(max(labels)+1)
    barys=[bary_wdl2(np.where(labels==i)) for i in range(num_class)]
    pl.figure(1, (num_class, 1))
    for i in range(num_class):
        pl.subplot(1,10,1+i)
        pl.imshow(barys[i][0,0,:,:],cmap='Blues',interpolation='nearest')
        pl.xticks(())
        pl.yticks(())
        if i==0:
            pl.ylabel('DWE Bary.')
        if num_class >1:
            pl.title('{}'.format(i))
    pl.tight_layout(pad=0,h_pad=-2,w_pad=-2) 
    pl.savefig("imgs/{}_dwe_bary.pdf".format(dataset_name))
コード例 #6
0
def plotCoeff(X, y, obj, featureNames, whichReg):
    """ Plot Regression's Coeff
    """
    clf = classifiers[whichReg]
    clf,_,_ = fitAlgo(clf, X,y, opt= True, param_dict = param_dist_dict[whichReg])
    if whichReg == "LogisticRegression":
    	coeff = np.absolute(clf.coef_[0])
    else:
    	coeff = np.absolute(clf.coef_)
    print coeff
    indices = np.argsort(coeff)[::-1]
    print indices
    print featureNames
    featureList = []
    # num_features = len(featureNames)
    print("Feature ranking:")
    for f in range(num_features):
        featureList.append(featureNames[indices[f]])
        print("%d. feature %s (%.2f)" % (f, featureNames[indices[f]], coeff[indices[f]]))
    fig = pl.figure(figsize=(8,6),dpi=150)
    pl.title("Feature importances",fontsize=30)
    # pl.bar(range(num_features), coeff[indices],
    #         yerr = std_importance[indices], color=paired[0], align="center",
    #         edgecolor=paired[0],ecolor=paired[1])
    pl.bar(range(num_features), coeff[indices], color=paired[0], align="center",
            edgecolor=paired[0],ecolor=paired[1])
    pl.xticks(range(num_features), featureList, size=15,rotation=90)
    pl.ylabel("Importance",size=30)
    pl.yticks(size=20)
    pl.xlim([-1, num_features])
    # fix_axes()
    pl.tight_layout()
    save_path = 'plots/'+obj+'/'+whichReg+'_feature_importances.pdf'
    fig.savefig(save_path)
コード例 #7
0
ファイル: omnibem.py プロジェクト: CancerRxGene/gdsctools
    def plot_number_alteration_by_tissue(self, fontsize=10, width=0.9):
        """Plot number of alterations

        .. plot::
            :width: 100%
            :include-source:

            from gdsctools import *
            data = gdsctools_data("test_omnibem_genomic_alterations.csv.gz")
            bem = OmniBEMBuilder(data)
            bem.filter_by_gene_list(gdsctools_data("test_omnibem_genes.txt"))
            bem.plot_number_alteration_by_tissue()

        """
        count = self.unified.groupby(['TISSUE_TYPE'])['GENE'].count()
        try:
            count.sort_values(inplace=True, ascending=False)
        except:
            count.sort(inplace=True, ascending=False)
        count.plot(kind="bar", width=width)
        pylab.grid()
        pylab.xlabel("Tissue Type", fontsize=fontsize)
        pylab.ylabel("Total number of alterations in cell lines",
                     fontsize=fontsize)
        try:pylab.tight_layout()
        except:pass
コード例 #8
0
def plotGaussian(X, y, obj, featureNames):
	"""Plot Gausian fit on top of X.
	"""
	save_path = '../MSPrediction-Python/plots/'+obj+'/'+'BayesGaussian2'
	clf = classifiers["BayesGaussian2"]
	clf,_,_ = fitAlgo(clf, X,y, opt= True, param_dict = param_dist_dict["BayesGaussian2"])
	unique_y = np.unique(y)
	theta = clf.theta_
	sigma = clf.sigma_
	class_prior = clf.class_prior_
	norm_func = lambda x, sigma, theta: 1 if np.isnan(x) else -0.5 * np.log(2 * np.pi*sigma) - 0.5 * ((x - theta)**2/sigma) 
	norm_func = np.vectorize(norm_func)
	n_samples = X.shape[0]
	for j in range(X.shape[1]):
		fcol = X[:,j]
		jfeature = featureNames[j]
		jpath = save_path +'_'+jfeature+'.pdf'
		fig = pl.figure(figsize=(8,6),dpi=150)
		for i, y_i in enumerate(unique_y):
			fcoli = fcol[y == y_i]
			itfreq = itemfreq(fcoli)
			uniqueVars = itfreq[:,0]
			freq = itfreq[:,1]
			freq = freq/sum(freq)
			the = theta[i, j]
			sig = sigma[i,j]
			pred = np.exp(norm_func(uniqueVars, sig, the))
			pl.plot(uniqueVars, pred, label= str(y_i)+'_model')
			pl.plot(uniqueVars, freq, label= str(y_i) +'_true')
		pl.xlabel(jfeature)
		pl.ylabel("density")
		pl.legend(loc='best')
		pl.tight_layout()
		# pl.show()
		fig.savefig(jpath)
コード例 #9
0
def plotMixNB(X, y, obj, featureNames, whichMix):
	"""Plot MixNB fit on top of X.
	"""
	save_path = '../MSPrediction-Python/plots/'+obj+'/'+whichMix
	clf = classifiers[whichMix]
	clf,_,_ = fitAlgo(clf, X,y, opt= True, param_dict = param_dist_dict[whichMix])
	unique_y = np.unique(y)
	# norm_func = lambda x, sigma, theta: 1 if np.isnan(x) else -0.5 * np.log(2 * np.pi*sigma) - 0.5 * ((x - theta)**2/sigma) 
	# norm_func = np.vectorize(norm_func)
	n_samples = X.shape[0]
	for j in range(X.shape[1]):
		fcol = X[:,j]
		optmodel = clf.optmodels[:,j]
		distname = clf.distnames[j]
		jfeature = featureNames[j]
		jpath = save_path +'_'+jfeature+'.pdf'
		fig = pl.figure(figsize=(8,6),dpi=150)
		for i, y_i in enumerate(unique_y):
			fcoli = fcol[y == y_i]
			itfreq = itemfreq(fcoli)
			uniqueVars = itfreq[:,0]
			freq = itfreq[:,1]
			freq = freq/sum(freq)
			pred = np.exp(optmodel[i](uniqueVars))
			# print pred
			# print pred
			pl.plot(uniqueVars, pred, label= str(y_i)+'_model')
			pl.plot(uniqueVars, freq, label= str(y_i) +'_true')
		pl.xlabel(jfeature)
		pl.ylabel("density")
		pl.title(distname)
		pl.legend(loc='best')
		pl.tight_layout()
		# pl.show()
		fig.savefig(jpath)
コード例 #10
0
def plot_importances(imp, clfName, obj):
    imp=np.vstack(imp)
    print imp
    mean_importance = np.mean(imp,axis=0)
    std_importance = np.std(imp,axis=0)
    indices = np.argsort(mean_importance)[::-1]
    print indices
    print featureNames
    featureList = []
    # num_features = len(featureNames)
    print("Feature ranking:")
    for f in range(num_features):
        featureList.append(featureNames[indices[f]])
        print("%d. feature %s (%.2f)" % (f, featureNames[indices[f]], mean_importance[indices[f]]))
    fig = pl.figure(figsize=(8,6),dpi=150)
    pl.title("Feature importances",fontsize=30)
    pl.bar(range(num_features), mean_importance[indices],
            yerr = std_importance[indices], color=paired[0], align="center",
            edgecolor=paired[0],ecolor=paired[1])
    pl.xticks(range(num_features), featureList, size=15,rotation=90)
    pl.ylabel("Importance",size=30)
    pl.yticks(size=20)
    pl.xlim([-1, num_features])
    # fix_axes()
    pl.tight_layout()
    save_path = 'plots/'+obj+'/'+clfName+'_feature_importances.pdf'
    fig.savefig(save_path)
コード例 #11
0
def param_sweeping(clf, obj, X, y, param_dist, metric, param, clfName):
	'''Plot a parameter sweeping (ps) curve with the param_dist as a axis, and the scoring based on metric as y axis.
	Keyword arguments:
	clf - - classifier
	X - - feature matrix
	y - - target array
	param - - a parameter of the classifier
	param_dist - - the parameter distribution of param
	clfName - - the name of the classifier
	metric - - the metric we use to evaluate the performance of the classifiers
	obj - - the name of the dataset we are using'''
	scores = []
	for i in param_dist:
		y_true = []
		y_pred = []
		# new classifer each iteration
		newclf = eval("clf.set_params("+ param + "= i)")
		y_pred, y_true, gs_score_list, amp = testAlgo(newclf, X, y, clfName)
		mean_fpr, mean_tpr, mean_auc = plot_unit_prep(y_pred, y_true, metric)
		scores.append(mean_auc)
		print("Area under the ROC curve : %f" % mean_auc)
	fig = pl.figure(figsize=(8,6),dpi=150)
	paramdist_len = len(param_dist)
	pl.plot(range(paramdist_len), scores, label = 'Parameter Sweeping Curve')
	pl.xticks(range(paramdist_len), param_dist, size = 15, rotation = 45)
	pl.xlabel(param.upper(),fontsize=30)
	pl.ylabel(metric.upper(),fontsize=30)
	pl.title('Parameter Sweeping Curve',fontsize=25)
	pl.legend(loc='lower right')
	pl.tight_layout()
	fig.savefig('plots/'+obj+'/'+ clfName +'_' + param +'_'+'ps.pdf')
	pl.show()
コード例 #12
0
ファイル: plotting.py プロジェクト: mattbierbaum/plinko
def plot_file_color(base, thin=True, start=0, size=14, save=False):
    conf, track, pegs = load(base)

    fig = pl.figure(figsize=(size,size*conf['top']/conf['wall']))

    track = track[start:]
    x = track[:,0];   y = track[:,1]
    t = np.linspace(0,1,x.shape[0])
    points = np.array([x,y]).transpose().reshape(-1,1,2)
    segs = np.concatenate([points[:-1],points[1:]],axis=1)
    lc = LineCollection(segs, linewidths=0.25, cmap=pl.cm.coolwarm)
    lc.set_array(t)
    pl.gca().add_collection(lc)

    #pl.scatter(x, y, c=np.arange(len(x)),linestyle='-',cmap=pl.cm.coolwarm)
    #pl.plot(track[-1000000:,0], track[-1000000:,1], '-', linewidth=0.0125, alpha=0.8)
    for peg in pegs:
        pl.gca().add_artist(pl.Circle(peg, conf['radius'], color='k', alpha=0.3))
    pl.xlim(0, conf['wall'])
    pl.ylim(0, conf['top'])
    pl.xticks([])
    pl.yticks([])
    pl.tight_layout()
    pl.show()
    if save:
        pl.savefig(base+".png", dpi=200)
コード例 #13
0
ファイル: plotting.py プロジェクト: mattbierbaum/plinko
def tracks_movie(base, skip=1, frames=500, size=10):
    """
    A movie of each particle as a point
    """
    conf, track, pegs = load(base)

    fig = pl.figure(figsize=(size,size*conf['top']/conf['wall']))
    plot = None

    for t in xrange(1,max(frames, track.shape[1]/skip)):
        tmp = track[:,t*skip,:]
        if not ((tmp[:,0] > 0) & (tmp[:,1] > 0) & (tmp[:,0] < conf['wall']) & (tmp[:,1] < conf['top'])).any():
            continue

        if plot is None:
            plot = pl.plot(tmp[:,0], tmp[:,1], 'k,', alpha=1.0, ms=0.1)[0]
            pl.xticks([])
            pl.yticks([])
            pl.xlim(0,conf['wall'])
            pl.ylim(0,conf['top'])
            pl.tight_layout()
        else:
            plot.set_xdata(tmp[:,0])
            plot.set_ydata(tmp[:,1])
        pl.draw()
        pl.savefig(base+'-movie-%05d.png' % (t-1))
コード例 #14
0
ファイル: 09-pca.py プロジェクト: jiamaozheng/StanfordSGTC
def pca(inF,MIN):
    df = pd.read_table(inF, header=0)
    dc = list(df.columns)
    dc[0]='GeneID'
    df.columns = dc
    
    print(df.shape)
    sel = ~((df.ix[:,2] < MIN) & (df.ix[:,3]< MIN) & (df.ix[:,4]< MIN) & (df.ix[:,5]< MIN) & (df.ix[:,6]< MIN) & (df.ix[:,7]< MIN) & (df.ix[:,8]< MIN) & (df.ix[:,9]< MIN))
    df = df.ix[sel,:]
    print(df.shape)
    
    X = df.ix[:,2:df.shape[1]].values.T
    y = df.columns[2:df.shape[1]].values
    X_std = StandardScaler().fit_transform(X)
    
    #pca = PCA(n_components=2)
    pca = PCA()
    Y_sklearn = pca.fit_transform(X_std)
    
    
    fig = plt.figure()
    plt.style.use('ggplot')
    #plt.style.use('seaborn-whitegrid')
    ax = fig.add_subplot(111)
    for lab, col in zip(y,('red','red', 'green','green', 'blue','blue','m','m')):
        ax.scatter(Y_sklearn[y==lab, 0],Y_sklearn[y==lab, 1],label=lab,c=col, s=80)
    
    
    ax.set_xlabel('Principal Component 1 : %.2f'%(pca.explained_variance_ratio_[0]*100) + '%')
    ax.set_ylabel('Principal Component 2 : %.2f'%(pca.explained_variance_ratio_[1]*100) + '%')
    ax.legend(loc='lower right', prop={'size':8})
    plt.tight_layout()
    plt.savefig(inF + '-RNASeq-MIN' + str(MIN) + '.pdf')
コード例 #15
0
ファイル: 09-pca.py プロジェクト: jiamaozheng/StanfordSGTC
def pca(inF,MIN):
    df = pd.read_table(inF, header=0)
    dc = list(df.columns)
    dc[0]='GeneID'
    df.columns = dc
    
    print(df.shape)
    sel = True 
    for i in range(4, df.shape[1]-1):
        sel = (df.ix[:,i] < MIN) & (df.ix[:,i+1]< MIN)
    df = df.ix[~sel,:]
    print(df.shape)
    
    X = df.ix[:,4:df.shape[1]].values.T
    y = df.columns[4:df.shape[1]].values
    X_std = StandardScaler().fit_transform(X)
    
    #pca = PCA(n_components=2)
    pca = PCA()
    Y_sklearn = pca.fit_transform(X_std)
    
    
    fig = plt.figure()
    plt.style.use('ggplot')
    #plt.style.use('seaborn-whitegrid')
    ax = fig.add_subplot(111)
    for lab, col in zip(y,['r','g','b','c'] + sns.color_palette("cubehelix", df.shape[1]-4-4)):
        ax.scatter(Y_sklearn[y==lab, 0],Y_sklearn[y==lab, 1],label=lab,c=col, s=80)
    
    
    ax.set_xlabel('Principal Component 1 : %.2f'%(pca.explained_variance_ratio_[0]*100) + '%')
    ax.set_ylabel('Principal Component 2 : %.2f'%(pca.explained_variance_ratio_[1]*100) + '%')
    ax.legend(loc='upper right', prop={'size':8})
    plt.tight_layout()
    plt.savefig(inF + '-MIN' + str(MIN) + '.pdf')
コード例 #16
0
ファイル: T_res_BNL.py プロジェクト: mmmerlin/my_code
def ShowRawToF():
    raw_codes = GetTimecodes_AllFilesInDir(timepix_path_1, xmin, xmax, ymin, ymax, 0, checkerboard_phase = None)
    offset = 0
    tmin = 0
    tmax = 11810

    fig = pl.figure(figsize=(14,10))
    n_codes, bins, patches = pl.hist([11810-i for i in raw_codes], bins = 11810, range = [0,11810])
    pl.yscale('log', nonposy='clip')


    for i,code in enumerate(raw_codes):
        raw_codes[i] = (11810. - code) - offset
        raw_codes[i] *= 20

    fig = pl.figure(figsize=(14,10))
    n_codes, bins, patches = pl.hist(raw_codes, bins = 1000, range = [0,40000])
    
#     n_codes, bins, patches = pl.hist(raw_codes, bins = tmax-tmin, range = [tmin,tmax])

#     pl.clf()
#     n_codes = n_codes[:-1] 
#     pl.plot(bins, n_codes, 'k-.o', label="Timecodes")
    
    pl.tight_layout()
    
    pl.show()
コード例 #17
0
ファイル: compute_hg.py プロジェクト: jonsafari/spectral-scfg
def printHeatMap(marginals, words, outFile):
    N = len(words)
    words_uni = [i.decode('UTF-8') for i in words]
    heatmap = np.zeros((N+1, N+1))
    for chart in marginals:
        heatmap[chart[0], chart[1]] = math.log(marginals[chart])
    fig, ax = plt.subplots()    
    mask = np.tri(heatmap.shape[0], k=0)
    heatmap = np.ma.array(heatmap, mask=mask)
    cmap = plt.cm.get_cmap('RdBu')
    cmap.set_bad('w')
    im = ax.pcolor(heatmap, cmap=cmap, alpha=0.8)
    font = mpl.font_manager.FontProperties(fname='/usr0/home/avneesh/spectral-scfg/data/wqy-microhei.ttf')
    ax.grid(True)
    ax.set_ylim([0,N])
    ax.invert_yaxis()
    ax.set_yticks(np.arange(heatmap.shape[1]-1)+0.5, minor=False)
    ax.set_yticklabels(words_uni, minor=False, fontproperties=font)
    ax.set_xticks(np.arange(heatmap.shape[0])+0.5, minor=True)
    ax.set_xticklabels(np.arange(heatmap.shape[0]), minor=True)
    ax.set_xticks([])
    cbar = fig.colorbar(im, use_gridspec=True)
    cbar.set_label('ln(sum)')
    ax.set_xlabel('Span End')
    ax.xaxis.set_label_position('top')
    ax.xaxis.tick_top()
    plt.ylabel('Span starting at word: ')
    plt.tight_layout()
    #ax.set_title('CKY Heat Map: Node Marginals')
    fig.savefig(outFile)    
コード例 #18
0
ファイル: plot.py プロジェクト: pabloriera/pymam
def multiplot(x,y,row=True):
    
    Nsp = len(y.keys())
    
    if len(x.keys())==1:
        xk = x.keys()[0]
        
        for i,yk in enumerate(y.iterkeys()):
            if row:
                pl.subplot(Nsp,1,i+1)
            else:
                pl.subplot(1,Nsp,i+1)
    
            pl.plot(x[xk],y[yk],label=yk)
            pl.xlabel(xk)
            pl.ylabel(yk)
        

    else:
    
        for i,(xk,yk) in enumerate(zip(x.iterkeys(),y.iterkeys())):
            if row:
                pl.subplot(Nsp,1,i+1)
            else:
                pl.subplot(1,Nsp,i+1)
    
            pl.plot(x[xk],y[yk],label=yk)
            pl.xlabel(xk)
            pl.ylabel(yk)           

    pl.tight_layout()  
コード例 #19
0
ファイル: LD.py プロジェクト: airanmehr/bio
def plotScalingFactor():
    r=2*1e-8
    l = 5e4
    dpi = 300
    j = 0
    for nu0 in [0.005, 0.1]:
        for s in [0.025, 0.1]:
            t = np.arange(0, 2 * (utl.logit(0.995) - utl.logit(nu0)) / s + 1., 1)
            fig, ax = plt.subplots(2, 1, figsize=(5.5, 2.5), dpi=dpi, sharex=True);
            nu(t, s=s, nu0=nu0).plot(color='k', legend=False, ax=ax[0])
            pplt.annotate(r'$s$={}, $\nu_0=${} ({} Sweep)'.format(s, nu0, ('Soft', 'Hard')[nu0 == 0.005]), fontsize=7,
                          ax=ax[0])
            pplt.setSize(ax=ax[0], fontsize=6)
            ax[0].set_ylabel(r'$\nu_t$')
            #
            H0 = H(t[0], s=s, nu0=nu0)
            Ht = H(t, s=s, nu0=nu0)
            df = pd.DataFrame([np.log(Ht / H0), -2 * r * t * l], columns=t, index=['log(Growth)', r'log(Decay)']).T
            df['log(Growth) + log(Decay)'] = df.sum(1)
            df.plot(ax=ax[1], grid=True, linewidth=2);
            ax[1].set_xlabel('Generations');
            ax[1].set_ylabel('Log(Scaling Factor)')
            ax[1].axvline(df.iloc[1:, 2].abs().idxmin(), color='k', linestyle='--', linewidth=0.5)
            # if j != 3:
            #     ax[1].legend_.remove()
            # else:
            ax[1].legend(['log(Growth)', r'log(Decay)', 'log(Growth) + log(Decay)'], bbox_to_anchor=(1.45, .75),
                         prop={'size': 6})
            pplt.setSize(ax[1], fontsize=6)

            plt.tight_layout(pad=0.1, rect=[0, 0, 0.7, 1])
            plt.gcf().subplots_adjust(bottom=0.15)
            pplt.savefig('decayFactors{}'.format(j), dpi=dpi)
            j += 1
コード例 #20
0
ファイル: rpkmZ.py プロジェクト: TorHou/gscripts
    def plot(self):
        f = pylab.figure(figsize=(8,4))
        co = [] #colors container
        for zScore, r in itertools.izip(self.zScores, self.log2Ratio):
            if zScore < self.pCut:
                if r > 0:
                    co.append(Colors().greenColor)
                elif r < 0:
                    co.append(Colors().redColor)
                else:
                    raise Exception
            else:
                co.append(Colors().blueColor)

        #print "Probability this is from a normal distribution: %.3e" %stats.normaltest(self.log2Ratio)[1]
        ax = f.add_subplot(121)
        pylab.axvline(self.meanLog2Ratio, color=Colors().redColor)
        pylab.axvspan(self.meanLog2Ratio-(2*self.stdLog2Ratio), 
                      self.meanLog2Ratio+(2*self.stdLog2Ratio), color=Colors().blueColor, alpha=0.2)
        his = pylab.hist(self.log2Ratio, bins=50, color=Colors().blueColor)
        pylab.xlabel("log2 Ratio %s/%s" %(self.sampleNames[1], self.sampleNames[0]))
        pylab.ylabel("Frequency")
        
        ax = f.add_subplot(122, aspect='equal')
        pylab.scatter(self.genes1, self.genes2, c=co, alpha=0.5)        
        pylab.ylabel("%s RPKM" %self.sampleNames[1])
        pylab.xlabel("%s RPKM" %self.sampleNames[0])
        pylab.yscale('log')
        pylab.xscale('log')
        pylab.tight_layout()
コード例 #21
0
ファイル: make-synth.py プロジェクト: estebanhurtado/cutedots
def synthesize(t1, t2, sig=1, length=800):
    td = trajdata.TrajData()
    td.trajs.append( synthTraj('UBL1', length, t1, 1) )
    td.trajs.append( synthTraj('UBL2', length, t2, sig) )
    td.filename = 'test.qtd'
    dio.trajDataSaveH5(td)
    curves = xcorr.corrFile('test.qtd', ['UB'], [1.0, 1.0, 1.0], 100)

    x1 = np.array(td.trajs[0].pointData)[:,0]
    x2 = np.array(td.trajs[1].pointData)[:,0]
    pl.figure(figsize=(5,6))
    pl.subplot(3,1,1)
    pl.plot(x1, 'r', linewidth=2)
    pl.ylim(np.min(x1) - np.max(x1)*0.1, np.max(x1) * 1.1)
    pl.ylabel("position of\nparticipant A (mm)")
    pl.xlabel("time (msec)")
    pl.subplot(3,1,2)
    pl.plot(x2, 'b', linewidth=2)
    if sig == 1:
        pl.ylim(np.min(x2) - np.max(x2)*0.1, np.max(x2) * 1.1)
    else:
        pl.ylim(np.min(x2)*1.1, np.max(x2) - np.min(x2)*0.1)
    pl.ylabel("position of\nparticipant B (mm)")
    pl.xlabel("time (msec)")
    pl.subplot(3,1,3)
    curves.plot(10)
    if sig == 1:
        pl.ylim(-0.6, 1.2)
    else:
        pl.ylim(-1.2, 0.6)
    pl.ylabel("cross-correlation\nof speed")
    pl.xlabel("delay (msec)")
    pl.xlim(-200, 200)
    pl.tight_layout()
コード例 #22
0
ファイル: t_tau_func.py プロジェクト: rjsmethurst/bayesian
def walker_steps(samples, nwalkers, limit):
    ur = N.load('/Users/becky/Projects/Green-Valley-Project/bayesian/find_t_tau_old/colour_plot/ur.npy')
    nuv = N.load('/Users/becky/Projects/Green-Valley-Project/bayesian/find_t_tau_old/colour_plot/nuvu.npy')
    s = samples.reshape(nwalkers, -1, 4)
    s = s[:,:limit,:]
    fig = P.figure(figsize=(9,9))
    ax1 = P.subplot(221, autoscale_on = False, aspect='auto', xlim=[0,13.8], ylim=[0,3])
    ax2 = P.subplot(222,  autoscale_on = False, aspect='auto', xlim=[0,13.8], ylim=[0,3])
    ax3 = P.subplot(223,  autoscale_on = False, aspect='auto', xlim=[0,13.8], ylim=[0,3])
    ax4 = P.subplot(224,  autoscale_on = False, aspect='auto', xlim=[0,13.8], ylim=[0,3])
    ax1.imshow(ur, origin='lower', aspect='auto', extent=[0, 13.8, 0, 3])
    ax2.imshow(ur, origin='lower', aspect='auto', extent=[0, 13.8, 0, 3])
    ax3.imshow(nuv, origin='lower', aspect='auto', extent=[0, 13.8, 0, 3])
    ax4.imshow(nuv, origin='lower', aspect='auto', extent=[0, 13.8, 0, 3])
    for n in range(len(s)):
        ax1.plot(s[n,:,0], s[n,:,1], 'k', alpha=0.5)
        ax2.plot(s[n,:,2], s[n,:,3], 'k', alpha=0.5)
        ax3.plot(s[n,:,0], s[n,:,1], 'k', alpha=0.5)
        ax4.plot(s[n,:,2], s[n,:,3], 'k', alpha=0.5)
    ax1.set_xlabel(r'$t_{bar}$')
    ax1.set_ylabel(r'$\tau_{bar}$')
    ax2.set_xlabel(r'$t_{no bar}$')
    ax2.set_ylabel(r'$\tau_{no bar}$')
    ax3.set_xlabel(r'$t_{bar}$')
    ax3.set_ylabel(r'$\tau_{bar}$')
    ax4.set_xlabel(r'$t_{no bar}$')
    ax4.set_ylabel(r'$\tau_{no bar}$')
    P.tight_layout()
    save_fig = '/Users/becky/Projects/Green-Valley-Project/bayesian/find_t_tau/bars/walkers_2d_steps_bars_'+str(nwalkers)+'_'+str(time.strftime('%H_%M_%d_%m_%y'))+'.pdf'
    fig.savefig(save_fig)
    return fig
コード例 #23
0
ファイル: F2d_F2.py プロジェクト: Jeff182/CJ
  def make_plotII(self):
    # retrieve data
    D=self.D

    kmap={}
    kmap['Q2 = 2']   = {'c':'r','ls':'-'}
    kmap['Q2 = 5']   = {'c':'g','ls':'--'}
    kmap['Q2 = 10']  = {'c':'b','ls':'-.'}
    kmap['Q2 = 100'] = {'c':'k','ls':':'}


    ax=py.subplot(111)
    DF=D['AV18']
    for Q2 in [2,5,10,100]:
      k='Q2 = %d'%Q2
      Q2=float(k.split('=')[1])
      DF=D['AV18'][D['AV18'].Q2==Q2]
      cls=kmap[k]['c']+kmap[k]['ls']
      ax.plot(DF.X,DF.THEORY,cls,lw=2.0,label=r'$Q^2=%0.0f~{\rm GeV}^2$'%Q2)

    ax.set_xlabel('$x$',size=25)
    ax.set_ylabel(r'$F_2^d\, /\, F_2^N$',size=25)
    ax.set_ylim(0.97,1.08)
    ax.axhline(1,color='k',ls='-',alpha=0.2)

    ax.legend(frameon=0,loc=2,fontsize=22)
    py.tick_params(axis='both',labelsize=22)
    py.tight_layout()
    py.savefig('gallery/F2d_F2_II.pdf')
コード例 #24
0
def runSimulation1(numSteps):
    """
    Runs the simulation for `numSteps` time steps.

    Returns a tuple of two lists: (rabbit_populations, fox_populations)
      where rabbit_populations is a record of the rabbit population at the
      END of each time step, and fox_populations is a record of the fox population
      at the END of each time step.

    Both lists should be `numSteps` items long.
    """

    rabbit_sim = []
    fox_sim = []
    for step in range(numSteps):
        rabbitGrowth()
        rabbit_sim.append(CURRENTRABBITPOP)
        foxGrowth()
        fox_sim.append(CURRENTFOXPOP)
    #print "CURRENTRABBITPOP", CURRENTRABBITPOP
    #print "CURRENTFOXPOP", CURRENTFOXPOP
    pylab.plot(range(numSteps), rabbit_sim, '-g', label='Rabbit population')
    pylab.plot(range(numSteps), fox_sim, '-o', label='Fox population')
    pylab.title('Fox and rabbit population in the wood')
    xlabel = "Plot for simulation of {} steps".format(numSteps)
    pylab.xlabel(xlabel)
    pylab.ylabel('Current fox and rabbit population')
    pylab.legend(loc='upper right')
    pylab.tight_layout()
    pylab.show()
    pylab.clf()
コード例 #25
0
ファイル: F2d_F2.py プロジェクト: Jeff182/CJ
  def make_plotI(self):
    # retrieve data
    D=self.D

    kmap={}
    kmap['AV18']   = {'c':'r','ls':'-'}
    kmap['CDBONN'] = {'c':'g','ls':'--'}
    kmap['WJC1']   = {'c':'k','ls':'-.'}
    kmap['WJC2']   = {'c':'b','ls':':'}

    ax=py.subplot(111)
    for k in ['AV18','CDBONN','WJC1','WJC2']:
      DF=D[k]
      DF=DF[DF.Q2==10]
      if k=='CDBONN':
        label='CDBonn'
      else:
        label=k
      cls=kmap[k]['c']+kmap[k]['ls']
      ax.plot(DF.X,DF.THEORY,cls,lw=2.0,label=tex(label))

    ax.set_xlabel('$x$',size=25)
    ax.set_ylabel(r'$F_2^d\, /\, F_2^N$',size=25)
    ax.set_ylim(0.97,1.08)
    ax.axhline(1,color='k',ls='-',alpha=0.2)

    ax.legend(frameon=0,loc=2,fontsize=22)
    py.tick_params(axis='both',labelsize=22)
    py.tight_layout()
    py.savefig('gallery/F2d_F2_I.pdf')
    py.close()
コード例 #26
0
ファイル: plot_temperature.py プロジェクト: ajmendez/templog
def plot_temp():
    data = read_temps()
    dates, values = map(np.array, zip(*[(d['date'], d['temperature'])
                                        for d in data]))
    tmp = (date2num(dates) % 1.0)*24.0
    ii = np.where((tmp > 0) & (tmp < 8))[0]
    continuum = get_continuum(dates, dates[ii], values[ii])
    
    
    setup(figsize=(12,6))
    
    setupplot(subplt=(1,2,1), autoticks=True, xlabel='Date',)
    pylab.plot(dates, values)
    pylab.plot(dates[ii], values[ii], '.r')
    pylab.plot(dates, continuum, '.k')
    plot_weather(np.min(date2num(dates)))
    # pylab.plot(dates, values-continuum+38, '.r')
    dateticks('%Y.%m.%d')
    
    
    setupplot(subplt=(2,2,2), autoticks=False, xlabel='Hour of Day')
    pylab.plot(tmp, values, '.')
    setupplot(subplt=(2,2,2), ylabel='', secondax=True)
    
    setupplot(subplt=(2,2,4), autoticks=False, xlabel='Hour of Day')
    sc = pylab.scatter(tmp, values-continuum+TNORM, 
                       c=date2num(dates)-np.min(date2num(dates)), s=15,
                       marker='.', edgecolor='none',
                       label='Days since Start')
    
    setupplot(subplt=(2,2,4), ylabel='', secondax=True)
    hcolorbar(sc, axes=[0.75, 0.42, 0.1, 0.01])
    
    pylab.tight_layout()
    pylab.show()
コード例 #27
0
ファイル: performance.py プロジェクト: FAIMS/DataGenerator
def createMP4(text, filename, thumbnail, faimsSync):
	fig = pylab.plt.figure()
	fig.suptitle(text)
	ax = fig.add_subplot(111)
	ax.set_aspect('equal')
	ax.get_xaxis().set_visible(False)
	ax.get_yaxis().set_visible(False)

	im = ax.imshow(numpy.random.rand(300,300),cmap='gray',interpolation='nearest')
	im.set_clim([0,1])
	fig.set_size_inches([3,3])


	pylab.tight_layout()
	if faimsSync:
		path = 'files/app/'
	else:
		path = 'files/server/'

	def update_img(n):    	
		tmp = numpy.random.rand(300,300)
		im.set_data(tmp)
		return im

	#legend(loc=0)
	photoUuid = uuid4()		
	if thumbnail:
		fig.savefig("%s%s_%s.thumbnail.jpg" % (path,photoUuid,filename))
	ani = animation.FuncAnimation(fig,update_img,20,interval=3)
	writer = animation.writers['ffmpeg'](fps=3)

	ani.save('%s%s_%s.mp4' % (path,photoUuid,filename),writer=writer,dpi=dpi)
	pylab.plt.close()
	return "%s%s_%s.mp4" % (path,photoUuid,filename)
コード例 #28
0
     def run(self):
         plts = {}
         graphs = {}
         pos  = 0

         plt.ion()
         plt.style.use('ggplot')

         for name in sorted(self.names.values()):
             p = plt.subplot(math.ceil(len(self.names) / 2), 2, pos+1)
             p.set_ylim([0, 100])
             p.set_title(self.machine_classes[name] + " " + name)

             p.get_xaxis().set_visible(False)

             X = range(0, NUM_ENTRIES, 1)
             Y = NUM_ENTRIES * [0]
             graphs[name] = p.plot(X, Y)[0]

             plts[name] = p
             pos += 1 

         plt.tight_layout()
         
         while True:
             for name, p in plts.items():
                 graphs[name].set_ydata(self.loads[name])

             plt.draw()
             plt.pause(0.05)
コード例 #29
0
ファイル: graph_time.py プロジェクト: avlonger/my-experiments
def set_font(font):
    pl.xlabel('String length', fontproperties=font)
    pl.tight_layout()
    for label in pl.axes().get_xticklabels():
        label.set_fontproperties(font)
    for label in pl.axes().get_yticklabels():
        label.set_fontproperties(font)
コード例 #30
0
ファイル: t_tau_func.py プロジェクト: rjsmethurst/bayesian
def corner_plot(s, labels):
    x, y = s[:,0], s[:,1]
    fig = P.figure(figsize=(10,10))
    ax2 = P.subplot(223)
    ax2.set_xlabel(labels[0])
    ax2.set_ylabel(labels[1])
    im = triangle.histo2d(x, y, ax=ax2, extent=[[0, 13.807108309208775],[0, 3.0]])
    [l.set_rotation(45) for l in ax2.get_xticklabels()]
    [j.set_rotation(45) for j in ax2.get_yticklabels()]
    ax1 = P.subplot(221, xlim=[0, 13.807108309208775])
    ax1.tick_params(axis='x', labelbottom='off')
    ax1.tick_params(axis='y', labelleft='off')
    ax1.hist(x, bins=50, histtype='step', color='k', range=(0, 13.807108309208775))
    ax3 = P.subplot(224)
    ax3.tick_params(axis='x', labelbottom='off')
    ax3.tick_params(axis='y', labelleft='off')
    ax3.hist(y, bins=50, orientation='horizontal', histtype='step',color='k', range=(0,3))
    P.subplots_adjust(wspace=0.05)
    P.subplots_adjust(hspace=0.05)
    cbar_ax = fig.add_axes([0.55, 0.565, 0.02, 0.405])
    cb = fig.colorbar(im, cax = cbar_ax)
    cb.solids.set_edgecolor('face')
    cb.set_label(r'predicted SFR $[M_{\odot} yr^{-1}]$', labelpad = 20, fontsize=16)
    P.tight_layout()
    return fig
コード例 #31
0
def plot_3_targs():

    #name three objects
    targNames = ['ob140613', 'ob150211', 'ob150029']

    #object alignment directories
    an_dirs = [
        '/g/lu/microlens/cross_epoch/OB140613/a_2018_09_24/prop/',
        '/g/lu/microlens/cross_epoch/OB150211/a_2018_09_19/prop/',
        '/g/lu/microlens/cross_epoch/OB150029/a_2018_09_24/prop/'
    ]
    align_dirs = ['align/align_t', 'align/align_t', 'align/align_t']
    points_dirs = ['points_a/', 'points_d/', 'points_d/']
    poly_dirs = ['polyfit_a/fit', 'polyfit_d/fit', 'polyfit_d/fit']

    xlim = [1.2, 2.0, 1.5]
    ylim = [1.0, 7.0, 1.5]

    #Output file
    #filename = '/Users/jlu/doc/proposals/keck/uc/19A/plot_3_targs.png'
    filename = '/Users/jlu/plot_3_targs.png'
    #figsize = (15, 4.5)
    figsize = (10, 4.5)

    ps = 9.92

    plt.close(1)
    plt.figure(1, figsize=figsize)

    Ntarg = len(targNames) - 1
    for i in range(Ntarg):
        rootDir = an_dirs[i]
        starName = targNames[i]
        align = align_dirs[i]
        poly = poly_dirs[i]
        point = points_dirs[i]

        s = starset.StarSet(rootDir + align)
        s.loadPolyfit(rootDir + poly, accel=0, arcsec=0)

        names = s.getArray('name')
        mag = s.getArray('mag')
        x = s.getArray('x')
        y = s.getArray('y')

        ii = names.index(starName)
        star = s.stars[ii]

        pointsTab = Table.read(rootDir + point + starName + '.points',
                               format='ascii')

        time = pointsTab[pointsTab.colnames[0]]
        x = pointsTab[pointsTab.colnames[1]]
        y = pointsTab[pointsTab.colnames[2]]
        xerr = pointsTab[pointsTab.colnames[3]]
        yerr = pointsTab[pointsTab.colnames[4]]

        if i == 0:
            print('Doing MJD')
            idx_2015 = np.where(time <= 57387)
            idx_2016 = np.where((time > 57387) & (time <= 57753))
            idx_2017 = np.where((time > 57753) & (time <= 58118))
            idx_2018 = np.where((time > 58119) & (time <= 58484))
        else:
            idx_2015 = np.where(time < 2016)
            idx_2016 = np.where((time >= 2016) & (time < 2017))
            idx_2017 = np.where((time >= 2017) & (time < 2018))
            idx_2018 = np.where((time >= 2018) & (time < 2019))

        fitx = star.fitXv
        fity = star.fitYv
        dt = time - fitx.t0
        fitLineX = fitx.p + (fitx.v * dt)
        fitSigX = np.sqrt(fitx.perr**2 + (dt * fitx.verr)**2)

        fitLineY = fity.p + (fity.v * dt)
        fitSigY = np.sqrt(fity.perr**2 + (dt * fity.verr)**2)

        from matplotlib.ticker import FormatStrFormatter
        fmtX = FormatStrFormatter('%5i')
        fmtY = FormatStrFormatter('%6.2f')
        fontsize1 = 16

        # Convert everything into relative coordinates:
        x -= fitx.p
        y -= fity.p
        fitLineX -= fitx.p
        fitLineY -= fity.p

        # Change plate scale.
        x = x * ps * -1.0
        y = y * ps
        xerr *= ps
        yerr *= ps
        fitLineX = fitLineX * ps * -1.0
        fitLineY = fitLineY * ps
        fitSigX *= ps
        fitSigY *= ps

        paxes = plt.subplot(1, Ntarg, i + 1)
        plt.errorbar(x[idx_2015],
                     y[idx_2015],
                     xerr=xerr[idx_2015],
                     yerr=yerr[idx_2015],
                     fmt='r.',
                     label='2015')
        plt.errorbar(x[idx_2016],
                     y[idx_2016],
                     xerr=xerr[idx_2016],
                     yerr=yerr[idx_2016],
                     fmt='g.',
                     label='2016')
        plt.errorbar(x[idx_2017],
                     y[idx_2017],
                     xerr=xerr[idx_2017],
                     yerr=yerr[idx_2017],
                     fmt='b.',
                     label='2017')
        plt.errorbar(x[idx_2018],
                     y[idx_2018],
                     xerr=xerr[idx_2018],
                     yerr=yerr[idx_2018],
                     fmt='c.',
                     label='2018')

        # if i==1:
        #     plt.yticks(np.arange(np.min(y-yerr-0.1*ps), np.max(y+yerr+0.1*ps), 0.3*ps))
        #     plt.xticks(np.arange(np.min(x-xerr-0.1*ps), np.max(x+xerr+0.1*ps), 0.25*ps))
        # else:
        #     plt.yticks(np.arange(np.min(y-yerr-0.1*ps), np.max(y+yerr+0.1*ps), 0.15*ps))
        #     plt.xticks(np.arange(np.min(x-xerr-0.1*ps), np.max(x+xerr+0.1*ps), 0.15*ps))
        paxes.tick_params(axis='both', which='major', labelsize=fontsize1)
        paxes.yaxis.set_major_formatter(FormatStrFormatter('%.2f'))
        paxes.xaxis.set_major_formatter(FormatStrFormatter('%.2f'))
        plt.xlabel('X offset (mas)', fontsize=fontsize1)
        plt.ylabel('Y offset (mas)', fontsize=fontsize1)
        plt.plot(fitLineX, fitLineY, 'k-', label='_nolegend_')
        plt.plot(fitLineX + fitSigX,
                 fitLineY + fitSigY,
                 'k--',
                 label='_nolegend_')
        plt.plot(fitLineX - fitSigX,
                 fitLineY - fitSigY,
                 'k--',
                 label='_nolegend_')

        # Plot lines between observed point and the best fit value along the model line.
        for ee in range(len(time)):
            if ee in idx_2015[0].tolist():
                color_line = 'red'
            if ee in idx_2016[0].tolist():
                color_line = 'green'
            if ee in idx_2017[0].tolist():
                color_line = 'blue'
            if ee in idx_2018[0].tolist():
                color_line = 'cyan'

            plt.plot([fitLineX[ee], x[ee]], [fitLineY[ee], y[ee]],
                     color=color_line,
                     linestyle='dashed',
                     alpha=0.8)

        plt.axis([xlim[i], -xlim[i], -ylim[i], ylim[i]])

        plt.title(starName.upper())
        if i == 0:
            plt.legend(loc=1, fontsize=12)

    plt.subplots_adjust(wspace=0.6,
                        hspace=0.6,
                        left=0.08,
                        bottom=0.05,
                        right=0.95,
                        top=0.90)
    plt.tight_layout()
    plt.show()
    plt.savefig(filename)

    return
コード例 #32
0
def plot_ratio(wdir, data, istep, Q2_bins, dpi=200):
    ratio_1 = 2.5
    ratio_2 = -3.0
    n_rows, n_columns = 4, 4
    fig = py.figure(figsize=(n_columns * 4.5, n_rows * 3.0))
    count = 0
    ax = {}
    label_1 = r'$\mathrm{E866}~pp$'
    label_2 = r'$\mathrm{E866}~pd$'

    for _ in data:
        for i in range(len(Q2_bins)):
            Q2_min, Q2_max = Q2_bins[i]
            thyk = data[_]['thy']
            ratio = data[_]['value'] / thyk
            data[_].update({'ratio': ratio})
            df = pd.DataFrame(data[_])
            df = df.query('Q2>%f and Q2<%f' % (Q2_min, Q2_max))
            count += 1
            ax[count] = py.subplot(n_rows, n_columns, count)
            df = df.query('ratio<%f' % (ratio_1))
            df = df.query('ratio>%f' % (ratio_2))
            thy = df['thy']
            xF = df.xF
            value = df.value
            alpha = df.alpha
            if _ == 10001:
                ax[count].errorbar(xF,
                                   value / thy,
                                   alpha / thy,
                                   color='firebrick',
                                   marker='.',
                                   linestyle='none',
                                   label=label_1)
            if _ == 10002:
                ax[count].errorbar(xF,
                                   value / thy,
                                   alpha / thy,
                                   color='darkgreen',
                                   marker='^',
                                   linestyle='none',
                                   label=label_2)
    count_max = count

    ax[1].legend(fontsize=20, loc=9)
    ax[9].legend(fontsize=20, loc='upper left')

    ## proton
    ax[1].set_ylim(0.5, 1.6)
    minorLocator = MultipleLocator(0.1)
    majorLocator = MultipleLocator(0.5)
    ax[1].yaxis.set_minor_locator(minorLocator)
    ax[1].yaxis.set_major_locator(majorLocator)
    ax[1].text(0.1, 0.6, r'$Q^2~\in~[37,42]\,\mathrm{GeV^2}$', fontsize=22)

    ax[2].set_ylim(0.5, 1.3)
    minorLocator = MultipleLocator(0.05)
    majorLocator = MultipleLocator(0.25)
    ax[2].yaxis.set_minor_locator(minorLocator)
    ax[2].yaxis.set_major_locator(majorLocator)
    ax[2].text(0.07, 0.57, r'$Q^2~\in~[47,49]\,\mathrm{GeV^2}$', fontsize=22)

    ax[3].set_ylim(0.5, 2.1)
    minorLocator = MultipleLocator(0.1)
    majorLocator = MultipleLocator(0.5)
    ax[3].yaxis.set_minor_locator(minorLocator)
    ax[3].yaxis.set_major_locator(majorLocator)
    ax[3].text(0.1, 1.8, r'$Q^2~\in~[54,58]\,\mathrm{GeV^2}$', fontsize=22)

    ax[4].set_ylim(0.7, 2.1)
    minorLocator = MultipleLocator(0.1)
    majorLocator = MultipleLocator(0.5)
    ax[4].yaxis.set_minor_locator(minorLocator)
    ax[4].yaxis.set_major_locator(majorLocator)
    ax[4].text(0.1, 1.8, r'$Q^2~\in~[63,66]\,\mathrm{GeV^2}$', fontsize=22)

    ax[5].set_ylim(0.3, 2.5)
    minorLocator = MultipleLocator(0.1)
    majorLocator = MultipleLocator(0.5)
    ax[5].yaxis.set_minor_locator(minorLocator)
    ax[5].yaxis.set_major_locator(majorLocator)
    ax[5].text(0.1, 2.1, r'$Q^2~\in~[70,73]\,\mathrm{GeV^2}$', fontsize=22)

    ax[6].set_ylim(0.5, 2.5)
    minorLocator = MultipleLocator(0.1)
    majorLocator = MultipleLocator(0.5)
    ax[6].yaxis.set_minor_locator(minorLocator)
    ax[6].yaxis.set_major_locator(majorLocator)
    ax[6].text(0.15, 2.1, r'$Q^2~\in~[118,131]\,\mathrm{GeV^2}$', fontsize=22)

    ax[7].set_ylim(0.3, 2.5)
    minorLocator = MultipleLocator(0.1)
    majorLocator = MultipleLocator(0.5)
    ax[7].yaxis.set_minor_locator(minorLocator)
    ax[7].yaxis.set_major_locator(majorLocator)
    ax[7].text(0.1, 2.1, r'$Q^2~\in~[148,156]\,\mathrm{GeV^2}$', fontsize=22)

    ax[8].set_ylim(0.4, 2.7)
    minorLocator = MultipleLocator(0.1)
    majorLocator = MultipleLocator(0.5)
    ax[8].yaxis.set_minor_locator(minorLocator)
    ax[8].yaxis.set_major_locator(majorLocator)
    ax[8].text(0.32, 2, r' $Q^2~\in~[173,222]\,\mathrm{GeV^2}$', fontsize=22)

    ## deuteron
    ax[9].set_ylim(0.5, 1.7)
    minorLocator = MultipleLocator(0.1)
    majorLocator = MultipleLocator(0.5)
    ax[9].yaxis.set_minor_locator(minorLocator)
    ax[9].yaxis.set_major_locator(majorLocator)
    ax[9].text(0.1, 0.6, r'$Q^2~\in~[37,42]\,\mathrm{GeV^2}$', fontsize=22)

    ax[10].set_ylim(0.5, 1.6)
    minorLocator = MultipleLocator(0.1)
    majorLocator = MultipleLocator(0.5)
    ax[10].yaxis.set_minor_locator(minorLocator)
    ax[10].yaxis.set_major_locator(majorLocator)
    ax[10].text(0.2, 1.4, r'$Q^2~\in~[47,49]\,\mathrm{GeV^2}$', fontsize=22)

    ax[11].set_ylim(0.4, 1.72)
    minorLocator = MultipleLocator(0.1)
    majorLocator = MultipleLocator(0.5)
    ax[11].yaxis.set_minor_locator(minorLocator)
    ax[11].yaxis.set_major_locator(majorLocator)
    ax[11].text(0.2, 1.5, r'$Q^2~\in~[52,57]\,\mathrm{GeV^2}$', fontsize=22)

    ax[12].set_ylim(0.6, 1.42)
    minorLocator = MultipleLocator(0.05)
    majorLocator = MultipleLocator(0.25)
    ax[12].yaxis.set_minor_locator(minorLocator)
    ax[12].yaxis.set_major_locator(majorLocator)
    ax[12].text(0.1, 1.27, r'$Q^2~\in~[62,65]\,\mathrm{GeV^2}$', fontsize=22)

    ax[13].set_ylim(0.45, 1.35)
    minorLocator = MultipleLocator(0.05)
    majorLocator = MultipleLocator(0.25)
    ax[13].yaxis.set_minor_locator(minorLocator)
    ax[13].yaxis.set_major_locator(majorLocator)
    ax[13].text(0.2, 1.2, r'$Q^2~\in~[70,72]\,\mathrm{GeV^2}$', fontsize=22)

    ax[14].set_ylim(0.45, 2.5)
    minorLocator = MultipleLocator(0.1)
    majorLocator = MultipleLocator(0.5)
    ax[14].yaxis.set_minor_locator(minorLocator)
    ax[14].yaxis.set_major_locator(majorLocator)
    ax[14].text(0.2, 2.2, r'$Q^2~\in~[124,129]\,\mathrm{GeV^2}$', fontsize=22)

    ax[15].set_ylim(0.45, 1.75)
    minorLocator = MultipleLocator(0.1)
    majorLocator = MultipleLocator(0.5)
    ax[15].yaxis.set_minor_locator(minorLocator)
    ax[15].yaxis.set_major_locator(majorLocator)
    ax[15].text(0.05,
                1.55,
                r'$Q^2~\in~[145,154]\,\mathrm{GeV^2}$',
                fontsize=22)

    ax[16].set_ylim(0.0, 2.0)
    minorLocator = MultipleLocator(0.1)
    majorLocator = MultipleLocator(0.5)
    ax[16].yaxis.set_minor_locator(minorLocator)
    ax[16].yaxis.set_major_locator(majorLocator)
    ax[16].text(0.05, 0.2, r'$Q^2~\in~[73,280]\,\mathrm{GeV^2}$', fontsize=22)

    for count in range(1, count_max + 1):
        if count % 4 == 1:
            ax[count].set_ylabel(r'\boldmath$\mathrm{data/theory}$', size=24)
            ax[count].yaxis.set_label_coords(-0.17, 0.5)

    for count in range(count_max, count_max - n_columns, -1):
        ax[count].set_xlabel(r'\boldmath$x_{\rm F}$', size=24)

    for i in range(1, 13):
        ax[i].set_xticklabels([])

    for _ in ax:
        ax[_].axhline(1, color='black', ls=':')
        #AX[_].set_ylim(0.8,1.2)
        ax[_].set_xlim(0.0, 1.0)
        ax[_].xaxis.set_label_coords(0.90, -0.12)
        ax[_].tick_params(axis='x', which='major', labelsize=18)
        ax[_].tick_params(axis='y', which='major', labelsize=18)
        ax[_].xaxis.set_tick_params(which='major', length=6)
        ax[_].xaxis.set_tick_params(which='minor', length=3)
        ax[_].yaxis.set_tick_params(which='major', length=6)
        ax[_].yaxis.set_tick_params(which='minor', length=3)
        minorLocator = MultipleLocator(0.05)
        majorLocator = MultipleLocator(0.2)
        ax[_].xaxis.set_minor_locator(minorLocator)
        ax[_].xaxis.set_major_locator(majorLocator)

    py.tight_layout()
    py.subplots_adjust(left=0.08,
                       bottom=0.08,
                       right=0.99,
                       top=0.97,
                       wspace=0.2,
                       hspace=0.1)
    py.savefig('%s/gallery/dy-%d.png' % (wdir, istep), dpi=dpi)
    py.close()
コード例 #33
0
         norm.pdf(beta_axis[2], loc=mean[2], scale=std[2]),
         color='red',
         lw=2)
plt.xlabel('beta[2]')

plt.subplot(4, 4, 13)
plt.scatter(samples['beta'][0][:, 0], samples['beta'][3][:, 0])
plt.xlabel('beta[0]')
plt.ylabel('beta[3]')

plt.subplot(4, 4, 14)
plt.scatter(samples['beta'][1][:, 0], samples['beta'][3][:, 0])
plt.xlabel('beta[1]')
plt.ylabel('beta[3]')

plt.subplot(4, 4, 15)
plt.scatter(samples['beta'][2][:, 0], samples['beta'][3][:, 0])
plt.xlabel('beta[2]')
plt.ylabel('beta[3]')

plt.subplot(4, 4, 16)
plt.hist(samples['beta'][3][:, 0], normed=True)
plt.plot(beta_axis[3],
         norm.pdf(beta_axis[3], loc=mean[3], scale=std[3]),
         color='red',
         lw=2)
plt.xlabel('beta[3]')

plt.tight_layout()
plt.show()
コード例 #34
0
def plotSOWFAvsFLORIS(prob, just_SOWFA=True, plot_prefix=""):

    # prob['floris_params:me'] = params[0:3]
    # prob['floris_params:MU'] = params[3:6]
    # prob['floris_params:cos_spread'] = params[6]

    # Define turbine locations and orientation
    prob['turbineX'] = np.array([1118.1, 1881.9])
    prob['turbineY'] = np.array([1279.5, 1720.5])

    ICOWESdata = loadmat('YawPosResults.mat')
    yawrange = ICOWESdata['yaw'][0]

    FLORISpower = list()

    for yaw1 in yawrange:

        # print 'yaw in = ', yaw1*np.pi/180.

        # assign values to yaw
        prob['yaw0'] = np.array([yaw1, 0.0])

        # run the problem at given conditions
        prob.run()

        # print np.sqrt((turbineY[0]-turbineY[1])**2+(turbineX[0]-turbineX[1])**2)/rotorDiameter[0] # print downwind distance

        FLORISpower.append(list(prob['wtPower0']))

        time.sleep(0.001)

    # time.sleep(10)
    # quit()
    FLORISpower = np.array(FLORISpower)

    SOWFApower = np.array([
        ICOWESdata['yawPowerT1'][0], ICOWESdata['yawPowerT2'][0]
    ]).transpose() / 1000.

    error_turbine2 = np.sum(np.abs(FLORISpower[:, 1] - SOWFApower[:, 1]))

    fig, axes = plt.subplots(ncols=2, nrows=1, sharey=False)

    axes[0].plot(yawrange.transpose(),
                 SOWFApower[:, 0],
                 'o',
                 markeredgecolor='r',
                 markerfacecolor='None',
                 markersize=4,
                 label='Turbine 1, SOWFA Results')
    axes[0].plot(yawrange.transpose(),
                 SOWFApower[:, 1],
                 'o',
                 markeredgecolor='b',
                 markerfacecolor='None',
                 markersize=4,
                 label='Turbine 2, SOWFA Results')
    axes[0].plot(yawrange.transpose(),
                 SOWFApower[:, 0] + SOWFApower[:, 1],
                 'k+',
                 label='Total, SOWFA results')
    axes[0].plot(yawrange.transpose(), FLORISpower[:, 0], 'k-')
    axes[0].plot(yawrange.transpose(), FLORISpower[:, 1], 'k-')
    axes[0].plot(yawrange.transpose(),
                 FLORISpower[:, 0] + FLORISpower[:, 1],
                 'k-',
                 label='FLORIS model')

    # axes[0, 0].plot(yawrange, FLORISpower[:, 1], '#7CFC00')
    axes[0].set_xlabel('yaw angle (deg.)')
    axes[0].set_ylabel('power (kW)')
    # axes[0, 0].set_ylim(500, 6000)
    # axes[0, 0].legend(loc=2)

    posrange = ICOWESdata['pos'][0]

    prob['yaw0'] = np.array([0.0, 0.0])

    FLORISpower = list()

    for pos2 in posrange:
        # Define turbine locations and orientation
        effUdXY = 0.523599

        Xinit = np.array([1118.1, 1881.9])
        Yinit = np.array([1279.5, 1720.5])
        XY = np.array([Xinit, Yinit]) + np.dot(
            np.array([[np.cos(effUdXY), -np.sin(effUdXY)],
                      [np.sin(effUdXY), np.cos(effUdXY)]]),
            np.array([[0., 0], [0, pos2]]))

        prob['turbineX'] = XY[0, :]
        prob['turbineY'] = XY[1, :]

        # run the problem at given conditions
        prob.run()

        # print np.sqrt((turbineY[0]-turbineY[1])**2+(turbineX[0]-turbineX[1])**2)/rotorDiameter[0] # print downwind distance

        FLORISpower.append(list(prob['wtPower0']))

    FLORISpower = np.array(FLORISpower)

    SOWFApower = np.array([
        ICOWESdata['posPowerT1'][0], ICOWESdata['posPowerT2'][0]
    ]).transpose() / 1000.

    error_turbine2 += np.sum(np.abs(FLORISpower[:, 1] - SOWFApower[:, 1]))

    # print error_turbine2
    axes[1].plot(posrange / rotorDiameter[0], FLORISpower[:, 0], 'k-')
    axes[1].plot(posrange / rotorDiameter[0],
                 SOWFApower[:, 0],
                 'o',
                 markeredgecolor='r',
                 markerfacecolor='None',
                 markersize=4,
                 label='Turbine 1, SOWFA Results')
    axes[1].plot(posrange / rotorDiameter[0], FLORISpower[:, 1], 'k-')
    axes[1].plot(posrange / rotorDiameter[0],
                 SOWFApower[:, 1],
                 'o',
                 markeredgecolor='b',
                 markerfacecolor='None',
                 markersize=4,
                 label='Turbine 2, SOWFA Results')
    axes[1].plot(posrange / rotorDiameter[0],
                 FLORISpower[:, 0] + FLORISpower[:, 1],
                 'k-',
                 label='FLORIS model')
    axes[1].plot(posrange / rotorDiameter[0],
                 SOWFApower[:, 0] + SOWFApower[:, 1],
                 'k+',
                 label='Total, SOWFA Results')
    axes[1].set_xlabel('y/D')
    axes[1].set_ylabel('power (kW)')
    axes[1].set_xlim(min(posrange / rotorDiameter[0]),
                     max(posrange / rotorDiameter[0]))
    # lgd = axes[1].legend(loc='center left', bbox_to_anchor=(1.0, 0.5))
    lgd = axes[0].legend(loc='lower left',
                         bbox_to_anchor=(0.0, 1.05),
                         fancybox=False,
                         shadow=False,
                         ncol=2)
    plt.tight_layout()

    if not plot_prefix == "":
        plt.savefig(plot_prefix + "SOWFA.pdf",
                    bbox_extra_artists=(lgd, ),
                    bbox_inches='tight')

    # ############
    if not just_SOWFA:
        fig, axes = plt.subplots(ncols=2, nrows=1, sharey=False)

        posrange = np.linspace(-3. * rotorDiameter[0],
                               30. * rotorDiameter[0],
                               num=1000)
        yaw = np.array([0.0, 0.0])
        wind_direction = 270.

        prob['yaw0'] = yaw
        prob['wind_direction'] = wind_direction

        FLORISpower = list()
        FLORISvelocity = list()

        for pos2 in posrange:

            # assign values to yaw
            prob['turbineX'] = np.array([0., pos2])
            prob['turbineY'] = np.array([0.0, 0.0])

            # run the problem at given conditions
            prob.run()

            # print np.sqrt((turbineY[0]-turbineY[1])**2+(turbineX[0]-turbineX[1])**2)/rotorDiameter[0] # print downwind distance

            FLORISpower.append(list(prob['wtPower0']))
            FLORISvelocity.append(list(prob['wtVelocity0']))

        FLORISpower = np.array(FLORISpower)
        FLORISvelocity = np.array(FLORISvelocity)

        # np.savetxt("downstream_velocity_original.txt", np.c_[posrange/rotorDiameter[0], FLORISvelocity[:, 1]], delimiter=',')

        axes[1].plot(posrange / rotorDiameter[0],
                     FLORISpower[:, 1],
                     '#7CFC00',
                     label='FLORIS model')
        axes[1].plot(np.array([7, 7]),
                     np.array([0, 1800]),
                     '--k',
                     label='tuning point')
        axes[1].set_xlabel('x/D')
        axes[1].set_ylabel('Power (kW)')
        axes[1].legend(loc=4)

        axes[0].plot(posrange / rotorDiameter[0],
                     FLORISvelocity[:, 1],
                     '#7CFC00',
                     label='FLORIS model')
        axes[0].plot(np.array([7, 7]),
                     np.array([2, 9]),
                     '--k',
                     label='tuning point')
        axes[0].set_xlabel('x/D')
        axes[0].set_ylabel('Valocity (m/s)')
        axes[0].legend(loc=4)
        # plt.show()

        plt.tight_layout()
        if not plot_prefix == "":
            plt.savefig(plot_prefix + "DownwindProfile.pdf")

        FLORIScenters = list()
        FLORISdiameters = list()
        FLORISoverlap = list()
        # prob['wakeCentersYT'][2] = 0.
        for pos2 in posrange:

            # assign values to yaw
            prob['turbineX'] = np.array([0., pos2])
            # prob['turbineY'] = np.array([0.0, prob['wakeCentersYT'][2]])
            prob['turbineY'] = np.array([0.0, 0.0])

            # run the problem at given conditions
            prob.run()

            # print np.sqrt((turbineY[0]-turbineY[1])**2+(turbineX[0]-turbineX[1])**2)/rotorDiameter[0] # print downwind distance
            # print prob['wakeCentersYT']
            FLORIScenters.append(list(prob['wakeCentersYT']))
            FLORISdiameters.append(list(prob['wakeDiametersT']))
            FLORISoverlap.append(list(prob['wakeOverlapTRel']))
            # print prob['wtVelocity0']

            # print prob['wakeOverlapTRel'][6:]

        FLORIScenters = np.array(FLORIScenters)
        FLORISdiameters = np.array(FLORISdiameters)
        FLORISoverlap = np.array(FLORISoverlap)

        fig, axes = plt.subplots(ncols=2, nrows=2, sharey=False, sharex=False)
        # plot wake center
        axes[0, 0].plot(posrange / rotorDiameter[0],
                        FLORIScenters[:, 2] / rotorDiameter[0],
                        'k',
                        label='Wake Center')
        # axes[0, 0].set_xlabel('x/D')
        axes[0, 0].set_ylabel('y/D')
        axes[0, 0].legend(loc=1)

        # plot wake diameters
        axes[0,
             1].plot(posrange / rotorDiameter[0],
                     FLORISdiameters[:, 3 * nTurbines + 0] / rotorDiameter[0],
                     'b',
                     label='Near Wake')
        axes[0,
             1].plot(posrange / rotorDiameter[0],
                     FLORISdiameters[:, 3 * nTurbines + 2] / rotorDiameter[0],
                     'r',
                     label='Far Wake')
        axes[0,
             1].plot(posrange / rotorDiameter[0],
                     FLORISdiameters[:, 3 * nTurbines + 4] / rotorDiameter[0],
                     'y',
                     label='Mixing Zone')
        # axes[0, 1].set_xlabel('x/D')
        axes[0, 1].set_ylabel('Wake Diameter / Rotor Diameter')
        axes[0, 1].legend(loc=2)
        axes[0, 1].set_ylim([-1., 5.])

        # plot wake relative overlap
        axes[1, 0].plot(posrange / rotorDiameter[0],
                        FLORISoverlap[:, 3 * nTurbines + 0],
                        'b',
                        label='Near Wake')
        axes[1, 0].plot(posrange / rotorDiameter[0],
                        FLORISoverlap[:, 3 * nTurbines + 2],
                        'r',
                        label='Far Wake')
        axes[1, 0].plot(posrange / rotorDiameter[0],
                        FLORISoverlap[:, 3 * nTurbines + 4],
                        'y',
                        label='Mixing Zone')
        axes[1, 0].set_xlabel('x/D')
        axes[1, 0].set_ylabel('Relative Overlap')
        axes[1, 0].legend(loc=0)
        axes[1, 0].set_ylim([-0.1, 1.1])

        posrange = np.linspace(-3. * rotorDiameter[0],
                               7. * rotorDiameter[0],
                               num=300)
        yaw = np.array([0.0, 0.0])
        wind_direction = 270.

        prob['yaw0'] = yaw
        prob['wind_direction'] = wind_direction

        FLORISpower = list()

        for pos2 in posrange:

            # assign values to yaw
            prob['turbineX'] = np.array([0., 5 * rotorDiameter[0]])
            prob['turbineY'] = np.array([0.0, pos2])

            # run the problem at given conditions
            prob.run()

            # print np.sqrt((turbineY[0]-turbineY[1])**2+(turbineX[0]-turbineX[1])**2)/rotorDiameter[0] # print downwind distance

            FLORISpower.append(list(prob['wtPower0']))

        FLORISpower = np.array(FLORISpower)

        axes[1, 1].plot(posrange / rotorDiameter[0], FLORISpower[:, 1],
                        '#7CFC00')  #, label="FLORIS model")
        axes[1, 1].set_xlabel('x/D')
        axes[1, 1].set_ylabel('Power (kW)')
        axes[1, 1].legend(loc=4)

        if not plot_prefix == "":
            plt.savefig(plot_prefix + "WakeProfile.pdf")

    #####################

    # FLORISaxialInd = list()
    # windspeed = np.linspace(0, 30, 100)
    # # prob['wakeCentersYT'][2] = 0.
    # for pos2 in posrange:
    #
    #     # assign values to yaw
    #     prob['turbineX'] = np.array([0., pos2])
    #     # prob['turbineY'] = np.array([0.0, prob['wakeCentersYT'][2]])
    #     prob['turbineY'] = np.array([0.0, 0.0])
    #
    #     # run the problem at given conditions
    #     prob.run()
    #
    #     # print np.sqrt((turbineY[0]-turbineY[1])**2+(turbineX[0]-turbineX[1])**2)/rotorDiameter[0] # print downwind distance
    #     # print prob['wakeCentersYT']
    #     FLORIScenters.append(list(prob['wakeCentersYT']))
    #     FLORISdiameters.append(list(prob['wakeDiametersT']))
    #     FLORISoverlap.append(list(prob['wakeOverlapTRel']))
    #     # print prob['wtVelocity0']
    #
    #     # print prob['wakeOverlapTRel'][6:]
    #
    # FLORIScenters = np.array(FLORIScenters)
    # FLORISdiameters = np.array(FLORISdiameters)
    # FLORISoverlap = np.array(FLORISoverlap)

    # fig, axes = plt.subplots(ncols=2, nrows=2, sharey=False, sharex=True)
    # # plot wake center
    # axes[0, 0].plot(posrange/rotorDiameter[0], FLORIScenters[:, 2], 'k', label='Wake Center')
    # # axes[0, 0].set_xlabel('x/D')
    # axes[0, 0].set_ylabel('Position')
    # axes[0, 0].legend(loc=1)
    plt.tight_layout()
    plt.show()
コード例 #35
0
        x0 = 10 * xc

    #plot the two calculations as an overlay, for both x and v
    figure(j)

    subplot(2, 1, 1)
    plot(t, xRel, t, xClass)
    legend(('Relativistic', 'Classical'))
    xlabel('time(s)')

    subplot(2, 1, 2)
    plot(t, vRel, t, vClass)
    xlabel('time(s)')
    title('v')
    suptitle('x0 = ' + str(x0) + 'm')
    tight_layout()
    savefig('Lab03-Q1a-Fig' + str(j + 1) + '.png')
#------------------------------------------------------------------------
# Relativistic period
x0_range = linspace(1, 10 * xc, 1000)


def g(x):
    return c*sqrt(((0.5*k*(x0**2-x**2)*(2.0*m*c**2+0.5*k*(x0**2-x**2))) \
                      /(m*c**2+0.5*k*(x0**2-x**2))**2))


def integrand(x):
    return 4.0 * g(x)**-1

コード例 #36
0
ファイル: plotting.py プロジェクト: umithardal/nicos
    def plot_map(self):
        import pylab

        # compile a list of reflexes allowed by current spectro config
        allowed, limited = self.generate_hkls()

        # calculate limits of movement from limits of phi and psi
        lim1, lim2, lim3, lim4 = [], [], [], []
        psimin, psimax = self.tasinfo['psilim']
        phimin, phimax = self.tasinfo['philim']
        coupling = self.tasinfo['axiscoupling']
        if self.mode == 'CKI':
            ki = self.const
            kf = self.cell.cal_kf(self.ny, ki)
        else:
            kf = self.const
            ki = self.cell.cal_ki1(self.ny, kf)
        for phival in linspace(phimin, phimax, 100):
            xy1 = self.cell.angle2Qcart([ki, kf, phival, psimin], coupling)
            xy2 = self.cell.angle2Qcart([ki, kf, phival, psimax], coupling)
            lim1.append(xy1[:2])
            lim2.append(xy2[:2])
        for psival in linspace(psimin, psimax, 100):
            xy1 = self.cell.angle2Qcart([ki, kf, phimin, psival], coupling)
            xy2 = self.cell.angle2Qcart([ki, kf, phimax, psival], coupling)
            lim3.append(xy1[:2])
            lim4.append(xy2[:2])

        # directions of axes
        dir1 = self.cell._orient1
        dir2 = cross(self.cell.cal_zone(), self.cell._orient1)
        # normalize second direction to smallest length
        comp = [abs(c) for c in dir2 if c != 0]
        complen = len(comp)
        if complen == 0:
            # should be impossible: all entries == 0, no change
            f = 1
        elif complen == 1:
            f = comp[0]
        elif complen == 2:
            f = gcd(comp[0], comp[1])
        else:
            f = min(gcd(comp[0], comp[1]), gcd(comp[1], comp[2]),
                    gcd(comp[0], comp[2]))
        dir2 /= f

        # set up pylab figure
        pylab.ion()
        pylab.figure('Reciprocal space visualization',
                     figsize=(7, 7),
                     dpi=120,
                     facecolor='1.0')
        pylab.clf()
        pylab.rc('text', usetex=True)
        pylab.rc('text.latex',
                 preamble=
                 r'\usepackage{amsmath}\usepackage{helvet}\usepackage{sfmath}')

        ax = pylab.subplot(111, aspect='equal')
        ax.set_axisbelow(True)  # draw grid lines below plotted points
        # register event handler to pylab
        pylab.connect('key_press_event', pylab_key_handler)

        def click_handler(event):
            if not event.inaxes: return
            canvas = pylab.gcf().canvas
            if canvas.toolbar.mode: return
            hkl = self.display_hkl(event.xdata, event.ydata, self.clicktext)
            if hkl is not None:
                self.plot_ellipsoid(hkl, event.xdata, event.ydata)
            canvas.draw()

        pylab.connect('button_release_event', click_handler)
        # monkey-patch formatting coordinates in the status bar
        pylab.gca().format_coord = self.format_coord

        pylab.title(
            'Available reciprocal space for %s %.3f \\AA$^{-1}$, E = %.3f %s' %
            (self.mode, self.const, self.E,
             self.tasinfo['energytransferunit']))
        pylab.xlabel('$Q_1$ (\\AA$^{-1}$) $\\rightarrow$ ( %d %d %d )' %
                     tuple(dir1))
        pylab.ylabel('$Q_2$ (\\AA$^{-1}$) $\\rightarrow$ ( %d %d %d )' %
                     tuple(dir2))
        pylab.grid(color='0.5', zorder=-2)
        if hasattr(pylab, 'tight_layout'):
            pylab.tight_layout()
        pylab.subplots_adjust(bottom=0.1)

        self.clicktext = pylab.text(0.5,
                                    0.01,
                                    '(click to show angles)',
                                    size='small',
                                    horizontalalignment='center',
                                    transform=pylab.gcf().transFigure)

        # plot origin
        self.plot_hkl((0, 0, 0), color='black')
        # plot allowed Bragg indices
        self.plot_hkls(allowed,
                       labels=['(%d%d%d)' % tuple(v) for v in allowed])
        # plot Bragg indices allowed by scattering plane, but limited by devices
        self.plot_hkls(limited, color='red')
        # plot user-supplied points
        for hkl in self.hkls:
            self.plot_hkl(hkl,
                          color='#009900',
                          edgecolor='black',
                          linewidth=0.5,
                          label='(%.3g %.3g %.3g)' % tuple(hkl))
        # plot user-supplied propagation vectors
        for tau in self.taus:
            tau = array(tau)
            allowed1, limited = self.generate_hkls(tau, origin=True)
            allowed2, limited = self.generate_hkls(-tau, origin=True)
            self.plot_hkls(allowed1 + allowed2,
                           color='#550055',
                           s=3,
                           marker='s')
        # plot user-supplied scan points
        if self.scan is not None:
            allowed, limited = self.check_hkls(self.scan)
            self.plot_hkls(allowed, color='#009900', s=2)
            self.plot_hkls(limited, color='red', s=2)
        # plot current spectrometer position
        current_pos = self.tasinfo['actpos']
        if abs(current_pos[3] - self.E) < 0.01:
            self.plot_hkls([current_pos[:3]], color='#990033', marker='x')
        # plot last calpos() result
        calpos = self.tasinfo['calpos']
        if calpos is not None and abs(calpos[3] - self.E) < 0.01:
            self.plot_hkls([calpos[:3]], color='#006600', marker='*')

        # plot limits of phi/psi
        for v in lim1, lim2, lim3, lim4:
            v = array(v)
            pylab.plot(v[:, 0], v[:, 1], color='0.7', zorder=-1)
コード例 #37
0
P.fill_between([1e8, 4e9],
               1e-3,
               1e3,
               linewidths=0.,
               color='k',
               alpha=0.1,
               zorder=-100)

P.xlabel(r"$M_\star$ $[M_\odot]$", fontsize=18)
P.ylabel(r"$\psi_{\rm SFR}$ $[M_\odot/{\rm yr}]$", fontsize=18)

P.gca().tick_params(axis='both',
                    which='major',
                    labelsize=20,
                    size=8.,
                    width=1.5,
                    pad=8.)
P.gca().tick_params(axis='both',
                    which='minor',
                    labelsize=20,
                    size=5.,
                    width=1.5,
                    pad=8.)

P.xscale('log')
P.yscale('log')

P.tight_layout()
#P.savefig('../draft/sfr_mstar_bounds.pdf')
P.show()
コード例 #38
0
    def finish(self):
        # Finish presentation
        #
        if not self.isReady:
            return

        if self.isUserAbort:
            # Clear screen
            #
            self.View.clear()
            self.View.present()
            ssp.Log.write("ABORT", "User aborted program")

        else:
            ssp.Log.write("ok", "Program finished")

        # Log timing information
        #
        if self.Conf.isTrackTime:
            self.avRendDur_s = self.avRendDur_s / self.nRendTotal
            self.avPresDur_s = self.avPresDur_s / self.nRendTotal
            self.avFrDur_s = self.avFrDur_s / self.nFrTotal
            ssp.Log.write(
                "INFO", "{0:.3f} ms/frame ({1:.3f} Hz), rendering: "
                "{2:.3f} ms/frame ({3} frames in total)".format(
                    self.avFrDur_s * 1000.0, 1 / self.avFrDur_s,
                    self.avRendDur_s * 1000.0, self.nFrTotal))
            ssp.Log.write(
                "INFO", "presenting: {0:.3f} ms/frame".format(
                    self.avPresDur_s * 1000.0))

            if glo.QDSpy_frRateStatsBufferLen > 0:
                if not self.dataDtFrOver:
                    data = self.dataDtFr[:self.dataDtFrLen]
                else:
                    data = self.dataDtFr
            else:
                data = np.array(self.dataDtFr)
            av = data.mean() * 1000.0
            std = data.std() * 1000.0
            ssp.Log.write(
                "INFO", "{0:.3f} +/- {1:.3f} ms/frame (over the last {2}"
                " frames) = {3:.3} Hz".format(av, std, len(data), 1000.0 / av))
            if self.nDroppedFr > 0:
                pcDrFr = 100.0 * self.nDroppedFr / self.nFrTotal
                ssp.Log.write(
                    "WARNING", "{0} frames dropped (={1:.3f} %)".format(
                        self.nDroppedFr, pcDrFr))

            ssp.Log.write(
                "DATA", {
                    "avgFreq_Hz": 1 / self.avFrDur_s,
                    "nFrames": self.nFrTotal,
                    "nDroppedFrames": self.nDroppedFr
                }.__str__())

            if QDSpy_verbose:
                # Generate a plot ...
                #
                pylab.title("Timing")
                pylab.subplot(2, 1, 1)
                pylab.plot(list(range(len(data))), data * 1000, "-")
                xArr = [0, len(data) - 1]
                dtFr_ms = self.dtFr_meas_s * 1000
                yMin = dtFr_ms + self.Conf.maxDtTr_ms
                yMax = dtFr_ms - self.Conf.maxDtTr_ms
                pylab.plot(xArr, [yMin, yMin], "k--")
                pylab.plot(xArr, [yMax, yMax], "k--")
                pylab.ylabel("frame duration [ms]")
                pylab.xlabel("frame #")
                pylab.xlim([10, len(data)])
                pylab.ylim([dtFr_ms - 10, dtFr_ms + 10])
                pylab.subplot(2, 1, 2)
                n, bins, pat = pylab.hist(data * 1000,
                                          100,
                                          histtype="bar",
                                          rwidth=0.9)
                pylab.setp(pat, 'facecolor', 'b', 'alpha', 0.75)
                #pylab.xlim([dtFr_ms-5,dtFr_ms+5])
                pylab.ylabel("# frames")
                pylab.xlabel("frame duration [ms]")
                pylab.tight_layout()
                pylab.show()
コード例 #39
0
ファイル: script.py プロジェクト: maayane/SLAB-Diffusion
def calculate_T_and_R_in_time(total_time=params.total_time,Etot=params.E,true_h=params.h,output_file=params.path_outputs,
                              dilution_factor = params.dillution_factor,v=params.v):

    space_x=np.linspace(0,Lx,num=Nx+1)
    delta_x=space_x[1]-space_x[0]
    space_y=np.linspace(0,Ly,num=Ny+1)
    delta_y=space_y[1]-space_y[0]
    space_z=np.linspace(0,h,num=Nz+1)
    delta_z=space_z[1]-space_z[0]    
    delta_t=F/((1/delta_x**2)+(1/delta_y**2)+(1/delta_z**2))
    Nt = int(round(total_time / float(delta_t)))
    print('given the total time,F and L, I have {0} time meshpoints'.format(Nt))
    
    #checking the normalization
    a=4.
    Ei=Etot/true_h**3
    print('the initial volumetric energy is',Ei)
    
    already_run=False
    if already_run==False:
        u,spacex,spacey,spacez,time=solver_3D.solver_3D_norm(Nx,Ny,Nz,Lx=Lx,Ly=Ly,Initial_xyz=Initial_trivariate,F=F,v=v,a=a,total_time=total_time,reflecting=True,Ei=Ei,output_file=output_file+'/images2D')#53.125)
        if os.path.exists(output_file+'/images2D')!=True:
            logger.info('the output file for the 2D images did not exist yet. I am creating it now')
            os.makedirs(output_file+'/images2D')
        plotter_3D.plot_u_latest_time(u,space_z,time,time_Units='tD',output_file=output_file,show_plots=False)
    
        #Temperature
        sig_cgs=5.6704e-5
        c_cgs=3e10
        initial_energy_density=1.#5000.0 #erg/cm^3
    
        a_bb = 4 * sig_cgs/ c_cgs
        print('I am calculating the temperature at the surface of the slab')
        temp=np.zeros((Nt + 1, Nx + 1, Ny+1))
        temp[:,:,:] = np.power(1. / a_bb * u[:,:,:,Nz], 0.25)
        #plotter_3D.plot_cuts_2D_temp(temp,spacez,time,time_Units='tD',output_file=output_file,dilution_factor=dilution_factor,show_plots=True)
        #plotter_3D.plot_temp_latest_time(temp,spacez,time,time_Units=None,output_file=output_file,show_plots=False)
        pylab.matshow(temp[-1,:,:].T)
        pylab.xlabel('x axis')
        pylab.ylabel('y axis')
        pylab.title('final temperature at the surface of the slab',y=1.08)#z=h/2
        pylab.colorbar()
        pylab.savefig(output_file + '/temperature_surface.png', bbox_inches='tight')
        #pylab.tight_layout()
        #pylab.show()
        #pdb.set_trace()
    else:
        time = np.linspace(0, total_time, num=Nt + 1)
    
    time_observed=[]
    print('dilution_factor',dilution_factor)
    time_diluted = time[::dilution_factor]
    index_dilute = range(Nt+1)[::dilution_factor]
    #print(np.shape(time_diluted))
    #print(np.shape(index_dilute))
    
    Sum_BB_fromfile=np.zeros((len(time[::dilution_factor]),100))
    
    already_run=False
    if already_run==False:
        for t, s in enumerate(time_diluted):
            Sum_BB_ind = np.zeros((100))
            #print(t)
            #print(s)
            print('*********************')
            print('Computing the observables at the surface of the slab for t/tD={0} (total time is {1})'.format(s,total_time))
            # edge = u[t, :, :, Nz]
            #if s >= tmin and s <= tmax:
            time_observed.append(s)
            #pylab.figure()
                #Sum_BB[t,:,0]=np.linspace(1e-10,1e-6,num=100)
            for i,l in enumerate(spacex):
                for j,k in enumerate(spacey):
                    #print(temp[int(index_dilute[t]),i,j,Nz]
                    #if temp[int(index_dilute[t]),i,j,Nz]!=0.:
                    #pdb.set_trace()
                    #print('I am calculating a cell {0} spectrum'.format()
                    bb_flux_spectrum=black_body_flux_density.black_body_flux_density(temp[int(index_dilute[t]),i,j],np.linspace(1e-10,1e-6,num=100),type='P',verbose=False,distance_pc=1,Radius=None)[2]#les luminosites seront celle de bb 1 solar radius a 1 pc!
                    #pylab.plot(bb_flux_spectrum[:,0]*1e9,bb_flux_spectrum[:,1])
                    #else:
                    #    bb_flux_spectrum=np.zeros(100,2)
                    #    bb_flux_spectrum[:, 0]=np.linspace(1e-10,1e-6,num=100)
                    Sum_BB_ind[:] = Sum_BB_ind[:] + bb_flux_spectrum[:, 1] #erg/sec/cm^2/Ang
                    #Sum_BB[t,:]=Sum_BB[t,:]+bb_flux_spectrum[:,1]
            #pylab.xlabel('wavelegth [$nm$]')
            #pylab.ylabel(r'$B_\lambda$ [$erg/s/cm^2/\AA$]')
            #pylab.title('Edge cells spectra at t={0}'.format(s))
            #pylab.savefig(output_file+'/cells_bb_spectra/cell_bb_' + str(t).zfill(5) + '.png', bbox_inches='tight')
            np.savetxt(output_file+'/Sum_BB_time_{0}.txt'.format(s), Sum_BB_ind[:])
    
    time_observed_x=[]
    for t, s in enumerate(time_diluted):
        #if s >= tmin and s <= tmax:
        #print('I am looking at the edge at time-meshpoint {0}, i.e time {1}'.format(int(index_dilute[t]), s))
        time_observed_x.append(s)
    np.savetxt(output_file+'/time_observed.txt',time_observed_x)
    
    distance_modulus=37.77
    distance_pc=distances_conversions.DM_to_pc(distance_modulus)
    
    time_observed_fromfile=np.genfromtxt(output_file+'/time_observed.txt')
    #Sum_BB_fromfile=np.genfromtxt(output_file+'/Sum_BB.txt',skip_header=1)
    for t, s in enumerate(time_diluted): #10s per step 1days~6 steps (60 s per day), 50 days en 50 min
        Sum_BB_fromfile[t,:]=np.genfromtxt(output_file+'/Sum_BB_time_{0}.txt'.format(s))
    
    #print(np.shape(Sum_BB_fromfile))
    #print(Sum_BB_fromfile[0,:])
    
    pylab.figure()
    for t,s in enumerate(time_observed_fromfile):
        #print(t)
        pylab.plot(np.linspace(1e-10,1e-6,num=100)*1e9,Sum_BB_fromfile[t,:])
    pylab.xlabel('wavelegth [$nm$]')
    pylab.ylabel(r'$B_\lambda$ [$erg/s/cm^2/\AA$]')
    #pylab.title('Sum of all edge cells spectra from day {0} to {1} days'.format(tmin,tmax/(3600*24)))
    if os.path.exists(output_file + '/cells_bb_spectra') != True:
        logger.info('the output file for the 2D images did not exist yet. I am creating it now')
        os.makedirs(output_file + '/cells_bb_spectra')

    pylab.savefig(output_file+'/cells_bb_spectra/sum_cells_bb.png', bbox_inches='tight')
    
    already_fit=False
    if already_fit==False:
        BB_evo=np.zeros((np.shape(time_observed_fromfile)[0],4))
        for t, s in enumerate(time_observed_fromfile):
            #print('I am looking at time {0}'.format(s))
            Sum_BB_fromfile_w_wavelengths = np.zeros((100, 2))
            Sum_BB_fromfile_w_wavelengths[:, 0] = np.linspace(1e-10, 1e-6, num=100)
            Sum_BB_fromfile_w_wavelengths[:, 1] = Sum_BB_fromfile[t, :]
            Xi_array, best_temp, index_min, best_coeff1, best_radius, best_luminosity=fit_black_body_flux_spec.fit_black_body_flux_spec(Sum_BB_fromfile_w_wavelengths,TempVec=np.logspace(3,6,1000),WaveUnits='m',distance=distance_pc,output_file=output_file)
            BB_evo[t,0]=s
            BB_evo[t,1]=best_temp
            BB_evo[t,2]=best_radius
            BB_evo[t,3]=best_luminosity
        np.savetxt(output_file+'/Sum_BB_properties.txt',BB_evo,header='time,best-fit temperature,best-fit radius,best-fit luminosity')
    
    
    BB_evo_fromfile=np.genfromtxt(output_file+'/Sum_BB_properties.txt',skip_header=1)
    '''
    pylab.figure()
    pylab.plot(BB_evo_fromfile[:,0],BB_evo_fromfile[:,1],'r-')
    pylab.xlabel(r'$\frac{t}{h^2/D(z=h)}$',fontsize=25)
    ax=pylab.gca()
    ax.set_xscale("log")
    pylab.grid()
    pylab.ylabel('temperature [K]',fontsize=25)
    pylab.xlim(BB_evo_fromfile[1,0],BB_evo_fromfile[-1,0])
    #pylab.title('Spectrum BB temperature')
    pylab.savefig(output_file+'/edge_spectrum_BB_T.png', bbox_inches='tight')
    
    BB_evo_fromfile=np.genfromtxt(output_file+'/Sum_BB_properties.txt',skip_header=1)
    pylab.figure()
    pylab.plot(BB_evo_fromfile[:,0],BB_evo_fromfile[:,2],'bo')
    pylab.xlabel(r'time [t/t_D]')
    pylab.ylabel('radius [arb]')
    pylab.title('Spectrum BB radius')
    pylab.grid()
    pylab.savefig(output_file+'/edge_spectrum_BB_R.png', bbox_inches='tight')
    pylab.show()
    '''

    #########################################################################
    u_total_Dcst = np.zeros(np.shape(time))
    u_grid = np.zeros(np.shape(time))
    flux = np.zeros((np.shape(time)[0], Nx + 1, Ny + 1))
    energy_released_in_time = np.zeros(np.shape(time))
    #print(np.shape(flux))
    # pdb.set_trace()
    flux_in_time = np.zeros((np.shape(time)[0]))
    print('I am caluclating u at the edge over time and u in the grid over time')
    for t, s in enumerate(time):
        u_total_Dcst[t] = np.sum(u[t, :, :, -1])
        u_grid[t] = np.sum(u[t, :, :, :])

    kernel_Dcst = np.zeros((np.shape(u_total_Dcst)[0], 2))
    kernel_Dcst[:, 0] = time
    kernel_Dcst[:, 1] = u_total_Dcst
    coeff_boundary = v / a
    surface_elementaire = (space_x[1] - space_x[0]) * (space_y[1] - space_y[0])
    Luminosities = c_cgs / a * u_total_Dcst * surface_elementaire * true_h ** 2  # u est en erg/cm^3, surface_elementaire *true_h**2 est en cm2, c^2/a est le vrai coeff buondary
    np.savetxt(output_file+'/Luminosities_Dcst.txt', Luminosities)
    #else:
    #time = np.linspace(0, total_time, num=Nt + 1)

    #########################################################################
    temperatures=np.genfromtxt(output_file+'/Sum_BB_properties.txt',skip_header=1)[:,1]
    Luminosities=np.genfromtxt(output_file+'/Luminosities_Dcst.txt')

    dilution_factor_1=dilution_factor
    dilution_factor_2=1
    Luminosities_diluted=Luminosities[::dilution_factor_1]

    pylab.figure()

    pylab.plot(time,Luminosities)
    pylab.xlabel(r'$\frac{t}{t_D}$', fontsize=25)
    pylab.ylabel(r'$erg/s$', fontsize=25)
    pylab.title('Total brightness at the surface')
    pylab.tight_layout()
    pylab.savefig(output_file + '/brightness_surface.png', bbox_inches='tight')
    #pylab.show()

    #print(Luminosities_diluted)

    #pdb.set_trace()

    radii=np.power((1./(4*math.pi*sig_cgs)*np.multiply(Luminosities_diluted,1/np.power(temperatures,4))),0.5)
    time_diluted=time[::dilution_factor_1]

    time_diluted_more=time_diluted[::dilution_factor_2]
    radii_diluted_more=radii[::dilution_factor_2]

    pylab.figure()
    pylab.plot(time_diluted_more,radii_diluted_more,'b-')
    pylab.grid()
    pylab.xlabel(r'$\frac{t}{t_D}$',fontsize=25)
    pylab.ylabel(r'Radius $r_{BB}$ [cm]', fontsize=25)
    pylab.tight_layout()
    pylab.savefig(output_file+'/Radius_surface.png',bbox_inches='tight')
    #pylab.show()

    #only if you ran solver_diffusion_and_calc_spectrum_w_true_values.py before
    BB_evo_fromfile=np.genfromtxt(output_file+'/Sum_BB_properties.txt',skip_header=1)

    #pylab.figure()
    #pylab.title('Spectrum BB temperature')
    #pylab.savefig(output_file/edge_spectrum_BB_T.png', bbox_inches='tight')


    #pylab.figure()
    f = plt.figure(figsize=(8,8))
    ax1 = plt.subplot(212)
    plt.plot(BB_evo_fromfile[:,0],BB_evo_fromfile[:,1],'r-')
    plt.xlabel(r'$\rm{\frac{t}{t_d}}$',fontsize=25)
    ax=pylab.gca()
    ax.set_xscale("log")
    pylab.grid(True, which="both")
    plt.ylabel('temperature [K]',fontsize=23)
    plt.xlim(BB_evo_fromfile[1,0],BB_evo_fromfile[-1,0])
    plt.yticks(fontsize=16)
    plt.xticks(fontsize=16)
    # share x only
    ax2 = plt.subplot(211, sharex=ax1)
    plt.plot(time_diluted_more,radii_diluted_more/1e15,'b-')
    pylab.grid(True, which="both")
    #plt.xlabel(r'$\frac{t}{h^2/D(z=h)}$',fontsize=25)
    plt.ylabel(r'Radius $r_{BB}$ [$\rm{10^{15}}\,$cm]', fontsize=18)
    #plt.savefig(output_file/edge_spectrum_BB_R_2.png',bbox_inches='tight')
    plt.yticks(fontsize=16)
    plt.xticks(fontsize=16)
    plt.xlim(0.01,1)
    #plt.ylim(0,16e15)
    plt.setp(ax2.get_xticklabels(), visible=False)
    pylab.tight_layout()
    #plt.savefig('./paper_figures/kernel_comparision_same_xaxis.pdf', facecolor='w', edgecolor='w',
    #              orientation='portrait',
    #              papertype=None, format='pdf', transparent=False, bbox_inches=None, pad_inches=0.5)
    plt.savefig(output_file+'/R_T_surface.png',bbox_inches='tight')


    pylab.show()
コード例 #40
0
    xmin, xmax = pylab.xlim()
    ymin, ymax = pylab.ylim()

    if name == 'F11':
        pylab.text(0.4 * xmax,
                   0.2 * ymax,
                   r'$F_{{{0}}}$'.format(str(number)),
                   fontsize=12)
    elif name == 'F12':
        pylab.text(0.4 * xmax,
                   0.75 * ymax,
                   '-' + r'$F_{{{0}}}$'.format(str(number)) +
                   r'$\rm /\textit{$F$}_{11}$',
                   fontsize=12)
    else:
        pylab.text(0.4 * xmax,
                   0.75 * ymax,
                   r'$F_{{{0}}}$'.format(str(number)) +
                   r'$\rm /\textit{$F$}_{11}$',
                   fontsize=12)

    pylab.xticks([0, 45, 90, 135, 180])
    pylab.gca().xaxis.set_minor_locator(MultipleLocator(15))

pylab.tight_layout()
pylab.legend(loc='center left',
             bbox_to_anchor=(1, 0.5),
             title='Vdc=' + str(vdc) + '  Vac=' + str(vac))
pylab.savefig(sample_name, bbox_inches='tight', dpi=400)
pylab.show()
コード例 #41
0
def plot_snapshot(filepath, snapshot_idx, do_slice, do_flip):

    fig = plt.figure()

    #ax1 = fig.add_subplot(121)
    #ax2 = plt.axes([0.58, 0.58, 0.29, 0.29])
    ax2 = fig.add_subplot(111)

    for core_idx in range(0, num_cores):
        print("Plotting chunk {0}".format(core_idx))
        if snapshot_idx < 66:
            fname = "{2}snapdir_{0:03d}/snapdir_{0:03d}/snapshot_{0:03d}.{1}.hdf5".format(
                snapshot_idx, core_idx, snapdir)
        else:
            fname = "{2}snapdir_{0:03d}/snapshot_{0:03d}.{1}.hdf5".format(
                snapshot_idx, core_idx, snapdir)
        fname = "/lustre/projects/p004_swin/bsmith/1.6Gpc/means/halo_1721673/dm_gadget/data/snapdir_020/snapshot_020.0.hdf5"

        print("Reading from file {0}".format(fname))
        with h5py.File(fname, 'r') as f:
            for type_idx in range(TypeMax):
                print("plotting ParticleType {0}".format(type_idx))
                tmp = "PartType{0}".format(type_idx)
                try:
                    part = f[tmp]['Coordinates'][:]
                except KeyError:
                    pass
                else:

                    if (do_slice == 1):
                        #w = np.where((part[:,2] > 800.0) & (part[:,2] < 804.0))[0]
                        w = np.where((part[:, 0] > 817.0)
                                     & (part[:, 1] < 779.0))[0]
                        print(
                            "There is {0} particles within this slice.".format(
                                len(w)))
                    else:
                        if (len(part) > dilute):
                            print(
                                "There are {0} particles and we are diluting it down to {1}"
                                .format(len(part), dilute))
                            w = sample(list(np.arange(0, len(part))), dilute)
    #                        w = np.sort(w)
                        else:
                            w = np.arange(0, len(part))

#                    print("The x coords range from [{0:.4f}, {1:.4f}]".format(min(part[:,0]), max(part[:,0])))
#                    print("The y coords range from [{0:.4f}, {1:.4f}]".format(min(part[:,1]), max(part[:,1])))
#                    print("The z coords range from [{0:.4f}, {1:.4f}]".format(min(part[:,2]), max(part[:,2])))

#                    ax1.scatter(part[w,0], part[w,1], marker = 'o', alpha = 0.5, color = PlotScripts.colors[type_idx-1], s = 1)

                    if (do_flip == 1):
                        #ax2.scatter(part[w,1], part[w,0], marker = 'o', alpha = 0.5, color = PlotScripts.colors[type_idx-1], s = 1)
                        ax2.scatter((part[w, 1] - 775.0), (part[w, 0] - 775.0),
                                    marker='o',
                                    alpha=0.5,
                                    color=PlotScripts.colors[type_idx - 1],
                                    s=1)
                    else:
                        #ax2.scatter(part[w,0] - 775.0, part[w,1] - 775.0, marker = 'o', alpha = 0.5, color = PlotScripts.colors[type_idx-1], s = 1)
                        ax2.scatter(part[w, 2] - 775.0,
                                    part[w, 0] - 775.0,
                                    marker='o',
                                    alpha=0.5,
                                    color=PlotScripts.colors[type_idx - 1],
                                    s=1)


#                        ax2.scatter((part[w,0] - 775.0), (part[w,1] - 775.0), marker = 'o', alpha = 0.5, color = PlotScripts.colors[type_idx-1], s = 1)

#ax2.add_patch(patches.Rectangle((817, 779), 1.0, 1.0, fill=False))
#ax2.add_patch(patches.Rectangle((45.0, 45.0), 5.0, 5.0, fill=False))
#ax2.add_patch(patches.Rectangle((10.0, 45.0), 5.0, 5.0, fill=False))

    ax2.add_patch(patches.Rectangle((45.0, 45.0), 5.0, 5.0, fill=False))
    ax2.add_patch(patches.Rectangle((45.0, 0.0), 5.0, 10.0, fill=False))

    for type_idx in range(1, TypeMax):  # PartType0 has no particles ever.
        label = 'PartType{0}'.format(type_idx)
        ax2.scatter(np.nan,
                    np.nan,
                    color=PlotScripts.colors[type_idx - 1],
                    label=label)

    #ax1.set_xlim([0, 1600])
    #ax1.set_ylim([0, 1600])

    #ax2.set_xlim([774, 827])
    #ax2.set_ylim([774, 827])

    ax2.set_xlim([0, 50])
    ax2.set_ylim([0, 50])

    #ax1.set_xlabel("")
    #ax1.set_ylabel("y [Mpc/h]")

    ax2.set_xlabel("z [Mpc/h]")
    ax2.set_ylabel("x [Mpc/h]")

    leg = ax2.legend(loc='upper left', numpoints=1, labelspacing=0.1)
    leg.draw_frame(False)  # Don't want a box frame
    for t in leg.get_texts():  # Reduce the size of the text
        t.set_fontsize(PlotScripts.global_legendsize)
        t.set_alpha(1)

    plt.tight_layout()

    if do_flip == 1:
        flip_tag = "flip"
    else:
        flip_tag = "noflip"

    if do_slice == 1:
        outputFile = './Slice_Core{2}_{0}{3}{1}'.format(
            snapshot_idx, output_format, core_idx, flip_tag)
    else:
        outputFile = './Grid_AllPart_Core{2}_{0}{3}{1}'.format(
            snapshot_idx, output_format, core_idx, flip_tag)

    outputFile = './Grid_AllPart_Snapshot20_chunk0_zx.png'
    plt.savefig(outputFile, bbox_inches='tight')  # Save the figure
    print('Saved file to {0}'.format(outputFile))
    plt.close()
コード例 #42
0
ファイル: plot_dirty_PCA.py プロジェクト: TheRiddle93/nchain
def plot_dirty_PCA(
        kinship_mat,
        figure_fn='pca.png',
        k_figure_fn='kinship_heatmap.png',
        title=None,
        pcs34=True,
        figure_dir='C:/Users/MariaIzabel/Desktop/MASTER/PHD/Bjarnicode',
        strains=None):
    from scipy import linalg

    evals, evecs = linalg.eig(kinship_mat)  #PCA via eigen decomp
    evals[evals < 0] = 0
    sort_indices = sp.argsort(evals, )
    ordered_evals = evals[sort_indices]
    print ordered_evals[-10:] / sp.sum(ordered_evals)
    pc1, pc2 = evecs[:, sort_indices[-1]], evecs[:, sort_indices[-2]]
    pc3, pc4 = evecs[:, sort_indices[-3]], evecs[:, sort_indices[-4]]
    if pcs34 == True:
        pc1 = pc3
        pc2 = pc4
    pylab.clf()

    tot = sum(evals)
    var_exp = [(i / tot) * 100 for i in sorted(evals, reverse=True)]
    np.savetxt('test.out', var_exp, delimiter=',')
    cum_var_exp = np.cumsum(var_exp)
    print cum_var_exp

    # Ploting the variance explained
    with plt.style.context('seaborn-whitegrid'):
        plt.figure(figsize=(6, 6))
        plt.bar(range(198),
                var_exp,
                alpha=1,
                align='center',
                label='individual explained variance')
        plt.step(range(198),
                 cum_var_exp,
                 where='mid',
                 label='cumulative explained variance')
        plt.ylabel('Explained variance ratio')
        plt.xlabel('Principal components')
        plt.legend(loc='best')
        #plt.tight_layout()
        plt.savefig('variance_explained_PC1234')
        plt.show()

    #Trying PCA 3D
    from mpl_toolkits.mplot3d import Axes3D
    from mpl_toolkits.mplot3d import proj3d

    fig = plt.figure(figsize=(8, 8))
    ax = fig.add_subplot(111, projection='3d')
    plt.rcParams['legend.fontsize'] = 10
    ax.plot(pc2,
            pc3,
            'o',
            markersize=8,
            color='blue',
            alpha=0.5,
            label='data points')
    plt.title('Principal Component Analysis (2 and 3)')
    ax.legend(loc='upper right')
    plt.xlabel('PC2 (' + str(round(var_exp[2])) + '%)')
    plt.ylabel('PC3 (' + str(round(var_exp[3])) + '%)')
    plt.savefig('PCA23_3D')

    if strains is not None:
        ct_marker_map = {'DK': '*', 'UK': '^', 'F': 'o', 'nan': 's'}
        gs_color_map = {
            'gsA': 'm',
            'gsB': 'g',
            'gsC': 'r',
            'gsE': 'b',
            'gsD': 'y',
            'nan': 'c'
        }
        pop_map = parse_pop_map()
        for i, strain in enumerate(strains):
            d = pop_map.get(strain, 'nan')
            if d == 'nan':
                gs = 'nan'
                country = 'nan'
                print 'na', strain, pc1[i], pc2[i]
            else:
                gs = d['genospecies']
                country = d['country']
            pylab.scatter(pc1[i],
                          pc2[i],
                          marker=ct_marker_map[country],
                          c=gs_color_map[gs],
                          alpha=0.3,
                          s=100,
                          edgecolor='none')
        for gs in gs_color_map:
            pylab.scatter([], [],
                          color=gs_color_map[gs],
                          marker='s',
                          label=gs,
                          s=100,
                          edgecolor='none')
        for country in ct_marker_map:
            if country != 'nan':
                pylab.scatter([], [],
                              color='k',
                              marker=ct_marker_map[country],
                              label=country,
                              s=100,
                              facecolors='none')

        pylab.legend(scatterpoints=1)

    else:
        pylab.plot(pc1, pc2, 'k.')
    if title is not None:
        pylab.title(title)
    pylab.xlabel('PC3')
    pylab.xlabel('PC4')
    pylab.tight_layout()
    pylab.savefig(figure_dir + '/' + figure_fn, format='pdf')
    pylab.clf()
    pylab.imshow(kinship_mat, cmap='hot', interpolation='nearest')
    pylab.savefig(figure_dir + '/' + k_figure_fn)
コード例 #43
0
ファイル: ceps.py プロジェクト: vlazzarini/instruments
import pylab as pl

def dft(s):
   N = len(s)
   out = pl.zeros(N)*1j;
   for k in range(0,N):
    for t in range(0, N):
     out[k] += s[t]*(pl.cos(2*pl.pi*k*t/N)
                     - 1j*pl.sin(2*pl.pi*k*t/N))
   return out/N

saw = pl.zeros(100)
t  = pl.arange(0,100)
T = 100
N = T // 2
for k in range(1,N):
    saw += (1/k)*pl.sin(2*pl.pi*k*t/T)
saw *= 2/(pl.pi)    

spec = dft(saw)
mags = abs(spec)
scal = max(mags)

pl.figure(figsize=(8,3))
pl.stem(t,mags/scal, 'k-', linewidth=1)
pl.ylim(0,1.1)
pl.tight_layout()
pl.show()

コード例 #44
0
ファイル: main05.py プロジェクト: JeffersonLab/txgrids
def plot_stf(target):

    data, tabnames, tag = get_data(target)

    #--collect data from different groups
    for tabname in tabnames:
        data[tabname] = {}
        nrep = data['nrep'][tabname]
        idxs = data['idx'][tabname]
        for q2 in Q2:
            data[tabname][q2] = {_: [] for _ in idxs}
        for i in range(nrep + 1):
            stf = lhapdf.mkPDF(tabname, i)
            for q2 in Q2:
                for idx in idxs:
                    F = np.array([x * stf.xfxQ2(idx, x, q2) for x in X])
                    data[tabname][q2][idx].append(F)

    #--plot data

    #--all channels
    nrows, ncols = 3, 3
    fig = py.figure(figsize=(ncols * 5, nrows * 3))

    cnt = 0
    for q2 in Q2:

        cnt += 1
        ax = py.subplot(nrows, ncols, cnt)
        ax.tick_params(axis='both',
                       which='both',
                       top=True,
                       right=True,
                       direction='in',
                       labelsize=20)
        for tabname in tabnames:
            if 908 not in data[tabname][q2]: continue
            for i in range(data['nrep'][tabname] + 1):
                if i == 0: label, alpha = data['label'][tabname], 1.0
                else: label, alpha = None, 0.1
                F2 = data[tabname][q2][908][i]
                ax.plot(X,
                        F2,
                        label=label,
                        color=data['color'][tabname],
                        alpha=alpha)
        #ax.set_ylim(0,2)
        ax.semilogx()
        ax.set_xticks([10e-5, 10e-4, 10e-3, 10e-2, 10e-1, 1])
        ax.axhline(0, 0, 1, ls='--', color='black', alpha=0.5)
        if cnt == 1:
            ax.legend(loc='lower left',
                      bbox_to_anchor=(0, 0.1),
                      frameon=False,
                      fontsize=15)
        if cnt == 1:
            ax.text(0.1,
                    0.7,
                    r'$xF_2^{(%s)}$' % tag,
                    size=35,
                    transform=ax.transAxes)
        if cnt == 7: ax.set_xlabel(r'$x$', size=20)
        ax.set_ylabel(r'$Q^2=%0.1f~{\rm GeV^2}$' % q2, size=20)

        cnt += 1
        ax = py.subplot(nrows, ncols, cnt)
        ax.tick_params(axis='both',
                       which='both',
                       top=True,
                       right=True,
                       direction='in',
                       labelsize=20)
        for tabname in tabnames:
            if 909 not in data[tabname][q2]: continue
            for i in range(data['nrep'][tabname] + 1):
                if i == 0: label, alpha = data['label'][tabname], 1.0
                else: label, alpha = None, 0.1
                FL = data[tabname][q2][909][i]
                ax.plot(X, FL, color=data['color'][tabname], alpha=alpha)
        #ax.set_ylim(0,0.3)
        ax.semilogx()
        ax.set_xticks([10e-5, 10e-4, 10e-3, 10e-2, 10e-1, 1])
        ax.axhline(0, 0, 1, ls='--', color='black', alpha=0.5)
        if cnt == 2:
            ax.text(0.1,
                    0.7,
                    r'$xF_L^{(%s)}$' % tag,
                    size=35,
                    transform=ax.transAxes)
        if cnt == 8: ax.set_xlabel(r'$x$', size=20)

        cnt += 1
        ax = py.subplot(nrows, ncols, cnt)
        ax.tick_params(axis='both',
                       which='both',
                       top=True,
                       right=True,
                       direction='in',
                       labelsize=20)
        for tabname in tabnames:
            if 910 not in data[tabname][q2]: continue
            for i in range(data['nrep'][tabname] + 1):
                if i == 0: label, alpha = data['label'][tabname], 1.0
                else: label, alpha = None, 0.1
                F3 = data[tabname][q2][910][i]
                ax.plot(X, F3, color=data['color'][tabname], alpha=alpha)
        ax.semilogx()
        ax.set_xticks([10e-5, 10e-4, 10e-3, 10e-2, 10e-1, 1])
        ax.axhline(0, 0, 1, ls='--', color='black', alpha=0.5)
        #ax.set_ylim(0,0.9)
        if cnt == 3:
            ax.text(0.1,
                    0.7,
                    r'$xF_3^{(%s)}$' % tag,
                    size=35,
                    transform=ax.transAxes)
        if cnt == 9: ax.set_xlabel(r'$x$', size=20)

    py.tight_layout()
    filename = 'gallery/%s/FX.png' % target
    py.savefig(filename)
    print('Saving figure to %s' % filename)
    py.clf()

    #--gamma channel
    nrows, ncols = 3, 2
    fig = py.figure(figsize=(ncols * 5, nrows * 3))

    cnt = 0
    for q2 in Q2:
        cnt += 1
        ax = py.subplot(nrows, ncols, cnt)
        ax.tick_params(axis='both',
                       which='both',
                       top=True,
                       right=True,
                       direction='in',
                       labelsize=20)
        for tabname in tabnames:
            if 900 not in data[tabname][q2]: continue
            for i in range(data['nrep'][tabname] + 1):
                if i == 0: label, alpha = data['label'][tabname], 1.0
                else: label, alpha = None, 0.1
                F2 = data[tabname][q2][900][i]
                ax.plot(X,
                        F2,
                        label=label,
                        color=data['color'][tabname],
                        alpha=alpha)
        #ax.set_ylim(0,2)
        ax.semilogx()
        ax.set_xticks([10e-5, 10e-4, 10e-3, 10e-2, 10e-1, 1])
        ax.axhline(0, 0, 1, ls='--', color='black', alpha=0.5)
        if cnt == 1:
            ax.legend(loc='lower left',
                      bbox_to_anchor=(0, 0.1),
                      frameon=False,
                      fontsize=15)
        if cnt == 1:
            ax.text(0.1,
                    0.7,
                    r'$xF_2^{(%s)\gamma}$' % tag,
                    size=35,
                    transform=ax.transAxes)
        if cnt == 7: ax.set_xlabel(r'$x$', size=20)
        ax.set_ylabel(r'$Q^2=%0.1f~{\rm GeV^2}$' % q2, size=20)

        cnt += 1
        ax = py.subplot(nrows, ncols, cnt)
        ax.tick_params(axis='both',
                       which='both',
                       top=True,
                       right=True,
                       direction='in',
                       labelsize=20)
        for tabname in tabnames:
            if 901 not in data[tabname][q2]: continue
            for i in range(data['nrep'][tabname] + 1):
                if i == 0: label, alpha = data['label'][tabname], 1.0
                else: label, alpha = None, 0.1
                FL = data[tabname][q2][901][i]
                ax.plot(X, FL, color=data['color'][tabname], alpha=alpha)
        #ax.set_ylim(0,0.3)
        ax.semilogx()
        ax.set_xticks([10e-5, 10e-4, 10e-3, 10e-2, 10e-1, 1])
        ax.axhline(0, 0, 1, ls='--', color='black', alpha=0.5)
        if cnt == 2:
            ax.text(0.1,
                    0.7,
                    r'$xF_L^{(%s)\gamma}$' % tag,
                    size=35,
                    transform=ax.transAxes)
        if cnt == 8: ax.set_xlabel(r'$x$', size=20)

    py.tight_layout()
    filename = 'gallery/%s/FXg.png' % target
    py.savefig(filename)
    print('Saving figure to %s' % filename)
    py.clf()

    #--Z channel
    nrows, ncols = 3, 3
    fig = py.figure(figsize=(ncols * 5, nrows * 3))

    cnt = 0
    for q2 in Q2:

        cnt += 1
        ax = py.subplot(nrows, ncols, cnt)
        ax.tick_params(axis='both',
                       which='both',
                       top=True,
                       right=True,
                       direction='in',
                       labelsize=20)
        for tabname in tabnames:
            if 905 not in data[tabname][q2]: continue
            for i in range(data['nrep'][tabname] + 1):
                if i == 0: label, alpha = data['label'][tabname], 1.0
                else: label, alpha = None, 0.1
                F2 = data[tabname][q2][905][i]
                ax.plot(X,
                        F2,
                        label=label,
                        color=data['color'][tabname],
                        alpha=alpha)
        #ax.set_ylim(0,2)
        ax.semilogx()
        ax.set_xticks([10e-5, 10e-4, 10e-3, 10e-2, 10e-1, 1])
        ax.axhline(0, 0, 1, ls='--', color='black', alpha=0.5)
        if cnt == 1:
            ax.legend(loc='lower left',
                      bbox_to_anchor=(0, 0.1),
                      frameon=False,
                      fontsize=15)
        if cnt == 1:
            ax.text(0.1,
                    0.7,
                    r'$xF_2^{(%s)Z}$' % tag,
                    size=35,
                    transform=ax.transAxes)
        if cnt == 7: ax.set_xlabel(r'$x$', size=20)
        ax.set_ylabel(r'$Q^2=%0.1f~{\rm GeV^2}$' % q2, size=20)

        cnt += 1
        ax = py.subplot(nrows, ncols, cnt)
        ax.tick_params(axis='both',
                       which='both',
                       top=True,
                       right=True,
                       direction='in',
                       labelsize=20)
        for tabname in tabnames:
            if 906 not in data[tabname][q2]: continue
            for i in range(data['nrep'][tabname] + 1):
                if i == 0: label, alpha = data['label'][tabname], 1.0
                else: label, alpha = None, 0.1
                FL = data[tabname][q2][906][i]
                ax.plot(X, FL, color=data['color'][tabname], alpha=alpha)
        #ax.set_ylim(0,0.3)
        ax.semilogx()
        ax.set_xticks([10e-5, 10e-4, 10e-3, 10e-2, 10e-1, 1])
        ax.axhline(0, 0, 1, ls='--', color='black', alpha=0.5)
        if cnt == 2:
            ax.text(0.1,
                    0.7,
                    r'$xF_L^{(%s)Z}$' % tag,
                    size=35,
                    transform=ax.transAxes)
        if cnt == 8: ax.set_xlabel(r'$x$', size=20)

        cnt += 1
        ax = py.subplot(nrows, ncols, cnt)
        ax.tick_params(axis='both',
                       which='both',
                       top=True,
                       right=True,
                       direction='in',
                       labelsize=20)
        for tabname in tabnames:
            if 907 not in data[tabname][q2]: continue
            for i in range(data['nrep'][tabname] + 1):
                if i == 0: label, alpha = data['label'][tabname], 1.0
                else: label, alpha = None, 0.1
                F3 = data[tabname][q2][907][i]
                ax.plot(X, F3, color=data['color'][tabname], alpha=alpha)
        ax.semilogx()
        ax.set_xticks([10e-5, 10e-4, 10e-3, 10e-2, 10e-1, 1])
        ax.axhline(0, 0, 1, ls='--', color='black', alpha=0.5)
        #ax.set_ylim(0,0.9)
        if cnt == 3:
            ax.text(0.1,
                    0.7,
                    r'$xF_3^{(%s)Z}$' % tag,
                    size=35,
                    transform=ax.transAxes)
        if cnt == 9: ax.set_xlabel(r'$x$', size=20)

    py.tight_layout()
    filename = 'gallery/%s/FXZ.png' % target
    py.savefig(filename)
    print('Saving figure to %s' % filename)
    py.clf()

    #--gamma/Z channel
    nrows, ncols = 3, 3
    fig = py.figure(figsize=(ncols * 5, nrows * 3))

    cnt = 0
    for q2 in Q2:

        cnt += 1
        ax = py.subplot(nrows, ncols, cnt)
        ax.tick_params(axis='both',
                       which='both',
                       top=True,
                       right=True,
                       direction='in',
                       labelsize=20)
        for tabname in tabnames:
            if 902 not in data[tabname][q2]: continue
            for i in range(data['nrep'][tabname] + 1):
                if i == 0: label, alpha = data['label'][tabname], 1.0
                else: label, alpha = None, 0.1
                F2 = data[tabname][q2][902][i]
                ax.plot(X,
                        F2,
                        label=label,
                        color=data['color'][tabname],
                        alpha=alpha)
        #ax.set_ylim(0,2)
        ax.semilogx()
        ax.set_xticks([10e-5, 10e-4, 10e-3, 10e-2, 10e-1, 1])
        ax.axhline(0, 0, 1, ls='--', color='black', alpha=0.5)
        if cnt == 1:
            ax.legend(loc='lower left',
                      bbox_to_anchor=(0, 0.1),
                      frameon=False,
                      fontsize=15)
        if cnt == 1:
            ax.text(0.1,
                    0.7,
                    r'$xF_2^{(%s)\gamma Z}$' % tag,
                    size=35,
                    transform=ax.transAxes)
        if cnt == 7: ax.set_xlabel(r'$x$', size=20)
        ax.set_ylabel(r'$Q^2=%0.1f~{\rm GeV^2}$' % q2, size=20)

        cnt += 1
        ax = py.subplot(nrows, ncols, cnt)
        ax.tick_params(axis='both',
                       which='both',
                       top=True,
                       right=True,
                       direction='in',
                       labelsize=20)
        for tabname in tabnames:
            if 903 not in data[tabname][q2]: continue
            for i in range(data['nrep'][tabname] + 1):
                if i == 0: label, alpha = data['label'][tabname], 1.0
                else: label, alpha = None, 0.1
                FL = data[tabname][q2][903][i]
                ax.plot(X, FL, color=data['color'][tabname], alpha=alpha)
        #ax.set_ylim(0,0.3)
        ax.semilogx()
        ax.set_xticks([10e-5, 10e-4, 10e-3, 10e-2, 10e-1, 1])
        ax.axhline(0, 0, 1, ls='--', color='black', alpha=0.5)
        if cnt == 2:
            ax.text(0.1,
                    0.7,
                    r'$xF_L^{(%s)\gamma Z}$' % tag,
                    size=35,
                    transform=ax.transAxes)
        if cnt == 8: ax.set_xlabel(r'$x$', size=20)

        cnt += 1
        ax = py.subplot(nrows, ncols, cnt)
        ax.tick_params(axis='both',
                       which='both',
                       top=True,
                       right=True,
                       direction='in',
                       labelsize=20)
        for tabname in tabnames:
            if 904 not in data[tabname][q2]: continue
            for i in range(data['nrep'][tabname] + 1):
                if i == 0: label, alpha = data['label'][tabname], 1.0
                else: label, alpha = None, 0.1
                F3 = data[tabname][q2][904][i]
                ax.plot(X, F3, color=data['color'][tabname], alpha=alpha)
        #ax.set_ylim(0,0.25)
        ax.semilogx()
        ax.set_xticks([10e-5, 10e-4, 10e-3, 10e-2, 10e-1, 1])
        ax.axhline(0, 0, 1, ls='--', color='black', alpha=0.5)
        if cnt == 3:
            ax.text(0.1,
                    0.7,
                    r'$xF_3^{(%s)\gamma Z}$' % tag,
                    size=35,
                    transform=ax.transAxes)
        if cnt == 9: ax.set_xlabel(r'$x$', size=20)

    py.tight_layout()
    filename = 'gallery/%s/FXgZ.png' % target
    py.savefig(filename)
    print('Saving figure to %s' % filename)
    py.clf()

    #--no charged current for deuteron/helium
    if target == 'deuteron': return
    if target == 'helium': return

    #--W plus
    nrows, ncols = 3, 3
    fig = py.figure(figsize=(ncols * 5, nrows * 3))

    cnt = 0
    for q2 in Q2:

        cnt += 1
        ax = py.subplot(nrows, ncols, cnt)
        ax.tick_params(axis='both',
                       which='both',
                       top=True,
                       right=True,
                       direction='in',
                       labelsize=20)
        for tabname in tabnames:
            if 940 not in data[tabname][q2]: continue
            for i in range(data['nrep'][tabname] + 1):
                if i == 0: label, alpha = data['label'][tabname], 1.0
                else: label, alpha = None, 0.1
                F2 = data[tabname][q2][940][i]
                ax.plot(X,
                        F2,
                        label=label,
                        color=data['color'][tabname],
                        alpha=alpha)
        #ax.set_ylim(0,12)
        ax.semilogx()
        ax.set_xticks([10e-5, 10e-4, 10e-3, 10e-2, 10e-1, 1])
        ax.axhline(0, 0, 1, ls='--', color='black', alpha=0.5)
        if cnt == 1:
            ax.legend(loc='lower left',
                      bbox_to_anchor=(0, 0.1),
                      frameon=False,
                      fontsize=15)
        if cnt == 1:
            ax.text(0.1,
                    0.7,
                    r'$xF_2^{(%s)W^+}$' % tag,
                    size=35,
                    transform=ax.transAxes)
        if cnt == 7: ax.set_xlabel(r'$x$', size=20)
        ax.set_ylabel(r'$Q^2=%0.1f~{\rm GeV^2}$' % q2, size=20)

        cnt += 1
        ax = py.subplot(nrows, ncols, cnt)
        ax.tick_params(axis='both',
                       which='both',
                       top=True,
                       right=True,
                       direction='in',
                       labelsize=20)
        for tabname in tabnames:
            if 941 not in data[tabname][q2]: continue
            for i in range(data['nrep'][tabname] + 1):
                if i == 0: label, alpha = data['label'][tabname], 1.0
                else: label, alpha = None, 0.1
                FL = data[tabname][q2][941][i]
                ax.plot(X, FL, color=data['color'][tabname], alpha=alpha)
        #ax.set_ylim(0,2.5)
        ax.semilogx()
        ax.set_xticks([10e-5, 10e-4, 10e-3, 10e-2, 10e-1, 1])
        ax.axhline(0, 0, 1, ls='--', color='black', alpha=0.5)
        if cnt == 2:
            ax.text(0.1,
                    0.7,
                    r'$xF_L^{(%s)W^+}$' % tag,
                    size=35,
                    transform=ax.transAxes)
        if cnt == 8: ax.set_xlabel(r'$x$', size=20)

        cnt += 1
        ax = py.subplot(nrows, ncols, cnt)
        ax.tick_params(axis='both',
                       which='both',
                       top=True,
                       right=True,
                       direction='in',
                       labelsize=20)
        for tabname in tabnames:
            if 942 not in data[tabname][q2]: continue
            for i in range(data['nrep'][tabname] + 1):
                if i == 0: label, alpha = data['label'][tabname], 1.0
                else: label, alpha = None, 0.1
                F3 = data[tabname][q2][942][i]
                ax.plot(X, F3, color=data['color'][tabname], alpha=alpha)
        #ax.set_ylim(0,20)
        ax.semilogx()
        ax.set_xticks([10e-5, 10e-4, 10e-3, 10e-2, 10e-1, 1])
        ax.axhline(0, 0, 1, ls='--', color='black', alpha=0.5)
        if cnt == 3:
            ax.text(0.1,
                    0.7,
                    r'$xF_3^{(%s)W^+}$' % tag,
                    size=35,
                    transform=ax.transAxes)
        if cnt == 9: ax.set_xlabel(r'$x$', size=20)

    py.tight_layout()
    filename = 'gallery/%s/WXp.png' % target
    py.savefig(filename)
    print('Saving figure to %s' % filename)
    py.clf()

    #--W minus
    nrows, ncols = 3, 3
    fig = py.figure(figsize=(ncols * 5, nrows * 3))

    cnt = 0
    for q2 in Q2:

        cnt += 1
        ax = py.subplot(nrows, ncols, cnt)
        ax.tick_params(axis='both',
                       which='both',
                       top=True,
                       right=True,
                       direction='in',
                       labelsize=20)
        for tabname in tabnames:
            if 930 not in data[tabname][q2]: continue
            for i in range(data['nrep'][tabname] + 1):
                if i == 0: label, alpha = data['label'][tabname], 1.0
                else: label, alpha = None, 0.1
                F2 = data[tabname][q2][930][i]
                ax.plot(X,
                        F2,
                        label=label,
                        color=data['color'][tabname],
                        alpha=alpha)
        #ax.set_ylim(0,12)
        ax.semilogx()
        ax.set_xticks([10e-5, 10e-4, 10e-3, 10e-2, 10e-1, 1])
        ax.axhline(0, 0, 1, ls='--', color='black', alpha=0.5)
        if cnt == 1:
            ax.legend(loc='lower left',
                      bbox_to_anchor=(0, 0.1),
                      frameon=False,
                      fontsize=15)
        if cnt == 1:
            ax.text(0.1,
                    0.7,
                    r'$xF_2^{(%s)W^-}$' % tag,
                    size=35,
                    transform=ax.transAxes)
        if cnt == 7: ax.set_xlabel(r'$x$', size=20)
        ax.set_ylabel(r'$Q^2=%0.1f~{\rm GeV^2}$' % q2, size=20)

        cnt += 1
        ax = py.subplot(nrows, ncols, cnt)
        ax.tick_params(axis='both',
                       which='both',
                       top=True,
                       right=True,
                       direction='in',
                       labelsize=20)
        for tabname in tabnames:
            if 931 not in data[tabname][q2]: continue
            for i in range(data['nrep'][tabname] + 1):
                if i == 0: label, alpha = data['label'][tabname], 1.0
                else: label, alpha = None, 0.1
                FL = data[tabname][q2][931][i]
                ax.plot(X, FL, color=data['color'][tabname], alpha=alpha)
        #ax.set_ylim(0,2.5)
        ax.semilogx()
        ax.set_xticks([10e-5, 10e-4, 10e-3, 10e-2, 10e-1, 1])
        ax.axhline(0, 0, 1, ls='--', color='black', alpha=0.5)
        if cnt == 2:
            ax.text(0.1,
                    0.7,
                    r'$xF_L^{(%s)W^-}$' % tag,
                    size=35,
                    transform=ax.transAxes)
        if cnt == 8: ax.set_xlabel(r'$x$', size=20)

        cnt += 1
        ax = py.subplot(nrows, ncols, cnt)
        ax.tick_params(axis='both',
                       which='both',
                       top=True,
                       right=True,
                       direction='in',
                       labelsize=20)
        for tabname in tabnames:
            if 932 not in data[tabname][q2]: continue
            for i in range(data['nrep'][tabname] + 1):
                if i == 0: label, alpha = data['label'][tabname], 1.0
                else: label, alpha = None, 0.1
                F3 = data[tabname][q2][932][i]
                ax.plot(X, F3, color=data['color'][tabname], alpha=alpha)
        ax.semilogx()
        ax.set_xticks([10e-5, 10e-4, 10e-3, 10e-2, 10e-1, 1])
        ax.axhline(0, 0, 1, ls='--', color='black', alpha=0.5)
        #ax.set_ylim(0,20)
        if cnt == 3:
            ax.text(0.1,
                    0.7,
                    r'$xF_3^{(%s)W^-}$' % tag,
                    size=35,
                    transform=ax.transAxes)
        if cnt == 9: ax.set_xlabel(r'$x$', size=20)

    py.tight_layout()
    filename = 'gallery/%s/WXm.png' % target
    py.savefig(filename)
    print('Saving figure to %s' % filename)
    py.clf()
コード例 #45
0
    def __init__(self):
        fig = pp.figure(figsize=(10, 6))
        self.States = np.load('States.npy')
        self.Covariances = np.load('Covariances.npy')
        self.times = np.load('Times.npy')
        self.IncomingTMass = np.load('Incoming.npy', )
        self.tau_s0s = np.load('tau_s.npy', )
        self.Q = np.load('Q.npy')
        self.T = np.load('Turbidity.npy')

        ax1 = pp.subplot2grid((4, 3), (0, 0), colspan=2, rowspan=2)
        ax1.plot(self.times, self.Q, 'k--', label='Measured Flow')
        ax1.set_ylabel('Applied Shear (Pa)')
        self.line1 = Line2D([], [], color='red')
        self.line1a = Line2D([], [], color='red', alpha=0.5)
        self.line1b = Line2D([], [], color='red', alpha=0.5)
        ax1.add_line(self.line1)
        ax1.add_line(self.line1a)
        ax1.add_line(self.line1b)

        ax2 = pp.subplot2grid((4, 3), (2, 0), colspan=2, rowspan=2)
        ax2.plot(self.times, self.T, 'k--', label='Measured Turbidity')
        ax2.set_ylabel('Turbidity (turbidity units)')
        ax2.set_xlabel('Time (time units)')
        self.line2 = Line2D([], [], color='red')
        self.line2a = Line2D([], [], color='red', alpha=0.5)
        self.line2b = Line2D([], [], color='red', alpha=0.5)

        ax2.add_line(self.line2)
        ax2.add_line(self.line2a)
        ax2.add_line(self.line2b)

        self.ax3 = pp.subplot2grid((4, 3), (0, 2))
        self.ax3.set_xlabel('Upstream Turbidity (turbidity units)')
        self.ax3.set_ylim(0, 10)

        self.line3 = Line2D([], [], color='red')
        self.line3a = Line2D([], [], color='black', linestyle='--')
        self.ax3.add_line(self.line3)
        self.ax3.add_line(self.line3a)

        self.ax4 = pp.subplot2grid((4, 3), (1, 2))
        self.ax4.set_xlabel('tau_s (N/m2)')
        self.ax4.set_ylim(0, 10.)

        self.line4 = Line2D([], [], color='red')
        self.line4a = Line2D([], [], color='black', linestyle='--')
        self.ax4.add_line(self.line4)
        self.ax4.add_line(self.line4a)

        self.ax5 = pp.subplot2grid((4, 3), (2, 2))
        self.ax5.plot([5, 5], [0, 1000000000], 'k--')
        self.ax5.set_xlabel('alpha (mass/m2)')
        self.line5 = Line2D([], [], color='red')
        self.ax5.add_line(self.line5)

        self.ax6 = pp.subplot2grid((4, 3), (3, 2))
        self.ax6.plot([0.2, 0.2], [0, 100000000], 'k--')
        self.ax6.set_xlabel('beta (1/s)')
        self.line6 = Line2D([], [], color='red')
        self.ax6.add_line(self.line6)

        pp.tight_layout()
        animation.TimedAnimation.__init__(self, fig, interval=50, blit=False)
コード例 #46
0
def ex_adjust():

    import numpy as np
    import pylab as pl

    ###########################################################################
    # 1d Example ##############################################################
    ###########################################################################

    # gage and radar coordinates
    obs_coords = np.array([5, 10, 15, 20, 30, 45, 65, 70, 77, 90])
    radar_coords = np.arange(0, 101)

    # true rainfall
    truth = np.abs(1.5 + np.sin(0.075 * radar_coords)) + np.random.uniform(
        -0.1, 0.1, len(radar_coords))

    # radar error
    erroradd = 0.7 * np.sin(0.2 * radar_coords + 10.)
    errormult = 0.75 + 0.015 * radar_coords
    noise = np.random.uniform(-0.05, 0.05, len(radar_coords))

    # radar observation
    radar = errormult * truth + erroradd + noise

    # gage observations are assumed to be perfect
    obs = truth[obs_coords]

    # add a missing value to observations (just for testing)
    obs[1] = np.nan

    # number of neighbours to be used
    nnear_raws = 3

    # adjust the radar observation by additive model
    add_adjuster = adjust.AdjustAdd(obs_coords,
                                    radar_coords,
                                    nnear_raws=nnear_raws)
    add_adjusted = add_adjuster(obs, radar)

    # adjust the radar observation by multiplicative model
    mult_adjuster = adjust.AdjustMultiply(obs_coords,
                                          radar_coords,
                                          nnear_raws=nnear_raws)
    mult_adjusted = mult_adjuster(obs, radar)

    # adjust the radar observation by MFB
    mfb_adjuster = adjust.AdjustMFB(obs_coords,
                                    radar_coords,
                                    nnear_raws=nnear_raws)
    mfb_adjusted = mfb_adjuster(obs, radar)

    # adjust the radar observation by AdjustMixed
    mixed_adjuster = adjust.AdjustMixed(obs_coords,
                                        radar_coords,
                                        nnear_raws=nnear_raws)
    mixed_adjusted = mixed_adjuster(obs, radar)

    # plotting
    pl.plot(radar_coords,
            radar,
            'k-',
            label="Unadjusted radar",
            linewidth=2.,
            linestyle="dashed")
    pl.xlabel("Distance (km)")
    pl.ylabel("Rainfall intensity (mm/h)")
    pl.plot(radar_coords, truth, 'k-', label="True rainfall", linewidth=2.)
    pl.plot(obs_coords,
            obs,
            'o',
            label="Gage observation",
            markersize=10.0,
            markerfacecolor="grey")
    pl.plot(radar_coords,
            add_adjusted,
            '-',
            color="red",
            label="Additive adjustment")
    pl.plot(radar_coords,
            mult_adjusted,
            '-',
            color="green",
            label="Multiplicative adjustment")
    pl.plot(radar_coords,
            mfb_adjusted,
            '-',
            color="orange",
            label="Mean Field Bias adjustment")
    pl.plot(radar_coords,
            mixed_adjusted,
            '-',
            color="blue",
            label="Mixed (mult./add.) adjustment")
    pl.legend(prop={'size': 12})

    pl.show()

    # Verification for this example
    rawerror = verify.ErrorMetrics(truth, radar)
    mfberror = verify.ErrorMetrics(truth, mfb_adjusted)
    adderror = verify.ErrorMetrics(truth, add_adjusted)
    multerror = verify.ErrorMetrics(truth, mult_adjusted)
    mixerror = verify.ErrorMetrics(truth, mixed_adjusted)

    # Verification reports
    maxval = 4.
    fig = pl.figure(figsize=(14, 8))
    ax = fig.add_subplot(231, aspect=1.)
    rawerror.report(ax=ax, unit="mm", maxval=maxval)
    ax.text(0.2, 0.9 * maxval, "Unadjusted radar")
    ax = fig.add_subplot(232, aspect=1.)
    adderror.report(ax=ax, unit="mm", maxval=maxval)
    ax.text(0.2, 0.9 * maxval, "Additive adjustment")
    ax = fig.add_subplot(233, aspect=1.)
    multerror.report(ax=ax, unit="mm", maxval=maxval)
    ax.text(0.2, 0.9 * maxval, "Multiplicative adjustment")
    ax = fig.add_subplot(234, aspect=1.)
    mixerror.report(ax=ax, unit="mm", maxval=maxval)
    ax.text(0.2, 0.9 * maxval, "Mixed (mult./add.) adjustment")
    mixerror.report(ax=ax, unit="mm", maxval=maxval)
    ax = fig.add_subplot(235, aspect=1.)
    mfberror.report(ax=ax, unit="mm", maxval=maxval)
    ax.text(0.2, 0.9 * maxval, "Mean Field Bias adjustment")

    pl.show()

    ###########################################################################
    # 2d Example ##############################################################
    ###########################################################################

    # a) CREATE SYNTHETIC DATA ------------------------------------------------

    # grid axes
    xgrid = np.arange(0, 10)
    ygrid = np.arange(20, 30)

    # number of observations
    num_obs = 10

    # create grid
    gridshape = len(xgrid), len(ygrid)
    grid_coords = util.gridaspoints(ygrid, xgrid)

    # Synthetic true rainfall
    truth = np.abs(10. * np.sin(0.1 * grid_coords).sum(axis=1))

    # Creating radar data by perturbing truth with multiplicative and additive error
    # YOU CAN EXPERIMENT WITH THE ERROR STRUCTURE
    radar = 0.6 * truth + 1. * np.random.uniform(
        low=-1., high=1, size=len(truth))
    radar[radar < 0.] = 0.

    # indices for creating obs from raw (random placement of gauges)
    obs_ix = np.random.uniform(low=0, high=len(grid_coords),
                               size=num_obs).astype('i4')

    # creating obs_coordinates
    obs_coords = grid_coords[obs_ix]

    # creating gauge observations from truth
    obs = truth[obs_ix]

    # b) GAUGE ADJUSTMENT -----------------------------------------------------

    # Mean Field Bias Adjustment
    mfbadjuster = adjust.AdjustMFB(obs_coords, grid_coords)
    mfbadjusted = mfbadjuster(obs, radar)

    # Additive Error Model
    addadjuster = adjust.AdjustAdd(obs_coords, grid_coords)
    addadjusted = addadjuster(obs, radar)

    # Multiplicative Error Model
    multadjuster = adjust.AdjustMultiply(obs_coords, grid_coords)
    multadjusted = multadjuster(obs, radar)

    # c) PLOTTING

    # Maximum value (used for normalisation of colorscales)
    maxval = np.max(np.concatenate((truth, radar, obs, addadjusted)).ravel())

    # Helper functions for repeated plotting tasks
    def scatterplot(x, y, title):
        """Quick and dirty helper function to produce scatter plots
        """
        pl.scatter(x, y)
        pl.plot([0, 1.2 * maxval], [0, 1.2 * maxval], '-', color='grey')
        pl.xlabel("True rainfall (mm)")
        pl.ylabel("Estimated rainfall (mm)")
        pl.xlim(0, maxval + 0.1 * maxval)
        pl.ylim(0, maxval + 0.1 * maxval)
        pl.title(title)

    def gridplot(data, title):
        """Quick and dirty helper function to produce a grid plot
        """
        xplot = np.append(xgrid, xgrid[-1] + 1.) - 0.5
        yplot = np.append(ygrid, ygrid[-1] + 1.) - 0.5
        grd = ax.pcolormesh(xplot,
                            yplot,
                            data.reshape(gridshape),
                            vmin=0,
                            vmax=maxval)
        ax.scatter(obs_coords[:, 0],
                   obs_coords[:, 1],
                   c=obs.ravel(),
                   marker='s',
                   s=50,
                   vmin=0,
                   vmax=maxval)
        pl.colorbar(grd, shrink=0.7)
        pl.title(title)

    # open figure
    fig = pl.figure(figsize=(10, 10))

    # True rainfall
    ax = fig.add_subplot(331, aspect='equal')
    gridplot(truth, 'True rainfall')

    # Unadjusted radar rainfall
    ax = fig.add_subplot(332, aspect='equal')
    gridplot(radar, 'Radar rainfall')

    # Scatter plot radar vs. observations
    ax = fig.add_subplot(333, aspect='equal')
    scatterplot(truth, radar, 'Radar vs. Truth (red: Gauges)')
    pl.plot(obs, radar[obs_ix], linestyle="None", marker="o", color="red")

    # Adjusted radar rainfall (MFB)
    ax = fig.add_subplot(334, aspect='equal')
    gridplot(mfbadjusted, 'Adjusted (MFB)')

    # Adjusted radar rainfall (additive)
    ax = fig.add_subplot(335, aspect='equal')
    gridplot(addadjusted, 'Adjusted (Add.)')

    # Adjusted radar rainfall (multiplicative)
    ax = fig.add_subplot(336, aspect='equal')
    gridplot(multadjusted, 'Adjusted (Mult.)')

    # Adjusted (MFB) vs. radar (for control purposes)
    ax = fig.add_subplot(337, aspect='equal')
    #scatterplot(obs, mfbadjusted[obs_ix], 'Adjusted (MFB) vs. Gauges\n(no x-validation!)')
    scatterplot(truth, mfbadjusted, 'Adjusted (MFB) vs. Truth')

    # Adjusted (Add) vs. radar (for control purposes)
    ax = fig.add_subplot(338, aspect='equal')
    #scatterplot(obs, addadjusted[obs_ix], 'Adjusted (Add.) vs. Gauges\n(no x-validation!)')
    scatterplot(truth, addadjusted, 'Adjusted (Add.) vs. Truth')

    # Adjusted (Mult.) vs. radar (for control purposes)
    ax = fig.add_subplot(339, aspect='equal')
    #scatterplot(obs, multadjusted[obs_ix], 'Adjusted (Mult.) vs. Gauges\n(no x-validation!)')
    scatterplot(truth, multadjusted, 'Adjusted (Mult.) vs. Truth')

    pl.tight_layout()
    pl.show()
コード例 #47
0
ax0 = fig.add_subplot(221)
ax1 = fig.add_subplot(222)
ax2 = fig.add_subplot(223)
ax3 = fig.add_subplot(224)
# %% Import Lena

lena = cv2.imread("zelda.tif")
lena = cv2.cvtColor(lena, cv2.COLOR_RGB2GRAY)  # RGBtoGray
lena = cv2.normalize(lena.astype("float"), None, 0, 1,
                     cv2.NORM_MINMAX)  # mat2gray
plt.gray()
plt.subplot(2, 2, 1)
plt.subplot(2, 2, 2)
plt.subplot(2, 2, 3)
plt.subplot(2, 2, 4)
plt.tight_layout(pad=1.2)
# plt.imshow(lena)

flag_record = 1
width = 128
image = np.zeros((width, width))
image_fusion = np.zeros((width * 2, width * 2))
bead_volume_bool = np.empty((width, width, width), bool)
radius = 6
beads = 8

fov = np.arange(-width / 2, width / 2, 1)

[x, y, z] = np.meshgrid(fov, fov, fov)

# r = np.sqrt(x**2 + y**2)
コード例 #48
0
    def bench(self, data, plot=True, get=False):
        """ Function to test drift rate search
			note this bench mark contains compilation times and multiple kernel calls. 
			larger input would be faster. 
		"""
        start = cu.Event()
        copy_htod = cu.Event()
        compute = cu.Event()
        stop = cu.Event()

        start.record()
        self.spectr_d = gpuarray.to_gpu(data)
        copy_htod.record()
        copy_htod.synchronize()
        self.sweep_kernel(self.spectr_d,
                          self.output_d,
                          self.delay_table_d,
                          self.nfreqs,
                          self.ntimes,
                          self.ndelays,
                          block=self.block_size,
                          grid=self.grid_size)
        compute.record()
        compute.synchronize()

        if get:
            out = self.output_d.get()
        else:
            operand = self.output_d[self.ndelays // 2]
            mean = gpuarray.sum(operand / np.float32(self.nfreqs)).get()
            var = gpuarray.sum(
                (operand - mean) * (operand - mean) / np.float32(self.nfreqs))
            std = np.sqrt(var.get())
            self.threshold_kernel(self.output_d,
                                  self.mask_d,
                                  np.float32(3 * std + mean),
                                  self.nfreqs,
                                  self.ndelays,
                                  block=self.block_size,
                                  grid=self.grid_size)
            out = (self.output_d * self.mask_d).get()

        stop.record()
        stop.synchronize()

        print "{} seconds to load data".format(
            start.time_till(copy_htod) * 1.e-3)
        print "{} seconds to compute {} channels, with {} delays".format(
            copy_htod.time_till(compute) * 1.e-3, self.nfreqs, self.ndelays)
        print copy_htod.time_till(compute) / (
            self.nfreqs *
            self.ndelays) * 1.e6, "nanoseconds per channel, per delay"
        if plot:
            import pylab as plt
            f, axes = plt.subplots(2, 1)
            axes[0].imshow(
                data,
                aspect='auto',
                extent=[0, self.nfreqs, 0, self.ntimes * self.delta_t],
                origin='lower')
            axes[0].set_xlabel('Freq [Hz]')
            axes[0].set_ylabel('Time [s]')
            axes[1].imshow(out,
                           aspect='auto',
                           extent=[0, self.nfreqs, -0.1, 0.1],
                           origin='lower')
            axes[1].set_xlabel('Freq [Hz]')
            axes[1].set_ylabel('Drift [Hz/s]')
            plt.tight_layout()
            plt.show()
        return out
コード例 #49
0
    def table_visulization(self):
        outcome_dataframe = self.outcome_dataframe
        factor_filtered_list = list(set(outcome_dataframe["FactorPortfolio"]))
        market_filtered_list = list(
            set(outcome_dataframe["MarketValuePortfolio"]))
        factor_count, market_count = len(factor_filtered_list), len(
            market_filtered_list)

        indicator = [
            'annual_return', 'annual_volatility', 'annual_sharpe',
            'max_retrace', 'max_retrace_date', 'max_win_streak_number',
            'max_lose_streak_number', 'profit_to_lose_percentage',
            'profit_to_lose', 'turnover_rate'
        ]

        data_storage = pd.DataFrame(np.zeros(
            (factor_count * market_count, len(indicator))),
                                    index=[(x, y) for x in factor_filtered_list
                                           for y in market_filtered_list],
                                    columns=indicator)

        for factorIndex in range(factor_count):
            for marketIndex in range(market_count):
                profit_series = outcome_dataframe["ret"][
                    (outcome_dataframe["FactorPortfolio"] ==
                     factor_filtered_list[factorIndex])
                    & (outcome_dataframe["MarketValuePortfolio"] ==
                       market_filtered_list[marketIndex])]

                symbol_series = outcome_dataframe["symbols"][
                    (outcome_dataframe["FactorPortfolio"] ==
                     factor_filtered_list[factorIndex])
                    & (outcome_dataframe["MarketValuePortfolio"] ==
                       market_filtered_list[marketIndex])]

                return_temp = profit_series.apply(lambda x: (1 + x)).product()
                data_storage['annual_return'][(factor_filtered_list[factorIndex], market_filtered_list[marketIndex])] = \
                    return_temp**(252/len(profit_series)) - 1
                data_storage['annual_volatility'][(factor_filtered_list[factorIndex], market_filtered_list[marketIndex])] = \
                    profit_series.std()*np.sqrt(252)
                data_storage['annual_sharpe'][(factor_filtered_list[factorIndex], market_filtered_list[marketIndex])] = \
                    profit_series.mean()/profit_series.std()*np.sqrt(252)
                max_retrace = profit_series.min()
                data_storage['max_retrace'][(
                    factor_filtered_list[factorIndex],
                    market_filtered_list[marketIndex])] = max_retrace
                data_storage['max_retrace_date'][(factor_filtered_list[factorIndex], market_filtered_list[marketIndex])] = \
                    outcome_dataframe['trade_date'][(outcome_dataframe['ret'] == max_retrace)].to_string()

                data_storage['max_win_streak_number'][(factor_filtered_list[factorIndex], market_filtered_list[marketIndex])] = \
                    max([len(list(v)) for k, v in itertools.groupby(profit_series > 0)])
                data_storage['max_lose_streak_number'][(factor_filtered_list[factorIndex], market_filtered_list[marketIndex])] = \
                    max([len(list(v)) for k, v in itertools.groupby(profit_series < 0)])

                profit_count, lose_count = len(
                    profit_series[profit_series > 0]), len(
                        profit_series[profit_series < 0])
                profit_return, lose_return = profit_series[profit_series > 0].apply(lambda x: 1 + x).product() - 1, \
                                             profit_series[profit_series < 0].apply(lambda x: 1 + x).product() - 1

                data_storage['profit_to_lose_percentage'][(factor_filtered_list[factorIndex], market_filtered_list[marketIndex])] =\
                    (profit_return / profit_count) / (abs(lose_return) / lose_count)
                data_storage['profit_to_lose'][(
                    factor_filtered_list[factorIndex],
                    market_filtered_list[marketIndex]
                )] = profit_count / lose_count
                data_storage['turnover_rate'][(
                    factor_filtered_list[factorIndex],
                    market_filtered_list[marketIndex])] = 0

        for tableIndex in range(len(data_storage.columns)):
            series_temp = data_storage[
                data_storage.columns[tableIndex]].values.reshape(
                    factor_count, market_count)

            plt.figure(3, figsize=(20, 40))
            pic_temp = plt.subplot(len(data_storage.columns), 1,
                                   tableIndex + 1)
            pic_temp.axis('off')
            pic_temp.axis('tight')
            table_temp = pic_temp.table(cellText=series_temp,
                                        loc='center',
                                        cellLoc='center',
                                        rowLabels=factor_filtered_list,
                                        colLabels=market_filtered_list,
                                        colLoc='center',
                                        colWidths=[0.1] *
                                        len(market_filtered_list))
            plt.title(data_storage.columns[tableIndex], loc='left', size=25)
            table_temp.set_fontsize(20)
            table_temp.scale(2, 2)

        plt.tight_layout()
        figure_temp = plt.figure(3)

        return figure_temp
    ] for T in Tls])
    rewls[0] = R0
    perf = (rewls - R0) / (Rmax - R0)
    np.save('results/performance', perf)
pl.figure()
errorfill(range(len(perf)),
          np.mean(perf, axis=1),
          yerr=np.std(perf, axis=1) / np.sqrt(len(perf[0])))
pl.xticks([0, 200, 400], [0, 200, 400])
pl.yticks([0, .5, 1.0], [0, .5, 1.0])
pl.xlim([0, 400])
pl.ylim([0, 1])
pl.xlabel('Time [ms]')
pl.ylabel('Performance')
simpleaxis(pl.gca())
pl.tight_layout(0)
pl.savefig('performance.pdf', dpi=600)

# plot value:
h = .1
try:
    V = np.load('results/value_obt.npy')
except IOError:
    S = np.load('results/spikes.npz')['S']
    y = np.array(map(lambda a: a.sum(axis=0), S))[:, 0]
    V = []
    for run, x in enumerate(y):
        V += [
            np.array([[
                np.dot(map(get_R4pv, get_path(x, [p, v])),
                       gamma**np.arange(301))
np.save(Directory + 'InitialCOV.npy', COV)
COR = np.corrcoef(Outputs.T)

AxisLabels = ['Q1', 'Q2', 'Q3', 'Q4', 'Q5', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6']
cmap = pp.get_cmap('jet', 30)
f, ax = pp.subplots(figsize=(9, 6))
sns.heatmap(COV,
            fmt="0.3f",
            annot=True,
            linewidths=.5,
            ax=ax,
            cmap=cmap,
            xticklabels=AxisLabels,
            yticklabels=AxisLabels)
#sns.heatmap(COR, fmt="0.3f",annot=True, linewidths=.5, ax=ax,cmap=cmap,xticklabels = AxisLabels,yticklabels=AxisLabels)
pp.tight_layout()
pp.show()
pp.savefig(Directory + '5_Pipes_Initial_Covariance_Matrix.png')

### Plot of the convergence of the mean and variance
#means = []
#variances = []
#NoSamples = np.arange(2,6.1,0.1)
##NoSamples = [10,30,100,300,1000,3000,10000,30000,100000,300000,1000000]
#for i in 10**NoSamples:
#	means.append(np.mean(Outputs[:int(i),-1]))
#	variances.append(np.std(Outputs[:int(i),-1])**2)
#

#pp.figure(figsize=(6, 4))
#pp.semilogx(10**NoSamples,means)
コード例 #52
0
    def daily_return_visulization(self, xtickNumber=5, visionType=""):
        global pic_temp
        outcome_dataframe = self.outcome_dataframe
        dataNumber = len(self.outcome_dataframe)

        factorFilteredList = list(set(outcome_dataframe["FactorPortfolio"])
                                  )  #将factor指标压缩成只包含不同指标的数组,如[1,2,3,4,5]
        marketFilteredList = list(
            set(outcome_dataframe["MarketValuePortfolio"]))

        if visionType == "factor":
            for factorIndex in range(len(factorFilteredList)):
                for marketIndex in range(len(marketFilteredList)):
                    profit_series = outcome_dataframe["ret"][
                        (outcome_dataframe["FactorPortfolio"] ==
                         factorFilteredList[factorIndex])
                        & (outcome_dataframe["MarketValuePortfolio"] ==
                           marketFilteredList[marketIndex])]
                    date_series = outcome_dataframe["trade_date"][
                        (outcome_dataframe["FactorPortfolio"] ==
                         factorFilteredList[factorIndex])
                        & (outcome_dataframe["MarketValuePortfolio"] ==
                           marketFilteredList[marketIndex])]

                    profit_cumulate_series = np.exp(
                        np.log(1 + profit_series).expanding(
                            1).sum()) - 1  # 抽取累积收益Series

                    dataframe_temp = pd.DataFrame({
                        'date':
                        date_series.apply(lambda x: str(x)).tolist(),
                        'profit':
                        profit_cumulate_series.tolist()
                    })  # 生成一个新的dataframe来储存/此处只是为了update index

                    #Draw Pic
                    plt.figure(1, figsize=(20, 30))
                    pic_temp = plt.subplot(len(factorFilteredList), 1,
                                           factorIndex + 1)
                    plt.plot(dataframe_temp['date'],
                             dataframe_temp['profit'],
                             label="Market=" +
                             str(marketFilteredList[marketIndex]))

                pic_temp.legend()
                xticks_increment = int(dataNumber / xtickNumber /
                                       len(factorFilteredList) /
                                       len(marketFilteredList))  # 设置画图步长
                plt.xticks(
                    [xticks_increment * (x) for x in range(xtickNumber)],
                    dataframe_temp['date'].loc[[
                        xticks_increment * (x) for x in range(xtickNumber)
                    ]])  # 设置x轴刻度
                plt.xlabel('Trade Date')
                plt.ylabel('Returns')
                plt.title("Factor = " + str(factorFilteredList[factorIndex]))

            plt.tight_layout()
            figure_temp = plt.figure(1)
            return figure_temp

        if visionType == "market":
            for marketIndex in range(len(marketFilteredList)):
                for factorIndex in range(len(factorFilteredList)):

                    profit_series = outcome_dataframe["ret"][
                        (outcome_dataframe["FactorPortfolio"] ==
                         factorFilteredList[factorIndex])
                        & (outcome_dataframe["MarketValuePortfolio"] ==
                           marketFilteredList[marketIndex])]
                    date_series = outcome_dataframe["trade_date"][
                        (outcome_dataframe["FactorPortfolio"] ==
                         factorFilteredList[factorIndex])
                        & (outcome_dataframe["MarketValuePortfolio"] ==
                           marketFilteredList[marketIndex])]

                    profit_cumulate_series = np.exp(
                        np.log(1 + profit_series).expanding(
                            1).sum()) - 1  # 抽取累积收益Series

                    dataframe_temp = pd.DataFrame({
                        'date':
                        date_series.apply(lambda x: str(x)).tolist(),
                        'profit':
                        profit_cumulate_series.tolist()
                    })  # 生成一个新的dataframe来储存/此处只是为了update index
                    #Draw Pic
                    plt.figure(2, figsize=(20, 30))
                    pic_temp = plt.subplot(len(marketFilteredList), 1,
                                           marketIndex + 1)
                    plt.plot(dataframe_temp['date'],
                             dataframe_temp['profit'],
                             label="Factor=" +
                             str(factorFilteredList[factorIndex]))

                pic_temp.legend()
                xticks_increment = int(dataNumber / xtickNumber /
                                       len(factorFilteredList) /
                                       len(marketFilteredList))  # 设置画图步长
                plt.xticks(
                    [xticks_increment * (x) for x in range(xtickNumber)],
                    dataframe_temp['date'].loc[[
                        xticks_increment * (x) for x in range(xtickNumber)
                    ]])  # 设置x轴刻度
                plt.title("Market = " + str(marketFilteredList[marketIndex]))
                plt.xlabel('Trade Date')
                plt.ylabel('Returns')

            plt.tight_layout()
            figure_temp = plt.figure(2)
            return figure_temp
コード例 #53
0
def Doplots_diurnal_monthly(mypathforResults, PlottingDF, variable_to_fill,
                            Site_ID, units, list_out, index_str, is_this_all):
    for index, item in enumerate(list_out):
        print "Doing diurnal plot for month and index ", index_str
        #Do Diurnal Plots for all 12 months
        #create an X axis series for all 24 hours
        t = np.arange(1, 25, 1)
        NN_label = str(item + "_NN")
        if is_this_all == True: NN_label = str(item + "_NN_all")
        Plottemp = PlottingDF[[NN_label, item]]

        fig = pl.figure(index,
                        figsize=(16, 12),
                        dpi=80,
                        facecolor='w',
                        edgecolor='k')
        fig.suptitle('Monthly ANN ensemble diurnal average for variable ' +
                     item + ' at ' + Site_ID + ' index ' + index_str)
        pl.subplots_adjust(top=100)

        pl.subplot(321)
        pl.title('Diurnal ' + item + ' month = 1')
        try:
            xdata1a = Plottemp[(PlottingDF.index.month == 1)][item].groupby(
                [lambda x: x.hour]).mean()
            plotxdata1a = True
        except:
            plotxdata1a = False
        try:
            xdata1b = Plottemp[(
                PlottingDF.index.month == 1)][NN_label].groupby(
                    [lambda x: x.hour]).mean()
            plotxdata1b = True
        except:
            plotxdata1b = False
        if (len(xdata1a) == 0): plotxdata1a = False
        if (len(xdata1b) == 0): plotxdata1b = False

        if plotxdata1a == True:
            pl.plot(t, xdata1a, 'b', label=item)
        if plotxdata1b == True:
            pl.plot(t, xdata1b, 'r', label=NN_label)
        pl.ylabel('Flux')
        pl.legend(loc='best')

        pl.subplot(322)
        pl.title('Diurnal ' + item + ' month = 3')
        try:
            xdata1a = Plottemp[(PlottingDF.index.month == 3)][item].groupby(
                [lambda x: x.hour]).mean()
            plotxdata1a = True
        except:
            plotxdata1a = False
        try:
            xdata1b = Plottemp[(
                PlottingDF.index.month == 3)][NN_label].groupby(
                    [lambda x: x.hour]).mean()
            plotxdata1b = True
        except:
            plotxdata1b = False
        if (len(xdata1a) == 0): plotxdata1a = False
        if (len(xdata1b) == 0): plotxdata1b = False

        if plotxdata1a == True:
            pl.plot(t, xdata1a, 'b', label=item)
        if plotxdata1b == True:
            pl.plot(t, xdata1b, 'r', label=NN_label)
        pl.ylabel('Flux')
        pl.legend(loc='best')

        pl.subplot(323)
        pl.title('Diurnal ' + item + ' month = 5')
        try:
            xdata1a = Plottemp[(PlottingDF.index.month == 5)][item].groupby(
                [lambda x: x.hour]).mean()
            plotxdata1a = True
        except:
            plotxdata1a = False
        try:
            xdata1b = Plottemp[(
                PlottingDF.index.month == 5)][NN_label].groupby(
                    [lambda x: x.hour]).mean()
            plotxdata1b = True
        except:
            plotxdata1b = False
        if (len(xdata1a) == 0): plotxdata1a = False
        if (len(xdata1b) == 0): plotxdata1b = False

        if plotxdata1a == True:
            pl.plot(t, xdata1a, 'b', label=item)
        if plotxdata1b == True:
            pl.plot(t, xdata1b, 'r', label=NN_label)
        pl.ylabel('Flux')
        pl.legend(loc='best')

        pl.subplot(324)
        pl.title('Diurnal ' + item + ' month = 7')
        try:
            xdata1a = Plottemp[(PlottingDF.index.month == 7)][item].groupby(
                [lambda x: x.hour]).mean()
            plotxdata1a = True
        except:
            plotxdata1a = False
        try:
            xdata1b = Plottemp[(
                PlottingDF.index.month == 7)][NN_label].groupby(
                    [lambda x: x.hour]).mean()
            plotxdata1b = True
        except:
            plotxdata1b = False
        if (len(xdata1a) == 0): plotxdata1a = False
        if (len(xdata1b) == 0): plotxdata1b = False

        if plotxdata1a == True:
            pl.plot(t, xdata1a, 'b', label=item)
        if plotxdata1b == True:
            pl.plot(t, xdata1b, 'r', label=NN_label)
        pl.ylabel('Flux')
        pl.legend(loc='best')

        pl.subplot(325)
        pl.title('Diurnal ' + item + ' month = 9')
        try:
            xdata1a = Plottemp[(PlottingDF.index.month == 9)][item].groupby(
                [lambda x: x.hour]).mean()
            plotxdata1a = True
        except:
            plotxdata1a = False
        try:
            xdata1b = Plottemp[(
                PlottingDF.index.month == 9)][NN_label].groupby(
                    [lambda x: x.hour]).mean()
            plotxdata1b = True
        except:
            plotxdata1b = False
        if (len(xdata1a) == 0): plotxdata1a = False
        if (len(xdata1b) == 0): plotxdata1b = False

        if plotxdata1a == True:
            pl.plot(t, xdata1a, 'b', label=item)
        if plotxdata1b == True:
            pl.plot(t, xdata1b, 'r', label=NN_label)
        pl.ylabel('Flux')
        pl.legend(loc='best')

        pl.subplot(326)
        pl.title('Diurnal ' + item + ' month = 11')
        try:
            xdata1a = Plottemp[(PlottingDF.index.month == 11)][item].groupby(
                [lambda x: x.hour]).mean()
            plotxdata1a = True
        except:
            plotxdata1a = False
        try:
            xdata1b = Plottemp[(
                PlottingDF.index.month == 11)][NN_label].groupby(
                    [lambda x: x.hour]).mean()
            plotxdata1b = True
        except:
            plotxdata1b = False
        if (len(xdata1a) == 0): plotxdata1a = False
        if (len(xdata1b) == 0): plotxdata1b = False

        if plotxdata1a == True:
            pl.plot(t, xdata1a, 'b', label=item)
        if plotxdata1b == True:
            pl.plot(t, xdata1b, 'r', label=NN_label)
        pl.ylabel('Flux')
        pl.legend(loc='best')

        pl.tight_layout()
        pl.savefig(mypathforResults +
                   '/Monthly ANN ensemble diurnal average for variable ' +
                   item + ' at ' + Site_ID + ' index ' + index_str)
        #pl.show()
        pl.close(index)
        pl.close()
        time.sleep(2)
コード例 #54
0
def make_cog(infile,
             lmin=650.,
             lmax=700.,
             sigfac=7.,
             interact=False,
             no_stamp=False):
    """Loads IFU frame "imfile" and extracts spectra using "fine".

    Args:
        infile (string): input extractions file
        lmin (float): lower wavelength limit for image generation
        lmax (float): upper wavelength limit for image generation
        sigfac (float): sigma multiplier for Gaussian extent of aperture
        interact (bool): set for interactive plotting
        no_stamp (bool): set to prevent printing DRP version stamp on plot

    Returns:
        None

    Raises:
        None

    """

    # The spaxel extraction file must already exist, so load extractions in
    if os.path.isfile(infile):
        print("USING extractions in %s!" % infile)
        ex, meta = np.load(infile)
    # No file found
    else:
        print("File not found: %s" % infile)
        return

    outname = infile.split('.')[0]

    # Automatic extraction using Gaussian fit for Standard Stars
    sixa, posa, adcpos, ellipse, status = \
        identify_spectra_gauss_fit(ex,
                                   prlltc=Angle(meta['PRLLTC'], unit='deg'),
                                   lmin=lmin, lmax=lmax,
                                   airmass=meta['airmass'],
                                   sigfac=sigfac)

    # Use all sky spaxels in image
    kixa, skystat = identify_sky_spectra(ex, adcpos, ellipse=ellipse)

    for ix in sixa:
        ex[ix].is_obj = True
    for ix in kixa:
        ex[ix].is_sky = True

    # Get sky spectrum
    if skystat == 0:
        skya = interp_spectra(ex, kixa, sky=True)
    else:
        skya = interp_spectra(ex, kixa)

    # Define our standard wavelength grid
    ll = None
    # Resample sky onto standard wavelength grid
    try:
        sky_a = interp1d(skya[0]['nm'],
                         skya[0]['ph_10m_nm'],
                         bounds_error=False)
    except:
        sky_a = None

    # Set up curve of growth
    kt = SedSpec.Spectra(ex)
    elrat = ellipse[1] / ellipse[0]
    xc = ellipse[2]
    yc = ellipse[3]
    theta = ellipse[4] * np.pi / 180.

    # Set up plot
    pl.figure(1)
    pl.clf()
    if not no_stamp:
        pl.title(outname)

    xs = range(20)
    rs = list(np.linspace(0, ellipse[0], 20))
    rs.reverse()
    print("max semi-major axis is %.2f asec" % ellipse[0])

    c1 = []
    c2 = []
    c3 = []
    c4 = []
    c5 = []
    px = []
    resout = []

    # Loop over semi-major axes
    for ix in xs:
        if rs[ix] <= 0.:
            continue
        a = rs[ix]
        b = rs[ix] * elrat
        kix = find_positions_ellipse(kt.KT.data, xc, yc, a, b, -theta)
        sixa = kt.good_positions[kix]
        print("%02d found %04d spaxels with a = %.3f" % (ix, len(sixa), a))

        if len(sixa) > 0:
            # get the summed spectrum over the selected spaxels
            resa = interp_spectra(ex, sixa)

            # get common wavelength scale
            if ll is None:
                ll = resa[0]['nm']
            # Copy and resample object spectrum onto standard wavelength grid
            res = {
                "doc": resa[0]["doc"],
                "ph_10m_nm": np.copy(resa[0]["ph_10m_nm"]),
                "spectra": np.copy(resa[0]["spectra"]),
                "coefficients": np.copy(resa[0]["coefficients"]),
                "nm": np.copy(ll)
            }

            fl = interp1d(resa[0]['nm'],
                          resa[0]['ph_10m_nm'],
                          bounds_error=False)

            # Calculate output corrected spectrum
            # Account for sky and aperture
            if sky_a is not None:
                res['ph_10m_nm'] = (fl(ll) - sky_a(ll)) * len(sixa)
            else:
                res['ph_10m_nm'] = fl(ll) * len(sixa)
            cog = res['ph_10m_nm']
            # 400 - 500 nm
            f1 = np.nanmean(cog[(ll > 400) * (ll < 500)])
            c1.append(f1)
            # 500 - 600 nm
            f2 = np.nanmean(cog[(ll > 500) * (ll < 600)])
            c2.append(f2)
            # 600 - 700 nm
            f3 = np.nanmean(cog[(ll > 600) * (ll < 700)])
            c3.append(f3)
            # 700 - 800 nm
            f4 = np.nanmean(cog[(ll > 700) * (ll < 800)])
            c4.append(f4)
            # 800 - 900 nm
            f5 = np.nanmean(cog[(ll > 800) * (ll < 900)])
            c5.append(f5)
            # Semi-major axis in arcsec
            px.append(a)
            # Output results
            res['a'] = a
            res['ix'] = ix
            res['Nspax'] = len(sixa)
            res['fl_400_500nm'] = f1
            res['fl_500_600nm'] = f2
            res['fl_600_700nm'] = f3
            res['fl_700_800nm'] = f4
            res['fl_800_900nm'] = f5
            # Store this iteration
            resout.append(res)

    maxph = np.nanmax([c1, c2, c3, c4, c5])

    # Normalize and get minimum half-max radius

    hmr = 1.e9

    # 400-500 nm
    c1 /= maxph
    if np.max(c1) == c1[0] and np.max(c1) > 0.5:
        c1f = interp1d(c1, px)
        hmx = c1f(0.5)
        if hmx < hmr:
            hmr = hmx

    # 500-600 nm
    c2 /= maxph
    if np.max(c2) == c2[0] and np.max(c2) > 0.5:
        c2f = interp1d(c2, px)
        hmx = c2f(0.5)
        if hmx < hmr:
            hmr = hmx

    # 600-700 nm
    c3 /= maxph
    if np.max(c3) == c3[0] and np.max(c3) > 0.5:
        c3f = interp1d(c3, px)
        hmx = c3f(0.5)
        if hmx < hmr:
            hmr = hmx

    # 700-800 nm
    c4 /= maxph
    if np.max(c4) == c4[0] and np.max(c4) > 0.5:
        c4f = interp1d(c4, px)
        hmx = c4f(0.5)
        if hmx < hmr:
            hmr = hmx

    # 800-900 nm
    c5 /= maxph
    if np.max(c5) == c5[0] and np.max(c5) > 0.5:
        c5f = interp1d(c5, px)
        hmx = c5f(0.5)
        if hmx < hmr:
            hmr = hmx

    if not no_stamp:
        pl.plot(px, c1, label='400-500 nm')
        pl.plot(px, c2, label='500-600 nm')
        pl.plot(px, c3, label='600-700 nm')
        pl.plot(px, c4, label='700-800 nm')
        pl.plot(px, c5, label='800-900 nm')
    else:
        pl.plot(px, c1, label='400-500 nm', linestyle=':')
        pl.plot(px, c2, label='500-600 nm', linestyle='-.')
        pl.plot(px, c3, label='600-700 nm', linestyle='--')
        pl.plot(px, c4, label='700-800 nm', linestyle='-')
        pl.plot(px, c5, label='800-900 nm', linestyle=':')
    if hmr < 1.e9:
        pl.plot([hmr, hmr], [-0.05, 1.05],
                ls='--',
                c='black',
                label='HalfLight')
        # pl.plot([0.05, hmr], [0.5, 0.5], ls='--', c='gray')
    pl.xlim(0.05, np.max(px) + 0.05)
    pl.ylim(-0.05, 1.05)
    pl.xlabel('Semi-major axis (arcsec)', {'fontsize': 14})
    pl.ylabel('Relative Irradiance', {'fontsize': 14})
    pl.legend()
    if not no_stamp:
        plot_drp_ver()
    else:
        ax = pl.gca()
        ax.tick_params(axis='both', which='major', labelsize=14)
        ltext = ax.get_legend().get_texts()
        pl.setp(ltext[0], fontsize=16)
        pl.setp(ltext[1], fontsize=16)
        pl.setp(ltext[2], fontsize=16)
        pl.setp(ltext[3], fontsize=16)
        pl.setp(ltext[4], fontsize=16)
        pl.tight_layout()
    if interact:
        pl.show()
    else:
        pl.savefig('cog_' + outname + '.pdf')
        print("Wrote cog_" + outname + ".pdf")

    np.save("cog_" + outname, resout)
    print("Wrote cog_" + outname + ".npy")
コード例 #55
0
def plot_E615_xF(wdir, istep, data):

    nrows, ncols = 1, 1
    fig = py.figure(figsize=(ncols * 5, nrows * 7))
    ax = py.subplot(nrows, ncols, 1)

    Xbins = []
    #adjust bins
    Xbins.append([0, 0.1])
    Xbins.append([0.1, 0.2])
    Xbins.append([0.2, 0.3])
    Xbins.append([0.3, 0.4])
    Xbins.append([0.4, 0.5])
    Xbins.append([0.5, 0.6])
    Xbins.append([0.7, 0.8])
    Xbins.append([0.8, 0.9])
    Xbins.append([0.9, 1])
    Xbins = Xbins[::-1]

    tab = {}
    tab['pT'] = data['pT']
    tab['xF'] = data['xF']
    tab['value'] = data['value']
    tab['alpha'] = data['alpha']
    tab['thy'] = np.mean(data['prediction-rep'], axis=0)
    tab['dthy'] = np.std(data['prediction-rep'], axis=0)
    for k in range(len(data['prediction-rep'])):
        tab['thy%d' % k] = data['prediction-rep'][k]

    tab = pd.DataFrame(tab)

    f = 1  #40
    for i in range(len(Xbins)):
        d = tab.query('xF>%f and xF<%f' % (Xbins[i][0], Xbins[i][1]))
        if len(d['xF']) != 0:
            ii = np.argsort(d['pT'].values)
            X = d['pT'].values[ii]
            Y = d['thy'].values[ii]
            YP = Y + d['dthy'].values[ii]
            YM = Y - d['dthy'].values[ii]
            if len(d['pT'].values) > 1:
                msg = r'$xF\in[%0.1f,%0.1f]$' % (Xbins[i][0], Xbins[i][1])
                p, = ax.plot(X[:-1], (Y * f**i)[:-1], alpha=0.3, label=None)
                ax.fill_between(X[:-1], (YM * f**i)[:-1], (YP * f**i)[:-1],
                                color=p.get_color(),
                                alpha=0.3,
                                label=None)

                ax.errorbar(d['pT'][:-1], (d['value'] * f**i)[:-1],
                            (d['alpha'] * f**i)[:-1],
                            zorder=10,
                            marker='o',
                            ls='none',
                            markeredgecolor='k',
                            ecolor='k',
                            color=p.get_color(),
                            label=msg)
            #ax.set_title('Q bin: '+str(Qbins[i][0])+'-'+str(Qbins[i][1]))
            #ax.semilogy()
            #ax.tick_params(axis='both',which='both',direction='in',pad=4,labelsize=18)
            #ax.set_xlabel(r'$pT$',size=20)
            #ax.xaxis.set_label_coords(0.95,-0.03)
            #ax.text(0.06,0.06,r'$d^2\sigma/dQdpT$',transform=ax.transAxes,size=20)
            #ax.text(0.78,0.91,r'$\bf E615 pT$',transform=ax.transAxes,size=17)
            #py.tight_layout()
    ax.legend(loc=4)
    ax.semilogy()
    ax.tick_params(axis='both',
                   which='both',
                   direction='in',
                   pad=4,
                   labelsize=18)
    ax.set_xlim(None, 4.5)
    #ax.set_ylim(1e-38,1e-20)
    #ax.set_xticks([0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8])
    #ax.set_xticklabels([r'$0$',r'',r'$0.2$',r'',r'$0.4$',r'',r'$0.6$',r'',r''])
    #ax.set_xlabel(r'$pT$',size=20)
    ax.xaxis.set_label_coords(0.95, -0.03)
    #ax.set_ylim(2.5e-1,8e2)
    ax.set_ylabel(r'$d^2\sigma/dxFdp_{\rm T}~\times %d^i$' % f, size=20)
    ax.set_xlabel(r'$p_{\rm T}$', size=20)
    ax.text(0.1, 0.23, r'$i=0$', transform=ax.transAxes, size=14)
    ax.text(0.5, 0.92, r'$i=10$', transform=ax.transAxes, size=14)
    ax.text(0.7,
            0.9,
            r'\boldmath{${\rm E615}$}',
            transform=ax.transAxes,
            size=17)
    py.tight_layout()
    py.savefig('%s/gallery/dy-pion-E615-xF-%d.png' % (wdir, istep))
コード例 #56
0
def fitLines(coordPairs,lineBasicData, CutLinesValues, bPlot = False) :
    
    fitData = []
    j = 1
    for i in range(0,len(coordPairs),1) :
        print i
        print coordPairs[i]
        print lineBasicData[i]
       
    for Values, basicData in itertools.izip(CutLinesValues[1:],lineBasicData[1:]):
        #chnage slicer values to skip lines which cannot be minimised i.e edge effects or detected false lines
        x   = Values[0]
        f   = Values[1]
        Err = Values[2]

        #chi2 = lambda bg, a, mu, sigma, R: (((f-convolutionfuncG(a, mu, sigma, x, R)+bg)/Err)**2).sum()
        #chi2 = lambda bg,a,mu,sigma: ((f -(a/sigma*pylab.sqrt(2*math.pi))*pylab.exp(-(x-mu)**2/sigma**2)+bg)**2/Err**2).sum() #just gauss
        #chi2 = lambda bg, a, mu, gamma,R: ((f-convolutionfuncL(a, mu, gamma, x, R)+bg)**2/Err**2).sum()	#circleLorentz
        chi2  = lambda bg, a, mu, gamma, sigma, R:(((f-convolutionfuncvoi(a, x, mu, sigma, gamma, R)+bg)/Err)**2).sum()	#circlevoigt
        #chi2  = lambda bg, a, mu, gamma, sigma:(((f-voiSb((x-mu), sigma, gamma,a)+bg)/Err)**2).sum()	#voigt

        #m=minuit.Minuit(chi2, bg=-505864.835856, a = -408608, mu= 666.961236213, gamma=11.1507399367, sigma=0.750795227728, R=4.87)
        #m=minuit.Minuit(chi2, bg=-510099.995856, a = -890000, mu= 668.961236213, gamma=11.1507399367, sigma=0.750795227728)#voigt beta extended
        #m=minuit.Minuit(chi2, bg=-505864.835856, a = -408608, mu= 666.961236213, gamma=11.1507399367, sigma=0.750795227728)#voigt shallow
        #m=minuit.Minuit(chi2, bg = -500000, a = -basicData[1], mu = basicData[0], gamma = basicData[2], sigma = basicData[2], R=4.87)#tester
        #m=minuit.Minuit(chi2, bg = -603807.71721, a = -801908.440558, mu = 389.77133122, gamma = 10.133591096, sigma = 10.161872412, R=4.255771982)
        m=minuit.Minuit(chi2, bg = -494532.214627, a = -275192.356194, mu = 389.755898794, gamma = 9.06574437224, sigma = 2, R=11.0398160531)

        m.tol = 10000000000
        m.printMode = 1
        m.migrad()
        m.hesse()
        m.values
        bg    = m.values['bg']
        a     = m.values['a']
        mu    = m.values['mu']
        gamma = m.values['gamma']
        sigma = m.values['sigma']
        R     = m.values['R']
        #fit =(a/sigma*pylab.sqrt(2*math.pi))*pylab.exp(-((x-mu)**2)/sigma**2)-bg
        #fit =convolutionfuncL(a, mu, gamma, x, R)-bg
        #fit = convolutionfuncG(a, mu, sigma, x, R)-bg
        fit = convolutionfuncvoi(a, x, mu, sigma, gamma,R)-bg
        #fit = voiSb((x-mu), sigma, gamma,a)-bg
        #fitData.append([a,mu,bg,sigma,m.errors])
        fitData.append([a,mu,bg,gamma,sigma,R,m.errors])
        print'fitLines> Covariance Matrix:\n', m.covariance
        

        if bPlot:
            pylab.figure()
            pylab.errorbar(x,f,Err,label='Data')
            pylab.xlabel('Pixels')
            pylab.ylabel('no. Photo electrons')
            pylab.plot(x,fit,label='Fitted Voigt X Circle')
            pylab.legend(loc='best')
            pylab.figure(108)

            pylab.subplot(5,2,j)
            pylab.tight_layout()
            ax = pylab.gca()
            for tick in ax.xaxis.get_major_ticks():
                tick.label1.set_fontsize(9)
            for tick in ax.yaxis.get_major_ticks():
                tick.label1.set_fontsize(9)
            pylab.errorbar(x,f,Err)
            pylab.plot(x,fit,label='line:%s'%(j))
            pylab.legend(loc='best',prop={'size':8})
            j+=1
                        


    fitData = pylab.reshape(fitData,(len(fitData),7))
    #out_txt(fitData,'')
    print 'fitLines> fitData:\n',fitData


    return[fitData]
コード例 #57
0
ファイル: main.py プロジェクト: karolis-sh/_archive
def test_acs_sa_wrapper():
    print '\ntest_acs_sa_wrapper pradžia'
    rez_dist_b, rez_dist_w = [], []
    rez_dura_b, rez_dura_w = [], []
    rez_ants_b, rez_ants_w = [], []
    rez_iter_b, rez_iter_w = [], []
    rez_alfa_b, rez_alfa_w = [], []
    rez_beta_b, rez_beta_w = [], []

    cities = [6, 7, 8, 9, 10, 12, 14, 16, 18, 20, 25, 30]
    for c in cities:
        print '\t', c, 'miestai'
        graph = AntGraph.generate_complete_graph((1000, 1000), c)
        acsim = ACSSA(graph, 30, 60)
        acsim.decrement = 0.99
        acsim.simulate(True)
        print '\t\tworst', acsim.worst_solution
        print '\t\tbest', acsim.best_solution

        rez_dist_b.append(acsim.best_solution['distance'])
        rez_dist_w.append(acsim.worst_solution['distance'])

        rez_dura_b.append(acsim.best_solution['duration'])
        rez_dura_w.append(acsim.worst_solution['duration'])

        rez_ants_b.append(acsim.best_solution['parameters']['ants'])
        rez_ants_w.append(acsim.worst_solution['parameters']['ants'])

        rez_iter_b.append(acsim.best_solution['parameters']['iterations'])
        rez_iter_w.append(acsim.worst_solution['parameters']['iterations'])

        rez_alfa_b.append(acsim.best_solution['parameters']['alfa'])
        rez_alfa_w.append(acsim.worst_solution['parameters']['alfa'])

        rez_beta_b.append(acsim.best_solution['parameters']['beta'])
        rez_beta_w.append(acsim.worst_solution['parameters']['beta'])

    fig = figure(200)
    g1 = fig.add_subplot(211)
    g1.set_title(
        u'Geriausio (žalia) ir blogiausio (raudona) maršruto algoritmo atstumai.'
    )
    g1.set_xlabel(u'Miestu skaičius')
    g1.set_ylabel(u'Atstumas')
    g1.plot(cities, rez_dist_b, 'g-', cities, rez_dist_w, 'r--')
    g1.grid(True)

    g2 = fig.add_subplot(212)
    g2.set_title(
        u'Geriausio (žalia) ir blogiausio (raudona) maršruto algoritmo laikai.'
    )
    g2.set_xlabel(u'Miestu skaičius')
    g2.set_ylabel(u'Laikas (s)')
    g2.plot(cities, rez_dura_b, 'g-', cities, rez_dura_w, 'r--')
    g2.grid(True)
    tight_layout()
    savefig('output/test_acs_sa_wrapper/test_acs_sa_wrapper_dist_dur.png')

    fig = figure(201)
    g1 = fig.add_subplot(211)
    g1.set_title(
        u'Geriausio (žalia) ir blogiausio (raudona) maršruto algoritmo skrudeliu skaičius.'
    )
    g1.set_xlabel(u'Miestu skaičius')
    g1.set_ylabel(u'Skruzdeles')
    g1.axis([cities[0], cities[len(cities) - 1], 0.0, OPTIMAL_ANTS * 2])
    g1.plot(cities, rez_ants_b, 'g-', cities, rez_ants_w, 'r--')
    g1.grid(True)

    g2 = fig.add_subplot(212)
    g2.set_title(
        u'Geriausio (žalia) ir blogiausio (raudona) maršruto algoritmo iteraciju skaičius.'
    )
    g2.set_xlabel(u'Miestu skaičius')
    g2.set_ylabel(u'Iteracijos')
    g2.axis(
        [cities[0], cities[len(cities) - 1], 0.0, OPTIMAL_ANT_ITERATIONS * 2])
    g2.plot(cities, rez_iter_b, 'g-', cities, rez_iter_w, 'r--')
    g2.grid(True)
    tight_layout()
    savefig('output/test_acs_sa_wrapper/test_acs_sa_wrapper_ant_iter.png')

    fig = figure(202)
    g1 = fig.add_subplot(211)
    g1.set_title(
        u'Geriausio (žalia) ir blogiausio (raudona) maršruto algoritmo alfa parametras.'
    )
    g1.set_xlabel(u'Miestu skaičius')
    g1.set_ylabel(u'alfa')
    g1.axis([cities[0], cities[len(cities) - 1], 0.0, 1.0])
    g1.plot(cities, rez_alfa_b, 'g-', cities, rez_alfa_w, 'r--')
    g1.grid(True)

    g2 = fig.add_subplot(212)
    g2.set_title(
        u'Geriausio (žalia) ir blogiausio (raudona) maršruto algoritmo beta parametras.'
    )
    g2.set_xlabel(u'Miestu skaičius')
    g2.set_ylabel(u'beta')
    g2.axis([cities[0], cities[len(cities) - 1], 0.0, 75.0])
    g2.plot(cities, rez_beta_b, 'g-', cities, rez_beta_w, 'r--')
    g2.grid(True)
    tight_layout()
    savefig('output/test_acs_sa_wrapper/test_acs_sa_wrapper_alfa_beta.png')
    print 'test_acs_sa_wrapper pabaiga\n'
コード例 #58
0
def plot_E615_xF(wdir, istep, data):

    Xbins = []
    #adjust bins
    Xbins.append([0, 0.1])
    Xbins.append([0.1, 0.2])
    Xbins.append([0.2, 0.3])
    Xbins.append([0.3, 0.4])
    Xbins.append([0.4, 0.5])
    Xbins.append([0.5, 0.6])
    Xbins.append([0.7, 0.8])
    Xbins.append([0.8, 0.9])
    Xbins.append([0.9, 1])
    Xbins = Xbins[::-1]

    tab = {}
    tab['pT'] = data['pT']
    tab['xF'] = data['xF']
    tab['value'] = data['value']
    tab['alpha'] = data['alpha']
    tab['thy'] = np.mean(data['prediction-rep'], axis=0)
    tab['dthy'] = np.std(data['prediction-rep'], axis=0)
    #for k in range(len(data['prediction-rep'])):
    #    tab['thy%d'%k]=data['prediction-rep'][k]
    tab = pd.DataFrame(tab)

    nrows, ncols = 8, 1
    fig = py.figure(figsize=(ncols * 5, nrows * 1))
    AX = {cnt: py.subplot(nrows, ncols, cnt) for cnt in range(1, 9)}

    cnt = 0
    for i in range(len(Xbins)):
        d = tab.query('xF>%f and xF<%f' % (Xbins[i][0], Xbins[i][1]))
        if len(d['xF']) != 0:
            ii = np.argsort(d['pT'].values)
            X = d['pT'].values[ii]
            Y = d['thy'].values[ii]
            YP = Y + d['dthy'].values[ii]
            YM = Y - d['dthy'].values[ii]
            if len(d['pT'].values) > 1:
                cnt += 1
                ax = AX[cnt]
                ax.fill_between(X[:-1], (YM / Y)[:-1], (YP / Y)[:-1],
                                color='y',
                                alpha=0.3,
                                label=None)

                ax.errorbar(d['pT'][:-1], (d['value'] / Y)[:-1],
                            (d['alpha'] / Y)[:-1],
                            zorder=10,
                            fmt='r.')
                msg = r'$x_F\in[%0.1f,%0.1f]$' % (Xbins[i][0], Xbins[i][1])
                ax.text(0.75, 0.8, msg, transform=ax.transAxes)
            #ax.set_title('Q bin: '+str(Qbins[i][0])+'-'+str(Qbins[i][1]))
            #ax.semilogy()
            #ax.tick_params(axis='both',which='both',direction='in',pad=4,labelsize=18)
            #ax.set_xlabel(r'$pT$',size=20)
            #ax.xaxis.set_label_coords(0.95,-0.03)
            #ax.text(0.06,0.06,r'$d^2\sigma/dQdpT$',transform=ax.transAxes,size=20)
            #ax.text(0.78,0.91,r'$\bf E615 pT$',transform=ax.transAxes,size=17)
            #py.tight_layout()

    for _ in AX:
        AX[_].set_xlim(2.0, 4.5)
        AX[_].axhline(1, color='k', alpha=0.3)
        if _ != 8: AX[_].set_xticklabels([])
        AX[_].tick_params(axis='both',
                          which='both',
                          direction='in',
                          labelsize=18)
        #AX[_].set_ylim(0,10)
        #AX[_].set_yticks([1,5])

    AX[4].set_ylabel(r'$\rm Ratio~to~theory$', size=30)
    AX[4].yaxis.set_label_coords(-.1, 0.03)
    AX[8].set_xlabel(r'$p_{\rm T}$', size=20)
    AX[8].xaxis.set_label_coords(0.95, -0.03)
    AX[8].set_xticks([2.5, 3, 3.5, 4])

    AX[1].set_ylim(0, 11)
    AX[2].set_ylim(0, 3)
    AX[3].set_ylim(0, 3)
    AX[4].set_ylim(0, 3)
    AX[5].set_ylim(0, 4)
    AX[6].set_ylim(0, 4)
    AX[7].set_ylim(0, 6)
    AX[8].set_ylim(0, 11)

    AX[1].set_yticks([1, 5, 10])
    AX[2].set_yticks([1, 2])
    AX[3].set_yticks([1, 2])
    AX[4].set_yticks([1, 2])
    AX[5].set_yticks([1, 3])
    AX[6].set_yticks([1, 3])
    AX[7].set_yticks([1, 5])
    AX[8].set_yticks([1, 5, 10])

    AX[8].text(0.7,
               0.2,
               r'\boldmath{${\rm E615}$}',
               transform=AX[8].transAxes,
               size=17)

    #AX[3].xaxis.set_label_coords(0.95,-0.03)
    #ax.set_ylim(1e-38,1e-20)
    #ax.set_xticks([0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8])
    #ax.set_xticklabels([r'$0$',r'',r'$0.2$',r'',r'$0.4$',r'',r'$0.6$',r'',r''])
    #ax.set_xlabel(r'$pT$',size=20)
    #ax.xaxis.set_label_coords(0.95,-0.03)
    #ax.set_ylim(2.5e-1,8e2)
    #ax.set_ylabel(r'$d^2\sigma/dQdp_{\rm T}~\times %d^i$'%f,size=20)
    #ax.text(0.1,0.23,r'$i=0$',transform=ax.transAxes,size=14)
    #ax.text(0.5,0.92,r'$i=10$',transform=ax.transAxes,size=14)
    #ax.text(0.7,0.9,r'\boldmath{${\rm E615}$}',transform=ax.transAxes,size=17)
    py.tight_layout()
    py.subplots_adjust(wspace=0.1, hspace=0.0)
    py.savefig('%s/gallery/dy-pion-E615-xF-%d.png' % (wdir, istep))
コード例 #59
0
ファイル: main.py プロジェクト: karolis-sh/_archive
def test_acs_sa_bf():
    print '\ntest_acs_sa_bf pradžia'
    bf = {'name': 'Pilnas perrinkimas'}
    acs = {'name': 'Skruzdeliu kolonijos'}
    sa = {'name': 'Simuliuoto \"atkaitinimo\"'}
    methods = [bf, acs, sa]
    cities = [6, 7, 8, 9, 10, 12, 14, 16, 18, 20, 25, 30, 40, 50, 60, 80, 100]

    bf_dist = []
    bf_dur = []
    acs_dist = []
    acs_dur = []
    sa_dist = []
    sa_dur = []

    for c in cities:
        print '\t', c, 'miestai'
        g = AntGraph.generate_complete_graph([1000, 1000], c)
        if c <= 10:
            bf_rez = g.brute_force_tsp()
            bf_dist.append(bf_rez['distance'])
            bf_dur.append(bf_rez['duration'])

        acs_sim = AntColonySystem(g, OPTIMAL_ANTS, OPTIMAL_ANT_ITERATIONS, 0.5,
                                  20)
        acs_sim.find_path()
        acs_rez = acs_sim.best_route
        acs_dist.append(acs_rez['distance'])
        acs_dur.append(acs_rez['duration'])

        sasim = TSPSA(g)
        sasim.t = 1000
        sasim.decrement = 0.9995
        sasim.simulate()
        sa_rez = sasim.result
        sa_dist.append(sa_rez['distance'])
        sa_dur.append(sa_rez['duration'])

    bf['distance'] = bf_dist
    bf['duration'] = bf_dur

    acs['distance'] = acs_dist
    acs['duration'] = acs_dur

    sa['distance'] = sa_dist
    sa['duration'] = sa_dur

    fig = figure(500)
    g1 = fig.add_subplot(211)
    g1.set_title(u'Rasti trumpiausi marsrutai')
    g1.set_xlabel(u'Miestu skaičius')
    g1.set_ylabel(u'Atstumas')
    for m in methods:
        lbl = "Paieskos metodas: " + m['name']
        g1.plot(cities[:len(m['distance'])], m['distance'], label=unicode(lbl))
        fontP = FontProperties()
        fontP.set_size('small')
        box1 = g1.get_position()
        g1.set_position([box1.x0, box1.y0, box1.width * 0.8, box1.height])
        lgd = g1.legend(prop=fontP, loc='center left', bbox_to_anchor=(1, 0.5))
    g1.grid(True)

    g2 = fig.add_subplot(212)
    g2.set_title(u'Algoritmu skaičiavo laikai')
    g2.set_xlabel(u'Miestu skaičius')
    g2.set_ylabel(u'Laikas (s)')
    for m in methods:
        lbl = "Paieskos metodas: " + m['name']
        g2.plot(cities[:len(m['duration'])], m['duration'], label=unicode(lbl))
        fontP = FontProperties()
        fontP.set_size('small')
        box2 = g2.get_position()
        g2.set_position([box2.x0, box2.y0, box2.width * 0.8, box2.height])
        lgd = g2.legend(prop=fontP, loc='center left', bbox_to_anchor=(1, 0.5))
    g2.grid(True)
    tight_layout()
    savefig('output/test_acs_sa_bf/test_acs_sa_bf.png',
            bbox_extra_artists=(lgd, ),
            bbox_inches='tight')

    fig = figure(501)
    g3 = fig.add_subplot(111)
    g3.set_title(u'Algoritmu skaičiavo laikai')
    g3.set_xlabel(u'Miestu skaičius')
    g3.set_ylabel(u'Laikas (s)')
    for m in methods:
        if m['name'] == bf['name']:
            continue
        lbl = "Paieskos metodas: " + m['name']
        g3.plot(cities[:len(m['duration'])], m['duration'], label=unicode(lbl))
        fontP = FontProperties()
        fontP.set_size('small')
        box3 = g3.get_position()
        g3.set_position([box3.x0, box3.y0, box3.width * 0.8, box3.height])
        lgd = g3.legend(prop=fontP, loc='center left', bbox_to_anchor=(1, 0.5))
    g3.grid(True)
    tight_layout()
    savefig('output/test_acs_sa_bf/test_acs_sa_bf2.png',
            bbox_extra_artists=(lgd, ),
            bbox_inches='tight')
    print 'test_acs_sa_bf pabaiga\n'
コード例 #60
0
def plot_E615_Q(wdir, istep, data):

    Qbins = []
    #adjust bins
    Qbins.append([4.05, 4.5])
    Qbins.append([4.5, 4.95])
    Qbins.append([4.95, 5.4])
    Qbins.append([5.4, 5.85])
    Qbins.append([5.85, 6.75])
    Qbins.append([6.75, 7.65])
    Qbins.append([7.65, 9])
    Qbins.append([9, 10.35])
    Qbins.append([10.35, 11.7])
    Qbins.append([11.7, 13.05])

    nrows, ncols = 6, 1
    fig = py.figure(figsize=(ncols * 5, nrows * 1))
    AX = {cnt: py.subplot(nrows, ncols, cnt) for cnt in range(1, 7)}

    tab = {}
    tab['pT'] = data['pT']
    tab['Q'] = data['Q']
    tab['value'] = data['value']
    tab['alpha'] = data['alpha']
    tab['thy'] = np.mean(data['prediction-rep'], axis=0)
    tab['dthy'] = np.std(data['prediction-rep'], axis=0)
    #for k in range(len(data['prediction-rep'])):
    #    tab['thy%d'%k]=data['prediction-rep'][k]

    tab = pd.DataFrame(tab)

    cnt = 0
    for i in range(len(Qbins)):
        d = tab.query('Q>%f and Q<%f' % (Qbins[i][0], Qbins[i][1]))
        if len(d['Q']) != 0:
            ii = np.argsort(d['pT'].values)
            X = d['pT'].values[ii]
            Y = d['thy'].values[ii]
            YP = Y + d['dthy'].values[ii]
            YM = Y - d['dthy'].values[ii]
            if len(d['pT'].values) > 1:
                cnt += 1
                if cnt > sorted(AX.keys())[-1]: continue
                ax = AX[cnt]
                msg = r'$Q\in[%0.1f,%0.1f]$' % (Qbins[i][0], Qbins[i][1])
                ax.text(0.75, 0.8, msg, transform=ax.transAxes)
                #p,=ax.plot(X[:-1],(Y*f**i)[:-1],alpha=0.3,label=None)
                ax.fill_between(X[:-1], (YM / Y)[:-1], (YP / Y)[:-1],
                                color='y',
                                alpha=0.3,
                                label=None)
                #for k in range(len(data['prediction-rep'])):
                ##for k in range(70):
                #    Yk=d['thy%d'%k].values[ii]
                #    #print k, np.sum(((d['value']-Yk)/d['alpha'])**2)/X.size
                #    ax.plot(X[:-1],(Yk*f**i)[:-1],ls='-'
                #        ,zorder=0
                #        ,color=p.get_color(),alpha=0.3)

                ax.errorbar(d['pT'][:-1], (d['value'] / Y)[:-1],
                            (d['alpha'] / Y)[:-1],
                            zorder=10,
                            fmt='r.')
            #ax.set_title('Q bin: '+str(Qbins[i][0])+'-'+str(Qbins[i][1]))
            #ax.semilogy()
            #ax.tick_params(axis='both',which='both',direction='in',pad=4,labelsize=18)
            #ax.set_xlabel(r'$pT$',size=20)
            #ax.xaxis.set_label_coords(0.95,-0.03)
            #ax.text(0.06,0.06,r'$d^2\sigma/dQdpT$',transform=ax.transAxes,size=20)
            #ax.text(0.78,0.91,r'$\bf E615 pT$',transform=ax.transAxes,size=17)
            #py.tight_layout()

    #ax.legend(loc=4)
    #ax.semilogy()
    #ax.tick_params(axis='both',which='both',direction='in',pad=4,labelsize=18)
    for _ in AX:
        AX[_].set_xlim(2.0, 4.5)
        AX[_].set_ylim(0, 3)
        AX[_].axhline(1, color='k', alpha=0.3)
        if _ != 6: AX[_].set_xticklabels([])
        AX[_].tick_params(axis='both',
                          which='both',
                          direction='in',
                          labelsize=18)
        AX[_].set_yticks([1, 2])

    AX[3].set_ylabel(r'$\rm Ratio~to~theory$', size=30)
    AX[3].yaxis.set_label_coords(-.1, -0.03)
    AX[6].set_xlabel(r'$p_{\rm T}$', size=20)
    AX[6].xaxis.set_label_coords(0.95, -0.03)
    AX[6].set_xticks([2.5, 3, 3.5, 4])

    #AX[3].xaxis.set_label_coords(0.95,-0.03)
    #ax.set_ylim(1e-38,1e-20)
    #ax.set_xticks([0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8])
    #ax.set_xticklabels([r'$0$',r'',r'$0.2$',r'',r'$0.4$',r'',r'$0.6$',r'',r''])
    #ax.set_xlabel(r'$pT$',size=20)
    #ax.xaxis.set_label_coords(0.95,-0.03)
    #ax.set_ylim(2.5e-1,8e2)
    #ax.set_ylabel(r'$d^2\sigma/dQdp_{\rm T}~\times %d^i$'%f,size=20)
    #ax.text(0.1,0.23,r'$i=0$',transform=ax.transAxes,size=14)
    #ax.text(0.5,0.92,r'$i=10$',transform=ax.transAxes,size=14)
    AX[6].text(0.7,
               0.4,
               r'\boldmath{${\rm E615}$}',
               transform=AX[6].transAxes,
               size=17)
    py.tight_layout()
    py.subplots_adjust(wspace=0.1, hspace=0.0)
    py.savefig('%s/gallery/dy-pion-E615-Q-%d.png' % (wdir, istep))