예제 #1
0
파일: window.py 프로젝트: wangyinz/mspass
def WindowData_with_duration(
    d,
    duration,
    t0shift=None,
    object_history=False,
    alg_name="scale",
    alg_id=None,
    dryrun=False,
):
    if duration < 0:
        detailline = "Window duration: {dur}  Data range:  {dst},{det}".format(
            dur=duration, dst=d.t0, det=d.endtime())
        d.elog.log_error(
            "WindowData",
            "Duration is a negative number.\n" + detailline,
            ErrorSeverity.Invalid,
        )
        d.kill()
        return d
    win_start = d.t0 + 1
    win_end = win_start + duration
    if d.dead():
        return d
    twcut = TimeWindow(win_start, win_end)
    if t0shift:
        twcut.shift(t0shift)
    try:
        # This handler duplicates an error test in the WindowData C code but
        # it will be more efficient to handle it here.
        if win_start < d.t0 or win_end > d.endtime():
            detailline = "Window range: {wst},{wet}  Data range:  {dst},{det}".format(
                wst=win_start, wet=win_end, dst=d.t0, det=d.endtime())
            d.elog.log_error(
                "WindowData",
                "Data range is smaller than window range\n" + detailline,
                ErrorSeverity.Invalid,
            )
            d.kill()
            return d
        if isinstance(d, TimeSeries):
            dcut = _WindowData(d, twcut)
            return dcut
        elif isinstance(d, Seismogram):
            dcut = _WindowData3C(d, twcut)
            return dcut
        else:
            raise RuntimeError(
                "WindowData:  Invalid input data type received=" +
                str(type(d)))
    except MsPASSError as err:
        d.log_error("WindowData", str(err), ErrorSeverity.Invalid)
        d.kill()
        return d
예제 #2
0
파일: window.py 프로젝트: wangyinz/mspass
def WindowData(
    d,
    win_start,
    win_end,
    t0shift=None,
    object_history=False,
    alg_name="scale",
    alg_id=None,
    dryrun=False,
):
    """
    Cut data defined by a TimeWindow object.

    Cutting a smaller waveform segment from a larger waveform segment
    is a very common seismic data processing task.   The function is
    a python wrapper to adapt C++ code that accomplishes that task
    to the MsPASS framework.

    Note this function uses one model for being bombproof with a map
    operation.  Any exception that makes the result invalid will cause
    an error message to be posted to the elog attribute of the input
    datum AND the data will be marked dead (killed).

    :param d: is the input data.  d must be either a :class:`mspasspy.ccore.seismic.TimeSeries` or :class:`mspasspy.ccore.seismic.Seismogram`
      object or the function will log an error to d and return a None.
    :param twin_start: defines the start of timeWindow to be cut
    :type twin_start: :class:`float`
    :param twin_end: defines the end of timeWindow to be cut
    :type twin_end: :class:`float`
    :param t0shift: is an optional time shift to apply to the time window.
      This parameter is convenient to avoid conversions to relative time.
      A typical example would be to set t0shift to an arrival time and let
      the window define time relative to that arrival time.  Default is None
      which cause the function to assume twin is to be used directly.
    :param object_history: boolean to enable or disable saving object
      level history.  Default is False.  Note this functionality is
      implemented via the mspass_func_wrapper decorator.
    :param alg_name:   When history is enabled this is the algorithm name
      assigned to the stamp for applying this algorithm.
      Default ("WindowData") should normally be just used.
      Note this functionality is implemented via the mspass_func_wrapper decorator.
    :param ald_id:  algorithm id to assign to history record (used only if
      object_history is set True.)
      Note this functionality is implemented via the mspass_func_wrapper decorator.
    :param dryrun:
      Note this functionality is implemented via the mspass_func_wrapper decorator.
    :param dryrun:
      Note this functionality is implemented via the mspass_func_wrapper decorator.

    :return: copy of d with sample range reduced to twin range.  Returns
      an empty version of the parent data type (default constructor) if
      the input is marked dead
    """
    if d.dead():
        return d
    twcut = TimeWindow(win_start, win_end)
    if t0shift:
        twcut.shift(t0shift)
    try:
        # This handler duplicates an error test in the WindowData C code but
        # it will be more efficient to handle it here.
        if twcut.start < d.t0 or twcut.end > d.endtime():
            detailline = "Window range: {wst},{wet}  Data range:  {dst},{det}".format(
                wst=twcut.start, wet=twcut.end, dst=d.t0, det=d.endtime())
            d.elog.log_error(
                "WindowData",
                "Data range is smaller than window range\n" + detailline,
                ErrorSeverity.Invalid,
            )
            d.kill()
            return d
        if isinstance(d, TimeSeries):
            dcut = _WindowData(d, twcut)
            return dcut
        elif isinstance(d, Seismogram):
            dcut = _WindowData3C(d, twcut)
            return dcut
        else:
            raise RuntimeError(
                "WindowData:  Invalid input data type received=" +
                str(type(d)))
    except MsPASSError as err:
        d.log_error("WindowData", str(err), ErrorSeverity.Invalid)
        d.kill()
        return d