Esempio n. 1
0
    def profile(self, Pz):
        thickness = self.thickness.value
        mbelow, tbelow = 0, (self.thetaM[0].value
                             if self.thetaM else DEFAULT_THETA_M)
        mabove, tabove = 0, (self.thetaM[-1].value
                             if self.thetaM else DEFAULT_THETA_M)
        z = np.sort([0] + [p.value for p in self.z] + [1]) * thickness

        rhoM = np.hstack((mbelow, [p.value for p in self.rhoM], mabove))
        PrhoM = monospline(z, rhoM, Pz)

        if np.any(np.isnan(PrhoM)):
            print("in mono")
            print("z %s" % str(z))
            print("p %s" % str([p.value for p in self.z]))

        if len(self.thetaM) > 1:
            thetaM = np.hstack(
                (tbelow, [p.value for p in self.thetaM], tabove))
            PthetaM = monospline(z, thetaM, Pz)
        elif len(self.thetaM) == 1:
            PthetaM = np.full_like(PrhoM, self.thetaM.value)
        else:
            PthetaM = np.full_like(PrhoM, DEFAULT_THETA_M)
        return PrhoM, PthetaM
Esempio n. 2
0
    def profile(self, Pz, below, above):
        thickness = self.thickness.value
        rbelow, ibelow = below
        rabove, iabove = above
        z = sort([0] + [p.value for p in self.z] + [1]) * thickness

        rho = hstack((rbelow, [p.value for p in self.rho], rabove))
        Prho = monospline(z, rho, Pz)

        if len(self.irho) > 0:
            irho = hstack((ibelow, [p.value for p in self.irho], iabove))
            Pirho = monospline(z, irho, Pz)
        else:
            Pirho = 0 * Prho
        return Prho, Pirho
Esempio n. 3
0
    def profile(self, Pz, below, above):
        thickness = self.thickness.value
        rbelow,ibelow = below
        rabove,iabove = above
        z = sort([0]+[p.value for p in self.z]+[1])*thickness

        rho = hstack((rbelow, [p.value for p in self.rho], rabove))
        Prho = monospline(z, rho, Pz)

        if len(self.irho)>0:
            irho = hstack((ibelow, [p.value for p in self.irho], iabove))
            Pirho = monospline(z, irho, Pz)
        else:
            Pirho = 0*Prho
        return Prho,Pirho
Esempio n. 4
0
 def profile(self, Pz):
     thickness = self.thickness.value
     z,p = [hstack( (0, cumsum(asarray([v.value for v in vector],'d'))) )
            for vector in (self.dz, self.dp)]
     if p[-1] == 0: p[-1] = 1
     p *= 1/p[-1]
     z *= thickness/z[-1]
     profile = clip(monospline(z, p, Pz), 0, 1)
     return profile
Esempio n. 5
0
 def profile(self, Pz):
     thickness = self.thickness.value
     z, p = [hstack((0, cumsum(asarray([v.value for v in vector], 'd'))))
             for vector in (self.dz, self.dp)]
     if p[-1] == 0: p[-1] = 1
     p *= 1/p[-1]
     z *= thickness/z[-1]
     profile = clip(monospline(z, p, Pz), 0, 1)
     return profile
Esempio n. 6
0
    def profile(self, Pz, thickness):
        mbelow, tbelow = 0, (self.thetaM[0].value if self.thetaM else 270)
        mabove, tabove = 0, (self.thetaM[-1].value if self.thetaM else 270)
        z = numpy.sort([0] + [p.value for p in self.z] + [1]) * thickness

        rhoM = numpy.hstack((mbelow, [p.value for p in self.rhoM], mabove))
        PrhoM = monospline(z, rhoM, Pz)

        if numpy.any(numpy.isnan(PrhoM)):
            print("in mono with bad PrhoM")
            print("z %s" % str(z))
            print("p %s" % str([p.value for p in self.z]))

        if len(self.thetaM) > 1:
            thetaM = numpy.hstack((tbelow, [p.value for p in self.thetaM], tabove))
            PthetaM = monospline(z, thetaM, Pz)
        elif len(self.thetaM) == 1:
            PthetaM = self.thetaM.value * numpy.ones_like(PrhoM)
        else:
            PthetaM = 270 * numpy.ones_like(PrhoM)
        return PrhoM, PthetaM
Esempio n. 7
0
    def profile(self, Pz, thickness):
        mbelow, tbelow = 0, (self.thetaM[0].value if self.thetaM else 270)
        mabove, tabove = 0, (self.thetaM[-1].value if self.thetaM else 270)
        z = numpy.sort([0] + [p.value for p in self.z] + [1]) * thickness

        rhoM = numpy.hstack((mbelow, [p.value for p in self.rhoM], mabove))
        PrhoM = monospline(z, rhoM, Pz)

        if numpy.any(numpy.isnan(PrhoM)):
            print("in mono with bad PrhoM")
            print("z %s" % str(z))
            print("p %s" % str([p.value for p in self.z]))

        if len(self.thetaM) > 1:
            thetaM = numpy.hstack(
                (tbelow, [p.value for p in self.thetaM], tabove))
            PthetaM = monospline(z, thetaM, Pz)
        elif len(self.thetaM) == 1:
            PthetaM = self.thetaM.value * numpy.ones_like(PrhoM)
        else:
            PthetaM = 270 * numpy.ones_like(PrhoM)
        return PrhoM, PthetaM
Esempio n. 8
0
def randomspline(n,p,a,b,nsteps=100,distribution=numpy.random.random):    
    """ 
        increasing monotonically only
        n control points, x random points on the range [a,b) where c is the step
    """
    #x = numpy.arange(a,b,step)
    #xt = numpy.random.uniform(min(x),max(x),p)
    Cx = numpy.cumsum(numpy.random.exponential(size=n))
    Cx = Cx/Cx[-1]*(b-a)+a
    Cy = distribution(Cx.shape)
    xt = numpy.linspace(min(Cx),max(Cx),p)
    #print (xt,monospline(Cx,Cy,xt),Cx,Cy)
    return (xt,monospline(Cx,Cy,xt),Cx,Cy)
Esempio n. 9
0
 def render(self, probe, slabs):
     interface = self.interface.value
     below_rho, below_irho = self.below.sld(probe)
     above_rho, above_irho = self.above.sld(probe)
     z = hstack((0, cumsum([v.value for v in self.dz])))
     p = hstack((0, cumsum([v.value for v in self.dp])))
     thickness = z[-1]
     if p[-1] == 0: p[-1] = 1
     p /= p[-1]
     Pw, Pz = slabs.microslabs(z[-1])
     profile = monospline(z, p, Pz)
     Pw, profile = util.merge_ends(Pw, profile, tol=1e-3)
     Prho = (1 - profile) * below_rho + profile * above_rho
     Pirho = (1 - profile) * below_irho + profile * above_irho
     slabs.extend(rho=[Prho], irho=[Pirho], w=Pw)
Esempio n. 10
0
 def render(self, probe, slabs):
     interface = self.interface.value
     below_rho,below_irho = self.below.sld(probe)
     above_rho,above_irho = self.above.sld(probe)
     z = hstack( (0, cumsum([v.value for v in self.dz])) )
     p = hstack( (0, cumsum([v.value for v in self.dp])) )
     thickness = z[-1]
     if p[-1] == 0: p[-1] = 1
     p /= p[-1]
     Pw,Pz = slabs.microslabs(z[-1])
     profile = monospline(z, p, Pz)
     Pw,profile = util.merge_ends(Pw, profile, tol=1e-3)
     Prho  = (1-profile)*below_rho  + profile*above_rho
     Pirho = (1-profile)*below_irho + profile*above_irho
     slabs.extend(rho=[Prho], irho=[Pirho], w=Pw)
Esempio n. 11
0
 def theory(self):
     return monospline(self.Cx, self.Cy, self.xt)
Esempio n. 12
0
 def theory(self):
     return monospline([q.x.value for q in self.cpoints], [q.y.value for q in self.cpoints], self.xt)
Esempio n. 13
0
def spline(x, x1, x2, x3, x4, x5, x6, x7, x8, y1, y2, y3, y4, y5, y6, y7, y8):
    return mon.monospline([x1, x2, x3, x4, x5, x6, x7, x8], [y1, y2, y3, y4, y5, y6, y7, y8], x)
Esempio n. 14
0
import numpy as np
from bumps.names import *
import bumps.mono as mon
import matplotlib.pyplot as plt
#
def spline(x, x1, x2, x3, x4, x5, x6, x7, x8, y1, y2, y3, y4, y5, y6, y7, y8):
    return mon.monospline([x1, x2, x3, x4, x5, x6, x7, x8], [y1, y2, y3, y4, y5, y6, y7, y8], x)
#def spline(x, *points):
#    return mon.monospline(points[slice(0, int(len(points)/2))], points[slice(int(len(points)/2), len(points))], [x])

x = np.linspace(5, 10, 8)
y = np.random.random(8)
#y = [4.0,4.0,6.3,8.03,9.6,11.9]
y = [.5, .245, .267, .5, .8, .3, .4, .9]
xt = np.linspace(5,10,50)
yt = mon.monospline(x, y, xt)
dyt = np.ones_like(yt) * 0.01

plt.plot(x, y, 'o')
#plt.plot(xt, yt)
#plt.show()
p = [5,6,7,8,9,0.1,0.2,0.3,0.4,0.5]
#M = Curve(spline, xt, yt , dyt,2x1=5, x2=6 , x3=7, x4=8, x5=9, y1=0.1, y2=0.2, y3=0.3, y4=0.4, y5=.5)
M = Curve(spline, xt, yt , dyt, x1=5, x2=6 , x3=7, x4=7.5, x5=8, x6=8.5, x7=9, x8=9.5, y1=0.1, y2=0.2, y3=0.3, y4=0.4, y5=.5, y6=.6, y7=.7, y8=.8)
M.x1.range(5, 10)
M.x2.range(5, 10)
M.x3.range(5, 10)
M.x4.range(5, 10)
M.x5.range(5, 10)
M.x6.range(5, 10)
M.x7.range(5, 10)