test_spec1d.py 16.3 KB
Newer Older
Shuai Feng's avatar
Shuai Feng committed
1
2
import sys
import unittest
3
4
from csst_ifs_gehong import spec1d as s
from csst_ifs_gehong import config as c
Shuai Feng's avatar
Shuai Feng committed
5
6
7
8
import numpy as np
import matplotlib.pyplot as plt
import warnings
warnings.simplefilter("ignore", ResourceWarning)
Shuai Feng's avatar
Shuai Feng committed
9
10
sys.path.insert(0, '..')

Shuai Feng's avatar
Shuai Feng committed
11
12
13
14
15
16
17
18
19

class test_spec1d(unittest.TestCase):

    """
    Test modules in spec1d.py
    """

    def test_StellarPop(self):

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

        print("=================================================================")
        print("==================Stellar Population Modelling===================")
        print(" ")
        print(">>> Start Test")
        print(" ")

        temp = s.StellarContinuumTemplate(inst)

Shuai Feng's avatar
Shuai Feng committed
30
        plt.figure(figsize=(15, 12))
Shuai Feng's avatar
Shuai Feng committed
31
32
33

        print("------------------------Test Magnitude---------------------------")
        print("1. mr=15")
Shuai Feng's avatar
Shuai Feng committed
34
        sed1 = s.StellarContinuum(inst, temp, mag=15, age=1, feh=0, vel=100, vdisp=100, ebv=0)
Shuai Feng's avatar
Shuai Feng committed
35
        print("2. mr=13")
Shuai Feng's avatar
Shuai Feng committed
36
        sed2 = s.StellarContinuum(inst, temp, mag=13, age=1, feh=0, vel=100, vdisp=100, ebv=0)
Shuai Feng's avatar
Shuai Feng committed
37
38
39
        if np.sum(sed1.flux) != np.sum(sed2.flux):
            print("No Problem!")
            plt.subplot(231)
Shuai Feng's avatar
Shuai Feng committed
40
41
            plt.plot(sed1.wave, sed1.flux, color='blue', lw=2, label='mr = 15')
            plt.plot(sed2.wave, sed2.flux, color='red', lw=2, label='mr = 13')
Shuai Feng's avatar
Shuai Feng committed
42
43
            plt.legend(frameon=False)
            plt.xlim(3900, 6200)
Shuai Feng's avatar
Shuai Feng committed
44

Shuai Feng's avatar
Shuai Feng committed
45
46
        print("---------------------------Test  Age-----------------------------")
        print("1. Age=0.1Gyr")
Shuai Feng's avatar
Shuai Feng committed
47
        sed1 = s.StellarContinuum(inst, temp, mag=15, age=0.1, feh=0, vel=100, vdisp=100, ebv=0)
Shuai Feng's avatar
Shuai Feng committed
48
        print("2. Age=1Gyr")
Shuai Feng's avatar
Shuai Feng committed
49
        sed2 = s.StellarContinuum(inst, temp, mag=15, age=1, feh=0, vel=100, vdisp=100, ebv=0)
Shuai Feng's avatar
Shuai Feng committed
50
51
52
        if np.sum(sed1.flux) != np.sum(sed2.flux):
            print("No Problem!")
            plt.subplot(232)
Shuai Feng's avatar
Shuai Feng committed
53
54
            plt.plot(sed1.wave, sed1.flux, color='blue', lw=2, label='Age = 0.1Gyr')
            plt.plot(sed2.wave, sed2.flux, color='red', lw=2, label='Age = 1Gyr')
Shuai Feng's avatar
Shuai Feng committed
55
56
57
58
59
            plt.legend(frameon=False)
            plt.xlim(3900, 6200)

        print("-----------------------Test  Metallicity-------------------------")
        print("1. [Fe/H]=0.5")
Shuai Feng's avatar
Shuai Feng committed
60
        sed1 = s.StellarContinuum(inst, temp, mag=15, age=1, feh=0.5, vel=100, vdisp=100, ebv=0)
Shuai Feng's avatar
Shuai Feng committed
61
        print("2. [Fe/H]=-0.5")
Shuai Feng's avatar
Shuai Feng committed
62
        sed2 = s.StellarContinuum(inst, temp, mag=15, age=1, feh=-0.5, vel=100, vdisp=100, ebv=0)
Shuai Feng's avatar
Shuai Feng committed
63
64
65
        if np.sum(sed1.flux) != np.sum(sed2.flux):
            print("No Problem!")
            plt.subplot(233)
Shuai Feng's avatar
Shuai Feng committed
66
67
            plt.plot(sed1.wave, sed1.flux, color='blue', lw=2, label='[Fe/H] = 0.5')
            plt.plot(sed2.wave, sed2.flux, color='red', lw=2, label='[Fe/H] = -0.5')
Shuai Feng's avatar
Shuai Feng committed
68
69
            plt.legend(frameon=False)
            plt.xlim(3900, 6200)
Shuai Feng's avatar
Shuai Feng committed
70

Shuai Feng's avatar
Shuai Feng committed
71
72
        print("------------------------Test  Velocity---------------------------")
        print("1. v=3000km/s")
Shuai Feng's avatar
Shuai Feng committed
73
        sed1 = s.StellarContinuum(inst, temp, mag=15, age=1, feh=0, vel=3000, vdisp=100, ebv=0)
Shuai Feng's avatar
Shuai Feng committed
74
        print("2. v=6000km/s")
Shuai Feng's avatar
Shuai Feng committed
75
        sed2 = s.StellarContinuum(inst, temp, mag=15, age=1, feh=0, vel=6000, vdisp=100, ebv=0)
Shuai Feng's avatar
Shuai Feng committed
76
77
78
        if np.sum(sed1.flux) != np.sum(sed2.flux):
            print("No Problem!")
            plt.subplot(234)
Shuai Feng's avatar
Shuai Feng committed
79
80
            plt.plot(sed1.wave, sed1.flux, color='blue', lw=2, label='v = 3000km/s')
            plt.plot(sed2.wave, sed2.flux, color='red', lw=2, label='v = 6000km/s')
Shuai Feng's avatar
Shuai Feng committed
81
82
            plt.legend(frameon=False)
            plt.xlim(3900, 6200)
Shuai Feng's avatar
Shuai Feng committed
83

Shuai Feng's avatar
Shuai Feng committed
84
85
        print("-------------------Test Velocity Dispersion----------------------")
        print("1. sigma=180km/s")
Shuai Feng's avatar
Shuai Feng committed
86
        sed1 = s.StellarContinuum(inst, temp, mag=15, age=1, feh=0.5, vel=100, vdisp=180, ebv=0)
Shuai Feng's avatar
Shuai Feng committed
87
        print("2. sigma=350km/s")
Shuai Feng's avatar
Shuai Feng committed
88
        sed2 = s.StellarContinuum(inst, temp, mag=15, age=1, feh=0.5, vel=100, vdisp=350, ebv=0)
Shuai Feng's avatar
Shuai Feng committed
89
90
91
        if np.sum(sed1.flux) != np.sum(sed2.flux):
            print("No Problem!")
            plt.subplot(235)
Shuai Feng's avatar
Shuai Feng committed
92
93
            plt.plot(sed1.wave, sed1.flux, color='blue', lw=2, label='sigma = 180km/s')
            plt.plot(sed2.wave, sed2.flux, color='red', lw=2, label='sigma = 350km/s')
Shuai Feng's avatar
Shuai Feng committed
94
95
96
97
98
            plt.legend(frameon=False)
            plt.xlim(3900, 6200)

        print("----------------------Test Dust Extinction-----------------------")
        print("1. E(B-V)=0.1")
Shuai Feng's avatar
Shuai Feng committed
99
        sed1 = s.StellarContinuum(inst, temp, mag=15, age=1, feh=0.5, vel=100, vdisp=100, ebv=0.1)
Shuai Feng's avatar
Shuai Feng committed
100
        print("2. E(B-V)=0.3")
Shuai Feng's avatar
Shuai Feng committed
101
        sed2 = s.StellarContinuum(inst, temp, mag=15, age=1, feh=0.5, vel=100, vdisp=100, ebv=0.3)
Shuai Feng's avatar
Shuai Feng committed
102
103
104
        if np.sum(sed1.flux) != np.sum(sed2.flux):
            print("No Problem!")
            plt.subplot(236)
Shuai Feng's avatar
Shuai Feng committed
105
106
            plt.plot(sed1.wave, sed1.flux, color='blue', lw=2, label='E(B-V) = 0.1')
            plt.plot(sed2.wave, sed2.flux, color='red', lw=2, label='E(B-V) = 0.3')
Shuai Feng's avatar
Shuai Feng committed
107
108
109
110
            plt.legend(frameon=False)
            plt.xlim(3900, 6200)

        plt.tight_layout()
Shuai Feng's avatar
Shuai Feng committed
111
112
        # plt.savefig('./image/test_spec1d_stellarpopulation.png')

Shuai Feng's avatar
Shuai Feng committed
113
114
    def test_Star(self):

115
        inst = c.config()
Shuai Feng's avatar
Shuai Feng committed
116
117
118
119
120
121
122
123
124

        print("================================================================")
        print("=================Single Star Spectra Modelling===================")
        print(" ")
        print(">>> Start Test")
        print(" ")

        temp = s.SingleStarTemplate(inst)

Shuai Feng's avatar
Shuai Feng committed
125
        plt.figure(figsize=(15, 12))
Shuai Feng's avatar
Shuai Feng committed
126
127
128

        print("------------------------Test Magnitude---------------------------")
        print("1. mr=15")
Shuai Feng's avatar
Shuai Feng committed
129
        sed1 = s.SingleStar(inst, temp, mag=15, teff=10000, feh=0, vel=100, ebv=0)
Shuai Feng's avatar
Shuai Feng committed
130
        print("2. mr=13")
Shuai Feng's avatar
Shuai Feng committed
131
        sed2 = s.SingleStar(inst, temp, mag=13, teff=10000, feh=0, vel=100, ebv=0)
Shuai Feng's avatar
Shuai Feng committed
132
133
134
        if np.sum(sed1.flux) != np.sum(sed2.flux):
            print("No Problem!")
            plt.subplot(221)
Shuai Feng's avatar
Shuai Feng committed
135
136
            plt.plot(sed1.wave, sed1.flux, color='blue', lw=2, label='mr = 15')
            plt.plot(sed2.wave, sed2.flux, color='red', lw=2, label='mr = 13')
Shuai Feng's avatar
Shuai Feng committed
137
138
139
140
141
            plt.legend(frameon=False)
            plt.xlim(3900, 6200)

        print("------------------------Test Tempreture--------------------------")
        print("1. Teff=6000K")
Shuai Feng's avatar
Shuai Feng committed
142
        sed1 = s.SingleStar(inst, temp, mag=15, teff=6000, feh=0, vel=100, ebv=0)
Shuai Feng's avatar
Shuai Feng committed
143
        print("1. Teff=10000K")
Shuai Feng's avatar
Shuai Feng committed
144
        sed2 = s.SingleStar(inst, temp, mag=15, teff=10000, feh=0, vel=100, ebv=0)
Shuai Feng's avatar
Shuai Feng committed
145
146
147
        if np.sum(sed1.flux) != np.sum(sed2.flux):
            print("No Problem!")
            plt.subplot(222)
Shuai Feng's avatar
Shuai Feng committed
148
149
            plt.plot(sed1.wave, sed1.flux, color='blue', lw=2, label='Teff = 6000K')
            plt.plot(sed2.wave, sed2.flux, color='red', lw=2, label='Teff = 10000K')
Shuai Feng's avatar
Shuai Feng committed
150
151
152
153
154
            plt.legend(frameon=False)
            plt.xlim(3900, 6200)

        print("-----------------------Test Metallicity--------------------------")
        print("1. [Fe/H]=-0.5")
Shuai Feng's avatar
Shuai Feng committed
155
        sed1 = s.SingleStar(inst, temp, mag=15, teff=10000, feh=-0.5, vel=100, ebv=0)
Shuai Feng's avatar
Shuai Feng committed
156
        print("2. [Fe/H]=0.5")
Shuai Feng's avatar
Shuai Feng committed
157
        sed2 = s.SingleStar(inst, temp, mag=15, teff=10000, feh=0.5, vel=100, ebv=0)
Shuai Feng's avatar
Shuai Feng committed
158
159
160
        if np.sum(sed1.flux) != np.sum(sed2.flux):
            print("No Problem!")
            plt.subplot(223)
Shuai Feng's avatar
Shuai Feng committed
161
162
            plt.plot(sed1.wave, sed1.flux, color='blue', lw=2, label='[Fe/H] = -0.5')
            plt.plot(sed2.wave, sed2.flux, color='red', lw=2, label='[Fe/H] = 0.5')
Shuai Feng's avatar
Shuai Feng committed
163
164
165
166
167
            plt.legend(frameon=False)
            plt.xlim(3900, 6200)

        print("------------------------Test  Velocity---------------------------")
        print("1. v=-200km/s")
Shuai Feng's avatar
Shuai Feng committed
168
        sed1 = s.SingleStar(inst, temp, mag=15, teff=10000, feh=0, vel=-200, ebv=0)
Shuai Feng's avatar
Shuai Feng committed
169
        print("2. v=200km/s")
Shuai Feng's avatar
Shuai Feng committed
170
        sed2 = s.SingleStar(inst, temp, mag=15, teff=10000, feh=0, vel=200, ebv=0)
Shuai Feng's avatar
Shuai Feng committed
171
172
173
        if np.sum(sed1.flux) != np.sum(sed2.flux):
            print("No Problem!")
            plt.subplot(224)
Shuai Feng's avatar
Shuai Feng committed
174
175
            plt.plot(sed1.wave, sed1.flux, color='blue', lw=2, label='v = -200km/s')
            plt.plot(sed2.wave, sed2.flux, color='red', lw=2, label='v = 200km/s')
Shuai Feng's avatar
Shuai Feng committed
176
177
            plt.legend(frameon=False)
            plt.xlim(3900, 6200)
Shuai Feng's avatar
Shuai Feng committed
178

Shuai Feng's avatar
Shuai Feng committed
179
        plt.tight_layout()
Shuai Feng's avatar
Shuai Feng committed
180
        # plt.savefig('./image/test_spec1d_singlestar.png')
Shuai Feng's avatar
Shuai Feng committed
181
182
183
184
185
186

        print("-----------------------------------------------------------------")
        print(">>> Unit test for **Single Stellar** Modelling has been passed!")

    def test_Gas(self):

187
        inst = c.config()
Shuai Feng's avatar
Shuai Feng committed
188
189
190
191
192
193
194

        print("================================================================")
        print("======================Ionized Gas Modelling======================")
        print(" ")
        print(">>> Start Test")
        print(" ")

Shuai Feng's avatar
Shuai Feng committed
195
        temp = s.EmissionLineTemplate(inst, model='hii')
Shuai Feng's avatar
Shuai Feng committed
196

Shuai Feng's avatar
Shuai Feng committed
197
        plt.figure(figsize=(15, 12))
Shuai Feng's avatar
Shuai Feng committed
198
199
200
201

        print("---------------------Test Total Halpha Flux----------------------")

        print("1. F_Halpha = 10 * 1e-17 erg/s/cm^2")
Shuai Feng's avatar
Shuai Feng committed
202
        sed1 = s.HII_Region(inst, temp, halpha=10, logz=-1, vel=100, vdisp=120, ebv=0.1)
Shuai Feng's avatar
Shuai Feng committed
203
        print("2. F_Halpha = 50 * 1e-17 erg/s/cm^2")
Shuai Feng's avatar
Shuai Feng committed
204
        sed2 = s.HII_Region(inst, temp, halpha=50, logz=-1, vel=100, vdisp=120, ebv=0.1)
Shuai Feng's avatar
Shuai Feng committed
205
206
207
        if np.sum(sed1.flux) != np.sum(sed2.flux):
            print("No Problem!")
            plt.subplot(231)
Shuai Feng's avatar
Shuai Feng committed
208
209
            plt.plot(sed2.wave, sed2.flux, color='red', lw=2, label='Flux = 50')
            plt.plot(sed1.wave, sed1.flux, color='blue', lw=2, label='Flux = 10')
Shuai Feng's avatar
Shuai Feng committed
210
211
212
213
214
215
            plt.legend(frameon=False)
            plt.xlim(3900, 6200)

        print("-------------------Test Gas-Phase Metallicity--------------------")

        print("1. [Z/H] = 0")
Shuai Feng's avatar
Shuai Feng committed
216
        sed1 = s.HII_Region(inst, temp, halpha=10, logz=0, vel=100, vdisp=120, ebv=0.1)
Shuai Feng's avatar
Shuai Feng committed
217
        print("2. [Z/H] = -0.5")
Shuai Feng's avatar
Shuai Feng committed
218
        sed2 = s.HII_Region(inst, temp, halpha=10, logz=-0.5, vel=100, vdisp=120, ebv=0.1)
Shuai Feng's avatar
Shuai Feng committed
219
220
221
        if np.sum(sed1.flux) != np.sum(sed2.flux):
            print("No Problem!")
            plt.subplot(232)
Shuai Feng's avatar
Shuai Feng committed
222
223
            plt.plot(sed2.wave, sed2.flux, color='red', lw=2, label='[Z/H] = -0.5')
            plt.plot(sed1.wave, sed1.flux, color='blue', lw=2, label='[Z/H] = 0')
Shuai Feng's avatar
Shuai Feng committed
224
225
226
227
228
229
            plt.legend(frameon=False)
            plt.xlim(3900, 6200)

        print("-------------------------Test  Velocity--------------------------")

        print("1. v=3000km/s")
Shuai Feng's avatar
Shuai Feng committed
230
        sed1 = s.HII_Region(inst, temp, halpha=10, logz=-1, vel=3000, vdisp=120, ebv=0.1)
Shuai Feng's avatar
Shuai Feng committed
231
        print("2. v=6000km/s")
Shuai Feng's avatar
Shuai Feng committed
232
        sed2 = s.HII_Region(inst, temp, halpha=10, logz=-1, vel=6000, vdisp=120, ebv=0.1)
Shuai Feng's avatar
Shuai Feng committed
233
234
235
        if np.sum(sed1.flux) != np.sum(sed2.flux):
            print("No Problem!")
            plt.subplot(233)
Shuai Feng's avatar
Shuai Feng committed
236
237
            plt.plot(sed1.wave, sed1.flux, color='blue', lw=2, label='v = 3000km/s')
            plt.plot(sed2.wave, sed2.flux, color='red', lw=2, label='v = 6000km/s')
Shuai Feng's avatar
Shuai Feng committed
238
239
240
241
242
243
            plt.legend(frameon=False)
            plt.xlim(3900, 6200)

        print("--------------------Test Velocity Dispersion---------------------")

        print("1. sigma=500km/s")
Shuai Feng's avatar
Shuai Feng committed
244
        sed1 = s.HII_Region(inst, temp, halpha=10, logz=-1, vel=100, vdisp=500, ebv=0.1)
Shuai Feng's avatar
Shuai Feng committed
245
        print("2. sigma=100km/s")
Shuai Feng's avatar
Shuai Feng committed
246
        sed2 = s.HII_Region(inst, temp, halpha=10, logz=-1, vel=100, vdisp=100, ebv=0.1)
Shuai Feng's avatar
Shuai Feng committed
247
248
249
        if np.sum(sed1.flux) != np.sum(sed2.flux):
            print("No Problem!")
            plt.subplot(234)
Shuai Feng's avatar
Shuai Feng committed
250
251
            plt.plot(sed1.wave, sed1.flux, color='blue', lw=2, label='sigma = 500km/s')
            plt.plot(sed2.wave, sed2.flux, color='red', lw=2, label='sigma = 100km/s')
Shuai Feng's avatar
Shuai Feng committed
252
253
254
255
256
257
            plt.legend(frameon=False)
            plt.xlim(3900, 6200)

        print("----------------------Test Dust Extinction-----------------------")

        print("1. E(B-V)=0.1")
Shuai Feng's avatar
Shuai Feng committed
258
        sed1 = s.HII_Region(inst, temp, halpha=10, logz=-1, vel=100, vdisp=120, ebv=0.1)
Shuai Feng's avatar
Shuai Feng committed
259
        print("2. E(B-V)=0.3")
Shuai Feng's avatar
Shuai Feng committed
260
        sed1 = s.HII_Region(inst, temp, halpha=10, logz=-1, vel=100, vdisp=120, ebv=0.3)
Shuai Feng's avatar
Shuai Feng committed
261
262
263
        if np.sum(sed1.flux) != np.sum(sed2.flux):
            print("No Problem!")
            plt.subplot(235)
Shuai Feng's avatar
Shuai Feng committed
264
265
            plt.plot(sed1.wave, sed1.flux, color='blue', lw=2, label='E(B-V) = 0.1')
            plt.plot(sed2.wave, sed2.flux, color='red', lw=2, label='E(B-V) = 0.3')
Shuai Feng's avatar
Shuai Feng committed
266
267
268
269
            plt.legend(frameon=False)
            plt.xlim(3900, 6200)

        plt.tight_layout()
Shuai Feng's avatar
Shuai Feng committed
270
        # plt.savefig('./image/test_spec1d_ionizedgas.png')
Shuai Feng's avatar
Shuai Feng committed
271
272
273
274
275
276

        print("-----------------------------------------------------------------")
        print(">>> Unit test for **Ionized Gas** Modelling has been passed!")

    def test_AGN(self):

277
        inst = c.config()
Shuai Feng's avatar
Shuai Feng committed
278
279
280
281
282
283
284

        print("================================================================")
        print("=====================AGN Spectra Modelling======================")
        print(" ")
        print(">>> Start Test")
        print(" ")

Shuai Feng's avatar
Shuai Feng committed
285
        temp = s.EmissionLineTemplate(inst, model='nlr')
Shuai Feng's avatar
Shuai Feng committed
286

Shuai Feng's avatar
Shuai Feng committed
287
        plt.figure(figsize=(15, 12))
Shuai Feng's avatar
Shuai Feng committed
288
289
290
291

        print("-------------------------Test  Redshift--------------------------")

        print("1. z=0.2")
Shuai Feng's avatar
Shuai Feng committed
292
293
294
        sed1 = s.AGN(inst, temp, bhmass=1e5, edd_ratio=0.05,
                     halpha_broad=100, halpha_narrow=100, vdisp_broad=2000, vdisp_narrow=500,
                     vel=20000, logz=0, ebv=0.1, dist=20)
Shuai Feng's avatar
Shuai Feng committed
295
        print("2. z=0.4")
Shuai Feng's avatar
Shuai Feng committed
296
297
298
        sed2 = s.AGN(inst, temp, bhmass=1e5, edd_ratio=0.05,
                     halpha_broad=100, halpha_narrow=100, vdisp_broad=2000, vdisp_narrow=500,
                     vel=40000, logz=0, ebv=0.1, dist=20)
Shuai Feng's avatar
Shuai Feng committed
299
300
301
        if np.sum(sed1.flux) != np.sum(sed2.flux):
            print("No Problem!")
            plt.subplot(221)
Shuai Feng's avatar
Shuai Feng committed
302
303
            plt.plot(sed1.wave, sed1.flux, color='blue', lw=2, label='z = 0.2')
            plt.plot(sed2.wave, sed2.flux, color='red', lw=2, label='z = 0.4')
Shuai Feng's avatar
Shuai Feng committed
304
305
            plt.legend(frameon=False)
            plt.xlim(3900, 6200)
Shuai Feng's avatar
Shuai Feng committed
306

Shuai Feng's avatar
Shuai Feng committed
307
308
309
        print("----------------------Test Black Hole Mass-----------------------")

        print("1. Mbh=1e6")
Shuai Feng's avatar
Shuai Feng committed
310
311
312
        sed1 = s.AGN(inst, temp, bhmass=1e6, edd_ratio=0.05,
                     halpha_broad=100, halpha_narrow=100, vdisp_broad=2000, vdisp_narrow=500,
                     vel=20000, logz=0, ebv=0.1, dist=20)
Shuai Feng's avatar
Shuai Feng committed
313
        print("2. Mbh=5e6")
Shuai Feng's avatar
Shuai Feng committed
314
315
316
        sed2 = s.AGN(inst, temp, bhmass=5e6, edd_ratio=0.05,
                     halpha_broad=100, halpha_narrow=100, vdisp_broad=2000, vdisp_narrow=500,
                     vel=20000, logz=0, ebv=0.1, dist=20)
Shuai Feng's avatar
Shuai Feng committed
317
318
319
        if np.sum(sed1.flux) != np.sum(sed2.flux):
            print("No Problem!")
            plt.subplot(222)
Shuai Feng's avatar
Shuai Feng committed
320
321
            plt.plot(sed1.wave, sed1.flux, color='blue', lw=2, label='Mbh = 1e6')
            plt.plot(sed2.wave, sed2.flux, color='red', lw=2, label='Mbh = 5e6')
Shuai Feng's avatar
Shuai Feng committed
322
323
324
325
326
327
            plt.legend(frameon=False)
            plt.xlim(3900, 6200)

        print("------------------------Eddington  Ratio-------------------------")

        print("1. Edd Ratio = 1.0")
Shuai Feng's avatar
Shuai Feng committed
328
329
330
        sed1 = s.AGN(inst, temp, bhmass=1e5, edd_ratio=1.0,
                     halpha_broad=100, halpha_narrow=100, vdisp_broad=2000, vdisp_narrow=500,
                     vel=20000, logz=0, ebv=0.1, dist=20)
Shuai Feng's avatar
Shuai Feng committed
331
        print("2. Edd Ratio = 0.1")
Shuai Feng's avatar
Shuai Feng committed
332
333
334
        sed2 = s.AGN(inst, temp, bhmass=1e5, edd_ratio=0.1,
                     halpha_broad=100, halpha_narrow=100, vdisp_broad=2000, vdisp_narrow=500,
                     vel=20000, logz=0, ebv=0.1, dist=20)
Shuai Feng's avatar
Shuai Feng committed
335
336
337
        if np.sum(sed1.flux) != np.sum(sed2.flux):
            print("No Problem!")
            plt.subplot(223)
Shuai Feng's avatar
Shuai Feng committed
338
339
            plt.plot(sed1.wave, sed1.flux, color='blue', lw=2, label='EddRatio = 1.0')
            plt.plot(sed2.wave, sed2.flux, color='red', lw=2, label='EddRatio = 0.1')
Shuai Feng's avatar
Shuai Feng committed
340
341
342
343
344
345
            plt.legend(frameon=False)
            plt.xlim(3900, 6200)

        print("----------------------Test Dust Extinction-----------------------")

        print("1. E(B-V)=0.1")
Shuai Feng's avatar
Shuai Feng committed
346
347
348
        sed1 = s.AGN(inst, temp, bhmass=1e5, edd_ratio=0.05,
                     halpha_broad=100, halpha_narrow=100, vdisp_broad=2000, vdisp_narrow=500,
                     vel=20000, logz=0, ebv=0.1, dist=20)
Shuai Feng's avatar
Shuai Feng committed
349
        print("2. E(B-V)=0.3")
Shuai Feng's avatar
Shuai Feng committed
350
351
352
        sed2 = s.AGN(inst, temp, bhmass=1e5, edd_ratio=0.05,
                     halpha_broad=100, halpha_narrow=100, vdisp_broad=2000, vdisp_narrow=500,
                     vel=20000, logz=0, ebv=0.3, dist=20)
Shuai Feng's avatar
Shuai Feng committed
353
354
355
        if np.sum(sed1.flux) != np.sum(sed2.flux):
            print("No Problem!")
            plt.subplot(224)
Shuai Feng's avatar
Shuai Feng committed
356
357
            plt.plot(sed1.wave, sed1.flux, color='blue', lw=2, label='E(B-V) = 0.1')
            plt.plot(sed2.wave, sed2.flux, color='red', lw=2, label='E(B-V) = 0.3')
Shuai Feng's avatar
Shuai Feng committed
358
359
360
361
            plt.legend(frameon=False)
            plt.xlim(3900, 6200)

        plt.tight_layout()
Shuai Feng's avatar
Shuai Feng committed
362
        # plt.savefig('./image/test_spec1d_agn.png')
Shuai Feng's avatar
Shuai Feng committed
363
364
365
366

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

Shuai Feng's avatar
Shuai Feng committed
367
368

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