test_map2d.py 7.77 KB
Newer Older
Shuai Feng's avatar
Shuai Feng committed
1
2
import sys
import unittest
3
4
from csst_ifs_gehong import map2d as m
from csst_ifs_gehong import config as c
Shuai Feng's avatar
Shuai Feng committed
5
import numpy as np
Shuai Feng's avatar
Shuai Feng committed
6
7
8
9
# import matplotlib.pyplot as plt
# import warnings

sys.path.insert(0, '..')
Shuai Feng's avatar
Shuai Feng committed
10
11
12
13
14
15
16
17
18
19


class test_map2d(unittest.TestCase):

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

    def test_sbmap(self):

20
        inst = c.config()
Shuai Feng's avatar
Shuai Feng committed
21
22
23
24
25

        print("------------------------- Sersic Model -------------------------")
        print(" ")
        print("Pars: Total Magnitude")
        sbmap0 = m.Map2d(inst)
Shuai Feng's avatar
Shuai Feng committed
26
        sbmap0.sersic_map(mag=12, r_eff=2, n=2.5, ellip=0.5, theta=-50)
Shuai Feng's avatar
Shuai Feng committed
27
        sbmap1 = m.Map2d(inst)
Shuai Feng's avatar
Shuai Feng committed
28
        sbmap1.sersic_map(mag=14, r_eff=2, n=2.5, ellip=0.5, theta=-50)
Shuai Feng's avatar
Shuai Feng committed
29
30
31
32
33
        if np.sum(sbmap1.map) != np.sum(sbmap0.map):
            print("No Problem!")

        print("Pars: Effective Radius")
        sbmap1 = m.Map2d(inst)
Shuai Feng's avatar
Shuai Feng committed
34
        sbmap1.sersic_map(mag=12, r_eff=4, n=2.5, ellip=0.5, theta=-50)
Shuai Feng's avatar
Shuai Feng committed
35
36
37
38
39
        if np.sum(sbmap1.map) != np.sum(sbmap0.map):
            print("No Problem!")

        print("Pars: Sersic Index")
        sbmap1 = m.Map2d(inst)
Shuai Feng's avatar
Shuai Feng committed
40
        sbmap1.sersic_map(mag=12, r_eff=2, n=5, ellip=0.5, theta=-50)
Shuai Feng's avatar
Shuai Feng committed
41
42
43
44
45
        if np.sum(sbmap1.map) != np.sum(sbmap0.map):
            print("No Problem!")

        print("Pars: Ellipse")
        sbmap1 = m.Map2d(inst)
Shuai Feng's avatar
Shuai Feng committed
46
        sbmap1.sersic_map(mag=12, r_eff=2, n=2.5, ellip=0.2, theta=-50)
Shuai Feng's avatar
Shuai Feng committed
47
48
49
50
51
        if np.sum(sbmap1.map) != np.sum(sbmap0.map):
            print("No Problem!")

        print("Pars: Position Angle")
        sbmap1 = m.Map2d(inst)
Shuai Feng's avatar
Shuai Feng committed
52
        sbmap1.sersic_map(mag=12, r_eff=2, n=2.5, ellip=0.5, theta=0)
Shuai Feng's avatar
Shuai Feng committed
53
54
55
        if np.sum(sbmap1.map) != np.sum(sbmap0.map):
            print("No Problem!")

Shuai Feng's avatar
Shuai Feng committed
56
57
58
59
60
61
62
63
        # plt.figure(figsize=(6,5))
        # plt.imshow(sbmap0.map, origin='lower', cmap='gray_r')
        # plt.xticks([])
        # plt.yticks([])
        # plt.title('Surface Brightness Modelling')
        # plt.colorbar(label='mag')
        # plt.tight_layout()
        # plt.savefig('./image/test_map2d_SBmap.png')
Shuai Feng's avatar
Shuai Feng committed
64
65
66

    def test_velmap(self):

67
        inst = c.config()
Shuai Feng's avatar
Shuai Feng committed
68
69
70
71
72

        print("------------------------ Velocity Model ------------------------")
        print(" ")
        print("Pars: Rotation Velocity")
        velmap0 = m.Map2d(inst)
Shuai Feng's avatar
Shuai Feng committed
73
        velmap0.tanh_map(vmax=200, rt=2, ellip=0.5, theta=-50)
Shuai Feng's avatar
Shuai Feng committed
74
        velmap1 = m.Map2d(inst)
Shuai Feng's avatar
Shuai Feng committed
75
        velmap1.tanh_map(vmax=100, rt=2, ellip=0.5, theta=-50)
Shuai Feng's avatar
Shuai Feng committed
76
77
78
79
80
        if np.sum(velmap1.map) != np.sum(velmap0.map):
            print("No Problem!")

        print("Pars: Turnover Radius")
        velmap1 = m.Map2d(inst)
Shuai Feng's avatar
Shuai Feng committed
81
        velmap1.tanh_map(vmax=200, rt=3, ellip=0.5, theta=-50)
Shuai Feng's avatar
Shuai Feng committed
82
83
84
85
86
        if np.sum(velmap1.map) != np.sum(velmap0.map):
            print("No Problem!")

        print("Pars: Inclination Angle")
        velmap1 = m.Map2d(inst)
Shuai Feng's avatar
Shuai Feng committed
87
        velmap1.tanh_map(vmax=200, rt=2, ellip=0.3, theta=-50)
Shuai Feng's avatar
Shuai Feng committed
88
89
90
91
92
        if np.sum(velmap1.map) != np.sum(velmap0.map):
            print("No Problem!")

        print("Pars: Position Angle")
        velmap1 = m.Map2d(inst)
Shuai Feng's avatar
Shuai Feng committed
93
        velmap1.tanh_map(vmax=200, rt=2, ellip=0.5, theta=100)
Shuai Feng's avatar
Shuai Feng committed
94
95
96
        if np.sum(velmap1.map) != np.sum(velmap0.map):
            print("No Problem!")

Shuai Feng's avatar
Shuai Feng committed
97
98
99
100
101
102
103
104
        # plt.figure(figsize=(6,5))
        # plt.imshow(velmap0.map, origin='lower', cmap='RdBu_r')
        # plt.xticks([])
        # plt.yticks([])
        # plt.title('Velocity Map Modelling')
        # plt.colorbar(label='km/s')
        # plt.tight_layout()
        # plt.savefig('./image/test_map2d_velmap.png')
Shuai Feng's avatar
Shuai Feng committed
105
106
107

    def test_gremap(self):

108
        inst = c.config()
Shuai Feng's avatar
Shuai Feng committed
109
110
111
112
113

        print("------------------------ Gredient Model ------------------------")
        print(" ")
        print("Pars: Central Intensity")
        velmap0 = m.Map2d(inst)
Shuai Feng's avatar
Shuai Feng committed
114
        velmap0.gred_map(a0=10, r_eff=1, gred=-1, ellip=0.5, theta=0)
Shuai Feng's avatar
Shuai Feng committed
115
        velmap1 = m.Map2d(inst)
Shuai Feng's avatar
Shuai Feng committed
116
        velmap1.gred_map(a0=20, r_eff=1, gred=-1, ellip=0.5, theta=0)
Shuai Feng's avatar
Shuai Feng committed
117
118
119
120
121
        if np.sum(velmap1.map) != np.sum(velmap0.map):
            print("No Problem!")

        print("Pars: Effective Radius")
        velmap1 = m.Map2d(inst)
Shuai Feng's avatar
Shuai Feng committed
122
        velmap1.gred_map(a0=10, r_eff=2, gred=-1, ellip=0.5, theta=0)
Shuai Feng's avatar
Shuai Feng committed
123
124
        if np.sum(velmap1.map) != np.sum(velmap0.map):
            print("No Problem!")
Shuai Feng's avatar
Shuai Feng committed
125

Shuai Feng's avatar
Shuai Feng committed
126
127
        print("Pars: Grediant")
        velmap1 = m.Map2d(inst)
Shuai Feng's avatar
Shuai Feng committed
128
        velmap1.gred_map(a0=10, r_eff=1, gred=-2, ellip=0.5, theta=0)
Shuai Feng's avatar
Shuai Feng committed
129
130
131
132
133
        if np.sum(velmap1.map) != np.sum(velmap0.map):
            print("No Problem!")

        print("Pars: Inclination Angle")
        velmap1 = m.Map2d(inst)
Shuai Feng's avatar
Shuai Feng committed
134
        velmap1.gred_map(a0=10, r_eff=1, gred=-1, ellip=0.3, theta=0)
Shuai Feng's avatar
Shuai Feng committed
135
136
137
138
139
        if np.sum(velmap1.map) != np.sum(velmap0.map):
            print("No Problem!")

        print("Pars: Position Angle")
        velmap1 = m.Map2d(inst)
Shuai Feng's avatar
Shuai Feng committed
140
        velmap1.gred_map(a0=10, r_eff=1, gred=-1, ellip=0.5, theta=100)
Shuai Feng's avatar
Shuai Feng committed
141
142
143
        if np.sum(velmap1.map) != np.sum(velmap0.map):
            print("No Problem!")

Shuai Feng's avatar
Shuai Feng committed
144
145
146
147
148
149
150
151
        # plt.figure(figsize=(6,5))
        # plt.imshow(velmap0.map, origin='lower', cmap='RdBu_r')
        # plt.xticks([])
        # plt.yticks([])
        # plt.title('Gredient Map Modelling')
        # plt.colorbar(label='')
        # plt.tight_layout()
        # plt.savefig('./image/test_map2d_gredmap.png')
Shuai Feng's avatar
Shuai Feng committed
152
153
154

    def test_input_image(self):

155
        inst = c.config()
Shuai Feng's avatar
Shuai Feng committed
156
157
158
159

        print("------------------------ Feed Image------------------------")
        print(" ")
        velmap0 = m.Map2d(inst)
Shuai Feng's avatar
Shuai Feng committed
160
        velmap0.gred_map(a0=10, r_eff=1, gred=-1, ellip=0.5, theta=0)
Shuai Feng's avatar
Shuai Feng committed
161
162
163
164
165
166
167
        velmap1 = m.Map2d(inst)
        velmap1.load_map(velmap0.map)
        if np.sum(velmap1.map) == np.sum(velmap0.map):
            print("No Problem!")

    def test_stellar_population_map(self):

168
        inst = c.config()
Shuai Feng's avatar
Shuai Feng committed
169
170
171
172
173
174
175
176
177
178
179

        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)
Shuai Feng's avatar
Shuai Feng committed
180
        agemap.gred_map(a0=9.5, gred=-1.2)
Shuai Feng's avatar
Shuai Feng committed
181
182

        fehmap = m.Map2d(inst)
Shuai Feng's avatar
Shuai Feng committed
183
        fehmap.gred_map(a0=-0.2, gred=-0.1)
Shuai Feng's avatar
Shuai Feng committed
184
185

        ebvmap = m.Map2d(inst)
Shuai Feng's avatar
Shuai Feng committed
186
187
188
189
        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)
Shuai Feng's avatar
Shuai Feng committed
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205

        if np.sum(stellarcontinuum.sbright) == np.sum(sbmap.map):
            print("SBmap No Problem!")
        if np.sum(stellarcontinuum.age) == np.sum(agemap.map):
            print("Agemap No Problem!")
        if np.sum(stellarcontinuum.feh) == np.sum(fehmap.map):
            print("FeHmap No Problem!")
        if np.sum(stellarcontinuum.vel) == np.sum(velmap.map):
            print("Velmap No Problem!")
        if np.sum(stellarcontinuum.vdisp) == np.sum(vdispmap.map):
            print("VDISPmap No Problem!")
        if np.sum(stellarcontinuum.ebv) == np.sum(ebvmap.map):
            print("SBmap No Problem!")

    def test_ionized_gas_map(self):

206
        inst = c.config()
Shuai Feng's avatar
Shuai Feng committed
207
208
209
210
211
212
213
214
215
216
217

        halphamap = m.Map2d(inst)
        halphamap.sersic_map()

        velmap = m.Map2d(inst)
        velmap.tanh_map()

        vdispmap = m.Map2d(inst)
        vdispmap.gred_map()

        logohmap = m.Map2d(inst)
Shuai Feng's avatar
Shuai Feng committed
218
        logohmap.gred_map(a0=9.5, gred=-1.2)
Shuai Feng's avatar
Shuai Feng committed
219
220

        ebvmap = m.Map2d(inst)
Shuai Feng's avatar
Shuai Feng committed
221
222
223
224
        ebvmap.gred_map(a0=0.2, gred=-0.1)

        gas = m.IonizedGasMap(inst, halpha=halphamap, zh=logohmap,
                              vel=velmap, vdisp=vdispmap, ebv=ebvmap)
Shuai Feng's avatar
Shuai Feng committed
225
226
227
228
229
230
231
232
233
234
235
236

        if np.sum(gas.halpha) == np.sum(halphamap.map):
            print("Halphamap No Problem!")
        if np.sum(gas.zh) == np.sum(logohmap.map):
            print("logOHmap No Problem!")
        if np.sum(gas.vel) == np.sum(velmap.map):
            print("Velmap No Problem!")
        if np.sum(gas.vdisp) == np.sum(vdispmap.map):
            print("VDISPmap No Problem!")
        if np.sum(gas.ebv) == np.sum(ebvmap.map):
            print("SBmap No Problem!")

Shuai Feng's avatar
Shuai Feng committed
237
238

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