Esempio n. 1
0
def equality_data_to_seglist(data, start, dt, equality, invert=False):
	"""
	Apply equality test threshold to data and parse the result into a segment list.
	"""
	# FIXME: numpy operations?
	if invert:
		return from_bitstream([d != equality for d in data], start, dt)
	else:
		return from_bitstream([d == equality for d in data], start, dt)
Esempio n. 2
0
def equality_data_to_seglist(data, start, dt, equality, invert=False):
    """
	Apply equality test threshold to data and parse the result into a segment list.
	"""
    # FIXME: numpy operations?
    if invert:
        return from_bitstream([d != equality for d in data], start, dt)
    else:
        return from_bitstream([d == equality for d in data], start, dt)
Esempio n. 3
0
def threshold_data_to_seglist(data, start, dt, min_threshold=None, max_threshold=None, invert=False):
	"""
	Apply min and max threshold to data and parse the result into a segment list. If invert, then invert, tautologies not withstanding.
	"""
	if min_threshold is None:
		min_threshold = -float("inf")
	if max_threshold is None:
		max_threshold = float("inf")
	if invert:
		return from_bitstream([min_threshold > d or d > max_threshold for d in data], start, dt)
	else:
		return from_bitstream([min_threshold < d and d < max_threshold for d in data], start, dt)
Esempio n. 4
0
def mask_data_to_seglist(data, start, dt, mask_on=0x1, mask_off=0x0):
    """
	Apply bitmask to data and parse the result into a segment list.
	"""
    # FIXME: numpy operations?
    return from_bitstream([(d & mask_on) & (not (d & mask_off)) for d in data],
                          start, dt)
Esempio n. 5
0
def threshold_data_to_seglist(data,
                              start,
                              dt,
                              min_threshold=None,
                              max_threshold=None,
                              invert=False):
    """
	Apply min and max threshold to data and parse the result into a segment list. If invert, then invert, tautologies not withstanding.
	"""
    if min_threshold is None:
        min_threshold = -float("inf")
    if max_threshold is None:
        max_threshold = float("inf")
    if invert:
        return from_bitstream(
            [min_threshold > d or d > max_threshold for d in data], start, dt)
    else:
        return from_bitstream(
            [min_threshold < d and d < max_threshold for d in data], start, dt)
Esempio n. 6
0
    def to_dqflag(self,
                  name=None,
                  minlen=1,
                  dtype=float,
                  round=False,
                  label=None,
                  description=None):
        """Convert this `StateTimeSeries` into a
        `~gwpy.segments.DataQualityFlag`

        Each contiguous set of `True` values are grouped as a
        `~gwpy.segments.Segment` running from the GPS time the first
        found `True`, to the GPS time of the next `False` (or the end
        of the series)

        Parameters
        ----------
        minlen : `int`, optional, default: 1
            minimum number of consecutive `True` values to identify as a
            `~gwpy.segments.Segment`. This is useful to ignore single
            bit flips, for example.

        dtype : `type`, `callable`, default: `float`
            output segment entry type, can pass either a type for simple
            casting, or a callable function that accepts a float and returns
            another numeric type

        round : `bool`, optional, default: False
            choose to round each `~gwpy.segments.Segment` to its
            inclusive integer boundaries

        Returns
        -------
        dqflag : `~gwpy.segments.DataQualityFlag`
            a segment representation of this `StateTimeSeries`, the span
            defines the `known` segments, while the contiguous `True`
            sets defined each of the `active` segments
        """
        from ..segments import (Segment, SegmentList, DataQualityFlag)
        start = self.x0.value
        dt = self.dx.value
        active = from_bitstream(self.value, start, dt, minlen=int(minlen))
        if dtype is not float:
            active = active.__class__(
                [Segment(dtype(s[0]), dtype(s[1])) for s in active])
        known = SegmentList([self.span])
        out = DataQualityFlag(name=name or self.name,
                              active=active,
                              known=known,
                              label=label or self.name,
                              description=description)
        if round:
            out = out.round()
        return out.coalesce()
Esempio n. 7
0
    def to_dqflag(self, name=None, minlen=1, dtype=None, round=False,
                  label=None, description=None):
        """Convert this series into a `~gwpy.segments.DataQualityFlag`

        Each contiguous set of `True` values are grouped as a
        `~gwpy.segments.Segment` running from the GPS time the first
        found `True`, to the GPS time of the next `False` (or the end
        of the series)

        Parameters
        ----------
        minlen : `int`, optional, default: 1
            minimum number of consecutive `True` values to identify as a
            `~gwpy.segments.Segment`. This is useful to ignore single
            bit flips, for example.

        dtype : `type`, `callable`
            output segment entry type, can pass either a type for simple
            casting, or a callable function that accepts a float and returns
            another numeric type, defaults to the `dtype` of the time index

        round : `bool`, optional, default: False
            choose to round each `~gwpy.segments.Segment` to its
            inclusive integer boundaries

        Returns
        -------
        dqflag : `~gwpy.segments.DataQualityFlag`
            a segment representation of this `StateTimeSeries`, the span
            defines the `known` segments, while the contiguous `True`
            sets defined each of the `active` segments
        """
        from glue.segmentsUtils import from_bitstream
        from ..segments import (Segment, SegmentList, DataQualityFlag)

        # format dtype
        if dtype is None:
            dtype = self.t0.dtype.type
        elif isinstance(dtype, numpy.dtype):
            dtype = dtype.type
        start = dtype(self.t0.value)  # <-- sets the dtype for the segments
        dt = self.dt.value

        # build segmentlists
        active = from_bitstream(self.value, start, dt, minlen=int(minlen))
        known = SegmentList([Segment(*map(dtype, self.span))])

        # build flag and return
        out = DataQualityFlag(name=name or self.name, active=active,
                              known=known, label=label or self.name,
                              description=description)
        if round:
            out = out.round()
        return out.coalesce()
Esempio n. 8
0
    def to_dqflag(self, name=None, minlen=1, dtype=float, round=False,
                  label=None, description=None):
        """Convert this `StateTimeSeries` into a
        `~gwpy.segments.DataQualityFlag`

        Each contiguous set of `True` values are grouped as a
        `~gwpy.segments.Segment` running from the GPS time the first
        found `True`, to the GPS time of the next `False` (or the end
        of the series)

        Parameters
        ----------
        minlen : `int`, optional, default: 1
            minimum number of consecutive `True` values to identify as a
            `~gwpy.segments.Segment`. This is useful to ignore single
            bit flips, for example.

        dtype : `type`, `callable`, default: `float`
            output segment entry type, can pass either a type for simple
            casting, or a callable function that accepts a float and returns
            another numeric type

        round : `bool`, optional, default: False
            choose to round each `~gwpy.segments.Segment` to its
            inclusive integer boundaries

        Returns
        -------
        dqflag : `~gwpy.segments.DataQualityFlag`
            a segment representation of this `StateTimeSeries`, the span
            defines the `known` segments, while the contiguous `True`
            sets defined each of the `active` segments
        """
        from ..segments import (Segment, SegmentList, DataQualityFlag)
        start = self.x0.value
        dt = self.dx.value
        active = from_bitstream(self.value, start, dt, minlen=int(minlen))
        if dtype is not float:
            active = active.__class__([Segment(dtype(s[0]), dtype(s[1])) for
                                       s in active])
        known = SegmentList([self.span])
        out = DataQualityFlag(name=name or self.name, active=active,
                              known=known, label=label or self.name,
                              description=description)
        if round:
            out = out.round()
        return out.coalesce()
Esempio n. 9
0
def mask_data_to_seglist(data, start, dt, mask_on=0x1, mask_off=0x0):
	"""
	Apply bitmask to data and parse the result into a segment list.
	"""
	# FIXME: numpy operations?
	return from_bitstream([(d & mask_on) & (not(d & mask_off)) for d in data], start, dt)