Esempio n. 1
0
class Complex(Variable):
    """A variable wrapper for a complex variable.
       """

    def __init__(self, default_value=(0.+0.j), iotype=None, desc=None,
                 **metadata):

        # Put iotype in the metadata dictionary
        if iotype is not None:
            metadata['iotype'] = iotype

        # Put desc in the metadata dictionary
        if desc is not None:
            metadata['desc'] = desc

        self._validator = Enthought_Complex(default_value=default_value,
                                            **metadata)

        super(Complex, self).__init__(default_value=default_value, **metadata)

    def validate(self, obj, name, value):
        """ Use the Enthought trait's validate.
        """
        return self._validator.validate(obj, name, value)

    def create_editor(self):
        """ User the one in the Enthought trait.
        """
        return self._validator.create_editor()
Esempio n. 2
0
class Complex(Variable):
    """A variable wrapper for a complex variable.
       """
    def __init__(self,
                 default_value=(0. + 0.j),
                 iotype=None,
                 desc=None,
                 **metadata):

        # Put iotype in the metadata dictionary
        if iotype is not None:
            metadata['iotype'] = iotype

        # Put desc in the metadata dictionary
        if desc is not None:
            metadata['desc'] = desc

        self._validator = Enthought_Complex(default_value=default_value,
                                            **metadata)

        super(Complex, self).__init__(default_value=default_value, **metadata)

    def validate(self, obj, name, value):
        """ Use the Enthought trait's validate.
        """
        return self._validator.validate(obj, name, value)

    def create_editor(self):
        """ User the one in the Enthought trait.
        """
        return self._validator.create_editor()
Esempio n. 3
0
class Optic(Traceable):
    abstract=True
    n_inside = Complex(1.0+0.0j) #refractive
    n_outside = Complex(1.0+0.0j)
    
    all_rays = Bool(False, desc="trace all reflected rays")
    
    vtkproperty = tvtk.Property(opacity = 0.4,
                             color = (0.8,0.8,1.0))
                             
    def _material_default(self):
        m = cmaterials.FullDielectricMaterial(n_inside = self.n_inside,
                                    n_outside = self.n_outside)
        return m
    
    def calc_refractive_index(self, wavelengths):
        """
        Evaluates an array of (complex) refractive indices.
        @param wavelengths: a shape=(N,1) array of wavelengths
        @returns: a 2-tuple representing the inside and outside
        refractive indices respectively. The items in the tuple can be
        either 1) an arrays with the same shape as wavelengths and with
                    dtype=numpy.complex128
            or 2) a complex scalar
        """
        return self.n_inside, self.n_outside
    
    @on_trait_change("n_inside, n_outside")
    def n_changed(self):
        self.material.n_inside = self.n_inside
        self.material.n_outside = self.n_outside
        self.update = True
Esempio n. 4
0
class TestTraits(HasTraits):
    b = Bool(False)
    i = Int(7)
    l = Int(12345678901234567890)
    f = Float(math.pi)
    c = Complex(complex(1.01234, 2.3))
    n = Any
    s = Str('String')
    u = Unicode(u'Unicode')
    inst = Instance(A)
    tuple = Tuple
    list = List
    pure_list = List(list(range(5)))
    dict = Dict
    numeric = Array(value=numpy.ones((2, 2, 2), 'f'))
    ref = Array
    if TVTK_AVAILABLE:
        _tvtk = Instance(tvtk.Property, ())

    def __init__(self):
        self.inst = A()
        self.tuple = (1, 2, 'a', A())
        self.list = [1, 1.1, 'a', 1j, self.inst]
        self.dict = {'a': 1, 'b': 2, 'ref': self.inst}
        self.ref = self.numeric
class TestTraits(HasTraits):
    b = Bool(False)
    i = Int(7)
    longi = Int(12345678901234567890)
    f = Float(math.pi)
    c = Complex(complex(1.01234, 2.3))
    n = Any
    s = Str("String")
    u = Str("Unicode")
    inst = Instance(A)
    tuple = Tuple
    list = List
    pure_list = List(list(range(5)))
    dict = Dict
    numeric = Array(value=numpy.ones((2, 2, 2), "f"))
    ref = Array
    if TVTK_AVAILABLE:
        _tvtk = Instance(tvtk.Property, ())

    def __init__(self):
        self.inst = A()
        self.tuple = (1, 2, "a", A())
        self.list = [1, 1.1, "a", 1j, self.inst]
        self.dict = {"a": 1, "b": 2, "ref": self.inst}
        self.ref = self.numeric
Esempio n. 6
0
    def __init__(self, default_value=(0.+0.j), iotype=None, desc=None,
                 **metadata):

        # Put iotype in the metadata dictionary
        if iotype is not None:
            metadata['iotype'] = iotype

        # Put desc in the metadata dictionary
        if desc is not None:
            metadata['desc'] = desc

        self._validator = Enthought_Complex(default_value=default_value,
                                            **metadata)

        super(Complex, self).__init__(default_value=default_value, **metadata)
Esempio n. 7
0
    def __init__(self,
                 default_value=(0. + 0.j),
                 iotype=None,
                 desc=None,
                 **metadata):

        # Put iotype in the metadata dictionary
        if iotype is not None:
            metadata['iotype'] = iotype

        # Put desc in the metadata dictionary
        if desc is not None:
            metadata['desc'] = desc

        self._validator = Enthought_Complex(default_value=default_value,
                                            **metadata)

        super(Complex, self).__init__(default_value=default_value, **metadata)
Esempio n. 8
0
class Test2(HasTraits):
    var = Complex(default_value="sdf")  # E: arg-type
Esempio n. 9
0
class Test(HasTraits):
    var = Complex()