コード例 #1
0
 def __init__(self, *args, **kwargs):
     model.HwComponent.__init__(self, *args, **kwargs)
     self.data = FakeDataFlow()
     # TODO automatically register the property when serializing the Component
     self.prop = model.IntVA(42)
     self.cont = model.FloatContinuous(2.0, [-1, 3.4])
     self.enum = model.StringEnumerated("a", {"a", "c", "bfds"})
コード例 #2
0
    def test_enumerated(self):
        prop = model.StringEnumerated("a", set(["a", "c", "bfds"]))
        self.assertEqual(prop.value, "a")
        self.assertEqual(prop.choices, set(["a", "c", "bfds"]))

        self.called = 0
        prop.subscribe(self.callback_test_notify)
        # now count
        prop.value = "c"  # +1
        assert (prop.value == "c")

        try:
            prop.value = "wfds"
            self.fail("Assigning out of bound should not be allowed.")
        except IndexError:
            pass  # as it should be

        prop.choices = set(["a", "c", "b", 5])
        assert (prop.value == "c")
        try:
            prop.choices = set(["a", "b"])
            self.fail(
                "Assigning choices not containing current value should not be allowed."
            )
        except IndexError:
            pass  # as it should be

        try:
            prop.value = 5
            self.fail("Assigning an int to a string should not be allowed.")
        except TypeError:
            pass  # as it should be

        try:
            prop.choices = 5
            self.fail("Choices should be allowed only if it's a set.")
        except TypeError:
            pass  # as it should be

        prop.unsubscribe(self.callback_test_notify)

        self.assertTrue(self.called == 1)

        # It's also allowed to use dict as choices
        prop = model.VAEnumerated((1, 2), {(1, 2): "aaa", (3, 5): "doo"})
        for v in prop.choices:
            prop.value = v  # they all should work
コード例 #3
0
    def __init__(self, name, daemon):
        model.Component.__init__(self, name=name, daemon=daemon)
        self.executor = futures.ThreadPoolExecutor(max_workers=1)
        self.number_futures = 0
        self.startAcquire = model.Event() # triggers when the acquisition of .data starts
        self.data = FakeDataFlow(sae=self.startAcquire)
        self.datas = SynchronizableDataFlow()

        self.data_count = 0
        self._df = None

        # TODO automatically register the property when serializing the Component
        self.prop = model.IntVA(42)
        self.cont = model.FloatContinuous(2.0, [-1, 3.4], unit="C")
        self.enum = model.StringEnumerated("a", {"a", "c", "bfds"})
        self.cut = model.IntVA(0, setter=self._setCut)
        self.listval = model.ListVA([2, 65])
コード例 #4
0
ファイル: vattributes_test.py プロジェクト: effting/odemis
    def test_enumerated(self):
        prop = model.StringEnumerated("a", {"a", "c", "bfds"})
        self.assertEqual(prop.value, "a")
        self.assertEqual(prop.choices, {"a", "c", "bfds"})

        self.called = 0
        prop.subscribe(self.callback_test_notify)
        # now count
        prop.value = "c"  # +1
        assert (prop.value == "c")

        try:
            prop.value = "wfds"
            self.fail("Assigning out of bound should not be allowed.")
        except IndexError:
            pass  # as it should be

        prop.choices = {"a", "c", "b", 5}
        assert (prop.value == "c")
        try:
            prop.choices = {"a", "b"}
            self.fail(
                "Assigning choices not containing current value should not be allowed."
            )
        except IndexError:
            pass  # as it should be

        try:
            prop.value = 5
            self.fail("Assigning an int to a string should not be allowed.")
        except TypeError:
            pass  # as it should be

        try:
            prop.choices = 5
            self.fail("Choices should be allowed only if it's a set.")
        except TypeError:
            pass  # as it should be

        prop.unsubscribe(self.callback_test_notify)

        self.assertTrue(self.called == 1)

        # It's also allowed to use dict as choices
        prop = model.VAEnumerated((1, 2), {(1, 2): "aaa", (3, 5): "doo"})
        for v in prop.choices:
            prop.value = v  # they all should work

        # It's also allowed to use tuples as choices, which contain no numbers
        prop = model.VAEnumerated((1, 1), {(1, 1), (4, 4), (5, "aaa")})
        prop.value = prop.clip((3, 3))
        # should find the closest value
        self.assertEqual(prop.value, (4, 4))
        for v in prop.choices:
            prop.value = v  # they all should work

        prop = model.VAEnumerated((1, "aaa"), {(1, "aaa"), (3, "bbb"),
                                               (4, "ccc")})
        prev_value = prop.value
        prop.value = prop.clip((3, 3))
        # should not find a closest value, but return old value
        self.assertEqual(prop.value, prev_value)
        for v in prop.choices:
            prop.value = v  # they all should work

        prop = model.VAEnumerated((1, "aaa"), {(1, "aaa"), (3, "bbb"),
                                               (4, "ccc")})
        prev_value = prop.value
        prop.value = prop.clip((5, "ddd"))
        # should not find a closest value as not all values in tuple are numbers, but return old value
        self.assertEqual(prop.value, prev_value)
        for v in prop.choices:
            prop.value = v  # they all should work
コード例 #5
0
    def __init__(self,
                 name,
                 role,
                 mag,
                 mag_choices=None,
                 na=0.95,
                 ri=1,
                 pole_pos=None,
                 x_max=None,
                 hole_diam=None,
                 focus_dist=None,
                 parabola_f=None,
                 rotation=None,
                 configurations=None,
                 **kwargs):
        """
        name (string): should be the name of the product (for metadata)
        mag (float > 0): magnification ratio
        mag_choices (None, list of floats > 0): list of allowed magnification ratio.
          If None, the magnification will be allowed for any value between 1e-3 to 1e6.
        na (float > 0): numerical aperture
        ri (0.01 < float < 100): refractive index
        pole_pos (2 floats > 0): position of the pole on the CCD (in px, without
          binning, with the top-left pixel as origin).
          Used for angular resolved imaging on SPARC (only). cf MD_AR_POLE
        x_max (float): the distance between the parabola origin and the cutoff
          position (in meters). Used for angular resolved imaging on SPARC (only).
          cf MD_AR_XMAX
        hole_diam (float): diameter of the hole in the mirror (in meters). Used
          for angular resolved imaging on SPARC (only).
          cf MD_AR_HOLE_DIAMETER
        focus_dist (float): the vertical mirror cutoff, iow the min distance
          between the mirror and the sample (in meters). Used for angular
          resolved imaging on SPARC (only).
          cf MD_AR_FOCUS_DISTANCE
        parabola_f (float): parabola_parameter=1/4f. Used for angular
          resolved imaging on SPARC (only).
          cf MD_AR_PARABOLA_F
        rotation (0<float<2*pi): rotation between the Y axis of the SEM
          referential and the optical path axis. Used on the SPARC to report
          the rotation between the AR image and the SEM image.
        configurations (dict str -> (dict str -> value)): {configuration name -> {attribute name -> value}}
          All the configurations supported and their settings. A "configuration" is a set of attributes with
          predefined values. When this argument is specified, a .configuration attribute will be available,
          with each configuration name, and changing it will automatically set all the associated attributes
          to their predefined value.
        """
        assert (mag > 0)
        model.HwComponent.__init__(self, name, role, **kwargs)

        self._swVersion = "N/A (Odemis %s)" % odemis.__version__
        self._hwVersion = name

        # allow the user to modify the value, if the lens is manually changed
        if mag_choices is None:
            self.magnification = model.FloatContinuous(mag,
                                                       range=(1e-3, 1e6),
                                                       unit="")
        else:
            mag_choices = frozenset(mag_choices)
            if mag not in mag_choices:
                raise ValueError("mag (%s) is not within the mag_choices %s" %
                                 (mag, mag_choices))
            self.magnification = model.FloatEnumerated(mag,
                                                       choices=mag_choices,
                                                       unit="")

        self.numericalAperture = model.FloatContinuous(na,
                                                       range=(1e-6, 1e3),
                                                       unit="")
        self.refractiveIndex = model.FloatContinuous(ri,
                                                     range=(0.01, 10),
                                                     unit="")

        if pole_pos is not None:
            if (not isinstance(pole_pos, collections.Iterable)
                    or len(pole_pos) != 2
                    or any(not 0 < v < 1e6 for v in pole_pos)):
                raise ValueError("pole_pos must be 2 positive values, got %s" %
                                 pole_pos)
            self.polePosition = model.ResolutionVA(tuple(pole_pos),
                                                   rng=((0, 0), (1e6, 1e6)),
                                                   unit="px")
        if x_max is not None:
            self.xMax = model.FloatVA(x_max, unit="m")
        if hole_diam is not None:
            self.holeDiameter = model.FloatVA(hole_diam, unit="m")
        if focus_dist is not None:
            self.focusDistance = model.FloatVA(focus_dist, unit="m")
        if parabola_f is not None:
            self.parabolaF = model.FloatVA(parabola_f, unit="m")
        if rotation is not None:
            self.rotation = model.FloatContinuous(rotation, (0, 2 * math.pi),
                                                  unit="rad")
        if configurations is not None:
            self._configurations = configurations

            # Find the configuration which is closest to the current settings
            def _compare_config(cn):
                settings = configurations[cn]
                score = 0
                for arg, value in settings.items():
                    try:
                        vaname = CONFIG_2_VA[arg]
                        va = getattr(self, vaname)
                    except (KeyError, AttributeError):
                        raise ValueError(
                            "Attribute name predefined in the configuration required"
                        )
                    if value == va.value:
                        score += 1
                return score

            current_conf = max(configurations, key=_compare_config)
            self.configuration = model.StringEnumerated(
                current_conf,
                choices=set(configurations.keys()),
                setter=self._setConfiguration)