Exemplo n.º 1
0
    def getWaveform(self, network, station, location, channel, starttime,
                    endtime, format="MSEED"):
        """
        Retrieves waveform data from the NERIES Web service and returns a ObsPy
        Stream object.

        :type network: str
        :param network: Network code, e.g. ``'BW'``.
        :type station: str
        :param station: Station code, e.g. ``'MANZ'``.
        :type location: str
        :param location: Location code, e.g. ``'01'``. Location code may
            contain wild cards.
        :type channel: str
        :param channel: Channel code, e.g. ``'EHE'``. . Channel code may
            contain wild cards.
        :type starttime: :class:`~obspy.core.utcdatetime.UTCDateTime`
        :param starttime: Start date and time.
        :type endtime: :class:`~obspy.core.utcdatetime.UTCDateTime`
        :param endtime: End date and time.
        :type format: ``'FSEED'`` or ``'MSEED'``, optional
        :param format: Output format. Either as full SEED (``'FSEED'``) or
            Mini-SEED (``'MSEED'``) volume. Defaults to ``'MSEED'``.
        :return: ObsPy :class:`~obspy.core.stream.Stream` object.

        .. rubric:: Example

        >>> from obspy.neries import Client
        >>> client = Client(user='******')
        >>> dt = UTCDateTime("2009-04-01T00:00:00")
        >>> st = client.getWaveform("NL", "WIT", "", "BH*", dt, dt+30)
        >>> print st  # doctest: +ELLIPSIS
        3 Trace(s) in Stream:
        NL.WIT..BHZ | 2009-04-01T00:00:00.010200Z - ... | 40.0 Hz, 1201 samples
        NL.WIT..BHN | 2009-04-01T00:00:00.010200Z - ... | 40.0 Hz, 1201 samples
        NL.WIT..BHE | 2009-04-01T00:00:00.010200Z - ... | 40.0 Hz, 1201 samples
        """
        tf = NamedTemporaryFile()
        self.saveWaveform(tf._fileobj, network, station, location, channel,
                          starttime, endtime, format=format)
        # read stream using obspy.mseed
        tf.seek(0)
        try:
            stream = read(tf.name, 'MSEED')
        except:
            stream = Stream()
        tf.close()
        # remove temporary file:
        try:
            os.remove(tf.name)
        except:
            pass
        # trim stream
        stream.trim(starttime, endtime)
        return stream
Exemplo n.º 2
0
def make_irisrequest(station, begin, end, channel, loc):

    print 'IRISREQUEST FOR STATION ', station

    net, sta = station.split('_')
    url = 'http://service.iris.edu/fdsnws/dataselect/1/query?'
    st = Stream()

    for i in channel:

        parameter = urllib.urlencode({
            'net': net,
            'sta': sta,
            'loc': loc,
            #'cha': i,                               #hs v2
            'starttime': begin,
            'endtime': end,
            'nodata': '404',
        })

        u = ('%s%s') % (url, parameter)
        saveUrl(station, u)

        #data = urllib.urlopen(u).read()                          #hs
        try:
            data = urllib.urlopen(u).read()  #hs
        except:
            continue

        #tf  = NamedTemporaryFile()                               #hs
        tf = NamedTemporaryFile(suffix='xtmp')  #hs
        tf.write(data)
        tf.seek(0)

        t = isMSEED(tf.name)

        if t == True:
            st += read(tf.name, 'MSEED')

        tf.close()
        os.remove(tf.name)
        break  #hs v2

#       if t == True:     size = proof_file_v3(st,channel)      #hs
    if len(st) > 0: size = proof_file_v3(st, channel)  #hs
    else: size = 0

    print 'SIZE: ----> ', size
    return size
Exemplo n.º 3
0
def make_irisrequest(station, begin, end, channel, loc):

    logger.info('\033[31m IRISREQUEST \033[0m\n' % ())

    net, sta = station.split('_')
    url = 'http://service.iris.edu/fdsnws/dataselect/1/query?'
    st = Stream()
    for i in channel:
        parameter = urllib.urlencode({
            'net': net,
            'sta': sta,
            'loc': loc,
            'cha': i,
            'starttime': begin,
            'endtime': end,
            'nodata': '404',
        })
        u = ('%s%s') % (url, parameter)
        data = urllib.urlopen(u).read()
        tf = NamedTemporaryFile()
        tf.write(data)
        tf.seek(0)
        st += read(tf.name, 'MSEED')
        tf.close()

    print st
    output = ('%s.%s-IRIS.mseed') % (net, sta)
    st.write(output, format='MSEED')

    size = proof_file_v2(output, channel)
    #print 'SIZE: ----> ',size
    try:
        #os.remove(fname)
        os.remove(output)
    except:
        print ''

    return size
Exemplo n.º 4
0
    def getWaveform(self,
                    network,
                    station,
                    location,
                    channel,
                    starttime,
                    endtime,
                    format="MSEED"):
        """
        Retrieves waveform data from the NERIES Web service and returns a ObsPy
        Stream object.

        :type network: str
        :param network: Network code, e.g. ``'BW'``.
        :type station: str
        :param station: Station code, e.g. ``'MANZ'``.
        :type location: str
        :param location: Location code, e.g. ``'01'``. Location code may
            contain wild cards.
        :type channel: str
        :param channel: Channel code, e.g. ``'EHE'``. . Channel code may
            contain wild cards.
        :type starttime: :class:`~obspy.core.utcdatetime.UTCDateTime`
        :param starttime: Start date and time.
        :type endtime: :class:`~obspy.core.utcdatetime.UTCDateTime`
        :param endtime: End date and time.
        :type format: ``'FSEED'`` or ``'MSEED'``, optional
        :param format: Output format. Either as full SEED (``'FSEED'``) or
            Mini-SEED (``'MSEED'``) volume. Defaults to ``'MSEED'``.
        :return: ObsPy :class:`~obspy.core.stream.Stream` object.

        .. rubric:: Example

        >>> from obspy.neries import Client
        >>> client = Client(user='******')
        >>> dt = UTCDateTime("2009-04-01T00:00:00")
        >>> st = client.getWaveform("NL", "WIT", "", "BH*", dt, dt+30)
        >>> print st  # doctest: +ELLIPSIS
        3 Trace(s) in Stream:
        NL.WIT..BHZ | 2009-04-01T00:00:00.010200Z - ... | 40.0 Hz, 1201 samples
        NL.WIT..BHN | 2009-04-01T00:00:00.010200Z - ... | 40.0 Hz, 1201 samples
        NL.WIT..BHE | 2009-04-01T00:00:00.010200Z - ... | 40.0 Hz, 1201 samples
        """
        tf = NamedTemporaryFile()
        self.saveWaveform(tf._fileobj,
                          network,
                          station,
                          location,
                          channel,
                          starttime,
                          endtime,
                          format=format)
        # read stream using obspy.mseed
        tf.seek(0)
        try:
            stream = read(tf.name, 'MSEED')
        except:
            stream = Stream()
        tf.close()
        # remove temporary file:
        try:
            os.remove(tf.name)
        except:
            pass
        # trim stream
        stream.trim(starttime, endtime)
        return stream