def include_exclude_caller(includedList, excludedList, startTime, endTime, protocol, server, include_list_string): """ Function to query the dqsegdb for lists of included and excluded flags. Returns lists of JSON for the included and excluded flags and lists of URLs used to query the database. Parameters ---------- includedList : `list` List of ifo,name,version tuples excludedList : `list` List of ifo,name,version tuples protocol : `string` Ex: 'https' server : `string` Ex: 'dqsegdb5.phy.syr.edu' include_list_string : `string` Ex: "metadata,known,active" startTime : `int` Ex: 999999999 endTime : `int` Ex: 999999999 """ from dqsegdb import apicalls ## Form the results for included and excluded flags includedJSON = [] includedURL = [] excludedJSON = [] excludedURL = [] if len(includedList) > 0: for entry in includedList: ifo = entry[0] name = entry[1] version = entry[2] result, queryurl = apicalls.dqsegdbQueryTimes( protocol, server, ifo, name, version, include_list_string, startTime, endTime) includedURL.append(queryurl) includedJSON.append(result) if len(excludedList) > 0: for entry in excludedList: ifo = entry[0] name = entry[1] version = entry[2] result, queryurl = apicalls.dqsegdbQueryTimes( protocol, server, ifo, name, include_list_string, startTime, endTime) excludedURL.append(queryurl) excludedJSON.append(result) return includedJSON, includedURL, excludedJSON, excludedURL, ifo
def include_exclude_caller(includedList,excludedList,startTime,endTime,protocol, server,include_list_string): """ Function to query the dqsegdb for lists of included and excluded flags. Returns lists of JSON for the included and excluded flags and lists of URLs used to query the database. Parameters ---------- includedList : `list` List of ifo,name,version tuples excludedList : `list` List of ifo,name,version tuples protocol : `string` Ex: 'https' server : `string` Ex: 'dqsegdb5.phy.syr.edu' include_list_string : `string` Ex: "metadata,known,active" startTime : `int` Ex: 999999999 endTime : `int` Ex: 999999999 """ from dqsegdb import apicalls ## Form the results for included and excluded flags includedJSON=[] includedURL=[] excludedJSON=[] excludedURL=[] if len(includedList) > 0: for entry in includedList: ifo=entry[0] name=entry[1] version=entry[2] result,queryurl=apicalls.dqsegdbQueryTimes(protocol,server,ifo,name,version,include_list_string,startTime,endTime) includedURL.append(queryurl) includedJSON.append(result) if len(excludedList) > 0: for entry in excludedList: ifo=entry[0] name=entry[1] version=entry[2] result,queryurl=apicalls.dqsegdbQueryTimes(protocol,server,ifo,name,include_list_string,startTime,endTime) excludedURL.append(queryurl) excludedJSON.append(result) return includedJSON,includedURL,excludedJSON,excludedURL,ifo
def find_segments(ifo,start_time,length): if ifo == 'H1': DQFlag = 'ODC_MASTER_SUMMARY' else: DQFlag = 'ODC-MASTER_OBS_INTENT' seg_dict=apicalls.dqsegdbQueryTimes('https','dqsegdb5.phy.syr.edu',ifo,DQFlag,'1','active,known,metadata',start_time,start_time+length) return seg_dict
def check_veto_def_exists(veto, url=None): """Assert veto flag exist in database for times given """ try: url = urlparse(url or SEGMENT_DATABASE) except AttributeError as e: e.args = ("Cannot parse URL for %r: %s" % (url or SEGMENT_DATABASE, str(e)),) raise try: metadata = apicalls.dqsegdbQueryTimes( url.scheme, url.netloc, veto.ifo, veto.name, veto.version, "metadata", veto.start_time, veto.end_time or 1e10) except URLError as e: raise AssertionError("Flag not found in database")
def check_veto_def_exists(veto, url=None): """Assert veto flag exist in database for times given """ try: url = urlparse(url or SEGMENT_DATABASE) except AttributeError as e: e.args = ("Cannot parse URL for %r: %s" % (url or SEGMENT_DATABASE, str(e)), ) raise try: metadata = apicalls.dqsegdbQueryTimes(url.scheme, url.netloc, veto.ifo, veto.name, veto.version, "metadata", veto.start_time, veto.end_time or 1e10) except URLError as e: raise AssertionError("Flag not found in database")
def query_dqsegdb(cls, flag, *args, **kwargs): """Query the advanced LIGO DQSegDB for the given flag Parameters ---------- flag : `str` The name of the flag for which to query *args Either, two `float`-like numbers indicating the GPS [start, stop) interval, or a `SegmentList` defining a number of summary segments url : `str`, optional, default: ``'https://segments.ligo.org'`` URL of the segment database Returns ------- flag : `DataQualityFlag` A new `DataQualityFlag`, with the `known` and `active` lists filled appropriately. """ from dqsegdb import apicalls # parse arguments if len(args) == 1 and isinstance(args[0], SegmentList): qsegs = args[0] elif len(args) == 1 and len(args[0]) == 2: qsegs = SegmentList([Segment(to_gps(args[0][0]), to_gps(args[0][1]))]) else: print(args) qsegs = SegmentList([Segment(*map(to_gps, args))]) # get server protocol, server = kwargs.pop( 'url', 'https://segments.ligo.org').split('://', 1) # parse flag out = cls(name=flag) if out.ifo is None or out.tag is None: raise ValueError("Cannot parse ifo or tag (name) for flag %r" % flag) # other keyword arguments request = kwargs.pop('request', 'metadata,active,known') # process query for start, end in qsegs: if float(end) == +inf: end = to_gps('now').seconds if out.version is None: data, versions, _ = apicalls.dqsegdbCascadedQuery( protocol, server, out.ifo, out.tag, request, int(start), int(end)) data['metadata'] = versions[-1]['metadata'] else: try: data, _ = apicalls.dqsegdbQueryTimes( protocol, server, out.ifo, out.tag, out.version, request, int(start), int(end)) except HTTPError as e: if e.code == 404: # if not found, annotate with flag name e.msg += ' [{0}]'.format(flag) raise # read from json buffer try: new = cls.read(StringIO(json.dumps(data)), format='json') except TypeError as e: if 'initial_value must be unicode' in str(e): # python2 new = cls.read(StringIO(json.dumps(data).decode('utf-8')), format='json') else: raise # restrict to query segments segl = SegmentList([Segment(start, end)]) new.known &= segl new.active &= segl out += new # replace metadata out.description = new.description out.isgood = new.isgood return out
def find_segments(ifo,start_time,length,DQFlag): seg_dict=apicalls.dqsegdbQueryTimes('https','segments.ligo.org',ifo,DQFlag,'1','active,known,metadata',start_time,start_time+length) return seg_dict