Ejemplo n.º 1
0
Xs = [0, 0.70]
Ys = [0.98, 0.28]
logTs = [7.55, 6.91]
logPs = [16.85, 16.87]

for X, Y, logT, logP in zip(Xs, Ys, logTs, logPs):
    mu = mmw(X=X, Y=Y)
    beta = lbeta(logT=logT, logP=logP, mu=mu)
    dens = ldensity(logT=logT, logP=logP, mu=mu)
    print u"For X=%5.3f, Y=%5.3f, log(T)=%5.3f, log(P)=%5.3f\n → μ=%5.3f → ρ=%5.3f, β=%5.3f" % (
        X, Y, logT, logP, mu, dens, beta)

# Problem #6
print "\nProblem #6:"

logTs = [6.3, 5.0]
logrhos = [0.3, -4.0]
X = 0.700
Y = 0.280
opacity = OpacityTable("GN93hz", load=True)
opacity.composition(X=X, Y=Y)
print u"Fixed composition at X=%.3g,Y=%.3g,Z=%.3g" % (opacity.X, opacity.Y,
                                                      opacity.Z)
print u"Using table %d" % (opacity.n + 1)

for logT, logrho in zip(logTs, logrhos):
    kappa = opacity.lookup(logrho=logrho, logT=logT)
    print u"log(T)=%5.3f, log(ρ)=%6.3f\n → log(κ)=%5.3f" % (logT, logrho,
                                                            kappa)
Ejemplo n.º 2
0
#===============================================================================
# Grid definition
#===============================================================================
print 'Density bounds [g/cm3]:', logRho_bounds
print 'Temperature bounds [K]:', logT_bounds
rho = np.logspace(logRho_bounds[0], logRho_bounds[1], 100)  # density grid
temp = np.logspace(logT_bounds[0], logT_bounds[1], 100)  # temperature grid
Nr, Nt = len(rho), len(temp)
rho_arr, temp_arr = np.meshgrid(rho, temp, indices='ij')

#===============================================================================
# Getting Rosseland mean opacities from OPAL
#===============================================================================
opr = np.ones((Nr, Nt)) * np.nan
for tidx in range(Nt):
    opr[:, tidx] = op.lookup(logrho=np.log10(rho),
                             logT=np.log10(temp[tidx]) * np.ones(Nr))
opr = 10**(opr)
#    # getting density boundaries for a given temperature
#    logRholim, logTlim = ionmix_grid_bounds(op, logTlim=[np.log10(temp[tidx])]*2)
#    rho_mask = (rho>10**logRholim[1])*(rho<10**logRholim[0])
#    rho_mask_len = len(np.nonzero(rho_mask)[0])
#
#    if rho_mask_len:
#        opr[rho_mask,tidx] =  op.kappa(rho=rho[rho_mask], T=temp[tidx]*np.ones(rho_mask_len))

#===============================================================================
# Ploting values of opr
#===============================================================================
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm
Ejemplo n.º 3
0
Y = 0.280
opacity1 = OpacityTable("OP17",load=False)
opacity2 = OpacityTable("GN93hz",load=False,X=X,Y=Y,efkey="cunha06")
opacity3 = OpacityTable("cunha06",load=False,X=X,Y=Y)
opacity1.composition(X=X,Y=Y)
opacity2.composition(X=X,Y=Y)
opacity3.composition(X=X,Y=Y)
print u"1: Fixed composition at X=%.3g,Y=%.3g,Z=%.3g" % (opacity1.X,opacity1.Y,opacity1.Z)
print u"2: Fixed composition at X=%.3g,Y=%.3g,Z=%.3g" % (opacity2.X,opacity2.Y,opacity2.Z)
print u"3: Fixed composition at X=%.3g,Y=%.3g,Z=%.3g" % (opacity3.X,opacity3.Y,opacity3.Z)
print u"1: Using table %d" % opacity1.n
print u"2: Using table %d" % opacity2.n
print u"3: Using table %d" % opacity3.n

for i,(logT,logrho) in enumerate(zip(logTs,logrhos)):
    kappa = opacity1.lookup(logrho=logrho,logT=logT)
    print u"1: log(T)=%5.3f, log(ρ)=%6.3f → κ=%5.3f" % (logT,logrho,kappa)
    kappa = opacity2.lookup(logrho=logrho,logT=logT)
    print u"2: log(T)=%5.3f, log(ρ)=%6.3f → κ=%5.3f" % (logT,logrho,kappa)
    kappa = opacity3.lookup(logrho=logrhosmall[i],logT=logTsmall[i])
    print u"3: log(T)=%5.3f, log(ρ)=%6.3f → κ=%5.3f" % (logTsmall[i],logrhosmall[i],kappa)
    kappa = opacity2.lookup(logrho=logrhosmall[i],logT=logTsmall[i])
    print u"2s log(T)=%5.3f, log(ρ)=%6.3f → κ=%5.3f" % (logTsmall[i],logrhosmall[i],kappa)
    
    
    
opacity1.composition(X=0.00,Y=1.00)
opacity2.composition(X=0.00,Y=1.00)
print u"1: Fixed composition at X=%.3g,Y=%.3g,Z=%.3g" % (opacity1.X,opacity1.Y,opacity1.Z)
print u"2: Fixed composition at X=%.3g,Y=%.3g,Z=%.3g" % (opacity2.X,opacity2.Y,opacity2.Z)
print u"1: Using table %d" % opacity1.n
Ejemplo n.º 4
0
class test_OpacityTable(object):
    """OpacityTable"""
    
    def setup(self):
        """Set up this test suite"""
        self.o = OpacityTable("GN93hz",load=False)

    def test_solar_composition(self):
        """Interpolated Values Succeed. logrho=[0.3,-4.0], logT=[6.3,5.0]"""
        self.o.composition(X=0.7,Y=0.28)
        assert self.o.n == 72, u"Table Mismatch, %g ≠ %g" % (self.o.n,72)
        v1 = self.o.lookup(logrho=0.3,logT=6.3)
        a1 = 1.885
        assert v1 - a1 < 1e-10, u"κ mismatch: %g ≠ %g" % (v1, a1)
        v2 = self.o.lookup(logrho=-4.0,logT=5.0)
        a2 = 3.436
        assert v2 - a2 < 1e-10, u"κ mismatch: %g ≠ %g" % (v2, a2)
        
    @nt.raises(AssertionError)
    def test_sanity_comp(self):
        """Composition should fail if X+Y > 1.0."""
        self.o.composition(X=0.7,Y=0.7)
        
    @nt.raises(ValueError)
    def test_lower_logR_bound(self):
        """Values below logR=-8.0 fail."""
        self.o.composition(X=0.70,Y=0.28)
        logrho, logT = self.o.invert_points(logR=-9.0,logT=5.00).T
        v1 = self.o.lookup(logrho=logrho,logT=logT)
        
    @nt.raises(ValueError)
    def test_upper_logR_bound(self):
        """Values above logR=1.0 fail."""
        self.o.composition(X=0.70,Y=0.28)
        logrho, logT = self.o.invert_points(logR=2.0,logT=5.00).T
        v1 = self.o.lookup(logrho=logrho,logT=logT)
        
    @nt.raises(ValueError)
    def test_lower_logT_bound(self):
        """Values below logT=3.00 fail."""
        self.o.composition(X=0.70,Y=0.28)
        logrho, logT = self.o.invert_points(logR=-4.0,logT=3.00).T
        v1 = self.o.lookup(logrho=logrho,logT=logT)
        
    @nt.raises(ValueError)
    def test_upper_logT_bound(self):
        """Values above logT=9.00 fail."""
        self.o.composition(X=0.70,Y=0.28)
        logrho, logT = self.o.invert_points(logR=-4.0,logT=9.00).T
        v1 = self.o.lookup(logrho=logrho,logT=logT)
        
    @nt.raises(ValueError)
    def test_corner_a_NaNs(self):
        """Values in the bottom right corner of the table should fail. logR=0.5, logT=8.5"""
        self.o.composition(X=0.70,Y=0.28)
        logrho, logT = self.o.invert_points(logR=0.5,logT=8.50).T
        v1 = self.o.lookup(logrho=logrho,logT=logT)
        assert v1 == 1.0
        
    @nt.raises(ValueError)
    def test_corner_b_NaNs(self):
        """Values in the top left corner of the Y=1.000 table should fail. logR=-8.0, logT=3.75"""
        self.o.composition(X=0.00,Y=1.00)
        logrho, logT = self.o.invert_points(logR=-8.0,logT=3.75).T
        v1 = self.o.lookup(logrho=logrho,logT=logT)
        assert v1 == 1.0
        
    def test_corner_a_valid(self):
        """Values in the bottom left corner of the table should succeed. logR=-8.0, logT=8.70"""
        self.o.composition(X=0.70,Y=0.28)
        logrho, logT = self.o.invert_points(logR=-8.0,logT=8.70).T
        v1 = self.o.lookup(logrho=logrho,logT=logT)
        a1 = -0.582
        assert v1 - a1  < 1e-10, u"κ mismatch: %g ≠ %g" % (v1, a1)
        
    def test_corner_b_valid(self):
        """Values in the top right corner of the table should succeed. logR=1.0, logT=3.75"""
        self.o.composition(X=0.70,Y=0.28)
        logrho, logT = self.o.invert_points(logR=1.0,logT=3.75).T
        v1 = self.o.lookup(logrho=logrho,logT=logT)
        a1 = 0.131
        assert v1 - a1  < 1e-10, u"κ mismatch: %g ≠ %g" % (v1, a1)
        
    def test_midtable_valid(self):
        """Direct values succeed. logR=-4.0, logT=5.45"""
        self.o.composition(X=0.70,Y=0.28)
        logrho, logT = self.o.invert_points(logR=-4.0,logT=5.45).T
        v1 = self.o.lookup(logrho=logrho,logT=logT)
        a1 = 0.680
        assert v1 - a1  < 1e-10, u"κ mismatch: %g ≠ %g" % (v1, a1)
Ejemplo n.º 5
0
class test_OpacityTable(object):
    """OpacityTable"""
    def setup(self):
        """Set up this test suite"""
        self.o = OpacityTable("GN93hz", load=False)

    def test_solar_composition(self):
        """Interpolated Values Succeed. logrho=[0.3,-4.0], logT=[6.3,5.0]"""
        self.o.composition(X=0.7, Y=0.28)
        assert self.o.n == 72, u"Table Mismatch, %g ≠ %g" % (self.o.n, 72)
        v1 = self.o.lookup(logrho=0.3, logT=6.3)
        a1 = 1.885
        assert v1 - a1 < 1e-10, u"κ mismatch: %g ≠ %g" % (v1, a1)
        v2 = self.o.lookup(logrho=-4.0, logT=5.0)
        a2 = 3.436
        assert v2 - a2 < 1e-10, u"κ mismatch: %g ≠ %g" % (v2, a2)

    @nt.raises(AssertionError)
    def test_sanity_comp(self):
        """Composition should fail if X+Y > 1.0."""
        self.o.composition(X=0.7, Y=0.7)

    @nt.raises(ValueError)
    def test_lower_logR_bound(self):
        """Values below logR=-8.0 fail."""
        self.o.composition(X=0.70, Y=0.28)
        logrho, logT = self.o.invert_points(logR=-9.0, logT=5.00).T
        v1 = self.o.lookup(logrho=logrho, logT=logT)

    @nt.raises(ValueError)
    def test_upper_logR_bound(self):
        """Values above logR=1.0 fail."""
        self.o.composition(X=0.70, Y=0.28)
        logrho, logT = self.o.invert_points(logR=2.0, logT=5.00).T
        v1 = self.o.lookup(logrho=logrho, logT=logT)

    @nt.raises(ValueError)
    def test_lower_logT_bound(self):
        """Values below logT=3.00 fail."""
        self.o.composition(X=0.70, Y=0.28)
        logrho, logT = self.o.invert_points(logR=-4.0, logT=3.00).T
        v1 = self.o.lookup(logrho=logrho, logT=logT)

    @nt.raises(ValueError)
    def test_upper_logT_bound(self):
        """Values above logT=9.00 fail."""
        self.o.composition(X=0.70, Y=0.28)
        logrho, logT = self.o.invert_points(logR=-4.0, logT=9.00).T
        v1 = self.o.lookup(logrho=logrho, logT=logT)

    @nt.raises(ValueError)
    def test_corner_a_NaNs(self):
        """Values in the bottom right corner of the table should fail. logR=0.5, logT=8.5"""
        self.o.composition(X=0.70, Y=0.28)
        logrho, logT = self.o.invert_points(logR=0.5, logT=8.50).T
        v1 = self.o.lookup(logrho=logrho, logT=logT)
        assert v1 == 1.0

    @nt.raises(ValueError)
    def test_corner_b_NaNs(self):
        """Values in the top left corner of the Y=1.000 table should fail. logR=-8.0, logT=3.75"""
        self.o.composition(X=0.00, Y=1.00)
        logrho, logT = self.o.invert_points(logR=-8.0, logT=3.75).T
        v1 = self.o.lookup(logrho=logrho, logT=logT)
        assert v1 == 1.0

    def test_corner_a_valid(self):
        """Values in the bottom left corner of the table should succeed. logR=-8.0, logT=8.70"""
        self.o.composition(X=0.70, Y=0.28)
        logrho, logT = self.o.invert_points(logR=-8.0, logT=8.70).T
        v1 = self.o.lookup(logrho=logrho, logT=logT)
        a1 = -0.582
        assert v1 - a1 < 1e-10, u"κ mismatch: %g ≠ %g" % (v1, a1)

    def test_corner_b_valid(self):
        """Values in the top right corner of the table should succeed. logR=1.0, logT=3.75"""
        self.o.composition(X=0.70, Y=0.28)
        logrho, logT = self.o.invert_points(logR=1.0, logT=3.75).T
        v1 = self.o.lookup(logrho=logrho, logT=logT)
        a1 = 0.131
        assert v1 - a1 < 1e-10, u"κ mismatch: %g ≠ %g" % (v1, a1)

    def test_midtable_valid(self):
        """Direct values succeed. logR=-4.0, logT=5.45"""
        self.o.composition(X=0.70, Y=0.28)
        logrho, logT = self.o.invert_points(logR=-4.0, logT=5.45).T
        v1 = self.o.lookup(logrho=logrho, logT=logT)
        a1 = 0.680
        assert v1 - a1 < 1e-10, u"κ mismatch: %g ≠ %g" % (v1, a1)
Ejemplo n.º 6
0
print "++Got Composition: %g" % (finish-start)


ntest = 1e4
logTs   = np.linspace(4.0,6.3,ntest)
logrhos = np.linspace(-6.0,0.3,ntest)
logkappa = np.empty((ntest,2))
ntest = int(ntest)

print "--Doing Interpolation"
start = time.clock()
for i in xrange(ntest):
    OT.lookup(logT=logTs[i],logrho=logrhos[i])
for i in xrange(ntest):
    func, args, kwargs, rvalue, hdr = OT.retrieve(inputs=True)
    logkappa[i,0] = rvalue
finish = time.clock()
print "--Done Interpolation: %g" % (finish-start)

print "++Doing Interpolation"
start = time.clock()
for i in xrange(ntest):
    logkappa[i,1] = OO.lookup(logT=logTs[i],logrho=logrhos[i])
finish = time.clock()
print "++Done Interpolation: %g" % (finish-start)

print "--Spurious Commands"
for i in xrange(100):
    OT.lookup(logT=logTs[i],logrho=logrhos[i])
OT.stop()
print "Threads Done!"
Ejemplo n.º 7
0
# Grid definition
#===============================================================================
print 'Density bounds [g/cm3]:', logRho_bounds
print 'Temperature bounds [K]:', logT_bounds
rho = np.logspace(logRho_bounds[0], logRho_bounds[1], 100) # density grid
temp = np.logspace(logT_bounds[0], logT_bounds[1], 100) # temperature grid 
Nr, Nt = len(rho), len(temp)
rho_arr, temp_arr = np.meshgrid(rho, temp, indices='ij')


#===============================================================================
# Getting Rosseland mean opacities from OPAL
#===============================================================================
opr = np.ones((Nr,Nt))*np.nan
for tidx in range(Nt):
    opr[:,tidx] = op.lookup(logrho=np.log10(rho), logT=np.log10(temp[tidx])*np.ones(Nr))
opr = 10**(opr)
#    # getting density boundaries for a given temperature
#    logRholim, logTlim = ionmix_grid_bounds(op, logTlim=[np.log10(temp[tidx])]*2)
#    rho_mask = (rho>10**logRholim[1])*(rho<10**logRholim[0])
#    rho_mask_len = len(np.nonzero(rho_mask)[0])
#
#    if rho_mask_len:
#        opr[rho_mask,tidx] =  op.kappa(rho=rho[rho_mask], T=temp[tidx]*np.ones(rho_mask_len))



#===============================================================================
# Ploting values of opr
#===============================================================================
import matplotlib.pyplot as plt