Example #1
0
 def test_save_modelS_amdl(self):
     a1 = adipls.load_amdl('data/modelS.amdl')
     a1.to_file(tmpfile)
     a2 = adipls.load_amdl(tmpfile)
     np.testing.assert_equal(a1.nmod, a2.nmod)
     np.testing.assert_equal(a1.nn, a2.nn)
     np.testing.assert_equal(a1.D, a1.D)
     np.testing.assert_equal(a1.A, a1.A)
Example #2
0
 def test_save_modelS_amdl(self):
     D1, A1, nmod1 = adipls.load_amdl('data/modelS.amdl', return_nmod=True)
     adipls.save_amdl(tmpfile, D1, A1, nmod=nmod1)
     D2, A2, nmod2 = adipls.load_amdl(tmpfile, return_nmod=True)
     self.assertTrue(np.all(nmod1 == nmod2))
     self.assertTrue(np.all(len(A1) == len(A2)))
     self.assertTrue(np.all(D1 == D2))
     self.assertTrue(np.all(A1 == A2))
Example #3
0
    def test_fgong_to_amdl_modelS(self):
        a1 = adipls.load_amdl('data/modelS.amdl', G=6.67232e-8)
        m2 = fgong.load_fgong('data/modelS.fgong', G=6.67232e-8)
        a2 = m2.to_amdl()

        np.testing.assert_allclose(a1.D, a2.D)
        np.testing.assert_allclose(a1.A, a2.A)
Example #4
0
    def test_fgong_to_amdl_mesa(self):
        a1 = adipls.load_amdl('data/mesa.amdl', G=6.67428e-8)
        f = fgong.load_fgong('data/mesa.fgong', G=6.67428e-8)
        a2 = f.to_amdl()

        np.testing.assert_allclose(a1.D, a2.D)
        np.testing.assert_allclose(a1.A, a2.A)
Example #5
0
    def test_amdl_to_fgong_mesa(self):
        I = [0, 3, 4, 9,
             14]  # only these columns can be restored from AMDL format

        m1 = fgong.load_fgong('data/mesa.fgong', G=6.67428e-8)
        a2 = adipls.load_amdl('data/mesa.amdl', G=6.67428e-8)
        m2 = a2.to_fgong()

        np.testing.assert_allclose(m1.glob[:2], m2.glob[:2])
        np.testing.assert_allclose(m1.var[:, I], m2.var[:, I])
Example #6
0
    def test_fgong_to_amdl_mesa(self):
        D1, A1 = adipls.load_amdl('data/mesa.amdl')
        glob, var = fgong.load_fgong('data/mesa.fgong')
        D2, A2 = adipls.fgong_to_amdl(glob, var, G=6.67232e-8)
        for (x, y) in zip(D1, D2):
            self.assertAlmostEqual(x, y)

        for i in range(len(A1)):
            for (x, y) in zip(A1[i], A2[i]):
                self.assertAlmostEqual(x, y)
Example #7
0
    def test_amdl_get(self):
        D, A = adipls.load_amdl('data/mesa.amdl')
        M, R, x, G1 = adipls.amdl_get(['M', 'R', 'x', 'G1'], D, A)
        self.assertEqual(M, D[0])
        self.assertEqual(R, D[1])
        self.assertTrue(np.all(x == A[:, 0]))
        self.assertTrue(np.all(G1 == A[:, 3]))

        cs, = adipls.amdl_get(['cs'], D, A)
        cs2 = adipls.amdl_get('cs2', D, A)
        self.assertTrue(np.allclose(cs**2, cs2))
Example #8
0
 def test_amdl_get_cross_check(self):
     D, A = adipls.load_amdl('data/mesa.amdl')
     M, R, P_c, rho_c, r, x, m, q, g, rho, P, Hp, G1, cs2, cs, tau \
         = adipls.amdl_get(['M','R', 'P_c', 'rho_c', 'r', 'x', 'm',
                             'q', 'g', 'rho', 'P', 'Hp', 'G1', 'cs2',
                             'cs', 'tau'], D, A)
     self.assertTrue(np.allclose(q, m / M, rtol=4 * EPS))
     self.assertTrue(np.allclose(x, r / R, rtol=4 * EPS))
     self.assertTrue(
         np.allclose(Hp, P / (rho * g), rtol=4 * EPS, equal_nan=True))
     self.assertTrue(np.allclose(cs2, G1 * P / rho, rtol=4 * EPS))
Example #9
0
    def test_amdl_properties(self):
        m = adipls.load_amdl('data/mesa.amdl')
        self.assertEqual(m.M, m.D[0])
        self.assertEqual(m.R, m.D[1])

        np.testing.assert_equal(m.x, m.A[:, 0])
        np.testing.assert_equal(m.Gamma_1, m.A[:, 3])
        np.testing.assert_equal(m.G1, m.A[:, 3])
        np.testing.assert_equal(m.G1, m.Gamma_1)
        np.testing.assert_allclose(m.cs**2, m.cs2)
        np.testing.assert_allclose(m.S2_1, m.S_1**2)
        np.testing.assert_allclose(np.maximum(m.N2, 0), m.N**2)
Example #10
0
    def test_amdl_properties_cross_check(self):
        m = adipls.load_amdl('data/mesa.amdl')
        np.testing.assert_allclose(m.q, m.m / m.M, rtol=4 * EPS)
        np.testing.assert_allclose(m.x, m.r / m.R, rtol=4 * EPS)
        np.testing.assert_allclose(m.Hp,
                                   m.P / (m.rho * m.g),
                                   rtol=4 * EPS,
                                   equal_nan=True)
        np.testing.assert_allclose(m.cs2,
                                   m.Gamma_1 * m.P / m.rho,
                                   rtol=4 * EPS)

        s = '%r' % m
Example #11
0
def convert(args):
    """Convert function for `tomso` command-line script."""
    from_format = (guess_format(args.input_file)
                   if args.from_format == 'guess'
                   else args.from_format)
    to_format = (guess_format(args.output_file)
                 if args.to_format == 'guess'
                 else args.to_format)

    if from_format == to_format:
        raise ValueError("input format and output format are both %s\n"
                         "did you mean to copy the file?" % from_format)

    kwargs = {}
    if args.G is not None:
        kwargs['G'] = args.G

    if from_format == 'fgong':
        from tomso.fgong import load_fgong
        m = load_fgong(args.input_file, **kwargs)
    elif from_format == 'amdl':
        from tomso.adipls import load_amdl
        m = load_amdl(args.input_file, **kwargs)
    elif from_format == 'gyre':
        from tomso.gyre import load_gyre
        m = load_gyre(args.input_file, **kwargs)
    else:
        raise ValueError("%s is not a valid input format" % from_format)

    if to_format == 'fgong':
        m.to_fgong(ivers=args.ivers).to_file(args.output_file)
    elif to_format == 'amdl':
        m.to_amdl().to_file(args.output_file)
    elif to_format == 'gyre':
        m.to_gyre().to_file(args.output_file)
    else:
        raise ValueError("%s is not a valid output format" % to_format)
Example #12
0
 def test_amdl_to_amdl(self):
     a = load_amdl('data/modelS.amdl')
     self.compare_models(a, a.to_fgong().to_amdl())
     self.compare_models(a, a.to_gyre().to_amdl())
     self.compare_models(a, a.to_fgong().to_gyre().to_amdl())
     self.compare_models(a, a.to_gyre().to_fgong().to_amdl())
Example #13
0
import numpy as np
import pandas as pd
from scipy.integrate import solve_bvp
from scipy.interpolate import InterpolatedUnivariateSpline
from tomso import fgong, adipls
from tomso.utils import integrate, complement
from tqdm import tqdm

# we divide by 0 here, and we like it
np.seterr(divide='ignore', invalid='ignore')

## load from amdl file because we redistribute the mesh
# ref: Notes on adiabatic oscillation programme
# Section 5: Equilibrium model variables
# https://users-phys.au.dk/jcd/adipack.v0_3/
amdl = adipls.load_amdl(amdl_fname, return_object=True)
G = amdl.G  # gravitational constant
M, R, P_c, rho_c = amdl.D[:4]  # mass, radius, central density and pressure
x, qv, Vg, G1, A, U = amdl.A.T  # dimensionless structure
r = x * R  # distance from center
m = qv * x**3 * M  # mass coordinate
g = G * m / r**2  # local gravitational acceleration
rho = qv * U * M / 4. / np.pi / R**3  # density
P = G * m * rho / G1 / r / Vg  # pressure
drho_dr = -(A + Vg) * rho / r  # density gradient

# fix irregularities at the centre
rho[x == 0] = rho_c
P[x == 0] = P_c
g[x == 0] = 0
drho_dr[x == 0] = 0
Example #14
0
 def test_load_modelS_amdl(self):
     a = adipls.load_amdl('data/modelS.amdl')
     self.assertEqual(a.nmod, 1)
     self.assertEqual(len(a.A), 2482)
     self.assertAlmostEqual(a.D[0], 1.989e33)
     self.assertAlmostEqual(a.D[1], 6.959894677e10)
Example #15
0
 def test_load_mesa_amdl(self):
     a = adipls.load_amdl('data/mesa.amdl')
     self.assertEqual(a.nmod, 1)
     self.assertEqual(len(a.A), 601)
     self.assertAlmostEqual(a.D[0], 1.988205400E+33)
     self.assertAlmostEqual(a.D[1], 6.204550713E+10)
Example #16
0
    def test_load_mesa_amdl_fail(self):
        np.savetxt(tmpfile, np.random.rand(100, 100))

        with self.assertRaises(IOError):
            a = adipls.load_amdl(tmpfile)
Example #17
0
 def test_load_modelS_amdl(self):
     D, A, nmod = adipls.load_amdl('data/modelS.amdl', return_nmod=True)
     self.assertEqual(nmod, 1)
     self.assertEqual(len(A), 2482)
     self.assertAlmostEqual(D[0], 1.989e33)
     self.assertAlmostEqual(D[1], 69599062580.0)
Example #18
0
 def test_load_mesa_amdl(self):
     D, A, nmod = adipls.load_amdl('data/mesa.amdl', return_nmod=True)
     self.assertEqual(nmod, 1)
     self.assertEqual(len(A), 601)
     self.assertAlmostEqual(D[0], 1.988205400E+33)
     self.assertAlmostEqual(D[1], 6.204550713E+10)