示例#1
0
def test_read_timeseries(source):
    ts = frread.read_timeseries(
        source,
        "H1:LSC-AS_Q",
    )
    assert ts.name == "H1:LSC-AS_Q"
    assert ts.data.length == 16384 * 60
    assert ts.deltaT == 6.103515625e-05
示例#2
0
def test_read_timeseries_start_duration(
    instart,
    induration,
    outstart,
    outduration,
):
    ts = frread.read_timeseries(
        str(TEST_GWF),
        "H1:LSC-AS_Q",
        start=instart,
        duration=induration,
    )
    assert ts.epoch == outstart
    assert ts.data.length * ts.deltaT == outduration
示例#3
0
文件: core.py 项目: mcoughlin/gwpy
    def read(cls, source, channel, start=None, end=None, datatype=None,
             verbose=False):
        """Read data into a `TimeSeries` from files on disk.

        Parameters
        ----------
        source : `str`, :class:`glue.lal.Cache`, :lalsuite:`LALCache`
            source for data, one of:

            - a filepath for a GWF-format frame file,
            - a filepath for a LAL-format Cache file
            - a Cache object from GLUE or LAL

        channel : `str`, :class:`~gwpy.detector.channel.Channel`
            channel (name or object) to read
        start : :class:`~gwpy.time.Time`, `float`, optional
            start GPS time of desired data
        end : :class:`~gwpy.time.Time`, `float`, optional
            end GPS time of desired data
        datatype : `type`, `numpy.dtype`, `str`, optional
            identifier for desired output data type
        verbose : `bool`, optional
            print verbose output

        Returns
        -------
        TimeSeries
            a new `TimeSeries` containing the data read from disk
        """
        from lalframe import frread
        if isinstance(channel, Channel):
            channel = channel.name
            if datatype is None:
                datatype = channel.dtype
        if start and isinstance(start, Time):
            start = start.gps
        if end and isinstance(end, Time):
            end = end.gps
        if start and end:
            duration = end-start
        elif end:
            raise ValueError("If `end` is given to TimeSeries.read, `start`"
                             "must also be given")
        else:
            duration = None
        lalts = frread.read_timeseries(source, channel, start=start,
                                       duration=duration, datatype=datatype,
                                       verbose=verbose)
        return cls.from_lal(lalts)
示例#4
0
def vec_from_frames(frames, channel, start, stop, verbose=False):
    """
    returns a numpy array of the data inculded in frames between start and stop
    CURRENTLY ASSUME CONTIGUOUS DATA, but we should check this
    """
    if frread is None:
        raise ImportError('could not import lalframe.frread!')
    vecs = []
    dt = 0
    for frame, frame_start, frame_dur in frames:
        if verbose:
            print(frame)
        s = max(frame_start, start)
        d = min(frame_start + frame_dur, stop) - s
        if d > 0:
            out = frread.read_timeseries(frame, channel, start=s, duration=d)
            vecs.append(out.data.data)
            dt = out.deltaT
    vec = np.concatenate(vecs)
    return vec, dt
示例#5
0
def  readframedata(frameCache, channelName, frameType, startTime, stopTime,
		   allowRedundantFlag, debugLevel):
  #READFRAMEDATA Read a single channel of data from frame files
  #
  #READFRAMEDATA finds and retrieves the requested time series data from a
  #set of frame files.  The data is specified by the frame file type,
  #channel name, start time, and duration or stop time.  The necessary frame
  #files are located using a file name caching scheme.
  #%
  #usage: [data, sampleFrequency, time] = ...
  #readframedata(frameCache, channelName, frameType, ...
  #startTime, stopTime, allowRedundantFlag, ...
  #debugLevel);
  #%
  #frameCache           file name cache
  #channelName          channel name
  #frameType            frame file type
  #startTime            GPS start time
  #stopTime             GPS stop time (or duration)
  #allowRedundantFlag   permit redundant frame data
  #debugLevel           verboseness of debug output
  #%
  #data                 data vector
  #sampleFrequency      sample frequency [Hz]
  #time                 time vector
  #%
  #READFRAMEDATA expects frame cache information in the format produced by
  #LOADFRAMECACHE which contains the site, frame type, duration, time, and
  #location of available frame data files.
  #%
  #The requested site designator is determined from the first character of
  #the requested channel name.  The frame file type may contain wildcards.
  #Unless redundant frame data is permitted, it is an error if the same
  #frame file appears more than once in the frame cache file.  If redundant
  #frame data is permitted, the first matching frame file from the cache is
  #used.  It is always an error if two frame files overlap but do not cover
  #the same time range or differ in type.  By default, redundant frame data
  #is permitted.
  #%
  #READFRAMEDATA retrieves data from the requested start time up to, but not
  #including, the requested stop time, such that stop minus start seconds
  #are retrieved.  Alternatively, the desired duration in seconds may be
  #specified instead of the GPS stop time parameter.
  #%
  #The resulting time series is returned as two row vectors containing the
  #data sequence and the corresponding GPS timestamps, as well as the scalar
  #sample frequency.  To protect against roundoff error, an integer sample
  #frequency is assumed.
  #%
  #If it is unable to load the requested data, READFRAMEDATA returns empty
  #result vectors and zero sample frequency as well as a warning if
  #debugLevel is set to 1 or higher.  By default, a debugLevel of unity is
  #assumed.
  #%
  #READFRAMEDATA is built on top of the FRGETVECT function from the FrameL
  #library, which is available from the following URL.
  #%
  #
  #%
  #
  #
  #Shourov K. Chatterji <*****@*****.**>
  #Jameson Rollins <*****@*****.**>
  #
  #$Id: readframedata.m 2326 2009-09-21 08:37:42Z jrollins $
  #
  # Rewritten in Python by Sudarshan Ghonge <*****@*****.**>
  # 2015-09-04
  # 
  # Update 217-11-30 Ported to gwpy. The pipeline now uses lal-cache and 
  # now does away with the need of the functions loadframecache

  #
  # if specified stop time precedes start time,
  if(stopTime<startTime):
    # treat stop time as a duration
    stopTime = startTime + stopTime
  
  # determine site designator from channel name
  site = channelName[0]
  
  #if specified frame cache is invalid
  if(not is_non_zero_file(frameCache)):
    if(debugLevel>=1):
      # Issue warning
      print 'Warning: Empty lal cache file ' + frameCache 
    
    data = []
    time = []
    sampleFrequency = 0
    return [data, sampleFrequency]
    # return empty results
  data = np.array([])
  time = np.array([])
  sampleFrequency = None

  try:
     #outputStruct  = TS.read(frameCache, channelName, start=startTime, end=stopTime, format='gwf.lalframe')
     #outputStruct = frame.read_frame(frameCache, channelName, start_time=startTime, end_time=stopTime, check_integrity=False)
     outputStruct = fr.read_timeseries(frameCache, channelName, start=startTime, duration = stopTime-startTime)
     readData = np.array(outputStruct.data.data)
     readSampleFrequency = 1/outputStruct.deltaT
  except Exception as inst:
     readData=[]
     if(debugLevel>=1):
       print  inst.message
  if((len(readData)==0) | np.any(np.isnan(readData))):
    if(debugLevel>=1):
      print 'Warning: Error reading %s from %s.' %(channelName, frameCache)
    data = []
    time = []
    sampleFrequency = 0
    return [data, sampleFrequency]
  if(sampleFrequency==None):
    sampleFrequency = readSampleFrequency
  elif(sampleFrequency!=readSampleFrequency):
    if(debugLevel>=1):
      print 'Warning: Inconsistent sample frequency for %s in frameCache.' %(channelname, frameCache)
    data = []
    time = []
    sampleFrequency = 0
    return [data, sampleFrequency]

  data = np.append(data, readData)

  return [data, sampleFrequency]
示例#6
0
def test_read_timeseries_error(inputs, message):
    with pytest.raises(RuntimeError) as exc:
        frread.read_timeseries(*inputs)
    assert str(exc.value) == message