def main_compare_gif_gotic2(): start = tconvert('Oct 15 2018 00:00:00') end = tconvert('Oct 21 2018 00:00:00') # gif data pfx = '/Users/miyo/Dropbox/KagraData/gif/' segments = GifData.findfiles(start, end, 'CALC_STRAIN', prefix=pfx) allfiles = [path for files in segments for path in files] strain = TimeSeries.read(source=allfiles, name='CALC_STRAIN', format='gif', pad=numpy.nan, nproc=2) strain = strain.detrend('linear') # gotic data source = '201805010000_201811010000.gotic' gifx = KagraGoticStrain.read(source, start=start, end=end).x gifx = gifx.detrend('linear') gifx = gifx * 0.9 # plot plot = Plot(gifx, strain, xscale='auto-gps') plot.legend() plot.subplots_adjust(right=.86) plot.savefig('result.png') plot.close()
def adjusted_window(st, et, jobdur): """ The given start time may not land on the start of a two hour segment. This function adjusts the start time and end time to the nearest two hour increments. Parameters ---------- st : `int` gps start time et : `int` gps end time jobdur : `int` Job duration Returns ------- adj_time_list : `list` Time list with adjusted start and end times """ starttime = tconvert(st) daystart = int(tconvert(datetime(starttime.year, starttime.month,starttime.day))) times = np.arange(daystart, et + 2 * jobdur, jobdur) index_nearest_st = np.argmin(np.abs(times - st)) index_nearest_et = np.argmin(np.abs(times - et)) if times[index_nearest_st] - st > 0: index_nearest_st -= 1 if times[index_nearest_et] - et < 0: index_nearest_et += 1 nearest_st = times[index_nearest_st] nearest_et = times[index_nearest_et] adjusted_times = np.arange(nearest_st, nearest_et + jobdur, jobdur) return adjusted_times
def make_plot(x_axis, y_axis, location): start_time = str(tconvert(int(min(x_axis)))) end_time = str(tconvert(int(max(x_axis)))) #converts y_axis time to microseconds from seconds MICROS_PER_SECOND = 1e6 # find outliers outlierinds = np.nonzero(np.logical_or(y_axis > -2.8e-6, y_axis < -1e-5)) outliertimes = x_axis[outlierinds] outliers = y_axis[outlierinds] print("Severe outliers found and removed (time: value):") for i, t in enumerate(outliertimes): print("{}: {}".format(t, outliers[i])) x = np.delete(x_axis, outlierinds) y_ax = np.delete(y_axis, outlierinds) * MICROS_PER_SECOND missing = np.nonzero(y_axis == 0) print("Missing values found and removed at times: {}".format(x[missing])) x = np.delete(x, missing) y_ax = np.delete(y_ax, missing) #creates array with slope and y-intercept of line of best fit lobf_array = np.polyfit(x, y_ax, 1) #dimensionless quantity that characterizes drift drift_coef = lobf_array[0] / MICROS_PER_SECOND y_axis_lobf = np.poly1d(lobf_array)(x) tmp = [lobf_array[0] * i for i in x] tmp += lobf_array[1] y_dif = y_ax - tmp print('making plots') fig = plt.figure(figsize=(13, 18)) plt.suptitle('Drift of cesium clock, from ' + start_time + ' until ' + end_time + location, fontsize=20) plt.subplots_adjust(top=0.88888888, bottom=0.1) ax1 = fig.add_subplot(211) ax1.set_title('Line of best fit versus offset') ax1.plot(x, y_ax, '#ff0000') ax1.plot(x, y_axis_lobf, '#617d8d') print(type(drift_coef)) print(str(drift_coef)) ax1.text(0.01, 0.05, 'Drift coefficient = ' + str(drift_coef), transform=ax1.transAxes, bbox=dict(facecolor='#99ccff', boxstyle='round', alpha=0.25)) ax1.set_xlabel('GPS time') ax1.set_ylabel('Offset [$\mu$s]') ax2 = fig.add_subplot(212) ax2.plot(x, y_dif) ax2.set_xlabel('GPS time') ax2.set_title('Residual of the line of best fit') ax2.set_ylabel('Difference [$\mu$s]') print('drift coefficient:') print(drift_coef) plt.tight_layout(pad=0.4, w_pad=0.5, h_pad=1) plt.subplots_adjust(left=0.2, right=0.8, top=0.9, bottom=0.1) fig.savefig('cesium_clock_drift_from_' + start_time.replace(' ', '_') + '_until_' + end_time.replace(' ', '_') + '.png', dpi=300)
def test_tconvert(): """Test :func:`gwpy.time.tconvert` """ # from GPS assert time.tconvert(1126259462.391) == ( datetime(2015, 9, 14, 9, 50, 45, 391000)) # from GPS using LAL LIGOTimeGPS assert time.tconvert(time.LIGOTimeGPS(1126259462.391)) == ( datetime(2015, 9, 14, 9, 50, 45, 391000)) assert time.tconvert(GlueGPS(1126259462.391)) == ( datetime(2015, 9, 14, 9, 50, 45, 391000)) # to GPS assert time.tconvert(datetime(2015, 9, 14, 9, 50, 45, 391000)) == ( time.LIGOTimeGPS(1126259462, 391000000)) # special cases now = time.tconvert() now2 = time.tconvert('now') assert now == now2 today = float(time.tconvert('today')) yesterday = float(time.tconvert('yesterday')) assert today - yesterday == pytest.approx(86400) assert now >= today tomorrow = float(time.tconvert('tomorrow')) assert tomorrow - today == pytest.approx(86400)
def make_plot(x_axis, y_axis, location): start_time = str(tconvert(int(min(x_axis)))) end_time = str(tconvert(int(max(x_axis)))) #converts y_axis time to microseconds from seconds MICROS_PER_SECOND = 1e6 # find outliers outlierinds = np.nonzero(np.logical_or(y_axis > -2.8e-6, y_axis < -1e-5)) outliertimes = x_axis[outlierinds] outliers = y_axis[outlierinds] print("Severe outliers found and removed (time: value):") for i, t in enumerate(outliertimes): print("{}: {}".format(t, outliers[i])) x = np.delete(x_axis, outlierinds) y_ax = np.delete(y_axis, outlierinds) * MICROS_PER_SECOND missing = np.nonzero(y_axis == 0) print("Missing values found and removed at times: {}".format(x[missing])) x = np.delete(x, missing) y_ax = np.delete(y_ax, missing) #creates array with slope and y-intercept of line of best fit lobf_array = np.polyfit(x, y_ax, 1) #dimensionless quantity that characterizes drift drift_coef = lobf_array[0]/MICROS_PER_SECOND y_axis_lobf = np.poly1d(lobf_array)(x) tmp = [lobf_array[0] * i for i in x] tmp += lobf_array[1] y_dif = y_ax - tmp print('making plots') fig = plt.figure(figsize=(13,18)) plt.suptitle('Drift of cesium clock, from ' + start_time + ' until ' + end_time + location, fontsize=20) plt.subplots_adjust(top=0.88888888, bottom=0.1) ax1 = fig.add_subplot(211) ax1.set_title('Line of best fit versus offset') ax1.plot(x, y_ax, '#ff0000') ax1.plot(x, y_axis_lobf, '#617d8d') print(type(drift_coef)) print(str(drift_coef)) ax1.text(0.01, 0.05, 'Drift coefficient = ' + str(drift_coef), transform=ax1.transAxes, bbox=dict(facecolor='#99ccff', boxstyle='round', alpha=0.25)) ax1.set_xlabel('GPS time') ax1.set_ylabel('Offset [$\mu$s]') ax2 = fig.add_subplot(212) ax2.plot(x, y_dif) ax2.set_xlabel('GPS time') ax2.set_title('Residual of the line of best fit') ax2.set_ylabel('Difference [$\mu$s]') print('drift coefficient:') print(drift_coef) plt.tight_layout(pad=0.4, w_pad=0.5, h_pad=1) plt.subplots_adjust(left=0.2, right=0.8, top=0.9, bottom=0.1) fig.savefig('cesium_clock_drift_from_' + start_time.replace(' ','_') + '_until_' + end_time.replace(' ','_') + '.png', dpi=300)
def test_tconvert(self): # from GPS date = time.tconvert(GPS) self.assertEqual(date, DATE) # from GPS using LAL LIGOTimeGPS try: from lal import LIGOTimeGPS except ImportError: pass else: d = time.tconvert(LIGOTimeGPS(GPS)) self.assertEqual(d, DATE) # to GPS gps = time.tconvert(date) self.assertEqual(gps, GPS) # special cases now = time.tconvert() now2 = time.tconvert('now') self.assertEqual(now, now2) today = time.tconvert('today') yesterday = time.tconvert('yesterday') self.assertAlmostEqual(today - yesterday, 86400) self.assertTrue(now >= today) tomorrow = time.tconvert('tomorrow') self.assertAlmostEqual(tomorrow - today, 86400)
def ligo_model_overflow_channels(dcuid, ifo=None, frametype=None, gpstime=None, accum=True): """ """ # FIXME: write a docstring ifo = ifo or const.IFO if ifo is None: raise ValueError("Cannot format channel without an IFO, " "please specify") if frametype is None: frametype = '%s_R' % ifo if gpstime is None: gpstime = tconvert().seconds - 1000 framefile = find_frames(ifo[0], frametype, gpstime, gpstime)[0].path allchannels = get_channels(framefile) if accum: regex = re.compile('%s:FEC-%d_(ADC|DAC)_OVERFLOW_ACC_\d+_\d+\Z' % (ifo, dcuid)) else: regex = re.compile('%s:FEC-%d_(ADC|DAC)_OVERFLOW_\d+_\d+\Z' % (ifo, dcuid)) return natural_sort(filter(regex.match, allchannels))
def from_coughlin_matfile(cls, matfile, which='1', calibration=1. / 16563, sample_rate=128, unit=units.nT, name=None): from scipy.io import loadmat from gwpy.time import tconvert mymat = loadmat(matfile, squeeze_me=True) ts = mymat['tt'] day = tconvert(date.fromordinal(int(np.floor(ts[0])) - 366)) if which == '1': return cls(mymat['data1'] * calibration, sample_rate=sample_rate, t0=day, unit=unit, name=name, channel=name) if which == '2': return cls(mymat['data2'] * calibration, sample_rate=sample_rate, t0=day, unit=unit, name=name, channel=name)
def ligo_model_overflow_channels(dcuid, ifo=None, frametype=None, gpstime=None, accum=True): """ """ # FIXME: write a docstring from lalframe.utils import get_channels ifo = ifo or const.IFO if ifo is None: raise ValueError("Cannot format channel without an IFO, " "please specify") if frametype is None: frametype = '%s_R' % ifo if gpstime is None: gpstime = tconvert().seconds - 1000 try: framefile = find_frames(ifo[0], frametype, gpstime, gpstime)[0].path except IndexError as e: e.args = ('No %s-%s frames found at GPS %d' % (ifo[0], frametype, gpstime),) raise allchannels = get_channels(framefile) if accum: regex = re.compile('%s:FEC-%d_(ADC|DAC)_OVERFLOW_ACC_\d+_\d+\Z' % (ifo, dcuid)) else: regex = re.compile('%s:FEC-%d_(ADC|DAC)_OVERFLOW_\d+_\d+\Z' % (ifo, dcuid)) return natural_sort(filter(regex.match, allchannels))
def ligo_model_overflow_channels(dcuid, ifo=None, frametype=None, gpstime=None, accum=True): """ """ # FIXME: write a docstring ifo = ifo or const.IFO if ifo is None: raise ValueError("Cannot format channel without an IFO, " "please specify") if frametype is None: frametype = '%s_R' % ifo if gpstime is None: gpstime = int(tconvert()) - 1000 try: framefile = find_frames(ifo[0], frametype, gpstime, gpstime)[0].path except IndexError as e: e.args = ('No %s-%s frames found at GPS %d' % (ifo[0], frametype, gpstime), ) raise try: allchannels = _CHANNELS[framefile] except KeyError: _CHANNELS[framefile] = get_channel_names(framefile) allchannels = _CHANNELS[framefile] if accum: regex = re.compile(r'%s:FEC-%d_(ADC|DAC)_OVERFLOW_ACC_\d+_\d+\Z' % (ifo, dcuid)) else: regex = re.compile(r'%s:FEC-%d_(ADC|DAC)_OVERFLOW_\d+_\d+\Z' % (ifo, dcuid)) return natural_sort(filter(regex.match, allchannels))
def _next(self): uchannels = self._unique_channel_names(self.channels) new = TimeSeriesDict() span = 0 epoch = 0 att = 0 self.logger.debug('Waiting for next NDS2 packet...') while span < self.interval: try: buffers = next(self.iterator) except RuntimeError as e: self.logger.error('RuntimeError caught: %s' % str(e)) if att < self.attempts: att += 1 wait_time = att / 3 + 1 self.logger.warning( 'Attempting to reconnect to the nds server... %d/%d' % (att, self.attempts)) self.logger.warning('Next attempt in minimum %d seconds' % wait_time) self.restart() sleep(wait_time - tconvert('now') % wait_time) continue else: self.logger.critical( 'Maximum number of attempts reached, exiting') break att = 0 for buff, c in zip(buffers, uchannels): ts = TimeSeries.from_nds2_buffer(buff) try: new.append({c: ts}, gap=self.gap, pad=self.pad) except ValueError as e: if 'discontiguous' in str(e): e.message = ( 'NDS connection dropped data between %d and ' '%d, restarting building the buffer from %d ') \ % (epoch, ts.span[0], ts.span[0]) self.logger.warning(str(e)) new = TimeSeriesDict() new[c] = ts.copy() elif ('starts before' in str(e)) or \ ('overlapping' in str(e)): e.message = ( 'Overlap between old data and new data in the ' 'nds buffer, only the new data will be kept.') self.logger.warning(str(e)) new = TimeSeriesDict() new[c] = ts.copy() else: raise span = abs(new[c].span) epoch = new[c].span[-1] self.logger.debug('%ds data for %s received' % (abs(ts.span), str(c))) out = type(new)() for chan in self.channels: out[chan] = new[self._channel_basename(chan)].copy() return out
def format(self, record): record.gpstime = tconvert('now') levelname = record.levelname if self.use_color and levelname in COLORS: levelname_color = ( COLOR_SEQ % (30 + COLORS[levelname]) + levelname + RESET_SEQ) record.levelname = levelname_color return logging.Formatter.format(self, record)
def read(cls, source, **kwargs): ''' Parameters ---------- start : end : Returns ------- cls ''' fname = source time, ns, ew, shear, azimuth, areal, cubic = loadtxt(fname, unpack=True) start = fname.split('_')[0] start_datetime = dt.strptime(start, '%Y%m%d%H%M') t0 = Time(start_datetime).gps start = tconvert(kwargs.pop('start', 0)) end = tconvert(kwargs.pop('end', 0)) #print start cls.t0 = t0 cls.time = time + t0 cls.ns = TimeSeries(ns, t0=cls.t0, dt=60 * u.min, unit='strain') cls.ew = TimeSeries(ew, t0=cls.t0, dt=60 * u.min, unit='strain') cls.shear = TimeSeries(shear, t0=cls.t0, dt=60 * u.min, unit='strain') cls.areal = TimeSeries(areal, t0=cls.t0, dt=60 * u.min, unit='strain') cls.azimuth = TimeSeries(azimuth, t0=cls.t0, dt=60 * u.min, unit='strain') cls.cubic = TimeSeries(cubic, t0=cls.t0, dt=60 * u.min, unit='strain') # crop cls.ns = cls.ns.crop(start, end) cls.ew = cls.ew.crop(start, end) cls.shear = cls.shear.crop(start, end) cls.areal = cls.areal.crop(start, end) cls.azimuth = cls.azimuth.crop(start, end) cls.cubic = cls.cubic.crop(start, end) return cls
def sync_clock(self): """Pause the `Monitor` to get a user-friendly epoch """ self.logger.info('Waiting to align with UTC clock...') seconds = 60 % self.interval == 0 and self.interval or 60 t = datetime.datetime.now() while t.second % seconds: t = datetime.datetime.now() self.logger.info('Aligned') self.epoch = int(tconvert())
def grab_time_triggers(glob_wildcard): time_segs = SegmentList([]) start_time_utc = tconvert(args.gps_start_time) for filename in glob.glob(glob_wildcard): data = SegmentList.read(filename) print 'grabbing trigger file:' + filename time_segs += data # print time_segs start_time_utc += datetime.timedelta(days=1) return time_segs
def flagger(self,start,stop,filelist): fs = self.fs # convert LIGO GPS time to datetime # make sure datetime object knows it is UTC timezone utc_start = tconvert(start).replace(tzinfo=pytz.utc) utc_stop = tconvert(stop).replace(tzinfo=pytz.utc) # 1970-1-1 in UTC defines epoch of unix time epoch = dt.datetime.utcfromtimestamp(0).replace(tzinfo=pytz.utc) print (utc_start - epoch).total_seconds() print (utc_stop - epoch).total_seconds() # get segments with required flag level segs_H1 = rl.getsegs(start, stop, 'H1',flag='STOCH_CAT1', filelist=filelist) good_data_H1 = np.zeros(stop-start,dtype=np.bool) for (begin, end) in segs_H1: good_data_H1[begin-start:end-start] = True segs_L1 = rl.getsegs(start, stop, 'L1',flag='STOCH_CAT1', filelist=filelist) good_data_L1 = np.zeros(stop-start,dtype=np.bool) for (begin, end) in segs_L1: good_data_L1[begin-start:end-start] = True # add time bit at beginning and end to _AND_ of two timeseries good_data = np.append(np.append(False,good_data_H1 & good_data_L1),False) # do diff to identify segments diff = np.diff(good_data.astype(int)) segs_begin = np.where(diff>0)[0] + start #+1 segs_end = np.where(diff<0)[0] + start #+1 # re-define without first and last time bit # This mask now defines conincident data from both L1 and H1 good_data = good_data_H1 & good_data_L1 # TODO: Add flagging of injections # Now loop over all segments found return segs_begin, segs_end
def webpage_info(st, et, output_dir, jobdur): starttime = tconvert(st) daystart = int(tconvert(datetime(starttime.year, starttime.month, starttime.day))) times = np.arange(daystart, daystart + 8640000 + jobdur, jobdur) nearest_st = list(abs(times - st)).index(min(abs(times - st))) st = times[nearest_st] nearest_et = list(abs(times - et)).index(min(abs(times - et))) et = times[nearest_et] save_webpage_str = '%d%02d%02d' % (starttime.year, starttime.month, starttime.day) datestrmdy = '%02d-%02d-%d' % (starttime.month, starttime.day, starttime.year) datestrdmy = '%02d-%02d-%d' % (starttime.day, starttime.month, starttime.year) datestrymd = '%d%02d%02d' % (starttime.year, starttime.month, starttime.day) webpage_output_dir = '%s/%s/day/%s' % (output_dir, 'HTML', save_webpage_str) webpage_info = {} webpage_info['mdy'] = datestrmdy webpage_info['dmy'] = datestrdmy webpage_info['ymd'] = datestrymd webpage_info['output_dir'] = webpage_output_dir return webpage_info
def grab_time_segments(glob_wildcard): known_start = [] known_end = [] start_time_utc = tconvert(args.gps_start_time) for filename in glob.glob(glob_wildcard): if os.path.isfile(filename): segments = numpy.atleast_2d(numpy.loadtxt(filename, delimiter=',')) known_start = [segments[i, 0] for i in range(len(segments))] known_end = [segments[i, 1] for i in range(len(segments))] start_time_utc += datetime.timedelta(days=1) for index in range(len(known_start)): g.write(str(known_start[index]) + " " + str(known_end[index]) + "\n")
def grab_time_triggers(wildcard, start, end): """Retrieve triggers from a given GPS time range """ time_segs = SegmentList([]) start_time_utc = tconvert(start) for filename in glob.glob(wildcard): data = SegmentList.read(filename) LOGGER.info(' '.join(['grabbing trigger file:', filename])) start_end_seg = Segment(start, end) c = data & SegmentList([start_end_seg]) time_segs += c start_time_utc += datetime.timedelta(days=1) return time_segs
def __init__(self, fig=None, interval=2, blit=True, repeat=False, logger=Logger('monitor'), figname=None, save_every=1, tight_bbox=False, pause=False, clock=False, **kwargs): self.logger = logger # record timing self.gpsstart = tconvert('now') self._clock = clock # pick up refresh kwargs = self.parse_params(kwargs) # set up figure if fig is None: fig = self.init_figure() # generate monitor self.interval = interval super(Monitor, self).__init__(fig, interval=int(100), blit=blit, repeat=repeat, **kwargs) self.figname = figname self.tight = tight_bbox or 'bbox_to_anchor' in self.params['legend'] self.save_every = save_every self.refresh_count = 0 if save_every * interval < 10 and figname: self.logger.warning('Saving too often!') self.legend = None self.suptitle = None # set up events connection self.buttons = {} self.paused = False if pause: self.buttons['pause'] = self._button('Pause', self.pause, 0.88) # announce self.logger.info('Monitor ready to start\n' ' Use the run() method of the monitor to execute')
def grab_time_segments(wildcard, start, segfile): """Retrieve time segments from a given start time """ known_start = [] known_end = [] start_time_utc = tconvert(start) for filename in glob.glob(wildcard): if os.path.isfile(filename): segments = numpy.atleast_2d(numpy.loadtxt(filename, delimiter=',')) known_start = [segments[i, 0] for i in range(len(segments))] known_end = [segments[i, 1] for i in range(len(segments))] start_time_utc += datetime.timedelta(days=1) for index in range(len(known_start)): segfile.write( str(known_start[index]) + " " + str(known_end[index]) + "\n")
def write_summary( ifo, gpstime, header='Analysis Summary', tableclass='table table-condensed table-hover table-responsive'): """Write the Qscan analysis summary HTML Parameters ---------- ifo : `str` the interferometer prefix gpstime : `float` the central GPS time of the analysis header : `str`, optional the text for the section header (``<h2``>) tableclass : `str`, optional the ``class`` for the summary ``<table>`` Returns ------- page : `~glue.markup.page` the formatted markup object containing the analysis summary table """ utc = tconvert(gpstime) page = markup.page() page.h2(header) page.p('This page shows time-frequency maps of a user-configured list of ' 'channels for a given interferometer and GPS time. Time-frequency ' 'maps are computed using the <a ' 'href="https://gwpy.github.io/docs/stable/examples/timeseries/' 'qscan.html" target="_blank">Q-transform</a>.') page.p("This analysis is based on the following run arguments.") page.table(class_=tableclass) # make table body page.tbody() page.tr() page.td("<b>Interferometer</b>") page.td("%s (%s)" % (OBSERVATORY_MAP[ifo]['name'], ifo)) page.tr.close() page.tr() page.td("<b>UTC Time</b>") page.td("%s" % utc) page.tr.close() page.tbody.close() # close table page.table.close() return page()
def find_latest_omicron_file(channel, basepath, ext='xml.gz', filetag=const.OMICRON_FILETAG.upper(), gps=None): """Find the most recent Omicron file for a given channel """ if gps is None: gps = int(tconvert('now')) gps5 = int(str(gps)[:5]) while gps5: cache = _iter_files_in_gps_directory(channel, basepath, gps5, ext, filetag=filetag) try: return list(cache)[-1] except IndexError: pass gps5 -= 1 raise RuntimeError("Failed to find any Omicron files for %r" % channel)
def path_to_file(chname, date, prefix='/Users/miyo/KagraData/gif/'): ''' Return path to file Parameter --------- date: datetime datetime. JST prefix: str location where gif binary data is saved. Return ------ path : str path to file ''' from gwpy.time import tconvert def second_is_00(date): ''' Parameters ---------- date : datetime if second is 0, return True, not if return False. ''' if date.second == 0: return True else: return False date_fmt = '%Y/%m/%d/%H/%y%m%d%H%M' # if not isinstance(date, datetime): date = tconvert(date) #raise ValueError('not datetime. {0}'.format(type(date))) if not second_is_00(date): raise ValueError('Second is not 0!') # date is datetime date_str = date.strftime(date_fmt) path_to_file = prefix + fname_fmt[chname].replace('<fname>', date_str) return path_to_file
def resultlogger(self, rdict, logfile='log.txt'): f = open(logfile, 'a') f.write('Test completed at time {0}\n'.format(tconvert('now'))) for serv, keys in rdict.iteritems(): f.write('server: [{0}]\n'.format(serv)) f.write('All connection attempts Succeeded : {0}\n'.format(keys.pop('connection', True))) f.write('{0:<35}\t{1:<25}\t{2:<25}\t{3:<25}\t{4:<25}\t{5:<25}\n'.format( 'Channel', 'Avail. than. list tetr.', 'Offline_iterator_created','Offline_iteration_succeeded', 'Online_iterator_created','Online_iteration_succeeded')) for chan, tests in keys.iteritems(): string = '{0:<35}\t{1:<25}\t{2:<25}\t{3:<25}\t{4:<25}\t{5:<25}\n'.format( chan, tests.pop('available', False), tests.pop('OfflineIteratorCreation', True), tests.pop('OfflineIterationTest', True), tests.pop('OnlineIteratorCreation', True), tests.pop('OnlineIterationTest', True)) f.write(string) f.write('\n') f.write('\n') f.close()
def set_date_options(self, start, end, section=DEFAULTSECT): """Set datetime options in [DEFAULT] based on the given times The following options are set - `gps-start-time` - the integer GPS start time of this job - `gps-end-time` - the integer GPS end time of this job - `yyyy` - the four-digit year of the start date - `mm` - the two-digit month of the start date - `dd` - the two-digit day-of-month of the start date - `yyyymm` - the six-digit year and month of the start date - `yyyymmdd` - the eight-digit year-month-day of the start date - `duration` - the duration of the job (seconds) Additionally, if LAL is available, the following extra options are also set - `leap-seconds` - the number of leap seconds for the start date - `gps-start-time-noleap` - the leap-corrected integer GPS start time - `gps-end-time-noleap` - the leap-corrected integer GPS end time """ utc = tconvert(start) self.set(section, 'gps-start-time', str(int(start))) self.set(section, 'gps-end-time', str(int(end))) self.set(section, 'yyyy', utc.strftime('%Y')) self.set(section, 'yy', utc.strftime('%y')) self.set(section, 'mm', utc.strftime('%m')) self.set(section, 'dd', utc.strftime('%d')) self.set(section, 'yyyymm', utc.strftime('%Y%m')) self.set(section, 'yyyymmdd', utc.strftime('%Y%m%d')) self.set(section, 'duration', str(int(end - start))) try: from lal import GPSLeapSeconds as leap_seconds except ImportError: pass else: nleap = leap_seconds(int(start)) self.set(section, 'leap-seconds', str(nleap)) self.set(section, 'gps-start-time-noleap', str(int(start) - nleap)) self.set(section, 'gps-end-time-noleap', str(int(end) - nleap))
def quickplot(chanList, gpsLength=3600, gpsStop=correct_time().gpsSeconds): ''' quickplot takes in a list of channels, and plots an hour worth of data for all channels specified. Inputs: chanList: list of channels valid for the CTN Lab fb4. gpsLength: length of time in seconds to plot from gpsStop. Default is one hour. gpsStop: gpstime to plot until. Default is now. ''' conn = nds2.connection('10.0.1.156', 8088) gpsStart = gpsStop - gpsLength data = conn.fetch(gpsStart, gpsStop, chanList) if gpsLength <= 60: units = 'seconds' timeDivisor = 1 elif gpsLength <= 3600: units = 'minutes' timeDivisor = 60 elif gpsLength <= 86400: units = 'hours' timeDivisor = 3600 elif gpsLength <= 604800: units = 'days' timeDivisor = 86400 displayTime = gpsLength / timeDivisor t = linspace(0, displayTime, gpsLength * 16) for dat in data: plot(t, dat.data) xlabel('Time [{}] from {} ({})'.format(units, tconvert(gpsStart), gpsStart)) print(chanList) print('gpsLength = {}'.format(gpsLength)) print('gpsStop = {}'.format(gpsStop))
def test_tconvert(self): # from GPS date = time.tconvert(GPS) self.assertEqual(date, DATE) # to GPS gps = time.tconvert(date) self.assertEqual(gps, GPS) # special cases now = time.tconvert() now2 = time.tconvert('now') self.assertEqual(now, now2) today = time.tconvert('today') yesterday = time.tconvert('yesterday') self.assertAlmostEqual(today - yesterday, 86400) self.assertTrue(now >= today)
def get_segments(ifo, start=1238112018, stop=-1): """ get_segments(ifo, start=1238112018, stop=-1) Query the segment database to find ANALYSIS_READY == 1 segments. Inputs: ifo = interferometer ['L' or 'H'] start = start time (default: beginning of O3) stop = stop time (default: now) Outputs: segments: a list of segments [seg id, start GPS, end GPS] """ # get the current GPS time if needed if stop == -1: stop = tconvert('now').gpsSeconds # quesry segment database segs = DataQualityFlag.query(ifo + '1:DMT-ANALYSIS_READY:1', start, stop) # convert to numerical (nteger) values return [[i, int(s.start), int(s.end)] for i, s in enumerate(segs.active)]
def path_to_file(chname, date, prefix='/Users/miyo/KagraData/gif/'): ''' Return path to file Parameter --------- date: gpstime(JST) prefix: str location where gif binary data is saved. Return ------ path : str path to file ''' date = tconvert(date) # GPS(JST) -> JST date = date + timedelta(hours=9) #UTC -> JST date_str = date.strftime('%Y/%m/%d/%H/%y%m%d%H%M') path_to_file = prefix + fname_fmt[chname].replace('<fname>', date_str) return path_to_file
def __init__(self, *channels, **kwargs): kwargs.setdefault('logger', Logger('monitor')) self.epoch = tconvert('now') self.sep = kwargs.pop('separate', False) # separate keyword arguments buffkeys = ['host', 'port', 'connection', 'interval', 'duration', 'pad', 'gap', 'attempts'] buffargs = {'logger': kwargs.get('logger')} for key in buffkeys: if key in kwargs: buffargs[key] = kwargs.pop(key) # set up buffer self.buffer = self.ITERATOR_CLASS(channels, **buffargs) labels = kwargs.pop('labels', kwargs.pop('label', [])) for i, channel in enumerate(self.buffer.channels): try: channel.label = labels[i] except IndexError: channel.label = None # set up monitor and go super(DataMonitor, self).__init__(**kwargs)
def write_summary( ifo, gpstime, incomplete=False, context='default', header='Summary', tableclass='table table-condensed table-hover table-responsive'): """Write the Qscan analysis summary HTML Parameters ---------- ifo : `str` the interferometer prefix gpstime : `float` the central GPS time of the analysis incomplete : `bool` boolean switch to determine whether the scan is still in progress context : `str`, optional the bootstrap context class for this result, see the bootstrap docs for more details header : `str`, optional the text for the section header (``<h2``>) tableclass : `str`, optional the ``class`` for the summary ``<table>`` Returns ------- page : `~MarkupPy.markup.page` the formatted markup object containing the analysis summary table """ utc = tconvert(gpstime) page = markup.page() page.div(class_='banner') page.h2(header) page.div.close() # banner page.div(class_='row') page.div(class_='col-md-5') page.table(class_=tableclass) # make table body page.tbody() page.tr() page.td("<b>Interferometer</b>", scope='row') page.td("%s (%s)" % (OBSERVATORY_MAP[ifo]['name'], ifo)) page.tr.close() page.tr() page.td("<b>UTC Time</b>", scope='row') page.td("%s" % utc) page.tr.close() page.tbody.close() # close table page.table.close() page.div.close() # col-md-5 # make summary table download button page.div(class_='col-xs-12 col-md-7') page.div(class_='btn-group', role='group') page.button(id_='summary_table_download', type='button', class_='btn btn-%s dropdown-toggle' % context, **{'data-toggle': 'dropdown'}) page.add('Download summary <span class="caret"></span>') page.button.close() page.ul(class_='dropdown-menu', role='menu', **{'aria-labelledby': 'summary_table_download'}) for ext in ['txt', 'csv', 'tex']: page.li('<a href="data/summary.%s" download="%s_%s_summary.%s">%s</a>' % (ext, ifo, gpstime, ext, ext)) page.ul.close() page.div.close() # btn-group page.div.close() # col-md-7 page.div.close() # row # write alert if incomplete: page.div(class_='row') page.div(class_='alert alert-%s' % context) page.p('<strong>Note</strong>: This scan is in progress, and will ' 'auto-refresh every 60 seconds until completion.') page.div.close() # alert page.div.close() # row return page()
# algorithm that takes segment/trigger list and writes to file def write_segs(trig_seg_list, output_file): start_end_seg = Segment(args.gps_start_time, args.gps_end_time) total_triggers = triggers + SegmentList([start_end_seg]) total_triggers.coalesce() total_triggers.write(output_file) # A check to make sure we're within the time window of aLIGO, and that end_time is after start_time if args.gps_start_time < 971574400: # roughly the end of S6 parser.error("gps_start_time before S6") if args.gps_end_time < args.gps_start_time: parser.error("end_time is before gps_start_time") # finds beginning of day for given gps time start_of_day = tconvert(args.gps_start_time) start_of_day_utc = start_of_day.replace(hour=0, minute=0, second=0) start_of_day_gps = tconvert(start_of_day) # finds UTC version of start/end times start_time_utc = tconvert(args.gps_start_time) end_time_utc = tconvert(args.gps_end_time) # opens files to be ready for writing f = open("total" + args.type_dq_flag + "trigs.txt", "w") # file that will hold collection of all triggers g = open("total" + args.type_dq_flag + "segs.txt", "w") # file that will hold collection of all segments # choosing to read in hveto! if args.type_dq_flag == 'hveto': print 'Data Quality Flag chosen is hveto, stored in the path ' + args.directory_path
""" __author__ = "Duncan Macleod <*****@*****.**>" __currentmodule__ = 'gwpy.timeseries' if __name__ == '__main__': from matplotlib import pyplot pyplot.ion() # Before anything else, we import the objects we will need: from gwpy.time import tconvert from gwpy.timeseries import TimeSeriesDict from gwpy.plotter import BodePlot # 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.fetch` method of the `TimeSeriesDict` # to retrieve all data in a single operation: data = TimeSeriesDict.fetch([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')
""" __author__ = "Duncan Macleod <*****@*****.**>" __currentmodule__ = 'gwpy.timeseries' if __name__ == '__main__': from matplotlib import pyplot pyplot.ion() # Before anything else, we import the objects we will need: from gwpy.time import tconvert from gwpy.timeseries import TimeSeriesDict from gwpy.plot import BodePlot # 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')
parser.add_argument('gps_end_time',type=int,help='Please enter GPS end time') parser.add_argument('directory_path',type=str,help='Please enter directory path for triggers and segments') #parser.add_argument('-s','--start_date', type=str, help='Please enter start date in YYYYMMDD format, required for the hveto option') #parser.add_argument('-e','--end_date', type=str, help='Please enter end date in YYYYMMDD format, required for the hveto option') parser.add_argument('type_dq_flag', type=str, help='Please enter either hveto, UPVh, OVL') parser.add_argument('-a', '--hveto_analysis_seg', type=str, help='Please enter offline hveto O1 offline analysis segment, 4,5,6,8,9') parser.add_argument('-o','--online_offline', type=str, help='Please enter either offline or online. This is for hveto.') args = parser.parse_args() #A check to make sure we're within the time window of aLIGO, and that end_time is after start_time if args.gps_start_time < 971574400: #roughly the end of S6 parser.error("gps_start_time before S6") if args.gps_end_time < args.gps_start_time: parser.error("end_time is before gps_start_time") #finds beginning of day for given gps time start_of_day = tconvert(args.gps_start_time) start_of_day = start_of_day.replace(hour=0,minute=0,second=0) start_of_day = tconvert(start_of_day) ################################################### #######CREATING TOTAL TRIGGER/SEGMENT FILES######## ################################################### ###choosing to read in hveto!### if args.type_dq_flag == 'hveto': print 'Data Quality Flag chosen is hveto, stored in the path ' + args.directory_path if args.online_offline == 'offline': analysis_segs_45689 = ['4', '5', '6', '7', '9'] analysis_segs_237 = ['2', '3'] if args.hveto_analysis_seg in analysis_segs_45689: pattern_trigs_hveto= os.path.join(args.directory_path, 'analysis' + args.hveto_analysis_seg , 'H1-omicron_BOTH-*-DARM','*VETO_SEGS_ROUND*.txt')
import os import subprocess import glob import gwpy from gwpy.timeseries import TimeSeries from gwpy.timeseries import TimeSeriesDict from matplotlib import pylab as pl from gwpy.detector import Channel from gwpy.time import tconvert ''' M6.7, Iburi, Sep 6 2018 03:07:59.3 M5.2, Nagano, May 25 2018 21:13:42.2 ''' start = tconvert('Aug 19 2018 00:19:40 UTC') # Fiji M8.2 end = tconvert('Aug 19 2018 01:19:40 UTC') #start = tconvert('Sep 6 2018 03:07:59.3 JST') # 1220238498 #start = tconvert('Sep 6 2018 03:10:13 JST') #end = tconvert('Sep 6 2018 03:10:14 JST') #end = tconvert('Sep 6 2018 03:37:59.3 JST') # # #start = tconvert('May 25 2018 21:13:42.2 JST') #end = tconvert('May 25 2018 21:23:42.2 JST') # make file list sources = [] mtrend = False
import time from gwpy.time import tconvert from gwpy.segments import DataQualityDict from gwpy.detector import ChannelList CHANNELS = ChannelList() STATES = {} DATA = {} SPECTROGRAMS = {} SPECTRUM = {} COHERENCE_COMPONENTS = {} COHERENCE_SPECTRUM = {} SEGMENTS = DataQualityDict() TRIGGERS = {} VERBOSE = False PROFILE = False START = time.time() # run time variables MODE = 4 WRITTEN_PLOTS = [] NOW = tconvert('now').seconds HTMLONLY = False # comments IFO = None HTML_COMMENTS_NAME = None
from gwpy.timeseries import TimeSeriesDict from gwpy.time import tconvert import numpy as np start = tconvert('Apr 15 2019 16:39:20 JST') end = tconvert('Apr 15 2019 16:39:21 JST') chname = [ 'K1:GIF-X_ANGLE_IN1_DQ', 'K1:GIF-X_LAMP_IN1_DQ', 'K1:GIF-X_PHASE_IN1_DQ', 'K1:GIF-X_PPOL_IN1_DQ', 'K1:GIF-X_P_AMP_IN1_DQ', 'K1:GIF-X_P_OFFSET_IN1_DQ', 'K1:GIF-X_ROTATION_IN1_DQ', 'K1:GIF-X_SPOL_IN1_DQ', 'K1:GIF-X_STRAIN_IN1_DQ', 'K1:GIF-X_S_AMP_IN1_DQ', 'K1:GIF-X_S_OFFSET_IN1_DQ', 'K1:GIF-X_ZABS_IN1_DQ', ] data = TimeSeriesDict.fetch(chname,start,end, host='10.68.10.121',port=8088) N = 128 angle = data['K1:GIF-X_ANGLE_IN1_DQ'] angle = angle.value[:N] angle = np.unwrap(angle) angle = np.rad2deg(angle) ppol = data['K1:GIF-X_PPOL_IN1_DQ'] p_ave = np.average(ppol.value)
def init_page(ifo, gpstime, toc={}, refresh=False, css=None, script=None, base=os.path.curdir, **kwargs): """Initialise a new `markup.page` This method constructs an HTML page with the following structure .. code-block:: html <html> <head> <!-- some stuff --> </head> <body> <div class="container"> <div class="page-header"> <h1>IFO</h1> <h3>GPSTIME</h3> </div> </div> <div class="container"> Parameters ---------- ifo : `str` the interferometer prefix gpstime : `float` the central GPS time of the analysis toc : `dict` metadata dictionary for navbar table of contents refresh : `bool` Boolean switch to enable periodic page refresh css : `list`, optional the list of stylesheets to link in the `<head>` script : `list`, optional the list of javascript files to link in the `<head>` base : `str`, optional, default '.' the path for the `<base>` tag to link in the `<head>` Returns ------- page : `markup.page` the structured markup to open an HTML document """ if not css: css = CSS_FILES if not script: script = JS_FILES # write CSS to static dir css, script = htmlio.finalize_static_urls( os.path.join(os.path.curdir, 'static'), css, script, ) # create page page = markup.page() page.header.append('<!DOCTYPE HTML>') page.html(lang='en') page.head() if refresh: page.add('<meta http-equiv="refresh" content="60">') page.add('<meta content="width=device-width, initial-scale=1.0" ' 'name="viewport">') page.base(href=base) page._full = True # link files for f in css: page.link(href=f, rel='stylesheet', type='text/css', media='all') for f in script: page.script('', src=f, type='text/javascript') # add other attributes for key in kwargs: getattr(page, key)(kwargs[key]) # finalize header page.head.close() page.body() # write banner page.add('<header class="navbar navbar-fixed-top navbar-%s">' % ifo.lower()) page.div(class_='container') page.div(class_='navbar-header') page.add('<button class="navbar-toggle" data-toggle="collapse" ' 'type="button" data-target=".navbar-collapse">') page.add('<span class="icon-bar"></span>') page.add('<span class="icon-bar"></span>') page.add('<span class="icon-bar"></span>') page.add('</button>') page.div(ifo, class_='navbar-brand') page.div(gpstime, class_='navbar-brand') page.div.close() # navbar-header page.add('<nav class="collapse navbar-collapse">') page.ul(class_='nav navbar-nav') page.li('<a href="#">Summary</a>') for key, block in toc.items(): page.li(class_='dropdown') page.add('<a class="dropdown-toggle" data-toggle="dropdown">') page.add('%s <b class="caret"></b>' % key) page.add('</a>') page.ul(class_='dropdown-menu', style='max-height: 700px; ' 'overflow-y: scroll;') page.li(block['name'], class_='dropdown-header') for chan in block['channels']: page.li() chanid = chan.name.lower().replace(':', '-') page.a(chan.name, href='#%s' % chanid) page.li.close() page.ul.close() page.li.close() page.li(class_='dropdown') page.add('<a class="dropdown-toggle" data-toggle="dropdown">') page.add('Links <b class="caret"></b>') page.add('</a>') page.ul(class_='dropdown-menu') page.li('Internal', class_='dropdown-header') page.li('<a href="about">About this scan</a>') page.li('', class_='divider') page.li('External', class_='dropdown-header') for name, link in OBSERVATORY_MAP[ifo]['links'].items(): page.li() if 'Summary' in name: day = str(tconvert(gpstime).date()).replace('-', '') link = '/'.join([link, day]) page.a(name, href=link, target='_blank') page.li.close() page.ul.close() page.li.close() page.ul.close() page.add('</nav>') page.div.close() # container page.add('</header>') # navbar # open container page.div(class_='container') return page
def __init__(self, logger=Logger): self.logger = logger('NDS tester') self.gpsb = int(tconvert('now') - 1200)