test_cube3d.py 2.69 KB
Newer Older
Shuai Feng's avatar
Shuai Feng committed
1
2
3
import sys
sys.path.insert(0, '..')
import unittest
4
5
6
7
from csst_ifs_gehong import spec1d as s
from csst_ifs_gehong import map2d as m
from csst_ifs_gehong import cube3d as b
from csst_ifs_gehong import config as c
Shuai Feng's avatar
Shuai Feng committed
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import numpy as np
import matplotlib.pyplot as plt

import warnings

class test_cube3d(unittest.TestCase):

    """
    Test modules in map2d.py
    """

    def test_cube(self):

        print("================================================================")
        print("=====================3D Spectrum Modelling======================")
        print(" ")
        print(">>> Start Test")
        print(" ")

        inst = c.instrument()
        gas_tem = s.EmissionLineTemplate(inst, model = 'hii')
        stellar_tem = s.StellarContinuumTemplate(inst)

        sbmap = m.Map2d(inst)
        sbmap.sersic_map()
        velmap = m.Map2d(inst)
        velmap.tanh_map()
        vdispmap = m.Map2d(inst)
        vdispmap.gred_map()
        agemap = m.Map2d(inst)
        agemap.gred_map(a0 = 9.5, gred = -1.2)
        fehmap = m.Map2d(inst)
        fehmap.gred_map(a0 = -0.2, gred = -0.1)
        ebvmap = m.Map2d(inst)
        ebvmap.gred_map(a0 = 0.2, gred = -0.1)
        stellarcontinuum = m.StellarPopulationMap(inst, sbright = sbmap, logage = agemap, 
                                                  feh = fehmap, vel = velmap, 
                                                  vdisp = vdispmap, ebv = ebvmap)

        sbmap = m.Map2d(inst)
        sbmap.sersic_map()
        velmap = m.Map2d(inst)
        velmap.tanh_map()
        vdispmap = m.Map2d(inst)
        vdispmap.gred_map()
        agemap = m.Map2d(inst)
        agemap.gred_map(a0 = 9.5, gred = -1.2)
        fehmap = m.Map2d(inst)
        fehmap.gred_map(a0 = -0.2, gred = -0.1)
        ebvmap = m.Map2d(inst)
        ebvmap.gred_map(a0 = 0.2, gred = -0.1)
        ionizedgas = m.IonizedGasMap(inst, halpha = agemap, zh = fehmap, 
                                     vel = velmap, vdisp = vdispmap, ebv = ebvmap)   

        u = b.Cube3D(inst, stellar_map = stellarcontinuum, gas_map = ionizedgas)

        u.make_cube(stellar_tem = stellar_tem, hii_tem = gas_tem)

        u.savefits('result.fits')

        plt.figure(figsize=(16,4))
        plt.plot(u.wave,np.log10(u.flux[50,50,:]),color='blue',label=r'$v=%4.2f$'%(velmap.map[50,50]))
        plt.plot(u.wave,np.log10(u.flux[5,95,:]),color='red',label=r'$v=%4.2f$'%(velmap.map[5,95]))
        plt.xlim(3500,9500)
        plt.legend(frameon=False)
        plt.savefig('./image/test_cube3d_spec.png')

        print("-----------------------------------------------------------------")
        print(">>> Unit test for **Spec Cube** Modelling has been passed!")

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