Example #1
0
    def addParameters(parameters):
        """
        Add parameters specific to staying in lock.
        """
        p = parameters.addSubSection(LockedMixin.lm_pname)
        p.add(params.ParameterInt(description = "Number of repeats for the lock to be considered good.",
                                  name = "buffer_length",
                                  value = 5))

        p.add(params.ParameterRangeFloat(description = "Lock response gain (near target offset).",
                                         name = "lock_gain",
                                         value = 0.5,
                                         min_value = 0.0,
                                         max_value = 1.0))

        p.add(params.ParameterRangeFloat(description = "Lock response maximum gain (far from target offset).",
                                         name = "lock_gain_max",
                                         value = 0.7,
                                         min_value = 0.0,
                                         max_value = 1.0))

        p.add(params.ParameterFloat(description = "Maximum allowed difference to still be in lock (nm).",
                                    name = "offset_threshold",
                                    value = 20.0))

        p.add(params.ParameterFloat(description = "Minimum sum to be considered locked (AU).",
                                    name = "minimum_sum",
                                    value = -1.0))
Example #2
0
    def addParameters(parameters):
        """
        Add parameters specific to scan mode.
        """
        p = parameters.addSubSection(ScanMixin.sm_pname)
        p.add(
            params.ParameterFloat(
                description="Minimum sum for finding the correct offset (AU).",
                name="minimum_sum",
                value=-1.0))

        p.add(
            params.ParameterFloat(
                description=
                "Maximum allowed difference for finding the correct offset (nm).",
                name="offset_threshold",
                value=100.0))

        p.add(
            params.ParameterFloat(description="Scan range in microns.",
                                  name="scan_range",
                                  value=10.0))

        p.add(
            params.ParameterFloat(description="Scan step size in microns.",
                                  name="scan_step",
                                  value=0.05))
Example #3
0
    def addParameters(parameters):
        """
        Add parameters specific to staying in lock.
        """
        p = parameters.addSubSection(LockedMixin.lm_pname)
        p.add(params.ParameterInt(description = "Number of repeats for the lock to be considered good.",
                                  name = "buffer_length",
                                  value = 5))
        
        p.add(params.ParameterFloat(description = "Maximum allowed difference to still be in lock (nm).",
                                    name = "offset_threshold",
                                    value = 20.0))

        p.add(params.ParameterFloat(description = "Minimum sum to be considered locked (AU).",
                                    name = "minimum_sum",
                                    value = -1.0))
Example #4
0
    def __init__(self, configuration=None, **kwds):
        super().__init__(**kwds)
        self.current_mode = None
        self.modes = []
        self.parameters = params.StormXMLObject()

        self.ui = focuslockUi.Ui_Dialog()
        self.ui.setupUi(self)

        # Add parameters
        self.parameters.add(
            params.ParameterFloat(description="Z stage jump size",
                                  name="jump_size",
                                  value=0.1))

        # Set up lock display.
        self.lock_display = lockDisplay.LockDisplay(
            configuration=configuration, jump_signal=self.jump, parent=self)
        layout = QtWidgets.QGridLayout(self.ui.lockDisplayWidget)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(self.lock_display)

        # Configure modes.
        lockModes.FindSumMixin.addParameters(self.parameters)
        lockModes.LockedMixin.addParameters(self.parameters)
        lockModes.ScanMixin.addParameters(self.parameters)
        for mode_class_name in configuration.get("lock_modes").split(","):
            a_class = getattr(lockModes, mode_class_name.strip())
            a_object = a_class(parameters=self.parameters, parent=self)
            self.ui.modeComboBox.addItem(a_object.getName())
            self.modes.append(a_object)

        # Set parameters values based on the config file parameters.
        c_params = configuration.get("parameters")
        for attr in params.difference(c_params, self.parameters):
            print(attr, c_params.get(attr))
            self.parameters.setv(attr, c_params.get(attr))
        self.newParameters(self.parameters)

        # Connect signals.
        self.ui.jumpNButton.clicked.connect(self.handleJumpNButton)
        self.ui.jumpPButton.clicked.connect(self.handleJumpPButton)
        self.ui.lockButton.clicked.connect(self.handleLockButton)
        self.ui.lockTargetSpinBox.valueChanged.connect(self.handleLockTarget)
        self.ui.modeComboBox.currentIndexChanged.connect(
            self.handleModeComboBox)

        self.setEnabled(False)
Example #5
0
    def processMessage(self, message):

        if message.isType("configuration"):
            if message.sourceIs("timing"):
                self.control.setTimingFunctionality(
                    message.getData()["properties"]["functionality"])

        elif message.isType("configure1"):
            self.sendMessage(
                halMessage.HalMessage(m_type="add to menu",
                                      data={
                                          "item name": "Focus Lock",
                                          "item data": "focus lock"
                                      }))

            self.sendMessage(
                halMessage.HalMessage(
                    m_type="initial parameters",
                    data={"parameters": self.view.getParameters()}))

        elif message.isType("configure2"):

            # Get functionalities. Do this here because the modules that provide these functionalities
            # will likely need functionalities from other modules. The IR laser for example might
            # need a functionality from a DAQ module.
            self.sendMessage(
                halMessage.HalMessage(m_type="get functionality",
                                      data={
                                          "name":
                                          self.configuration.get("ir_laser"),
                                          "extra data":
                                          "ir_laser"
                                      }))

            self.sendMessage(
                halMessage.HalMessage(m_type="get functionality",
                                      data={
                                          "name":
                                          self.configuration.get("qpd"),
                                          "extra data": "qpd"
                                      }))

            self.sendMessage(
                halMessage.HalMessage(m_type="get functionality",
                                      data={
                                          "name":
                                          self.configuration.get("z_stage"),
                                          "extra data": "z_stage"
                                      }))

        elif message.isType("new parameters"):
            p = message.getData()["parameters"]
            message.addResponse(
                halMessage.HalMessageResponse(
                    source=self.module_name,
                    data={"old parameters": self.view.getParameters().copy()}))
            self.view.newParameters(p.get(self.module_name))
            message.addResponse(
                halMessage.HalMessageResponse(
                    source=self.module_name,
                    data={"new parameters": self.view.getParameters()}))

        elif message.isType("show"):
            if (message.getData()["show"] == "focus lock"):
                self.view.show()

        elif message.isType("start"):
            self.view.start()
            self.control.start()
            if message.getData()["show_gui"]:
                self.view.showIfVisible()

        elif message.isType("start film"):
            self.control.startFilm(message.getData()["film settings"])

        elif message.isType("stop film"):
            self.control.stopFilm()
            message.addResponse(
                halMessage.HalMessageResponse(
                    source=self.module_name,
                    data={"parameters": self.view.getParameters().copy()}))
            lock_good = params.ParameterSetBoolean(
                name="good_lock", value=self.control.isGoodLock())
            lock_mode = params.ParameterString(
                name="lock_mode", value=self.control.getLockModeName())
            lock_sum = params.ParameterFloat(
                name="lock_sum", value=self.control.getQPDSumSignal())
            lock_target = params.ParameterFloat(
                name="lock_target", value=self.control.getLockTarget())
            message.addResponse(
                halMessage.HalMessageResponse(
                    source=self.module_name,
                    data={
                        "acquisition":
                        [lock_good, lock_mode, lock_sum, lock_target]
                    }))

        elif message.isType("tcp message"):

            # See control handles this message.
            handled = self.control.handleTCPMessage(message)

            # If not, check view.
            if not handled:
                handled = self.view.handleTCPMessage(message)

            # Mark if we handled the message.
            if handled:
                message.addResponse(
                    halMessage.HalMessageResponse(source=self.module_name,
                                                  data={"handled": True}))
Example #6
0
    def createParameters(self, cam_fn, parameters_from_file):
        """
        Create (initial) parameters for the current feed.

        cam_fn - A camera / feed functionality object.
        parameters_from_file - The parameters that were read from the XML file.
        """
        # Check that we are not writing over something that already exists.
        if (self.parameters.has(self.getFeedName())):
            msg = "Display parameters for " + self.getFeedName() + " already exists."
            raise halExceptions.HalException(msg)

        # Create a sub-section for this camera / feed.
        p = self.parameters.addSubSection(self.getFeedName())

        # Add display specific parameters.
        p.add(params.ParameterFloat(name = "center_x",
                                    value = 0.0,
                                    is_mutable = False))

        p.add(params.ParameterFloat(name = "center_y",
                                    value = 0.0,
                                    is_mutable = False))
            
        p.add(params.ParameterSetString(description = "Color table",
                                        name = "colortable",
                                        value = self.color_tables.getColorTableNames()[0],
                                        allowed = self.color_tables.getColorTableNames()))
                        
        p.add(params.ParameterInt(description = "Display maximum",
                                  name = "display_max",
                                  value = 100))

        p.add(params.ParameterInt(description = "Display minimum",
                                  name = "display_min",
                                  value = 0))

        p.add(params.ParameterSetBoolean(name = "initialized",
                                         value = False,
                                         is_mutable = False))

        p.add(params.ParameterInt(name = "max_intensity",
                                  value = 100,
                                  is_mutable = False,
                                  is_saved = False))

        p.add(params.ParameterInt(name = "scale",
                                  value = 0,
                                  is_mutable = False))
            
        p.add(params.ParameterInt(description = "Frame to display when filming with a shutter sequence",
                                  name = "sync",
                                  value = 0))

        # Set parameters with default values from feed/camera functionality
        if cam_fn.hasParameter("colortable"):
            p.setv("colortable", cam_fn.getParameter("colortable"))
        else:
            p.setv("colortable", self.default_colortable)
        p.setv("display_max", cam_fn.getParameter("default_max"))
        p.setv("display_min", cam_fn.getParameter("default_min"))
        p.setv("max_intensity", cam_fn.getParameter("max_intensity"))

        # If they exist, update with the values that we loaded from a file.
        # Also, some parameters files will have 'extra' parameters, typically
        # sub-sections for the different feeds. We skip these here as this
        # will be handled when we change to the feed and call the
        # setCameraFunctionality() method.
        #
        if parameters_from_file is not None:
            for attr in parameters_from_file.getAttrs():
                if p.has(attr):
                    p.setv(attr, parameters_from_file.get(attr))
Example #7
0
    def __init__(self, camera_name=None, config=None, **kwds):
        """
        camera_name - This is the name of this camera's section in the config XML file.        
        config - These are the values in the parameters section as a StormXMLObject().
        """
        super().__init__(**kwds)

        # This is the hardware module that will actually control the camera.
        self.camera = None

        # Sub-classes should set this to a CameraFunctionality object.
        self.camera_functionality = None

        self.camera_name = camera_name

        # This is a flag for whether or not the camera is in a working state.
        # It might not be if for example the parameters were bad.
        self.camera_working = True

        # The length of a fixed length film.
        self.film_length = None

        # The current frame number, this gets reset by startCamera().
        self.frame_number = 0

        # The camera parameters.
        self.parameters = params.StormXMLObject()

        # This is how we tell the thread that is handling actually talking
        # to the camera hardware to stop.
        self.running = False

        # This is how we know that the camera thread that is talking to the
        # camera actually started.
        self.thread_started = False

        #
        # These are the minimal parameters that every camera must provide
        # to work with HAL.
        #

        # The exposure time.
        self.parameters.add(
            params.ParameterFloat(description="Exposure time (seconds)",
                                  name="exposure_time",
                                  value=1.0))

        # This is frames per second as reported by the camera. It is used
        # for hardware timed waveforms (if any).
        self.parameters.add(
            params.ParameterFloat(name="fps", value=0, is_mutable=False))

        #
        # Chip size, ROI of the chip and the well depth.
        #
        x_size = 256
        y_size = 256
        self.parameters.add(
            params.ParameterInt(name="x_chip",
                                value=x_size,
                                is_mutable=False,
                                is_saved=False))

        self.parameters.add(
            params.ParameterInt(name="y_chip",
                                value=y_size,
                                is_mutable=False,
                                is_saved=False))

        self.parameters.add(
            params.ParameterInt(name="max_intensity",
                                value=128,
                                is_mutable=False,
                                is_saved=False))

        #
        # Note: These are all expected to be in units of binned pixels. For
        # example if the camera is 512 x 512 and we are binning by 2s then
        # the maximum value of these would 256 x 256.
        #
        self.parameters.add(
            params.ParameterRangeInt(description="AOI X start",
                                     name="x_start",
                                     value=1,
                                     min_value=1,
                                     max_value=x_size))

        self.parameters.add(
            params.ParameterRangeInt(description="AOI X end",
                                     name="x_end",
                                     value=x_size,
                                     min_value=1,
                                     max_value=x_size))

        self.parameters.add(
            params.ParameterRangeInt(description="AOI Y start",
                                     name="y_start",
                                     value=1,
                                     min_value=1,
                                     max_value=y_size))

        self.parameters.add(
            params.ParameterRangeInt(description="AOI Y end",
                                     name="y_end",
                                     value=y_size,
                                     min_value=1,
                                     max_value=y_size))

        self.parameters.add(
            params.ParameterInt(name="x_pixels", value=0, is_mutable=False))

        self.parameters.add(
            params.ParameterInt(name="y_pixels", value=0, is_mutable=False))

        self.parameters.add(
            params.ParameterRangeInt(description="Binning in X",
                                     name="x_bin",
                                     value=1,
                                     min_value=1,
                                     max_value=4))

        self.parameters.add(
            params.ParameterRangeInt(description="Binning in Y",
                                     name="y_bin",
                                     value=1,
                                     min_value=1,
                                     max_value=4))

        # Frame size in bytes.
        self.parameters.add(
            params.ParameterInt(name="bytes_per_frame",
                                value=x_size * y_size * 2,
                                is_mutable=False,
                                is_saved=False))

        #
        # How/if data from this camera is saved.
        #
        self.parameters.add(
            params.ParameterString(
                description="Camera save filename extension",
                name="extension",
                value=""))

        self.parameters.add(
            params.ParameterSetBoolean(
                description="Save data from this camera when filming",
                name="saved",
                value=True))

        self.parameters.set("extension", config.get("extension", ""))
        self.parameters.set("saved", config.get("saved", True))

        #
        # Camera display orientation. Values can only be changed by
        # changing the config.xml file.
        #
        self.parameters.add(
            params.ParameterSetBoolean(name="flip_horizontal",
                                       value=False,
                                       is_mutable=False))

        self.parameters.add(
            params.ParameterSetBoolean(name="flip_vertical",
                                       value=False,
                                       is_mutable=False))

        self.parameters.add(
            params.ParameterSetBoolean(name="transpose",
                                       value=False,
                                       is_mutable=False))

        self.parameters.set("flip_horizontal",
                            config.get("flip_horizontal", False))
        self.parameters.set("flip_vertical",
                            config.get("flip_vertical", False))
        self.parameters.set("transpose", config.get("transpose", False))

        #
        # Camera default display minimum and maximum.
        #
        # These are the values the display will use by default. They can
        # only be changed by changing the config.xml file.
        #
        self.parameters.add(
            params.ParameterInt(name="default_max",
                                value=2000,
                                is_mutable=False))

        self.parameters.add(
            params.ParameterInt(name="default_min",
                                value=100,
                                is_mutable=False))

        self.parameters.set("default_max", config.get("default_max", 2000))
        self.parameters.set("default_min", config.get("default_min", 100))

        self.finished.connect(self.handleFinished)
        self.newData.connect(self.handleNewData)