def test_query(self): try: new = Channel.query(self.channel) except URLError as e: msg = str(e) if ('timed out' in msg.lower() or 'connection reset' in msg.lower()): self.skipTest(msg) raise except ValueError as e: if 'No JSON object could be decoded' in str(e): self.skipTest(str(e)) raise except Exception as e: try: import kerberos except ImportError: self.skipTest('Channel.query() requires kerberos ' 'to be installed') else: if isinstance(e, kerberos.GSSError): self.skipTest(str(e)) else: raise self.assertTrue(str(new) == self.channel) self.assertTrue(new.ifo == self.channel.split(':', 1)[0]) self.assertTrue(new.sample_rate == units.Quantity(32768, 'Hz')) self.assertTrue(new.texname == self.channel.replace('_', r'\_'))
def test_query(self): try: new = Channel.query(self.channel) except URLError as e: msg = str(e) if ('timed out' in msg.lower() or 'connection reset' in msg.lower()): self.skipTest(msg) raise except ValueError as e: if 'No JSON object could be decoded' in str(e): self.skipTest(str(e)) raise except Exception as e: try: import kerberos except ImportError: self.skipTest('Channel.query() requires kerberos ' 'to be installed') else: if isinstance(e, kerberos.GSSError): self.skipTest(str(e)) else: raise self.assertTrue(str(new) == self.channel) self.assertTrue(new.ifo == self.channel.split(':', 1)[0]) self.assertTrue(new.sample_rate == units.Quantity(32768, 'Hz')) self.assertTrue(new.texname == self.channel.replace('_', r'\_'))
def test_query(self): try: new = Channel.query(self.channel) except URLError as e: msg = str(e) if "timed out" in msg.lower() or "connection reset" in msg.lower(): self.skipTest(msg) raise except Exception as e: try: import kerberos except ImportError: self.skipTest("Channel.query() requires kerberos " "to be installed") else: if isinstance(e, kerberos.GSSError): self.skipTest(str(e)) else: raise self.assertTrue(str(new) == self.channel) self.assertTrue(new.ifo == self.channel.split(":", 1)[0]) self.assertTrue(new.sample_rate == units.Quantity(32768, "Hz")) self.assertTrue(new.texname == self.channel.replace("_", r"\_"))
def get_channel(channel, find_trend_source=True, timeout=5): """Define a new :class:`~gwpy.detector.channel.Channel` Parameters ---------- channel : `str` name of new channel find_trend_source : `bool`, optional, default: `True` query for raw version of trend channel (trends not in CIS) timeout : `float`, optional, default: `5` number of seconds to wait before connection times out Returns ------- Channel : :class:`~gwpy.detector.channel.Channel` new channel. """ if ' ' in str(channel): name = str(channel) try: type_ = Channel.MATCH.match(name).groupdict()['type'] except AttributeError: type_ = None found = globalv.CHANNELS.sieve(name=name.replace('*', '\*'), exact_match=True) elif ',' in str(channel): name, type_ = str(channel).rsplit(',', 1) found = globalv.CHANNELS.sieve(name=name, type=type_, exact_match=True) else: type_ = isinstance(channel, Channel) and channel.type or None sr = isinstance(channel, Channel) and channel.sample_rate or None name = str(channel) found = globalv.CHANNELS.sieve(name=name, type=type_, sample_rate=sr, exact_match=True) if len(found) == 1: return found[0] elif len(found) > 1: cstrings = ['%s [%s, %s]' % (c.ndsname, c.sample_rate, c.unit) for c in found] raise ValueError("Ambiguous channel request '%s', multiple existing " "channels recovered:\n %s" % (str(channel), '\n '.join(cstrings))) else: matches = list(Channel.MATCH.finditer(name)) # match single raw channel if len(matches) == 1 and not re.search('\.[a-z]+\Z', name): try: raise ValueError("") # XXX: hacky removal of CIS query new = Channel.query(name, timeout=timeout) except (ValueError, urllib2.URLError, GSSError): new = Channel(str(channel)) else: new.name = str(channel) # match single trend elif len(matches) == 1: # set default trend type based on mode if type_ is None and globalv.MODE == SUMMARY_MODE_GPS: type_ = 's-trend' elif type_ is None: type_ = 'm-trend' name += ',%s' % type_ new = Channel(name) if find_trend_source: try: source = get_channel(new.name.rsplit('.')[0]) except ValueError: pass else: new.url = source.url new.unit = source.unit try: new.bits = source.bits except AttributeError: pass try: new.filter = source.filter except AttributeError: pass for param in filter(lambda x: x.endswith('_range') and not hasattr(new, x), vars(source)): setattr(new, param, getattr(source, param)) # determine sample rate for trends if type_ == 'm-trend': new.sample_rate = 1/60. elif type_ == 's-trend': new.sample_rate = 1 # match composite channel else: parts = get_channels([m.group() for m in matches]) new = Channel(name) new.subchannels = parts new._ifo = "".join(set(p.ifo for p in parts if p.ifo)) globalv.CHANNELS.append(new) try: return get_channel(new) except RuntimeError as e: if 'maximum recursion depth' in str(e): raise RuntimeError("Recursion error while access channel " "information for %s" % str(channel)) else: raise