Example #1
0
    def __init__(self, module_params=None, qt_settings=None, **kwds):
        super().__init__(**kwds)
        self.analyzers = []
        self.basename = None
        self.feed_names = []
        self.number_fn_requested = 0
        self.pixel_size = 0.1
        self.shutters_info = None

        configuration = module_params.get("configuration")

        self.spot_counter = findSpots.SpotCounter(
            max_threads=configuration.get("max_threads"),
            max_size=configuration.get("max_size"))

        self.view = SpotCounterView(module_name=self.module_name,
                                    configuration=configuration)
        self.view.halDialogInit(
            qt_settings,
            module_params.get("setup_name") + " spot counter")

        # Spot counter parameters.
        self.parameters = params.StormXMLObject()

        self.parameters.add(
            params.ParameterRangeInt(
                description="Maximum counts for the spotcounter graph",
                name="max_spots",
                value=500,
                min_value=0,
                max_value=1000,
                is_mutable=False,
                is_saved=False))

        self.parameters.add(
            params.ParameterRangeFloat(description="Scale bar length in nm",
                                       name="scale_bar_len",
                                       value=2000,
                                       min_value=100,
                                       max_value=10000))

        self.parameters.add(
            params.ParameterRangeInt(
                description="Spot detection threshold (camera counts)",
                name="threshold",
                value=250,
                min_value=1,
                max_value=10000))

        self.parameters.add(
            params.ParameterString(description="Which camera to display.",
                                   name="which_camera",
                                   value="",
                                   is_mutable=False,
                                   is_saved=False))
Example #2
0
    def __init__(self, parameters = None, **kwds):
        kwds["parameters"] = parameters    
        super().__init__(**kwds)
        self.hzs_film_off = False
        self.hzs_pname = "hardware_z_scan"
        self.hzs_zvals = None
        self.name = "Hardware Z Scan"

        # Add hardware z scan specific parameters.
        p = self.parameters.addSubSection(self.hzs_pname)

        # FIXME: Should be a parameter custom? Both focuslock and illumination
        #        waveforms should be parsed / created / generated by a single
        #        module somewhere else?
        p.add(params.ParameterString(description = "Frame z steps (in microns).",
                                     name = "z_offsets",
                                     value = ""))
Example #3
0
    def processMessage(self, message):

        if message.isType("add to menu"):
            self.view.addMenuItem(message.getData()["item name"],
                                  message.getData()["item data"])

        elif message.isType("add to ui"):
            [module, parent_widget] = message.getData()["ui_parent"].split(".")
            if (module == self.module_name):
                self.view.addUiWidget(parent_widget,
                                      message.getData()["ui_widget"],
                                      message.getData().get("ui_order"))

        elif message.isType("change directory"):
            self.view.setFilmDirectory(message.getData()["directory"])

        elif message.isType("start"):
            if message.getData()["show_gui"]:
                self.view.addMenuItems()
                self.view.addWidgets()
                self.view.show()

            self.sendMessage(
                halMessage.HalMessage(
                    m_type="change directory",
                    data={"directory": self.view.getFilmDirectory()}))

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

        elif message.isType("stop film"):
            self.view.stopFilm()
            notes_param = params.ParameterString(
                name="notes", value=self.view.getNotesEditText())
            message.addResponse(
                halMessage.HalMessageResponse(
                    source=self.module_name,
                    data={"acquisition": [notes_param]}))

        elif message.isType("tests done"):
            self.view.close()
Example #4
0
def test_parameters_4():

    # Load parameters.
    p1 = params.parameters(test.xmlFilePathAndName("test_parameters.xml"),
                           recurse=True)

    # Create another set of parameters with only 1 item.
    p2 = params.StormXMLObject()
    p2.add(params.ParameterString(name="test_param", value="bar"))
    p2s = p2.addSubSection("camera1")
    p2s.add(params.ParameterSetBoolean(name="flip_horizontal", value=True))
    p2s.add(params.ParameterSetBoolean(name="flip_vertical", value=False))

    # Test copy.
    [p3, ur] = params.copyParameters(p1, p2)

    # Their should be one un-recognized parameter, 'flip_vertical'.
    assert (len(ur) == 1) and (ur[0] == "flip_vertical")

    # 'camera1.flip_horizontal' in p3 should be True.
    assert p3.get("camera1.flip_horizontal")

    # 'test_param' should be 'bar'.
    assert (p3.get("test_param") == "bar")
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 __init__(self, display_name = None, feed_name = "camera1", default_colortable = None, **kwds):
        super().__init__(**kwds)

        # General (alphabetically ordered).
        self.cam_fn = None
        self.cfv_functionality = CameraFrameViewerFunctionality()
        self.color_gradient = None
        self.color_tables = colorTables.ColorTables(os.path.dirname(__file__) + "/../colorTables/all_tables/")
        self.cycle_length = 0
        self.default_colortable = default_colortable
        self.default_parameters = params.StormXMLObject(validate = False) 
        self.display_name = display_name
        self.display_timer = QtCore.QTimer(self)
        self.filming = False
        self.frame = False
        self.parameters = False
        self.rubber_band_rect = None
        self.show_grid = False
        self.show_info = True
        self.show_target = False
        self.stage_functionality = None

        #
        # Keep track of the default feed_name in the default parameters, these
        # are the parameters that will be used when we change parameter files
        # and the parameters file doesn't specify anything for this view.
        #
        self.default_parameters.add(params.ParameterString(name = "feed_name",
                                                           value = feed_name,
                                                           is_mutable = False))

        # Set current parameters to default parameters.
        self.parameters = self.default_parameters.copy()
        
        # UI setup.
        self.ui = cameraDisplayUi.Ui_Frame()
        self.ui.setupUi(self)

        # Camera frame display.
        self.camera_view = self.ui.cameraGraphicsView
        self.camera_scene = qtCameraGraphicsScene.QtCameraGraphicsScene(parent = self)
        self.camera_widget = qtCameraGraphicsScene.QtCameraGraphicsItem()
        
        self.camera_scene.addItem(self.camera_widget)
        self.camera_view.setScene(self.camera_scene)
        self.camera_view.setBackgroundBrush(QtGui.QBrush(QtGui.QColor(0,0,0)))
        
        # Display range slider.
        self.ui.rangeSlider = qtRangeSlider.QVRangeSlider()
        layout = QtWidgets.QGridLayout(self.ui.rangeSliderWidget)
        layout.setContentsMargins(1,1,1,1)
        layout.addWidget(self.ui.rangeSlider)
        self.ui.rangeSliderWidget.setLayout(layout)
        self.ui.rangeSlider.setEmitWhileMoving(True)

        # Color tables combo box.
        for color_name in sorted(self.color_tables.getColorTableNames()):
            self.ui.colorComboBox.addItem(color_name[:-5])

        self.ui.gridAct = QtWidgets.QAction(self.tr("Show Grid"), self)
        self.ui.infoAct = QtWidgets.QAction(self.tr("Hide Info"), self)
        self.ui.targetAct = QtWidgets.QAction(self.tr("Show Target"), self)

        # The default is not to show the shutter or the record button.
        self.ui.recordButton.hide()
        self.ui.shutterButton.hide()

        # These are always hidden unless we are filming.
        self.ui.syncLabel.hide()
        self.ui.syncSpinBox.hide()

        # FIXME: This only sort of works, the text is still getting cut-off.
        self.ui.feedComboBox.setSizeAdjustPolicy(QtWidgets.QComboBox.AdjustToContents)
        
        # Connect signals.
        self.camera_view.horizontalScrollBar().sliderReleased.connect(self.handleScrollBar)
        self.camera_view.newCenter.connect(self.handleNewCenter)
        self.camera_view.newScale.connect(self.handleNewScale)
        self.camera_view.verticalScrollBar().sliderReleased.connect(self.handleScrollBar)

        self.camera_view.dragMove.connect(self.handleDragMove)
        self.camera_view.dragStart.connect(self.handleDragStart)
        self.camera_view.rubberBandChanged.connect(self.handleRubberBandChanged)

        self.ui.autoScaleButton.clicked.connect(self.handleAutoScale)
        self.ui.colorComboBox.currentIndexChanged[str].connect(self.handleColorTableChange)
        self.ui.feedComboBox.currentIndexChanged[str].connect(self.handleFeedChange)
        self.ui.gridAct.triggered.connect(self.handleGrid)
        self.ui.infoAct.triggered.connect(self.handleInfo)        
        self.ui.rangeSlider.doubleClick.connect(self.handleAutoScale)        
        self.ui.rangeSlider.rangeChanged.connect(self.handleRangeChange)
        self.ui.syncSpinBox.valueChanged.connect(self.handleSync)
        self.ui.targetAct.triggered.connect(self.handleTarget)

        # Display timer, the display updates at approximately 10Hz.
        self.display_timer.setInterval(100)
        self.display_timer.timeout.connect(self.handleDisplayTimer)
        self.display_timer.start()
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)
Example #8
0
    def __init__(self, parameters = None, **kwds):
        super().__init__(**kwds)
        self.parameters = parameters
        self.will_overwrite = False

        # Add default film parameters.        
        self.parameters.add(params.ParameterSetString(description = "Acquisition mode",
                                                      name = "acq_mode",
                                                      value = "fixed_length",
                                                      allowed = ["run_till_abort", "fixed_length"]))
        
        self.parameters.add(params.ParameterSetBoolean(description = "Automatically increment movie counter between movies",
                                                       name = "auto_increment",
                                                       value = True))
        
        self.parameters.add(params.ParameterSetBoolean(description = "Run shutters during the movie",
                                                       name = "auto_shutters",
                                                       value = True))
        
        self.parameters.add(params.ParameterString(description = "Current movie file name",
                                                   name = "filename",
                                                   value = "movie"))

        formats = imagewriters.availableFileFormats(parameters.get("test_mode", False))
        self.parameters.add(params.ParameterSetString(description = "Movie file type",
                                                      name = "filetype",
                                                      value = formats[0],
                                                      allowed = formats))
        
        self.parameters.add(params.ParameterRangeInt(description = "Movie length in frames",
                                                     name = "frames",
                                                     value = 10,
                                                     min_value = 1,
                                                     max_value = 1000000000))
        
        self.parameters.add(params.ParameterSetBoolean(description = "Sound bell at the end of long movies",
                                                       name = "want_bell",
                                                       value = True))

        # Initial UI configuration.
        self.ui = filmUi.Ui_GroupBox()
        self.ui.setupUi(self)
        
        for extname in self.parameters.getp("extension").getAllowed():
            self.ui.extensionComboBox.addItem(extname)
        
        for typename in self.parameters.getp("filetype").getAllowed():
            self.ui.filetypeComboBox.addItem(typename)

        self.ui.framesText.setText("")
        self.ui.sizeText.setText("")

        self.setDirectory(self.parameters.get("directory"))
        self.setShutters("NA")
        self.newParameters(self.parameters)
        self.updateFilenameLabel()

        # Connect signals
        self.ui.autoIncCheckBox.stateChanged.connect(self.handleAutoInc)
        self.ui.autoShuttersCheckBox.stateChanged.connect(self.handleAutoShutters)
        self.ui.extensionComboBox.currentIndexChanged.connect(self.handleExtension)
        self.ui.filenameEdit.textChanged.connect(self.handleFilename)
        self.ui.filetypeComboBox.currentIndexChanged.connect(self.handleFiletype)
        self.ui.indexSpinBox.valueChanged.connect(self.handleIndex)
        self.ui.lengthSpinBox.valueChanged.connect(self.handleLength)
        self.ui.liveModeCheckBox.stateChanged.connect(self.handleLiveMode)
        self.ui.modeComboBox.currentIndexChanged.connect(self.handleMode)
Example #9
0
    def handleResponses(self, message):

        if message.isType("get functionality"):
            assert (len(message.getResponses()) == 1)
            for response in message.getResponses():
                self.camera_functionalities.append(response.getData()["functionality"])
                self.number_fn_requested -= 1

            # And we are done with the parameter change.
            if self.parameter_change and (self.number_fn_requested == 0):
                self.parameter_change = False
                self.sendMessage(halMessage.HalMessage(m_type = "parameters changed"))

        # Modules that need additional time to get ready to film should
        # specify at start up that they need to be waited for.
        elif message.isType("start film"):

            # No modules requested waits, so start now.
            if (len(self.wait_for) == 0):
                self.startCameras()
        
        # Modules are expected to add their current parameters as responses
        # to the 'stop film' message. We save them in an xml file here.
        elif message.isType("stop film"):
            self.film_state = "idle"
            acq_p = None
            notes = ""
            film_settings = message.getData()["film settings"]
            number_frames = message.getData()["number frames"]
            if film_settings.isSaved():
                to_save = params.StormXMLObject()
                acq_p = to_save.addSubSection("acquisition")
                acq_p.add(params.ParameterString(name = "version",
                                                 value = hgit.getVersion()))
                acq_p.add(params.ParameterInt(name = "number_frames",
                                              value = number_frames))
                for response in message.getResponses():
                    data = response.getData()

                    # Add general parameters 'en-bloc'.
                    if "parameters" in data:
                        to_save.addSubSection(response.source,
                                              svalue = data["parameters"])

                    # Add any acquisition parameters, these will be a list.
                    if "acquisition" in data:
                        for p in data["acquisition"]:
                            acq_p.addParameter(p.getName(), p)
                            if (p.getName() == "notes"):
                                notes = p.getv()

                to_save.saveToFile(film_settings.getBasename() + ".xml")

                if self.logfile_fp is not None:
                    msg = ",".join([str(datetime.datetime.now()),
                                    film_settings.getBasename(),
                                    notes])
                    msg += "\r\n"
                    self.logfile_fp.write(msg)
                    self.logfile_fp.flush()

            # Now that everything is complete end the filming lock out.
            self.setLockout(False, acquisition_parameters = acq_p)
Example #10
0
    def __init__(self, parameters = None, **kwds):
        """
        parameters - This is just the 'feed' section of the parameters.
        """
        super().__init__(**kwds)

        self.feeds = {}
        if parameters is None:
            return

        # Create the feeds.
        self.parameters = parameters
        for feed_name in self.parameters.getAttrs():
            file_params = self.parameters.get(feed_name)
            
            # Create default feed parameters.
            max_value = 100000
            feed_params = params.StormXMLObject()

            # Feeds are saved with their name as the extension.
            feed_params.add(params.ParameterString(name = "extension",
                                                   value = feed_name,
                                                   is_mutable = True))
            
            feed_params.add(params.ParameterString(name = "feed_type",
                                                   value = "",
                                                   is_mutable = False))

            feed_params.add(params.ParameterSetBoolean(name = "saved",
                                                       value = False))

            # This is the camera that drives the feed.
            feed_params.add(params.ParameterString(name = "source",
                                                   value = "",
                                                   is_mutable = False))
            
            feed_params.add(params.ParameterRangeInt(description = "AOI X start.",
                                                     name = "x_start",
                                                     value = 1,
                                                     min_value = 1,
                                                     max_value = max_value))

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

            feed_params.add(params.ParameterRangeInt(description = "AOI Y start.",
                                                     name = "y_start",
                                                     value = 1,
                                                     min_value = 1,
                                                     max_value = max_value))
            
            feed_params.add(params.ParameterRangeInt(description = "AOI Y end.",
                                                     name = "y_end",
                                                     value = 1,
                                                     min_value = 1,
                                                     max_value = max_value))

            # Figure out what type of feed this is.
            fclass = None
            feed_type = file_params.get("feed_type")
            if (feed_type == "average"):
                fclass = FeedFunctionalityAverage
                
                feed_params.add(params.ParameterInt(description = "Number of frames to average.",
                                                    name = "frames_to_average",
                                                    value = 1))
                            
            elif (feed_type == "interval"):
                fclass = FeedFunctionalityInterval

                feed_params.add(params.ParameterInt(description = "Interval cycle length.",
                                                    name = "cycle_length",
                                                    value = 1))
                
                feed_params.add(params.ParameterCustom(description = "Frames to capture.",
                                                       name = "capture_frames",
                                                       value = "1"))

            elif (feed_type == "slice"):
                fclass = FeedFunctionalitySlice
            else:
                raise FeedException("Unknown feed type '" + feed_type + "' in feed '" + feed_name + "'")

            # Update with values from the parameters file. Depending on the parameters
            # file it might include parameters that we don't have and which we silently
            # ignore.
            #
            for attr in file_params.getAttrs():
                if feed_params.has(attr):
                    feed_params.setv(attr, file_params.get(attr))

            # Replace the values in the parameters that were read from a file with these values.
            self.parameters.addSubSection(feed_name, feed_params, overwrite = True)

            camera_name = feed_params.get("source") + "." + feed_name
            self.feeds[camera_name] = fclass(feed_name = feed_name,
                                             camera_name = camera_name,
                                             parameters = feed_params)
Example #11
0
    def __init__(self, config=None, is_master=False, **kwds):
        kwds["config"] = config
        super().__init__(**kwds)
        self.reversed_shutter = config.get("reversed_shutter", False)

        # The camera configuration.
        self.camera_functionality = cameraFunctionality.CameraFunctionality(
            camera_name=self.camera_name,
            have_emccd=True,
            have_preamp=True,
            have_shutter=True,
            have_temperature=True,
            is_master=is_master,
            parameters=self.parameters)
        self.camera_functionality.setEMCCDGain = self.setEMCCDGain
        self.camera_functionality.toggleShutter = self.toggleShutter

        # Load Andor DLL & get the camera.
        andor.loadAndorDLL(
            os.path.join(config.get("andor_path"), config.get("andor_dll")))
        handle = andor.getCameraHandles()[config.get("camera_id")]
        self.camera = andor.AndorCamera(config.get("andor_path"), handle)

        # Dictionary of Andor camera properties we'll support.
        self.andor_props = {
            "adchannel": True,
            "baselineclamp": True,
            "emccd_advanced": True,
            "emccd_gain": True,
            "emgainmode": True,
            "exposure_time": True,
            "extension": True,
            "external_trigger": True,
            "frame_transfer_mode": True,
            "hsspeed": True,
            "isolated_cropmode": True,
            "kinetic_cycle_time": True,
            "low_during_filming": True,
            "off_during_filming": True,
            "preampgain": True,
            "saved": True,
            "temperature": True,
            "vsamplitude": True,
            "vsspeed": True,
            "x_bin": True,
            "x_end": True,
            "x_start": True,
            "y_bin": True,
            "y_end": True,
            "y_start": True
        }

        # Add Andor EMCCD specific parameters.
        self.parameters.setv("max_intensity", self.camera.getMaxIntensity())

        [gain_low, gain_high] = self.camera.getEMGainRange()
        self.parameters.add(
            "emccd_gain",
            params.ParameterRangeInt(description="EMCCD Gain",
                                     name="emccd_gain",
                                     value=gain_low,
                                     min_value=gain_low,
                                     max_value=gain_high,
                                     order=2))

        # Adjust ranges of the size and binning parameters.
        [x_size, y_size] = self.camera.getCameraSize()
        self.parameters.getp("x_end").setMaximum(x_size)
        self.parameters.getp("x_start").setMaximum(x_size)
        self.parameters.getp("y_end").setMaximum(y_size)
        self.parameters.getp("y_start").setMaximum(y_size)

        self.parameters.setv("x_end", x_size)
        self.parameters.setv("y_end", y_size)
        self.parameters.setv("x_chip", x_size)
        self.parameters.setv("y_chip", y_size)

        [x_max_bin, y_max_bin] = self.camera.getMaxBinning()
        self.parameters.getp("x_bin").setMaximum(x_max_bin)
        self.parameters.getp("y_bin").setMaximum(y_max_bin)

        # FIXME: Need to check if camera supports frame transfer mode.
        self.parameters.add(
            params.ParameterSetInt(
                description="Frame transfer mode (0 = off, 1 = on)",
                name="frame_transfer_mode",
                value=1,
                allowed=[0, 1]))

        [mint, maxt] = self.camera.getTemperatureRange()
        self.parameters.add(
            params.ParameterRangeInt(description="Target temperature",
                                     name="temperature",
                                     value=-70,
                                     min_value=mint,
                                     max_value=maxt))

        preamp_gains = self.camera.getPreampGains()
        self.parameters.add(
            params.ParameterSetFloat(description="Pre-amplifier gain",
                                     name="preampgain",
                                     value=preamp_gains[0],
                                     allowed=preamp_gains))

        hs_speeds = self.camera.getHSSpeeds()[0]
        self.parameters.add(
            params.ParameterSetFloat(description="Horizontal shift speed",
                                     name="hsspeed",
                                     value=hs_speeds[0],
                                     allowed=hs_speeds))

        vs_speeds = self.camera.getVSSpeeds()
        self.parameters.add(
            params.ParameterSetFloat(description="Vertical shift speed",
                                     name="vsspeed",
                                     value=vs_speeds[-1],
                                     allowed=vs_speeds))

        #        self.parameters.getp("exposure_time").setMaximum(self.camera.getMaxExposure())

        self.parameters.getp("exposure_time").setOrder(2)
        self.parameters.setv("exposure_time", 0.0)

        self.parameters.add(
            params.ParameterRangeFloat(
                description="Kinetic cycle time (seconds)",
                name="kinetic_cycle_time",
                value=0.0,
                min_value=0.0,
                max_value=100.0))

        ad_channels = list(range(self.camera.getNumberADChannels()))
        self.parameters.add(
            params.ParameterSetInt(
                description="Analog to digital converter channel",
                name="adchannel",
                value=0,
                allowed=ad_channels))

        n_modes = list(range(self.camera.getNumberEMGainModes()))
        self.parameters.add(
            params.ParameterSetInt(description="EMCCD gain mode",
                                   name="emgainmode",
                                   value=0,
                                   allowed=n_modes))

        self.parameters.add(
            params.ParameterSetBoolean(description="Baseline clamp",
                                       name="baselineclamp",
                                       value=True))

        # FIXME: Need to get amplitudes from the camera.
        self.parameters.add(
            params.ParameterSetInt(description="Vertical shift amplitude",
                                   name="vsamplitude",
                                   value=0,
                                   allowed=[0, 1, 2]))

        self.parameters.add(
            params.ParameterSetBoolean(description="Fan off during filming",
                                       name="off_during_filming",
                                       value=False))

        self.parameters.add(
            params.ParameterSetBoolean(description="Fan low during filming",
                                       name="low_during_filming",
                                       value=False))

        self.parameters.add(
            params.ParameterSetBoolean(
                description="Use an external camera trigger",
                name="external_trigger",
                value=False))

        self.parameters.add(
            params.ParameterString(description="Camera head model",
                                   name="head_model",
                                   value=self.camera.getHeadModel(),
                                   is_mutable=False))

        self.parameters.add(
            params.ParameterSetBoolean(description="Isolated crop mode",
                                       name="isolated_cropmode",
                                       value=False))

        self.parameters.add(
            params.ParameterSetBoolean(description="Advanced EMCCD gain mode",
                                       name="emccd_advanced",
                                       value=False))

        self.newParameters(self.parameters, initialization=True)