From 6c9aff4b2defec79d9275119e68703a6200279b6 Mon Sep 17 00:00:00 2001 From: Ansgar Wehrhahn <31626864+AWehrhahn@users.noreply.github.com> Date: Tue, 9 Mar 2021 14:53:31 +0100 Subject: [PATCH] Test the radiative transfer --- .gitignore | 1 + test/sme_synth.py | 26 +- test/test_call.py | 588 +++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 600 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 6b1f92d..4eb1720 100644 --- a/.gitignore +++ b/.gitignore @@ -85,3 +85,4 @@ src/eos/eos_math_special.c src/eos/eos.c src/sme/hlinop.c src/sme/hlinprof.c +debug_radiative_transfer.npz diff --git a/test/sme_synth.py b/test/sme_synth.py index 631079e..8cca1a1 100644 --- a/test/sme_synth.py +++ b/test/sme_synth.py @@ -176,12 +176,12 @@ def InputLineList(self, linelist): names of the elements (with Ionization level) """ try: - atomic = linelist.atomic.T - species = linelist.species + atomic = linelist["atomic"].T + species = linelist["species"] except AttributeError: raise TypeError("linelist has to be a LineList type") - nlines = len(linelist) + nlines = 1 species = np.asarray(species, "U8") assert ( @@ -265,16 +265,16 @@ def InputModel(self, teff, grav, vturb, atmo): raise ValueError("Turbulence velocity must be positive or zero") try: - motype = atmo.depth + motype = atmo["depth"] depth = atmo[motype] ndepth = len(depth) - t = atmo.temp - xne = atmo.xne - xna = atmo.xna - rho = atmo.rho + t = atmo["temp"] + xne = atmo["xne"] + xna = atmo["xna"] + rho = atmo["rho"] vt = np.full(ndepth, vturb) if np.size(vturb) == 1 else vturb - wlstd = atmo.wlstd - opflag = atmo.opflag + wlstd = atmo["wlstd"] + opflag = atmo["opflag"] args = [ ndepth, teff, @@ -291,9 +291,9 @@ def InputModel(self, teff, grav, vturb, atmo): ] type = "sdddusdddddd" # s : short, d: double, u: unicode (string) - if atmo.geom == "SPH": - radius = atmo.radius - height = atmo.height + if atmo["geom"] == "SPH": + radius = atmo["radius"] + height = atmo["height"] motype = "SPH" args = args[:5] + [radius] + args[5:] + [height] type = type[:5] + "d" + type[5:] + "d" diff --git a/test/test_call.py b/test/test_call.py index ac2b5fc..ae15dff 100644 --- a/test/test_call.py +++ b/test/test_call.py @@ -1,17 +1,22 @@ from os.path import dirname, join import pytest +import numpy as np from sme_synth import SME_DLL from cwrapper import get_lib_name + @pytest.fixture def libfile(): return join(dirname(__file__), "../lib/", get_lib_name()) + @pytest.fixture def datadir(): - return join(dirname(__file__), "../share/libsme") + # the path has to end with a path seperator + return join(dirname(__file__), "../share/libsme/") + @pytest.fixture def dll(libfile, datadir): @@ -19,16 +24,595 @@ def dll(libfile, datadir): # the library file has been loaded from a different location return SME_DLL(libfile, datadir) + def test_simple_call(dll): version = dll.SMELibraryVersion() assert isinstance(version, str) + def test_call_with_input(dll): dll.InputWaveRange(5000, 6000) + +def test_radiative_transfer(dll, libfile, datadir): + + # species wlcent gflog excit j_lo ... term_lower term_upper error atom_number ionization + # 35 Ca 1 6439.075 0.39 2.525682 3.0 ... 3p6.3d.4s 3D 3p6.3d.4p 3F* 0.5 1.0 1.0 + linelist = { + "species": np.array(["Ca 1"]), + "atomic": np.array( + [ + [ + 1.00000000e00, + 1.00000000e00, + 6.43907500e03, + 2.52568209e00, + 3.90000000e-01, + 7.64900000e00, + -6.07200000e00, + -7.56900000e00, + ] + ] + ), + } + + nan = np.nan + abund = np.array( + [ + 0.92067888, + -1.10589182, + -10.98589182, + -10.65589182, + -9.33589182, + -3.60589182, + -4.20589182, + -3.34589182, + -7.47589182, + -4.10589182, + -5.79589182, + -4.43589182, + -5.58589182, + -4.52589182, + -6.62589182, + -4.91589182, + -6.53589182, + -5.63589182, + -7.00589182, + -5.69589182, + -8.88589182, + -7.08589182, + -8.10589182, + -6.39589182, + -6.60589182, + -4.53589182, + -7.04589182, + -5.81589182, + -7.84589182, + -7.47589182, + -8.99589182, + -8.38589182, + -9.73589182, + -8.69589182, + -9.49589182, + -8.78589182, + -9.51589182, + -9.16589182, + -9.82589182, + -9.45589182, + -10.57589182, + -10.15589182, + nan, + -10.28589182, + -11.12589182, + -10.46589182, + -11.09589182, + -10.32589182, + -11.23589182, + -9.99589182, + -11.02589182, + -9.85589182, + -10.48589182, + -9.79589182, + -10.95589182, + -9.85589182, + -10.93589182, + -10.45589182, + -11.31589182, + -10.61589182, + nan, + -11.07589182, + -11.51589182, + -10.96589182, + -11.73589182, + -10.93589182, + -11.55589182, + -11.11589182, + -11.93589182, + -11.19589182, + -11.93589182, + -11.18589182, + -12.15589182, + -11.18589182, + -11.77589182, + -10.63589182, + -10.65589182, + -10.41589182, + -11.11589182, + -10.86589182, + -11.13589182, + -10.28589182, + -11.38589182, + nan, + nan, + nan, + nan, + nan, + nan, + -12.01589182, + nan, + -12.57589182, + nan, + nan, + nan, + nan, + nan, + nan, + nan, + ] + ) + abund[np.isnan(abund)] = -99 + + atmo = { + "teff": 5777.0, + "logg": 4.4, + "abund": abund, + "vturb": 2, + "lonh": 1.5, + "source": "marcs2012p_t2.0.sav", + "method": "grid", + "geom": "PP", + "radius": 1.0, + "height": np.array( + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + ] + ), + "opflag": np.array( + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0] + ), + "wlstd": 5000.0, + "depth": "RHOX", + "interp": "RHOX", + "RHOX": np.array( + [ + 0.01227157, + 0.01586509, + 0.020498, + 0.02646569, + 0.03414687, + 0.0440273, + 0.05672962, + 0.07305083, + 0.09400917, + 0.12090689, + 0.13708606, + 0.15540696, + 0.17615128, + 0.19963689, + 0.22622397, + 0.25631865, + 0.29037854, + 0.32892201, + 0.37253475, + 0.42187725, + 0.4776943, + 0.54082989, + 0.61222844, + 0.69295062, + 0.78418885, + 0.8872738, + 1.00369726, + 1.13510934, + 1.28334122, + 1.45038586, + 1.63833817, + 1.84927511, + 2.08503906, + 2.34680463, + 2.63433651, + 2.94509704, + 3.2732565, + 3.60953624, + 3.94241103, + 4.26021865, + 4.55298557, + 4.8141394, + 5.03808133, + 5.22112386, + 5.37096192, + 5.5017032, + 5.62320824, + 5.74153326, + 5.86070096, + 5.98362442, + 6.25028179, + 6.55794018, + 6.92123437, + 7.35662696, + 7.88457253, + ] + ), + "tau": np.array( + [ + 1.83158147e-05, + 2.85514842e-05, + 4.43180966e-05, + 6.86532336e-05, + 1.06313543e-04, + 1.64771374e-04, + 2.55720760e-04, + 3.97459938e-04, + 6.18653888e-04, + 9.63976440e-04, + 1.20393963e-03, + 1.50381269e-03, + 1.87878028e-03, + 2.34759219e-03, + 2.93442683e-03, + 3.66815363e-03, + 4.58557641e-03, + 5.73283270e-03, + 7.16846626e-03, + 8.96338886e-03, + 1.12064218e-02, + 1.40110610e-02, + 1.75177791e-02, + 2.19002900e-02, + 2.73711469e-02, + 3.42068219e-02, + 4.27387971e-02, + 5.33805898e-02, + 6.66645261e-02, + 8.32214418e-02, + 1.03866269e-01, + 1.29607314e-01, + 1.61724865e-01, + 2.01811295e-01, + 2.51873195e-01, + 3.14530520e-01, + 3.93018001e-01, + 4.91396106e-01, + 6.14773215e-01, + 7.69633082e-01, + 9.63720160e-01, + 1.20718696e00, + 1.51180239e00, + 1.88539541e00, + 2.33263750e00, + 2.87159001e00, + 3.53113892e00, + 4.34688225e00, + 5.35996637e00, + 6.61665825e00, + 1.01386634e01, + 1.55929432e01, + 2.40845454e01, + 3.74098229e01, + 5.87642762e01, + ] + ), + "temp": np.array( + [ + 4085.16994646, + 4127.44078991, + 4171.19282404, + 4215.79809774, + 4260.92327871, + 4306.45182793, + 4352.26406468, + 4398.13504503, + 4444.07681192, + 4489.80294658, + 4513.06800491, + 4536.21869593, + 4559.30147126, + 4582.42253166, + 4605.68664112, + 4629.04105898, + 4652.73456775, + 4676.67229242, + 4701.05835482, + 4726.19319126, + 4752.172988, + 4779.35286739, + 4808.03777524, + 4838.63523596, + 4871.63662132, + 4907.60095122, + 4946.91407451, + 4990.3104116, + 5038.11825734, + 5091.84925956, + 5152.10858889, + 5220.50712708, + 5297.70074231, + 5385.40352207, + 5485.59813843, + 5599.15339345, + 5728.90239472, + 5876.72885555, + 6044.80873598, + 6235.33366695, + 6451.44405423, + 6695.6820376, + 6983.76545365, + 7306.61661858, + 7607.2121053, + 7868.69435733, + 8093.13095323, + 8287.80432747, + 8460.95776317, + 8618.1860197, + 8901.73132469, + 9166.99843088, + 9423.6885857, + 9678.12942929, + 9939.64783894, + ] + ), + "rho": np.array( + [ + 1.25532527e-09, + 1.60793410e-09, + 2.05735160e-09, + 2.62985348e-09, + 3.35882161e-09, + 4.28658226e-09, + 5.46683964e-09, + 6.96782234e-09, + 8.87590170e-09, + 1.13010448e-08, + 1.27481184e-08, + 1.43792405e-08, + 1.62170090e-08, + 1.82873431e-08, + 2.06193429e-08, + 2.32454191e-08, + 2.62018226e-08, + 2.95291364e-08, + 3.32722799e-08, + 3.74807518e-08, + 4.22094131e-08, + 4.75182948e-08, + 5.34724961e-08, + 6.01419151e-08, + 6.76016383e-08, + 7.59299795e-08, + 8.52133959e-08, + 9.55329541e-08, + 1.06984907e-07, + 1.19634655e-07, + 1.33556211e-07, + 1.48774780e-07, + 1.65292858e-07, + 1.83007695e-07, + 2.01666745e-07, + 2.20866962e-07, + 2.39897735e-07, + 2.57865201e-07, + 2.73778822e-07, + 2.86759804e-07, + 2.96131623e-07, + 3.01580262e-07, + 3.02413211e-07, + 2.99348729e-07, + 2.95474700e-07, + 2.92182514e-07, + 2.89832346e-07, + 2.88403097e-07, + 2.87775557e-07, + 2.87833463e-07, + 2.89764840e-07, + 2.93711739e-07, + 2.99756567e-07, + 3.08129510e-07, + 3.19048955e-07, + ] + ), + "xna": np.array( + [ + 5.96495925e14, + 7.64040782e14, + 9.77584725e14, + 1.24960360e15, + 1.59596097e15, + 2.03675983e15, + 2.59751622e15, + 3.31062905e15, + 4.21711754e15, + 5.36921227e15, + 6.05663647e15, + 6.83145811e15, + 7.70445189e15, + 8.68786114e15, + 9.79553433e15, + 1.10428861e16, + 1.24470388e16, + 1.40272935e16, + 1.58049462e16, + 1.78035954e16, + 2.00492401e16, + 2.25702651e16, + 2.53976919e16, + 2.85646536e16, + 3.21068944e16, + 3.60615471e16, + 4.04697727e16, + 4.53701842e16, + 5.08083901e16, + 5.68158524e16, + 6.34279168e16, + 7.06566265e16, + 7.85033713e16, + 8.69200895e16, + 9.57860912e16, + 1.04911307e17, + 1.13957803e17, + 1.22500199e17, + 1.30068064e17, + 1.36243746e17, + 1.40703914e17, + 1.43299333e17, + 1.43700396e17, + 1.42250328e17, + 1.40413447e17, + 1.38851146e17, + 1.37735021e17, + 1.37056657e17, + 1.36757599e17, + 1.36785211e17, + 1.37702672e17, + 1.39578478e17, + 1.42451056e17, + 1.46429823e17, + 1.51618463e17, + ] + ), + "xne": np.array( + [ + 4.64332593e10, + 5.95149902e10, + 7.62552880e10, + 9.76283302e10, + 1.24873879e11, + 1.59568894e11, + 2.03711571e11, + 2.59813189e11, + 3.31031213e11, + 4.21308341e11, + 4.75231577e11, + 5.35873772e11, + 6.04120053e11, + 6.80927452e11, + 7.67367809e11, + 8.64669410e11, + 9.74228829e11, + 1.09763662e12, + 1.23674790e12, + 1.39375188e12, + 1.57117229e12, + 1.77207219e12, + 2.00003579e12, + 2.25946321e12, + 2.55562723e12, + 2.89513712e12, + 3.28578249e12, + 3.73811714e12, + 4.26434025e12, + 4.88403178e12, + 5.62143902e12, + 6.51550155e12, + 7.62226388e12, + 9.03619874e12, + 1.09179517e13, + 1.35247862e13, + 1.73153768e13, + 2.30486418e13, + 3.20113910e13, + 4.63786483e13, + 6.99245407e13, + 1.09328533e14, + 1.78908132e14, + 2.95205182e14, + 4.54550317e14, + 6.49979183e14, + 8.72693704e14, + 1.11638096e15, + 1.37891933e15, + 1.65962852e15, + 2.28194794e15, + 3.02742940e15, + 3.93537108e15, + 5.05437513e15, + 6.47130238e15, + ] + ), + "citation_info": "", + } + + dll.SetLibraryPath(datadir) + dll.InputLineList(linelist) + dll.InputModel(5770, 4.44, 0.7, atmo) + dll.InputAbund(lambda *_, **__: abund) + dll.Ionization(0) + dll.SetVWscale(1.0) + dll.SetH2broad(True) + + dll.InputWaveRange(6436, 6442) + dll.Opacity() + _, wint, sint, cint = dll.Transf([1], 0.01, 0.03) + + # For comparison + np.savez("debug_radiative_transfer.npz", wave=wint, spec=sint, cont=cint) + + if __name__ == "__main__": libfile = join(dirname(__file__), "../lib/", "libsme-5.dll") datadir = join(dirname(__file__), "../share/libsme") dll = SME_DLL(libfile, datadir) version = dll.SMELibraryVersion() - print(version) \ No newline at end of file + print(version)