コード例 #1
0
ファイル: test_plugins.py プロジェクト: yodamaster/ufo-core
def test_uca_direct():
    try:
        from gi.repository import Ufo, Uca

        if have_camera_plugin():
            from ufo import Camera

            uca_pm = Uca.PluginManager()
            mock = uca_pm.get_camerav('mock', [])
            camera = Camera(camera=mock, count=3)

            result = list(camera())
            assert (len(result) == 3)
    except ImportError:
        pass
コード例 #2
0
ファイル: uca.py プロジェクト: MariaMatveeva/concert
    def __init__(self, name):
        from gi.repository import GObject, Uca

        self._manager = Uca.PluginManager()
        self._data = None
        self._array = None

        try:
            self.camera = self._manager.get_camerav(name, [])
        except:
            raise ValueError("`{0}' is not a valid camera".format(name))

        units = {
            Uca.Unit.METER: q.m,
            Uca.Unit.SECOND: q.s,
            Uca.Unit.DEGREE_CELSIUS: q.Celsius,
            Uca.Unit.COUNT: q.count
        }

        parameters = []

        for prop in self.camera.props:
            getter, setter, unit = None, None, None

            uca_unit = self.camera.get_unit(prop.name)

            if uca_unit in units:
                unit = units[uca_unit]

            if prop.flags & GObject.ParamFlags.READABLE:
                getter = _new_getter_wrapper(self.camera, prop.name, unit)

            if prop.flags & GObject.ParamFlags.WRITABLE:
                setter = _new_setter_wrapper(self.camera, prop.name, unit)

            parameter = Parameter(prop.name, getter, setter, unit)
            parameters.append(parameter)

        super(Camera, self).__init__(parameters)
コード例 #3
0
ファイル: test.py プロジェクト: ufo-kit/uca-phantom
def command(fmt, log, ip, interface, xnetwork):
    # First we set up the logging for the command
    logging.basicConfig(
        format=LOG_FORMAT,
        level=LOG_CONFIG[log]
    )
    logger = logging.getLogger('test.py')

    # Exporting the variables
    logger.debug("Attempting to connect to phantom at IP %s", ip)
    os.environ['PH_NETWORK_ADDRESS'] = ip
    if xnetwork:
        os.environ['PH_NETWORK_INTERFACE'] = interface

    # Creating the plugin manager and the camera object
    plugin_manager = Uca.PluginManager()
    logger.debug("Created the plugin manager")
    camera = plugin_manager.get_camerav(CAMERA_IDENTIFIER, [])
    logger.debug("Created the camera object")

    camera.props.image_format = "image_format_{}".format(fmt.lower())

    # Starting the readout
    camera.start_recording()
    logger.info("Readout threads started!")

    # Grabbing a frame for testing and then displaying it
    a, buf = create_array_from(camera)
    camera.grab(buf)
    logger.info("Frame acquired")

    plt.imshow(a, cmap="gray")
    plt.show()
    logger.debug("Plot of the image has been closed by the user")

    # Cleaning up - Stopping the camera connection
    logger.debug("Stopping tze camera connection")
    camera.stop_recording()
コード例 #4
0
ファイル: uca.py プロジェクト: ufo-kit/concert
    def __init__(self, name, params=None):
        """
        Create a new libuca camera.

        The *name* is passed to the uca plugin manager.

        :raises CameraError: In case camera *name* does not exist.
        """

        super(Camera, self).__init__()

        import gi
        gi.require_version('Uca', '2.0')

        from gi.repository import GObject, GLib, Uca

        self._manager = Uca.PluginManager()

        params = params if params else {}

        try:
            self.uca = self._manager.get_camerah(name, params)
        except GLib.GError as ge:
            raise base.CameraError(str(ge))
        except Exception:
            raise base.CameraError("`{0}' is not a valid camera".format(name))

        units = {
            Uca.Unit.METER: q.m,
            Uca.Unit.SECOND: q.s,
            Uca.Unit.DEGREE_CELSIUS: q.celsius,
            Uca.Unit.COUNT: q.dimensionless,
            Uca.Unit.PIXEL: q.pixel,
        }

        parameters = {}

        for prop in self.uca.props:
            if prop.name in ('trigger-source', 'trigger-type',
                             'frames-per-second'):
                continue

            getter, setter, unit = None, None, None

            uca_unit = self.uca.get_unit(prop.name)

            if uca_unit in units:
                unit = units[uca_unit]

            if prop.flags & GObject.ParamFlags.READABLE:
                getter = _new_getter_wrapper(prop.name, unit)

            if prop.flags & GObject.ParamFlags.WRITABLE:
                setter = _new_setter_wrapper(prop.name, unit)

            name = prop.name.replace('-', '_')

            if uca_unit in units:
                parameters[name] = Quantity(unit,
                                            fget=getter,
                                            fset=setter,
                                            help=prop.blurb)
            else:
                parameters[name] = Parameter(fget=getter,
                                             fset=setter,
                                             help=prop.blurb)

        if parameters:
            self.install_parameters(parameters)

        class _Dummy(object):
            pass

        setattr(self.uca, 'enum_values', _Dummy())

        def get_enum_bunch(enum):
            enum_map = {}

            for key, value in list(enum.__enum_values__.items()):
                name = value.value_nick.upper().replace('-', '_')
                enum_map[name] = key

            return Bunch(enum_map)

        for prop in self.uca.props:
            if hasattr(prop, 'enum_class'):
                setattr(self.uca.enum_values, prop.name.replace('-', '_'),
                        get_enum_bunch(prop.default_value))

        self._uca_get_frame_rate = _new_getter_wrapper('frames-per-second')
        self._uca_set_frame_rate = _new_setter_wrapper('frames-per-second')

        # Invert the uca trigger source dict in order to return concert values
        trigger_dict = self.uca.enum_values.trigger_source.__dict__
        self._uca_to_concert_trigger = {
            v: k
            for k, v in list(trigger_dict.items())
        }
        self._uca_get_trigger = _new_getter_wrapper('trigger-source')
        self._uca_set_trigger = _new_setter_wrapper('trigger-source')

        self._record_shape = None
        self._record_dtype = None
コード例 #5
0
ファイル: update-props.py プロジェクト: ufodaq/uca
                           optionals=optionals)


def output(camera, name):
    template = """
{name}
{name_underline}
{props}"""

    name_underline = '=' * len(name)

    stream = open('{}.rst'.format(name), 'w')
    props = '\n'.join((get_prop_string(prop) for prop in camera.props))
    stream.write(
        template.format(name=name, name_underline=name_underline, props=props))


if __name__ == '__main__':
    pm = Uca.PluginManager()

    if len(sys.argv) < 2:
        print("Usage: update-props.py NAME")
        sys.exit(0)

    name = sys.argv[1]

    try:
        output(pm.get_camerav(name, []), name)
    except GLib.GError as e:
        print("Could not query {}: {}".format(name, e.message))