Example #1
0
def plotTest():
    breakPrint()
    generalPrint("testsSignalProcess", "Running test function: plotTest")
    # read in data
    atsReader = DataReaderATS(atsPath)
    # now get some data
    startTime1 = "2016-02-21 03:00:00"
    stopTime1 = "2016-02-21 03:05:00"
    timeData1 = atsReader.getPhysicalData(startTime1, stopTime1)
    timeData1.printInfo()
    # get a second set of data
    startTime2 = "2016-02-21 03:03:00"
    stopTime2 = "2016-02-21 03:05:00"
    timeData2 = atsReader.getPhysicalData(startTime2, stopTime2)
    timeData2.printInfo()
    # now plot
    fig = plt.figure(figsize=(20, 10))
    timeData1.view(sampleStop=timeData1.numSamples - 1,
                   fig=fig,
                   xlim=[timeData1.startTime, timeData2.stopTime])
    timeData2.view(sampleStop=timeData2.numSamples - 1,
                   fig=fig,
                   xlim=[timeData1.startTime, timeData2.stopTime])
    fig.tight_layout(rect=[0, 0.02, 1, 0.96])
    addLegends(fig)
    plt.show()
Example #2
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()
def testATS():
    breakPrint()
    generalPrint("testsDataReader", "Running test function: testATS")
    # read in ATS data
    atsReader = DataReaderATS(atsPath)
    atsReader.printInfo()
    # now get some data
    startTime = "2016-02-21 03:00:00"
    stopTime = "2016-02-21 04:00:00"
    # let's get some unscaled data
    unscaledData = atsReader.getUnscaledData(startTime, stopTime)
    unscaledData.printInfo()
    # now let's look at the data
    unscaledData.view(sampleEnd=20000)
    # let's try physical data
    physicalData = atsReader.getPhysicalData(startTime, stopTime)
    physicalData.printInfo()
    # let's view it
    physicalData.view()
    # but all we see is 50Hz and 16Hz noise
    # so we can apply a low pass filter
    physicalData.view(sampleEnd=20000, lpfilt=4)
    # now let's try and write it out
    # as the ascii format
    writer = DataWriterAscii()
    writer.setOutPath(ats_2ascii)
    writer.writeDataset(atsReader)
Example #4
0
def standardDataTest():
    breakPrint()
    generalPrint("testsSpectralCalc",
                 "Running test function: standardDataTest")
    # read in data
    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()
    specCal = SpectrumCalculator(timeData.sampleFreq, timeData.numSamples)
    specData = specCal.calcFourierCoeff(timeData)
    specData.printInfo()
    # now try writing out the spectra
    refTime = datetime.strptime("2016-02-21 00:00:00", "%Y-%m-%d %H:%M:%S")
    specWriter = SpectrumWriter(specPath, refTime)
    specWriter.openBinaryForWriting("spectra", 0, specData.sampleFreq,
                                    timeData.numSamples, 0, 0, 1,
                                    specData.chans)
    specWriter.writeBinary(specData, 0)
    specWriter.writeCommentsFile(specData.comments)
    specWriter.closeFile()
    # now try and read everything in again and get the spec data
    specReader = SpectrumReader(specPath)
    specReader.openBinaryForReading("spectra", 0)
    specReader.printInfo()
    specData = specReader.readBinaryWindowLocal(0)
    specData.printInfo()
Example #5
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()
def testWindowDecimate():
    breakPrint()
    generalPrint("testsWindowDecimate",
                 "Running test function: testWindowDecimate")
    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()
    # 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(specPath, 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()
Example #7
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()