def test_extract_depth_points(): s = "READ DECK6 72 RHOX,T,P,XNE,ABROSS,ACCRAD,VTURB, FLXCNV,VCOMV,VELSND\n" m = model.Model() no_dp = m._extract_no_of_depth_points(s) assert no_dp == 72
def test_extract_metallicity(): s = "ABUNDANCE SCALE 0.10000 ABUNDANCE CHANGE 1 0.92140 2 0.07843" correct = -1 m = model.Model() assert m._extract_metallicity(s) == correct
def test_extract_column_names(): s = "READ DECK6 72 RHOX,T,P,XNE,ABROSS,ACCRAD,VTURB, FLXCNV,VCOMV,VELSND\n" correct = ["RHOX","T","P","XNE","ABROSS","ACCRAD","VTURB", "FLXCNV","VCOMV","VELSND"] m = model.Model() column_names = m._extract_columns_names(s) assert all([x == y for x,y in zip(column_names,correct)] + [len(correct) == len(column_names)])
def test_read_chemical_composition(): s = "ABUNDANCE CHANGE 3 -10.92 4 -10.64 5 -9.10 6 -3.52 7 -3.12 8 -3.21\n" correct = {3: -10.92, 4: -10.64, 5: -9.10, 6: -3.52, 7: -3.12, 8: -3.21} m = model.Model() cc = m._extract_chemical_composition(s) assert correct == cc
def test_read_H_He_chemical_composition(): s = "ABUNDANCE SCALE 1.00000 ABUNDANCE CHANGE 1 0.90040 2 0.08034\n" correct = {1: 0.90040, 2: 0.08034} m = model.Model() cc = m._extract_chemical_composition(s) assert correct == cc
def test_teff_logg_extraction(): s = "TEFF 5777. GRAVITY 3.44000 LTE" m = model.Model() teff = m._extract_teff(s) assert teff == 5777. logg = m._extract_logg(s) assert logg == 3.44
def test_load_model(): m = model.Model() assert 5777 == m.teff assert 4.44 == m.logg assert 0.00 == m.metallicity assert 0.9204 == m.chemical_composition["H"] assert 0.9204 == m.chemical_composition[1] assert -4.12 == m.chemical_composition["N"] assert -4.12 == m.chemical_composition[7]
def test_return_best_model(mock_file): # Mock parameters object parameters = MagicMock() parameters.teff = 3600. parameters.logg = 1.15 nearest_model = model.Model() g = models_grid.Grid("path_to_grid") model_string = g.get_best_model(parameters) nearest_model.model_from_string(model_string) assert nearest_model.teff == 3500. assert nearest_model.logg == 1.0
def test_reading_model_in(file_mock): m = model.Model() m._read_model(file_mock) assert m.teff == 6000. assert m.logg == 4.00 assert m.metallicity == pytest.approx(-0.30102, 0.0001) assert m.title == "[0.0] VTURB=0 L/H=1.25 NOVER NEW ODF" assert m.chemical_composition["H"] == 0.90040 assert m.chemical_composition[1] == 0.90040 assert m.chemical_composition["He"] == 0.08034 assert m.chemical_composition[2] == 0.08034 assert m.chemical_composition["C"] == -4.52 assert m.chemical_composition[6] == -4.52 assert m.chemical_composition[9] == -8.48 assert m.chemical_composition[14] == -5.49 assert m.pradk == 1.4875E+00 assert all([x==y for x,y in zip(m.structure["T"], [3658.0, 3683.4, 3711.3])])
def test_reading_model_in_patch_open(mock_file): m = model.Model() m._open_model("file_name") assert m.teff == 3500. assert m.logg == 0.00 assert m.metallicity == -1. assert m.title == "[-1.0] VTURB=2 L/H=1.25 NOVER NEW ODF" assert m.chemical_composition["H"] == 0.92140 assert m.chemical_composition[1] == 0.92140 assert m.pradk == 1.9980E-01 teffs = [1995.0, 1996.6, 2009.4, 2023.1, 2038.4, 2053.2, 2070.1, 2089.8, 2107.0, 2125.0, 2142.8, 2162.1, 2183.6, 2203.9, 2222.5, 2241.3, 2261.3, 2283.2, 2304.4, 2322.1, 2340.3, 2359.4, 2380.2, 2402.1, 2419.4, 2437.2, 2456.1, 2476.9, 2499.7, 2519.7, 2538.9, 2560.0, 2583.4, 2610.2, 2634.1, 2657.5, 2684.2, 2714.1, 2747.9, 2778.0, 2811.1, 2847.8, 2886.4, 2924.5, 2964.3, 3006.6, 3053.6, 3107.7, 3172.2, 3251.9, 3347.1, 3456.9, 3570.3, 3698.2, 3832.9, 3982.1, 4140.9, 4321.9, 4517.8, 4741.3, 4990.8, 5274.7, 5596.3, 5938.8, 6246.8, 6485.9, 6668.4, 6826.9, 6970.1, 7099.1, 7229.7, 7344.8,] assert all([x==y for x,y in zip(m.structure["T"], teffs)])
def test_extract_PRADK(): s = "PRADK 1.4875E+00\n" correct = 1.4875 m = model.Model() assert correct == m._extract_PRADK(s)
def test_read_title(): s = "TITLE [0.0] VTURB=0 L/H=1.25 NOVER NEW ODF \n" m = model.Model() title = m._extract_title(s) assert title == "[0.0] VTURB=0 L/H=1.25 NOVER NEW ODF"
def test_output_model_as_string(): m = model.Model() m.model_from_string(model_text) output_model_string = m.get_model_string() assert True # Unfortunatelly manual check