Пример #1
0
def station(url=g_url,
            site=g_default_site,
            majorversion=1,
            parsed=True,
            selection=None,
            **kwargs):

    url = fillurl(url, site, 'station', majorversion)

    params = fix_params(kwargs)

    if selection:
        lst = []
        for k, v in params.items():
            lst.append('%s=%s' % (k, v))

        for (network, station, location, channel, tmin, tmax) in selection:
            if location == '':
                location = '--'

            lst.append(' '.join((network, station, location, channel,
                                 sdatetime(tmin), sdatetime(tmax))))

        post = '\n'.join(lst)
        params = dict(post=post.encode())

    if parsed:
        from pyrocko.io import stationxml
        format = params.get('format', 'xml')
        if format == 'text':
            if params.get('level', 'station') == 'channel':
                return stationxml.load_channel_table(
                    stream=_request(url, **params))
            else:
                raise InvalidRequest('if format="text" shall be parsed, '
                                     'level="channel" is required')

        elif format == 'xml':
            assert params.get('format', 'xml') == 'xml'
            return stationxml.load_xml(stream=_request(url, **params))
        else:
            raise InvalidRequest('format must be "xml" or "text"')
    else:
        return _request(url, **params)
Пример #2
0
def station(url=g_url, site=g_default_site, majorversion=1, parsed=True,
            selection=None, **kwargs):

    url = fillurl(url, site, 'station', majorversion)

    params = fix_params(kwargs)

    if selection:
        lst = []
        for k, v in params.items():
            lst.append('%s=%s' % (k, v))

        for (network, station, location, channel, tmin, tmax) in selection:
            if location == '':
                location = '--'

            lst.append(' '.join((network, station, location, channel,
                                 sdatetime(tmin), sdatetime(tmax))))

        post = '\n'.join(lst)
        params = dict(post=post.encode())

    if parsed:
        from pyrocko.io import stationxml
        format = kwargs.get('format', 'xml')
        if format == 'text':
            if kwargs.get('level', 'station') == 'channel':
                return stationxml.load_channel_table(
                    stream=_request(url, **params))
            else:
                raise InvalidRequest('if format="text" shall be parsed, '
                                     'level="channel" is required')

        elif format == 'xml':
            assert kwargs.get('format', 'xml') == 'xml'
            return stationxml.load_xml(stream=_request(url, **params))
        else:
            raise InvalidRequest('format must be "xml" or "text"')
    else:
        return _request(url, **params)
Пример #3
0
def station(
        site=g_default_site,
        url=g_url,
        majorversion=1,
        timeout=g_timeout,
        check=True,
        selection=None,
        parsed=True,
        **kwargs):

    '''
    Query FDSN web service for station metadata.

    :param site:
        :ref:`Registered site name <registered-site-names>` or full base URL of
        the service (e.g. ``'https://geofon.gfz-potsdam.de'``).
    :type site: str, optional
    :param url:
        URL template (default should work in 99% of cases).
    :type url: str, optional
    :param majorversion:
        Major version of the service to query (always ``1`` at the time of
        writing).
    :type majorversion: int, optional
    :param timeout:
        Network timeout in [s]. Global default timeout can be configured in
        Pyrocko's configuration file under ``fdsn_timeout``.
    :type timeout: float, optional
    :param check:
        If ``True`` arguments are checked against self-description (WADL) of
        the queried web service if available or FDSN specification.
    :type check: bool, optional
    :param selection:
        If given, selection to be queried as a list of tuples
        ``(network, station, location, channel, tmin, tmax)``. Useful for
        detailed queries.
    :type selection: list of tuples, optional
    :param parsed:
        If ``True`` parse received content into
        :py:class:`~pyrocko.io.stationxml.FDSNStationXML`
        object, otherwise return open file handle to raw data stream.
    :type parsed: bool, optional
    :param \\*\\*kwargs:
        Parameters passed to the server (see `FDSN web services specification
        <https://www.fdsn.org/webservices>`_).

    :returns:
        See description of ``parsed`` argument above.

    :raises:
        On failure, :py:exc:`~pyrocko.util.DownloadError` or one of its
        sub-types defined in the :py:mod:`~pyrocko.client.fdsn` module is
        raised.
    '''

    service = 'station'

    if check:
        check_params(service, site, url, majorversion, timeout, **kwargs)

    params = fix_params(kwargs)

    url = fillurl(service, site, url, majorversion, 'query')
    if selection:
        lst = []
        for k, v in params.items():
            lst.append('%s=%s' % (k, v))

        for (network, station, location, channel, tmin, tmax) in selection:
            if location == '':
                location = '--'

            lst.append(' '.join((network, station, location, channel,
                                 sdatetime(tmin), sdatetime(tmax))))

        post = '\n'.join(lst)
        params = dict(post=post.encode())

    if parsed:
        from pyrocko.io import stationxml
        format = kwargs.get('format', 'xml')
        if format == 'text':
            if kwargs.get('level', 'station') == 'channel':
                return stationxml.load_channel_table(
                    stream=_request(url, timeout=timeout, **params))
            else:
                raise InvalidRequest('if format="text" shall be parsed, '
                                     'level="channel" is required')

        elif format == 'xml':
            return stationxml.load_xml(
                stream=_request(url, timeout=timeout, **params))
        else:
            raise InvalidRequest('format must be "xml" or "text"')
    else:
        return _request(url, timeout=timeout, **params)