예제 #1
0
tf = comfft[:size] / reffft[:size]

plot = BodePlot(tf)
plot.maxes.set_title('Transfer function')
#coh = ref.coherence_spectrogram(com,stride,fftlength=fft,overlap=ol)

# The time axis of coherencegram seems buggy in this version. Temporal fix is needed.
#coh.dx = stride

#cohplot=coh.plot(figsize = (12, 8),vmin=0.,vmax=1.)
#ax = cohplot.gca()
ax = plot.gca()
#ax.set_ylabel('Frequency [Hz]')
#ax.set_yscale('log')
#ax.set_title(latexrefchname + ' ' + latexchname)

#if fmin < 0:
#    fmin = 0.8/fft
#ax.set_ylim(fmin,fmax)

#cohplot.add_colorbar(cmap='YlGnBu_r',label='Coherence')

fname = outdir + '/' + refchannel + '_' + channel + '_TF_' + gpsstart + '_' + gpsend + '_' + index + '.png'
plot.savefig(fname, dpi=dpi)

plot.clf()
plot.close()

print(fname)
print('Successfully finished !')
예제 #2
0
def main(channel,start,end):

    data = TimeSeries.read(
        dumped_gwf_fmt.format(start=start,end=end,chname=channel),
        channel, verbose=True ,nproc=8)


    # Filter
    zpk_bp_high = filter_design.highpass(0.3, data.sample_rate, 
                                         ftype='butter',analog=False,
                                         gpass=2,gstop=40,fstop=0.03
    )
    zpk_bp_mid = filter_design.bandpass(0.03, 0.3, data.sample_rate, 
                                        ftype='butter',analog=False,
                                        gpass=2, gstop=40,fstop=(0.003,3)
    )
    zpk_bp_low = filter_design.lowpass(0.03, data.sample_rate, 
                                       ftype='butter',analog=False,
                                       gpass=2, gstop=40, fstop=0.3
    )
    filters = [zpk_bp_high, zpk_bp_mid, zpk_bp_low]

    # Plot Bodeplot
    plot = BodePlot(*filters,
                    frequencies=numpy.logspace(-4,1,1e5),
                    dB=True,sample_rate=data.sample_rate,
                    unwrap=False,analog=False,
                    title='filter')
    axes = plot.get_axes()
    labels = ['High (300mHz-)','Mid (50mHz-300mHz)','Low (-50mHz)']
    for i,ax in enumerate(axes):
        ax.legend(labels,loc='lower left')
        
    #axes[0].set_yscale('log')
    #axes[0].set_ylim(1e-3,2e0)
    axes[0].set_ylim(-40,2)
    axes[-1].set_xlim(5e-3,3e0)
    axes[-1].set_ylim(-200,200)
    plot.savefig('Bodeplot_BandPass.png')
    plot.close()
        
    # Filtering
    data_high = data.filter(zpk_bp_high, filtfilt=True,analog=False)
    data_mid = data.filter(zpk_bp_mid, filtfilt=True,analog=False)
    data_low = data.filter(zpk_bp_low, filtfilt=True,analog=False)

    # 
    data_high = data_high.crop(*data_high.span.contract(1))
    data_mid = data_mid.crop(*data_mid.span.contract(1))
    data_low = data_low.crop(*data_low.span.contract(1))
        
    # Plot TimeSeries        
    from gwpy.plot import Plot    
    data_set = [data,data_high, data_mid, data_low]
    plot = Plot(*data_set,
                separate=True, sharex=True, sharey=True,
                color='gwpy:ligo-livingston',
                figsize=[10,10])

    # Add text, and save figure
    title = channel[3:].replace('_',' ')
    labels = ['No filt', 'High (300mHz-)', 'Mid (50mHz-300mHz)', 'Low (-50mHz)']
    if data.unit == ' ':
        yaxis_label = 'Count'
    else:
        yaxis_label = data.unit
    axes = plot.get_axes()
    for i,ax in enumerate(axes):
        ax.legend([labels[i]],loc='upper left')
    plot.text(0.04, 0.5, yaxis_label, va='center', rotation='vertical',fontsize=18)
    axes[0].set_title(title,fontsize=16)
    axes[-1].set_xscale('Hours', epoch=start)
    plot.savefig(timeseriesplot_fname_fmt.format(channel=channel))
    plot.close()
예제 #3
0
def main(start, end, chname):
    data = TimeSeries.read(dumped_gwf_fmt.format(start=start,
                                                 end=end,
                                                 chname=channel),
                           channel,
                           verbose=True,
                           nproc=8)

    # Filtering
    from gwpy.signal import filter_design
    from gwpy.plot import BodePlot
    import numpy
    bp_high = filter_design.highpass(
        0.3,
        data.sample_rate,
        analog=True,
        ftype='butter',
        gpass=2,
        gstop=30  #,fstop()
    )
    bp_mid = filter_design.bandpass(
        0.05,
        0.3,
        data.sample_rate,
        analog=True,
        ftype='butter',
        gpass=2,
        gstop=30  #,fstop=(0.01,0.5)
    )
    bp_low = filter_design.lowpass(
        0.05,
        data.sample_rate,
        analog=True,
        ftype='butter',
        gpass=2,
        gstop=30  #, fstop=2
    )
    filters = [bp_high, bp_mid, bp_low]

    plot = BodePlot(*filters,
                    analog=True,
                    frequencies=numpy.logspace(-3, 1, 1e5),
                    dB=False,
                    unwrap=False,
                    title='filter')
    axes = plot.get_axes()
    axes[0].set_yscale('log')
    axes[0].set_ylim(1e-4, 2e0)
    axes[-1].set_xlim(1e-2, 1e0)
    axes[-1].set_ylim(-180, 180)
    plot.savefig('Bodeplot_BandPass.png')
    plot.close()

    data_high = data.filter(bp_high, filtfilt=True)
    data_high = data_high.crop(*data_high.span.contract(1))
    data_mid = data.filter(bp_mid, filtfilt=True)
    data_mid = data_mid.crop(*data_mid.span.contract(1))
    data_low = data.filter(bp_low, filtfilt=True)
    data_low = data_low.crop(*data_low.span.contract(1))

    # Plot TimeSeries
    title = channel[3:].replace('_', ' ')
    labels = [
        'No filt', 'High (300mHz-)', 'Mid (50mHz-300mHz)', 'Low (-50mHz)'
    ]
    if data.unit == ' ':
        yaxis_label = 'Count'
    else:
        yaxis_label = data.unit

    from gwpy.plot import Plot
    data_set = [data, data_high, data_mid, data_low]
    plot = Plot(*data_set,
                separate=True,
                sharex=True,
                sharey=True,
                color='gwpy:ligo-livingston',
                figsize=[10, 10])

    axes = plot.get_axes()
    for i, ax in enumerate(axes):
        ax.legend([labels[i]], loc='upper left')

    plot.text(0.04,
              0.5,
              yaxis_label,
              va='center',
              rotation='vertical',
              fontsize=16)
    #plot.text(0.5, 0.93, title, va='center',ha='center',rotation='horizontal',fontsize=16)
    axes[0].set_title(title, fontsize=16)
    axes[-1].set_xscale('Hours', epoch=start)
    plot.savefig(timeseriesplot_fname_fmt.format(channel=channel))
    plot.close()
예제 #4
0
def main(channel, start, end):
    data = TimeSeries.read(dumped_gwf_fmt.format(start=start,
                                                 end=end,
                                                 chname=channel),
                           channel,
                           verbose=True,
                           nproc=8)

    # Make Filter
    dnumden_120qa = trillium.tf_120qa(analog=True,
                                      sample_rate=2048 / 2,
                                      Hz=False,
                                      normalize=False)

    #
    filters = [dnumden_120qa]

    #plot_dfilt(*dnumden_120qa)

    # Plot Bodeplot
    plot = BodePlot(*filters,
                    frequencies=numpy.logspace(-3, 3, 1e5),
                    dB=False,
                    sample_rate=2048 / 2,
                    unwrap=False,
                    analog=True,
                    title='filter')

    axes = plot.get_axes()
    labels = ['Trillium120QA', 'TrilliumCompact']
    for i, ax in enumerate(axes):
        ax.legend(labels, loc='lower left')

    #axes[0].set_yscale('log')
    axes[0].set_ylim(1e-3, 1e8)
    #axes[0].set_ylim(-40,2)
    #axes[-1].set_xlim(5e-3,3e0)
    axes[-1].set_ylim(-200, 200)
    plot.savefig('Bodeplot_Trillium120QA.png')
    plot.close()

    exit()
    # Filtering
    data_calib = data.filter(zpk_trillium120qa, filtfilt=True, analog=False)

    # crop
    data_calib = data_low.crop(*data_calib.span.contract(1))

    # Plot TimeSeries
    from gwpy.plot import Plot
    data_set = [data_calib]
    plot = Plot(*data_set,
                separate=True,
                sharex=True,
                sharey=True,
                color='gwpy:ligo-livingston',
                figsize=[10, 10])

    # Add text, and save figure
    title = channel[3:].replace('_', ' ')
    labels = [
        'No filt', 'High (300mHz-)', 'Mid (50mHz-300mHz)', 'Low (-50mHz)'
    ]
    if data.unit == ' ':
        yaxis_label = 'Count'
    else:
        yaxis_label = data.unit
    axes = plot.get_axes()
    for i, ax in enumerate(axes):
        ax.legend([labels[i]], loc='upper left')
    plot.text(0.04,
              0.5,
              yaxis_label,
              va='center',
              rotation='vertical',
              fontsize=18)
    axes[0].set_title(title, fontsize=16)
    axes[-1].set_xscale('Hours', epoch=start)
    plot.savefig(timeseriesplot_fname_fmt.format(channel=channel))
    plot.close()

    # Plot ASD
    fftlen = 2**7
    specgram = data.spectrogram2(fftlength=fftlen, overlap=2,
                                 window='hanning')**(1 / 2.)
    median = specgram.percentile(50)
    low = specgram.percentile(5)
    high = specgram.percentile(95)
    plot = Plot()
    ylabel_fmt = r'{yaxis_label} [{yaxis_label}/\rtHz]'
    ax = plot.gca(
        xscale='log',
        xlim=(1e-3, 10),
        xlabel='Frequency [Hz]',
        yscale='log',  #ylim=(3e-24, 2e-20),
        ylabel=ylabel_fmt.format(yaxis_label=yaxis_label))
    ax.plot_mmm(median, low, high, color='gwpy:ligo-livingston')
    ax.set_title(title, fontsize=16)
    plot.savefig(asdplot_fname_fmt.format(channel=channel))
    plot.close()

    # Plot Spectrogram
    specgram = data.spectrogram(fftlen * 2, fftlength=fftlen,
                                overlap=.5)**(1 / 2.)
    plot = specgram.imshow(norm='log')
    ax = plot.gca()
    ax.set_yscale('log')
    ax.set_ylim(1e-3, 10)
    ax.set_title(title, fontsize=16)
    ax.colorbar(label=ylabel_fmt.format(yaxis_label=yaxis_label))
    plot.savefig(spectrogramplot_fname_fmt.format(channel=channel))