Exemple #1
0
def get_waveforms(session, wfdisc, station=None, channel=None, starttime=None, 
        endtime=None, wfids=None):
    """
    Get waveforms.

    Parameters
    ----------
    session : sqlalchemy.orm.Session instance
        Must be bound.
    wfdisc : mapped Wfdisc table class
    station, channel : str, optional
        Desired station, channel code strings
    starttimes, endtimes : float, optional
        Epoch start times, end times.  
        Traces will be cut to these times.
    wfids : iterable of int, optional
        Wfdisc wfids.  Obviates the above arguments and just returns full Wfdisc
        row waveforms.

    Returns
    -------
    obspy.Stream
        Traces are merged and cut to requested times.

    """
    #TODO: add evids= option?, use with stawin= option in .execute method?
    #TODO: implement get_arrivals if arrivals=True
    Wfdisc = wfdisc

    st = Stream()
    if not wfids:
        t1 = float(starttime)
        t2 = float(endtime)
        sta = station
        chan = channel

        t1_utc = UTCDateTime(float(t1))
        t2_utc = UTCDateTime(float(t2))

        wfs = get_wfdisc_rows( session,Wfdisc, sta, chan, t1, t2)

        #TODO: do arrival stuff here
        for wf in wfs:
            try:
                tr = wfdisc2trace(wf)
                tr.trim(t1_utc, t2_utc)
                st.append(tr)
            except AttributeError:
                #tr is None b/c data couldn't be read
                pass
    else:
        wfs = get_wfdisc_rows( session,Wfdisc, wfids=wfids)
        for wf in wfs:
            try:
                tr = wfdisc2trace(wf)
                st.append(tr)
            except AttributeError:
                pass

    return st
Exemple #2
0
    def to_trace(self):
        """
        Read the wfdisc line into a Trace instance.  Minimal header.

        Returns
        -------
        obspy.Trace

        """
        return wfdisc2trace(self)
Exemple #3
0
    def to_trace(self):
        """
        Read the wfdisc line into a Trace instance.  Minimal header.

        Returns
        -------
        obspy.Trace

        """
        return wfdisc2trace(self)
Exemple #4
0
def get_waveforms(session,
                  wfdisc,
                  station=None,
                  channel=None,
                  starttime=None,
                  endtime=None,
                  wfids=None):
    """
    Get waveforms.

    Parameters
    ----------
    session : sqlalchemy.orm.Session instance
        Must be bound.
    wfdisc : mapped Wfdisc table class
    station, channel : str, optional
        Desired station, channel code strings
    starttimes, endtimes : float, optional
        Epoch start times, end times.  
        Traces will be cut to these times.
    wfids : iterable of int, optional
        Wfdisc wfids.  Obviates the above arguments and just returns full Wfdisc
        row waveforms.

    Returns
    -------
    obspy.Stream
        Traces are merged and cut to requested times.

    """
    #TODO: add evids= option?, use with stawin= option in .execute method?
    #TODO: implement get_arrivals if arrivals=True
    Wfdisc = wfdisc

    st = Stream()
    if not wfids:
        t1 = float(starttime)
        t2 = float(endtime)
        sta = station
        chan = channel

        t1_utc = UTCDateTime(float(t1))
        t2_utc = UTCDateTime(float(t2))

        wfs = get_wfdisc_rows(session, Wfdisc, sta, chan, t1, t2)

        #TODO: do arrival stuff here
        for wf in wfs:
            try:
                tr = wfdisc2trace(wf)
                tr.trim(t1_utc, t2_utc)
                st.append(tr)
            except AttributeError:
                #tr is None b/c data couldn't be read
                pass
    else:
        wfs = get_wfdisc_rows(session, Wfdisc, wfids=wfids)
        for wf in wfs:
            try:
                tr = wfdisc2trace(wf)
                st.append(tr)
            except AttributeError:
                pass

    return st
Exemple #5
0
def get_waveforms(session, wfdisc, station=None, channel=None, starttime=None,
                  endtime=None, wfids=None, tol=None):
    """
    Request waveforms.

    Parameters
    ----------
    session : sqlalchemy.orm.Session instance
        Must be bound.
    wfdisc : mapped Wfdisc table class
    station, channel : str, optional
        Desired station, channel code strings
    starttimes, endtimes : float, optional
        Epoch start times, end times.
        Traces will be cut to these times.
    wfids : iterable of int, optional
        Wfdisc wfids.  Obviates the above arguments and just returns full Wfdisc
        row waveforms.
    tol : float
        If provided, a warning is fired if any Trace is not within tol seconds
        of starttime and endtime.

    Returns
    -------
    obspy.Stream
        Traces are merged and cut to requested times.

    Raises
    ------
    ValueError
        Returned Stream contains trace start/end times outside of the tolerance.

    """
    # TODO: add evids= option?, use with stawin= option in .execute method?
    # TODO: implement get_arrivals if arrivals=True
    Wfdisc = wfdisc

    st = Stream()
    if wfids:
        station = channel = starttime = endtime = None

    starttime = float(starttime) if starttime is not None else None
    endtime = float(endtime) if endtime is not None else None

    t1_utc = UTCDateTime(starttime) if starttime is not None else None
    t2_utc = UTCDateTime(endtime) if endtime is not None else None

    wfs = get_wfdisc_rows(session, Wfdisc, station, channel, starttime, endtime,
                          wfids=wfids)
    # TODO:
    # Maybe a warning can be fired if the get_waveforms(session, Wfdisc,
    # starttime=t_S, endtime=t_E) function gets data that does not cover
    # starttime endtime (within a tolerance)
    for wf in wfs:
        try:
            tr = wfdisc2trace(wf)
        except IOError:
            # can't read file
            tr = None

        if tr:
            # None utc times will pass through
            tr.trim(t1_utc, t2_utc)
            st.append(tr)
            # TODO: do arrival stuff here?

    if all([tol, starttime, endtime]):
        starttimes, endtimes = zip(*[(t.stats.starttime, t.stats.endtime) for t in st])
        min_t = float(min(starttimes))
        max_t = float(max(endtimes))
        if (abs(min_t - starttime) > tol) or (abs(max_t - endtime) > tol):
            msg = "Trace times are outside of tolerance: {}".format(tol)
            # XXX: change this to a real Pisces exception
            raise ValueError(msg)


    return st
Exemple #6
0
def get_waveforms(session,
                  wfdisc,
                  station=None,
                  channel=None,
                  starttime=None,
                  endtime=None,
                  wfids=None,
                  tol=None):
    """
    Request waveforms.

    Parameters
    ----------
    session : sqlalchemy.orm.Session instance
        Must be bound.
    wfdisc : mapped Wfdisc table class
    station, channel : str, optional
        Desired station, channel code strings
    starttimes, endtimes : float, optional
        Epoch start times, end times.
        Traces will be cut to these times.
    wfids : iterable of int, optional
        Wfdisc wfids.  Obviates the above arguments and just returns full Wfdisc
        row waveforms.
    tol : float
        If provided, a warning is fired if any Trace is not within tol seconds
        of starttime and endtime.

    Returns
    -------
    obspy.Stream
        Traces are merged and cut to requested times.

    Raises
    ------
    ValueError
        Returned Stream contains trace start/end times outside of the tolerance.

    """
    # TODO: add evids= option?, use with stawin= option in .execute method?
    # TODO: implement get_arrivals if arrivals=True
    Wfdisc = wfdisc

    st = Stream()
    if wfids:
        station = channel = starttime = endtime = None

    starttime = float(starttime) if starttime is not None else None
    endtime = float(endtime) if endtime is not None else None

    t1_utc = UTCDateTime(starttime) if starttime is not None else None
    t2_utc = UTCDateTime(endtime) if endtime is not None else None

    wfs = get_wfdisc_rows(session,
                          Wfdisc,
                          station,
                          channel,
                          starttime,
                          endtime,
                          wfids=wfids)
    # TODO:
    # Maybe a warning can be fired if the get_waveforms(session, Wfdisc,
    # starttime=t_S, endtime=t_E) function gets data that does not cover
    # starttime endtime (within a tolerance)
    for wf in wfs:
        try:
            tr = wfdisc2trace(wf)
        except IOError:
            # can't read file
            tr = None

        if tr:
            # None utc times will pass through
            tr.trim(t1_utc, t2_utc)
            st.append(tr)
            # TODO: do arrival stuff here?

    if all([tol, starttime, endtime]):
        starttimes, endtimes = zip(*[(t.stats.starttime, t.stats.endtime)
                                     for t in st])
        min_t = float(min(starttimes))
        max_t = float(max(endtimes))
        if (abs(min_t - starttime) > tol) or (abs(max_t - endtime) > tol):
            msg = "Trace times are outside of tolerance: {}".format(tol)
            # XXX: change this to a real Pisces exception
            raise ValueError(msg)

    return st