Ejemplo n.º 1
0
    def test_defaulTextValues(self, qtbot):
        cdw = CameraDataWidget()
        cdw.show()
        qtbot.addWidget(cdw)

        assert cdw.bufferUpdatedValueLabel.text() == NO_DATA_VALUE
        assert cdw.accumPeriodValueLabel.text() == NO_DATA_VALUE
        assert cdw.fluxValueLabel.text() == NO_DATA_VALUE
        assert cdw.maxAdcValueLabel.text() == NO_DATA_VALUE
        assert cdw.fwhmValueLabel.text() == NO_DATA_VALUE
        assert cdw.centroidXLabel.text() == NO_DATA_VALUE
        assert cdw.centroidYLabel.text() == NO_DATA_VALUE
        assert cdw.rmsXLabel.text() == NO_DATA_VALUE
        assert cdw.rmsYLabel.text() == NO_DATA_VALUE
 def test_getGeneralConfiguration(self, qtbot):
     cdw = CameraDataWidget()
     qtbot.addWidget(cdw)
     dc = DataController(cdw)
     currentConfig = dc.getGeneralConfiguration()
     truthConfig = GeneralConfig()
     assert currentConfig == truthConfig
 def test_noneFrame(self, qtbot, mocker):
     cdw = CameraDataWidget()
     qtbot.addWidget(cdw)
     dc = DataController(cdw)
     ffModel = mocker.patch.object(dc.fullFrameModel, "calculateCentroid")
     dc.passFrame(None, self.fullFrameStatus)
     assert ffModel.call_count == 0
 def test_setFrameChecks(self, qtbot):
     cdw = CameraDataWidget()
     qtbot.addWidget(cdw)
     dc = DataController(cdw)
     dc.setFrameChecks(passFrame, passFrame)
     assert dc.fullFrameModel.frameCheck is not None
     assert dc.roiFrameModel.frameCheck is not None
 def test_setBufferSize(self, qtbot):
     cdw = CameraDataWidget()
     qtbot.addWidget(cdw)
     dc = DataController(cdw)
     truthBufferSize = 256
     dc.setBufferSize(truthBufferSize)
     assert dc.getBufferSize() == truthBufferSize
 def test_parametersAfterConstruction(self, qtbot):
     cdw = CameraDataWidget()
     qtbot.addWidget(cdw)
     dc = DataController(cdw)
     assert dc.cameraDataWidget is not None
     assert dc.updater is not None
     assert dc.fullFrameModel is not None
     assert dc.roiFrameModel is not None
     assert dc.bufferModel is not None
     assert dc.roiResetDone is False
     assert dc.filesCreated is False
     assert dc.centroidFilename is None
     assert dc.psdFilename is None
     assert dc.telemetrySavePath is None
     assert dc.telemetrySetup is False
     assert dc.fullTelemetrySavePath is None
     assert dc.configVersion is None
     assert dc.configFile is None
     assert dc.dataConfig is not None
     assert dc.generalConfig is not None
     assert dc.timeHandler is not None
     assert dc.cameraModelName is None
     assert dc.roiFrameModel.timeHandler is not None
     assert dc.fullFrameModel.timeHandler is not None
     assert dc.takeScreenshot is False
    def test_setCameraModelName(self, qtbot):
        cdw = CameraDataWidget()
        qtbot.addWidget(cdw)
        dc = DataController(cdw)

        modelName = "ProSilice GT-650"
        dc.setCameraModelName(modelName)
        assert dc.cameraModelName == modelName
 def test_getCentroids(self, qtbot, mocker):
     cdw = CameraDataWidget()
     qtbot.addWidget(cdw)
     dc = DataController(cdw)
     truth_centroids = (241.542, 346.931)
     centroids = dc.getCentroids(False)
     assert centroids == (None, None)
     dc.bufferModel.getCentroids = mocker.Mock(return_value=truth_centroids)
     centroids = dc.getCentroids(True)
     assert centroids == truth_centroids
 def test_failedFrame(self, qtbot, mocker):
     cdw = CameraDataWidget()
     qtbot.addWidget(cdw)
     dc = DataController(cdw)
     mocker.patch(
         'spot_motion_monitor.views.camera_data_widget.CameraDataWidget.updateFullFrameData'
     )
     dc.fullFrameModel.calculateCentroid = mocker.Mock(
         side_effect=FrameRejected)
     dc.passFrame(self.frame, self.fullFrameStatus)
     assert dc.cameraDataWidget.updateFullFrameData.call_count == 0
 def test_handleAcquireRoiStateChange(self, qtbot, mocker):
     cdw = CameraDataWidget()
     qtbot.addWidget(cdw)
     dc = DataController(cdw)
     dc.filesCreated = True
     mockCleanTelemetry = mocker.patch.object(dc, 'cleanTelemetry')
     mockBufferModelReset = mocker.patch.object(dc.bufferModel, 'reset')
     dc.handleAcquireRoiStateChange(Qt.Unchecked)
     assert mockCleanTelemetry.call_count == 1
     assert mockBufferModelReset.call_count == 1
     assert dc.filesCreated is False
 def test_getCentroidForUpdate(self, qtbot, mocker):
     cdw = CameraDataWidget()
     qtbot.addWidget(cdw)
     dc = DataController(cdw)
     truthInfo = GenericFrameInformation(self.timestamp, 300.3, 400.2,
                                         32042.42, 145.422, 15.532, 70,
                                         None)
     dc.fullFrameModel.calculateCentroid = mocker.Mock(
         return_value=truthInfo)
     info = dc.getCentroidForUpdate(self.frame)
     assert info.centerX == truthInfo.centerX
     assert info.centerY == truthInfo.centerY
Ejemplo n.º 12
0
    def test_reset(self, qtbot):
        cdw = CameraDataWidget()
        cdw.show()
        qtbot.addWidget(cdw)

        cdw.bufferUpdatedValueLabel.setText(str(datetime.now()))
        cdw.accumPeriodValueLabel.setText('25.0')
        cdw.centroidXLabel.setText('300.24')
        cdw.centroidYLabel.setText('242.53')
        cdw.fluxValueLabel.setText('2532.42')
        cdw.fwhmValueLabel.setText('14.53')
        cdw.maxAdcValueLabel.setText('453.525')
        cdw.rmsXLabel.setText('0.353')
        cdw.rmsYLabel.setText('1.533')

        cdw.reset()

        assert cdw.bufferUpdatedValueLabel.text() == NO_DATA_VALUE
        assert cdw.accumPeriodValueLabel.text() == NO_DATA_VALUE
        assert cdw.fluxValueLabel.text() == NO_DATA_VALUE
        assert cdw.maxAdcValueLabel.text() == NO_DATA_VALUE
        assert cdw.fwhmValueLabel.text() == NO_DATA_VALUE
        assert cdw.centroidXLabel.text() == NO_DATA_VALUE
        assert cdw.centroidYLabel.text() == NO_DATA_VALUE
        assert cdw.rmsXLabel.text() == NO_DATA_VALUE
        assert cdw.rmsYLabel.text() == NO_DATA_VALUE
    def test_writeScreenshot(self, qtbot):
        cdw = CameraDataWidget()
        qtbot.addWidget(cdw)
        dc = DataController(cdw)

        dc.takeScreenshot = True
        output_file = "ccd_20181030_223015.fits"

        dc.writeScreenshot(self.frame)

        assert os.path.exists(output_file) is True
        assert dc.takeScreenshot is False

        os.remove(output_file)
 def test_getPsd(self, qtbot, mocker):
     cdw = CameraDataWidget()
     qtbot.addWidget(cdw)
     dc = DataController(cdw)
     currentFps = 40
     psd = dc.getPsd(False, currentFps)
     assert psd == (None, None, None)
     dc.bufferModel.rollBuffer = True
     truth_psd = (np.random.random(3), np.random.random(3),
                  np.random.random(3))
     dc.bufferModel.getPsd = mocker.Mock(return_value=truth_psd)
     psd = dc.getPsd(True, currentFps)
     dc.bufferModel.getPsd.assert_called_with(currentFps)
     assert psd == truth_psd
    def test_writingData(self, qtbot):
        cdw = CameraDataWidget()
        qtbot.addWidget(cdw)
        currentFps = 40
        dc = DataController(cdw)
        assert dc.cameraDataWidget.saveDataCheckBox.isChecked() is False
        assert dc.generalConfig.saveBufferData is False
        assert dc.filesCreated is False

        nonePsd = (None, None, None)

        dc.writeDataToFile(nonePsd, currentFps)
        assert dc.filesCreated is False

        qtbot.mouseClick(cdw.saveDataCheckBox, Qt.LeftButton)
        assert dc.generalConfig.saveBufferData is True

        dc.writeDataToFile(nonePsd, currentFps)
        assert dc.filesCreated is False

        # Setup buffer model
        dc.setBufferSize(4)
        dc.bufferModel.updateInformation(
            GenericFrameInformation(self.timestamp, 300.3, 400.2, 32042.42,
                                    145.422, 14.836, 70, None), (0, 0))
        dc.bufferModel.updateInformation(
            GenericFrameInformation(self.timestamp + self.deltaTime, 300.4,
                                    400.4, 32045.42, 146.422, 15.836, 70,
                                    None), (0, 0))
        dc.bufferModel.updateInformation(
            GenericFrameInformation(self.timestamp + self.deltaTime * 2, 300.2,
                                    400.5, 32040.42, 142.422, 12.836, 70,
                                    None), (0, 0))
        dc.bufferModel.updateInformation(
            GenericFrameInformation(self.timestamp + self.deltaTime * 3, 300.1,
                                    400.3, 32043.42, 143.422, 13.836, 70,
                                    None), (0, 0))
        assert dc.bufferModel.rollBuffer is True
        centroidOutputFile = 'smm_centroid_20181030_223015.h5'
        psdOutputFile = 'smm_psd_20181030_223015.h5'
        psdInfo = dc.bufferModel.getPsd(currentFps)
        dc.writeDataToFile(psdInfo, currentFps)
        assert dc.filesCreated is True
        assert dc.centroidFilename == centroidOutputFile
        assert dc.psdFilename == psdOutputFile
        assert os.path.exists(centroidOutputFile)
        assert os.path.exists(psdOutputFile)
        os.remove(centroidOutputFile)
        os.remove(psdOutputFile)
    def test_setDataConfiguration(self, qtbot):
        cdw = CameraDataWidget()
        qtbot.addWidget(cdw)
        dc = DataController(cdw)

        truthConfig = DataConfig()
        truthConfig.buffer.pixelScale = 0.5
        truthConfig.fullFrame.sigmaScale = 1.753
        truthConfig.fullFrame.minimumNumPixels = 15
        truthConfig.roiFrame.thresholdFactor = 0.99
        dc.setDataConfiguration(truthConfig)
        assert dc.bufferModel.pixelScale == truthConfig.buffer.pixelScale
        assert dc.fullFrameModel.sigmaScale == truthConfig.fullFrame.sigmaScale
        assert dc.fullFrameModel.minimumNumPixels == truthConfig.fullFrame.minimumNumPixels
        assert dc.roiFrameModel.thresholdFactor == truthConfig.roiFrame.thresholdFactor
    def test_setGeneralConfiguration(self, qtbot):
        cdw = CameraDataWidget()
        qtbot.addWidget(cdw)
        dc = DataController(cdw)

        truthConfig = GeneralConfig()
        truthConfig.site = "Cerro Pachon"
        truthConfig.configVersion = "0.1.10"
        truthConfig.timezone = "TAI"
        dc.setGeneralConfiguration(truthConfig)
        assert dc.generalConfig == truthConfig
        assert dc.fullTelemetrySavePath == truthConfig.fullTelemetrySavePath
        assert dc.removeTelemetryDir == truthConfig.removeTelemetryDir
        assert dc.configVersion == truthConfig.configVersion
        assert dc.timeHandler.timezone == truthConfig.timezone
        assert dc.fullFrameModel.timeHandler.timezone == truthConfig.timezone
        assert dc.roiFrameModel.timeHandler.timezone == truthConfig.timezone
    def test_updateRoiFrameData(self, qtbot, mocker):
        cdw = CameraDataWidget()
        qtbot.addWidget(cdw)
        dc = DataController(cdw)
        mockCameraDataWidgetReset = mocker.patch.object(cdw, 'reset')
        mockBufferModelUpdateInfo = mocker.patch.object(
            dc.bufferModel, 'updateInformation')
        dc.roiFrameModel.calculateCentroid = mocker.Mock(
            return_value=GenericFrameInformation(self.timestamp, 242.3, 286.2,
                                                 2519.534, 104.343, 11.963, 50,
                                                 1.532))

        dc.passFrame(self.frame, self.roiFrameStatus)
        assert mockCameraDataWidgetReset.call_count == 1
        assert mockBufferModelUpdateInfo.call_count == 1
        dc.passFrame(self.frame, self.roiFrameStatus)
        assert mockCameraDataWidgetReset.call_count == 1
        assert mockBufferModelUpdateInfo.call_count == 2
    def test_noTelemetryDirCleanup(self, qtbot):
        cdw = CameraDataWidget()
        qtbot.addWidget(cdw)
        saveTelemetryDir = os.path.join(os.path.abspath(os.path.curdir),
                                        'temp2')
        telemetryOutputDir = 'dsm_telemetry'
        fullSaveDir = os.path.join(saveTelemetryDir, telemetryOutputDir)
        dc = DataController(cdw)
        dc.telemetrySavePath = saveTelemetryDir
        dc.removeTelemetryDir = False

        # Setup buffer model
        dc.setBufferSize(4)
        dc.bufferModel.updateInformation(
            GenericFrameInformation(self.timestamp, 300.3, 400.2, 32042.42,
                                    145.422, 14.836, 70, None), (0, 0))
        dc.bufferModel.updateInformation(
            GenericFrameInformation(self.timestamp + self.deltaTime, 300.4,
                                    400.4, 32045.42, 146.422, 15.836, 70,
                                    None), (0, 0))
        dc.bufferModel.updateInformation(
            GenericFrameInformation(self.timestamp + self.deltaTime * 2, 300.2,
                                    400.5, 32040.42, 142.422, 12.836, 70,
                                    None), (0, 0))
        dc.bufferModel.updateInformation(
            GenericFrameInformation(self.timestamp + self.deltaTime * 3, 300.1,
                                    400.3, 32043.42, 143.422, 13.836, 70,
                                    None), (0, 0))

        telemetryFile = 'dsm_20181030_223015.dat'
        configFile = 'dsm_ui_config.yaml'
        roiInfo = dc.bufferModel.getInformation(self.roiFrameStatus.currentFps)
        dc.writeTelemetryFile(roiInfo, self.roiFrameStatus)
        assert os.path.exists(fullSaveDir) is True
        assert os.path.exists(os.path.join(fullSaveDir, telemetryFile)) is True
        assert os.path.exists(os.path.join(fullSaveDir, configFile)) is True
        dc.cleanTelemetry()
        assert os.path.exists(os.path.join(fullSaveDir,
                                           telemetryFile)) is False
        assert os.path.exists(os.path.join(fullSaveDir, configFile)) is False
        assert os.path.exists(fullSaveDir) is True
        assert dc.telemetrySetup is False
        os.removedirs(fullSaveDir)
    def test_showRoiInformation(self, qtbot, mocker):
        cdw = CameraDataWidget()
        qtbot.addWidget(cdw)
        dc = DataController(cdw)
        mockCameraDataWidgetUpdateRoiInfo = mocker.patch.object(
            cdw, 'updateRoiFrameData')
        mockWriteTelemetryFile = mocker.patch.object(dc, 'writeTelemetryFile')
        roiInfo = RoiFrameInformation(242.5, 286.3, 2501.42, 104.753, 13.672,
                                      2.5432, 2.2353, (1000, 25))
        dc.bufferModel.getInformation = mocker.Mock(return_value=roiInfo)

        dc.showRoiInformation(True, self.roiFrameStatus)
        assert mockCameraDataWidgetUpdateRoiInfo.call_count == 1
        mockCameraDataWidgetUpdateRoiInfo.assert_called_with(roiInfo)
        assert mockWriteTelemetryFile.call_count == 1
        mockWriteTelemetryFile.assert_called_with(roiInfo, self.roiFrameStatus)
        dc.showRoiInformation(False, self.roiFrameStatus)
        assert mockCameraDataWidgetUpdateRoiInfo.call_count == 1
        assert mockWriteTelemetryFile.call_count == 1
        mockWriteTelemetryFile.assert_called_once_with(roiInfo,
                                                       self.roiFrameStatus)
Ejemplo n.º 21
0
    def test_noneForRoiFramePassedValues(self, qtbot):
        cdw = CameraDataWidget()
        cdw.show()
        qtbot.addWidget(cdw)

        rfi = None
        cdw.updateRoiFrameData(rfi)

        assert cdw.bufferUpdatedValueLabel.text() == NO_DATA_VALUE
        assert cdw.accumPeriodValueLabel.text() == NO_DATA_VALUE
        assert cdw.fluxValueLabel.text() == NO_DATA_VALUE
        assert cdw.maxAdcValueLabel.text() == NO_DATA_VALUE
        assert cdw.fwhmValueLabel.text() == NO_DATA_VALUE
        assert cdw.centroidXLabel.text() == NO_DATA_VALUE
        assert cdw.centroidYLabel.text() == NO_DATA_VALUE
        assert cdw.rmsXLabel.text() == NO_DATA_VALUE
        assert cdw.rmsYLabel.text() == NO_DATA_VALUE
Ejemplo n.º 22
0
    def test_fullFramePassedValues(self, qtbot):
        cdw = CameraDataWidget()
        cdw.show()
        qtbot.addWidget(cdw)

        ffi = FullFrameInformation(200, 342, 4032.428492, 170.482945, 12.7264)
        cdw.updateFullFrameData(ffi)

        assert cdw.bufferUpdatedValueLabel.text() == NO_DATA_VALUE
        assert cdw.accumPeriodValueLabel.text() == NO_DATA_VALUE
        assert cdw.centroidXLabel.text() == str(ffi.centerX)
        assert cdw.centroidYLabel.text() == str(ffi.centerY)
        assert cdw.fluxValueLabel.text() == self.formatFloatText(ffi.flux)
        assert cdw.maxAdcValueLabel.text() == self.formatFloatText(ffi.maxAdc)
        assert cdw.fwhmValueLabel.text() == self.formatFloatText(ffi.fwhm)
        assert cdw.rmsXLabel.text() == NO_DATA_VALUE
        assert cdw.rmsYLabel.text() == NO_DATA_VALUE
 def test_updateFullFrameData(self, qtbot, mocker):
     cdw = CameraDataWidget()
     qtbot.addWidget(cdw)
     dc = DataController(cdw)
     mockCameraDataWidgetReset = mocker.patch.object(cdw, 'reset')
     mockTakeScreenshot = mocker.patch.object(dc, 'writeScreenshot')
     mocker.patch(
         'spot_motion_monitor.views.camera_data_widget.CameraDataWidget.updateFullFrameData'
     )
     dc.fullFrameModel.calculateCentroid = mocker.Mock(
         return_value=GenericFrameInformation(self.timestamp, 300.3, 400.2,
                                              32042.42, 145.422, 17.525, 70,
                                              None))
     dc.takeScreenshot = True
     dc.passFrame(self.frame, self.fullFrameStatus)
     assert dc.cameraDataWidget.updateFullFrameData.call_count == 1
     assert mockCameraDataWidgetReset.call_count == 0
     assert mockTakeScreenshot.call_count == 1
     assert dc.roiResetDone is False
     dc.roiResetDone = True
     dc.passFrame(self.frame, self.fullFrameStatus)
     assert mockCameraDataWidgetReset.call_count == 1
     assert dc.roiResetDone is False
Ejemplo n.º 24
0
    def test_roiFramePassedValues(self, qtbot, mocker):
        cdw = CameraDataWidget()
        cdw.show()
        qtbot.addWidget(cdw)

        rfi = RoiFrameInformation(243.23, 354.97, 2763.58328, 103.53245,
                                  14.2542, 1.4335, 1.97533, (1000, 25.0))
        cdw.updateRoiFrameData(rfi)

        assert cdw.bufferUpdatedValueLabel.text() != NO_DATA_VALUE
        assert cdw.accumPeriodValueLabel.text() == self.formatFloatText(
            rfi.validFrames[1])
        assert cdw.centroidXLabel.text() == self.formatFloatText(rfi.centerX)
        assert cdw.centroidYLabel.text() == self.formatFloatText(rfi.centerY)
        assert cdw.fluxValueLabel.text() == self.formatFloatText(rfi.flux)
        assert cdw.maxAdcValueLabel.text() == self.formatFloatText(rfi.maxAdc)
        assert cdw.fwhmValueLabel.text() == self.formatFloatText(rfi.fwhm)
        assert cdw.rmsXLabel.text() == self.formatFloatText(rfi.rmsX)
        assert cdw.rmsYLabel.text() == self.formatFloatText(rfi.rmsY)
 def test_getBufferSize(self, qtbot):
     cdw = CameraDataWidget()
     qtbot.addWidget(cdw)
     dc = DataController(cdw)
     bufferSize = dc.getBufferSize()
     assert bufferSize == 1024