예제 #1
0
def smallDataTest():
    breakPrint()
    generalPrint("testsSpectralCalc", "Running test function: smallDataTest")
    # read in data
    reader = DataReaderATS(atsPath)
    startTime1 = "2016-02-21 03:00:00"
    stopTime1 = "2016-02-21 03:30:00"
    timeData = reader.getPhysicalData(startTime1, stopTime1)
    timeData.printInfo()
    # now let's try the calibrator
    cal = Calibrator(calPath)
    cal.printInfo()
    sensors = reader.getSensors(timeData.chans)
    serials = reader.getSerials(timeData.chans)
    choppers = reader.getChoppers(timeData.chans)
    timeData = cal.calibrate(timeData, sensors, serials, choppers)
    timeData.printInfo()
    specCal = SpectrumCalculator(timeData.sampleFreq, timeData.numSamples)
    specData = specCal.calcFourierCoeff(timeData)
    specData.printInfo()
    fig = plt.figure(figsize=(10, 10))
    specData.view(fig=fig, label="Raw spectral data")
    # now let's try and process something
    sproc = SignalProcessor()
    timeData2 = reader.getPhysicalData(startTime1, stopTime1)
    timeData2 = cal.calibrate(timeData2, sensors, serials, choppers)
    timeData2 = sproc.notchFilter(timeData2, 50.0)
    timeData2 = sproc.notchFilter(timeData2, 16.6667)
    specData2 = specCal.calcFourierCoeff(timeData2)
    specData2.printInfo()
    specData2.view(fig=fig, label="Notch filtered")
    # set plot properties
    fig.tight_layout(rect=[0, 0.02, 1, 0.96])
    addLegends(fig)
    plt.show()
예제 #2
0
def testResample():
    breakPrint()
    generalPrint("testsSignalProcess", "Running test function: testResample")
    # read in data
    spamReader = DataReaderSPAM(spamPath)
    # now get some data
    startTime = "2016-02-07 02:00:00"
    stopTime = "2016-02-07 03:00:00"
    # let's get some unscaled data
    timeData = spamReader.getUnscaledData(startTime, stopTime)
    timeData.printInfo()
    timeDataSave = copy.deepcopy(timeData)
    timeData.printInfo()
    # now do some signal processing
    sproc = SignalProcessor()
    timeData = sproc.resample(timeData, 50)
    timeData.printInfo()
    # now let's plot and see what happens
    fig = plt.figure(figsize=(20, 10))
    x = timeData.getDateArray()
    xlim = [timeDataSave.startTime, x[4000]]
    timeDataSave.view(sampleStop=20000, fig=fig, xlim=xlim, label="Raw data")
    timeData.view(sampleStop=4000, fig=fig, xlim=xlim, label="Resampled data")
    fig.tight_layout(rect=[0, 0.02, 1, 0.96])
    addLegends(fig)
    plt.show()
예제 #3
0
def hpFilterTest():
    breakPrint()
    generalPrint("testsSignalProcess", "Running test function: hpFilterTest")
    # read in data
    atsReader = DataReaderATS(atsPath)
    # now get some data
    startTime = "2016-02-21 03:00:00"
    stopTime = "2016-02-21 04:00:00"
    timeData = atsReader.getPhysicalData(startTime, stopTime)
    timeDataSave = copy.deepcopy(timeData)
    timeData.printInfo()
    # now do some signal processing
    sproc = SignalProcessor()
    timeData = sproc.highPass(timeData, 24)
    timeData.printInfo()
    # now let's plot and see what happens
    fig = plt.figure(figsize=(20, 10))
    timeDataSave.view(fig=fig, label="Raw data")
    timeData.view(fig=fig, label="High pass filtered")
    fig.tight_layout(rect=[0, 0.02, 1, 0.96])
    addLegends(fig)
    plt.show()
예제 #4
0
def testWindowDecimateNotch():
    breakPrint()
    generalPrint("testsWindowDecimate",
                 "Running test function: testWindowDecimateNotch")    
    reader = DataReaderATS(atsPath)
    timeData = reader.getPhysicalSamples()
    timeData.printInfo()
    # now let's try the calibrator
    cal = Calibrator(calPath)
    cal.printInfo()
    sensors = reader.getSensors(timeData.chans)
    serials = reader.getSerials(timeData.chans)
    choppers = reader.getChoppers(timeData.chans)
    timeData = cal.calibrate(timeData, sensors, serials, choppers)
    timeData.printInfo()
    # let's apply some filtering and notching
    sproc = SignalProcessor()
    timeData = sproc.notchFilter(timeData, 50.0)
    timeData = sproc.notchFilter(timeData, 16.6667)
    timeData = sproc.lowPass(timeData, 50)
    # calculate decimation parameters
    decParams = DecimationParams(timeData.sampleFreq)
    decParams.setDecimationParams(7, 6)
    decParams.printInfo()
    numLevels = decParams.numLevels
    timeData.addComment(
        "Decimating with {} levels and {} frequencies per level".format(
            numLevels, decParams.freqPerLevel))
    # now do window parameters
    winParams = WindowParams(decParams)
    winParams.printInfo()
    # create the decimator
    dec = Decimator(timeData, decParams)
    dec.printInfo()

    for iDec in range(0, numLevels):
        # get the data for the current level
        check = dec.incrementLevel()
        if not check:
            break  # not enough data
        timeData = dec.timeData
        # create the windower and give it window parameters for current level
        fsDec = dec.sampleFreq
        win = Windower(datetimeRef, timeData, winParams.getWindowSize(iDec),
                       winParams.getOverlap(iDec))
        numWindows = win.numWindows
        if numWindows < 2:
            break  # do no more decimation

        # add some comments
        timeData.addComment(
            "Evaluation frequencies for level {} are {}".format(
                iDec,
                listToString(decParams.getEvalFrequenciesForLevel(iDec))))
        timeData.addComment(
            "Windowing with window size {} samples, overlap {} samples and {} windows"
            .format(
                winParams.getWindowSize(iDec), winParams.getOverlap(iDec),
                numWindows))

        # create the spectrum calculator and statistics calculators
        specCalc = SpectrumCalculator(fsDec, winParams.getWindowSize(iDec))
        # get ready a file to save the spectra
        specWrite = SpectrumWriter(specPathNotch, datetimeRef)
        specWrite.openBinaryForWriting("spectra", iDec, fsDec,
                                       winParams.getWindowSize(iDec),
                                       winParams.getOverlap(iDec),
                                       win.winOffset, numWindows,
                                       timeData.chans)

        # loop though windows, calculate spectra and save
        for iW in range(0, numWindows):
            # get the window data
            winData = win.getData(iW)
            # calculate spectra
            specData = specCalc.calcFourierCoeff(winData)
            # write out spectra
            specWrite.writeBinary(specData, iW)

        # close spectra file
        specWrite.writeCommentsFile(timeData.comments)
        specWrite.closeFile()
예제 #5
0
def testFillGap():
    breakPrint()
    generalPrint("testsSignalProcess", "Running test function: testFillGap")
    # read in data
    atsReader = DataReaderATS(atsPath)
    # now get some data
    startTime1 = "2016-02-21 03:00:00"
    stopTime1 = "2016-02-21 03:08:00"
    timeData1 = atsReader.getPhysicalData(startTime1, stopTime1)
    # more data
    startTime2 = "2016-02-21 03:10:00"
    stopTime2 = "2016-02-21 03:15:00"
    timeData2 = atsReader.getPhysicalData(startTime2, stopTime2)
    # now do some signal processing
    sproc = SignalProcessor()
    timeData = sproc.fillGap(timeData1, timeData2)
    timeData.printInfo()
    # now let's plot and see what happens
    fig = plt.figure(figsize=(20, 10))
    x = timeData.getDateArray()
    xlim = [timeData1.startTime, timeData2.stopTime]
    timeData.view(sampleStop=timeData.numSamples - 1,
                  fig=fig,
                  xlim=xlim,
                  label="Gap filled")
    timeData1.view(sampleStop=timeData1.numSamples - 1,
                   fig=fig,
                   xlim=xlim,
                   label="Section1")
    timeData2.view(sampleStop=timeData2.numSamples - 1,
                   fig=fig,
                   xlim=xlim,
                   label="Section2")
    fig.tight_layout(rect=[0, 0.02, 1, 0.96])
    addLegends(fig)
    plt.show()

    # now test with spam data
    spamReader = DataReaderSPAM(spamPath)
    # now get some data
    startTime1 = "2016-02-07 02:00:00"
    stopTime1 = "2016-02-07 02:08:00"
    timeData1 = spamReader.getPhysicalData(startTime1, stopTime1)
    # more data
    startTime2 = "2016-02-07 02:10:00"
    stopTime2 = "2016-02-07 02:15:00"
    timeData2 = spamReader.getPhysicalData(startTime2, stopTime2)
    # now do some signal processing
    sproc = SignalProcessor()
    timeData = sproc.fillGap(timeData1, timeData2)
    timeData.printInfo()
    # now let's plot and see what happens
    fig = plt.figure(figsize=(20, 10))
    x = timeData.getDateArray()
    xlim = [timeData1.startTime, timeData2.stopTime]
    timeData.view(sampleStop=timeData.numSamples - 1,
                  fig=fig,
                  xlim=xlim,
                  label="Gap filled")
    timeData1.view(sampleStop=timeData1.numSamples - 1,
                   fig=fig,
                   xlim=xlim,
                   label="Section1")
    timeData2.view(sampleStop=timeData2.numSamples - 1,
                   fig=fig,
                   xlim=xlim,
                   label="Section2")
    fig.tight_layout(rect=[0, 0.02, 1, 0.96])
    addLegends(fig)
    plt.show()