Esempio n. 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()
Esempio n. 2
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()
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()