def kagra_seis_now(start, end, fftlen=2**8, ovlp=2**7, axis='X', verbose=True): if axis in ['X', 'Y', 'Z']: chname = 'K1:PEM-SEIS_EXV_GND_{0}_OUT_DQ'.format(axis) vel = TimeSeries.fetch(chname, start, end, host='10.68.10.121', port=8088, verbose=verbose) vel_asd = vel.asd(fftlength=fftlen, overlap=ovlp) return vel_asd elif axis == 'H': vel_x = kagra_seis_now(start, end, axis='X') vel_y = kagra_seis_now(start, end, axis='Y') vel_h = (vel_x**2 + vel_y**2)**(1. / 2) return vel_h elif axis == 'V': return kagra_seis('Z', pctl) elif axis == 'GIF': chname = 'K1:GIF-X_STRAIN_OUT16' vel = TimeSeries.fetch(chname, start, end, host='10.68.10.121', port=8088, verbose=verbose) # strain vel = vel * 3000 * 1e6 vel_asd = vel.asd(fftlength=fftlen, overlap=ovlp) return vel_asd elif axis == 'L_diff': chname = 'K1:PEM-SEIS_EXV_GND_X_OUT16' exv = TimeSeries.fetch(chname, start, end, host='10.68.10.121', port=8088, verbose=verbose) chname = 'K1:PEM-SEIS_IXV_GND_X_OUT16' ixv = TimeSeries.fetch(chname, start, end, host='10.68.10.121', port=8088, verbose=verbose) vel_diff = exv - ixv vel_asd = vel_diff.asd(fftlength=fftlen, overlap=ovlp) return vel_asd elif axis == 'OpLev_L': chname = 'K1:VIS-ETMX_TM_DAMP_L_IN1_DQ' vel = TimeSeries.fetch(chname, start, end, host='10.68.10.121', port=8088, verbose=verbose) else: raise ValueError('hoge')
def generate_fast_vco(ifo, segment, frames=False, fit=True): """ Parameters: ----------- ifo : start interferometer, e.g. 'L1' segment : array like time segment. first entry start second entry end frames : bool read from frames or nds2 fit : bool fit from imc-f (default) or spline interpolation Returns: -------- vco_data : saves file 'L1:IMC-VCO_PREDICTION-st-dur.hdf' """ st = segment[0] et = segment[1] chan1_pat = '%s:SYS-TIMING_C_FO_A_PORT_11_SLAVE_CFC_FREQUENCY_5' chan2_pat = '%s:IMC-F_OUT_DQ' if frames: connection = datafind.GWDataFindHTTPConnection() cache = connection.find_frame_urls( ifo[0], '%s_R' % ifo, st, et + 1, urltype='file') if fit: imc = TimeSeries.read(cache, chan2_pat % ifo, st, et) else: imc = TimeSeries.read(cache, chan2_pat % ifo, st, st + 1) pslvco = TimeSeries.read(cache, chan1_pat % ifo, st, et + 1) else: if fit: imc = TimeSeries.fetch(chan2_pat % ifo, st, et) else: print 'HI BEFORE LOADING IMC' imc = TimeSeries.fetch(chan2_pat % ifo, st, st + 1) print 'HI BEFORE LOADING PSL' pslvco = TimeSeries.fetch(chan1_pat % ifo, st, et + 1) print 'HI AFTER LOADING' pslvco = pslvco[16 + 8::16] if fit: imc_srate = int(imc.sample_rate.value) imc2 = imc[imc_srate / 2::imc_srate] data = np.array((imc2.value, pslvco.value)).T vco_interp = fit_with_imc(data, imc) else: vco_interp = interp_spline(pslvco) chan = "%s:IMC-VCO_PREDICTION" % (ifo,) vco_data = TimeSeries(vco_interp, epoch=st, sample_rate=256, name=chan, channel=chan) return vco_data
def generate_fast_vco(ifo, segment, frames=False, fit=True): """ Parameters: ----------- ifo : start interferometer, e.g. 'L1' segment : array like time segment. first entry start second entry end frames : bool read from frames or nds2 fit : bool fit from imc-f (default) or spline interpolation Returns: -------- vco_data : saves file 'L1:IMC-VCO_PREDICTION-st-dur.hdf' """ st = segment[0] et = segment[1] chan1_pat = '%s:SYS-TIMING_C_FO_A_PORT_11_SLAVE_CFC_FREQUENCY_5' chan2_pat = '%s:IMC-F_OUT_DQ' if frames: connection = datafind.GWDataFindHTTPConnection() cache = connection.find_frame_urls( ifo[0], '%s_R' % ifo, st, et + 1, urltype='file') if fit: imc = TimeSeries.read(cache, chan2_pat % ifo, st, et) else: imc = TimeSeries.read(cache, chan2_pat % ifo, st, st + 1) pslvco = TimeSeries.read(cache, chan1_pat % ifo, st, et + 1) else: if fit: imc = TimeSeries.fetch(chan2_pat % ifo, st, et) else: imc = TimeSeries.fetch(chan2_pat % ifo, st, st + 1) pslvco = TimeSeries.fetch(chan1_pat % ifo, st, et + 1) pslvco = pslvco[16 + 8::16] if fit: imc_srate = int(imc.sample_rate.value) imc2 = imc[imc_srate / 2::imc_srate] data = np.array((imc2.value, pslvco.value)).T vco_interp = fit_with_imc(data, imc) else: vco_interp = interp_spline(pslvco) chan = "%s:IMC-VCO_PREDICTION" % (ifo,) vco_data = TimeSeries(vco_interp, epoch=st, sample_rate=256, name=chan, channel=chan) return vco_data
def get_timeseries(chname,**kwargs): start = kwargs.pop('start',None) end = kwargs.pop('end',None) nds = kwargs.pop('nds',None) fname = to_gwffname(chname,**kwargs) if os.path.exists(fname): print('{0} exist.',format(fname)) print('Skip fetch from nds {0}'.format(fname)) data = TimeSeries.read(fname,chname,start,end, format='gwf.lalframe', verbose=True, pad=np.nan) return data elif nds and not os.path.exists(fname): print('{0} dose not exist.',format(fname)) data = TimeSeries.fetch(chname, start, end, verbose=True, host='10.68.10.121', port=8088, pad=np.nan, verify=True,type=1,dtype=np.float32) data.write(fname,format='gwf.lalframe') print('wrote data in '+fname) return data else: print(nds) print(os.path.exists(fname)) print(fname) raise ValueError('! Must use nds or load files') exit()
def calibrate_imc_pslvco(ifo, start_time, dur, cache=None): st, et = start_time, start_time + dur if cache: pslvco = TimeSeries.read(cache, chan1_pat % ifo, start=st, end=et) imc = TimeSeries.read(cache, chan2_pat % ifo, start=st, end=et) else: imc = TimeSeries.fetch(chan2_pat % ifo, st, et) pslvco = TimeSeries.fetch(chan1_pat % ifo, st, et) arr_psl = pslvco[8::16] arr_imc = imc tmp1 = (arr_imc[8192::16384])[:-1] tmp2 = arr_psl[1:] a, b = numpy.polyfit(tmp1, tmp2, 1) return a, b
def locked(): lockstate = TimeSeries.fetch('K1:GRD-LSC_LOCK_OK',start,end,host='10.68.10.121',port=8088,pad=np.nan) fs = (1./lockstate.dt).value locked = (lockstate == 1.0*u.V).to_dqflag(round=False,minlen=2**10*fs) # *1 ok = locked.active ok = SegmentList(sorted(ok,key=lambda x:x.end-x.start,reverse=True)) # *2 myprint(ok) ok.write('segments_locked.txt') print('Finished segments_locked.txt')
def get_time_series(channel_names, t_start, t_end, return_failed=False): """ Extract time series data for a list of channel(s). Parameters ---------- channel_names : list of strings Names of channels to load. t_start : float, int Start time of time series segment. t_end : float, int End time of time series segment. return_failed : {False, True} If True, return list of channels that failed to load. Returns ------- time_series_list : list Gwpy TimeSeries objects. channels_failed : list Names of channels that failed to load, only return if return_failed is True. """ time_series_list = [] channels_failed = [] for name in channel_names: try: time_series_list.append(TimeSeries.fetch(name, t_start, t_end)) except RuntimeError: channels_failed.append(name) print('') logging.warning('Channel failed to load: ' + name + ' at time ' + str(t_start) + ' to ' + str(t_end) + '.') print('') else: logging.info('Channel successfully extracted: ' + name + ' at time ' + str(t_start) + ' to ' + str(t_end) + '.') if len(time_series_list) == 0: print('') logging.warning( 'No channels were successfully extracted. Check that channel names and times are valid.', warn=True) print('') elif len(channels_failed) > 0: N_failed, N_chans = [len(channels_failed), len(time_series_list)] print('Failed to extract {} of {} channels:'.format(N_failed, N_chans)) for c in channels_failed: print(c) print('Check that these channel names and times are valid.') if return_failed: return time_series_list, channels_failed else: return time_series_list
def check_decoded_times(start_time, timewindow=30): """Check the decoded IRIG-B times within a window of size timewindow surrounding the event time and make sure the times are all correct (i.e. they are either the correct UTC or GPS time; either one is considered correct). Save the results of the check to a text file for upload to LIGO's EVNT log.""" for chan in CHANS: format_string = 'Decoding {}+/-{}s on channel {}.' start_time = int(start_time) msg = format_string.format(start_time, timewindow, chan) print(msg) # print a header, since output will be arranged tabularly, e.g. # 1225152018 | 1225152018 | 18 | GPS | 0 | 0 | 0 | 306 | ... # 2018 | Thu Nov 02 00:00:00 2018 | Fri Nov 02 23:59:42 2018 print("Actual GPS | Decode GPS | Leap | Scale | Sec | Min | Hr | Day " "| Year | Decoded Date/Time | Actual UTC Date/Time") print("-----------+------------+------+-------+-----+-----+----+-----" "+------+--------------------------+-------------------------") row_fmt = ("{gps_actual:>10d} | {gps_decoded:>10d} | {leap:>4d} | " "{scale:<5} | {second:>3d} | {minute:>3d} | {hour:>2d} | " "{day:>3d} | {year:>4d} | {datetime_decoded:<24} | " "{datetime_actual:<24}") timeseries = TimeSeries.fetch(chan, start_time - timewindow, start_time + timewindow + 1).value # deal with one second at a time, writing results to file for i in range(2 * timewindow + 1): timeseries_slice = timeseries[i * BITRATE:(i + 1) * BITRATE] gps_actual = (start_time - timewindow) + i leap_seconds = get_leap_seconds(gps_actual) t_actual = Time(gps_actual, format='gps', scale='utc') decoded = geco_irig_decode.decode_timeseries(timeseries_slice) t = decoded['datetime'] dt = (t - t_actual.to_datetime()).seconds datetime_actual = t_actual.to_datetime().strftime(TFORMAT) # check whether the times agree, or whether they are off by the # current number of leap seconds if dt == 0: scale = "UTC" elif dt == leap_seconds: scale = "GPS" else: scale = "ERROR" print( row_fmt.format( gps_actual=gps_actual, # foo = dict(gps_actual=gps_actual, gps_decoded=int(Time(t).gps), leap=leap_seconds, scale=scale, datetime_decoded=t.strftime(TFORMAT), datetime_actual=datetime_actual, **decoded))
def test_fetch(self): try: nds_buffer = mockutils.mock_nds2_buffer( 'X1:TEST', self.data, 1000000000, self.data.shape[0], 'm') except ImportError as e: self.skipTest(str(e)) nds_connection = mockutils.mock_nds2_connection([nds_buffer]) with mock.patch('nds2.connection') as mock_connection, \ mock.patch('nds2.buffer', nds_buffer): mock_connection.return_value = nds_connection # use verbose=True to hit more lines ts = TimeSeries.fetch('X1:TEST', 1000000000, 1000000001, verbose=True) nptest.assert_array_equal(ts.value, self.data) self.assertEqual(ts.sample_rate, self.data.shape[0] * units.Hz) self.assertTupleEqual(ts.span, (1000000000, 1000000001)) self.assertEqual(ts.unit, units.meter)
def fetch_lemi(cls, ifo, direction, st, et): # check direction if direction.upper() != 'X' and direction.upper() != 'Y': raise ValueError('Direction must be X or Y') # set channels for LEMIs if ifo == 'L1': chan = ('L1:PEM-EY_VAULT_MAG_LEMI_%s_DQ' % direction.upper()) elif ifo == 'H1': chan = ('H1:PEM-VAULT_MAG_1030X195Y_COIL_%s_DQ' % direction.upper()) else: raise ValueError('ifo must be L1 or H1') # fetch, set units, multiply by calibration data = TimeSeries.fetch(chan, st, et) * 0.305 data.override_unit(units.pT) return cls.from_timeseries(data)
def fetch(chname, start, end, ndsserver='10.68.10.121'): try: print('Loading data from nds server... It may take few minutes..') print('ChannelName : {}'.format(chname)) data = TimeSeries.fetch(chname, start, end, host=ndsserver, port=8088) print('Done.') return data except RuntimeError as e: print('[Error]', e) print( '[Error] Faild to establish a connection to NDSserver({})'.format( ndsserver)) print('[Error] Please check the connection with "ping {}"'.format( ndsserver)) print('[Error] Exit..') exit() except ImportError as e: print('[Error] {}. Please execute "source ~/.bash_profile"'.format(e)) exit()
def get_spec(channel, t0, t1, qrange=(4, 96), frange=(20, 300), tres=0.001, fres=1, outseg=None, verbose=False): """ Load data and create spectrogram from q-transform(s). Parameters ---------- channels : list t0 : int, float t1 : int, float qrange : tuple, optional frange : tuple, optional tres : float, optional fres : float, optional outseg : tuple, optional Returns ------- specs : list """ if outseg is None: t = (t0 + t1) / 2. dt = 0.5 outseg = (t - dt, t + dt) ts = TimeSeries.fetch(channel, t0, t1, verbose=verbose) spec = ts.q_transform(qrange=qrange, frange=frange, tres=tres, fres=fres, outseg=outseg) if spec.name is None: spec.name = channel return spec
def _read_data(channel, st, et, frames=False): """ get data, either from frames or from nds2 """ ifo = channel.split(':')[0] if frames: # read from frames connection = datafind.GWDataFindHTTPConnection() print ifo[0] if channel.split(':')[1] == 'GDS-CALIB_STRAIN': cache = connection.find_frame_urls(ifo[0],ifo+'_HOFT_C00', st, et, urltype='file') else: cache = connection.find_frame_urls(ifo[0], ifo + '_C', st, et,urltype='file') try: data = TimeSeries.read(cache, channel, st, et) except IndexError: cache = connection.find_frame_urls(ifo[0], ifo+'_R', st, et, urltype='file') data = TimeSeries.read(cache, channel, st, et) else: data = TimeSeries.fetch(channel, st, et) return data
lflag=bool(llabel) if fft > stride: print('Warning: stride is shorter than fft length. Set stride=fft') stride=fft #unit = r'Amplitude [$\sqrt{\mathrm{Hz}^{-1}}$]' unit = r'Amplitude [1/rHz]' if channel.find('ACC_') != -1: unit = 'Acceleration [m/s^2/rHz]' elif channel.find('MIC_') != -1: unit = 'Sound [Pa/rHz]' # Get data from frame files if kamioka: data = TimeSeries.fetch(channel,float(gpsstartmargin),float(gpsendmargin),host='k1nds0',port=8088) else: if ll: sources = mylib.GetLLFilelist(gpsstartmargin,gpsendmargin) elif GEO: sources = mylib.GetGeoFilelist(gpsstart,gpsend) else: sources = mylib.GetFilelist(gpsstartmargin,gpsendmargin) data = TimeSeries.read(sources,channel,format='gwf.lalframe',start=float(gpsstartmargin),end=float(gpsendmargin)) if fft <= 2.*data.dt.value: fft=2.*data.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))
from gwpy.time import Time from gwpy.timeseries import TimeSeries from gwpy.plotter import TimeSeriesPlot from matplotlib.ticker import MultipleLocator, FormatStrFormatter start = Time('2014-11-29 00:00:00', format='iso', scale='utc') end = Time('2014-11-30 00:00:00', format='iso', scale='utc') print start.iso, start.gps print end.iso, end.gps #TCS = TimeSeries.fetch('L1:TCS-ITMY_HWS_CHAMBERTEMPERATURESENSORB.mean,m-trend', start, end, verbose=True) RH = TimeSeries.fetch('L1:TCS-ITMY_RH_LOWERRTD.mean,m-trend', start, end, verbose=True) ITMY = TimeSeries.fetch('L1:SUS-ITMY_M0_DAMP_V_IN1_DQ.mean,m-trend', start, end, verbose=True)
I would like to study the gravitational wave strain time-series around the time of an interesting simulated signal during the last science run (S6). I have access to the frame files on the LIGO Data Grid machine `ldas-pcdev2.ligo-wa.caltech.edu` and so can read them directly. """ from gwpy.time import Time from gwpy.timeseries import TimeSeries from gwpy import version __author__ = "Duncan Macleod <*****@*****.**>" __version__ = version.version # set the times start = Time('2010-09-16 06:42:00', format='iso', scale='utc') end = Time('2010-09-16 06:43:00', format='iso', scale='utc') # make timeseries data = TimeSeries.fetch('H1:LDAS-STRAIN', start, end) data.unit = 'strain' # plot plot = data.plot() if __name__ == '__main__': try: outfile = __file__.replace('.py', '.png') except NameError: pass else: plot.save(outfile) print("Example output saved as\n%s" % outfile)
def get_calibrated_DARM(ifo, gw_channel, t_start, t_end, FFT_time, overlap_time, calibration_file): """ Import DARM channel, convert it to ASD, and calibrate it. Parameters ---------- ifo: str Interferometer, 'H1' or 'L1'. gw_channel : str GW channel to use, must be 'strain_channel' or 'deltal_channel'. t_start : float, int Start time of time series segment. t_end : float, int End time of time series segment. FFT_time : float, int FFT time (seconds). overlap_time : float, int FFT overlap time (seconds). calibration_file : str Name of DARM calibration file to be used. Returns ------- darm_asd : FrequencySeries Calibrated ASD of imported gravitational wave channel. """ if gw_channel == 'strain_channel': strain = TimeSeries.fetch(ifo + ':GDS-CALIB_STRAIN', t_start, t_end) strain_asd = strain.asd(FFT_time, overlap_time) darm_asd = strain_asd * 4000. # Strain to DARM, multiply by 4 km elif gw_channel == 'deltal_channel': darm = TimeSeries.fetch(ifo + ':CAL-DELTAL_EXTERNAL_DQ', t_start, t_end) darm_asd = darm.asd(FFT_time, overlap_time) # Load DARM calibration file try: with open(calibration_file, 'r') as get_cal: lines = get_cal.readlines() except IOError: print('') logging.error('Calibration file ' + calibration_file + ' not found.') print('') raise # Get frequencies and calibration factors cal_freqs = np.zeros(len(lines)) dB_ratios = np.zeros(len(lines)) for i, line in enumerate(lines): values = line.split() cal_freqs[i] = float(values[0]) dB_ratios[i] = float(values[1]) cal_factors = 10.0**(dB_ratios / 20.) # Convert to calibration factors # Interpolate calibration factors then apply to DARM ASD adjusted_ratios = np.interp(darm_asd.frequencies.value, cal_freqs, cal_factors) darm_asd = darm_asd * adjusted_ratios else: print('') logging.error('Invalid input ' + str(gw_channel) + ' for arg gw_channel.') print('') print( 'Please correctly specify GW channel calibration method in the configuration file.' ) print( 'To calibrate from the strain-calibrated channel, H1:GDS-CALIB_STRAIN, write "strain_channel".' ) print( 'To calibrate from H1:CAL-DELTAL_EXTERNAL_DQ, write "deltal_channel".' ) raise NameError(gw_channel) return darm_asd
from gwpy.timeseries import TimeSeries gwdata = TimeSeries.fetch('H1:LDAS-STRAIN', 'September 16 2010 06:40', 'September 16 2010 06:50') specgram = gwdata.spectrogram(20, fftlength=8, overlap=4) ** (1/2.) plot = specgram.plot(norm='log', vmin=1e-23, vmax=1e-19) ax = plot.gca() ax.set_ylim(40, 4000) ax.set_yscale('log') plot.add_colorbar(label='Gravitational-wave strain [m/$\sqrt{\mathrm{Hz}}$]') plot.show()
from matplotlib.ticker import MultipleLocator, FormatStrFormatter from gwpy.time import Time from gwpy.timeseries import (TimeSeries, TimeSeriesDict) print "Import Modules Success" #Start-End Time start = Time('2014-06-17 04:00:00', format='iso', scale='utc') end = Time('2014-06-17 15:00:00', format='iso', scale='utc') print start.iso, start.gps print end.iso, end.gps data = TimeSeries.fetch('L1:HPI-ETMY_BLND_IPS_Z_IN1_DQ.mean,m-trend', start, end, verbose=True) plot_data = data.plot() ax = plot_data.gca() #plot_data.show() ax.set_epoch(start.gps) ax.set_xlim(start.gps, end.gps) ax.set_ylabel('Amplitude[ ]') ax.set_title(data.channel.texname) #ax.set_ylim([20000,30000]) plot_data.save('L1-HPI-ETMY_BLND_IPS_Z_IN1_DQ_JUN14.png') print "PLOT SAVED"
print('- Input : Ground differential with seismometer') gnd_vel = seismodel.kagra_seis_now(start, end, axis='L_diff', fftlen=fftlen, ovlp=ovlp, verbose=False) df = gnd_vel.df.value gnd_vel = gnd_vel.crop(df, 8 + df) freq = gnd_vel.frequencies.value omega = 2.0 * np.pi * freq gnd = gnd_vel / (2.0 * np.pi * freq) df = gnd.df.value print('- Output : Xarm cavity locking with AOM') kwargs = {'host': '10.68.10.121', 'port': 8088, 'verbose': False} data = TimeSeries.fetch('K1:CAL-CS_PROC_XARM_FILT_AOM_OUT16', start, end, **kwargs) xarm = data.asd(fftlength=fftlen, overlap=ovlp) c = 299792458 # m/sec lam = 1064e-9 # m output = xarm * 3000.0 / (c / lam) * 1e6 elif not nominal and read_sensor == 'gif': print('Reading data') print('- Input : Ground differential') gnd_vel = seismodel.kagra_seis_now(start, end, axis='GIF', fftlen=fftlen, ovlp=ovlp, verbose=False) gnd_vel = gnd_vel.crop(df, 8 + df)
to calculate discrete PSDs for each stride. This is fine for long-duration data, but give poor resolution when studying short-duration phenomena. The `~TimeSeries.spectrogram2` method allows for highly-overlapping FFT calculations to over-sample the frequency content of the input `TimeSeries` to produce a much more feature-rich output. """ __author__ = "Duncan Macleod <*****@*****.**>" __currentmodule__ = 'gwpy.timeseries' # As with the other `~gwpy.spectrogram.Spectrogram` examples, we import the # `TimeSeries` class, and :meth:`~TimeSeries.fetch` the data, but in this # example we only need 5 seconds of datam, from gwpy.timeseries import TimeSeries gwdata = TimeSeries.fetch( 'L1:OAF-CAL_DARM_DQ', 'Feb 28 2015 06:02:05', 'Feb 28 2015 06:02:10') # Now we can call the `~TimeSeries.spectrogram2` method of `gwdata` to # calculate our over-dense `~gwpy.spectrogram.Spectrogram` specgram = gwdata.spectrogram2(fftlength=0.15, overlap=0.14) ** (1/2.) # To whiten the `specgram` we can use the :meth:`~Spectrogram.ratio` method # to divide by the overall median: medratio = specgram.ratio('median') # Finally, we make a plot: plot = medratio.plot(norm='log', vmin=0.5, vmax=10) plot.set_yscale('log') plot.set_ylim(40, 8192) plot.add_colorbar(label='Amplitude relative to median') plot.set_title('L1 $h(t)$ with noise interference')
from gwpy.time import Time from gwpy.timeseries import TimeSeries from matplotlib.ticker import MultipleLocator, FormatStrFormatter start = Time('2014-11-30 00:00:00', format='iso', scale='utc') end = Time('2014-12-01 00:00:00', format='iso', scale='utc') print start.iso, start.gps print end.iso, end.gps LF = TimeSeries.fetch('L1:SUS-ITMY_M0_OSEMINF_LF_OUT_DQ.mean,m-trend', start, end, verbose=True) RT = TimeSeries.fetch('L1:SUS-ITMY_M0_OSEMINF_RT_OUT_DQ.mean,m-trend', start, end, verbose=True) F1 = TimeSeries.fetch('L1:SUS-ITMY_M0_OSEMINF_F1_OUT_DQ.mean,m-trend', start, end, verbose=True) F2 = TimeSeries.fetch('L1:SUS-ITMY_M0_OSEMINF_F2_OUT_DQ.mean,m-trend', start, end, verbose=True) F3 = TimeSeries.fetch('L1:SUS-ITMY_M0_OSEMINF_F3_OUT_DQ.mean,m-trend', start, end, verbose=True) SD = TimeSeries.fetch('L1:SUS-ITMY_M0_OSEMINF_SD_OUT_DQ.mean,m-trend', start, end, verbose=True) print 'data fetched' plot_LF = LF.plot() ax = plot_LF.gca() ax.plot(RT, label = 'L1:SUS-ITMY\_M0\_OSEMINF\_RT\_OUT\_DQ.mean') ax.plot(F1, label = 'L1:SUS-ITMY\_M0\_OSEMINF\_F1\_OUT\_DQ.mean') ax.plot(F2, label = 'L1:SUS-ITMY\_M0\_OSEMINF\_F2\_OUT\_DQ.mean') ax.plot(F3, label = 'L1:SUS-ITMY\_M0\_OSEMINF\_F3\_OUT\_DQ.mean') ax.plot(SD, label = 'L1:SUS-ITMY\_M0\_OSEMINF\_SD\_OUT\_DQ.mean') ax.set_ylabel('um') ax.legend(loc='upper right', ncol=1, fancybox=True, shadow=True) print 'plotting'
#This script compares HAM4 (SR2), HAM5 (SR3, SRM) in-chamber temp to V dof SR2 (HSTS), SRM (HSTS), SR3 (HLTS) from gwpy.time import Time from gwpy.timeseries import TimeSeries from gwpy.plotter import TimeSeriesPlot from matplotlib.ticker import MultipleLocator, FormatStrFormatter start = Time('2014-11-27 21:00:00', format='iso', scale='utc') end = Time('2014-12-01 21:00:00', format='iso', scale='utc') print start.iso, start.gps print end.iso, end.gps SR2 = TimeSeries.fetch('L1:SUS-SR2_M1_DAMP_V_IN1_DQ.mean,m-trend', start, end, verbose=True) SR3 = TimeSeries.fetch('L1:SUS-SR3_M1_DAMP_V_IN1_DQ.mean,m-trend', start, end, verbose=True) SRM = TimeSeries.fetch('L1:SUS-SRM_M1_DAMP_V_IN1_DQ.mean,m-trend', start, end, verbose=True) TCS_HAM4 = TimeSeries.fetch('L1:TCS-ITMY_HWS_CHAMBERTEMPERATURESENSORA.mean,m-trend', start, end, verbose=True) TCS_HAM5 = TimeSeries.fetch('L1:TCS-ITMX_HWS_CHAMBERTEMPERATURESENSORA.mean,m-trend', start, end, verbose=True) print 'data fetched' plot_HAM4 = TimeSeriesPlot(TCS_HAM4, SR2, sep=True) ax1 = plot_HAM4.axes[0] #plot TCS_HAM4 ax1.plot(TCS_HAM5, label='L1:TCS-ITMX\_HWS\_CHAMBERTEMPERATURESENSORA.mean') #plot TCS_HAM5 #ax1.lines[0].set_color('red') ax1.set_ylim(18,18.6) ax1.set_ylabel('C') ax1.set_title('(HWS) Temperature vs. SRC (4 days)') ax1.legend(loc='upper right', ncol=1, fancybox=True, shadow=True) ax1.grid(True, which='both', axis='both') # add more grid #mj = MultipleLocator(1) ml1 = MultipleLocator(0.1)
""" from gwpy.time import Time from gwpy.timeseries import TimeSeries from gwpy import version __author__ = "Duncan Macleod <*****@*****.**>" __version__ = version.version # set the times start = Time('2010-09-16 06:42:00', format='iso', scale='utc') end = Time('2010-09-16 06:43:00', format='iso', scale='utc') # find the data using NDS data = TimeSeries.fetch('H1:LDAS-STRAIN', start.gps, end.gps, verbose=True) data.unit = 'strain' # calculate spectrogram specgram = data.spectrogram(1) asdspecgram = specgram ** (1/2.) medratio = asdspecgram.ratio('median') # plot plot = medratio.plot() plot.logy = True plot.ylim = [40, 4096] plot.add_colorbar(log=True, clim=[0.1, 10], label='ASD ratio to median average') plot.ylim = [40, 4000] if __name__ == '__main__':
"""Filtering a `TimeSeries` with a ZPK filter Several data streams read from the LIGO detectors are whitened before being recorded to prevent numerical errors when using single-precision data storage. In this example we read such `channel <gwpy.detector.Channel>` and undo the whitening to show the physical content of these data. """ __author__ = "Duncan Macleod <*****@*****.**>" __currentmodule__ = 'gwpy.timeseries' # First, we import the `TimeSeries` and `~TimeSeries.fetch` the data: from gwpy.timeseries import TimeSeries white = TimeSeries.fetch( 'L1:OAF-CAL_DARM_DQ', 'March 2 2015 12:00', 'March 2 2015 12:30') # Now, we can re-calibrate these data into displacement units by first applying # a `highpass <TimeSeries.highpass>` filter to remove the low-frequency noise, # and then applying our de-whitening filter in `ZPK <TimeSeries.zpk>` format # with five zeros at 100 Hz and five poles at 1 Hz (giving an overall DC # gain of 10 :sup:`-10`: hp = white.highpass(4) displacement = hp.zpk([100]*5, [1]*5, 1e-10) # We can visualise the impact of the whitening by calculating the ASD # `~gwpy.spectrum.Spectrum` before and after the filter, whiteasd = white.asd(8, 4) dispasd = displacement.asd(8, 4)
def coherence( gw_channel, ifo, sensor_time_series, t_start, t_end, FFT_time, overlap_time, cohere_plot, thresh1, thresh2, path, ts ): """ Coherence between DARM signal and sensor signal. Notifies user if a certain amount of the data exhibits poor coherence. This coherence data will be reported in the csv output file. Parameters ---------- gw_channel : str Either 'strain_channel' or 'deltal_channel'. ifo : str Interferometer name, 'H1' or 'L1'. sensor_time_series : list Sensor TimeSeries objects. t_start : float, int Start time of time series segment. t_end : float, int End time of time series segment. FFT_time : Length (seconds) of FFT averaging windows. overlap_time : float, int Overlap time (seconds) of FFT averaging windows. cohere_plot : bool If True, save coherence plot to path. thresh1 : float, int Coherence threshold. Used only for notifications. thresh2 : float, int Threshold for how much of coherence data falls below thresh1. Used only for notifications. path : str Output directory ts : time.time object Time stamp of main routine; important for output plots and directory name. Returns ------- coherence_dict : dict Dictionary of channel names and coherences (gwpy FrequencySeries object). """ if type(sensor_TS) != list: sensor_TS = [sensor_TS] ts1 = time.time() thresh_single = thresh1*(1e-2) coherence_dict = {} for i, sensor_timeseries in enumerate(sensor_TS): # COMPUTE COHERENCE if cal_from == 'strain_channel': darm = TimeSeries.fetch(interfer+':GDS-CALIB_STRAIN', iT, fT) elif cal_from == 'deltal_channel': darm = TimeSeries.fetch(interfer+':CAL-DELTAL_EXTERNAL_DQ', iT, fT) coherence = sensor_timeseries.coherence(darm, FFT_t, overlap) coherences = np.asarray(coherence.value) freqs = np.asarray(coherence.frequencies.value) coherence_dict[x.name] = coherences # Save to output dictionary # PLOT COHERENCE DATA if cohere_plot: # Create plot ax = plt.subplot(111) plt.plot(freqs, coherences, '-', color = 'b') plt.ylabel('Coherence') plt.xlabel('Frequency [Hz]') plt.ylim([0, 1]) plt.xlim([10, max(freqs)]) ax.set_xscale('log', nonposx = 'clip') ax.autoscale(False) plt.grid(b=True, which='major',color='0.75',linestyle=':',zorder = 1) plt.minorticks_on() plt.grid(b=True, which='minor',color='0.65',linestyle=':', zorder = 1) plt.title(sensor_timeseries.name[7:].replace('_DQ','') + ' and ' + darm.name[7:].replace('_DQ','')) plt.suptitle(datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S'), fontsize = 10) # Export plot if path is None: path = datetime.datetime.fromtimestamp(ts).strftime('DATA_%Y-%m-%d_%H:%M:%S') if not os.path.exists(path): os.makedirs(path) path = path + '/' + sensor_timeseries.name[7:].replace('_DQ', '') + '_coherence_plot' plt.savefig(path) plt.close() # COHERENCE REPORT # Reports coherence results if overall coherence falls below threshold pts_above_threshold = np.count_nonzero(coherences > thresh_single) # How many points are above thresh1% pts_total = float(len(coherences)) percent_above_threshold = (pts_above_threshold / pts_total) * (10**2) if percent_above_threshold < thresh2: print('\n') print('Less than {:.1f}% of {} data has a coherence of {:.1f}% or greater.'.format(thresh2, sensor_timeseries.name, thresh1)) print('Only {:.3f}% of the data fit this criteria.'.format(percent_cohere)) else: print('\n') print('Coherence thresholds passed for channel {}.'.format(sensor_timeseries.name)) ts2 = time.time() - ts1 print('Coherence(s) calculated. (Runtime: {:.3f} s)'.format(ts2)) return coherence_dict
from gwpy.timeseries import TimeSeries gwdata = TimeSeries.fetch('H1:LDAS-STRAIN', 968654552, 968654562) plot = gwdata.plot() plot.set_ylabel('Gravitational-wave strain amplitude') plot.show()
from gwpy.timeseries import TimeSeries data = TimeSeries.fetch('H1:LDAS-STRAIN', 968654552, 968654562) plot = data.plot() plot.show()
#sio.savemat(funame, mdict={'data': vdata, 't_start': t_start}, # do_compression=True) #print("Data saved as " + funame) chan_head = ifo + ':' + 'ISI-' + 'GND_STS' + '_' sensors = ['ETMX', 'ETMY', 'ITMY'] dofs = ['X', 'Y', 'Z'] bands = ['30M_100M', '100M_300M', '300M_1', '1_3', '3_10', '10_30'] channels = [] for sensor in sensors: for dof in dofs: for band in bands: channel = chan_head + sensor + '_' + dof + '_BLRMS_' + band + '.mean, m-trend' channels.append(channel) data = np.array([]) data = TimeSeries.fetch(channels[0], t_start, t_start + dur) for i in channels[1:]: print('Fetching ' + i) add = TimeSeries.fetch(i, t_start, t_start + dur) data = np.vstack((data, add)) print('Fetched ' + i) funame = ifo + '_Months_data.mat' sio.savemat(funame, mdict={ 'data': vdata, 't_start': t_start }, do_compression=True)
from gwpy.timeseries import TimeSeries llo = TimeSeries.fetch('L1:LDAS-STRAIN,rds', 'August 1 2010', 'August 1 2010 00:10') variance = llo.spectral_variance(10, fftlength=1, log=True, low=1e-24, high=1e-19, nbins=100) plot = variance.plot(norm='log', vmin=0.5, vmax=100) ax = plot.gca() ax.grid() ax.set_xlim(40, 4096) ax.set_ylim(1e-24, 1e-19) ax.set_xlabel('Frequency [Hz]') ax.set_ylabel(r'GW ASD [strain/\rtHz]') ax.set_title('LIGO Livingston Observatory sensitivity variance') plot.save('variance.png') #commonto!
from gwpy.time import Time from gwpy.timeseries import TimeSeries from matplotlib.ticker import MultipleLocator, FormatStrFormatter start = Time('2014-11-27 21:00:00', format='iso', scale='utc') end = Time('2014-12-01 21:00:00', format='iso', scale='utc') print start.iso, start.gps print end.iso, end.gps FMC = TimeSeries.fetch('L0:FMC-CS_LVEA_ZONE1_TP2.mean,m-trend', start, end, verbose=True) #closest to ITMX and HAM4 HWS = TimeSeries.fetch('L1:TCS-ITMY_HWS_CHAMBERTEMPERATURESENSORB.mean,m-trend', start, end, verbose=True) #HAM4 RH = TimeSeries.fetch('L1:TCS-ITMX_RH_LOWERRTD.mean,m-trend', start, end, verbose=True) #assume that ITMX means ITMX print "data-fetched" FMC_C = (FMC-32)*(5.0/9) plot = FMC_C.plot() ax = plot.gca() ax.plot(HWS, label='L1:TCS-ITMY\_HWS\_CHAMBERTEMPERATURESENSORB.mean') ax.plot(RH, label = 'L1:TCS-ITMX\_RH\_LOWERRTD.mean') #ax.set_ylim() ax.legend(loc='upper right', ncol=1, fancybox=True, shadow=True) print ' plotting' plot.show()
from gwpy.timeseries import TimeSeries gwdata = TimeSeries.fetch('H1:LDAS-STRAIN', 'September 16 2010 06:40', 'September 16 2010 06:50') specgram = gwdata.spectrogram(20, fftlength=8, overlap=4)**(1 / 2.) plot = specgram.plot(norm='log', vmin=1e-23, vmax=1e-19) ax = plot.gca() ax.set_ylim(40, 4000) ax.set_yscale('log') plot.add_colorbar(label='GW strain ASD [strain/$\sqrt{\mathrm{Hz}}$]') plot.show()
""" from gwpy.timeseries import TimeSeries from gwpy import version __author__ = "Duncan Macleod <*****@*****.**>" __version__ = version.version # set the times goodtime = 1061800700 badtime = 1061524816 duration = 120 # read the data over the network gooddata = TimeSeries.fetch('L1:PSL-ISS_PDB_OUT_DQ', goodtime, goodtime + duration) gooddata.name = 'Clean data' baddata = TimeSeries.fetch('L1:PSL-ISS_PDB_OUT_DQ', badtime, badtime + duration) baddata.name = 'Noisy data' # calculate spectrum with 1/8 Hz resolution goodasd = gooddata.asd(4, 2) badasd = baddata.asd(4, 2) # plot plot = badasd.plot() ax = plot.gca() ax.plot(goodasd) ax.set_xlim(10, 8000) ax.set_ylim(1e-6, 5e-4)
def getTimeSeries(self, arg_list): """Verify and interpret arguments to get all TimeSeries objects defined""" # retrieve channel data from NDS as a TimeSeries for chans in arg_list.chan: for chan in chans: if chan not in self.chan_list: self.chan_list.append(chan) if len(self.chan_list) < self.min_timeseries: raise ArgumentError( 'A minimum of %d channels must be specified for this product' % self.min_timeseries) if len(arg_list.start) > 0: self.start_list = list(set(map(int, arg_list.start))) else: raise ArgumentError('No start times specified') # Verify the number of datasets specified is valid for this plot self.n_datasets = len(self.chan_list) * len(self.start_list) if self.n_datasets < self.get_min_datasets(): raise ArgumentError( '%d datasets are required for this plot but only %d are ' 'supplied' % (self.get_min_datasets(), self.n_datasets)) if self.n_datasets > self.get_max_datasets(): raise ArgumentError( 'A maximum of %d datasets allowed for this plot but %d ' 'specified' % (self.get_max_datasets(), self.n_datasets)) if arg_list.duration: self.dur = int(arg_list.duration) else: self.dur = 10 verb = self.verbose > 1 # determine how we're supposed get our data source = 'NDS2' frame_cache = False if arg_list.framecache: source = 'frames' frame_cache = arg_list.framecache # set up filter parameters for all channels highpass = 0 if arg_list.highpass: highpass = float(arg_list.highpass) self.filter += "highpass(%.1f) " % highpass # Get the data from NDS or Frames # time_groups is a list of timeseries index grouped by # start time for coherence like plots self.time_groups = [] for start in self.start_list: time_group = [] for chan in self.chan_list: if verb: print 'Fetching %s %d, %d using %s' % \ (chan, start, self.dur, source) if frame_cache: data = TimeSeries.read(frame_cache, chan, start=start, end=start+self.dur) else: data = TimeSeries.fetch(chan, start, start+self.dur, verbose=verb) if highpass > 0: data = data.highpass(highpass) self.timeseries.append(data) time_group.append(len(self.timeseries)-1) self.time_groups.append(time_group) # report what we have if they asked for it self.log(3, ('Channels: %s' % self.chan_list)) self.log(3, ('Start times: %s, duration' % self.start_list, self.dur)) self.log(3, ('Number of time series: %d' % len(self.timeseries))) if len(self.timeseries) != self.n_datasets: self.log(0, ('%d datasets requested but only %d transfered' % (self.n_datasets, len(self.timeseries)))) if len(self.timeseries) > self.get_min_datasets(): self.log(0, 'Proceeding with the data that was transferred.') else: self.log(0, 'Not enough data for requested plot.') sys.exit(2) return
from gwpy.plot import Plot ''' Fetch seismometer data from nds. ''' # - data1 ----------------------------- start = '2019 May 13 00:00:00 JST' end = '2019 May 13 04:00:00 JST' chname = 'K1:PEM-SEIS_EXV_GND_X_OUT_DQ' # ------------------------------------- # fetch data data = TimeSeries.fetch(chname, start, end, host='k1nds0', port=8088, verbose=True) print('fetch done') # calc spectrum fftlength = 2**9 sg = data.spectrogram2(fftlength=fftlength, overlap=fftlength / 2, nproc=2, window='hanning')**(1 / 2.) print('fft done') # percentile median = sg.percentile(50) low = sg.percentile(5) high = sg.percentile(95)
from matplotlib.ticker import MultipleLocator, FormatStrFormatter from gwpy.time import Time from gwpy.timeseries import (TimeSeries, TimeSeriesDict) print "Import Modules Success" #Start-End Time start = Time('2014-06-29 00:00:00', format='iso', scale='utc') end = Time('2014-07-02 00:00:00', format='iso', scale='utc') print start.iso, start.gps print end.iso, end.gps data1 = TimeSeries.fetch('L1:SUS-ITMX_M0_DAMP_V_IN1_DQ.mean,m-trend', start, end, verbose=True) data2 = TimeSeries.fetch('L1:SUS-ITMY_M0_DAMP_V_IN1_DQ.mean,m-trend', start, end, verbose=True) plot_SUS = data1.plot() ax = plot_SUS.gca() ax.plot(data2, label = 'L1:SUS-ITMY\_M0\_DAMP\_V\_IN1\_DQ.mean') #plot_data.show() ax.set_epoch(start.gps) ax.set_xlim(start.gps, end.gps) ax.set_ylabel('Amplitude (um)') ax.set_title('SUS CS Vertical Position trends') #ax.set_ylim([-1,1]) ax.legend(loc='lower left', ncol=1, fancybox=True, shadow=True) plot_SUS.save('SUS-CS-Vertical-3days.png') print "PLOT SAVED"
from gwpy.time import Time from gwpy.timeseries import TimeSeries from gwpy.plotter import TimeSeriesPlot from matplotlib.ticker import MultipleLocator, FormatStrFormatter start = Time('2014-11-27 21:00:00', format='iso', scale='utc') end = Time('2014-12-01 21:00:00', format='iso', scale='utc') print start.iso, start.gps print end.iso, end.gps FMC = TimeSeries.fetch('L0:FMC-CS_LVEA_AVTEMP.mean,m-trend', start, end, verbose=True) TCS_HAM4 = TimeSeries.fetch('L1:TCS-ITMY_HWS_CHAMBERTEMPERATURESENSORA.mean,m-trend', start, end, verbose=True) TCS_HAM5 = TimeSeries.fetch('L1:TCS-ITMX_HWS_CHAMBERTEMPERATURESENSORA.mean,m-trend', start, end, verbose=True) RH_ITMY = TimeSeries.fetch('L1:TCS-ITMY_RH_LOWERRTD.mean,m-trend', start, end, verbose=True) #ITMY = TimeSeries.fetch('L1:SUS-ITMY_M0_DAMP_V_IN1_DQ.mean,m-trend', start, end, verbose=True) print "data fetched" FMC_C = (FMC-32)*(5.0/9) plot = TimeSeriesPlot(FMC_C, TCS_HAM4, sep=True) ax1 = plot.axes[0] ax1.lines[0].set_color('red') ax1.set_ylim(17.5,19.1) ax1.set_ylabel('C') ax1.set_title('Temperature (4 days)') ax1.legend(loc='upper right', ncol=1, fancybox=True, shadow=True) ax1.grid(True, which='both', axis='both') # add more grid #mj = MultipleLocator(1) ml1 = MultipleLocator(0.1) #ax1.yaxis.set_major_locator(mj)
""" from gwpy.time import Time, TimeDelta from gwpy.timeseries import TimeSeries from gwpy import version __author__ = "Duncan Macleod <*****@*****.**>" __version__ = version.version # set the times goodtime = 1061800700 badtime = 1061524816 duration = 120 # read the data over the network gooddata = TimeSeries.fetch('L1:PSL-ISS_PDB_OUT_DQ', goodtime, goodtime+duration, verbose=True) baddata = TimeSeries.fetch('L1:PSL-ISS_PDB_OUT_DQ', badtime, badtime+duration, verbose=True) # calculate spectrum with 1.8 Hz resolution goodasd = gooddata.asd(8, 4, 'welch') badasd = baddata.asd(8, 4, 'welch') # plot plot = badasd.plot() plot.add_spectrum(goodasd) plot.xlim = [10, 8000] plot.ylim = [1e-6, 5e-4] if __name__ == '__main__': try:
ifo = "L1" f_cal = {"L1": 33.7, "H1": 37.3}[ifo] pad = 8 st = int(sys.argv[1]) - pad dur = 2 * pad darm_chan = ifo + ":LSC-DARM_OUT_DQ" sus_chan = ifo + ":SUS-ETMY_L3_ISCINF_L_IN1_DQ" inj_chan = ifo + ":CAL-INJ_HARDWARE_OUT_DQ" # Modify these to diagnose NDS2 problems nds_kwargs = {} # {'verbose':True, 'host':'nds.ligo.caltech.edu' print "Fetching DARM" darm = TimeSeries.fetch(darm_chan, st, st + dur + 1, **nds_kwargs) print "Fetching ISCINF" sus = TimeSeries.fetch(sus_chan, st, st + dur + 1, **nds_kwargs) print "Fetching INJ" inj = TimeSeries.fetch(inj_chan, st, st + dur + 1, **nds_kwargs) # Sample rates all the same assert sus.sample_rate.value == darm.sample_rate.value assert inj.sample_rate.value == darm.sample_rate.value srate = int(darm.sample_rate.value) # Hardware inj channel delayed two samples getting to EY SUS # DARM delayed one sample # Probably because inj goes from CAL->LSC->SUSEY and DARM just LSC->SUSEY inj = inj[:-srate] darm = darm[1 : -srate + 1]
#This program plots ISI_ITMX CPS spectrum around 1099109374.275391 (Nov 3 2014 20:08:51 PST/Nov 4 2014 04:08:51) #Before trips 253-373 #After trips 374-494 from gwpy.timeseries import TimeSeries from matplotlib.ticker import MultipleLocator, FormatStrFormatter print "Import Module Success" H1CPS = TimeSeries.fetch('H1:ISI-ITMX_ST1_CPSINF_H1_IN1_DQ', 1099109347.275391, 1099109347.575391) H2CPS = TimeSeries.fetch('H1:ISI-ITMX_ST1_CPSINF_H2_IN1_DQ', 1099109347.275391, 1099109347.575391) V1CPS = TimeSeries.fetch('H1:ISI-ITMX_ST1_CPSINF_V1_IN1_DQ', 1099109347.275391, 1099109347.575391) V2CPS = TimeSeries.fetch('H1:ISI-ITMX_ST1_CPSINF_V2_IN1_DQ', 1099109347.275391, 1099109347.575391) print "Data Fetched" plot_H1 = H1CPS.plot() ax = plot_H1.gca() ax.plot(H2CPS, label='H1:ISI-ITMX\_ST1\_CPSINF\_H2\_IN1\_DQ') ax.plot(V1CPS, label='H1:ISI-ITMX\_ST1\_CPSINF\_V1\_IN1\_DQ') ax.plot(V2CPS, label='H1:ISI-ITMX\_ST1\_CPSINF\_V2\_IN1\_DQ') ax.set_ylim(-25000,10000) mj = MultipleLocator(2000) ml1 = MultipleLocator(50) ml2 = MultipleLocator(1000) ax.yaxis.set_major_locator(mj) ax.yaxis.set_minor_locator(ml2) ax.xaxis.set_minor_locator(ml1) L = ax.legend(loc='upper right', ncol=1, fancybox=True, shadow=True)
ifo = 'L1' f_cal = {'L1': 33.7, 'H1': 37.3}[ifo] pad = 8 st = int(sys.argv[1]) - pad dur = 2 * pad darm_chan = ifo + ":LSC-DARM_OUT_DQ" sus_chan = ifo + ":SUS-ETMY_L3_ISCINF_L_IN1_DQ" inj_chan = ifo + ":CAL-INJ_HARDWARE_OUT_DQ" # Modify these to diagnose NDS2 problems nds_kwargs = {} # {'verbose':True, 'host':'nds.ligo.caltech.edu' print "Fetching DARM" darm = TimeSeries.fetch(darm_chan, st, st + dur + 1, **nds_kwargs) print "Fetching ISCINF" sus = TimeSeries.fetch(sus_chan, st, st + dur + 1, **nds_kwargs) print "Fetching INJ" inj = TimeSeries.fetch(inj_chan, st, st + dur + 1, **nds_kwargs) # Sample rates all the same assert (sus.sample_rate.value == darm.sample_rate.value) assert (inj.sample_rate.value == darm.sample_rate.value) srate = int(darm.sample_rate.value) # Hardware inj channel delayed two samples getting to EY SUS # DARM delayed one sample # Probably because inj goes from CAL->LSC->SUSEY and DARM just LSC->SUSEY inj = inj[:-srate] darm = darm[1:-srate + 1]
from gwpy.time import Time from gwpy.timeseries import TimeSeries from matplotlib.ticker import MultipleLocator, FormatStrFormatter start = Time('2014-11-27 20:00:00', format='iso', scale='utc') end = Time('2014-11-28 20:00:00', format='iso', scale='utc') print start.iso, start.gps print end.iso, end.gps FMC = TimeSeries.fetch('L0:FMC-CS_LVEA_ZONE1_TP4', start, end, verbose=True) TCS = TimeSeries.fetch('L1:TCS-ITMY_HWS_CHAMBERTEMPERATURESENSORA', start, end, verbose=True) print 'data fetched' FMC_C = (FMC-32)*(5.0/9) FMC_asd = FMC.asd(1000,500) TCS_asd = TCS.asd(1000,500) ratio = FMC_asd/TCS_asd ratio_plot = ratio.plot(color = 'black', label = 'FMC asd/TCS asd') ax = ratio_plot.gca() ax.plot(FMC_asd, label = 'FMC-CS\_LVEA\_ZONE1\_TP4') ax.plot(TCS_asd, label = 'L1:TCS-ITMY\_HWS\_CHAMBERTEMPERATURESENSORA') ax.legend(loc='upper right', ncol=1, fancybox=True, shadow=True) ax.set_xlabel('Frequency (Hz)') ax.set_ylabel('Amplitude [ ]') ax.set_title('1000 FFT') ratio_plot.show()
I'm interested in the level of ground motion surrounding a particular time during commissioning of the Advanced LIGO Livingston Observatory. I don't have access to the frame files on disk, so I'll need to use NDS. """ from gwpy.time import tconvert from gwpy.timeseries import TimeSeries from gwpy import version __author__ = "Duncan Macleod <*****@*****.**>" __version__ = version.version # read the data over the network lho = TimeSeries.fetch('H1:LDAS-STRAIN', 'August 1 2010', 'August 1 2010 00:02') lho.unit = 'strain' #llo = TimeSeries.fetch('L1:LDAS-STRAIN', start.gps, end.gps, verbose=True) #llo.unit = 'strain' # calculate spectrum with 0.5Hz resolution lhoasd = lho.asd(2, 1) #lloasd = llo.asd(2, 1) # plot plot = lhoasd.plot(color='b', label='LHO') #plot.add_spectrum(lloasd, color='g', label='LLO') plot.xlim = [40, 4096] plot.ylim = [1e-23, 7.5e-21] # hide some axes
from matplotlib.ticker import MultipleLocator, FormatStrFormatter from gwpy.time import Time from gwpy.timeseries import (TimeSeries, TimeSeriesDict) print "Import Modules Success" #Start-End Time start = Time('2014-06-11 21:00:00', format='iso', scale='utc') end = Time('2014-06-15 07:36:00', format='iso', scale='utc') print start.iso, start.gps print end.iso, end.gps data = TimeSeries.fetch('L1:ALS-C_TRX_A_LF_OUT_DQ.mean,m-trend', start, end, verbose=True) plot_data = data.plot() ax = plot_data.gca() #plot_data.show() ax.set_epoch(start.gps) ax.set_xlim(start.gps, end.gps) ax.set_ylabel('Counts') ax.set_title(data.channel.texname) #ax.set_ylim([15000,25000]) plot_data.save('L1-ALS-C_TRX_A_LF_OUT_DQ_HEPI-ON.png') print "PLOT SAVED" # Channel List # L1:ALS-C_TRY_A_LF_OUT_DQ - Green Laser Y
# Slide through the data fitting PSL to IMC for data around each sample coeffs = [] for idx in xrange(maxidx): idx1 = max(0, idx - width) idx2 = min(idx + width, maxidx) coeffs.append( polyfit(data[idx1:idx2, 0], data[idx1:idx2, 1], 1, w=weights[idx1 - idx + width:idx2 - idx + width])) coeffs = array(coeffs) times = arange(len(coeffs)) + 0.5 imc = TimeSeries.fetch("%s:IMC-F_OUT_256_DQ" % ifo, st, et, host='nds2.ligo-wa.caltech.edu') samp_times = arange(len(imc)) / float(imc.sample_rate.value) coeffs0 = interp(samp_times, times, coeffs[:, 0]) coeffs1 = interp(samp_times, times, coeffs[:, 1]) - 7.6e7 vco_interp = coeffs0 * imc + coeffs1 chan = "%s:IMC-VCO_PREDICTION" % (ifo, ) vco_data = TimeSeries(vco_interp, epoch=st, sample_rate=imc.sample_rate.value, name=chan, channel=chan) vco_data.write("%s-vcoprediction-%u-%u.hdf" % (ifo, st, dur), format='hdf')
from matplotlib.ticker import MultipleLocator, FormatStrFormatter from gwpy.time import Time from gwpy.timeseries import (TimeSeries, TimeSeriesDict) print "Import Modules Success" #Start-End Time start = Time('2014-06-29 00:00:00', format='iso', scale='utc') end = Time('2014-07-02 00:00:00', format='iso', scale='utc') print start.iso, start.gps print end.iso, end.gps data1 = TimeSeries.fetch('L0:FMC-EY_VEA_202A_TEMP.mean,m-trend', start, end, verbose=True) data2 = TimeSeries.fetch('L0:FMC-EY_VEA_202B_TEMP.mean,m-trend', start, end, verbose=True) data3 = TimeSeries.fetch('L0:FMC-EY_VEA_202C_TEMP.mean,m-trend', start, end, verbose=True) data4 = TimeSeries.fetch('L0:FMC-EY_VEA_202D_TEMP.mean,m-trend', start, end, verbose=True) data5 = TimeSeries.fetch('L0:FMC-EY_VEA_202_AVTEMP.mean,m-trend', start, end, verbose=True) #data6 = TimeSeries.fetch('L0:FMC-EX_VEA_AVTEMP.mean,m-trend', start, end, verbose=True) plot_TEMP = data1.plot() ax = plot_TEMP.gca() ax.plot(data2, label = 'L0:FMC-EY\_VEA\_202B\_AVTEMP.mean') ax.plot(data3, label = 'L0:FMC-EY\_VEA\_202C\_AVTEMP.mean') ax.plot(data4, label = 'L0:FMC-EY\_VEA\_202D\_AVTEMP.mean') ax.plot(data5, label = 'L0:FMC-EY\_VEA\_AVTEMP.mean') #ax.plot(data6, label = 'L0:FMC-EX\_VEA\_AVTEMP.mean') ax.set_epoch(start.gps) ax.set_xlim(start.gps, end.gps) ax.set_ylabel('Temperature (F)')
#! /usr/bin/env python from gwpy.timeseries import TimeSeries from numpy import * import sys ifo = sys.argv[1] chan = ifo + ":GDS-CALIB_STRAIN" st = int(sys.argv[2]) dur = 2048 fmin, fmax = 30., 1024. chunk, step = 64, 16 fftlen, overlap = 16, 8 data = TimeSeries.fetch(chan, st, st + dur, verbose=True) srate = data.sample_rate.value psd_est = data.psd(fftlen, overlap, method='median').value psd_est[0] = 1. inv_psd_est = 1. / psd_est inv_psd_est[0] = 0. df = 1. / float(fftlen) freqs = df * arange(len(inv_psd_est)) freqs[0] = 1.e-6 integrand = freqs**(-7. / 3.) * inv_psd_est integrand[:int(fmin / df)] = 0. integrand[int(fmax / df):] = 0.
def getTimeSeries(self, arg_list): """Verify and interpret arguments to get all TimeSeries objects defined""" # retrieve channel data from NDS as a TimeSeries for chans in arg_list.chan: for chan in chans: if chan not in self.chan_list: self.chan_list.append(chan) if len(self.chan_list) < self.min_timeseries: raise ArgumentError('A minimum of %d channels must be ' + 'specified for this product' % self.min_timeseries) if len(arg_list.start) > 0: for start_arg in arg_list.start: if type(start_arg) is list: for starts in start_arg: if isinstance(starts, basestring): starti = int(starts) elif starts is list: for start_str in starts: starti = int(start_str) # ignore duplicates (to make it easy for ldvw) if starti not in self.start_list: self.start_list.append(starti) else: self.start_list.append(int(start_arg)) else: raise ArgumentError('No start times specified') # Verify the number of datasets specified is valid for this plot self.n_datasets = len(self.chan_list) * len(self.start_list) if self.n_datasets < self.get_min_datasets(): raise ArgumentError('%d datasets are required for this ' + 'plot but only %d are supplied' % (self.get_min_datasets(), self.n_datasets)) if self.n_datasets > self.get_max_datasets(): raise ArgumentError('A maximum of %d datasets allowed for ' + 'this plot but %d specified' % (self.get_max_datasets(), self.n_datasets)) if arg_list.duration: self.dur = int(arg_list.duration) else: self.dur = 10 verb = self.verbose > 1 # determine how we're supposed get our data source = 'NDS2' frame_cache = False if arg_list.framecache: source = 'frames' frame_cache = arg_list.framecache # set up filter parameters for all channels highpass = 0 if arg_list.highpass: highpass = float(arg_list.highpass) self.filter += "highpass(%.1f) " % highpass # Get the data from NDS or Frames # time_groups is a list of timeseries index grouped by # start time for coherence like plots self.time_groups = [] for start in self.start_list: time_group = [] for chan in self.chan_list: if verb: print 'Fetching %s %d, %d using %s' % \ (chan, start, self.dur, source) if frame_cache: data = TimeSeries.read(frame_cache, chan, start=start, end=start+self.dur) else: data = TimeSeries.fetch(chan, start, start+self.dur, verbose=verb) if highpass > 0: data = data.highpass(highpass) self.timeseries.append(data) time_group.append(len(self.timeseries)-1) self.time_groups.append(time_group) # report what we have if they asked for it self.log(3, ('Channels: %s' % self.chan_list)) self.log(3, ('Start times: %s, duration' % self.start_list, self.dur)) self.log(3, ('Number of time series: %d' % len(self.timeseries))) if len(self.timeseries) != self.n_datasets: self.log(0, ('%d datasets requested but only %d transfered' % (self.n_datasets, len(self.timeseries)))) if len(self.timeseries) > self.get_min_datasets(): self.log(0, 'Proceeding with the data that was transferred.') else: self.log(0, 'Not enough data for requested plot.') from sys import exit exit(2) return
help= 'GPS start time or datetime of analysis. Default: 5 minutes prior to current time' ) parser.add_argument( '--duration', type=int, default=60, required=False, help='Duration of of analysis in seconds. Default: 60 seconds') args = parser.parse_args() gpsend = args.gpsstart + args.duration #Timeseries Data TS = TimeSeries.fetch(channel, args.gpsstart, gpsend) specgram = TS.spectrogram(2, fftlength=1, overlap=.5)**(1 / 2.) normalised = specgram.ratio('median') #Plot QSpectrogram qspecgram = TS.q_transform(qrange=(4, 150), frange=(10, 100), outseg=(args.gpsstart, gpsend), fres=.01) plot = qspecgram.imshow(figsize=[8, 4]) cmap = cm.get_cmap('viridis') ax = plot.gca() ax.set_title('Q Transform') ax.set_xscale('seconds') ax.set_yscale('log') ax.set_ylim(10, 100)
### Set the channel that witnesses fringes (to plot specgram for) witness_base = "GDS-CALIB_STRAIN" #witness_base = "LSC-MICH_IN1_DQ" #witness_base = '%s:ASC-Y_TR_A_NSUM_OUT_DQ' % ifo #witness_base = 'LSC-SRCL_IN1_DQ' #witness_base = "LSC-REFL_A_RF9_Q_ERR_DQ" #witness_base = "ASC-AS_A_RF45_Q_PIT_OUT_DQ" #witness_base = "ASC-AS_B_RF36_Q_PIT_OUT_DQ" #witness_base = "OMC-LSC_SERVO_OUT_DQ" if plotspec==1: witness_chan = ifo + ':' + witness_base print witness_chan # load timeseries for witness channel witness=TimeSeries.fetch(witness_chan, start_time, start_time+dur, verbose=True) if witness_base=="GDS-CALIB_STRAIN": witness=witness.highpass(20,gpass=3) # highpass the witness data elif witness_base=="ASC-AS_B_RF45_I_PIT_OUT_DQ" or witness_base=="ASC-AS_B_RF36_Q_PIT_OUT_DQ" or witness_base=="LSC-MICH_IN1_DQ" or witness_base=="ASC-AS_A_RF45_Q_PIT_OUT_DQ": witness=witness.highpass(10,gpass=3) # highpass the witness data # Calculate DARM spectrogram secsPerFFT = .75 # Hz overlap = 0.9 # fractional overlap Fs = witness.sample_rate.value NFFT = int(round(Fs*secsPerFFT)) noverlap = int(round(overlap*NFFT)) Pxx, freq, t, im = specgram(witness.value,NFFT=NFFT,Fs=witness.sample_rate.value,noverlap=noverlap,scale_by_freq='magnitude',detrend=mlab.detrend_linear,window=mlab.window_hanning) ### Known SUS displacement w/r/t sus frame channels (in microns) position_chans = [\ 'SUS-BS_M1_DAMP_L_IN1_DQ',\
#darmbase = ':OMC-DCPD_SUM_OUT_DQ' darmbase = ':GDS-CALIB_STRAIN' darmchan = ifo + darmbase rangechan = ifo + ':DMT-SNSH_EFFECTIVE_RANGE_MPC.mean' fnm = 'FMCLVE_channels.txt' # load channel names from text file # Note: to generate this file, ran: nds_query -l -n nds.ligo-la.caltech.edu -t raw LVE-* > LVE_channels.txt lines = loadtxt(fnm, dtype='str', usecols=[0],skiprows=2) # get BNS range data #if dur>=60*60: #else: range=TimeSeries.fetch(rangechan, start_time, start_time+dur, verbose=True,host='nds.ligo.caltech.edu') trange = arange(0.0,len(range.value))/range.sample_rate.value # Get DARM data darm=TimeSeries.fetch(darmchan, start_time-filter_pad, start_time+dur, verbose=True,host='nds.ligo.caltech.edu') darm=darm.detrend() darm=darm.highpass(20) # build notch filter for 60Hz line Norder=2 zpk = iirfilter(Norder, [59.8/(darm.sample_rate.value/2.0), 60.2/(darm.sample_rate.value/2.0)], btype='bandstop', ftype='butter', output='zpk') darm = darm.filter(*zpk) # Calculate DARM BLRMS stride=30 # seconds flower=75 # Hz fupper=95 # Hz
def getTimeSeries(self, arg_list): """Verify and interpret arguments to get all TimeSeries objects defined""" # retrieve channel data from NDS as a TimeSeries for chans in arg_list.chan: for chan in chans: if chan not in self.chan_list: self.chan_list.append(chan) if len(self.chan_list) < self.min_timeseries: raise ArgumentError("A minimum of %d channels must be specified for this product" % self.min_timeseries) if len(arg_list.start) > 0: self.start_list = list(set(map(int, arg_list.start))) else: raise ArgumentError("No start times specified") # Verify the number of datasets specified is valid for this plot self.n_datasets = len(self.chan_list) * len(self.start_list) if self.n_datasets < self.get_min_datasets(): raise ArgumentError( "%d datasets are required for this plot but only %d are " "supplied" % (self.get_min_datasets(), self.n_datasets) ) if self.n_datasets > self.get_max_datasets(): raise ArgumentError( "A maximum of %d datasets allowed for this plot but %d " "specified" % (self.get_max_datasets(), self.n_datasets) ) if arg_list.duration: self.dur = int(arg_list.duration) else: self.dur = 10 verb = self.verbose > 1 # determine how we're supposed get our data source = "NDS2" frame_cache = False if arg_list.framecache: source = "frames" frame_cache = arg_list.framecache # set up filter parameters for all channels highpass = 0 if arg_list.highpass: highpass = float(arg_list.highpass) self.filter += "highpass(%.1f) " % highpass # Get the data from NDS or Frames # time_groups is a list of timeseries index grouped by # start time for coherence like plots self.time_groups = [] for start in self.start_list: time_group = [] for chan in self.chan_list: if verb: print "Fetching %s %d, %d using %s" % (chan, start, self.dur, source) if frame_cache: data = TimeSeries.read(frame_cache, chan, start=start, end=start + self.dur) else: data = TimeSeries.fetch(chan, start, start + self.dur, verbose=verb) if highpass > 0: data = data.highpass(highpass) self.timeseries.append(data) time_group.append(len(self.timeseries) - 1) self.time_groups.append(time_group) # report what we have if they asked for it self.log(3, ("Channels: %s" % self.chan_list)) self.log(3, ("Start times: %s, duration" % self.start_list, self.dur)) self.log(3, ("Number of time series: %d" % len(self.timeseries))) if len(self.timeseries) != self.n_datasets: self.log(0, ("%d datasets requested but only %d transfered" % (self.n_datasets, len(self.timeseries)))) if len(self.timeseries) > self.get_min_datasets(): self.log(0, "Proceeding with the data that was transferred.") else: self.log(0, "Not enough data for requested plot.") sys.exit(2) return
def main(): # Parse commandline arguments opts = parse_commandline() ########################################################################### # Parse Ini File # ########################################################################### # ---- Create configuration-file-parser object and read parameters file. cp = ConfigParser.ConfigParser() cp.read(opts.inifile) # ---- Read needed variables from [parameters] and [channels] sections. alwaysPlotFlag = cp.getint('parameters', 'alwaysPlotFlag') sampleFrequency = cp.getint('parameters', 'sampleFrequency') blockTime = cp.getint('parameters', 'blockTime') searchFrequencyRange = json.loads( cp.get('parameters', 'searchFrequencyRange')) searchQRange = json.loads(cp.get('parameters', 'searchQRange')) searchMaximumEnergyLoss = cp.getfloat('parameters', 'searchMaximumEnergyLoss') searchWindowDuration = cp.getfloat('parameters', 'searchWindowDuration') whiteNoiseFalseRate = cp.getfloat('parameters', 'whiteNoiseFalseRate') plotTimeRanges = json.loads(cp.get('parameters', 'plotTimeRanges')) plotFrequencyRange = json.loads(cp.get('parameters', 'plotFrequencyRange')) plotNormalizedERange = json.loads( cp.get('parameters', 'plotNormalizedERange')) frameCacheFile = cp.get('channels', 'frameCacheFile') frameTypes = cp.get('channels', 'frameType').split(',') channelNames = cp.get('channels', 'channelName').split(',') detectorName = channelNames[0].split(':')[0] det = detectorName.split('1')[0] ########################################################################### # create output directory # ########################################################################### # if outputDirectory not specified, make one based on center time if opts.outDir is None: outDir = './scans' else: outDir = opts.outDir + '/' outDir += '/' # report status if not os.path.isdir(outDir): if opts.verbose: print('creating event directory') os.makedirs(outDir) if opts.verbose: print('outputDirectory: {0}'.format(outDir)) ######################################################################## # Determine if this is a normal omega scan or a Gravityspy # # omega scan with unique ID. If Gravity spy then additional # # files and what not must be generated # ######################################################################## IDstring = "{0:.2f}".format(opts.eventTime) ########################################################################### # Process Channel Data # ########################################################################### # find closest sample time to event time centerTime = np.floor(opts.eventTime) + np.round( (opts.eventTime - np.floor(opts.eventTime)) * sampleFrequency) / sampleFrequency # determine segment start and stop times startTime = round(centerTime - blockTime / 2) stopTime = startTime + blockTime # This is for ordering the output page by SNR loudestEnergyAll = [] channelNameAll = [] peakFreqAll = [] mostSignQAll = [] for channelName in channelNames: if 'STRAIN' in channelName: frameType = frameTypes[0] else: frameType = frameTypes[1] # Read in the data if opts.NSDF: data = TimeSeries.fetch(channelName, startTime, stopTime) else: connection = datafind.GWDataFindHTTPConnection() cache = connection.find_frame_urls(det, frameType, startTime, stopTime, urltype='file') data = TimeSeries.read(cache, channelName, format='gwf', start=startTime, end=stopTime) # resample data if data.sample_rate.decompose().value != sampleFrequency: data = data.resample(sampleFrequency) # Cropping the results before interpolation to save on time and memory # perform the q-transform try: specsgrams = [] for iTimeWindow in plotTimeRanges: durForPlot = iTimeWindow / 2 try: outseg = Segment(centerTime - durForPlot, centerTime + durForPlot) qScan = data.q_transform(qrange=(4, 64), frange=(10, 2048), gps=centerTime, search=0.5, tres=0.002, fres=0.5, outseg=outseg, whiten=True) qValue = qScan.q qScan = qScan.crop(centerTime - iTimeWindow / 2, centerTime + iTimeWindow / 2) except: outseg = Segment(centerTime - 2 * durForPlot, centerTime + 2 * durForPlot) qScan = data.q_transform(qrange=(4, 64), frange=(10, 2048), gps=centerTime, search=0.5, tres=0.002, fres=0.5, outseg=outseg, whiten=True) qValue = qScan.q qScan = qScan.crop(centerTime - iTimeWindow / 2, centerTime + iTimeWindow / 2) specsgrams.append(qScan) loudestEnergyAll.append(qScan.max().value) peakFreqAll.append(qScan.yindex[np.where( qScan.value == qScan.max().value)[1]].value[0]) mostSignQAll.append(qValue) channelNameAll.append(channelName) except: print('bad channel {0}: skipping qScan'.format(channelName)) continue if opts.make_webpage: # Set some plotting params myfontsize = 15 mylabelfontsize = 20 myColor = 'k' if detectorName == 'H1': title = "Hanford" elif detectorName == 'L1': title = "Livingston" else: title = "VIRGO" if 1161907217 < startTime < 1164499217: title = title + ' - ER10' elif startTime > 1164499217: title = title + ' - O2a' elif 1126400000 < startTime < 1137250000: title = title + ' - O1' else: raise ValueError("Time outside science or engineering run\ or more likely code not updated to reflect\ new science run") # Create one image containing all spectogram grams superFig = Plot(figsize=(27, 6)) superFig.add_subplot(141, projection='timeseries') superFig.add_subplot(142, projection='timeseries') superFig.add_subplot(143, projection='timeseries') superFig.add_subplot(144, projection='timeseries') iN = 0 for iAx, spec in zip(superFig.axes, specsgrams): iAx.plot(spec) iAx.set_yscale('log', basey=2) iAx.set_xscale('linear') xticks = np.linspace(spec.xindex.min().value, spec.xindex.max().value, 5) xticklabels = [] dur = float(plotTimeRanges[iN]) [ xticklabels.append(str(i)) for i in np.linspace(-dur / 2, dur / 2, 5) ] iAx.set_xticks(xticks) iAx.set_xticklabels(xticklabels) iAx.set_xlabel('Time (s)', labelpad=0.1, fontsize=mylabelfontsize, color=myColor) iAx.set_ylim(10, 2048) iAx.yaxis.set_major_formatter(ScalarFormatter()) iAx.ticklabel_format(axis='y', style='plain') iN = iN + 1 superFig.add_colorbar(ax=iAx, cmap='viridis', label='Normalized energy', clim=plotNormalizedERange, pad="3%", width="5%") superFig.suptitle(title, fontsize=mylabelfontsize, color=myColor, x=0.51) superFig.save(outDir + channelName.replace(':', '-') + '_' + IDstring + '_spectrogram_' + '.png') if opts.make_webpage: channelNameAll = [i.replace(':', '-') for i in channelNameAll] loudestEnergyAll = [str(i) for i in loudestEnergyAll] peakFreqAll = [str(i) for i in peakFreqAll] mostSignQAll = [str(i) for i in mostSignQAll] # Zip SNR with channelName loudestEnergyAll = dict(zip(channelNameAll, loudestEnergyAll)) peakFreqAll = dict(zip(channelNameAll, peakFreqAll)) mostSignQAll = dict(zip(channelNameAll, mostSignQAll)) plots = glob.glob(outDir + '*.png'.format(channelName)) plots = [i.split('/')[-1] for i in plots] channelPlots = dict(zip(channelNameAll, plots)) f1 = open(outDir + 'index.html', 'w') env = Environment(loader=FileSystemLoader('../')) template = env.get_template('webpage/omegatemplate.html') print >> f1, template.render(channelNames=channelNameAll, SNR=loudestEnergyAll, Q=mostSignQAll, FREQ=peakFreqAll, ID=IDstring, plots=channelPlots) f1.close() for channelName in channelNameAll: f2 = open(outDir + '%s.html' % channelName, 'w') template = env.get_template('webpage/channeltemplate.html'.format( opts.pathToHTML)) # List plots for given channel print >> f2, template.render(channelNames=channelNameAll, thisChannel=channelName, plots=channelPlots) f2.close()
temp[len(temp)/2] = 1. return TimeSeries(temp, epoch=data.epoch, sample_rate=data.sample_rate) def step_like(data): temp = zeros(len(data)) temp[len(temp)/2:] = 1. return TimeSeries(temp, epoch=data.epoch, sample_rate=data.sample_rate) if __name__ == '__main__': import sys if len(sys.argv) < 6: print "Args: chan t_PSD dur_PSD seglen t_glitch" exit() chan = sys.argv[1] t1_psd = int(sys.argv[2]) dur_psd = int(sys.argv[3]) seglen = int(sys.argv[4]) tt = float(sys.argv[5]) st = int(tt) - seglen/2 data_for_psd = TimeSeries.fetch(chan, t1_psd, t1_psd+dur_psd) data = TimeSeries.fetch(chan, st, st+seglen) invasd = build_whitener(data_for_psd, seglen, method='median-mean') data = step_like(data) temp = apply_whitening(data, invasd) #plot = data.plot() plot = temp.plot() plot.show()
data = np.loadtxt('waterdrain.csv', delimiter=',') minutes = data[:, 0] * 60 + data[:, 1] * 1 time = minutes * 60 + float(tconvert('Jul 19 2019 00:00:00 JST')) drain = data[:, 2] / 8000 if True: # Download samewhere. I forgot. value = np.fromfile('eyv_z_out16_value') # fs=16 times = np.fromfile('eyv_z_out16_time') seis = TimeSeries(value, times=times, unit='um/sec', name='EYV_Z') seis = seis.rms(60) if False: # No data in Kamioka NDS... start, end = time[0], time[-1] print(tconvert(start)) print(start) print(tconvert(end)) chname = 'K1:PEM-SEIS_EYV_GND_Z_OUT16' seis = TimeSeries.fetch(chname, start, end, host='10.68.10.121', port=8088) print(seis) fig, ax = plt.subplots(1, 1, figsize=(10, 6)) ax.plot(seis, label='EXV') ax.plot(time, drain, 'ko', label='Water Drain [m3/s] /8000') ax.set_ylabel('Ground Velocity [um/sec]') #ax.set_xlabel('GPS Time') ax.legend(fontsize=20) ax.set_ylim(0, 0.025) ax.set_xscale('auto-gps') plt.savefig('result.png') plt.close()