Beispiel #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
Beispiel #2
0
def polarityReversal(timeData: TimeData,
                     reversal: Dict[str, bool],
                     inplace: bool = True) -> TimeData:
    """Multiply the data by -1 (polarity reversal)
    
    Parameters
    ----------
    timeData : TimeData
        timeData to normalise
    reversal : Dict[str, bool]
        Keys are channels and values are boolean flags for reversing
    inplace : bool, optional
        Whether to manipulate the data inplace

    Returns
    -------
    TimeData
        Normalised time data
    """
    if not inplace:
        timeData = timeData.copy()
    timeData.data = polarityReversalData(timeData.data, reversal)
    timeData.addComment(
        "Polarity reversal with parameters: {}".format(reversal))
    return timeData
Beispiel #3
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
Beispiel #4
0
def bandPass(
    timeData: TimeData, cutoffLow: float, cutoffHigh: float, inplace: bool = True
) -> TimeData:
    """Bandpass butterworth filter for time data
    
    Parameters
    ----------
    timeData : TimeData
        timeData to filter
    cutoff : float
        Cutoff frequency in Hz
    inplace : bool, optional
        Whether to manipulate the data inplace        

    Returns
    -------
    TimeData
        Filtered time data
    """
    if not inplace:
        timeData = timeData.copy()
    timeData.data = bandPassData(
        timeData.data, timeData.sampleFreq, cutoffLow, cutoffHigh
    )
    timeData.addComment(
        "Band pass filter applied with cutoffs {} Hz and {} Hz".format(
            cutoffLow, cutoffHigh
        )
    )
    return timeData
Beispiel #5
0
def normalise(timeData: TimeData, inplace: bool = True) -> TimeData:
    """Normalise time data
    
    Parameters
    ----------
    timeData : TimeData
        timeData to normalise
    inplace : bool, optional
        Whether to manipulate the data inplace

    Returns
    -------
    TimeData
        Normalised time data
    """
    if not inplace:
        timeData = timeData.copy()
    timeData.data = normaliseData(timeData.data)
    timeData.addComment("Data normalised")
    return timeData
Beispiel #6
0
def scale(timeData: TimeData,
          scalars: Dict[str, bool],
          inplace: bool = True) -> TimeData:
    """Scale the data by an arbitrary amount
    
    Parameters
    ----------
    timeData : TimeData
        timeData to normalise
    scalars : Dict[str, float]
        Keys are channels and values are boolean flags for reversing
    inplace : bool, optional
        Whether to manipulate the data inplace

    Returns
    -------
    TimeData
        Normalised time data
    """
    if not inplace:
        timeData = timeData.copy()
    timeData.data = scaleData(timeData.data, scalars)
    timeData.addComment("Time data scaled with scalars: {}".format(scalars))
    return timeData
Beispiel #7
0
def notchFilter(timeData: TimeData, notch: float, inplace: bool = True) -> TimeData:
    """Bandpass butterworth filter for time data
    
    Parameters
    ----------
    timeData : TimeData
        timeData to filter
    notch : float
        Frequency to notch filter in Hz
    inplace : bool, optional
        Whether to manipulate the data inplace        

    Returns
    -------
    TimeData
        Filtered time data
    """
    if not inplace:
        timeData = timeData.copy()
    timeData.data = notchFilterData(
        timeData.data, timeData.sampleFreq, notch, notch / 5.0
    )
    timeData.addComment("Notch filter applied at {} Hz".format(notch))
    return timeData