Example #1
0
    def __init__(self, parameters = None, **kwds):
        kwds["parameters"] = parameters    
        super().__init__(**kwds)
        self.clm_counter = 0
        self.clm_max_zvals = 0
        self.clm_pname = "calibrate"
        self.clm_zvals = []
        self.name = "Calibrate"

        # Add calibration specific parameters.
        p = self.parameters.addSubSection(self.clm_pname)
        p.add(params.ParameterRangeInt(description = "Frames to pause between steps.",
                                       name = "frames_to_pause",
                                       value = 2,
                                       min_value = 1,
                                       max_value = 100))        
        p.add(params.ParameterRangeInt(description = "Frames before to pause at start.",
                                       name = "deadtime",
                                       value = 20,
                                       min_value = 1,
                                       max_value = 100))
        p.add(params.ParameterRangeFloat(description = "Distance +- z to move in nanometers.",
                                         name = "range",
                                         value = 600,
                                         min_value = 100,
                                         max_value = 5000))
        p.add(params.ParameterRangeFloat(description = "Step size in z in nanometers.",
                                         name = "step_size",
                                         value = 10,
                                         min_value = 1,
                                         max_value = 100))
Example #2
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 #3
0
    def __init__(self, parameters=None, **kwds):
        kwds["parameters"] = parameters
        super().__init__(**kwds)
        # self.szs  Software Z Scan object
        self.szs_counter = 0
        self.szs_max_zvals = 0
        self.szs_pname = "software_z_scan"
        self.szs_zvals = []
        self.szs_first_move = True
        self.szs_film_off = False
        self.name = "Software Z Scan"

        # Add calibration specific parameters.
        p = self.parameters.addSubSection(self.szs_pname)
        p.add(
            params.ParameterRangeInt(
                description="Frames to pause between z-steps.",
                name="frames_per_step",
                value=2,
                min_value=1,
                max_value=100))
        p.add(
            params.ParameterRangeInt(
                description="Frames to pause before scan starts.",
                name="deadtime",
                value=2,
                min_value=1,
                max_value=100))
        p.add(
            params.ParameterRangeFloat(
                description="Distance +- z to move in nanometers.",
                name="range",
                value=5000,
                min_value=100,
                max_value=50000))
        p.add(
            params.ParameterRangeFloat(
                description="Step size in z in nanometers.",
                name="step_size",
                value=250,
                min_value=1,
                max_value=10000))
Example #4
0
    def __init__(self, parameters=None, **kwds):
        kwds["parameters"] = parameters
        super().__init__(**kwds)
        self.name = "Optimal"
        self.olm_bracket_step = None
        self.olm_counter = 0
        self.olm_fvalues = None
        self.olm_mode = "none"
        self.olm_pname = "optimal_mode"
        self.olm_quality_threshold = 0
        self.olm_relative_z = None
        self.olm_scan_hold = None
        self.olm_scan_step = None
        self.olm_scan_state = "na"
        self.olm_zvalues = None

        # Add optimal lock specific parameters.
        p = self.parameters.addSubSection(self.olm_pname)
        p.add(
            params.ParameterRangeFloat(
                description="Distance +- z in nanometers",
                name="bracket_step",
                value=1000.0,
                min_value=10.0,
                max_value=10000.0))
        p.add(
            params.ParameterRangeFloat(description="Minimum 'quality' signal",
                                       name="quality_threshold",
                                       value=0.0,
                                       min_value=0.0,
                                       max_value=1000.0))
        p.add(
            params.ParameterRangeFloat(
                description="Step size in z in nanometers",
                name="scan_step",
                value=100.0,
                min_value=10.0,
                max_value=1000.0))
        p.add(
            params.ParameterRangeInt(
                description="Frames to pause between steps",
                name="scan_hold",
                value=10,
                min_value=1,
                max_value=100))
Example #5
0
    def __init__(self, config=None, is_master=False, **kwds):
        kwds["config"] = config
        super().__init__(**kwds)

        # The camera configuration.
        self.camera_functionality = cameraFunctionality.CameraFunctionality(
            camera_name=self.camera_name,
            is_master=is_master,
            parameters=self.parameters)

        # Load the library and start the camera.
        self.camera = hcam.HamamatsuCameraMR(camera_id=config.get("camera_id"))

        # Dictionary of the Hamamatsu camera properties we'll support.
        self.hcam_props = {
            "binning": True,
            "defect_correct_mode": True,
            "exposure_time": True,
            "output_trigger_kind[0]": True,
            "output_trigger_polarity[0]": True,
            "readout_speed": True,
            "subarray_hpos": True,
            "subarray_hsize": True,
            "subarray_vpos": True,
            "subarray_vsize": True,
            "trigger_source": True
        }

        max_intensity = 2**self.camera.getPropertyValue("bit_per_channel")[0]
        self.parameters.setv("max_intensity", max_intensity)

        self.parameters.setv("exposure_time", 0.1)

        x_chip = self.camera.getPropertyValue("image_width")[0]
        y_chip = self.camera.getPropertyValue("image_height")[0]
        self.parameters.setv("x_chip", x_chip)
        self.parameters.setv("y_chip", y_chip)

        text_values = self.camera.sortedPropertyTextOptions("binning")
        self.parameters.add(
            params.ParameterSetString(description="Camera binning.",
                                      name="binning",
                                      value=text_values[0],
                                      allowed=text_values))

        text_values = self.camera.sortedPropertyTextOptions(
            "defect_correct_mode")
        self.parameters.add(
            params.ParameterSetString(description="Defect correction mode.",
                                      name="defect_correct_mode",
                                      value=text_values[0],
                                      allowed=text_values))

        # FIXME: Can't save this as the property name is not valid XML.
        text_values = self.camera.sortedPropertyTextOptions(
            "output_trigger_kind[0]")
        self.parameters.add(
            params.ParameterSetString(
                description="Camera 'fire' pin output kind.",
                name="output_trigger_kind[0]",
                value=text_values[1],
                allowed=text_values,
                is_saved=False))

        # FIXME: Can't save this as the property name is not valid XML.
        text_values = self.camera.sortedPropertyTextOptions(
            "output_trigger_polarity[0]")
        self.parameters.add(
            params.ParameterSetString(
                description="Camera 'fire' pin output polarity.",
                name="output_trigger_polarity[0]",
                value=text_values[1],
                allowed=text_values,
                is_saved=False))

        self.parameters.add(
            params.ParameterRangeInt(description="Read out speed",
                                     name="readout_speed",
                                     value=2,
                                     min_value=1,
                                     max_value=2))

        # These all need to multiples of 4.
        self.parameters.add(
            params.ParameterRangeInt(description="AOI X start",
                                     name="subarray_hpos",
                                     value=0,
                                     min_value=0,
                                     max_value=(x_chip - 1)))

        self.parameters.add(
            params.ParameterRangeInt(description="AOI Width",
                                     name="subarray_hsize",
                                     value=x_chip,
                                     min_value=4,
                                     max_value=x_chip))

        self.parameters.add(
            params.ParameterRangeInt(description="AOI Y start",
                                     name="subarray_vpos",
                                     value=0,
                                     min_value=0,
                                     max_value=(y_chip - 1)))

        self.parameters.add(
            params.ParameterRangeInt(description="AOI Height",
                                     name="subarray_vsize",
                                     value=y_chip,
                                     min_value=4,
                                     max_value=y_chip))

        text_values = self.camera.sortedPropertyTextOptions("trigger_source")
        self.parameters.add(
            params.ParameterSetString(description="Camera trigger source.",
                                      name="trigger_source",
                                      value=text_values[0],
                                      allowed=text_values))

        ## Disable editing of the HAL versions of these parameters.
        for param in [
                "x_bin", "x_end", "x_start", "y_end", "y_start", "y_bin"
        ]:
            self.parameters.getp(param).setMutable(False)

        self.newParameters(self.parameters, initialization=True)
Example #6
0
    def __init__(self, config = None, is_master = False, **kwds):
        """
        Create an Andor camera control object and initialize
        the camera.
        """
        kwds["config"] = config
        super().__init__(**kwds)
        self.is_master = is_master
        
        # The camera functionality.
        self.camera_functionality = cameraFunctionality.CameraFunctionality(camera_name = self.camera_name,
                                                                            have_temperature = True,
                                                                            is_master = is_master,
                                                                            parameters = self.parameters)
        
        # Load the library and start the camera.
        andor.loadSDK3DLL(config.get("andor_sdk"))
        self.camera = andor.SDK3Camera(config.get("camera_id"))

        # Dictionary of the Andor settings we'll use and their types.
        #
        # FIXME: Maybe the AndorSDK3 module should know the types?
        #
        self.andor_props = {"AOIBinning" : "enum",
                            "AOIHeight" : "int",
                            "AOILeft" : "int",
                            "AOITop" : "int",
                            "AOIWidth" : "int",
                            "CycleMode" : "enum",
                            "ExposureTime" : "float",
                            "FrameCount" : "int",
                            "FrameRate" : "float",
                            "FanSpeed" : "enum",
                            "IOInvert" : "bool",
                            "IOSelector" : "enum",
                            "SensorCooling" : "bool",
                            "SensorHeight" : "int",
                            "SensorTemperature" : "float",
                            "SensorWidth" : "int",
                            "SimplePreAmpGainControl" : "enum",
                            "TemperatureControl" : "enum",
                            "TemperatureStatus" : "enum",
                            "TriggerMode" : "enum"}
        
        self.camera.setProperty("CycleMode", self.andor_props["CycleMode"], "Continuous")

        # Set trigger mode.
        print(">", self.camera_name, "trigger mode set to", config.get("trigger_mode"))
        self.camera.setProperty("TriggerMode", self.andor_props["TriggerMode"], config.get("trigger_mode"))

        # Add Andor SDK3 specific parameters.
        #
        # FIXME: These parameter have different names but the same meaning as the
        #        parameters HAL defines. How to reconcile? It seems best to use
        #        these names as their meaning will be clearly to user.
        #
        max_intensity = 2**16
        self.parameters.setv("max_intensity", max_intensity)

        x_chip = self.camera.getProperty("SensorWidth", self.andor_props["SensorWidth"])
        y_chip = self.camera.getProperty("SensorHeight", self.andor_props["SensorHeight"])
        self.parameters.setv("x_chip", x_chip)
        self.parameters.setv("y_chip", y_chip)

        self.parameters.add(params.ParameterSetString(description = "AOI Binning",
                                                      name = "AOIBinning",
                                                      value = "1x1",
                                                      allowed = ["1x1", "2x2", "3x3", "4x4", "8x8"]))
        
        self.parameters.add(params.ParameterRangeInt(description = "AOI Width",
                                                     name = "AOIWidth",
                                                     value = x_chip,
                                                     min_value = 128,
                                                     max_value = x_chip))
        
        self.parameters.add(params.ParameterRangeInt(description = "AOI Height",
                                                     name = "AOIHeight",
                                                     value = y_chip,
                                                     min_value = 128,
                                                     max_value = y_chip))

        self.parameters.add(params.ParameterRangeInt(description = "AOI Left",
                                                     name = "AOILeft",
                                                     value = 1,
                                                     min_value = 1,
                                                     max_value = x_chip/2))

        self.parameters.add(params.ParameterRangeInt(description = "AOI Top",
                                                     name = "AOITop",
                                                     value = 1,
                                                     min_value = 1,
                                                     max_value = y_chip/2))

        self.parameters.add(params.ParameterSetString(description = "Fan Speed",
                                                      name = "FanSpeed",
                                                      value = "On",
                                                      allowed = ["On", "Off"]))

        self.parameters.add(params.ParameterSetBoolean(description = "Sensor cooling",
                                                       name = "SensorCooling",
                                                       value = True))

        self.parameters.add(params.ParameterSetString(description = "Pre-amp gain control",
                                                      name = "SimplePreAmpGainControl",
                                                      value = "16-bit (low noise & high well capacity)",
                                                      allowed = ["16-bit (low noise & high well capacity)", 
                                                                  "Something else.."]))

        self.parameters.add(params.ParameterRangeFloat(description = "Exposure time (seconds)", 
                                                       name = "ExposureTime", 
                                                       value = 0.1,
                                                       min_value = 0.0,
                                                       max_value = 10.0))

        # FIXME: We never actually set this. Maybe we can't?
        self.parameters.add(params.ParameterRangeFloat(description = "Target temperature", 
                                                       name = "temperature", 
                                                       value = -20.0,
                                                       min_value = -50.0,
                                                       max_value = 25.0))

        # Disable editing of the HAL versions of these parameters.
        for param in ["exposure_time", "x_bin", "x_end", "x_start", "y_end", "y_start", "y_bin"]:
            self.parameters.getp(param).setMutable(False)

        self.newParameters(self.parameters, initialization = True)
Example #7
0
    def __init__(self, w1=None, configuration=None, **kwds):
        super().__init__(**kwds)
        self.w1 = w1

        # Query W1 for it's maximum speed.
        max_speed = self.w1.commandResponse("MS_MAX,?")
        assert max_speed is not None

        # Create dictionaries for the configuration of the
        # filter wheels and two dichroic mirror sets.
        self.filter_wheel_1_config = {}
        values = configuration.get("filter_wheel_1")
        filter_names = values.split(",")
        for pos, filter_name in enumerate(filter_names):
            self.filter_wheel_1_config[filter_name] = pos + 1

        self.filter_wheel_2_config = {}
        values = configuration.get("filter_wheel_2")
        filter_names = values.split(",")
        for pos, filter_name in enumerate(filter_names):
            self.filter_wheel_2_config[filter_name] = pos + 1

        self.dichroic_mirror_config = {}
        values = configuration.get("dichroic_mirror")
        dichroic_names = values.split(",")
        for pos, dichroic_name in enumerate(dichroic_names):
            self.dichroic_mirror_config[dichroic_name] = pos + 1

        self.camera_dichroic_config = {}
        values = configuration.get("camera_dichroic")
        camera_dichroic_names = values.split(",")
        for pos, camera_dichroic in enumerate(camera_dichroic_names):
            self.camera_dichroic_config[camera_dichroic] = pos + 1

        # Create parameters
        self.parameters = params.StormXMLObject()

        self.parameters.add(
            params.ParameterSetBoolean(
                description="Bypass spinning disk for brightfield mode?",
                name="bright_field_bypass",
                value=False))

        self.parameters.add(
            params.ParameterSetBoolean(description="Spin the disk?",
                                       name="spin_disk",
                                       value=True))

        # Disk properties
        self.parameters.add(
            params.ParameterSetString(
                description="Disk pinhole size",
                name="disk",
                value="50-micron pinholes",
                allowed=["50-micron pinholes", "25-micron pinholes"]))

        self.parameters.add(
            params.ParameterRangeInt(description="Disk speed (RPM)",
                                     name="disk_speed",
                                     value=max_speed,
                                     min_value=1,
                                     max_value=max_speed))

        # Dichroic mirror position
        values = sorted(self.dichroic_mirror_config.keys())
        self.parameters.add(
            params.ParameterSetString(description="Dichroic mirror position",
                                      name="dichroic_mirror",
                                      value=values[0],
                                      allowed=values))

        # Filter wheel positions
        values = sorted(self.filter_wheel_1_config.keys())
        self.parameters.add(
            params.ParameterSetString(
                description="Camera 1 Filter Wheel Position (1-10)",
                name="filter_wheel_pos1",
                value=values[0],
                allowed=values))

        values = sorted(self.filter_wheel_2_config.keys())
        self.parameters.add(
            params.ParameterSetString(
                description="Camera 2 Filter Wheel Position (1-10)",
                name="filter_wheel_pos2",
                value=values[0],
                allowed=values))

        # Camera dichroic positions
        values = sorted(self.camera_dichroic_config.keys())
        self.parameters.add(
            params.ParameterSetString(
                description="Camera dichroic mirror position (1-3)",
                name="camera_dichroic_mirror",
                value=values[0],
                allowed=values))

        # Aperature settings
        self.parameters.add(
            params.ParameterRangeInt(
                description="Aperture value (1-10; small to large)",
                name="aperture",
                value=10,
                min_value=1,
                max_value=10))

        self.newParameters(self.parameters, initialization=True)
Example #8
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 #9
0
    def __init__(self, config=None, is_master=False, **kwds):
        kwds["config"] = config
        super().__init__(**kwds)
        self.is_master = is_master

        # The camera functionality.
        self.camera_functionality = cameraFunctionality.CameraFunctionality(
            camera_name=self.camera_name,
            is_master=self.is_master,
            parameters=self.parameters)

        # Initialize library.
        spinnaker.pySpinInitialize(verbose=False)

        # Get the camera & set some defaults.
        self.camera = spinnaker.getCamera(config.get("camera_id"))

        # Set FLIR-specific camera properties to control relationship between
        # exposure time and frame rate: This dictionary will allow extension in the future if needed
        self.exposure_control = {"CameraControlExposure": True}

        # Extract preset values if provided
        if config.has("presets"):
            # Extract preset values
            presets = config.get("presets")

            print("Configuring preset values of spinnaker camera: " +
                  str(config.get("camera_id")))

            # Loop over values and set them
            for p_name in presets.getAttrs():
                if self.camera.hasProperty(
                        p_name
                ):  # Confirm the camera has the property and warn if not
                    p_value = presets.get(p_name)
                    self.camera.setProperty(p_name, p_value)  # Set value
                    set_value = self.camera.getProperty(
                        p_name).getValue()  # Check set
                    print("   " + str(p_name) + ": " + str(p_value) + " (" +
                          str(set_value) + ")")
                else:
                    if p_name not in self.exposure_control.keys():
                        print("!!!! preset " + str(p_name) +
                              " is not a valid parameter for this camera")

            # Set the exposure-frame-rate-control parameters
            self.exposure_control["CameraControlExposure"] = presets.get(
                "CameraControlExposure", True)
            print("Set exposure control properties:")
            for key in self.exposure_control.keys():
                print("   " + str(key) + ": " +
                      str(self.exposure_control[key]))

        else:
            print("No presets provided for spinnaker camera: " +
                  str(config.get("camera_id")))

        # Verify that we have turned off some of these 'features'.
        ## REMOVED THIS BLOCK AS IT IS CAMERA SPECIFIC
        #for feature in ["pgrDefectPixelCorrectionEnable",
        #                "BlackLevelClampingEnable",
        #                "SharpnessEnabled",
        #                "GammaEnabled"]:
        #    if self.camera.hasProperty(feature):
        #        assert not self.camera.getProperty(feature).getValue()

        # Configure 'master' cameras to not use triggering.
        #
        self.camera.getProperty("TriggerMode")
        if self.is_master:
            self.camera.setProperty("TriggerMode", "Off")

            # This line is connected to the DAQ.
            self.camera.setProperty("LineSelector", "Line1")
            self.camera.setProperty("LineSource", "ExposureActive")

            # This line is connected to the other cameras.
            self.camera.setProperty("LineSelector", "Line2")
            self.camera.setProperty("LineMode", "Output")
            self.camera.setProperty("LineSource", "ExposureActive")

        # Configure 'slave' cameras to use triggering.
        # We are following: http://www.ptgrey.com/KB/11052
        #
        # "Configuring Synchronized Capture with Multiple Cameras"
        #
        # Also, we connected the master camera to the DAQ card
        # using it's OPTO-OUT connection.
        #
        else:
            self.camera.setProperty("TriggerMode", "On")
            self.camera.setProperty("TriggerSource", "Line3")
            self.camera.setProperty("TriggerOverlap", "ReadOut")
            self.camera.setProperty(
                "TriggerActivation",
                config.get("trigger_activation", "FallingEdge"))

        #
        # Dictionary of Point Grey specific camera parameters.
        #

        # All cameras can set these.
        self.pgrey_props = {
            "BlackLevel": True,
            "Gain": True,
            "Height": True,
            "OffsetX": True,
            "OffsetY": True,
            "Width": True
        }

        # Only master cameras can set "AcquisitionFrameRate".
        if self.is_master:
            self.pgrey_props["AcquisitionFrameRate"] = True

            #
            # FIXME: We're using a made up max_value for this parameter because it is
            #        the default parameter. If we use the real range then any
            #        parameters that are added later could have their frame rate
            #        changed in an unexpected way. Unfortunately this also means that
            #        if the user goes above the real maximum on this parameter then
            #        the software will crash.
            #
            self.parameters.add(
                params.ParameterRangeFloat(
                    description="Acquisition frame rate (FPS)",
                    name="AcquisitionFrameRate",
                    value=10.0,
                    max_value=5000,
                    min_value=self.camera.getProperty(
                        "AcquisitionFrameRate").getMinimum()))

        # Slave cameras can set "ExposureTime".
        #
        # FIXME? If this is too large then the slave will be taking images
        #        at a different rate than master. Maybe this should be
        #        limited? Automatically set based on "master" frame rate?
        #
        else:
            self.pgrey_props["ExposureTime"] = True
            self.parameters.add(
                params.ParameterRangeFloat(description="Exposure time (us)",
                                           name="ExposureTime",
                                           value=99800.0,
                                           max_value=self.camera.getProperty(
                                               "ExposureTime").getMaximum(),
                                           min_value=self.camera.getProperty(
                                               "ExposureTime").getMinimum()))

        # Load properties as required by the spinnaker Python wrapper.
        for pname in self.pgrey_props:
            self.camera.getProperty(pname)

        max_intensity = 2**12
        self.parameters.setv("max_intensity", max_intensity)

        # Set chip size and HAL parameter ranges.
        x_chip = self.camera.getProperty("WidthMax").getValue()
        self.parameters.setv("x_chip", x_chip)
        for pname in ["x_end", "x_start"]:
            self.parameters.getp(pname).setMaximum(x_chip)

        y_chip = self.camera.getProperty("HeightMax").getValue()
        self.parameters.setv("y_chip", y_chip)
        for pname in ["y_end", "y_start"]:
            self.parameters.getp(pname).setMaximum(y_chip)

        #
        # Reset X, Y offsets. We do this here because otherwise the
        # initial ranges of these parameters will be incorrect and the
        # only way to fix them is using the parameters editor.
        #
        self.camera.setProperty("OffsetX", 0)
        self.camera.setProperty("OffsetY", 0)

        self.parameters.add(
            params.ParameterRangeFloat(
                description="Black level",
                name="BlackLevel",
                value=1.0,
                max_value=self.camera.getProperty("BlackLevel").getMaximum(),
                min_value=self.camera.getProperty("BlackLevel").getMinimum()))

        self.parameters.add(
            params.ParameterRangeFloat(
                description="Gain",
                name="Gain",
                value=10.0,
                max_value=self.camera.getProperty("Gain").getMaximum(),
                min_value=self.camera.getProperty("Gain").getMinimum()))

        self.parameters.add(
            params.ParameterRangeInt(description="AOI height",
                                     name="Height",
                                     value=y_chip,
                                     max_value=y_chip,
                                     min_value=4))

        self.parameters.add(
            params.ParameterRangeInt(description="AOI x offset",
                                     name="OffsetX",
                                     value=0,
                                     max_value=x_chip - 4,
                                     min_value=0))

        self.parameters.add(
            params.ParameterRangeInt(description="AOI y offset",
                                     name="OffsetY",
                                     value=0,
                                     max_value=y_chip - 4,
                                     min_value=0))

        self.parameters.add(
            params.ParameterRangeInt(description="AOI width",
                                     name="Width",
                                     value=x_chip,
                                     max_value=x_chip,
                                     min_value=4))

        # Disable editing of the HAL versions of these parameters.
        for param in [
                "exposure_time", "x_bin", "x_end", "x_start", "y_end",
                "y_start", "y_bin"
        ]:
            self.parameters.getp(param).setMutable(False)

        self.newParameters(self.parameters, initialization=True)
    def __init__(self, config=None, is_master=False, **kwds):
        kwds["config"] = config
        super().__init__(**kwds)
        self.is_master = is_master

        # The camera functionality.
        self.camera_functionality = cameraFunctionality.CameraFunctionality(
            camera_name=self.camera_name,
            is_master=self.is_master,
            parameters=self.parameters)

        # Initialize library.
        spinnaker.pySpinInitialize(verbose=False)

        # Get the camera & set some defaults.
        self.camera = spinnaker.getCamera(config.get("camera_id"))

        # In order to turn off pixel defect correction the camera has
        # to be in video mode 0.
        self.camera.setProperty("VideoMode", "Mode0")
        self.camera.setProperty("pgrDefectPixelCorrectionEnable", False)

        # Set pixel format.
        #self.camera.setProperty("PixelFormat", "Mono12Packed")
        #self.camera.setProperty("PixelFormat", "Mono12p")
        self.camera.setProperty("PixelFormat", "Mono16")

        self.camera.setProperty("VideoMode", config.get("video_mode"))

        # We don't want any of these 'features'.
        self.camera.setProperty("AcquisitionFrameRateAuto", "Off")
        self.camera.setProperty("ExposureAuto", "Off")
        self.camera.setProperty("GainAuto", "Off")

        if self.camera.hasProperty("pgrExposureCompensationAuto"):
            self.camera.setProperty("pgrExposureCompensationAuto", "Off")

        if self.camera.hasProperty("BlackLevelClampingEnable"):
            self.camera.setProperty("BlackLevelClampingEnable", False)

        if self.camera.hasProperty("SharpnessEnabled"):
            self.camera.setProperty("SharpnessEnabled", False)

        if self.camera.hasProperty("GammaEnabled"):
            self.camera.setProperty("GammaEnabled", False)

        #
        # No idea what this means in the context of a black and white
        # camera. We try and turn it off but that seems to be much
        # harder to do than one would hope.
        #
        self.camera.setProperty("OnBoardColorProcessEnabled", False)

        # Verify that we have turned off some of these 'features'.
        for feature in [
                "pgrDefectPixelCorrectionEnable", "BlackLevelClampingEnable",
                "SharpnessEnabled", "GammaEnabled"
        ]:
            if self.camera.hasProperty(feature):
                assert not self.camera.getProperty(feature).getValue()

        # Configure 'master' cameras to not use triggering.
        #
        self.camera.getProperty("TriggerMode")
        if self.is_master:
            self.camera.setProperty("TriggerMode", "Off")

            # This line is connected to the DAQ.
            self.camera.setProperty("LineSelector", "Line1")
            self.camera.setProperty("LineSource", "ExposureActive")

            # This line is connected to the other cameras.
            self.camera.setProperty("LineSelector", "Line2")
            self.camera.setProperty("LineMode", "Output")
            self.camera.setProperty("LineSource", "ExposureActive")

        # Configure 'slave' cameras to use triggering.
        #
        # We are following: http://www.ptgrey.com/KB/11052
        # "Configuring Synchronized Capture with Multiple Cameras"
        #
        # Also, we connected the master camera to the DAQ card
        # using it's OPTO-OUT connection.
        #
        else:
            self.camera.setProperty("TriggerMode", "On")
            self.camera.setProperty("TriggerSource", "Line3")
            self.camera.setProperty("TriggerOverlap", "ReadOut")
            self.camera.setProperty(
                "TriggerActivation",
                config.get("trigger_activation", "FallingEdge"))

        #
        # Dictionary of Point Grey specific camera parameters.
        #

        # All cameras can set these.
        self.pgrey_props = {
            "BlackLevel": True,
            "Gain": True,
            "Height": True,
            "OffsetX": True,
            "OffsetY": True,
            "Width": True
        }

        # Only master cameras can set "AcquisitionFrameRate".
        if self.is_master:
            self.pgrey_props["AcquisitionFrameRate"] = True

            #
            # FIXME: We're using a made up max_value for this parameter because it is
            #        the default parameter. If we use the real range then any
            #        parameters that are added later could have their frame rate
            #        changed in an unexpected way. Unfortunately this also means that
            #        if the user goes above the real maximum on this parameter then
            #        the software will crash.
            #
            self.parameters.add(
                params.ParameterRangeFloat(
                    description="Acquisition frame rate (FPS)",
                    name="AcquisitionFrameRate",
                    value=10.0,
                    max_value=500.0,
                    min_value=self.camera.getProperty(
                        "AcquisitionFrameRate").getMinimum()))

        # Slave cameras can set "ExposureTime".
        #
        # FIXME? If this is too large then the slave will be taking images
        #        at a different rate than master. Maybe this should be
        #        limited? Automatically set based on "master" frame rate?
        #
        else:
            self.pgrey_props["ExposureTime"] = True
            self.parameters.add(
                params.ParameterRangeFloat(description="Exposure time (us)",
                                           name="ExposureTime",
                                           value=99800.0,
                                           max_value=self.camera.getProperty(
                                               "ExposureTime").getMaximum(),
                                           min_value=self.camera.getProperty(
                                               "ExposureTime").getMinimum()))

        # Load properties as required by the spinnaker Python wrapper.
        for pname in self.pgrey_props:
            self.camera.getProperty(pname)

        max_intensity = 2**12
        self.parameters.setv("max_intensity", max_intensity)

        # Set chip size and HAL parameter ranges.
        x_chip = self.camera.getProperty("WidthMax").getValue()
        self.parameters.setv("x_chip", x_chip)
        for pname in ["x_end", "x_start"]:
            self.parameters.getp(pname).setMaximum(x_chip)

        y_chip = self.camera.getProperty("HeightMax").getValue()
        self.parameters.setv("y_chip", y_chip)
        for pname in ["y_end", "y_start"]:
            self.parameters.getp(pname).setMaximum(y_chip)

        #
        # Reset X, Y offsets. We do this here because otherwise the
        # initial ranges of these parameters will be incorrect and the
        # only way to fix them is using the parameters editor.
        #
        self.camera.setProperty("OffsetX", 0)
        self.camera.setProperty("OffsetY", 0)

        self.parameters.add(
            params.ParameterRangeFloat(
                description="Black level",
                name="BlackLevel",
                value=1.0,
                max_value=self.camera.getProperty("BlackLevel").getMaximum(),
                min_value=self.camera.getProperty("BlackLevel").getMinimum()))

        self.parameters.add(
            params.ParameterRangeFloat(
                description="Gain",
                name="Gain",
                value=10.0,
                max_value=self.camera.getProperty("Gain").getMaximum(),
                min_value=self.camera.getProperty("Gain").getMinimum()))

        self.parameters.add(
            params.ParameterRangeInt(description="AOI height",
                                     name="Height",
                                     value=y_chip,
                                     max_value=y_chip,
                                     min_value=4))

        self.parameters.add(
            params.ParameterRangeInt(description="AOI x offset",
                                     name="OffsetX",
                                     value=0,
                                     max_value=x_chip - 4,
                                     min_value=0))

        self.parameters.add(
            params.ParameterRangeInt(description="AOI y offset",
                                     name="OffsetY",
                                     value=0,
                                     max_value=y_chip - 4,
                                     min_value=0))

        self.parameters.add(
            params.ParameterRangeInt(description="AOI width",
                                     name="Width",
                                     value=x_chip,
                                     max_value=x_chip,
                                     min_value=4))

        # Disable editing of the HAL versions of these parameters.
        for param in [
                "exposure_time", "x_bin", "x_end", "x_start", "y_end",
                "y_start", "y_bin"
        ]:
            self.parameters.getp(param).setMutable(False)

        self.newParameters(self.parameters, initialization=True)
    def __init__(self, config=None, is_master=False, **kwds):
        kwds["config"] = config
        super().__init__(**kwds)

        self.fake_frame = 0
        self.fake_frame_size = [0, 0]
        self.sleep_time = 0

        #
        # The camera functionality. Note the connection to self.parameters
        # which should not be changed to point to some other parameters
        # object when the parameters change. This is enforced by the
        # getCameraConfiguration() method.
        #
        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)
        #
        # In general these should be handled by a thread as they may be slow.
        #
        self.camera_functionality.setEMCCDGain = self.setEMCCDGain
        self.camera_functionality.toggleShutter = self.toggleShutter

        #
        # Override defaults with camera specific values.
        #
        self.parameters.set(
            "exposure_time",
            params.ParameterRangeFloat(description="Exposure time (seconds)",
                                       name="exposure_time",
                                       value=0.02,
                                       min_value=0.01,
                                       max_value=10.0))
        self.parameters.setv("max_intensity", 512)

        chip_size = 512
        for pname in ["x_start", "x_end", "y_start", "y_end"]:
            self.parameters.getp(pname).setMaximum(chip_size)

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

        #
        # Emulation camera specific parameters.
        #
        self.parameters.add(
            params.ParameterRangeFloat(description="Camera rolling constant",
                                       name="roll",
                                       value=0.1,
                                       min_value=0.0,
                                       max_value=1.0))
        self.parameters.setv("roll", config.get("roll"))

        self.parameters.add(
            params.ParameterRangeInt(description="EMCCD gain",
                                     name="emccd_gain",
                                     value=10,
                                     min_value=2,
                                     max_value=50))

        self.parameters.add(
            params.ParameterSetFloat(description="Pre-amp gain",
                                     name="preampgain",
                                     value=1.0,
                                     allowed=[1.0, 2.0, 5.0]))

        self.parameters.add(
            params.ParameterRangeFloat(description="Target temperature",
                                       name="temperature",
                                       value=-20.0,
                                       min_value=-50.0,
                                       max_value=25.0))

        self.newParameters(self.parameters, initialization=True)
Example #12
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)
    def __init__(self, config=None, is_master=False, **kwds):
        """
        Create a Photometrics camera control object and initialize the camera.
        """
        kwds["config"] = config
        super().__init__(**kwds)
        self.is_master = is_master

        # Load the library and start the camera.
        #
        pvcam.loadPVCAMDLL(config.get("pvcam_sdk"))
        pvcam.initPVCAM()

        names = pvcam.getCameraNames()
        if not config.get("camera_name") in names:
            msg = "Camera " + config.get("camera_name") + " is not available. "
            msg += "Available cameras are " + ",".join(str(names)) + "."
            raise halExceptions.HardwareException(msg)

        self.camera = pvcam.PVCAMCamera(camera_name=config.get("camera_name"))

        # Create the camera functionality.
        #
        have_shutter = self.camera.hasParameter("param_shtr_status")
        have_temperature = self.camera.hasParameter("param_temp_setpoint")
        have_temperature = False

        self.camera_functionality = cameraFunctionality.CameraFunctionality(
            camera_name=self.camera_name,
            have_shutter=have_shutter,
            have_temperature=have_temperature,
            is_master=is_master,
            parameters=self.parameters)

        # Add Photometrics specific parameters. These all start with 'param_'.
        #
        self.parameters.add(
            params.ParameterRangeInt(
                description="Sensor readout speed",
                name="param_spdtab_index",
                value=self.camera.getParameterCurrent("param_spdtab_index"),
                min_value=0,
                max_value=self.camera.getParameterCount("param_spdtab_index") -
                1))

        # Dictionary of the Photometrics camera properties we'll support.
        #
        self.pvcam_props = {
            "exposure_time": True,
            "param_spdtab_index": True,
            "x_bin": True,
            "x_end": True,
            "x_start": True,
            "y_bin": True,
            "y_end": True,
            "y_start": True
        }

        # FIXME: Display needs to realize that the camera bit depth has
        #        changed. For now we're just setting to the maximum.
        #
        #bit_depth = self.camera.getParameterCurrent("param_bit_depth")
        self.parameters.setv("max_intensity", 2**16)

        # X/Y may be reversed here.
        #
        x_chip = self.camera.getParameterCurrent("param_par_size")
        y_chip = self.camera.getParameterCurrent("param_ser_size")

        # Adjust ranges of our size and binning parameters based on the chip size.
        #
        self.parameters.getp("x_end").setMaximum(x_chip)
        self.parameters.getp("x_start").setMaximum(x_chip)
        self.parameters.getp("y_end").setMaximum(y_chip)
        self.parameters.getp("y_start").setMaximum(y_chip)

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

        # FIXME: Need to actually query for possible binning values.
        #
        self.parameters.getp("x_bin").setMaximum(2)
        self.parameters.getp("y_bin").setMaximum(2)

        # Start with 100ms exposure time.
        self.parameters.getp("exposure_time").setOrder(2)
        self.parameters.setv("exposure_time", 0.1)

        self.newParameters(self.parameters, initialization=True)
Example #14
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 #15
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)