Example #1
0
def draw_date_score():
    # dir_name 에는 보간값 있는 폴더 이름 적기
    st = time.time()

    # 프리셋 적용
    preset_ds()
    plt.title(f"소녀전선 한국서버 <허수미궁+> 등급컷 변화 그래프")

    # 점, 그래프 그리기
    ds_plot_in100([1, 10, 50, 100], marker='o', mfc='w')
    ds_plot([5, 10, 15, 20, 30, 40, 50], marker='o', mfc='w')
    # 가로선 그리기
    draw_axhline(200000, '황금요정 확정지급 점수\n200,000점')
    draw_axhline(400000, '최고등급 보상 확정지급 점수\n400,000점')

    # 범례
    plt.legend(bbox_to_anchor=(1, 0.5), loc="center left")
    plt.figtext(0.10, 0.04, "36베이스 - 소녀전선 데이터베이스 https://girlsfrontline.kr", ha="left", va="top", alpha=0.5, size=12)
    plt.figtext(0.88, 0.04, "구글 설문 및 36베이스 카카오톡 봇으로 표본 조사중입니다. 많이 참여해주세요.", ha="right", va="top", alpha=0.5, size=12)

    # 저장
    # plt.show()
    plt.savefig(f'../image/{event_name}/date_score/{datetime.date.today()}.png')
    shutil.copy(f'../image/{event_name}/date_score/{datetime.date.today()}.png', "../docs/recent.png")
    print(f">>> {time.time() - st} secs.")
    return
Example #2
0
def plot_3panel(X1,
                X2,
                X3,
                Y,
                xlims1=None,
                xlims2=None,
                xlims3=None,
                ymax=None,
                X1lab='dBZ',
                X2lab='ZDR',
                X3lab=r'Kdp (dB km$^{-1}$)',
                ylab=None,
                label=True,
                labelTx=' ',
                labelpos=None):
    """Create a 3-panel vertical plot of reflectivity, differential reflectivity,
      and specific differential phase.
    """
    fig, (ax1, ax2, vax3) = plt.subplots(1, 3, sharey=True)

    if xlims1 is None:
        xlims1 = (-20, 30.)
    if xlims2 is None:
        xlims2 = (-1.5, 1.5)
    if xlims3 is None:
        xlims3 = (.2, .4)
    if ymax is None:
        ymax = 10.
    ax1.plot(X1, Y, color='k')
    ax2.plot(X2, Y, color='k')
    ax3.plot(X3, Y, color='k')
    ax1.set_xlim(xlims1)
    ax2.set_xlim(xlims2)
    ax3.set_xlim(xlims3)
    ax1.set_xlabel(X1lab)
    ax2.set_xlabel(X2lab)
    ax3.set_xlabel(X3lab)

    # Set y axis characteristics
    ax1.set_ylim(0., ymax)
    if ylab is None:
        ax1.set_ylabel('Altitude (km)')
    else:
        ax1.set_ylabel(ylab)
    ax1.vlines(0, 0, ymax)
    ax2.vlines(0, 0, ymax)
    ax1.xaxis.grid(color='k', ls=':', lw=1)
    ax2.xaxis.grid(color='k', ls=':', lw=1)
    ax3.xaxis.grid(color='k', ls=':', lw=1)
    ax1.yaxis.grid(color='k', ls=':', lw=.5)
    ax2.yaxis.grid(color='k', ls=':', lw=.5)
    ax3.yaxis.grid(color='k', ls=':', lw=.5)
    # Add label to above plot unless location specified
    if label:
        if labelpos is None:
            labelpos = (.15, .91)
        plt.figtext(labelpos[0], labelpos[1], labelTx)

    return fig, ax1, ax2, ax3
Example #3
0
def plot_zdr_rhv(X1,
                 X2,
                 Y,
                 xlims1=None,
                 xlims2=None,
                 ymax=None,
                 label=True,
                 labelTx=' ',
                 labelpos=None):
    """Create a vertical plot of differential reflectivity and copolar correlation
    coefficient.
    """
    fig, ax = plt.subplots()
    axes = [ax, ax.twiny()]

    if xlims1 is None:
        xlims1 = (-1.5, 1.5)
    if xlims2 is None:
        xlims2 = (.8, 1.)
    if ymax is None:
        ymax = 10.

    axes[0].plot(X1, Y, label='Differential Reflectivity', color='b')
    axes[1].plot(X2, Y, label='CoPolar Correlation Coefficient', color='r')
    axes[0].set_xlim(xlims1)
    axes[1].set_xlim(xlims2)
    axes[0].set_xlabel('Differential Reflectivity (dB)')
    axes[1].set_xlabel('CoPolar Correlation Coefficient')
    axes[0].tick_params(axis='x', colors='b')
    axes[1].tick_params(axis='x', colors='r')
    axes[0].xaxis.label.set_color('b')
    axes[1].xaxis.label.set_color('r')
    axes[0].set_ylim(0., ymax)
    axes[0].set_ylabel('Altitude (km)')
    axes[0].vlines(0, 0, ymax)
    axes[0].xaxis.grid(color='b', ls=':', lw=1)
    axes[1].xaxis.grid(color='r', ls=':', lw=1)
    axes[0].yaxis.grid(color='k', ls=':', lw=.5)

    handles1, labels1 = axes[0].get_legend_handles_labels()
    handles2, labels2 = axes[1].get_legend_handles_labels()
    plt.legend(
        [handles1[0], handles2[0]],
        ['Differential Reflectivity', 'CoPolar Correlation Coefficient'],
        loc=6,
        fontsize=11)
    # Add label to lower left in plot unless location specified
    if label:
        if labelpos is None:
            labelpos = (.15, .15)
        plt.figtext(labelpos[0], labelpos[1], labelTx)

    return fig, ax, axes
Example #4
0
def plot_add_stats(instance=None, avg=None, sd=None, points=None,
                   good_samples=None, tot_samples=None, labelpos=None):
    """Add text to the figure that contains statistics."""
    if labelpos is None:
        labelpos=(.15, .7)
    if instance == 'single':
        plt.figtext(labelpos[0], labelpos[1],
            "Avg Zdr = %g\nStd Dev = %g\nPoints = %g\n"%(avg, sd, points))
    elif instance == 'multi':
        plt.figtext(labelpos[0], labelpos[1],
            "Avg Zdr = %g\nStd Dev = %g\nSamples = %g used of %g total\nPoints = %g\n"%
            (avg, sd, good_samples, tot_samples, points))
    else:
        print "Need to supply either single or multiple run statistics!!"
def plot_reg(x, y, out_file):
    f, ax = plt.subplots(figsize=(6.5, 6.5))
    sns.despine(f, left=True, bottom=True)
    i = np.logical_and(np.isfinite(x), np.isfinite(y))
    x = x[i]
    y = y[i]
    sns.regplot(x, y, ax=ax)
    r = np.polyfit(x, y, 1)
    print(i.sum())
    print(r)
    filename = os.path.basename(out_file)
    plt.title(filename[:-4])
    plt.figtext(0.1, 0.95, 'a = {:0.4f}'.format(r[0]))
    plt.figtext(0.1, 0.90, 'b = {:0.4f}'.format(r[1]))
    plt.savefig(out_file)
Example #6
0
def plot_3panel(X1, X2, X3, Y, 
               xlims1=None, xlims2=None, xlims3=None, ymax=None,
               X1lab='dBZ', X2lab='ZDR', X3lab=r'Kdp (dB km$^{-1}$)', ylab=None,
               label=True, labelTx=' ', labelpos=None):
    """Create a 3-panel vertical plot of reflectivity, differential reflectivity,
      and specific differential phase.
    """
    fig, (ax1, ax2, vax3) = plt.subplots(1, 3, sharey=True)
    
    if xlims1 is None:
      xlims1 = (-20, 30.)    
    if xlims2 is None:
      xlims2 = (-1.5, 1.5)
    if xlims3 is None:
      xlims3 = (.2, .4)
    if ymax is None:
      ymax = 10.
    ax1.plot(X1, Y, color='k')
    ax2.plot(X2, Y, color='k')
    ax3.plot(X3, Y, color='k')
    ax1.set_xlim(xlims1)
    ax2.set_xlim(xlims2)
    ax3.set_xlim(xlims3)
    ax1.set_xlabel(X1lab)
    ax2.set_xlabel(X2lab)
    ax3.set_xlabel(X3lab)
    
    # Set y axis characteristics
    ax1.set_ylim(0., ymax)
    if ylab is None:
        ax1.set_ylabel('Altitude (km)')
    else:
        ax1.set_ylabel(ylab)
    ax1.vlines(0,0,ymax)
    ax2.vlines(0,0,ymax)
    ax1.xaxis.grid(color='k', ls=':', lw=1)
    ax2.xaxis.grid(color='k', ls=':', lw=1)
    ax3.xaxis.grid(color='k', ls=':', lw=1)
    ax1.yaxis.grid(color='k', ls=':', lw=.5)
    ax2.yaxis.grid(color='k', ls=':', lw=.5)
    ax3.yaxis.grid(color='k', ls=':', lw=.5)
    # Add label to above plot unless location specified
    if label:
        if labelpos is None:
            labelpos = (.15,.91)
        plt.figtext(labelpos[0], labelpos[1], labelTx)

    return fig, ax1, ax2, ax3
Example #7
0
    def __init__(self, poll, parties, elections=None, join_coalitions=True):
        plt.rcParams['figure.figsize'] = (12, 6)

        self._fig, ax = plt.subplots()

        plt.rcParams['xtick.labelsize'] = 16
        plt.rcParams['axes.labelweight'] = 'bold'
        plt.rcParams['font.weight'] = 'normal'
        plt.rcParams['xtick.major.pad']='16'
        plt.rcParams['axes.titlesize'] = 20
        plt.rcParams['axes.titleweight'] = 'bold'

        parties_votes = []

        for i, p in enumerate(parties.parties.values()):    
                parties_votes.append((p, poll.get_party(p,join_coalitions)))
                
        parties_votes.sort(key=lambda x: x[1], reverse=True)
        parties_votes = []
        for i, p in enumerate(parties.parties.values()):    
            parties_votes.append((p, poll.get_party(p,join_coalitions)))
            
        parties_votes.sort(key=lambda x: x[1], reverse=True)
        width = 0.6
        left_lim = 0.1
        plt.title(poll.pollster + poll.date.strftime(' - %-d %b'), loc='left', x=0, y=1.1, fontdict={'ha':'left'})
        names = []
        for i, (p, votes) in enumerate(parties_votes):    
            a = ax.bar(left_lim+i, votes, width=width, color=p.color, edgecolor='none')
            ax.text(left_lim+i+width/2, votes-4, '{0}%'.format(votes), 
                   fontdict={'weight':'bold', 'color':'w', 'fontsize':'20', 'ha':'center', 'va':'center'})
            names.append(p.short_name)
            if elections:
                vot =elections.get_party(p,join_coalitions)
                if a:
                    plt.plot([left_lim+i-0.1*width, left_lim+i+width+0.1*width], [vot, vot], color=[0.2,0.2,0.2], linewidth=3)

        idx = np.arange(len(parties.parties))+width/2 + left_lim
        ax.set_xticks(idx)
        ax.set_xlim([0, idx[-1]+width/2 + left_lim])
        ax.set_xticklabels(names);
        ax.spines['top'].set_visible(False)
        ax.spines['right'].set_visible(False)
        ax.spines['left'].set_visible(False)
        ax.xaxis.set_ticks_position('none') 
        ax.yaxis.set_ticks_position('none') 
        if poll.error:
            plt.figtext(0.125,.94,'({}% error)'.format(poll.error), fontdict={'fontsize': 12})
Example #8
0
def draw_plot(states, times, caption):
    try:
        with plt.xkcd():
            #plt.style.use('fivethirtyeight')
            fig, ax = plt.subplots(nrows=1, ncols=1, sharex=True, sharey=True)
            fig.suptitle('Spring damping over time',  fontsize=18, fontweight='bold')

            displacement = [n[0] for n in states]
            ax.plot(times, displacement)

            ax.set_xlabel('Time (s)')
            ax.set_ylabel('Displacement (m)')
            ax.axis('tight')
            figtext(.52, .15, caption)
            plt.show()

    except Exception as ex:
        print(ex)
Example #9
0
def plot_zdr_rhv(X1, X2, Y, xlims1=None, xlims2=None, ymax=None,
               label=True, labelTx=' ', labelpos=None):
    """Create a vertical plot of differential reflectivity and copolar correlation
    coefficient.
    """
    fig, ax = plt.subplots()
    axes = [ax, ax.twiny()]
    
    if xlims1 is None:
      xlims1 = (-1.5, 1.5)
    if xlims2 is None:
      xlims2 = (.8, 1.)
    if ymax is None:
      ymax = 10.
      
    axes[0].plot(X1, Y, label='Differential Reflectivity', color='b')
    axes[1].plot(X2, Y, label='CoPolar Correlation Coefficient', color='r')
    axes[0].set_xlim(xlims1)
    axes[1].set_xlim(xlims2)
    axes[0].set_xlabel('Differential Reflectivity (dB)')
    axes[1].set_xlabel('CoPolar Correlation Coefficient')
    axes[0].tick_params(axis='x', colors='b')
    axes[1].tick_params(axis='x', colors='r')
    axes[0].xaxis.label.set_color('b')
    axes[1].xaxis.label.set_color('r')
    axes[0].set_ylim(0., ymax)
    axes[0].set_ylabel('Altitude (km)')
    axes[0].vlines(0, 0, ymax)
    axes[0].xaxis.grid(color='b', ls=':', lw=1)
    axes[1].xaxis.grid(color='r', ls=':', lw=1)
    axes[0].yaxis.grid(color='k', ls=':', lw=.5)
    
    handles1, labels1 = axes[0].get_legend_handles_labels()
    handles2, labels2 = axes[1].get_legend_handles_labels()
    plt.legend([handles1[0], handles2[0]],
            ['Differential Reflectivity','CoPolar Correlation Coefficient'],
            loc=6, fontsize =11)
    # Add label to lower left in plot unless location specified
    if label:
        if labelpos is None:
            labelpos = (.15, .15)
        plt.figtext(labelpos[0], labelpos[1], labelTx)

    return fig, ax, axes
Example #10
0
def pressSat(event):
     tempData=np.nan_to_num(theData.data)
     maxHarg=np.argmax(tempData[:,1])
     minHarg=np.argmin(tempData[:,1])
        
     '''linear fit to saturated data (+- 25 points from max/min field)
     '''   
     highFit=np.polyfit(theData.data[maxHarg-25:maxHarg+25,1],theData.data[maxHarg-25:maxHarg+25,2],1)
     lowFit=np.polyfit(theData.data[minHarg-25:minHarg+25,1],theData.data[minHarg-25:minHarg+25,2],1)
        
     '''  Average intercept
     '''   
     fitSat=(highFit[1]-lowFit[1])/2

        
     ''' display ms
      '''
     txtSat='ms = '+str(fitSat)
     plt.figtext(0.75, 0.4,txtSat)
     theData.fitSat=fitSat
Example #11
0
def pressSat(event):
     tempData=np.nan_to_num(theData.data)
     maxHarg=np.argmax(tempData[:,1])
     minHarg=np.argmin(tempData[:,1])

     '''linear fit to saturated data (+- 25 points from max/min field)
     '''
     highFit=np.polyfit(theData.data[maxHarg-25:maxHarg+25,1],theData.data[maxHarg-25:maxHarg+25,2],1)
     lowFit=np.polyfit(theData.data[minHarg-25:minHarg+25,1],theData.data[minHarg-25:minHarg+25,2],1)

     '''  Average intercept
     '''
     fitSat=(highFit[1]-lowFit[1])/2


     ''' display ms
      '''
     txtSat='ms = '+str(fitSat)
     plt.figtext(0.75, 0.4,txtSat)
     theData.fitSat=fitSat
Example #12
0
def plot_add_stats(instance=None,
                   avg=None,
                   sd=None,
                   points=None,
                   good_samples=None,
                   tot_samples=None,
                   labelpos=None):
    """Add text to the figure that contains statistics."""
    if labelpos is None:
        labelpos = (.15, .7)
    if instance == 'single':
        plt.figtext(
            labelpos[0], labelpos[1],
            "Avg Zdr = %g\nStd Dev = %g\nPoints = %g\n" % (avg, sd, points))
    elif instance == 'multi':
        plt.figtext(
            labelpos[0], labelpos[1],
            "Avg Zdr = %g\nStd Dev = %g\nSamples = %g used of %g total\nPoints = %g\n"
            % (avg, sd, good_samples, tot_samples, points))
    else:
        print "Need to supply either single or multiple run statistics!!"
Example #13
0
    def print_info(self):

        try:
            pat_surname, pat_firstname = self.dicom.PatientName.split('^')
        except ValueError:
            pat_surname = self.dicom.PatientName
            pat_firstname = ''

        pat_name = ' '.join((pat_surname, pat_firstname.title()))

        pat_id = self.dicom.PatientID
        pat_sex = self.dicom.PatientSex
        pat_bdate = datetime.strptime(
            self.dicom.PatientBirthDate, '%Y%m%d').strftime("%e %b %Y")

        info = "%s (%s) sex: %s\nbirthdate: %s" % (pat_name, pat_id,
                                                   pat_sex, pat_bdate)
        plt.figtext(0.08, 0.865, info, fontsize=12)

        info = "duration: %s s | samples: %s | sample freq.: %s/s" % (
            self.duration,
            self.samples,
            self.sampling_frequency)
        plt.figtext(0.08, 0.02, info, fontsize=10)

        info = "%s mm/s | %s mm/mV" % (self.mm_s, self.mm_mv)
        plt.figtext(0.68, 0.02, info, fontsize=10)

        plt.figtext(0.5, 0.865, self.legend(), fontsize=10)

        info = 'E. O. Ospedali Galliera\nECG date: '
        date_str = (self.dicom.InstanceCreationDate +
                    self.dicom.InstanceCreationTime)
        info += datetime.strftime(datetime.strptime(date_str,
                                                    '%Y%m%d%H%M%S'),
                                  '%d %b %Y %H:%M')
        plt.figtext(0.03, 0.94, info, fontsize=12)
Example #14
0
def draw_per_score(date, gets=[0, 10, 20, 40, 50]):
    st = time.time()

    # 그래프 기초 설정
    preset_ps()
    plt.title(f"소녀전선 한국서버 <허수미궁+> {date} 분포 그래프")

    # 점, 그래프 그리기
    ps_scatter(date, marker='s', label="전체 표본")
    ps_plot(date, annotate=gets, label="예상 점수 그래프")
    # 가로선 그리기
    draw_axhline(200000, '황금요정 확정지급 점수\n200,000점')
    draw_axhline(400000, '최고등급 보상 확정지급 점수\n400,000점')

    # 범례
    plt.legend(loc=1)
    plt.figtext(0.10, 0.04, "36베이스 - 소녀전선 데이터베이스 https://girlsfrontline.kr", ha="left", va="top", alpha=0.5, size=12)
    plt.figtext(0.94, 0.04, "구글 설문 및 36베이스 카카오톡 봇으로 표본 조사중입니다. 많이 참여해주세요.", ha="right", va="top", alpha=0.5, size=12)

    # 저장
    # plt.show()
    plt.savefig(f'../image/{event_name}/per_score/{date}.png')
    print(f">>> {time.time() - st} secs.")
    return
Example #15
0
def add_header(text_1="", text_2="", text_3="", fontsize=15):
    """
	Add text footer to a figure.



	Author: Albenis Pérez Alarcón
	contact:[email protected]
	
	Parameters
	----------

	text_1 : str
	text_2 : str
	text_3 : str


	Returns
	-------
	`matplotlib.image.FigureImage`
	The `matplotlib.image.FigureImage` instance created

	"""

    coords = plt.gca().get_position().get_points()
    plt.figtext((coords[0, 0] + 0.50) / 2.0,
                0.97,
                text_1,
                horizontalalignment='center',
                verticalalignment='center',
                fontsize=fontsize,
                fontweight="bold")

    plt.figtext((coords[0, 0] + 1.5) / 2.0,
                0.97,
                text_2,
                horizontalalignment='center',
                verticalalignment='center',
                fontsize=fontsize,
                fontweight="bold")

    plt.figtext((coords[0, 0] + 0.44) / 2.0,
                0.93,
                text_3,
                horizontalalignment='center',
                verticalalignment='center',
                fontsize=fontsize - 2)
    return
Example #16
0
def add_footer(text_1="", text_2="", text_3="", fontsize=13):
    """Add footer to a figure.

	Add text footer to a figure.


	Author: Albenis Pérez Alarcón
	contact:[email protected]
	
	Parameters
	----------

	text_1 : str
	text_2 : str
	text_3 : str
	text to put in the figure, all text are lower center	

	Returns
	-------
	`matplotlib.image.FigureImage`
	The `matplotlib.image.FigureImage` instance created

	"""

    coords = plt.gca().get_position().get_points()

    plt.figtext((coords[0, 0] + 1.) / 2.0,
                0.09,
                text_1,
                fontsize=fontsize,
                horizontalalignment='center',
                fontweight='bold')
    plt.figtext((coords[0, 0] + 1.) / 2.0,
                0.07,
                text_2,
                horizontalalignment='center',
                verticalalignment='center',
                fontsize=fontsize)

    plt.figtext((coords[0, 0] + 1.) / 2.0,
                0.03,
                text_3,
                horizontalalignment='center',
                verticalalignment='center',
                fontsize=fontsize)
    return
Example #17
0
def plot_(fig, l1, l2, t):
    plt.figure(fig)
    plt.xlabel(l1)
    plt.ylabel(l2)
    plt.title(t)


j = 0

for i in range(df.shape[1]):
    df = df.rename(columns={i: header[i]})
    if header[i] in continuous:
        dist = df[header[i]].sort_values()
        plot_(j, 'values', header[i], header[i])
        dist.plot.hist(bins=20)
        plt.figtext(1, 0.4, df[header[i]].describe())
    else:
        dist = df[header[i]].value_counts(sort=False)
        miss = [' Not in universe', ' ?', ' Not in universe or children', ' Not in universe under 1 year old']
        m = 0
        for k in miss:
            if k in dist.index.tolist():
                m = +dist[k]
                dist = dist.drop(k)
        dist = dist * 100. / df.shape[0]
        if df[header[i]].dtype == 'int64':
            plot_(j, 'categories', 'Frequency', header[i])
            df[header[i]].hist(bins=50)
        else:
            plot_(j, 'categories', 'Percentage', header[i])
            dist.plot.bar()
Example #18
0
#ablated_fitness[1] = '#cc7a00'
connect(axnet2, DA, DD, "arc3,rad= 0.00", Rs, ablated_fitness[6])
connect(axnet2, AS, DA, "arc3,rad= 0.00", Rs, ablated_fitness[0])
connect(axnet2, AS, VD, "arc3,rad= 0.00", Rs, ablated_fitness[1])
connect(axnet2, DA, DB, "arc3,rad= 0.00", Rs, ablated_fitness[2])
connect(axnet2, DB, AS, "arc3,rad= 0.00", Rs, ablated_fitness[3])
connect(axnet2, VD, VA, "arc3,rad= 0.00", Rs, ablated_fitness[4])
connect(axnet2, VD, VB, "arc3,rad= 0.00", Rs, ablated_fitness[5])
connect(axnet2, VB, DD, "arc3,rad= 0.00", Rs, ablated_fitness[7])
connect(axnet2, VA, DD, "arc3,rad= 0.00", Rs, ablated_fitness[8])
Gapjunction(axnet2, VD, DD, "arc3,rad= 0.0", Rs, ablated_fitness[9])

for ax in [axnet1, axnet2]:
    ax.set_xlim(-0.5, 10.5)
    ax.set_ylim(-1.0, 19.5)
    ax.axis('off')
    ax.set_aspect('equal')
####################################################################

####################################################################
fz = 88
plt.figtext(0.02, 0.94, 'A', ha='center', va='center', fontsize=fz)
plt.figtext(0.22, 0.94, 'B', ha='center', va='center', fontsize=fz)
plt.figtext(0.62, 0.94, 'C', ha='center', va='center', fontsize=fz)

fig.subplots_adjust(left=0.02, bottom=0.15, right=1.00, top=1.00)
plt.savefig('dv_propagation.png', dpi=100)
plt.savefig('dv_propagation.pdf')
#######################################################################
#######################################################################
def age_plot(dataname2age2num, age2pval, age2label, outfn, plot_type='bar', 
             title='', output_png=False, scale_x=False, xlabel='Age', 
             methods_str=''):
    """  """
    ages = sorted(age2label.keys())

    fig = plt.figure()
    ax1 = fig.add_subplot(111)
    plt.subplots_adjust(bottom=0.27)

    width = 0.35

    plt.xlabel(xlabel)
    plt.ylabel('Fraction')

    # hack to make sure background is last if present
    data_names = []; bgs = []
    for name in sorted(dataname2age2num):
        if 'ackground' in name:
            bgs.append(name)
        else:
            data_names.append(name)
    data_names += bgs
      
    dataname2avgdepth = {}
    for dataname_idx, name in enumerate(data_names):
        # compute average depth, age, and total number of proteins
        N = 0.
        avg_depth = 0.
        avg_age = 0.
        for age in dataname2age2num[name]: 
            N += dataname2age2num[name][age]
            avg_depth += (age * dataname2age2num[name][age])

            try:
                avg_age += (float(age2label[age]) * dataname2age2num[name][age])
            except ValueError:
                avg_age += (age * dataname2age2num[name][age])

        avg_age /= N
        avg_depth /= N

        # plot data
        heights = []
        x_base = []
        for age_idx, age in enumerate(ages):
            if age in dataname2age2num[name] and \
                    dataname2age2num[name][age] != 0.0:
                heights.append(dataname2age2num[name][age] / N)
                x_base.append(age if scale_x else age_idx)
            else:
                heights.append(0.0)
                x_base.append(age if scale_x else age_idx)

        # line or bar plot
        if plot_type == 'line':
            line_color = '#990000' if dataname_idx % 2 == 0 else 'black'
            ax1.plot(x_base, heights, 'x-', label='%s (N=%d)' % (name, N), 
                     linewidth=2, mew=3, markersize=8, color=line_color)

        else:
            r = numpy.array(x_base, dtype='float_')
            bar_color = '#990000' if dataname_idx % 2 == 1 else 'black'
            r += .03 if dataname_idx % 2 == 1 else -.03

            ax1.bar(r - width * (1-dataname_idx), heights, width, 
                    label='%s (N=%d)' % (name, N), color=bar_color)



    # now set up axes limits and ticks
    ax1.set_xticks(x_base)
    x_range = x_base[-1] - x_base[0]
    pad = max(.03 * x_range, 1)
    ax1.set_xlim(x_base[0] - pad, x_base[-1] + pad)

    ymin = ax1.viewLim.ymin
    ymax = ax1.viewLim.ymax
    y_range = ymax - ymin

    ax1.set_ylim(-.05 * y_range, ymax + (.23 * y_range))

    leg = ax1.legend(prop={'size': 12}, loc='upper left', numpoints=1)
    leg.get_frame().set_fill(False)
    #leg.draw_frame(False)

    # write p-value *'s
    for age_idx, age in enumerate(ages):
        if age in age2pval:
            pval_str = ''
            if .01 < age2pval[age] < 0.05:
                pval_str = '*'
            elif .001 < age2pval[age] <= 0.01:
                pval_str = '**'
            elif age2pval[age] <= 0.001:
                pval_str = '***'

            ax1.text(age if scale_x else age_idx, ymin - (.025 * y_range), 
                     pval_str, horizontalalignment='center', 
                     verticalalignment='center', weight='bold')

    # set x_tick names
    labels = []
    for age in ages:
        if age in age2label:
            label = age2label[age]
            if label != str(age):
                labels.append('%s (%d)' % (label, age))
            else:
                labels.append('%d' % age)
        else:
            labels.append('')

    xtickNames = plt.setp(ax1, xticklabels = labels)
    plt.setp(xtickNames, fontsize=10)
    plt.setp(xtickNames, rotation=30)
    plt.setp(xtickNames, horizontalalignment='right')


    title_obj = plt.title(title, fontsize=12)

    plt.figtext(0.07, 0.01, '[DB: '+methods_str+']', size=9)

    plt.savefig(outfn)
    if output_png: plt.savefig(outfn.replace('.pdf', '.png'))
    
    return
Example #20
0
    def print_info(self, interpretation):
        """Print info about the patient and about the ecg signals.
        """

        try:
            pat_surname, pat_firstname = self.dicom.PatientName.decode('ISO-8859-1').split('^')
        except ValueError:
            pat_surname = self.dicom.PatientName
            pat_firstname = ''

        pat_name = ' '.join((pat_surname, pat_firstname.title()))
        pat_age = self.dicom.get('PatientAge', '').strip('Y')

        pat_id = self.dicom.PatientID
        pat_sex = self.dicom.PatientSex
        try:
            pat_bdate = datetime.strptime(
                self.dicom.PatientBirthDate, '%Y%m%d').strftime("%e %b %Y")
        except ValueError:
            pat_bdate = ""

        # Strip microseconds from acquisition date
        regexp = "\.\d+$"
        acquisition_date_no_micro = re.sub(
            regexp, '', self.dicom.AcquisitionDateTime)

        acquisition_date = datetime.strftime(
            datetime.strptime(
                acquisition_date_no_micro, '%Y%m%d%H%M%S'),
            '%d %b %Y %H:%M'
        )

        info = "%s\n%s: %s\n%s: %s\n%s: %s (%s %s)\n%s: %s" % (
            pat_name,
            i18n.pat_id,
            pat_id,
            i18n.pat_sex,
            pat_sex,
            i18n.pat_bdate,
            pat_bdate,
            pat_age,
            i18n.pat_age,
            i18n.acquisition_date,
            acquisition_date
        )

        plt.figtext(0.08, 0.87, info, fontsize=8)

        plt.figtext(0.30, 0.87, self.legend(), fontsize=8)

        if interpretation:
            plt.figtext(0.45, 0.87, self.interpretation(), fontsize=8)

        info = "%s: %s s %s: %s Hz" % (
            i18n.duration, self.duration,
            i18n.sampling_frequency,
            self.sampling_frequency
        )

        plt.figtext(0.08, 0.025, info, fontsize=8)

        info = INSTITUTION
        if not info:
            info = self.dicom.get('InstitutionName', '')

        plt.figtext(0.38, 0.025, info, fontsize=8)

        # TODO: the lowpass filter 0.05-40 Hz will have to became a parameter
        info = "%s mm/s %s mm/mV 0.05-40 Hz" % (self.mm_s, self.mm_mv)
        plt.figtext(0.76, 0.025, info, fontsize=8)
def feature_by_age_boxplot(age2vals, age2label, outfn, title='', xlabel='Age',
                           ylabel='Value', scale_x = False, output_png=False, 
                           methods_str=''):
    fig = plt.figure()

    if len(age2vals.keys()) > 1:
        fig_width = fig.get_figwidth()
        fig_height = fig.get_figheight()
        fig.set_figwidth(fig_width * 1.7)
        fig.set_figheight(fig_height * 1.2)

    ax1 = fig.add_subplot(111)
    plt.subplots_adjust(bottom=0.26)
    
    ages = sorted(age2label.keys())

    box_data = []
    box_pos = []
    for i, age in enumerate(ages):
        if age in age2vals:
            box_data.append(age2vals[age])
            box_pos.append(age if scale_x else i)
        else:
            box_data.append([])
            box_pos.append(age if scale_x else i)

    bp = plt.boxplot(box_data, widths=.6, sym='', patch_artist=True, 
                     positions=box_pos)

    plt.setp(bp['boxes'], color='#99CCFF', edgecolor="black", lw=1)
    #plt.setp(bp['boxes'], color='darkkhaki', edgecolor="black", lw=1)
    plt.setp(bp['whiskers'], color='black', lw=1)
    plt.setp(bp['medians'], color='black', lw=1.5)
    plt.setp(bp['caps'], color='black', lw=1)


    for i, age in enumerate(ages):
        x_pos = age if scale_x else i
        if age in age2vals:
            ax1.plot(x_pos, numpy.average(age2vals[age]), 'x', color='red', 
                     markersize=6, markeredgewidth=1.5)


    if age2label: 
        labels = []
        for age in ages:
            if age < 0: 
                labels.append('')
            elif age in age2label:
                np = len(age2vals[age]) if age in age2vals else 0
                labels.append('%s (%d)' % (age2label[age], age))
                #labels.append('%s (n=%d)' % (age2label[age], np))
            else:
                labels.append('')

        xtickNames = plt.setp(ax1, xticklabels = labels)
        plt.setp(xtickNames, fontsize=10)
        plt.setp(xtickNames, rotation=45)
        plt.setp(xtickNames, horizontalalignment='right')


    ymin = ax1.viewLim.ymin
    ymax = ax1.viewLim.ymax
    y_range = ymax - ymin
    #ax1.set_ylim(-.05 * ymin, 1.05 * ymax)
    ax1.set_ylim(ymin - (.02 * y_range), ymax + (.02 * y_range))

    xmin = ax1.viewLim.xmin
    xmax = ax1.viewLim.xmax
    x_range = xmax - xmin
    pad = .02 * x_range
    ax1.set_xlim(xmin - pad, xmax + pad)


    plt.xlabel(xlabel)
    plt.ylabel(ylabel)

    plt.title(title)

    plt.figtext(0.1, 0.01, '[DB: '+methods_str+']', size=10)

    plt.savefig(outfn)
    if output_png: plt.savefig(outfn.replace('.pdf', '.png'))
    
    return
Example #22
0
    for i in range(1, ceval):
        xeval = -cset[i] / mset[i]
        yeval = mset[i - 1] * xeval + cset[i - 1]
        plt.plot([xeval, xeval], [0, yeval], '.k', ms=13)
        plt.plot([xeval, xeval], [0, yeval], '.g', ms=9)
        wl += (yeval) / 22. / (ceval - 1)

    wavelength[ind] = wl

    ax1.set_xlim(0, 350)

    #####################################
    plt.figtext(0.053,
                0.93,
                'wavelength ~= %.2f worm length' % (wl),
                ha='left',
                va='center',
                fontsize=20)

    fig.subplots_adjust(left=0.05, bottom=0.04, right=0.98, top=0.96)
    plt.savefig('wavelength_figures/plot_sel_%d.png' % ind)

### The script fails in this 7 solution, they were calculated manually.
#wavelength[48] = 0.7
#wavelength[52] = 0.75
#wavelength[60] = 0.9
#wavelength[67] = 0.8
#wavelength[72] = 0.8
#wavelength[97] = 0.85
#wavelength[100] = 0.8
Example #23
0
def plot_clades_relationships(clade_pairs, folder, remove_highest=0):

    ds = get_dataset('Stool')
    ds = compute_relative_values(ds)

    # Use numeric Tree. We will discreteze relevant values ourselves
    # and plot the numeric correlations
    tree = Tree(ds)

    same_lineages = 0

    for clade_1, clade_2 in clade_pairs:

        # Get the nodes in the phylogenetic tree
        from_node = tree.node_for_clade_name(clade_1)
        to_node = tree.node_for_clade_name(clade_2)

        if from_node.is_in_lineage(to_node):
            same_lineages += 1

        title_text = 'Relative clade abundances'
        title(title_text)
        # find from-to bacteria abundances
        xs = []
        ys = []

        # Get the total abundance for hte clades in the tree
        abundance_from = tree.abundance_column_in_subtree(from_node)
        abundance_to = tree.abundance_column_in_subtree(to_node)

        x_zeroes = 0
        y_zeroes = 0


        # List the in-sample values for each sample
        for index, _row in enumerate(ds[1:]):
            from_abundance = abundance_from[index]
            to_abundance = abundance_to[index]

            if from_abundance == 0.0:
                x_zeroes += 1

            if to_abundance == 0.0:
                y_zeroes += 1

            # if from_abundance < 0.01 and to_abundance < 0.01:
            xs.append(from_abundance)
            ys.append(to_abundance)
            # else:
            #     xs.append(0.0)
            #     ys.append(0.0)

        if remove_highest > 0.0:
            xs, ys = pairwise_remove_highest_values(remove_highest, xs, ys)
            ys, xs = pairwise_remove_highest_values(remove_highest, ys, xs)

                        # All data was eventyally removed
            if len(xs) == 0:
                print 'Warning. lowest values:%f removed all data from caldes:%s-%s' % (remove_highest, from_node.name, to_node.name)
                continue

        print 'x zeroes: ', x_zeroes
        print 'y zeroes: ', y_zeroes
        grid(True)

        text_x = 0.67
        sample_points = 'Sample points: %d' % len(xs)
        figtext(text_x, 0.85, sample_points, fontsize=10)

        from_clade = from_node.name.replace('|', '-')
        to_clade = to_node.name.replace('|', '-')
        xlabel(from_clade, fontsize=10)
        ylabel(to_clade, fontsize=10)

        disc_x, discrete_xs = discretize_row(xs, maxent_discretization_splitter)
        disc_y, discrete_ys = discretize_row(ys, maxent_discretization_splitter)

        # plot discretization lines
        a, b = [disc_x, disc_x], [-0.001, max(ys)]
        c, d = [-0.001, max(xs)], [disc_y, disc_y]
        plot(a, b, c='r')
        plot(c, d, c='r')

        # Discrete bin sizes
        pairs = zip(discrete_ys, discrete_xs)
        _00 = '00: ' + str(len([x for x in pairs if x == (0,0)]))
        _01 = '01: ' + str(len([x for x in pairs if x == (0,1)]))
        _10 = '10: ' + str(len([x for x in pairs if x == (1,0)]))
        _11 = '11: ' + str(len([x for x in pairs if x == (1,1)]))
        figtext(text_x, 0.82, _00, fontsize=10)
        figtext(text_x, 0.79, _01, fontsize=10)
        figtext(text_x, 0.76, _10, fontsize=10)
        figtext(text_x, 0.73, _11, fontsize=10)
        phi_coeff, phi_r = pearsonr(discrete_xs, discrete_ys)
        phi = 'phi: %f, %f' % (phi_coeff, phi_r)
        figtext(text_x, 0.70, phi, fontsize=10)

        # Depth of nodes in the phylogenetic tree
        from_depth = 'x depth: %d' % from_node.depth
        to_depth = 'y depth: %d' % to_node.depth
        figtext(text_x, 0.67, from_depth, fontsize=10)
        figtext(text_x, 0.64, to_depth, fontsize=10)

        # Discretization values
        median_x = 'splitter x: %f' % disc_x
        median_y = 'splitter y: %f' % disc_y
        figtext(text_x, 0.61, median_x, fontsize=10)
        figtext(text_x, 0.58, median_y, fontsize=10)

        # Same lineage
        same_lineage = 'False'
        if tree.nodes_have_same_lineage(from_node, to_node):
            same_lineage = ' True'
        figtext(text_x, 0.55, 'Same lineage: ' + same_lineage, fontsize=10)

        # Pearson and spearman correlations
        try:
            pearson = pearsonr(xs, ys)
            spearman = spearmanr(xs, ys)

            pearson = 'Pearson: %.3f, %.3f' % (pearson[0], pearson[1])
            spearman = 'Spearman: %.3f, %.3f' % (spearman[0], spearman[1])

            figtext(text_x, 0.52, pearson, fontsize=10)
            figtext(text_x, 0.49, spearman, fontsize=10)
        except Exception, e:
            print e
            print 'clades1: ', from_node.name
            print 'clades2: ', to_node.name
            print 'xs: %s', xs
            print 'ys: %s', ys

        # vals = vals[:-20]
        scatter(xs, ys, s=1, color='#0066FF')
        file_name = folder + from_node.name.replace('|', '-').replace('/', '%') + '---' + to_node.name.replace('|', '-').replace('/', '%')
        # file_name = os.path.join(dir, file_name)
        # print '[RESULT] ', file_name
        # print vals
        savefig(file_name)
        close()
Example #24
0
def GeneByGeneOutput(setOfAligns,parameters):
    logging.info('Making the GBG plots...')
    h = 2.0 # plot hieght
    l = 4.0 # plot width
    MB = 0.05 # percent buffer from side
    LB = 0.01 # percent buffer for corner
    seq1len = setOfAligns.seqOfInt.length
    colors = ['b','g','r','c','m']
    
    plotNum = 0
    plots = 0
    
    GBGdata = open(parameters['OUTFILE'] + '/images/GBGdata.txt','wb')
    GBGdata.write('GBGX.pdf:ts1!ts2!ts3!ts4!\n')
    
    numToExpect = 0
    for pAlign in setOfAligns.aligns:
        if len(pAlign.localAligns) > 0:
            numToExpect += 1
    
    for pAlign in setOfAligns.aligns:
        if len(pAlign.localAligns) > 0:
            if plotNum%4 == 0:
                fig = plt.figure(figsize=(22,17))
                plots += 1
                plt.figtext(0.5, 0.965,  'Local Alignments for soi: ' + setOfAligns.seqOfInt.name + ', test seqs (' + str(1+(plots-1)*4) + '-' + str(min(4+(plots-1)*4,numToExpect)) + '/' + str(numToExpect), ha='center', color='black', weight='bold', size='large')
                gbgstring = 'GBG' + str(plots) + '.pdf:'
                ax = []
                ax.append(fig.add_subplot(411))
                plotNum = 0
            else:
                ax.append(fig.add_subplot(411+plotNum%4))
            seq2len = pAlign.testSeq.length
            seq1las = []
            seq2las = []
            seqRatio = []
            scoreRolling = 0
            for locA in pAlign.localAligns:
                
                for i in range(len(locA.SOIrange)):
                    seq1las.append(locA.SOIrange[i])
                    seq2las.append(locA.TSrange[i])
                    if setOfAligns.seqOfInt.dataDepths != 0:
                        scoreSum = sum(locA.fullScoreVec[locA.SOIrange[i][0]:locA.SOIrange[i][1]])
                    else:
                        scoreSum = sum(locA.fullScoreVec[locA.SOIrange[i][0]:locA.SOIrange[i][1]])
                    seqRatio.append(scoreSum/float(locA.SOIrange[i][1]-locA.SOIrange[i][0]))
                    scoreRolling += scoreSum
            totRatio = [scoreRolling/float(seq1len),scoreRolling/float(seq2len)]

            if seq1len <= seq2len:
                rL = 0.3 # relitive y start of lower
                rU = 0.7 # relitive y start of higher
                ratio = (seq2len - seq1len)/float(2*seq2len)
                s1xm = MB + ratio
                s1xx = 1 - MB - ratio
            else:
                rL = 0.7 # relitive y start of lower
                rU = 0.3 # relitive y start of higher
                ratio = (seq1len - seq2len)/float(2*seq1len)
                s1xm = MB + ratio
                s1xx = 1 - MB - ratio
            # top, smaller line
            ax[plotNum].axhline(y = rU*h, xmin = s1xm, xmax = s1xx, color='black')
            ax[plotNum].plot([s1xm*l,s1xm*l],[rU*h - 3*MB, rU*h + 3*MB],color='black') # left bound
            ax[plotNum].plot([s1xx*l,s1xx*l],[rU*h - 3*MB, rU*h + 3*MB],color='black') # right bound
            ax[plotNum].axhline(y = rU*h - 3*MB, xmin = s1xm, xmax = s1xm + LB, color='black') # left lower corner
            ax[plotNum].axhline(y = rU*h + 3*MB, xmin = s1xm, xmax = s1xm + LB, color='black') # left upper corner
            ax[plotNum].axhline(y = rU*h - 3*MB, xmin = s1xx, xmax = s1xx - LB, color='black') # right lower corner
            ax[plotNum].axhline(y = rU*h + 3*MB, xmin = s1xx, xmax = s1xx - LB, color='black') # right upper corner
            
            # bottom, larger line
            ax[plotNum].axhline(y = rL*h, xmin = MB, xmax = 1 - MB, color='black') # main line
            ax[plotNum].plot([MB*l,MB*l],[rL*h - 3*MB, rL*h + 3*MB],color='black') # left bound
            ax[plotNum].plot([(1 - MB)*l,(1 - MB)*l],[rL*h - 3*MB, rL*h + 3*MB],color='black') # right bound
            ax[plotNum].axhline(y = rL*h - 3*MB, xmin = MB, xmax = MB + LB, color='black') # left lower corner
            ax[plotNum].axhline(y = rL*h + 3*MB, xmin = MB, xmax = MB + LB, color='black') # left upper corner
            ax[plotNum].axhline(y = rL*h - 3*MB, xmin = 1 - MB, xmax = 1 - (MB + LB), color='black') # right lower corner
            ax[plotNum].axhline(y = rL*h + 3*MB, xmin = 1 - MB, xmax = 1 - (MB + LB), color='black') # right upper corner
            if seq1len <= seq2len:
                ax[plotNum].text(MB*l - MB/2*l, rL*h, '0',verticalalignment='center') # left text, bot
                ax[plotNum].text((1 - MB)*l + MB/4*l, rL*h + 3*MB, str(seq2len),verticalalignment='center') # right text1, bot
                ax[plotNum].text((1 - MB)*l + MB/4*l, rL*h - 3*MB, str(totRatio[1])[0:5],verticalalignment='center') # right text2, bot
                ax[plotNum].text(s1xm*l - MB/2*l, rU*h, '0',verticalalignment='center') # left text, top
                ax[plotNum].text(s1xx*l + MB/4*l, rU*h + 3*MB, str(seq1len),verticalalignment='center') # right text1, top
                ax[plotNum].text(s1xx*l + MB/4*l, rU*h - 3*MB, str(totRatio[0])[0:5],verticalalignment='center') # right text2, top
            else:
                ax[plotNum].text(MB*l - MB/2*l, rL*h, '0',verticalalignment='center') # left text, bot
                ax[plotNum].text((1 - MB)*l + MB/4*l, rL*h + 3*MB, str(seq1len),verticalalignment='center') # right text1, bot
                ax[plotNum].text((1 - MB)*l + MB/4*l, rL*h - 3*MB, str(totRatio[0])[0:5],verticalalignment='center') # right text2, bot
                ax[plotNum].text(s1xm*l - MB/2*l, rU*h, '0',verticalalignment='center') # left text, top
                ax[plotNum].text(s1xx*l + MB/4*l, rU*h + 3*MB, str(seq2len),verticalalignment='center') # right text1, top
                ax[plotNum].text(s1xx*l + MB/4*l, rU*h - 3*MB, str(totRatio[1])[0:5],verticalalignment='center') # right text2, top
            # local alignments
            for i in range(len(seq1las)):
                if seq1len <= seq2len:
                    ax[plotNum].text(l*(MB + (1 - 2*MB)*seq2las[i][0]/float(seq2len) + MB + (1 - 2*MB)*seq2las[i][1]/float(seq2len) + s1xm + (1 - 2*MB)*seq1las[i][0]/float(seq2len) + s1xm + (1 - 2*MB)*seq1las[i][1]/float(seq2len))/4.0,(rL*h - 10*MB + rL*h - 10*MB + rU*h + 5*MB + rU*h + 5*MB)/4.0,str(seqRatio[i])[0:4],horizontalalignment='center')
                    ax[plotNum].axhspan(rU*h - 3*MB, rU*h + 3*MB, xmin = s1xm + (1 - 2*MB - 2*ratio)*seq1las[i][0]/float(seq1len), xmax = s1xm + (1 - 2*MB - 2*ratio)*seq1las[i][1]/float(seq1len), facecolor = colors[i%5], alpha = 0.35) # top seq
                    ax[plotNum].axhspan(rL*h - 3*MB, rL*h + 3*MB, xmin = MB + (1 - 2*MB)*seq2las[i][0]/float(seq2len), xmax = MB + (1 - 2*MB)*seq2las[i][1]/float(seq2len), facecolor = colors[i%5], alpha = 0.35) # bot seq
                    ax[plotNum].plot([l*(s1xm + (1 - 2*MB - 2*ratio)*seq1las[i][0]/float(seq1len)),l*(MB + (1 - 2*MB)*seq2las[i][0]/float(seq2len))],[rU*h - 3*MB,rL*h + 3*MB],color = 'black', alpha = 0.35) # left line
                    ax[plotNum].plot([l*(s1xm + (1 - 2*MB - 2*ratio)*seq1las[i][1]/float(seq1len)),l*(MB + (1 - 2*MB)*seq2las[i][1]/float(seq2len))],[rU*h - 3*MB,rL*h + 3*MB],color = 'black', alpha = 0.35) # right line
                    ax[plotNum].text(l*(MB + .01 + (1 - 2*MB)*seq2las[i][0]/float(seq2len)),rL*h - 10*MB,str(seq2las[i][0]),horizontalalignment='center') # lower left text
                    ax[plotNum].text(l*(MB - .01 + (1 - 2*MB)*seq2las[i][1]/float(seq2len)),rL*h - 10*MB,str(seq2las[i][1]),horizontalalignment='center') # lower right text
                    ax[plotNum].text(l*(s1xm + .01 + (1 - 2*MB - 2*ratio)*seq1las[i][0]/float(seq1len)),rU*h + 5*MB,str(seq1las[i][0]),horizontalalignment='center') # upper left text
                    ax[plotNum].text(l*(s1xm - .01 + (1 - 2*MB - 2*ratio)*seq1las[i][1]/float(seq1len)),rU*h + 5*MB,str(seq1las[i][1]),horizontalalignment='center') # upper right text
                else:
                    ax[plotNum].text(l*(MB + (1 - 2*MB)*seq1las[i][0]/float(seq1len) + MB + (1 - 2*MB)*seq1las[i][1]/float(seq1len) + s1xm + (1 - 2*MB)*seq2las[i][0]/float(seq1len) + s1xm + (1 - 2*MB)*seq2las[i][1]/float(seq1len))/4.0,(rL*h - 10*MB + rL*h - 10*MB + rU*h + 5*MB + rU*h + 5*MB)/4.0,str(seqRatio[i])[0:4],horizontalalignment='center') 
                    ax[plotNum].axhspan(rU*h - 3*MB, rU*h + 3*MB, xmin = s1xm + (1 - 2*MB - 2*ratio)*seq2las[i][0]/float(seq2len), xmax = s1xm + (1 - 2*MB - 2*ratio)*seq2las[i][1]/float(seq2len), facecolor = colors[i%5], alpha = 0.35) # top seq
                    ax[plotNum].axhspan(rL*h - 3*MB, rL*h + 3*MB, xmin = MB + (1 - 2*MB)*seq1las[i][0]/float(seq1len), xmax = MB + (1 - 2*MB)*seq1las[i][1]/float(seq1len), facecolor = colors[i%5], alpha = 0.35) # bot seq
                    ax[plotNum].plot([l*(s1xm + (1 - 2*MB - 2*ratio)*seq2las[i][0]/float(seq2len)),l*(MB + (1 - 2*MB)*seq1las[i][0]/float(seq1len))],[rU*h + 3*MB,rL*h - 3*MB],color = 'black', alpha = 0.35) # left line
                    ax[plotNum].plot([l*(s1xm + (1 - 2*MB - 2*ratio)*seq2las[i][1]/float(seq2len)),l*(MB + (1 - 2*MB)*seq1las[i][1]/float(seq1len))],[rU*h + 3*MB,rL*h - 3*MB],color = 'black', alpha = 0.35) # right line
                    ax[plotNum].text(l*(MB + .01 + (1 - 2*MB)*seq1las[i][0]/float(seq1len)),rL*h + 5*MB,str(seq1las[i][0]),horizontalalignment='center') # lower left text
                    ax[plotNum].text(l*(MB - .01 + (1 - 2*MB)*seq1las[i][1]/float(seq1len)),rL*h + 5*MB,str(seq1las[i][1]),horizontalalignment='center') # lower right text
                    ax[plotNum].text(l*(s1xm + .01 + (1 - 2*MB - 2*ratio)*seq2las[i][0]/float(seq2len)),rU*h - 10*MB,str(seq2las[i][0]),horizontalalignment='center') # upper left text
                    ax[plotNum].text(l*(s1xm - .01 + (1 - 2*MB - 2*ratio)*seq2las[i][1]/float(seq2len)),rU*h - 10*MB,str(seq2las[i][1]),horizontalalignment='center') # upper right text
            ax[plotNum].set_ylim(0,h)
            ax[plotNum].set_xlim(0,l)
            ax[plotNum].set_yticklabels([])
            ax[plotNum].set_xticklabels([])
            ax[plotNum].set_yticks([])
            ax[plotNum].set_xticks([])
            plt.xlabel(pAlign.testSeq.name + ' rf ' + str(pAlign.localAligns[0].offset), multialignment='center')
            gbgstring += pAlign.testSeq.name
            if (plotNum+1)%4 == 0 and plotNum > 1:
                gbgstring += '\n'
                GBGdata.write(gbgstring)
                fig.savefig(parameters['OUTFILE'] + '/images/GBG' + str(plots) + '.png', bbox_inches='tight', pad_inches=0.03)
                fig.savefig(parameters['OUTFILE'] + '/images/GBG' + str(plots) + '.pdf')
                logging.debug('Made GBG plot ' + str(plots))
            else:
                gbgstring += '!'
            plotNum += 1
    gbgstring += '\n'
    GBGdata.write(gbgstring)
    fig.savefig(parameters['OUTFILE'] + '/images/GBG' + str(plots) + '.png', bbox_inches='tight', pad_inches=0.03)
    fig.savefig(parameters['OUTFILE'] + '/images/GBG' + str(plots) + '.pdf')
    logging.debug('Made GBG plot ' + str(plots))
    GBGdata.close()
Example #25
0
               vmin=-10,
               vmax=10,
               origin='lower',
               interpolation='none')
    ax1.set_xticks([])
    ax1.set_yticks([6, 16, 41])
    ax1.set_yticklabels(['Head', 'Neck', 'Tail'], fontsize=22)
    ax1.set_xticks([0, 200, 400, 600])
    ax1.set_xticklabels(['0', '10', '20', '30'], fontsize=22)
    ax1.set_xlim(0, 600)
    ax1.set_ylim(-0.5, 48.5)
    ax1.set_xlabel('Time (s)', fontsize=22)
    #    ax1.set_ylabel('Body axis', fontsize = 22)
    plt.figtext(0.5,
                0.955,
                'Inactivated anterior half of the body, Ind %d' % ind,
                fontsize=24,
                va='center',
                ha='center')

    #calculate amplitud as in Fouad 2017
    amplitude_fouad = np.zeros(3)
    head, neck, tail = 7, 17, 42
    L = 100.
    p = 0
    for position in [head, neck, tail]:
        dt = 1 / 20.
        dk = np.diff(curv[:, position])
        amplitude_fouad[p] = np.sqrt(L * np.mean(dk**2) / dt)
        p += 1
    np.savetxt('../../data/amplitude_fouad_BWM_%d' % ind, amplitude_fouad)
Example #26
0
            fontsize=fz)
axnet3.annotate('',
                xy=(0.3, yloc),
                xycoords='axes fraction',
                xytext=(0.95, yloc),
                arrowprops=dict(arrowstyle=lstyle_inter,
                                color='k',
                                linewidth=1))
##################################################################
######################################################################
xpos = 0.015, 0.340, 0.675
ypos = [0.94, 0.43]
fzl = 70

letters = ['A', 'B', 'C']
[
    plt.figtext(xpos[i],
                ypos[0],
                letters[i],
                fontsize=fzl,
                ha='center',
                va='center') for i in range(3)
]
#[plt.figtext(xpos[i], ypos[1], 'B%d'%(i+1), fontsize = fzl, ha = 'center', va = 'center') for i in range(3)]
######################################################################

fig.subplots_adjust(left=0.02, bottom=0.00, right=0.98, top=1.02)
plt.savefig('phase_delay.png' % (), dpi=100)
plt.savefig('phase_delay.pdf')
#plt.savefig('phase_delay.svg')
def main():

    infilenames = [
        "mc_ttbar.dat", "zipfile_save_data_400k.zip",
        "regular_save_data_400k.npy", "compressed_save_data_400k.npz",
        "pickle_save_data_400k.dat", "onebyonesixty400k.npz",
        "onebyonesixty400kcompressed.npz", "fourbyforty400k.npz",
        "fourbyforty400kcompressed.npz", "thirtytwobyfive400k.npz",
        "thirtytwobyfive400kcompressed.npz"
    ]
    #infilenames = ["mc_ttbar.dat", "onebyonesixty400k.npz"]
    #infilenames = [ "onebyonesixty400k.npz"]
    #infilenames = ["mc_ttbar.dat","zipfile_save_data_400k.zip"]
    #infilenames = ["mc_dy_1000collisions.dat"]
    #infilenames = ["thirtytwobyfive400k.npz", "thirtytwobyfive400kcompressed.npz"]
    read_times = []
    process_times = []
    #infilenames = ["thirtytwobyfive400kcompressed.npz", "mc_ttbar.dat"]
    for i, infilename in enumerate(infilenames):
        print infilename
        infile = open(infilename)
        collisions = None
        start_time = time()

        if infilename[0] == 'm':
            collisions = cms_tools.get_collisions(infile)
        elif infilename[0] == 'z':
            collisions = cms_tools.get_collisions(infile)
        elif infilename[0] == 'r':
            collisions = cms_tools.get_array_collisions(infile)
        elif infilename[0] == 'c':
            collisions = cms_tools.get_compressed_collisions(infile)
        elif infilename[0] == 'p':
            collisions = cms_tools.get_pickle_collisions(infile)
        elif infilename[0] == 'o':
            collisions = cms_tools.get_onebyonesixty_collisions(infile)
        elif infilename[0] == 'f':
            collisions = cms_tools.get_fourbyforty_collisions(infile)
        elif infilename[0] == 't':
            collisions = cms_tools.get_thirtytwobyfive_collisions(infile)

        #print "type collisions: ",type(collisions)
        #print "# collisions: %d" % (len(collisions))
        time_to_read_in_data = time() - start_time
        read_times.append(time_to_read_in_data)

        start_time = time()
        masses = do_some_standard_analysis(collisions)
        print "type masses: ", type(masses)
        time_to_process_data = time() - start_time
        process_times.append(time_to_process_data)

        # print collisions[0]

        # Make a diagnostic plot.
        masses = np.array(masses)
        plt.figure()
        plt.hist(masses[masses > 0], bins=100, range=(0, 80))
        plt.xlim(0, 80)
        plt.figtext(0.4, 0.8, infilename, size=18)
        name = "diagnostic_plot_%s.png" % (infilename.split('.')[0])
        plt.savefig(name)
        #plt.show()

    print read_times
    print process_times

    for n, r, p in zip(infilenames, read_times, process_times):
        print "%-40s  %5.2f %5.2f" % (n, r, p)

    plt.figure()
    plt.plot(read_times, 'ko')
    plt.xlim(-1, len(read_times))

    plt.figure()
    plt.plot(process_times, 'ro')
    plt.xlim(-1, len(process_times))

    points = []
    for name in infilenames:
        points.append(os.path.getsize(name))

    plt.figure()
    for i, (point, name) in enumerate(zip(points, infilenames)):
        plt.plot(i, point, 'o', markersize=20, label=name)

    plt.legend()
    plt.xlim(-1, len(points))

    for i in range(len(points)):
        plt.plot(points[i],
                 process_times[i],
                 'o',
                 markersize=15,
                 label=infilenames[i])
    plt.legend()
    plt.ylabel('mag Y [G]')

    plt.subplot(1, 3, 3)
    plt.plot(power_resampled[idx], magZ_body[idx], 'yo', power_resampled[idx],
             pz[idx][0] * power_resampled[idx] + pz[idx][1], '--k')
    plt.xlabel('current [kA]')
    plt.ylabel('mag Z [G]')

    # display results
    plt.figtext(0.24,
                0.03,
                'CAL_MAG{}_XCOMP: {:.3f} {}'.format(calibration_instance[idx],
                                                    factor * px[idx][0], unit),
                horizontalalignment='center',
                fontsize=12,
                multialignment='left',
                bbox=dict(boxstyle="round",
                          facecolor='#D8D8D8',
                          ec="0.5",
                          pad=0.5,
                          alpha=1),
                fontweight='bold')
    plt.figtext(0.51,
                0.03,
                'CAL_MAG{}_YCOMP: {:.3f} {}'.format(calibration_instance[idx],
                                                    factor * py[idx][0], unit),
                horizontalalignment='center',
                fontsize=12,
                multialignment='left',
                bbox=dict(boxstyle="round",
                          facecolor='#D8D8D8',
Example #29
0
RC0 = sc.array([R0, C0])

pops, infodict = integrate.odeint(dCR_dt, RC0, t, full_output=True)

print(infodict['message'])     # >>> 'Integration successful.'


f1 = p.figure()  # Open empty figure object
p.plot(t, pops[:, 0], 'g-', label='Resource density')  # Plot
p.plot(t, pops[:, 1], 'b-', label='Consumer density')
p.grid()
p.legend(loc='best')
p.xlabel('Time')
p.ylabel('Population density')
p.title('Consumer-Resource population dynamics')
p.figtext(.79, .58, " r =" + str(r) + "\n a =" + str(a) + "\n z = " + str(z)
          + "\n e = " + str(e) + "\n K = " + str(K))
# p.show()  # To display the figure


# Plot consumer density against resource density
f2 = p.figure()
p.plot(pops[:, 0], pops[:, 1], 'r-', label='Consumer density')
p.grid()
p.xlabel('Resource density')
p.ylabel('Consumer density')
p.title('Consumer-Resource population dynamics')
p.figtext(.79, .58, " r =" + str(r) + "\n a =" + str(a) + "\n z = " + str(z)
          + "\n e = " + str(e) + "\n K = " + str(K))
# p.show()  # To display the figure

# Save both figures into a single pdf
Example #30
0
def cmdline_chart_compare(db, options, *args):
    import matplotlib
    matplotlib.use('Agg')
    import numpy as np
    import matplotlib.pylab as plt

    labels = []
    timing_sets = []
    command_names = None

    run_kinds = parse_timings_selections(db, *args)

    # iterate the timings selections and accumulate data
    for run_kind in run_kinds:
        query = TimingQuery(db, run_kind)
        timings = query.get_timings()
        if not timings:
            print("No timings for %s" % run_kind.label())
            continue
        labels.append(run_kind.label())
        timing_sets.append(timings)

        # it only makes sense to compare those commands that have timings
        # in the first selection, because that is the one everything else
        # is compared to. Remember the first selection's command names.
        if not command_names:
            command_names = query.get_sorted_command_names()

    if len(timing_sets) < 2:
        bail("Not enough timings")

    if options.command_names:
        command_names = [
            name for name in command_names if name in options.command_names
        ]

    chart_path = options.chart_path
    if not chart_path:
        chart_path = 'compare_' + '_'.join(
            [filesystem_safe_string(l) for l in labels]) + '.svg'

    N = len(command_names)
    M = len(timing_sets) - 1
    if M < 2:
        M = 2

    group_positions = np.arange(N)  # the y locations for the groups
    dist = 1. / (1. + M)
    height = (1. - dist) / M  # the height of the bars

    fig = plt.figure(figsize=(12, 5 + 0.2 * N * M))
    plot1 = fig.add_subplot(121)
    plot2 = fig.add_subplot(122)

    left = timing_sets[0]

    # Iterate timing sets. Each loop produces one bar for each command name
    # group.
    for label_i, label in enumerate(labels[1:], 1):
        right = timing_sets[label_i]
        if not right:
            continue

        for cmd_i, command_name in enumerate(command_names):
            if command_name not in right:
                #skip
                continue

            left_N, left_min, left_max, left_avg = left[command_name]
            right_N, right_min, right_max, right_avg = right[command_name]

            div_avg = 100. * (do_div(left_avg, right_avg) - 1.0)
            if div_avg <= 0:
                col = '#55dd55'
            else:
                col = '#dd5555'

            diff_val = do_diff(left_avg, right_avg)

            ofs = (dist + height) / 2. + height * (label_i - 1)

            barheight = height * (1.0 - dist)

            y = float(cmd_i) + ofs

            plot1.barh((y, ), (div_avg, ),
                       barheight,
                       color=col,
                       edgecolor='white')
            plot1.text(0.,
                       y + height / 2.,
                       '%s %+5.1f%%' % (label, div_avg),
                       ha='right',
                       va='center',
                       size='small',
                       rotation=0,
                       family='monospace')

            plot2.barh((y, ), (diff_val, ),
                       barheight,
                       color=col,
                       edgecolor='white')
            plot2.text(0.,
                       y + height / 2.,
                       '%s %+6.2fs' % (label, diff_val),
                       ha='right',
                       va='center',
                       size='small',
                       rotation=0,
                       family='monospace')

    for p in (plot1, plot2):
        xlim = list(p.get_xlim())
        if xlim[1] < 10.:
            xlim[1] = 10.
        # make sure the zero line is far enough right so that the annotations
        # fit inside the chart. About half the width should suffice.
        if xlim[0] > -xlim[1]:
            xlim[0] = -xlim[1]
        p.set_xlim(*xlim)
        p.set_xticks((0, ))
        p.set_yticks(group_positions + (height / 2.))
        p.set_yticklabels(())
        p.set_ylim((len(command_names), 0))
        p.grid()

    plot1.set_xticklabels(('+-0%', ), rotation=0)
    plot1.set_title('Average runtime change from %s in %%' % labels[0],
                    size='medium')

    plot2.set_xticklabels(('+-0s', ), rotation=0)
    plot2.set_title('Average runtime change from %s in seconds' % labels[0],
                    size='medium')

    margin = 1. / (2 + N * M)
    titlemargin = 0
    if options.title:
        titlemargin = margin * 1.5

    fig.subplots_adjust(left=0.005,
                        right=0.995,
                        wspace=0.3,
                        bottom=margin,
                        top=1.0 - margin - titlemargin)

    ystep = (1.0 - 2. * margin - titlemargin) / len(command_names)

    for idx, command_name in enumerate(command_names):
        ylabel = '%s\nvs. %.1fs' % (command_name, left[command_name][3])

        ypos = 1.0 - margin - titlemargin - ystep / M - ystep * idx
        plt.figtext(0.5,
                    ypos,
                    command_name,
                    ha='center',
                    va='top',
                    size='medium',
                    weight='bold')
        plt.figtext(0.5,
                    ypos - ystep / (M + 1),
                    '%s\n= %.2fs' % (labels[0], left[command_name][3]),
                    ha='center',
                    va='top',
                    size='small')

    if options.title:
        plt.figtext(0.5,
                    1. - titlemargin / 2,
                    options.title,
                    ha='center',
                    va='center',
                    weight='bold')

    plt.savefig(chart_path)
    print('wrote chart file:', chart_path)
Example #31
0
def plot_bacteria_hist(folder, depth=6, mid_quantile=False):
    """
    Saves a histogram of abundances binned
    :return:
    """

    # Get the stool dataset and discretize it
    ds = parser.get_dataset()
    ds = compute_relative_values(ds)
    t = Tree(ds)
    ds = t.dataset_at_depth(depth)

    # Get header names to priint on the plots
    headers = ds[0][2:]

    for index, header  in enumerate(headers):

        node = t.node_for_clade_name(header)
        abundances = t.abundance_column_in_subtree(node)
        abundances = [round(x,3) for x in abundances]

        if mid_quantile:
            abundances.sort()
            abundances = abundances[int(len(abundances)*0.25): -int(len(abundances)*0.25)]

        xlabel('Relative abundance')
        ylabel('Bin size')

        title_text = header.replace('/','-').replace('|', '-')
        title(title_text)
        binwidth = 0.001
        bins, bin_sizes, patches = hist(abundances, bins=np.arange(min(abundances), max(abundances) + binwidth, binwidth), color='#0066FF')

        # Write discretized values
        threshold, discretized_abundances = discretize_row(abundances, maxent_discretization_splitter)
        _0 = '0: ' + str(len([x for x in discretized_abundances if x == 0]))
        _1 = '1: ' + str(len([x for x in discretized_abundances if x == 1]))

        text_x = 0.7

        smaples_text = 'Samples: %d' % len(abundances)
        figtext(text_x, 0.85, smaples_text, fontsize=10)

        threshold_text = 'Splitter: %f' % threshold
        figtext(text_x, 0.82, threshold_text, fontsize=10)
        figtext(text_x, 0.79, _0, fontsize=10)
        figtext(text_x, 0.76, _1, fontsize=10)

        # Draw threshold line
        max_bin = len(abundances)
        if len(bins) != 0:
            max_bin = max(bins)

        a, b = [threshold, threshold], [0, max_bin]
        plot(a, b, c='r')

        grid(True)

        # Write max and avg
        # max_abundance = 'max: %f' % max(abundances)
        # avg_abundance = 'avg: %f' % (sum(abundances) / float(len(abundances)))
        # figtext(text_x, 0.76, max_abundance, fontsize=10)
        # figtext(text_x, 0.73, avg_abundance, fontsize=10)

        # write variance
        # variance = 'var: %f' % tvar(abundances)
        # figtext(text_x, 0.70, variance, fontsize=10)

        # Save fig to folder
        if not (os.path.exists(folder)):
            os.makedirs(folder)
        file_name = os.path.join(folder, title_text)
        print 'Hist: ', file_name
        savefig(file_name)

        close()
plt.title('2D Background Frequency', fontsize=14)
H, xedges, yedges = np.histogram2d(bkg_template[1],bkg_template[0],bins=50,range=[[0,1],[0,1]])
imbkg = plt.imshow(H, interpolation='nearest', origin='low', extent=[xedges[0], xedges[-1], yedges[0], yedges[-1]])
ax = plt.gca()
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="5%", pad=0.05)
cbar = plt.colorbar(cax=cax)
cbar.ax.set_ylabel('Frequency')
plt.savefig('2D_Histograms.png')
#plt.ylim(0,10)
#plt.xlim(12,21)

txt = 'Figure A: The location of a sphere in both radius density plots indidcates the location of a data point for the background and signal datasets.  \nThe radius of the sphere indicates the neighbor density of the particular datapoint.  Note how the radii of the background points are \ngenerally the same and the points are scattered throughout the plot in the signal plot the points are concentrated in the center and those \nclosest to the center have the largest radii indicated that they have the largest neighbor densities in the center of the plot.'
fig_template = plt.figure(figsize=(12,6))
fig_template.add_subplot(1,2,1)
plt.figtext(.5, -.01,txt, horizontalalignment='center',verticalalignment='center')
plt.scatter(data[0],data[1],s=sigFD*50,alpha=0.1)
plt.xlim(0,1)
plt.ylim(0,1)

plt.xlabel('Signal Dataset #1')
plt.ylabel('Signal Dataset #2')
plt.title('Signal Function Density', fontsize=14)
fig_template.add_subplot(1,2,2)
plt.scatter(data[0],data[1],s=bkgFD*50,alpha=0.1)
plt.xlim(0,1)
plt.ylim(0,1)
plt.xlabel('Background Dataset 1')
plt.ylabel('Background Dataset 2')
plt.title('Background Function Density', fontsize=14)
plt.savefig('bubble_plots.png')
Example #33
0
ax22 = plt.subplot(gm[60:77, 97:175])
####################
axo1 = plt.subplot(gm[:52, 200:288])
axoc = plt.subplot(gm[:52, 291:294])
axo2 = plt.subplot(gm[60:77, 200:288])
#########################################################################################

selected, wt, ns, bwm, wt2, ns2, bwm2, curv, curv_prof, speeds_mean = np.load(
    'myfile.npy')

#######################################################################
x1, x2, x3, y1, y2 = 0.015, 0.31, 0.61, 0.96, 0.30
letters = [[x1, y1, 'A'], [x1, y2, 'B'], [x2, y1, 'C'], [x2, y2, 'D'],
           [x3, y1, 'E'], [x3, y2, 'F']]
for l in letters:
    plt.figtext(l[0], l[1], l[2], fontsize=34, ha='center', va='center')
#########################################################################################
#######################################################################
control, headparal, midbodyparal, edge = '#1b9e77', '#d95f02', '#7570b3', 'k'
[head, neck, tail] = [0, 1, 2]

ax1.scatter(1 * np.ones(15),
            wt[:, head],
            lw=0.5,
            s=100,
            color=control,
            edgecolors=edge,
            label='Control')  #wild type head amplitude
ax1.scatter(2 * np.ones(15),
            ns[:, head],
            lw=0.5,
Example #34
0
def skydip(data,
           averagepol=True,
           tsky=300.,
           plot=False,
           temperature=288,
           pressure=101325.,
           humidity=0.5):
    """Determine the opacity from a set of 'skydip' obervations.
    This can be any set of observations over a range of elevations,
    but will ususally be a dedicated (set of) scan(s).
    Return a list of 'n' opacities for 'n' IFs. In case of averagepol
    being 'False' a list of 'n*m' elements where 'm' is the number of
    polarisations, e.g.
    nIF = 3, nPol = 2 => [if0pol0, if0pol1, if1pol0, if1pol1, if2pol0, if2pol1]

    The opacity is determined by fitting a first order polynomial to:


        Tsys(airmass) = p0 + airmass*p1

    where

        airmass = 1/sin(elevation)

        tau =  p1/Tsky

    Parameters:
        data:       a list of file names or scantables or a single
                    file name or scantable.
        averagepol: Return the average of the opacities for the polarisations
                    This might be useful to set to 'False' if one polarisation
                    is corrupted (Mopra). If set to 'False', an opacity value
                    per polarisation is returned.
        tsky:       The sky temperature (default 300.0K). This might
                    be read from the data in the future.
        plot:       Plot each fit (airmass vs. Tsys). Default is 'False'
    """
    # quiten output
    verbose = rcParams["verbose"]
    rcParams["verbose"] = False
    try:
        if plot:
            from matplotlib import pylab
        scan = _import_data(data)
        f = fitter()
        f.set_function(poly=1)
        sel = selector()
        basesel = scan.get_selection()
        inos = scan.getifnos()
        pnos = scan.getpolnos()
        opacities = []
        om = model(temperature, pressure, humidity)
        for ino in inos:
            sel.set_ifs(ino)
            opacity = []
            fits = []
            airms = []
            tsyss = []
            if plot:
                pylab.cla()
                pylab.ioff()
                pylab.clf()
                pylab.xlabel("Airmass")
                pylab.ylabel(r"$T_{sys}$")
            for pno in pnos:
                sel.set_polarisations(pno)
                scan.set_selection(basesel + sel)
                freq = scan.get_coordinate(0).get_reference_value() / 1e9
                freqstr = "%0.4f GHz" % freq
                tsys = scan.get_tsys()
                elev = scan.get_elevation()
                airmass = [1. / math.sin(i) for i in elev]
                airms.append(airmass)
                tsyss.append(tsys)
                f.set_data(airmass, tsys)
                f.fit()
                fits.append(f.get_fit())
                params = f.get_parameters()["params"]
                opacity.append(params[1] / tsky)
            if averagepol:
                opacities.append(sum(opacity) / len(opacity))
            else:
                opacities += opacity
            if plot:
                colors = ['b', 'g', 'k']
                n = len(airms)
                for i in range(n):
                    pylab.plot(airms[i], tsyss[i], 'o', color=colors[i])
                    pylab.plot(airms[i], fits[i], '-', color=colors[i])
                    pylab.figtext(0.7,
                                  0.3 - (i / 30.0),
                                  r"$\tau_{fit}=%0.2f$" % opacity[i],
                                  color=colors[i])
                if averagepol:
                    pylab.figtext(0.7,
                                  0.3 - (n / 30.0),
                                  r"$\tau_{avg}=%0.2f$" % opacities[-1],
                                  color='r')
                    n += 1
                pylab.figtext(0.7,
                              0.3 - (n / 30.0),
                              r"$\tau_{model}=%0.2f$" %
                              om.get_opacities(freq * 1e9),
                              color='grey')

                pylab.title("IF%d : %s" % (ino, freqstr))

                pylab.ion()
                pylab.draw()
                raw_input("Hit <return> for next fit...")
            sel.reset()

        scan.set_selection(basesel)
        if plot:
            pylab.close()
        return opacities
    finally:
        rcParams["verbose"] = verbose
Example #35
0
                    vmin=-10,
                    vmax=10,
                    origin='lower')
ax1.set_xlim(0, 120)
ax1.set_xticks([0, 40, 80, 120])
ax1.set_xticklabels([])
ax1.set_yticks([1, 21])
ax1.set_yticklabels(['', ''])
ax1.text(-1, 1, 'Head', va='center', ha='right', fontsize=fzl)
ax1.text(-1, 21, 'Tail', va='center', ha='right', fontsize=fzl)

############ Velocity #######
###############################
s = np.where(np.array(sel) == 23)[0]
ax2.plot(np.linspace(0, 10, len(v[s][0])), 1000 * v[s][0], 'k', linewidth=3)
ax2.axhline(y=0.22, linestyle='--', color='r')
ax2.set_ylim(0.05, 0.35)
ax2.set_xlim(0, 6)
ax2.set_yticks([0.1, 0.2, 0.3])
ax2.set_ylabel('Velocity (mm/s)', fontsize=fzl, labelpad=24)
ax2.set_xlabel('Time (s)', fontsize=fzl, labelpad=22)
###############################
fz = 70
plt.figtext(0.018, 0.95, 'A', fontsize=fz, ha='center', va='center')
plt.figtext(0.018, 0.46, 'B', fontsize=fz, ha='center', va='center')
plt.figtext(0.460, 0.95, 'C', fontsize=fz, ha='center', va='center')
###############################
fig.subplots_adjust(left=0.08, bottom=0.02, right=1.0, top=0.98)
plt.savefig('behavior.png', dpi=100)
plt.savefig('behavior.pdf')
Example #36
0
def GeneCDFplots(setOfAligns, numGenes,parameters):
    logging.info('Making the CDF plots (This may take a while)...')
    lensoi = setOfAligns.seqOfInt.length
    colors = ['b','g','r','c','m']
    
    if numGenes > len(setOfAligns.testSeqs)/setOfAligns.seqOfInt.readingFrames or numGenes < 1:
        numGenes = len(setOfAligns.testSeqs)*setOfAligns.seqOfInt.readingFrames
    geneCount = 0
    
    plots = 0
    
    CDFdata = open(parameters['OUTFILE'] + '/images/CDFdata.txt','wb')
    CDFdata.write('CDFX.pdf:soi!testseq\n')
    
    for pAlign in setOfAligns.aligns:
        if len(pAlign.localAligns) > 0:
            if geneCount < numGenes:
                geneCount += 1
                plotNum = 0
                totalForLocA = 0
                for locA in pAlign.localAligns:
                    totalForLocA += 1
                    # get density ratio
                    seqRatio = []
                    if setOfAligns.seqOfInt.dataDepths != 0:
                        for i in range(len(locA.SOIrange)):
                            scoreSum = (sum(locA.fullScoreVec[locA.SOIrange[i][0]:locA.SOIrange[i][1]]))
                            seqRatio.append(scoreSum/float(locA.SOIrange[i][1]-locA.SOIrange[i][0]))
                    else:
                        for i in range(len(locA.SOIrange)):
                            scoreSum = (sum(locA.fullScoreVec[locA.SOIrange[i][0]:locA.SOIrange[i][1]]))
                            seqRatio.append(scoreSum/float(locA.SOIrange[i][1]-locA.SOIrange[i][0]))
                            
                    # make the empty plot, 4 per page
                    if plotNum%4 == 0:
                        fig = plt.figure(figsize=(22,17))
                        plt.figtext(0.5, 0.965,  'Local Alignments for soi: ' + setOfAligns.seqOfInt.name + ' vs ' + pAlign.testSeq.name + ' rf ' + str(pAlign.localAligns[0].offset), ha='center', color='black', weight='bold', size='large')
                        
                        ax = []
                        ax.append(fig.add_subplot(811))
                        ax.append(fig.add_subplot(812))
                        plotNum = 0
                        plots += 1
                        
                    else:
                        ax.append(fig.add_subplot(811+(plotNum%4)*2))
                        ax.append(fig.add_subplot(811+(plotNum%4)*2+1))
                        
                    # make the upper plot, the match vector
                    temp = numpy.zeros(lensoi)
                    for i in range(len(locA.SOIrange)):
                        temp[locA.SOIrange[i][0]:locA.SOIrange[i][1]] = 2*numpy.ones(locA.SOIrange[i][1]-locA.SOIrange[i][0])
                    ax[plotNum*2].pcolor(numpy.reshape(numpy.array(locA.fullScoreVec) + temp,(1,lensoi)))
                    
                    # plot the cdfs
                    ax[plotNum*2+1].plot(locA.cdfL)
                    ax[plotNum*2+1].plot(locA.cdfR)
                    for i in range(len(locA.SOIrange)):
                        ax[plotNum*2+1].axvspan(locA.SOIrange[i][0],locA.SOIrange[i][1], facecolor = 'r', alpha = 0.35)
                    
                    # mark off the intron area
                    intronArea = numpy.asarray(numpy.asarray(locA.cdfL) == numpy.asarray(locA.cdfR),dtype=numpy.int32)
                    ranges = rangeFinder(intronArea)
                    
                    for i in range(len(ranges)):
                        ax[plotNum*2+1].axvspan(ranges[i][0],ranges[i][1], facecolor = 'm', alpha = 0.35)
                    
                    #ax[plotNum*2+1].text((locA.SOIrange[0]+locA.SOIrange[1])/2.0,(max(max(locA.cdfL),max(locA.cdfR)) + min(min(locA.cdfL),min(locA.cdfR)))/2*1.66,str(seqRatio)[0:4],verticalalignment='center',horizontalalignment='center')
                    
                    
                    # make the tick marks
                    ax[plotNum].set_yticklabels([])
                    ax[plotNum*2].set_yticks([])
                    prevTicks = []
                    prevLabs = []
                    for i in range(len(locA.SOIrange)):
                        prevTicks.extend([locA.SOIrange[i][0],(locA.SOIrange[i][0]+locA.SOIrange[i][1])/2.0,locA.SOIrange[i][1]])
                        prevLabs.extend([str(locA.SOIrange[i][0]),str(seqRatio[i])[0:4],str(locA.SOIrange[i][1])])
                    newXticks, newXtickLabels = intronAdderXticks(prevTicks,prevLabs,ranges)
                    ax[plotNum*2].set_xticks(newXticks)
                    ax[plotNum*2].set_xticklabels(newXtickLabels)
                    #ax[plotNum*2].set_xticks([locA.SOIrange[0],(locA.SOIrange[0]+locA.SOIrange[1])/2.0,locA.SOIrange[1]])
                    #ax[plotNum*2].set_xticklabels([str(locA.SOIrange[0]),str(seqRatio)[0:4],str(locA.SOIrange[1])])
                    ax[plotNum*2+1].set_yticklabels([])
                    ax[plotNum*2+1].set_yticks([])
                    ax[plotNum*2].set_xlim(0,lensoi)
                    ax[plotNum*2+1].set_xlim(0,lensoi)
                    plotNum += 1
                    #plt.show()
                    if ((plotNum)%4 == 0 and plotNum > 1) or totalForLocA == len(pAlign.localAligns):
                        #print plotNum, (plotNum)%4, totalForLocA, len(pAlign.localAligns)
                        CDFdata.write('CDF' + str(plots) + '.pdf:' + setOfAligns.seqOfInt.name + '!' + pAlign.testSeq.name + '\n')
                        fig.savefig(parameters['OUTFILE'] + '/images/CDF' + str(plots) + '.png', bbox_inches='tight', pad_inches=0.03)
                        fig.savefig(parameters['OUTFILE'] + '/images/CDF' + str(plots) + '.pdf')
                        logging.debug('Made CDF plot ' + str(plots) + '...')
                    #return 0
            else:
                #plt.show()
                CDFdata.close()
                return 0
    CDFdata.close()
    qry_c = ''
    for w in qry_raw:
        qry_c += w + ' '
    cap = ('DOC: ' + '\n'.join(
        [''.join(doc_c[idx:idx + CH])
         for idx in range(0, len(doc_c), CH)]) + '\n\n' + 'QRY: ' + '\n'.join([
             ''.join(qry_c[idx:idx + CH]) for idx in range(0, len(qry_c), CH)
         ]) + '\n' + 'ANS: ' + ''.join(text[6].rstrip()))
    num_lines = cap.count('\n')
    if num_lines < 10: bot = 0.35
    elif num_lines < 13: bot = 0.40
    elif num_lines < 16: bot = 0.45
    elif num_lines < 19: bot = 0.50
    else: bot = 0.55
    fig.subplots_adjust(bottom=bot)
    plt.figtext(
        0.06,
        0.0,
        cap,
        weight='medium',
    )

    # add colorbar
    fig.subplots_adjust(right=0.95)
    cbar_ax = fig.add_axes([0.97, bot, 0.01, 0.90 - bot])
    fig.colorbar(im, cax=cbar_ax)

    #plt.show()
    plt.savefig(root_dir + '%s.png' % X[0], bbox_inches='tight')
    plt.close()
Example #38
0
        numb_growing_in_rad += 1
    else:
        ax10.plot(curv_profile_rad[ind], color='green')

for ax in [ax0, ax10]:
    ax.set_xlim(pos_norm, n_seg - 1)
    ax.set_xticks([])
    ax.set_yticks([0.5, 1.0, 1.5, 2.0])
    ax.set_ylim(0.4, 2.1)
    ax.set_ylabel('Normalized curvature', fontsize=15)

ax10.set_xticks([1 + pos_norm, n_seg - 2])
ax10.set_xticklabels(['Head', 'Tail'], fontsize=15)

plt.figtext(0.5,
            0.96,
            'Negative slope N=%d' % (numb_growing_in_rad),
            color='k',
            fontsize=20,
            ha='center')
plt.figtext(0.5,
            0.485,
            'Positive slope N=%d' % (nsel - numb_growing_in_rad),
            color='k',
            fontsize=20,
            ha='center')

fig.subplots_adjust(left=0.09, bottom=0.05, right=0.99, top=0.95)

plt.savefig('plot_2.png', dpi=200)
Example #39
0
def cmdline_chart_compare(db, options, *args):
  import matplotlib
  matplotlib.use('Agg')
  import numpy as np
  import matplotlib.pylab as plt

  labels = []
  timing_sets = []
  command_names = None

  run_kinds = parse_timings_selections(db, *args)

  # iterate the timings selections and accumulate data
  for run_kind in run_kinds:
    query = TimingQuery(db, run_kind)
    timings = query.get_timings()
    if not timings:
      print "No timings for %s" % run_kind.label()
      continue
    labels.append(run_kind.label())
    timing_sets.append(timings)

    # it only makes sense to compare those commands that have timings
    # in the first selection, because that is the one everything else
    # is compared to. Remember the first selection's command names.
    if not command_names:
      command_names = query.get_sorted_command_names()


  if len(timing_sets) < 2:
    bail("Not enough timings")

  if options.command_names:
    command_names = [name for name in command_names
                     if name in options.command_names]

  chart_path = options.chart_path
  if not chart_path:
    chart_path = 'compare_' + '_'.join(
      [ filesystem_safe_string(l) for l in labels ]
      ) + '.svg'

  N = len(command_names)
  M = len(timing_sets) - 1
  if M < 2:
    M = 2

  group_positions = np.arange(N)  # the y locations for the groups
  dist = 1. / (1. + M)
  height = (1. - dist) / M     # the height of the bars

  fig = plt.figure(figsize=(12, 5 + 0.2*N*M))
  plot1 = fig.add_subplot(121)
  plot2 = fig.add_subplot(122)

  left = timing_sets[0]

  # Iterate timing sets. Each loop produces one bar for each command name
  # group.
  for label_i,label in enumerate(labels[1:],1):
    right = timing_sets[label_i]
    if not right:
      continue

    for cmd_i, command_name in enumerate(command_names):
      if command_name not in right:
        #skip
        continue

      left_N, left_min, left_max, left_avg = left[command_name]
      right_N, right_min, right_max, right_avg = right[command_name]

      div_avg = 100. * (do_div(left_avg, right_avg) - 1.0)
      if div_avg <= 0:
        col = '#55dd55'
      else:
        col = '#dd5555'

      diff_val = do_diff(left_avg, right_avg)

      ofs = (dist + height) / 2. + height * (label_i - 1)

      barheight = height * (1.0 - dist)

      y = float(cmd_i) + ofs

      plot1.barh((y, ),
                 (div_avg, ),
                 barheight,
                 color=col, edgecolor='white')
      plot1.text(0., y + height/2.,
                 '%s %+5.1f%%' % (label, div_avg),
                 ha='right', va='center', size='small',
                 rotation=0, family='monospace')

      plot2.barh((y, ),
                 (diff_val, ),
                 barheight,
                 color=col, edgecolor='white')
      plot2.text(0., y + height/2.,
                 '%s %+6.2fs' % (label, diff_val),
                 ha='right', va='center', size='small',
                 rotation=0, family='monospace')


  for p in (plot1, plot2):
    xlim = list(p.get_xlim())
    if xlim[1] < 10.:
      xlim[1] = 10.
    # make sure the zero line is far enough right so that the annotations
    # fit inside the chart. About half the width should suffice.
    if xlim[0] > -xlim[1]:
      xlim[0] = -xlim[1]
    p.set_xlim(*xlim)
    p.set_xticks((0,))
    p.set_yticks(group_positions + (height / 2.))
    p.set_yticklabels(())
    p.set_ylim((len(command_names), 0))
    p.grid()

  plot1.set_xticklabels(('+-0%',), rotation=0)
  plot1.set_title('Average runtime change from %s in %%' % labels[0],
                  size='medium')

  plot2.set_xticklabels(('+-0s',), rotation=0)
  plot2.set_title('Average runtime change from %s in seconds' % labels[0],
                  size='medium')

  margin = 1./(2 + N*M)
  titlemargin = 0
  if options.title:
    titlemargin = margin * 1.5

  fig.subplots_adjust(left=0.005, right=0.995, wspace=0.3, bottom=margin,
                      top=1.0-margin-titlemargin)

  ystep = (1.0 - 2.*margin - titlemargin) / len(command_names)

  for idx,command_name in enumerate(command_names):
    ylabel = '%s\nvs. %.1fs' % (
                     command_name,
                     left[command_name][3])

    ypos=1.0 - margin - titlemargin - ystep/M - ystep * idx
    plt.figtext(0.5, ypos,
                command_name,
                ha='center', va='top',
                size='medium', weight='bold')
    plt.figtext(0.5, ypos - ystep/(M+1),
                '%s\n= %.2fs' % (
                  labels[0], left[command_name][3]),
                ha='center', va='top',
                size='small')

  if options.title:
    plt.figtext(0.5, 1. - titlemargin/2, options.title, ha='center',
                va='center', weight='bold')

  plt.savefig(chart_path)
  print 'wrote chart file:', chart_path
plt.xticks([0, min(durations), max(durations)], ['0', str(int(math.ceil(min(durations)))), str(int(math.ceil(max(durations))))])
plt.xlabel('Time since start (s)')

for tick in ax.xaxis.get_major_ticks():
    tick.tick1On = False
    tick.tick2On = False


#ax.tick_params(top='off', right='off')

#ax.spines['top'].set_color('none')
#ax.spines['right'].set_color('none')

# ax = plt.subplot(212, frame_on=False)
# plt.plot(xseries2, yseries2, 'r-')
# plt.xlim(0, math.ceil(max(duration1, duration2)))
# plt.ylim(0, 21)
# ax.tick_params(top='off', right='off')
# plt.xticks([0, math.ceil(duration1), math.ceil(duration2)])
# plt.yticks([0, 20], ['0', '20'])
# #ax.spines['top'].set_color('none')
# #ax.spines['right'].set_color('none')

# plt.ylabel('Hadoop')

# plt.xticks((0, math.ceil(min(duration1, duration2)), math.ceil(max(duration1, duration2))), ('0', str(int(math.ceil(min(duration1, duration2)))), str(int(math.ceil(max(duration1, duration2))))))

plt.figtext(0.0, (0.2+0.95)/2, 'Number of chunks', rotation='vertical', verticalalignment='center')

plt.savefig('smithwaterman-util.pdf', format='pdf')
Example #41
0
def skydip(data, averagepol=True, tsky=300., plot=False,
           temperature=288, pressure=101325., humidity=0.5):
    """Determine the opacity from a set of 'skydip' obervations.
    This can be any set of observations over a range of elevations,
    but will ususally be a dedicated (set of) scan(s).
    Return a list of 'n' opacities for 'n' IFs. In case of averagepol
    being 'False' a list of 'n*m' elements where 'm' is the number of
    polarisations, e.g.
    nIF = 3, nPol = 2 => [if0pol0, if0pol1, if1pol0, if1pol1, if2pol0, if2pol1]

    The opacity is determined by fitting a first order polynomial to:


        Tsys(airmass) = p0 + airmass*p1

    where

        airmass = 1/sin(elevation)

        tau =  p1/Tsky

    Parameters:
        data:       a list of file names or scantables or a single
                    file name or scantable.
        averagepol: Return the average of the opacities for the polarisations
                    This might be useful to set to 'False' if one polarisation
                    is corrupted (Mopra). If set to 'False', an opacity value
                    per polarisation is returned.
        tsky:       The sky temperature (default 300.0K). This might
                    be read from the data in the future.
        plot:       Plot each fit (airmass vs. Tsys). Default is 'False'
    """
    # quiten output
    verbose = rcParams["verbose"]
    rcParams["verbose"] = False
    try:
        if plot:
            from matplotlib import pylab
        scan = _import_data(data)
        f = fitter()
        f.set_function(poly=1)
        sel = selector()
        basesel = scan.get_selection()
        inos = scan.getifnos()
        pnos = scan.getpolnos()
        opacities = []
        om = model(temperature, pressure, humidity)
        for ino in inos:
            sel.set_ifs(ino)
            opacity = []
            fits = []
            airms = []
            tsyss = []
            if plot:
                pylab.cla()
                pylab.ioff()
                pylab.clf()
                pylab.xlabel("Airmass")
                pylab.ylabel(r"$T_{sys}$")
            for pno in pnos:
                sel.set_polarisations(pno)
                scan.set_selection(basesel+sel)
                freq = scan.get_coordinate(0).get_reference_value()/1e9
                freqstr = "%0.4f GHz" % freq
                tsys = scan.get_tsys()
                elev = scan.get_elevation()
                airmass = [ 1./math.sin(i) for i in elev ]
                airms.append(airmass)
                tsyss.append(tsys)
                f.set_data(airmass, tsys)
                f.fit()
                fits.append(f.get_fit())
                params = f.get_parameters()["params"]
                opacity.append(params[1]/tsky)
            if averagepol:
                opacities.append(sum(opacity)/len(opacity))
            else:
                opacities += opacity
            if plot:
                colors = ['b','g','k']
                n = len(airms)
                for i in range(n):
                    pylab.plot(airms[i], tsyss[i], 'o', color=colors[i])
                    pylab.plot(airms[i], fits[i], '-', color=colors[i])
                    pylab.figtext(0.7,0.3-(i/30.0),
                                      r"$\tau_{fit}=%0.2f$" % opacity[i],
                                      color=colors[i])
                if averagepol:
                    pylab.figtext(0.7,0.3-(n/30.0),
                                      r"$\tau_{avg}=%0.2f$" % opacities[-1],
                                      color='r')
                    n +=1
                pylab.figtext(0.7,0.3-(n/30.0),
                              r"$\tau_{model}=%0.2f$" % om.get_opacities(freq*1e9),
                              color='grey')

                pylab.title("IF%d : %s" % (ino, freqstr))

                pylab.ion()
                pylab.draw()
                raw_input("Hit <return> for next fit...")
            sel.reset()

        scan.set_selection(basesel)
        if plot:
            pylab.close()
        return opacities
    finally:
        rcParams["verbose"] = verbose
Example #42
0
 def cupper(self, event):
     theta = np.linspace(-np.pi / 2, np.pi / 2, 1000)
     Lx = np.array([0.2, 0.4, 0.6])
     Ly = np.linspace(-1, 1, 1000)
     fig = plt.figure(
         "Rectangular_x_Beam_pattern",
         figsize=(22, 12),
         facecolor="white",
         edgecolor="blue",
     )
     fig.set_size_inches(15, 10)
     P_rectangular1 = np.sin((np.pi * Lx[0] / wavelength[2]) * np.sin(theta)) / (
         (np.pi * Lx[0] / wavelength[2]) * np.sin(theta)
     )
     P_rectangular2 = np.sin((np.pi * Lx[1] / wavelength[2]) * np.sin(theta)) / (
         (np.pi * Lx[1] / wavelength[2]) * np.sin(theta)
     )
     P_rectangular3 = np.sin((np.pi * Lx[2] / wavelength[2]) * np.sin(theta)) / (
         (np.pi * Lx[2] / wavelength[2]) * np.sin(theta)
     )
     ax = plt.subplot(131)
     plt.figtext(
         0.5,
         0.5,
         z,
         style="italic",
         wrap=True,
         horizontalalignment="center",
         fontsize=18,
         color="gray",
     )
     plt.plot(
         np.degrees(theta),
         10 * np.log10((P_rectangular1 / np.amax(P_rectangular1)) ** 2),
         "b",
         label="0.2m",
     )
     plt.xlabel(r"Angle $\theta$($\circ$)")
     plt.ylabel("Power(dB)")
     plt.yticks(np.linspace(-40, 0, 5))
     plt.ylim([-40, 0])
     plt.grid(True)
     plt.title("Dx = 0.2 m")
     ax = plt.subplot(132)
     plt.plot(
         np.degrees(theta),
         10 * np.log10((P_rectangular2 / np.amax(P_rectangular2)) ** 2),
         "g",
         label="0.4m",
     )
     plt.xlabel(r"Dy $\theta$($\circ$)")
     plt.ylabel("Power(dB)")
     plt.yticks(np.linspace(-40, 0, 5))
     plt.ylim([-40, 0])
     plt.grid(True)
     plt.title("Dx = 0.4 m")
     ax = plt.subplot(133)
     plt.plot(
         np.degrees(theta),
         10 * np.log10((P_rectangular3 / np.amax(P_rectangular3)) ** 2),
         "purple",
         label=" 0.6 m",
     )
     plt.xlabel("Dy ( m )")
     plt.ylabel(r"Power $\theta$($\circ$)")
     plt.yticks(np.linspace(-40, 0, 5))
     plt.ylim([-40, 0])
     plt.grid(True)
     plt.title("Dx = 0.6 m")
     plt.tight_layout()
     plt.savefig("Rectangular_x_Beam_pattern.png")
     plt.show()
Example #43
0
    plt.subplot(2, 3, 6)
    plt.plot(thrust_resampled[idx], magZ_body[idx], 'yo',
             thrust_resampled[idx],
             pz_th[idx][0] * thrust_resampled[idx] + pz_th[idx][1], '--k')
    plt.xlabel('thrust []')
    plt.ylabel('mag Z [G]')

    # display results
    plt.figtext(
        0.24,
        0.03,
        'Thrust CAL_MAG{}_XCOMP: {:.3f}[G] \nCurrent CAL_MAG{}_XCOMP: {:.3f}[G/kA]'
        .format(calibration_instance[idx], px_th[idx][0],
                calibration_instance[idx], -px_curr[idx][0]),
        horizontalalignment='center',
        fontsize=12,
        multialignment='left',
        bbox=dict(boxstyle="round",
                  facecolor='#D8D8D8',
                  ec="0.5",
                  pad=0.5,
                  alpha=1),
        fontweight='bold')

    plt.figtext(
        0.51,
        0.03,
        'Thrust CAL_MAG{}_YCOMP: {:.3f}[G] \nCurrent CAL_MAG{}_YCOMP: {:.3f}[G/kA]'
        .format(calibration_instance[idx], py_th[idx][0],
                calibration_instance[idx], -py_curr[idx][0]),
        horizontalalignment='center',
Example #44
0
plt.close('all')

fig = plt.figure(figsize=[12, 6])

gm = gridspec.GridSpec(100, 190)
ax2 = plt.subplot(gm[:, :])

h = ax2.hist(1. / curvature,
             bins=20,
             range=[0, 2100],
             orientation="vertical",
             color='b')
ax2.set_xlim(0, 2100)
#ax2.yaxis.tick_right()
#ax2.yaxis.set_label_position("right")
ax2.set_ylabel('Counts', fontsize=18, rotation=270, labelpad=13)
ax2.set_ylim(0, 15)
ax2.set_xlabel('Curvature (1/m)', fontsize=18, labelpad=2)
#ax0.set_xticks([])
#ax2.set_yticks([25, 50, 75, 100])
#ax2.get_children()[19].set_facecolor('r')

plt.figtext(0.5,
            0.94,
            'Trayectory curvature distribution',
            fontsize=20,
            va='center',
            ha='center')

plt.savefig('trayectory_curvature_distribution.png')
Example #45
0
    def print_info(self, interpretation):
        """Print info about the patient and about the ecg signals.
        """

        try:
            pat_surname, pat_firstname = self.dicom.PatientName.decode('ISO-8859-1').split('^')
        except ValueError:
            pat_surname = self.dicom.PatientName
            pat_firstname = ''

        pat_name = ' '.join((pat_surname, pat_firstname.title()))
        pat_age = self.dicom.get('PatientAge', '').strip('Y')

        pat_id = self.dicom.PatientID
        pat_sex = self.dicom.PatientSex
        try:
            pat_bdate = datetime.strptime(
                self.dicom.PatientBirthDate, '%Y%m%d').strftime("%e %b %Y")
        except ValueError:
            pat_bdate = ""

        acquisition_date = datetime.strftime(datetime.strptime(
            self.dicom.AcquisitionDateTime, '%Y%m%d%H%M%S'), '%d %b %Y %H:%M')

        info = "%s\n%s: %s\n%s: %s\n%s: %s (%s %s)\n%s: %s" % (
            pat_name,
            i18n.pat_id,
            pat_id,
            i18n.pat_sex,
            pat_sex,
            i18n.pat_bdate,
            pat_bdate,
            pat_age,
            i18n.pat_age,
            i18n.acquisition_date,
            acquisition_date
        )

        plt.figtext(0.08, 0.87, info, fontsize=8)

        plt.figtext(0.30, 0.87, self.legend(), fontsize=8)

        if interpretation:
            plt.figtext(0.45, 0.87, self.interpretation(), fontsize=8)

        info = "%s: %s s %s: %s Hz" % (
            i18n.duration, self.duration,
            i18n.sampling_frequency,
            self.sampling_frequency
        )

        plt.figtext(0.08, 0.025, info, fontsize=8)

        info = INSTITUTION
        if not info:
            info = self.dicom.get('InstitutionName', '')

        plt.figtext(0.38, 0.025, info, fontsize=8)

        # TODO: the lowpass filter 0.05-40 Hz will have to became a parameter
        info = "%s mm/s %s mm/mV 0.05-40 Hz" % (self.mm_s, self.mm_mv)
        plt.figtext(0.76, 0.025, info, fontsize=8)
Example #46
0
     10 * np.log10((P_rectangular2 / np.amax(P_rectangular2)) ** 2),
     "g",
     label="0.4m",
 )
 plt.xlabel(r"Dy $\theta$($\circ$)")
 plt.ylabel("Power(dB)")
 plt.yticks(np.linspace(-40, 0, 5))
 plt.ylim([-40, 0])
 plt.grid(True)
 plt.title("Dx = 0.4 m")
 ax = plt.subplot(133)
 plt.figtext(
     0.5,
     0.5,
     z,
     style="italic",
     wrap=True,
     horizontalalignment="center",
     fontsize=18,
     color="gray",
 )
 plt.plot(
     np.degrees(theta),
     10 * np.log10((P_rectangular3 / np.amax(P_rectangular3)) ** 2),
     "purple",
     label=" 0.6 m",
 )
 plt.xlabel("Dy ( m )")
 plt.ylabel(r"Power $\theta$($\circ$)")
 plt.yticks(np.linspace(-40, 0, 5))
 plt.ylim([-40, 0])
 plt.grid(True)
Example #47
0
               all_crit)
###################
c = venn3(subsets=sets,
          set_labels=('Ablations', 'Posture', 'Trayectory'),
          ax=ax4,
          alpha=0.65)
for text in c.set_labels:
    text.set_fontsize(18)
for text in c.subset_labels:
    text.set_fontsize(18)

plt.figtext(0.09,
            0.92,
            'A and B class neuron ablation analysis',
            fontsize=22,
            bbox={
                'facecolor': colors[0],
                'alpha': 0.5,
                'pad': 18
            })
plt.figtext(0.62,
            0.92,
            'Body posture analysis',
            fontsize=22,
            bbox={
                'facecolor': colors[1],
                'alpha': 0.5,
                'pad': 18
            })
plt.figtext(0.132,
            0.4,