How to use the gwpy.segments.Segment function in gwpy

To help you get started, we’ve selected a few gwpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gwpy / gwpy / gwpy / io / cache.py View on Github external
except ValueError as exc:
        exc.args = ('Failed to parse {!r} as LIGO-T050017-compatible '
                    'filename'.format(name),)
        raise
    start = float(start)
    dur = dur.rsplit('.', 1)[0]
    while True:  # recursively remove extension components
        try:
            dur = float(dur)
        except ValueError:
            if '.' not in dur:
                raise
            dur = dur.rsplit('.', 1)[0]
        else:
            break
    return obs, desc, Segment(start, start+dur)
github gwpy / gwpy / gwpy / table / io / hacr.py View on Github external
# get database names and loop over each on
    databases = get_database_names(start, end)
    rows = []
    for db in databases:
        conn = connect(db, **connectkwargs)
        cursor = conn.cursor()
        # find process ID(s) for this channel
        pids = query("select process_id, gps_start, gps_stop "
                     "from job where monitorName = %r and channel = %r"
                     % (monitor, str(channel)), connection=conn)
        for p, s, e in pids:
            # validate this process id
            if pid is not None and int(p) != int(pid):
                continue
            tspan = Segment(float(s), float(e))
            if not tspan.intersects(span):
                continue
            # execute trigger query
            q = ('select %s from mhacr where process_id = %d and '
                 'gps_start > %s and gps_start < %d %s order by gps_start asc'
                 % (', '.join(columns), int(p), span[0], span[1],
                    selectionstr))
            n = cursor.execute(q)
            if n == 0:
                continue
            # get new events, convert to recarray, and append to table
            rows.extend(cursor.fetchall())
    return EventTable(rows=rows, names=columns)
github gwpy / gwpy / gwpy / timeseries / timeseries.py View on Github external
overlap = 0
            elif overlap is None:
                overlap = recommended_overlap(window) * fftlength
            whiten = self.asd(fftlength, overlap, window=window, **asd_kw)
        if isinstance(whiten, FrequencySeries):
            # apply whitening (with error on division by zero)
            with numpy.errstate(all='raise'):
                data = self.whiten(asd=whiten, fduration=fduration,
                                   highpass=highpass)
        else:
            data = self
        # determine search window
        if gps is None:
            search = None
        elif search is not None:
            search = Segment(gps-search/2, gps+search/2) & self.span
        qgram, _ = qtransform.q_scan(
            data, frange=frange, qrange=qrange, norm=norm,
            mismatch=mismatch, search=search)
        return qgram.interpolate(
            tres=tres, fres=fres, logf=logf, outseg=outseg)
github gwpy / gwpy / gwpy / io / cache.py View on Github external
the path name of a file

    Returns
    -------
    segment : `~gwpy.segments.Segment`
        the ``[start, stop)`` GPS segment covered by the given file

    Notes
    -----
    |LIGO-T050017|_ declares a filenaming convention that includes
    documenting the GPS start integer and integer duration of a file,
    see that document for more details.
    """
    from ..segments import Segment
    try:  # CacheEntry
        return Segment(filename.segment)
    except AttributeError:  # file path (str)
        return filename_metadata(filename)[2]
github gwpy / gwpy / gwpy / segments / io / segwizard.py View on Github external
def _format_segment(tokens, strict=True, gpstype=LIGOTimeGPS):
    """Format a list of tokens parsed from an ASCII file into a segment.
    """
    try:
        start, end, dur = tokens
    except ValueError:  # two-columns
        return Segment(map(gpstype, tokens))
    seg = Segment(gpstype(start), gpstype(end))
    if strict and abs(seg) != gpstype(dur):
        raise ValueError("segment {0!r} has incorrect duration".format(seg))
    return seg
github gwpy / gwpy / gwpy / timeseries / io / cache.py View on Github external
# sort cache
    try:
        cache.sort(key=file_segment)  # sort
    except ValueError:
        # if this failed, then the sieving will also fail, but lets proceed
        # anyway, since the user didn't actually ask us to do this (but
        # its a very good idea)
        return cache

    # sieve cache
    if start is None:  # start time of earliest file
        start = file_segment(cache[0])[0]
    if end is None:  # end time of latest file
        end = file_segment(cache[-1])[-1]
    return sieve(cache, segment=Segment(start, end))
github gwpy / gwpy / gwpy / timeseries / timeseries.py View on Github external
overlap = 0
            elif overlap is None:
                overlap = recommended_overlap(window) * fftlength
            whiten = self.asd(fftlength, overlap, window=window, **asd_kw)
        if isinstance(whiten, FrequencySeries):
            # apply whitening (with error on division by zero)
            with numpy.errstate(all='raise'):
                data = self.whiten(asd=whiten, fduration=fduration,
                                   highpass=highpass)
        else:
            data = self
        # determine search window
        if gps is None:
            search = None
        elif search is not None:
            search = Segment(gps-search/2, gps+search/2) & self.span
        qgram, _ = qtransform.q_scan(
            data, frange=frange, qrange=qrange, norm=norm,
            mismatch=mismatch, search=search)
        return qgram.interpolate(
            tres=tres, fres=fres, logf=logf, outseg=outseg)