예제 #1
0
# User defined parameters
#===============================================================================
composition_request = {'X': 0.9, 'Y': 0.02, 'dXc': 0.001}
logT_bounds = [3.8, 8]
logRho_bounds = [-11, -3]

#===============================================================================
# Loading OPAL table
#===============================================================================
# 1. requires: pystellar and AstroObject python modules see: https://github.com/alexrudy
# 2. add requiered opal table to pystellar/data/
# 3. edit pystellar/OPAL.yml and add a new entry for the table
# 4. make a symbolic link or copy pystellar/data/ to ./
op = OpacityTable(fkey='Gz020', filename='/home/rth/src/pystellar/OPAL.yml')

op.composition(**composition_request)

composition_match = {
    key: getattr(op, key)
    for key in ['X', 'Y', 'Z', 'dXc', 'dXo']
}
print 'Requested composition :', pretty_print_composition(composition_request)
print 'Found composition     :', pretty_print_composition(composition_match)

#===============================================================================
# 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
예제 #2
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)
예제 #3
0
print "\nProblem #6:"

print "1: OP17"
print "2: GN93hz"
print "3: cunha06"
logTs   = [6.3, 5.0]
logrhos = [0.3,-4.0]
logTsmall = [3.05,3.95]
logrhosmall = [-8.0,-4.0]
X = 0.700
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])
예제 #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)
예제 #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)
예제 #6
0
# User defined parameters
#===============================================================================
composition_request = {'X': 0.9, 'Y': 0.02, 'dXc': 0.001}
logT_bounds = [3.8,8]
logRho_bounds = [-11, -3]

#===============================================================================
# Loading OPAL table
#===============================================================================
# 1. requires: pystellar and AstroObject python modules see: https://github.com/alexrudy
# 2. add requiered opal table to pystellar/data/
# 3. edit pystellar/OPAL.yml and add a new entry for the table
# 4. make a symbolic link or copy pystellar/data/ to ./
op = OpacityTable(fkey='Gz020',filename='/home/rth/src/pystellar/OPAL.yml')

op.composition(**composition_request)

composition_match = {key: getattr(op, key) for key in ['X', 'Y', 'Z', 'dXc', 'dXo']}
print 'Requested composition :', pretty_print_composition(composition_request)
print 'Found composition     :', pretty_print_composition(composition_match)

#===============================================================================
# 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')