Ejemplo n.º 1
0
# and set the times of our query, and the channels we want:
start = tconvert('May 27 2014 04:00')
end = start + 1800
gndchannel = 'L1:ISI-GND_STS_ITMY_Z_DQ'
hpichannel = 'L1:HPI-ITMY_BLND_L4C_Z_IN1_DQ'

# We can call the :meth:`~TimeSeriesDict.get` method of the `TimeSeriesDict`
# to retrieve all data in a single operation:
data = TimeSeriesDict.get([gndchannel, hpichannel], start, end, verbose=True)
gnd = data[gndchannel]
hpi = data[hpichannel]

# Next, we can call the :meth:`~TimeSeries.average_fft` method to calculate
# an averages, complex-valued FFT for each `TimeSeries`:
gndfft = gnd.average_fft(100, 50, window='hamming')
hpifft = hpi.average_fft(100, 50, window='hamming')

# Finally, we can divide one by the other to get the transfer function
# (up to the lower Nyquist)
size = min(gndfft.size, hpifft.size)
tf = hpifft[:size] / gndfft[:size]

# The `~gwpy.plot.BodePlot` knows how to separate a complex-valued
# `~gwpy.frequencyseries.FrequencySeries` into magnitude and phase:
plot = BodePlot(tf)
plot.maxes.set_title(
    r'L1 ITMY ground $\rightarrow$ HPI transfer function')
plot.maxes.set_ylim(-55, 50)
plot.show()
Ejemplo n.º 2
0
#if fft < com.dt.value:
#    fft=2*com.dt.value
#    ol=fft/2.  #  overlap in FFTs.
#    stride=2*fft
#    print("Given fft/stride was bad against the sampling rate. Automatically set to:")
#    print("fft="+str(fft))
#    print("ol="+str(ol))
#    print("stride="+str(stride))

reffft = ref.average_fft(fft, ol, window='hanning')
comfft = com.average_fft(fft, ol, window='hanning')

size = min(reffft.size, comfft.size)
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
Ejemplo n.º 3
0
# To create a low-pass filter at 1000 Hz for 4096 Hz-sampled data:

from gwpy.signal.filter_design import notch

n = notch(100, 4096)

# To view the filter, you can use the `~gwpy.plot.BodePlot`:

from gwpy.plot import BodePlot

plot = BodePlot(n, sample_rate=4096)
plot.show()
Ejemplo n.º 4
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()
Ejemplo n.º 5
0
# To create a band-pass filter for 100-1000 Hz for 4096 Hz-sampled data:

from gwpy.signal.filter_design import bandpass
bp = bandpass(100, 1000, 4096)

# To view the filter, you can use the `~gwpy.plot.BodePlot`:

from gwpy.plot import BodePlot
plot = BodePlot(bp, sample_rate=4096)
plot.show()
Ejemplo n.º 6
0
from gwpy.signal.filter_design import bandpass
from gwpy.plot import BodePlot
zpk = bandpass(40, 1000, 4096, analog=True)
plot = BodePlot(zpk, analog=True, title='40-1000\,Hz bandpass filter')
plot.show()
Ejemplo n.º 7
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()
Ejemplo n.º 8
0
from gwpy.signal.filter_design import bandpass
from gwpy.plot import BodePlot

zpk = bandpass(40, 1000, 4096, analog=False)
plot = BodePlot(zpk,
                analog=False,
                sample_rate=4096,
                title='40-1000 Hz bandpass filter')
plot.show()
Ejemplo n.º 9
0
	chunk_start += averaging_time
	chunk_end += averaging_time
	N += 1

hoft_tf_data = hoft_tf_data / N
hoft_tf = FrequencySeries(hoft_tf_data, f0=f0, df=df)

if options.analyze_calcs_hoft:
	CALCS_tf_data = CALCS_tf_data / N
	CALCS_tf = FrequencySeries(CALCS_tf_data, f0=f0, df=df)
if options.analyze_additional_hoft:
	additional_hoft_tf_data = additional_hoft_tf_data / N
	additional_hoft_tf = FrequencySeries(additional_hoft_tf_data, f0=f0, df=df)

# Make plot that compares all of the derived response functions and the model response
plot = BodePlot(response_fs, frequencies=freqs, dB = False, linewidth=2)
plot.add_frequencyseries(hoft_tf*3995.1, dB = False, color='#ee0000',linewidth=2)
if options.analyze_calcs_hoft:
	plot.add_frequencyseries(CALCS_tf, dB=False, color='#4ba6ff', linewidth=2)
if options.analyze_additional_hoft:
	plot.add_frequencyseries(additional_hoft_tf*3995.1, dB = False, color="#94ded7", linewidth=2)
plot.legend([r'Reference model response function', r'GDS h(t) derived response function', r'CALCS h(t) derived response function', r'DCS h(t) derived response function'], loc='upper right', fontsize='x-small')
# FIXME: Figure out how to make the legend and title appropriate and flexible
plot.maxes.set_yscale('log')
plot.paxes.set_yscale("linear")
plot.save('%s_%s_%s_all_tf.png' % (ifo, options.gps_start_time, options.gps_end_time))

# Make a plot that compares the ratios of each derived response to the model
ratio_hoft = hoft_tf / response_fs
if options.analyze_calcs_hoft:
	ratio_CALCS = CALCS_tf / response_fs
Ejemplo n.º 10
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))