Beispiel #1
0
    def __init__(self,
                 below=None,
                 above=None,
                 thickness=0,
                 z=[],
                 rho=[],
                 irho=[],
                 name="Freeform"):
        self.name = name
        self.below, self.above = below, above
        self.thickness = Par.default(thickness,
                                     name=name + " thickness",
                                     limits=(0, inf))
        self.interface = Par.default(0,
                                     name=name + " interface",
                                     limits=(0, inf))
        self.interface.fittable = False

        def parvec(vector, name, limits):
            return [
                Par.default(p, name=name + "[%d]" % i, limits=limits)
                for i, p in enumerate(vector)
            ]
        self.rho, self.irho, self.z \
            = [parvec(v,name+" "+part,limits)
               for v,part,limits in zip((rho, irho, z),
                                        ('rho', 'irho', 'z'),
                                        ((-inf,inf),(0,inf),(0,1))
                                        )]
        if len(self.z) != len(self.rho):
            raise ValueError("must have one z for each rho value")
        if len(self.irho) > 0 and len(self.z) != len(self.irho):
            raise ValueError("must have one z for each irho value")
Beispiel #2
0
    def __init__(self, thickness=0, interface=0,
                 below=None, above=None,
                 dz=None, dp=None, name="Interface"):
        self.name = name
        self.below, self.above = below,above
        self.thickness = Par.default(thickness, limits=(0,inf),
                                     name=name+" thickness")
        self.interface = Par.default(interface, limits=(0,inf),
                                     name=name+" interface")


        # Choose reasonable defaults if not given
        if dp is None and dz is None:
            dp = [1]*5
        if dp is None:
            dp = [1]*len(dz)
        if dz is None:
            dz = [1]*len(dp)
        if len(dz) != len(dp):
            raise ValueError("Need one dz for every dp")

        #if len(z) != len(vf)+2:
        #    raise ValueError("Only need vf for interior z, so len(z)=len(vf)+2")
        self.dz = [Par.default(p,name=name+" dz[%d]"%i,limits=(0,inf))
                  for i,p in enumerate(dz)]
        self.dp = [Par.default(p,name=name+" dp[%d]"%i,limits=(0,inf))
                   for i,p in enumerate(dp)]
        self.inflections = ParFunction(inflections, dx=self.dz, dy=self.dp,
                                       name=name+" inflections")
Beispiel #3
0
    def __init__(self,
                 weight=[],
                 rhoM=[],
                 thetaM=[270],
                 interfaceM=[0],
                 name="LAYER",
                 **kw):
        if (len(thetaM) != 1 and len(thetaM) != len(weight) and len(rhoM) != 1
                and len(rhoM) != len(weight) and len(interfaceM) != 1
                and len(interfaceM) != len(weight) - 1):
            raise ValueError(
                "Must have one rhoM, thetaM and intefaceM for each layer")
        if interfaceM != [0]:
            raise NotImplementedError("Doesn't support magnetic roughness")

        BaseMagnetism.__init__(self, stack=stack, name=name, **kw)
        self.weight = [
            Parameter.default(v, name=name + " weight[%d]" % i)
            for i, v in enumerate(weight)
        ]
        self.rhoM = [
            Parameter.default(v, name=name + " rhoM[%d]" % i)
            for i, v in enumerate(rhoM)
        ]
        self.thetaM = [
            Parameter.default(v, name=name + " thetaM[%d]" % i)
            for i, v in enumerate(thetaM)
        ]
        self.interfaceM = [
            Parameter.default(v, name=name + " interfaceM[%d]" % i)
            for i, v in enumerate(interfaceM)
        ]
Beispiel #4
0
    def __init__(self,
                 thickness=0,
                 interface=0,
                 profile=None,
                 tol=1e-3,
                 magnetism=None,
                 name=None,
                 **kw):
        if not name:
            name = profile.__name__
        if interface != 0:
            raise NotImplementedError("interface not yet supported")
        if profile is None:
            raise TypeError("Need profile")
        self.name = name
        self.thickness = Parameter.default(thickness, name=name + " thickness")
        self.interface = Parameter.default(interface, name=name + " interface")
        self.profile = profile
        self.tol = tol
        self.magnetism = magnetism

        # TODO: maybe make these lazy (and for magnetism below as well)
        rho_start = _LayerLimit(self, isend=False, isrho=True)
        irho_start = _LayerLimit(self, isend=False, isrho=False)
        rho_end = _LayerLimit(self, isend=True, isrho=True)
        irho_end = _LayerLimit(self, isend=True, isrho=False)
        self.start = SLD(name + " start", rho=rho_start, irho=irho_start)
        self.end = SLD(name + " end", rho=rho_end, irho=irho_end)

        self._parameters = _set_vars(self, name, profile, kw, self.RESERVED)
Beispiel #5
0
 def __init__(self,
              extent=1,
              dead_below=0,
              dead_above=0,
              interface_below=None,
              interface_above=None,
              name="LAYER"):
     self.dead_below = Parameter.default(dead_below,
                                         limits=(0, inf),
                                         name=name + " deadM below")
     self.dead_above = Parameter.default(dead_above,
                                         limits=(0, inf),
                                         name=name + " deadM above")
     if interface_below is not None:
         interface_below = Parameter.default(interface_below,
                                             limits=(0, inf),
                                             name=name +
                                             " interfaceM below")
     if interface_above is not None:
         interface_above = Parameter.default(interface_above,
                                             limits=(0, inf),
                                             name=name +
                                             "  interfaceM above")
     self.interface_below = interface_below
     self.interface_above = interface_above
     self.name = name
     self.extent = extent
Beispiel #6
0
    def __init__(self,
                 interface=0,
                 below=None,
                 above=None,
                 dz=None,
                 dp=None,
                 name="Interface"):
        self.name = name
        self.below, self.above = below, above
        self.interface = Par.default(interface,
                                     limits=(0, inf),
                                     name=name + " interface")

        # Choose reasonable defaults if not given
        if dp is None and dz is None:
            dp = [1] * 5
        if dp is None:
            dp = [1] * len(dz)
        if dz is None:
            dz = [10. / len(dp)] * len(dp)
        if len(dz) != len(dp):
            raise ValueError("Need one dz for every dp")
        #if len(z) != len(vf)+2:
        #    raise ValueError("Only need vf for interior z, so len(z)=len(vf)+2")
        self.dz = [
            Par.default(p, name=name + " dz[%d]" % i, limits=(0, inf))
            for i, p in enumerate(dz)
        ]
        self.dp = [
            Par.default(p, name=name + " dp[%d]" % i, limits=(0, inf))
            for i, p in enumerate(dp)
        ]
Beispiel #7
0
 def __init__(self,
              thickness=0,
              interface=0,
              below=None,
              above=None,
              z=None,
              vf=None,
              name="Interface"):
     self.name = name
     self.below, self.above = below, above
     self.thickness = Par.default(thickness,
                                  limits=(0, inf),
                                  name=name + " thickness")
     self.interface = Par.default(interface,
                                  limits=(0, inf),
                                  name=name + " interface")
     if len(z) != len(vf):
         raise ValueError("Need one vf for every z")
     #if len(z) != len(vf)+2:
     #    raise ValueError("Only need vf for interior z, so len(z)=len(vf)+2")
     self.z = [
         Par.default(p, name=name + " z[%d]" % i, limits=(0, 1))
         for i, p in enumerate(z)
     ]
     self.vf = [
         Par.default(p, name=name + " vf[%d]" % i, limits=(0, 1))
         for i, p in enumerate(vf)
     ]
Beispiel #8
0
 def __init__(self,
              thickness=0,
              left=None,
              right=None,
              rho=(),
              irho=(),
              rhoz=(),
              irhoz=(),
              name="Freeform"):
     self.name = name
     self.left, self.right = left, right
     self.thickness = Par.default(thickness,
                                  limits=(0, inf),
                                  name=name + " thickness")
     self.rho, self.irho, self.rhoz, self.irhoz \
         = [[Par.default(p, name=name+" [%d] %s"%(i, part), limits=limits)
             for i, p in enumerate(v)]
            for v, part, limits
            in zip((rho, irho, rhoz, irhoz),
                   ('rho', 'irho', 'rhoz', 'irhoz'),
                   ((-inf, inf), (-inf, inf), (0, 1), (0, 1)))
           ]
     if len(self.rhoz) > 0 and len(self.rhoz) != len(self.rho):
         raise ValueError("must have one z value for each rho")
     if len(self.irhoz) > 0 and len(self.irhoz) != len(self.irho):
         raise ValueError("must have one z value for each irho")
Beispiel #9
0
 def __init__(self, center=0, width=0, sigma=1, name="gauss"):
     self.center = Par.default(center, limits=(-inf,inf),
                             name=name + " center")
     self.width = Par.default(width, limits=(0,inf),
                            name=name + " width")
     self.stretch = Par.default(sigma, limits=(0,inf),
                              name=name + " sigma")
Beispiel #10
0
    def __init__(self, thickness=0, interface=0, name="VolumeProfile",
                 material=None, solvent=None, profile=None, **kw):
        if interface != 0: raise NotImplementedError("interface not yet supported")
        if profile is None or material is None or solvent is None:
            raise TypeError("Need polymer, solvent and profile")
        self.name = name
        self.thickness = Parameter.default(thickness, name="solvent thickness")
        self.interface = Parameter.default(interface, name="solvent interface")
        self.profile = profile
        self.solvent = solvent
        self.material = material

        # Query profile function for the list of arguments
        vars = inspect.getargspec(profile)[0]
        #print "vars",vars
        if inspect.ismethod(profile): vars = vars[1:]  # Chop self
        vars = vars[1:]  # Chop z
        #print vars
        unused = [k for k in kw.keys() if k not in vars]
        if len(unused) > 0:
            raise TypeError("Profile got unexpected keyword argument '%s'"%unused[0])
        dups = [k for k in vars
                if k in ('thickness','interface','polymer','solvent','profile')]
        if len(dups) > 0:
            raise TypeError("Profile has conflicting argument '%s'"%dups[0])
        for k in vars: kw.setdefault(k,0)
        for k,v in kw.items():
            setattr(self,k,Parameter.default(v,name=k))

        self._parameters = vars
Beispiel #11
0
    def __init__(self,
                 stack,
                 weight=(),
                 rhoM=(),
                 thetaM=(DEFAULT_THETA_M, ),
                 interfaceM=(0),
                 name="mag. stack",
                 **kw):
        if (len(thetaM) != 1 and len(thetaM) != len(weight) and len(rhoM) != 1
                and len(rhoM) != len(weight) and len(interfaceM) != 1
                and len(interfaceM) != len(weight) - 1):
            raise ValueError(
                "Must have one rhoM, thetaM and intefaceM for each layer")
        if interfaceM != [0]:
            raise NotImplementedError("Doesn't support magnetic roughness")

        MagneticLayer.__init__(self, stack=stack, name=name, **kw)
        self.weight = [
            Parameter.default(v, name=name + " weight[%d]" % i)
            for i, v in enumerate(weight)
        ]
        self.rhoM = [
            Parameter.default(v, name=name + " rhoM[%d]" % i)
            for i, v in enumerate(rhoM)
        ]
        self.thetaM = [
            Parameter.default(v, name=name + " angle[%d]" % i)
            for i, v in enumerate(thetaM)
        ]
        self.interfaceM = [
            Parameter.default(v, name=name + " interface[%d]" % i)
            for i, v in enumerate(interfaceM)
        ]
Beispiel #12
0
    def __init__(self, thickness=0, interface=0, name="VolumeProfile",
                 material=None, solvent=None, profile=None, **kw):
        if interface != 0:
            raise NotImplementedError("interface not yet supported")
        if profile is None or material is None or solvent is None:
            raise TypeError("Need polymer, solvent and profile")
        self.name = name
        self.thickness = Parameter.default(thickness, name="solvent thickness")
        self.interface = Parameter.default(interface, name="solvent interface")
        self.profile = profile
        self.solvent = solvent
        self.material = material

        # Query profile function for the list of arguments
        vars = inspect.getargspec(profile)[0]
        #print("vars", vars)
        if inspect.ismethod(profile):
            vars = vars[1:]  # Chop self
        vars = vars[1:]  # Chop z
        #print(vars)
        unused = [k for k in kw.keys() if k not in vars]
        if len(unused) > 0:
            raise TypeError("Profile got unexpected keyword argument '%s'"%unused[0])
        dups = [k for k in vars
                if k in ('thickness', 'interface', 'polymer', 'solvent', 'profile')]
        if len(dups) > 0:
            raise TypeError("Profile has conflicting argument '%s'"%dups[0])
        for k in vars:
            kw.setdefault(k, 0)
        for k, v in kw.items():
            setattr(self, k, Parameter.default(v, name=k))

        self._parameters = vars
Beispiel #13
0
 def __init__(self, stack, rhoM=(0, 0), thetaM=(270, 270),
              name="twist", **kw):
     MagneticLayer.__init__(self, stack=stack, name=name, **kw)
     self.rhoM = [Parameter.default(v, name=name+" rhoM[%d]"%i)
                  for i, v in enumerate(rhoM)]
     self.thetaM = [Parameter.default(v, name=name+" angle[%d]"%i)
                    for i, v in enumerate(thetaM)]
Beispiel #14
0
    def __init__(self,
                 thickness=0,
                 interface=0,
                 name="EndTetheredPolymer",
                 polymer=None,
                 solvent=None,
                 chi=0,
                 chi_s=0,
                 h_dry=None,
                 l_lat=1,
                 mn=None,
                 m_lat=1,
                 pdi=1,
                 phi_b=0):
        if interface != 0:
            raise NotImplementedError("interface not yet supported")
        if polymer is None or solvent is None or h_dry is None or mn is None:
            raise TypeError("Need polymer, solvent and profile")

        self.thickness = Parameter.default(thickness, name="SCF thickness")
        self.interface = Parameter.default(interface, name="SCF interface")
        self.chi = Parameter.default(chi, name="Chi")
        self.chi_s = Parameter.default(chi_s, name="Surface chi")
        self.h_dry = Parameter.default(h_dry, name="Dry thickness")
        self.l_lat = Parameter.default(l_lat, name="Lattice layer length")
        self.mn = Parameter.default(mn, name="Num. avg. MW")
        self.m_lat = Parameter.default(m_lat, name="Lattice segegment mass")
        self.pdi = Parameter.default(pdi, name="Dispersity")
        self.phi_b = Parameter.default(phi_b, name="Free polymer conc.")
        self.solvent = solvent
        self.polymer = polymer
        self.name = name
Beispiel #15
0
 def __init__(self, center=0, width=0, sigma=1, name="gauss"):
     self.center = Par.default(center, limits=(-inf,inf),
                             name=name + " center")
     self.width = Par.default(width, limits=(0,inf),
                            name=name + " width")
     self.stretch = Par.default(sigma, limits=(0,inf),
                              name=name + " sigma")
Beispiel #16
0
 def __init__(self, edges=None, cdf=None,
              args=(), loc=None, scale=None, truncated=True):
     self.edges = numpy.asarray(edges)
     self.cdf = cdf
     self.truncated = truncated
     self.loc = Parameter.default(loc)
     self.scale = Parameter.default(scale)
     self.args = [Parameter.default(a) for a in args]
Beispiel #17
0
 def __init__(self,
              rhoM=(0, 0), thetaM=(270, 270),
              name="LAYER", **kw):
     BaseMagnetism.__init__(self, name=name, **kw)
     self.rhoM = [Parameter.default(v, name=name+" rhoM[%d]"%i)
                  for i, v in enumerate(rhoM)]
     self.thetaM = [Parameter.default(v, name=name+" thetaM[%d]"%i)
                    for i, v in enumerate(thetaM)]
Beispiel #18
0
 def __init__(self, edges=None, cdf=None,
              args=[], loc=None, scale=None, truncated=True):
     self.edges = numpy.asarray(edges)
     self.cdf = cdf
     self.truncated = truncated
     self.loc = Parameter.default(loc)
     self.scale = Parameter.default(scale)
     self.args = [Parameter.default(a) for a in args]
Beispiel #19
0
 def __init__(self,
              rhoM=(0, 0), thetaM=(DEFAULT_THETA_M, DEFAULT_THETA_M),
              name="LAYER", **kw):
     BaseMagnetism.__init__(self, name=name, **kw)
     self.rhoM = [Parameter.default(v, name=name+" rhoM[%d]"%i)
                  for i, v in enumerate(rhoM)]
     self.thetaM = [Parameter.default(v, name=name+" thetaM[%d]"%i)
                    for i, v in enumerate(thetaM)]
Beispiel #20
0
 def __init__(self, thickness=0, interface=0, name="Mushroom", polymer=None, solvent=None, sigma=0, vf=0, delta=0):
     self.thickness = Parameter.default(thickness, name="Mushroom thickness")
     self.interface = Parameter.default(interface, name="Mushroom interface")
     self.delta = Parameter.default(delta, name="delta")
     self.vf = Parameter.default(vf, name="vf")
     self.sigma = Parameter.default(sigma, name="sigma")
     self.solvent = solvent
     self.polymer = polymer
     self.name = name
Beispiel #21
0
 def __init__(self, rhoM=[0, 0], thetaM=[270, 270], name="LAYER", **kw):
     BaseMagnetism.__init__(self, name=name, **kw)
     self.rhoM = [
         Parameter.default(v, name=name + " rhoM[%d]" % i)
         for i, v in enumerate(rhoM)
     ]
     self.thetaM = [
         Parameter.default(v, name=name + " thetaM[%d]" % i)
         for i, v in enumerate(thetaM)
     ]
Beispiel #22
0
 def __init__(self, material=None, thickness=0, interface=0, name=None,
              magnetism=None):
     if name is None: name = material.name
     self.name = name
     self.material = material
     self.thickness = Par.default(thickness, limits=(0,inf),
                                  name=name+" thickness")
     self.interface = Par.default(interface, limits=(0,inf),
                                  name=name+" interface")
     self.magnetism = magnetism
Beispiel #23
0
    def __init__(
        self,
        thickness=0,
        interface=0,
        name="EndTetheredPolymer",
        polymer=None,
        solvent=None,
        chi=0,
        chi_s=0,
        h_dry=None,
        l_lat=1,
        mn=None,
        m_lat=1,
        pdi=1,
    ):
        if interface != 0:
            raise NotImplementedError("interface not yet supported")
        if polymer is None or solvent is None or h_dry is None or mn is None:
            raise TypeError("Need polymer, solvent and profile")

        self.thickness = Parameter.default(thickness, name="SCF thickness")
        self.interface = Parameter.default(interface, name="SCF interface")
        self.chi = Parameter.default(chi, name="chi")
        self.chi_s = Parameter.default(chi_s, name="surface chi")
        self.h_dry = Parameter.default(h_dry, name="dry thickness")
        self.l_lat = Parameter.default(l_lat, name="lattice layer length")
        self.mn = Parameter.default(mn, name="Num. Avg. MW")
        self.m_lat = Parameter.default(m_lat, name="lattice segment mass")
        self.pdi = Parameter.default(pdi, name="Dispersity")
        self.solvent = solvent
        self.polymer = polymer
        self.name = name
Beispiel #24
0
 def __init__(self, thickness=0, interface=0, name="Mushroom",
              polymer=None, solvent=None, sigma=0,
              vf=0, delta=0):
     self.thickness = Parameter.default(thickness, name="Mushroom thickness")
     self.interface = Parameter.default(interface, name="Mushroom interface")
     self.delta = Parameter.default(delta, name="delta")
     self.vf = Parameter.default(vf, name="vf")
     self.sigma = Parameter.default(sigma, name="sigma")
     self.solvent = solvent
     self.polymer = polymer
     self.name = name
Beispiel #25
0
 def __init__(self,
              stack,
              rhoM=0,
              thetaM=DEFAULT_THETA_M,
              name="magnetic",
              **kw):
     MagneticLayer.__init__(self, stack=stack, name=name, **kw)
     self.rhoM = Parameter.default(rhoM, name=name + " SLD")
     self.thetaM = Parameter.default(thetaM,
                                     limits=(0, 360),
                                     name=name + " angle")
Beispiel #26
0
 def __init__(self, material=None, thickness=0, interface=0, name=None,
              magnetism=None):
     if name is None:
         name = material.name
     self.name = name
     self.material = material
     self.thickness = Par.default(thickness, limits=(0, inf),
                                  name=name+" thickness")
     self.interface = Par.default(interface, limits=(0, inf),
                                  name=name+" interface")
     self.magnetism = magnetism
Beispiel #27
0
 def __init__(self, extent=1, dead_below=0, dead_above=0, interface_below=None, interface_above=None, name="LAYER"):
     self.dead_below = Parameter.default(dead_below, limits=(0, inf), name=name + " deadM below")
     self.dead_above = Parameter.default(dead_above, limits=(0, inf), name=name + " deadM above")
     if interface_below is not None:
         interface_below = Parameter.default(interface_below, limits=(0, inf), name=name + " interfaceM below")
     if interface_above is not None:
         interface_above = Parameter.default(interface_above, limits=(0, inf), name=name + "  interfaceM above")
     self.interface_below = interface_below
     self.interface_above = interface_above
     self.name = name
     self.extent = extent
Beispiel #28
0
 def __init__(self, thickness=0, interface=0,
              material=None, solvent=None, vf=None,
              name="ChebyVF", method="interp"):
     if interface != 0:
         raise NotImplementedError("interface not yet supported")
     self.name = name
     self.thickness = Par.default(thickness, name="solvent thickness")
     self.interface = Par.default(interface, name="solvent interface")
     self.solvent = solvent
     self.material = material
     self.vf = [Par.default(p, name="vf[%d]"%i) for i, p in enumerate(vf)]
     self.method = method
Beispiel #29
0
 def __init__(self, thickness=0, interface=0,
              material=None, solvent=None, vf=None,
              name="ChebyVF", method="interp"):
     if interface != 0:
         raise NotImplementedError("interface not yet supported")
     self.name = name
     self.thickness = Par.default(thickness, name="solvent thickness")
     self.interface = Par.default(interface, name="solvent interface")
     self.solvent = solvent
     self.material = material
     self.vf = [Par.default(p, name="vf[%d]"%i) for i,p in enumerate(vf)]
     self.method = method
Beispiel #30
0
 def __init__(self, stack=None,
              dead_below=0, dead_above=0,
              interface_below=None, interface_above=None,
              name="magnetic"):
     self.stack = Stack(stack)
     self.dead_below = Parameter.default(dead_below, limits=(0, inf),
                                         name=name+" dead below")
     self.dead_above = Parameter.default(dead_above, limits=(0, inf),
                                         name=name+" dead above")
     self.interface_below = interface_below
     self.interface_above = interface_above
     self.name = name
Beispiel #31
0
 def __call__(self, thickness=None, interface=None, magnetism=None):
     c = copy(self)
     # Only set values if they are not None so that defaults
     # carry over from the copied layer
     if thickness is not None:
         c.thickness = Par.default(thickness, limits=(0,inf),
                                   name=self.name+" thickness")
     if interface is not None:
         c.interface = Par.default(interface, limits=(0,inf),
                                   name=self.name+" interface")
     if magnetism is not None:
         c.magnetism = magnetism
     return c
Beispiel #32
0
 def __call__(self, thickness=None, interface=None, magnetism=None):
     c = copy(self)
     # Only set values if they are not None so that defaults
     # carry over from the copied layer
     if thickness is not None:
         c.thickness = Par.default(thickness, limits=(0, inf),
                                   name=self.name+" thickness")
     if interface is not None:
         c.interface = Par.default(interface, limits=(0, inf),
                                   name=self.name+" interface")
     if magnetism is not None:
         c.magnetism = magnetism
     return c
Beispiel #33
0
    def __init__(self, thickness=0, interface=0, profile=None, tol=1e-3,
                 magnetism=None, name=None, **kw):
        if not name: name = profile.__name__
        if interface != 0: raise NotImplementedError("interface not yet supported")
        if profile is None: raise TypeError("Need profile")
        self.name = name
        self.thickness = Parameter.default(thickness, name=name+" thickness")
        self.interface = Parameter.default(interface, name=name+" interface")
        self.profile = profile
        self.tol = tol
        self.magnetism = magnetism

        self._parameters = _set_vars(self, name, profile, kw, self.RESERVED)
Beispiel #34
0
    def __init__(self,
                 weight=None,
                 rhoM=None,
                 thetaM=None,
                 interfaceM=None,
                 name="LAYER",
                 **kw):
        weight_n = 0 if weight is None else len(weight)
        rhoM_n = 0 if rhoM is None else len(rhoM)
        thetaM_n = 0 if thetaM is None else len(thetaM)
        interfaceM_n = 0 if interfaceM is None else (len(interfaceM) + 1)
        n = max(weight_n, rhoM_n, thetaM_n, interfaceM_n)

        if n == 0:
            raise ValueError(
                "Must specify one of weight, rhoM, thetaM or interfaceM as vector"
            )
        if ((weight_n > 1 and weight_n != n) or (rhoM_n > 1 and rhoM_n != n)
                or (thetaM_n > 1 and thetaM_n != n)
                or (interfaceM_n > 1 and interfaceM_n != n)):
            raise ValueError(
                "Inconsistent lengths for weight, rhoM, thetaM and interfaceM")

        # TODO: intefaces need to be implemented in profile.add_magnetism
        if interfaceM is not None:
            raise NotImplementedError(
                "Doesn't yet support magnetic interfaces")

        if weight is None:
            weight = [1]
        if rhoM is None:
            rhoM = [0]
        if thetaM is None:
            thetaM = [DEFAULT_THETA_M]
        #if interfaceM is None:
        #    interfaceM = [0]

        BaseMagnetism.__init__(self, name=name, **kw)
        self.weight = [
            Parameter.default(v, name=name + " weight[%d]" % i)
            for i, v in enumerate(weight)
        ]
        self.rhoM = [
            Parameter.default(v, name=name + " rhoM[%d]" % i)
            for i, v in enumerate(rhoM)
        ]
        self.thetaM = [
            Parameter.default(v, name=name + " thetaM[%d]" % i)
            for i, v in enumerate(thetaM)
        ]
Beispiel #35
0
 def __init__(self, thickness=0, interface=0, rho=[], irho=[],
              name="Cheby", method="interp"):
     if interface != 0:
         raise NotImplementedError("interface not yet supported")
     self.name = name
     self.method = method
     self.thickness = Par.default(thickness, limits=(0,inf),
                                name=name+" thickness")
     self.rho, self.irho \
         = [[Par.default(p, name=name+"[%d] %s"%(i,part), limits=limits)
             for i,p in enumerate(v)]
            for v,part,limits in zip((rho, irho),
                                     ('rho', 'irho'),
                                     ((-inf,inf), (-inf,inf)),
                                     )]
Beispiel #36
0
    def __init__(self, base, parts, by='volume', name=None, use_incoherent=False):
        # Split [M1, M2, F2, ...] into [M1, M2, ...], [F2, ...]
        material = [parts[i] for i in range(0, len(parts), 2)]
        fraction = [parts[i] for i in range(1, len(parts), 2)]
        # Convert M1, M2, ... to materials if necessary
        if not isinstance(base, Scatterer):
            base = Material(base)
        material = [p if isinstance(p, Scatterer) else Material(p)
                    for p in material]

        # Specify the volume calculator based on the type of fraction
        if by == 'volume':
            _volume = _VolumeFraction(base, material)
        elif by == 'mass':
            _volume = _MassFraction(base, material)
        else:
            raise ValueError('fraction must be one of volume, mass or number')

        # Name defaults to names of individual components
        if name is None:
            name = "+".join(p.name for p in material)

        # Make the fractions into fittable parameters
        fraction = [Par.default(w, limits=(0, 100), name=f.name+"% "+by)
                    for w, f in zip(fraction, material)]

        self._volume = _volume
        self.base = base
        self.material = material
        self.fraction = fraction
        self.name = name
        self.use_incoherent = use_incoherent
Beispiel #37
0
 def __init__(self, solvent=air, thickness=0, name=None):
     self.parts = []
     self.solvent = solvent
     if name is None: name="solvent "+solvent.name
     self.name = name
     self.thickness = Par.default(thickness, limits=(0,inf),
                                name=name+" thickness")
Beispiel #38
0
 def __init__(self, solvent=air, thickness=0, name=None):
     self.parts = []
     self.solvent = solvent
     if name == None: name="solvent "+solvent.name
     self.name = name
     self.thickness = Par.default(thickness, limits=(0,inf),
                                name=name+" thickness")
Beispiel #39
0
 def __init__(self, thickness=0, interface=0, rho=(), irho=(),
              name="Cheby", method="interp"):
     if interface != 0:
         raise NotImplementedError("interface not yet supported")
     self.name = name
     self.method = method
     self.thickness = Par.default(thickness, limits=(0, inf),
                                  name=name+" thickness")
     self.rho, self.irho \
         = [[Par.default(p, name=name+"[%d] %s"%(i, part), limits=limits)
             for i, p in enumerate(v)]
            for v, part, limits
            in zip((rho, irho),
                   ('rho', 'irho'),
                   ((-inf, inf), (-inf, inf)))
           ]
Beispiel #40
0
    def __init__(self, base, parts, by='volume', name=None, use_incoherent=False):
        # Split [M1,M2,F2,...] into [M1,M2,...], [F2,...]
        material = [parts[i] for i in range(0, len(parts), 2)]
        fraction = [parts[i] for i in range(1, len(parts), 2)]
        # Convert M1,M2, ... to materials if necessary
        if not isinstance(base,Scatterer): base = Material(base)
        material = [p if isinstance(p,Scatterer) else Material(p)
                    for p in material]

        # Specify the volume calculator based on the type of fraction
        if by == 'volume':
            _volume = _VolumeFraction(base, material)
        elif by == 'mass':
            _volume = _MassFraction(base, material)
        else:
            raise ValueError('fraction must be one of volume, mass or number')

        # Name defaults to names of individual components
        if name is None: name = "+".join(p.name for p in material)

        # Make the fractions into fittable parameters
        fraction = [Par.default(w,limits=(0,100), name=f.name+"% "+by)
                    for w,f in zip(fraction,material)]

        self._volume = _volume
        self.base = base
        self.material = material
        self.fraction = fraction
        self.name = name
        self.use_incoherent = use_incoherent
Beispiel #41
0
 def __init__(self, thickness=0, left=None, right=None,
              rho=[], irho=[], rhoz=[], irhoz=[], name="Freeform"):
     self.name = name
     self.left, self.right = left,right
     self.thickness = Par.default(thickness, limits=(0,inf),
                                name=name+" thickness")
     self.rho,self.irho,self.rhoz,self.irhoz \
         = [[Par.default(p,name=name+" [%d] %s"%(i,part),limits=limits)
             for i,p in enumerate(v)]
            for v,part,limits in zip((rho, irho, rhoz, irhoz),
                                     ('rho', 'irho', 'rhoz', 'irhoz'),
                                     ((-inf,inf),(-inf,inf),(0,1),(0,1))
                                     )]
     if len(self.rhoz) > 0 and len(self.rhoz) != len(self.rho):
         raise ValueError("must have one z value for each rho")
     if len(self.irhoz) > 0 and len(self.irhoz) != len(self.irho):
         raise ValueError("must have one z value for each irho")
Beispiel #42
0
 def __init__(self, thickness=0, interface=0,
              below=None, above=None,
              z=None, vf=None, name="Interface"):
     self.name = name
     self.below, self.above = below,above
     self.thickness = Par.default(thickness, limits=(0,inf),
                                  name=name+" thickness")
     self.interface = Par.default(interface, limits=(0,inf),
                                  name=name+" interface")
     if len(z) != len(vf):
         raise ValueError("Need one vf for every z")
     #if len(z) != len(vf)+2:
     #    raise ValueError("Only need vf for interior z, so len(z)=len(vf)+2")
     self.z = [Par.default(p,name=name+" z[%d]"%i,limits=(0,1))
               for i,p in enumerate(z)]
     self.vf = [Par.default(p,name=name+" vf[%d]"%i,limits=(0,1))
                for i,p in enumerate(vf)]
Beispiel #43
0
    def __init__(self, weight=[], rhoM=[], thetaM=[270], interfaceM=[0], name="LAYER", **kw):
        if (
            len(thetaM) != 1
            and len(thetaM) != len(weight)
            and len(rhoM) != 1
            and len(rhoM) != len(weight)
            and len(interfaceM) != 1
            and len(interfaceM) != len(weight) - 1
        ):
            raise ValueError("Must have one rhoM, thetaM and intefaceM for each layer")
        if interfaceM != [0]:
            raise NotImplementedError("Doesn't support magnetic roughness")

        BaseMagnetism.__init__(self, stack=stack, name=name, **kw)
        self.weight = [Parameter.default(v, name=name + " weight[%d]" % i) for i, v in enumerate(weight)]
        self.rhoM = [Parameter.default(v, name=name + " rhoM[%d]" % i) for i, v in enumerate(rhoM)]
        self.thetaM = [Parameter.default(v, name=name + " thetaM[%d]" % i) for i, v in enumerate(thetaM)]
        self.interfaceM = [Parameter.default(v, name=name + " interfaceM[%d]" % i) for i, v in enumerate(interfaceM)]
Beispiel #44
0
 def __init__(self, parts=None):
     # Split [M1, N1, M2, N2, ...] into [M1, M2, ...], [N1, N2, ...]
     formula = [parts[i] for i in range(0, len(parts), 2)]
     count = [parts[i] for i in range(1, len(parts), 2)]
     # Convert M1, M2, ... to materials if necessary
     formula = [periodictable.formula(p) for p in formula]
     count = [Par.default(w, limits=(0, inf), name=str(f)+" count")
              for w, f in zip(count, formula)]
     self.parts = formula
     self.count = count
Beispiel #45
0
 def __init__(self, parts=None):
     # Split [M1,N1,M2,N2,...] into [M1,M2,...], [N1,N2,...]
     formula = [parts[i] for i in range(0, len(parts),2)]
     count = [parts[i] for i in range(1, len(parts),2)]
     # Convert M1,M2, ... to materials if necessary
     formula = [periodictable.formula(p) for p in formula]
     count = [Par.default(w,limits=(0,inf), name=str(f)+" count")
               for w,f in zip(count,formula)]
     self.parts = formula
     self.count = count
Beispiel #46
0
    def __init__(self, thickness=0, interface=0, profile=None, tol=1e-3,
                 magnetism=None, name=None, **kw):
        if not name: name = profile.__name__
        if interface != 0: raise NotImplementedError("interface not yet supported")
        if profile is None: raise TypeError("Need profile")
        self.name = name
        self.thickness = Parameter.default(thickness, name=name+" thickness")
        self.interface = Parameter.default(interface, name=name+" interface")
        self.profile = profile
        self.tol = tol
        self.magnetism = magnetism

        # TODO: maybe make these lazy (and for magnetism below as well)
        rho_start = _LayerLimit(self, isend=False, isrho=True)
        irho_start = _LayerLimit(self, isend=False, isrho=False)
        rho_end= _LayerLimit(self, isend=True, isrho=True)
        irho_end= _LayerLimit(self, isend=True, isrho=False)
        self.start = SLD(name+" start", rho=rho_start, irho=irho_start)
        self.end = SLD(name+" end", rho=rho_end, irho=irho_end)

        self._parameters = _set_vars(self, name, profile, kw, self.RESERVED)
Beispiel #47
0
 def __init__(self, below=None, above=None, thickness=0,
              z=[], rho=[], irho=[], name="Freeform"):
     self.name = name
     self.below, self.above = below,above
     self.thickness = Par.default(thickness,name=name+" thickness",
                                  limits=(0,inf))
     self.interface = Par.default(0, name=name+" interface",
                                  limits=(0,inf))
     self.interface.fittable = False
     def parvec(vector,name,limits):
         return [Par.default(p,name=name+"[%d]"%i,limits=limits)
                 for i,p in enumerate(vector)]
     self.rho, self.irho, self.z \
         = [parvec(v,name+" "+part,limits)
            for v,part,limits in zip((rho, irho, z),
                                     ('rho', 'irho', 'z'),
                                     ((-inf,inf),(0,inf),(0,1))
                                     )]
     if len(self.z) != len(self.rho):
         raise ValueError("must have one z for each rho value")
     if len(self.irho) > 0 and len(self.z) != len(self.irho):
         raise ValueError("must have one z for each irho value")
Beispiel #48
0
 def __init__(self, stack, repeat=1, interface=None, name=None, 
              magnetism=None):
     if name is None: name = "multilayer"
     if interface is None: interface = stack[-1].interface.value
     self.magnetism = magnetism
     self.name = name
     self.repeat = IntPar(repeat, limits=(0,inf),
                          name=name + " repeats")
     self.stack = stack
     self.interface = Par.default(interface, limits=(0,inf),
                                  name=name+" top interface")
     # Thickness is computed; don't make it a simple attribute
     self._thickness = Function(self._calc_thickness,name="repeat thickness")
Beispiel #49
0
 def __init__(self, stack, repeat=1, interface=None, name=None,
              magnetism=None):
     if name is None: name = "multilayer"
     if interface is None: interface = stack[-1].interface.value
     self.magnetism = magnetism
     self.name = name
     self.repeat = IntPar(repeat, limits=(0, inf),
                          name=name + " repeats")
     self.stack = stack
     self.interface = Par.default(interface, limits=(0, inf),
                                  name=name+" top interface")
     # Thickness is computed; don't make it a simple attribute
     self._thickness = Function(self._calc_thickness, name="repeat thickness")
Beispiel #50
0
 def __init__(self, thickness=0, interface=0, name="brush",
              polymer=None, solvent=None, base_vf=None,
              base=None, length=None, power=None, sigma=None):
     self.thickness = Parameter.default(thickness, name="brush thickness")
     self.interface = Parameter.default(interface, name="brush interface")
     self.base_vf = Parameter.default(base_vf, name="base_vf")
     self.base = Parameter.default(base, name="base")
     self.length = Parameter.default(length, name="length")
     self.power = Parameter.default(power, name="power")
     self.sigma = Parameter.default(sigma, name="sigma")
     self.solvent = solvent
     self.polymer = polymer
     self.name = name
Beispiel #51
0
 def __init__(self, thickness=0, interface=0, name="brush",
              polymer=None, solvent=None, base_vf=None,
              base=None, length=None, power=None, sigma=None):
     prefix = name + " "
     self.thickness = Parameter.default(thickness, name=prefix+"thickness")
     self.interface = Parameter.default(interface, name=prefix+"interface")
     self.base_vf = Parameter.default(base_vf, name=prefix+"base_vf")
     self.base = Parameter.default(base, name=prefix+"base")
     self.length = Parameter.default(length, name=prefix+"length")
     self.power = Parameter.default(power, name=prefix+"power")
     self.sigma = Parameter.default(sigma, name=prefix+"sigma")
     self.solvent = solvent
     self.polymer = polymer
     self.name = name
Beispiel #52
0
def _set_vars(self, name, profile, kw, reserved):
    # Query profile function for the list of arguments
    vars = inspect.getargspec(profile)[0]
    #print "vars",vars
    if inspect.ismethod(profile): vars = vars[1:]  # Chop self
    vars = vars[1:]  # Chop z
    #print vars
    unused = [k for k in kw.keys() if k not in vars]
    if len(unused) > 0:
        raise TypeError("Profile got unexpected keyword argument '%s'"%unused[0])
    dups = [k for k in vars if k in reserved]
    if len(dups) > 0:
        raise TypeError("Profile has conflicting argument %r"%dups[0])
    for k in vars: kw.setdefault(k,0)
    for k,v in kw.items():
        setattr(self,k,Parameter.default(v,name=name+" "+k))

    return vars
Beispiel #53
0
def _set_vars(self, name, profile, kw, reserved):
    # Query profile function for the list of arguments
    vars = inspect.getargspec(profile)[0]
    #print "vars", vars
    if inspect.ismethod(profile):
        vars = vars[1:]  # Chop self
    vars = vars[1:]  # Chop z
    #print vars
    unused = [k for k in kw.keys() if k not in vars]
    if len(unused) > 0:
        raise TypeError("Profile got unexpected keyword argument '%s'" %
                        unused[0])
    dups = [k for k in vars if k in reserved]
    if len(dups) > 0:
        raise TypeError("Profile has conflicting argument %r" % dups[0])
    for k in vars:
        kw.setdefault(k, 0)
    for k, v in kw.items():
        setattr(self, k, Parameter.default(v, name=name + " " + k))

    return vars
Beispiel #54
0
 def __init__(self,
              samples=None,
              ratio=None,
              probe=None,
              name=None,
              coherent=False,
              interpolation=0,
              **kw):
     self.samples = samples
     self.probe = probe
     self.ratio = [
         Parameter.default(r, name="ratio %d" % i)
         for i, r in enumerate(ratio)
     ]
     self.parts = [Experiment(s, probe, **kw) for s in samples]
     self.coherent = coherent
     self.interpolation = interpolation
     self._substrate = self.samples[0][0].material
     self._surface = self.samples[0][-1].material
     self._cache = {}
     self._name = name
Beispiel #55
0
 def parvec(vector, name, limits):
     return [Parameter.default(p, name=name + "[%d]" % i, limits=limits) for i, p in enumerate(vector)]
Beispiel #56
0
 def __init__(self, rhoM=0, thetaM=270, name="LAYER", **kw):
     BaseMagnetism.__init__(self, name=name, **kw)
     self.rhoM = Parameter.default(rhoM, name=name + " rhoM")
     self.thetaM = Parameter.default(thetaM, limits=(0, 360), name=name + " thetaM")
Beispiel #57
0
 def __init__(self, stack, rhoM=0, thetaM=270, name="magnetic", **kw):
     MagneticLayer.__init__(self, stack=stack, name=name, **kw)
     self.rhoM = Parameter.default(rhoM, name=name+" SLD")
     self.thetaM = Parameter.default(thetaM, limits=(0, 360),
                                     name=name+" angle")
Beispiel #58
0
 def __init__(self, material, profile, fraction=1):
     self.material = material
     self.profile = profile
     self.fraction = Par.default(fraction, limits=(0,1),
                               name=self.material.name+" fraction")