Exemplo n.º 1
0
def interpolateToSecond(timeData: TimeData, inplace: bool = True) -> TimeData:
    """Interpolate data to be on the second

    Some formats of time data (e.g. SPAM) do not start on the second with their sampling. This method interpolates so that sampling starts on the second and improves interoperability with other recording formats. 

    Parameters
    ----------
    timeData : TimeData
        Time data to interpolate onto the second
    inplace :  bool, optional
        Whether to do the interpolation inplace or not. Default is True.
    
    Returns
    -------
    TimeData
        Time data interpolated to start on the second
    """
    startTimeInterp, numSamplesInterp, dataInterp = interpolateToSecondData(
        timeData.data, timeData.sampleFreq, timeData.startTime
    )
    if not inplace:
        timeData = timeData.copy()
    timeData.numSamples = numSamplesInterp
    timeData.startTime = startTimeInterp
    # calculate end timeEnd
    timeData.stopTime = timeData.startTime + timedelta(
        seconds=(1.0 / timeData.sampleFreq) * (timeData.numSamples - 1)
    )
    timeData.data = dataInterp
    timeData.addComment(
        "Time data interpolated to nearest second. New start time {}, new end time {}, new number of samples {} ".format(
            timeData.startTime, timeData.stopTime, timeData.numSamples
        )
    )
    return timeData
Exemplo n.º 2
0
def resample(timeData: TimeData, resampFreq: float, inplace: bool = True) -> TimeData:
    """Resample time data
    
    Parameters
    ----------
    timeData : TimeData
        timeData to filter
    resampFreq : float
        The frequency to resample to
    inplace : bool, optional
        Whether to manipulate the data inplace        

    Returns
    -------
    TimeData
        Filtered time data
    """
    origFreq = timeData.sampleFreq
    if not inplace:
        timeData = timeData.copy()
    timeData.data = resampleData(timeData.data, timeData.sampleFreq, resampFreq)
    # update the time info
    timeData.sampleFreq = resampFreq
    timeData.numSamples = timeData.data[timeData.chans[0]].size
    timeData.stopTime = timeData.startTime + timedelta(
        seconds=(1.0 / timeData.sampleFreq) * (timeData.numSamples - 1)
    )
    timeData.addComment(
        "Time data resampled from {:.6f} Hz to {:.6f} Hz".format(origFreq, resampFreq)
    )
    return timeData