def load_events(filename, format='detect'): '''Read events file. :param filename: name of file as str :param format: file format: ``'detect'``, ``'basic'``, or ``'yaml'`` :returns: list of :py:class:`Event` objects ''' if format == 'detect': fmt = detect_format(filename) assert fmt in ('yaml', 'basic') if fmt == 'yaml': from pyrocko import guts events = [ ev for ev in guts.load_all(filename=filename) if isinstance(ev, Event) ] return events elif fmt == 'basic': return list(Event.load_catalog(filename)) else: from pyrocko.io.io_common import FileLoadError FileLoadError('unknown event file format: %s' % fmt)
def load_xml(*args, **kwargs): wadl = guts.load_xml(*args, **kwargs) if not isinstance(wadl, Application): FileLoadError('Not a WADL file.') return wadl
def load_stations(filename, format='detect'): '''Read stations file. :param filename: filename :returns: list of :py:class:`Station` objects ''' if format == 'detect': format = detect_format(filename) if format == 'yaml': from pyrocko import guts stations = [ st for st in guts.load_all(filename=filename) if isinstance(st, Station) ] return stations elif format == 'basic': stations = [] f = open(filename, 'r') station = None channel_names = [] for (iline, line) in enumerate(f): toks = line.split(None, 5) if line.strip().startswith('#') or line.strip() == '': continue if len(toks) == 5 or len(toks) == 6: net, sta, loc = toks[0].split('.') lat, lon, elevation, depth = [float(x) for x in toks[1:5]] if len(toks) == 5: name = '' else: name = toks[5].rstrip() station = Station(net, sta, loc, lat, lon, elevation=elevation, depth=depth, name=name) stations.append(station) channel_names = [] elif len(toks) == 4 and station is not None: name, azi, dip, gain = (toks[0], float_or_none(toks[1]), float_or_none(toks[2]), float(toks[3])) if name in channel_names: logger.warning('redefined channel! (line: %i, file: %s)' % (iline + 1, filename)) else: channel_names.append(name) channel = Channel(name, azimuth=azi, dip=dip, gain=gain) station.add_channel(channel) else: logger.warning('skipping invalid station/channel definition ' '(line: %i, file: %s' % (iline + 1, filename)) f.close() return stations else: from pyrocko.io.io_common import FileLoadError raise FileLoadError('unknown event file format: %s' % format)