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

        # The camera configuration.
        """ lines 32 - 34 are modified"""
        self.camera_functionality = cameraFunctionality.CameraFunctionality(
            camera_name=self.camera_name,
            is_master=is_master,
            parameters=self.parameters)

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

        # 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
        }

        max_intensity = 2**self.camera.getParameterCurrent("param_bit_depth")
        print(max_intensity)
        self.parameters.setv("max_intensity", max_intensity)

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

        x_chip = self.camera.getParameterCurrent("param_par_size")
        y_chip = self.camera.getParameterCurrent("param_ser_size")
        self.parameters.setv("x_chip", x_chip)
        self.parameters.setv("y_chip", y_chip)

        self.parameters.getp("x_bin").setMaximum(2)
        self.parameters.getp("y_bin").setMaximum(2)

        self.newParameters(self.parameters, initialization=True)
Example #2
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 #3
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 #4
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)
    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 #8
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)