<commit_before>from tomso.adipls import load_amdl
from tomso.fgong import load_fgong
from tomso.gyre import load_gyre
from math import frexp
import unittest

# We should be able to make various round trips between different
# format and preserve the data relevant for adiabatic oscillations.
# Conversion to AMDL might modify the data because we mimic ADIPLS's
# own FGONG-to-AMDL script.

mech_scalars = ['R', 'M', 'G']
mech_vectors = ['r', 'q', 'm', 'rho', 'P', 'Gamma_1', 'N2', 'U', 'V', 'tau']

thermo_scalars = ['L']
thermo_vectors = ['T']

class TestConversionFunctions(unittest.TestCase):
    def compare_floats(self, x, y, attr='', index=0, places=12):
        self.assertAlmostEqual(frexp(x)[0], frexp(y)[0], places=places,
                               msg='%s at k=%i' % (attr, index))

    def compare_models(self, m0, m1, thermo=False):
        self.assertEqual(len(m0), len(m1))

        scalars = mech_scalars + thermo_scalars if thermo else mech_scalars
        vectors = mech_vectors + thermo_vectors if thermo else mech_vectors

        for attr in scalars:
            self.compare_floats(getattr(m0, attr), getattr(m1, attr),
                                attr=attr)

        for attr in vectors:
            x0 = getattr(m0, attr)
            x1 = getattr(m1, attr)
            for i in range(len(m0)):
                self.compare_floats(x0[i], x1[i], attr=attr, index=i)

    def test_fgong_to_fgong(self):
        f = load_fgong('data/modelS.fgong', return_object=True)
        self.compare_models(f, f.to_gyre().to_fgong(), thermo=True)

    def test_gyre_to_gyre(self):
        g = load_gyre('data/mesa.gyre', return_object=True)
        self.compare_models(g, g.to_fgong().to_gyre(), thermo=True)

    def test_amdl_to_amdl(self):
        a = load_amdl('data/modelS.amdl', return_object=True)
        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())

if __name__ == '__main__':
    unittest.main()
<commit_msg>Also test Teff and L_r in model conversion<commit_after>from tomso.adipls import load_amdl
from tomso.fgong import load_fgong
from tomso.gyre import load_gyre
from math import frexp
import unittest

# We should be able to make various round trips between different
# format and preserve the data relevant for adiabatic oscillations.
# Conversion to AMDL might modify the data because we mimic ADIPLS's
# own FGONG-to-AMDL script.

mech_scalars = ['R', 'M', 'G']
mech_vectors = ['r', 'q', 'm', 'rho', 'P', 'Gamma_1', 'N2', 'U', 'V', 'tau']

thermo_scalars = ['L', 'Teff']
thermo_vectors = ['L_r', 'T']

class TestConversionFunctions(unittest.TestCase):
    def compare_floats(self, x, y, attr='', index=0, places=12):
        self.assertAlmostEqual(frexp(x)[0], frexp(y)[0], places=places,
                               msg='%s at k=%i' % (attr, index))

    def compare_models(self, m0, m1, thermo=False):
        self.assertEqual(len(m0), len(m1))

        scalars = mech_scalars + thermo_scalars if thermo else mech_scalars
        vectors = mech_vectors + thermo_vectors if thermo else mech_vectors

        for attr in scalars:
            self.compare_floats(getattr(m0, attr), getattr(m1, attr),
                                attr=attr)

        for attr in vectors:
            x0 = getattr(m0, attr)
            x1 = getattr(m1, attr)
            for i in range(len(m0)):
                self.compare_floats(x0[i], x1[i], attr=attr, index=i)

    def test_fgong_to_fgong(self):
        f = load_fgong('data/modelS.fgong', return_object=True)
        self.compare_models(f, f.to_gyre().to_fgong(), thermo=True)

    def test_gyre_to_gyre(self):
        g = load_gyre('data/mesa.gyre', return_object=True)
        self.compare_models(g, g.to_fgong().to_gyre(), thermo=True)

    def test_amdl_to_amdl(self):
        a = load_amdl('data/modelS.amdl', return_object=True)
        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())

if __name__ == '__main__':
    unittest.main()

{'fraction_non_alphanumeric': 0.13292910447761194, 'fraction_numerical': 0.009328358208955223, 'mean_word_length': 3.1640776699029125, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3276809', 'n_tokens_mistral': 1571, 'n_tokens_neox': 1517, 'n_words': 347}