Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
csst-sims
csst_ifs_gehong
Commits
7c2ce85a
Commit
7c2ce85a
authored
Oct 26, 2024
by
Shuai Feng
Browse files
fix PEP8 bugs
parent
1128112c
Pipeline
#7131
failed with stage
in 0 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
csst_ifs_gehong/config.py
View file @
7c2ce85a
...
@@ -22,13 +22,12 @@ class config():
...
@@ -22,13 +22,12 @@ class config():
dpix : float, optional
dpix : float, optional
Pixel size in the spatial direction, by default 0.2arcsec
Pixel size in the spatial direction, by default 0.2arcsec
"""
"""
def
__init__
(
self
,
wave_min
=
3500.0
,
wave_max
=
10000.0
,
def
__init__
(
self
,
wave_min
=
3500.0
,
wave_max
=
10000.0
,
dlam
=
2.0
,
inst_fwhm
=
0.1
,
dlam
=
2.0
,
inst_fwhm
=
0.1
,
nx
=
30
,
ny
=
30
,
dpix
=
0.2
):
nx
=
30
,
ny
=
30
,
dpix
=
0.2
):
self
.
dlam
=
dlam
self
.
dlam
=
dlam
self
.
wave
=
np
.
arange
(
wave_min
,
wave_max
,
dlam
)
self
.
wave
=
np
.
arange
(
wave_min
,
wave_max
,
dlam
)
self
.
wave_min
=
wave_min
self
.
wave_min
=
wave_min
self
.
inst_fwhm
=
inst_fwhm
self
.
inst_fwhm
=
inst_fwhm
self
.
nx
=
nx
self
.
nx
=
nx
self
.
ny
=
ny
self
.
ny
=
ny
...
...
csst_ifs_gehong/cube3d.py
View file @
7c2ce85a
...
@@ -9,86 +9,78 @@ class Cube3D():
...
@@ -9,86 +9,78 @@ class Cube3D():
Class of 3-dimentional spectral cube
Class of 3-dimentional spectral cube
"""
"""
def
__init__
(
self
,
config
,
stellar_map
=
None
,
gas_map
=
None
):
def
__init__
(
self
,
config
,
stellar_map
=
None
,
gas_map
=
None
):
self
.
config
=
config
self
.
config
=
config
self
.
nx
=
config
.
nx
self
.
nx
=
config
.
nx
self
.
ny
=
config
.
ny
self
.
ny
=
config
.
ny
self
.
dpix
=
config
.
dpix
self
.
dpix
=
config
.
dpix
self
.
fov_x
=
config
.
fov_x
self
.
fov_x
=
config
.
fov_x
self
.
fov_y
=
config
.
fov_y
self
.
fov_y
=
config
.
fov_y
self
.
wave
=
config
.
wave
self
.
wave
=
config
.
wave
self
.
nz
=
len
(
self
.
wave
)
self
.
nz
=
len
(
self
.
wave
)
self
.
wave0
=
np
.
min
(
self
.
wave
)
self
.
wave0
=
np
.
min
(
self
.
wave
)
self
.
inst_fwhm
=
config
.
inst_fwhm
self
.
inst_fwhm
=
config
.
inst_fwhm
self
.
flux
=
np
.
zeros
((
self
.
nx
,
self
.
ny
,
self
.
nz
))
self
.
flux
=
np
.
zeros
((
self
.
nx
,
self
.
ny
,
self
.
nz
))
self
.
stellar_map
=
stellar_map
self
.
stellar_map
=
stellar_map
self
.
gas_map
=
gas_map
self
.
gas_map
=
gas_map
def
make_cube
(
self
,
stellar_tem
=
None
,
hii_tem
=
None
):
def
make_cube
(
self
,
stellar_tem
=
None
,
hii_tem
=
None
):
for
i
in
range
(
self
.
nx
):
for
i
in
range
(
self
.
nx
):
for
j
in
range
(
self
.
ny
):
for
j
in
range
(
self
.
ny
):
if
self
.
stellar_map
is
not
None
:
if
self
.
stellar_map
is
not
None
:
ss
=
StellarContinuum
(
self
.
config
,
stellar_tem
,
mag
=
self
.
stellar_map
.
mag
[
i
,
j
],
ss
=
StellarContinuum
(
self
.
config
,
stellar_tem
,
mag
=
self
.
stellar_map
.
mag
[
i
,
j
],
age
=
self
.
stellar_map
.
age
[
i
,
j
],
feh
=
self
.
stellar_map
.
feh
[
i
,
j
],
age
=
self
.
stellar_map
.
age
[
i
,
j
],
feh
=
self
.
stellar_map
.
feh
[
i
,
j
],
vel
=
self
.
stellar_map
.
vel
[
i
,
j
],
vdisp
=
self
.
stellar_map
.
vdisp
[
i
,
j
],
vel
=
self
.
stellar_map
.
vel
[
i
,
j
],
vdisp
=
self
.
stellar_map
.
vdisp
[
i
,
j
],
ebv
=
self
.
stellar_map
.
ebv
[
i
,
j
])
ebv
=
self
.
stellar_map
.
ebv
[
i
,
j
])
if
self
.
gas_map
is
not
None
:
if
self
.
gas_map
is
not
None
:
gg
=
HII_Region
(
self
.
config
,
hii_tem
,
halpha
=
self
.
gas_map
.
halpha
[
i
,
j
],
gg
=
HII_Region
(
self
.
config
,
hii_tem
,
halpha
=
self
.
gas_map
.
halpha
[
i
,
j
],
logz
=
self
.
gas_map
.
zh
[
i
,
j
],
vel
=
self
.
gas_map
.
vel
[
i
,
j
],
logz
=
self
.
gas_map
.
zh
[
i
,
j
],
vel
=
self
.
gas_map
.
vel
[
i
,
j
],
vdisp
=
self
.
gas_map
.
vdisp
[
i
,
j
],
ebv
=
self
.
gas_map
.
ebv
[
i
,
j
])
vdisp
=
self
.
gas_map
.
vdisp
[
i
,
j
],
ebv
=
self
.
gas_map
.
ebv
[
i
,
j
])
self
.
flux
[
i
,
j
,
:]
=
ss
.
flux
+
gg
.
flux
self
.
flux
[
i
,
j
,
:]
=
ss
.
flux
+
gg
.
flux
else
:
else
:
self
.
flux
[
i
,
j
,
:]
=
ss
.
flux
self
.
flux
[
i
,
j
,
:]
=
ss
.
flux
def
wcs_info
(
self
):
def
wcs_info
(
self
):
# wcs = fits.Header()
# wcs = fits.Header()
wcs_dict
=
{
'CTYPE1'
:
'WAVE '
,
wcs_dict
=
{
'CTYPE1'
:
'WAVE '
,
'CUNIT1'
:
'Angstrom'
,
'CUNIT1'
:
'Angstrom'
,
'CDELT1'
:
self
.
config
.
dlam
,
'CDELT1'
:
self
.
config
.
dlam
,
'CRPIX1'
:
1
,
'CRPIX1'
:
1
,
'CRVAL1'
:
np
.
min
(
self
.
wave
),
'CRVAL1'
:
np
.
min
(
self
.
wave
),
'CTYPE2'
:
'RA---TAN'
,
'CTYPE2'
:
'RA---TAN'
,
'CUNIT2'
:
'deg'
,
'CUNIT2'
:
'deg'
,
'CDELT2'
:
self
.
dpix
/
3600.
,
'CDELT2'
:
self
.
dpix
/
3600.
,
'CRPIX2'
:
np
.
round
(
self
.
ny
/
2.
),
'CRPIX2'
:
np
.
round
(
self
.
ny
/
2.
),
'CRVAL2'
:
0.5
,
'CRVAL2'
:
0.5
,
'CTYPE3'
:
'DEC--TAN'
,
'CTYPE3'
:
'DEC--TAN'
,
'CUNIT3'
:
'deg'
,
'CUNIT3'
:
'deg'
,
'CDELT3'
:
self
.
dpix
/
3600.
,
'CDELT3'
:
self
.
dpix
/
3600.
,
'CRPIX3'
:
np
.
round
(
self
.
nx
/
2.
),
'CRPIX3'
:
np
.
round
(
self
.
nx
/
2.
),
'CRVAL3'
:
1
,
'CRVAL3'
:
1
,
'BUNIT'
:
'10**(-17)*erg/s/cm**2/Angstrom'
}
'BUNIT'
:
'10**(-17)*erg/s/cm**2/Angstrom'
}
input_wcs
=
astropy
.
wcs
.
WCS
(
wcs_dict
)
input_wcs
=
astropy
.
wcs
.
WCS
(
wcs_dict
)
self
.
wcs_header
=
input_wcs
.
to_header
()
self
.
wcs_header
=
input_wcs
.
to_header
()
def
insert_spec
(
self
,
spec
,
dx
=
0
,
dy
=
0
):
def
insert_spec
(
self
,
spec
,
dx
=
0
,
dy
=
0
):
x0
=
np
.
int
(
np
.
round
(
self
.
config
.
nx
/
2.
))
x0
=
np
.
int
(
np
.
round
(
self
.
config
.
nx
/
2.
))
y0
=
np
.
int
(
np
.
round
(
self
.
config
.
ny
/
2.
))
y0
=
np
.
int
(
np
.
round
(
self
.
config
.
ny
/
2.
))
self
.
flux
[
x0
+
dx
,
y0
+
dy
,
:]
=
self
.
flux
[
x0
+
dx
,
y0
+
dy
,
:]
+
spec
.
flux
self
.
flux
[
x0
+
dx
,
y0
+
dy
,
:]
=
self
.
flux
[
x0
+
dx
,
y0
+
dy
,
:]
+
spec
.
flux
def
savefits
(
self
,
filename
,
path
=
'./'
):
def
savefits
(
self
,
filename
,
path
=
'./'
):
hdr
=
fits
.
Header
()
hdr
=
fits
.
Header
()
hdr
[
'FILETYPE'
]
=
'SCICUBE'
hdr
[
'FILETYPE'
]
=
'SCICUBE'
hdr
[
'CODE'
]
=
'CSST-IFS-GEHONG'
hdr
[
'CODE'
]
=
'CSST-IFS-GEHONG'
hdr
[
'VERSION'
]
=
'0.0.1'
hdr
[
'VERSION'
]
=
'0.0.1'
hdr
[
'OBJECT'
]
=
'NGC1234'
hdr
[
'OBJECT'
]
=
'NGC1234'
hdr
[
'RA'
]
=
0.0
hdr
[
'RA'
]
=
0.0
hdr
[
'DEC'
]
=
0.0
hdr
[
'DEC'
]
=
0.0
hdu0
=
fits
.
PrimaryHDU
(
header
=
hdr
)
hdu0
=
fits
.
PrimaryHDU
(
header
=
hdr
)
self
.
wcs_info
()
self
.
wcs_info
()
hdr
=
self
.
wcs_header
hdr
=
self
.
wcs_header
hdu1
=
fits
.
ImageHDU
(
self
.
flux
,
header
=
hdr
)
hdu1
=
fits
.
ImageHDU
(
self
.
flux
,
header
=
hdr
)
# Output
# Output
hdulist
=
fits
.
HDUList
([
hdu0
,
hdu1
])
hdulist
=
fits
.
HDUList
([
hdu0
,
hdu1
])
hdulist
.
writeto
(
path
+
filename
,
overwrite
=
True
)
hdulist
.
writeto
(
path
+
filename
,
overwrite
=
True
)
\ No newline at end of file
csst_ifs_gehong/map2d.py
View file @
7c2ce85a
...
@@ -49,23 +49,23 @@ def Sersic2D(x, y, mag=12.0, r_eff=1.0, n=2.0, ellip=0.5,
...
@@ -49,23 +49,23 @@ def Sersic2D(x, y, mag=12.0, r_eff=1.0, n=2.0, ellip=0.5,
x_min
=
-
(
x
-
x_0
)
*
sin_theta
+
(
y
-
y_0
)
*
cos_theta
x_min
=
-
(
x
-
x_0
)
*
sin_theta
+
(
y
-
y_0
)
*
cos_theta
z
=
(
abs
(
x_maj
/
a
)
**
2
+
abs
(
x_min
/
b
)
**
2
)
**
(
1
/
2
)
z
=
(
abs
(
x_maj
/
a
)
**
2
+
abs
(
x_min
/
b
)
**
2
)
**
(
1
/
2
)
profile
=
np
.
exp
(
-
bn
*
(
z
**
(
1
/
n
)
-
1
))
profile
=
np
.
exp
(
-
bn
*
(
z
**
(
1
/
n
)
-
1
))
# Normalization
# Normalization
integral
=
a
*
b
*
2
*
np
.
pi
*
n
*
np
.
exp
(
bn
)
/
(
bn
**
(
2
*
n
))
*
sp
.
gamma
(
2
*
n
)
integral
=
a
*
b
*
2
*
np
.
pi
*
n
*
np
.
exp
(
bn
)
/
(
bn
**
(
2
*
n
))
*
sp
.
gamma
(
2
*
n
)
prof_norm
=
profile
/
integral
*
pixelscale
prof_norm
=
profile
/
integral
*
pixelscale
# Calibration
# Calibration
total_flux
=
10.
**
((
22.5
-
mag
)
*
0.4
)
total_flux
=
10.
**
((
22.5
-
mag
)
*
0.4
)
sb_mag
=
22.5
-
2.5
*
np
.
log10
(
prof_norm
*
total_flux
/
pixelscale
)
sb_mag
=
22.5
-
2.5
*
np
.
log10
(
prof_norm
*
total_flux
/
pixelscale
)
return
sb_mag
return
sb_mag
def
VelMap2D
(
x
,
y
,
vmax
=
200.0
,
rt
=
1.0
,
ellip
=
0.5
,
def
VelMap2D
(
x
,
y
,
vmax
=
200.0
,
rt
=
1.0
,
ellip
=
0.5
,
theta
=
0.0
,
x_0
=
0.0
,
y_0
=
0.0
):
theta
=
0.0
,
x_0
=
0.0
,
y_0
=
0.0
):
"""
"""
VelMap2D: Caculate the velocity at given spatial position base on the rotating disk model.
VelMap2D: Caculate the velocity at given spatial position base on the rotating disk model.
The rotation curve is adpot as the tanh model.
The rotation curve is adpot as the tanh model.
Parameters
Parameters
----------
----------
...
@@ -102,15 +102,15 @@ def VelMap2D(x, y, vmax=200.0, rt=1.0, ellip=0.5,
...
@@ -102,15 +102,15 @@ def VelMap2D(x, y, vmax=200.0, rt=1.0, ellip=0.5,
x_min
=
-
(
x
-
x_0
)
*
sin_theta
+
(
y
-
y_0
)
*
cos_theta
x_min
=
-
(
x
-
x_0
)
*
sin_theta
+
(
y
-
y_0
)
*
cos_theta
z
=
(
abs
(
x_maj
/
a
)
**
2
+
abs
(
x_min
/
b
)
**
2
)
**
(
1
/
2
)
z
=
(
abs
(
x_maj
/
a
)
**
2
+
abs
(
x_min
/
b
)
**
2
)
**
(
1
/
2
)
profile
=
vmax
*
np
.
tanh
(
z
)
*
((
x_maj
/
a
)
/
z
)
profile
=
vmax
*
np
.
tanh
(
z
)
*
((
x_maj
/
a
)
/
z
)
return
profile
return
profile
def
GradMap2D
(
x
,
y
,
a0
=
10.0
,
r_eff
=
1.0
,
gred
=-
1.0
,
ellip
=
0.5
,
def
GradMap2D
(
x
,
y
,
a0
=
10.0
,
r_eff
=
1.0
,
gred
=-
1.0
,
ellip
=
0.5
,
theta
=
0.0
,
x_0
=
0.0
,
y_0
=
0.0
):
theta
=
0.0
,
x_0
=
0.0
,
y_0
=
0.0
):
"""
"""
GradMap2D: Caculate the intensity at given spatial position base on the disk model.
GradMap2D: Caculate the intensity at given spatial position base on the disk model.
The radial profile is adpot as the gradient model.
The radial profile is adpot as the gradient model.
Parameters
Parameters
----------
----------
...
@@ -149,7 +149,7 @@ def GradMap2D(x, y, a0=10.0, r_eff=1.0, gred=-1.0, ellip=0.5,
...
@@ -149,7 +149,7 @@ def GradMap2D(x, y, a0=10.0, r_eff=1.0, gred=-1.0, ellip=0.5,
x_min
=
-
(
x
-
x_0
)
*
sin_theta
+
(
y
-
y_0
)
*
cos_theta
x_min
=
-
(
x
-
x_0
)
*
sin_theta
+
(
y
-
y_0
)
*
cos_theta
z
=
(
abs
(
x_maj
/
a
)
**
2
+
abs
(
x_min
/
b
)
**
2
)
**
(
1
/
2
)
z
=
(
abs
(
x_maj
/
a
)
**
2
+
abs
(
x_min
/
b
)
**
2
)
**
(
1
/
2
)
profile
=
a0
+
z
*
gred
profile
=
a0
+
z
*
gred
return
profile
return
profile
...
@@ -207,7 +207,7 @@ class Map2d(object):
...
@@ -207,7 +207,7 @@ class Map2d(object):
xsh_rot
=
xsh
*
np
.
cos
(
pa_radians
)
+
ysh
*
np
.
sin
(
pa_radians
)
xsh_rot
=
xsh
*
np
.
cos
(
pa_radians
)
+
ysh
*
np
.
sin
(
pa_radians
)
ysh_rot
=
-
xsh
*
np
.
sin
(
pa_radians
)
+
ysh
*
np
.
cos
(
pa_radians
)
ysh_rot
=
-
xsh
*
np
.
sin
(
pa_radians
)
+
ysh
*
np
.
cos
(
pa_radians
)
return
ysh_rot
,
xsh_rot
return
ysh_rot
,
xsh_rot
def
sersic_map
(
self
,
mag
=
12.0
,
r_eff
=
2.0
,
n
=
2.5
,
ellip
=
0.5
,
theta
=-
50.0
):
def
sersic_map
(
self
,
mag
=
12.0
,
r_eff
=
2.0
,
n
=
2.5
,
ellip
=
0.5
,
theta
=-
50.0
):
"""
"""
Generate 2D map of Sersic model
Generate 2D map of Sersic model
...
@@ -246,11 +246,11 @@ class Map2d(object):
...
@@ -246,11 +246,11 @@ class Map2d(object):
self
.
n
=
n
self
.
n
=
n
self
.
ellip
=
ellip
self
.
ellip
=
ellip
self
.
theta
=
theta
self
.
theta
=
theta
self
.
map
=
Sersic2D
(
self
.
x
,
self
.
y
,
mag
=
self
.
mag
,
self
.
map
=
Sersic2D
(
self
.
x
,
self
.
y
,
mag
=
self
.
mag
,
r_eff
=
self
.
reff
,
n
=
self
.
n
,
r_eff
=
self
.
reff
,
n
=
self
.
n
,
ellip
=
self
.
ellip
,
theta
=
self
.
theta
,
ellip
=
self
.
ellip
,
theta
=
self
.
theta
,
pixelscale
=
self
.
xsamp
*
self
.
ysamp
)
pixelscale
=
self
.
xsamp
*
self
.
ysamp
)
def
tanh_map
(
self
,
vmax
=
200.0
,
rt
=
2.0
,
ellip
=
0.5
,
theta
=-
50.0
):
def
tanh_map
(
self
,
vmax
=
200.0
,
rt
=
2.0
,
ellip
=
0.5
,
theta
=-
50.0
):
"""
"""
Generate 2D velocity map of rotating disk according to tanh rotation curve
Generate 2D velocity map of rotating disk according to tanh rotation curve
...
@@ -284,9 +284,9 @@ class Map2d(object):
...
@@ -284,9 +284,9 @@ class Map2d(object):
self
.
rt
=
rt
/
self
.
xsamp
self
.
rt
=
rt
/
self
.
xsamp
self
.
ellip
=
ellip
self
.
ellip
=
ellip
self
.
theta
=
theta
self
.
theta
=
theta
self
.
map
=
VelMap2D
(
self
.
x
,
self
.
y
,
vmax
=
self
.
vmax
,
rt
=
self
.
rt
,
self
.
map
=
VelMap2D
(
self
.
x
,
self
.
y
,
vmax
=
self
.
vmax
,
rt
=
self
.
rt
,
ellip
=
self
.
ellip
,
theta
=
self
.
theta
)
ellip
=
self
.
ellip
,
theta
=
self
.
theta
)
def
gred_map
(
self
,
a0
=
10
,
r_eff
=
1
,
gred
=-
1
,
ellip
=
0.5
,
theta
=
0
):
def
gred_map
(
self
,
a0
=
10
,
r_eff
=
1
,
gred
=-
1
,
ellip
=
0.5
,
theta
=
0
):
"""
"""
Generate 2D maps according to the radial gradient form
Generate 2D maps according to the radial gradient form
...
@@ -319,9 +319,9 @@ class Map2d(object):
...
@@ -319,9 +319,9 @@ class Map2d(object):
self
.
gred
=
gred
self
.
gred
=
gred
self
.
ellip
=
ellip
self
.
ellip
=
ellip
self
.
theta
=
theta
self
.
theta
=
theta
self
.
map
=
GradMap2D
(
self
.
x
,
self
.
y
,
a0
=
self
.
a0
,
r_eff
=
self
.
reff
,
self
.
map
=
GradMap2D
(
self
.
x
,
self
.
y
,
a0
=
self
.
a0
,
r_eff
=
self
.
reff
,
gred
=
self
.
gred
,
ellip
=
self
.
ellip
,
theta
=
self
.
theta
)
gred
=
self
.
gred
,
ellip
=
self
.
ellip
,
theta
=
self
.
theta
)
def
load_map
(
self
,
image
):
def
load_map
(
self
,
image
):
"""
"""
Generate 2D map according to input image
Generate 2D map according to input image
...
@@ -339,10 +339,10 @@ class Map2d(object):
...
@@ -339,10 +339,10 @@ class Map2d(object):
class
StellarPopulationMap
():
class
StellarPopulationMap
():
"""
"""
Class of 2D maps for the parameters of stellar population, such as
Class of 2D maps for the parameters of stellar population, such as
surface brightness, median age and metallicity of stellar population,
surface brightness, median age and metallicity of stellar population,
velocity and velocity dispersion maps, and dust extinction.
velocity and velocity dispersion maps, and dust extinction.
Parameters
Parameters
----------
----------
config : class
config : class
...
@@ -360,7 +360,7 @@ class StellarPopulationMap():
...
@@ -360,7 +360,7 @@ class StellarPopulationMap():
ebv : class, optional
ebv : class, optional
Class of the map of dust extinction, by default None
Class of the map of dust extinction, by default None
"""
"""
def
__init__
(
self
,
config
,
sbright
=
None
,
logage
=
None
,
def
__init__
(
self
,
config
,
sbright
=
None
,
logage
=
None
,
feh
=
None
,
vel
=
None
,
vdisp
=
None
,
ebv
=
None
):
feh
=
None
,
vel
=
None
,
vdisp
=
None
,
ebv
=
None
):
self
.
nx
=
config
.
nx
self
.
nx
=
config
.
nx
...
@@ -368,29 +368,29 @@ class StellarPopulationMap():
...
@@ -368,29 +368,29 @@ class StellarPopulationMap():
self
.
dpix
=
config
.
dpix
self
.
dpix
=
config
.
dpix
self
.
fov_x
=
config
.
fov_x
self
.
fov_x
=
config
.
fov_x
self
.
fov_y
=
config
.
fov_y
self
.
fov_y
=
config
.
fov_y
if
(
sbright
is
None
):
if
(
sbright
is
None
):
print
(
'Input SurfaceBrightness Map is empty!'
)
print
(
'Input SurfaceBrightness Map is empty!'
)
else
:
else
:
self
.
sbright
=
sbright
.
map
self
.
sbright
=
sbright
.
map
self
.
mag
=
self
.
sbright
-
2.5
*
np
.
log10
(
self
.
dpix
*
self
.
dpix
)
self
.
mag
=
self
.
sbright
-
2.5
*
np
.
log10
(
self
.
dpix
*
self
.
dpix
)
if
(
logage
is
None
):
if
(
logage
is
None
):
print
(
'Input Age Map is empty!'
)
print
(
'Input Age Map is empty!'
)
else
:
else
:
self
.
logage
=
logage
.
map
self
.
logage
=
logage
.
map
self
.
age
=
10
**
self
.
logage
/
1e9
self
.
age
=
10
**
self
.
logage
/
1e9
if
(
feh
is
None
):
if
(
feh
is
None
):
print
(
'Input Metallicity Map is empty!'
)
print
(
'Input Metallicity Map is empty!'
)
else
:
else
:
self
.
feh
=
feh
.
map
self
.
feh
=
feh
.
map
if
(
vel
is
None
):
if
(
vel
is
None
):
print
(
'Input Velocity Map is empty!'
)
print
(
'Input Velocity Map is empty!'
)
else
:
else
:
self
.
vel
=
vel
.
map
self
.
vel
=
vel
.
map
if
(
vdisp
is
None
):
if
(
vdisp
is
None
):
print
(
'Input VelocityDispersion Map is empty!'
)
print
(
'Input VelocityDispersion Map is empty!'
)
else
:
else
:
...
@@ -399,7 +399,7 @@ class StellarPopulationMap():
...
@@ -399,7 +399,7 @@ class StellarPopulationMap():
if
len
(
self
.
vdisp
[
ind_overrange
])
>
0
:
if
len
(
self
.
vdisp
[
ind_overrange
])
>
0
:
print
(
"Notice: Spaxel with <10km/s in the input vdisp map will be automatically adjusted to 10km/s."
)
print
(
"Notice: Spaxel with <10km/s in the input vdisp map will be automatically adjusted to 10km/s."
)
self
.
vdisp
[
ind_overrange
]
=
10
self
.
vdisp
[
ind_overrange
]
=
10
if
(
ebv
is
None
):
if
(
ebv
is
None
):
print
(
'Input EBV Map is empty!'
)
print
(
'Input EBV Map is empty!'
)
else
:
else
:
...
@@ -408,12 +408,12 @@ class StellarPopulationMap():
...
@@ -408,12 +408,12 @@ class StellarPopulationMap():
if
len
(
self
.
ebv
[
ind_overrange
])
>
0
:
if
len
(
self
.
ebv
[
ind_overrange
])
>
0
:
print
(
"Notice: Spaxel with < 0 mag in the input ebv map will be automatically adjusted to 0 mag."
)
print
(
"Notice: Spaxel with < 0 mag in the input ebv map will be automatically adjusted to 0 mag."
)
self
.
ebv
[
ind_overrange
]
=
0
self
.
ebv
[
ind_overrange
]
=
0
class
IonizedGasMap
():
class
IonizedGasMap
():
"""
"""
Class of 2D maps for the parameters of ionized gas, such as
Class of 2D maps for the parameters of ionized gas, such as
Halpha flux map, gas-phase metallicity map,
Halpha flux map, gas-phase metallicity map,
velocity and velocity dispersion maps, and dust extinction.
velocity and velocity dispersion maps, and dust extinction.
Parameters
Parameters
...
@@ -432,13 +432,13 @@ class IonizedGasMap():
...
@@ -432,13 +432,13 @@ class IonizedGasMap():
Class of the map of dust extinction, by default None
Class of the map of dust extinction, by default None
"""
"""
def
__init__
(
self
,
config
,
halpha
=
None
,
zh
=
None
,
vel
=
None
,
vdisp
=
None
,
ebv
=
None
):
def
__init__
(
self
,
config
,
halpha
=
None
,
zh
=
None
,
vel
=
None
,
vdisp
=
None
,
ebv
=
None
):
self
.
nx
=
config
.
nx
self
.
nx
=
config
.
nx
self
.
ny
=
config
.
ny
self
.
ny
=
config
.
ny
self
.
dpix
=
config
.
dpix
self
.
dpix
=
config
.
dpix
self
.
fov_x
=
config
.
fov_x
self
.
fov_x
=
config
.
fov_x
self
.
fov_y
=
config
.
fov_y
self
.
fov_y
=
config
.
fov_y
if
(
halpha
is
None
):
if
(
halpha
is
None
):
print
(
'Input Halpha Map is empty!'
)
print
(
'Input Halpha Map is empty!'
)
else
:
else
:
...
@@ -470,4 +470,4 @@ class IonizedGasMap():
...
@@ -470,4 +470,4 @@ class IonizedGasMap():
ind_overrange
=
(
self
.
ebv
<
0
)
ind_overrange
=
(
self
.
ebv
<
0
)
if
len
(
self
.
ebv
[
ind_overrange
])
>
0
:
if
len
(
self
.
ebv
[
ind_overrange
])
>
0
:
print
(
"Notice: Spaxel with < 0 mag in the input ebv map will be automatically adjusted to 0 mag."
)
print
(
"Notice: Spaxel with < 0 mag in the input ebv map will be automatically adjusted to 0 mag."
)
self
.
ebv
[
ind_overrange
]
=
0
self
.
ebv
[
ind_overrange
]
=
0
\ No newline at end of file
csst_ifs_gehong/spec1d.py
View file @
7c2ce85a
...
@@ -47,8 +47,8 @@ def readcol(filename, **kwargs):
...
@@ -47,8 +47,8 @@ def readcol(filename, **kwargs):
def
log_rebin
(
lamRange
,
spec
,
oversample
=
False
,
velscale
=
None
,
flux
=
False
):
def
log_rebin
(
lamRange
,
spec
,
oversample
=
False
,
velscale
=
None
,
flux
=
False
):
"""
"""
Logarithmically rebin a spectrum, while rigorously conserving the flux.
Logarithmically rebin a spectrum, while rigorously conserving the flux.
This function is taken from ppxf.
This function is taken from ppxf.
Parameters
Parameters
----------
----------
...
@@ -175,7 +175,7 @@ def calibrate(wave, flux, mag, filtername='SLOAN_SDSS.r'):
...
@@ -175,7 +175,7 @@ def calibrate(wave, flux, mag, filtername='SLOAN_SDSS.r'):
else
:
else
:
filter_file
=
data_path
+
'/data/filter/'
+
filtername
+
'.filter'
filter_file
=
data_path
+
'/data/filter/'
+
filtername
+
'.filter'
wave0
,
response0
=
readcol
(
filter_file
)
wave0
,
response0
=
readcol
(
filter_file
)
# Setting the response
# Setting the response
func
=
interp1d
(
wave0
,
response0
)
func
=
interp1d
(
wave0
,
response0
)
response
=
np
.
copy
(
wave
)
response
=
np
.
copy
(
wave
)
...
@@ -183,17 +183,17 @@ def calibrate(wave, flux, mag, filtername='SLOAN_SDSS.r'):
...
@@ -183,17 +183,17 @@ def calibrate(wave, flux, mag, filtername='SLOAN_SDSS.r'):
response
[
ind_extra
]
=
0
response
[
ind_extra
]
=
0
ind_inside
=
(
wave
<
max
(
wave0
))
&
(
wave
>
min
(
wave0
))
ind_inside
=
(
wave
<
max
(
wave0
))
&
(
wave
>
min
(
wave0
))
response
[
ind_inside
]
=
func
(
wave
[
ind_inside
])
response
[
ind_inside
]
=
func
(
wave
[
ind_inside
])
# Flux map of datacube for given filter band
# Flux map of datacube for given filter band
preflux
=
np
.
sum
(
flux
*
response
*
np
.
mean
(
np
.
diff
(
wave
)))
/
np
.
sum
(
response
*
np
.
mean
(
np
.
diff
(
wave
)))
preflux
=
np
.
sum
(
flux
*
response
*
np
.
mean
(
np
.
diff
(
wave
)))
/
np
.
sum
(
response
*
np
.
mean
(
np
.
diff
(
wave
)))
# Real flux from magnitude for given filter
# Real flux from magnitude for given filter
realflux
=
(
mag
*
u
.
STmag
).
to
(
u
.
erg
/
u
.
s
/
u
.
cm
**
2
/
u
.
AA
).
value
realflux
=
(
mag
*
u
.
STmag
).
to
(
u
.
erg
/
u
.
s
/
u
.
cm
**
2
/
u
.
AA
).
value
# Normalization
# Normalization
flux_ratio
=
realflux
/
preflux
flux_ratio
=
realflux
/
preflux
flux_calibrate
=
flux
*
flux_ratio
*
1e17
# Units: 10^-17 erg/s/A/cm^2
flux_calibrate
=
flux
*
flux_ratio
*
1e17
# Units: 10^-17 erg/s/A/cm^2
return
flux_calibrate
return
flux_calibrate
# ----------------
# ----------------
...
@@ -218,11 +218,10 @@ def Calzetti_Law(wave, Rv=4.05):
...
@@ -218,11 +218,10 @@ def Calzetti_Law(wave, Rv=4.05):
"""
"""
wave_number
=
1.
/
(
wave
*
1e-4
)
wave_number
=
1.
/
(
wave
*
1e-4
)
reddening_curve
=
np
.
zeros
(
len
(
wave
))
reddening_curve
=
np
.
zeros
(
len
(
wave
))
idx
=
(
wave
>=
1200
)
&
(
wave
<
6300
)
idx
=
(
wave
>=
1200
)
&
(
wave
<
6300
)
reddening_curve
[
idx
]
=
2.659
*
(
-
2.156
+
1.509
*
wave_number
[
idx
]
-
0.198
*
reddening_curve
[
idx
]
=
2.659
*
(
-
2.156
+
1.509
*
wave_number
[
idx
]
-
0.198
*
(
wave_number
[
idx
]
**
2
))
+
0.011
*
(
wave_number
[
idx
]
**
3
)
+
Rv
(
wave_number
[
idx
]
**
2
))
+
0.011
*
(
wave_number
[
idx
]
**
3
)
+
Rv
idx
=
(
wave
>=
6300
)
&
(
wave
<=
22000
)
idx
=
(
wave
>=
6300
)
&
(
wave
<=
22000
)
reddening_curve
[
idx
]
=
2.659
*
(
-
1.857
+
1.040
*
wave_number
[
idx
])
+
Rv
reddening_curve
[
idx
]
=
2.659
*
(
-
1.857
+
1.040
*
wave_number
[
idx
])
+
Rv
return
reddening_curve
return
reddening_curve
...
@@ -277,7 +276,7 @@ def SingleEmissinoLine(wave, line_wave, FWHM_inst):
...
@@ -277,7 +276,7 @@ def SingleEmissinoLine(wave, line_wave, FWHM_inst):
float array
float array
Spectra of single emission line
Spectra of single emission line
"""
"""
sigma
=
FWHM_inst
/
2.355
sigma
=
FWHM_inst
/
2.355
flux
=
norm
.
pdf
(
wave
,
line_wave
,
sigma
)
flux
=
norm
.
pdf
(
wave
,
line_wave
,
sigma
)
return
flux
return
flux
...
@@ -295,20 +294,20 @@ class EmissionLineTemplate():
...
@@ -295,20 +294,20 @@ class EmissionLineTemplate():
dlam : float, optional
dlam : float, optional
Wavelength width per pixel, by default 0.1A
Wavelength width per pixel, by default 0.1A
model : str, optional
model : str, optional
Emission line model, including 'hii' for HII region and 'nlr' for narrow line region of AGN,
Emission line model, including 'hii' for HII region and 'nlr' for narrow line region of AGN,
by default 'hii'
by default 'hii'
"""
"""
def
__init__
(
self
,
config
,
lam_range
=
[
500
,
15000
],
dlam
=
0.1
,
model
=
'hii'
):
def
__init__
(
self
,
config
,
lam_range
=
[
500
,
15000
],
dlam
=
0.1
,
model
=
'hii'
):
self
.
lam_range
=
lam_range
self
.
lam_range
=
lam_range
self
.
wave
=
np
.
arange
(
lam_range
[
0
],
lam_range
[
1
],
0.1
)
self
.
wave
=
np
.
arange
(
lam_range
[
0
],
lam_range
[
1
],
0.1
)
self
.
FWHM_inst
=
config
.
inst_fwhm
self
.
FWHM_inst
=
config
.
inst_fwhm
self
.
model
=
model
self
.
model
=
model
# HII region model of fsps-cloudy
# HII region model of fsps-cloudy
if
model
==
'hii'
:
if
model
==
'hii'
:
# Loading emission line flux table
# Loading emission line flux table
flux_table_file
=
data_path
+
'/data/fsps.nebular.fits'
flux_table_file
=
data_path
+
'/data/fsps.nebular.fits'
line_table
=
fits
.
open
(
flux_table_file
)
line_table
=
fits
.
open
(
flux_table_file
)
...
@@ -317,18 +316,18 @@ class EmissionLineTemplate():
...
@@ -317,18 +316,18 @@ class EmissionLineTemplate():
line_list
=
line_table
[
1
].
data
line_list
=
line_table
[
1
].
data
line_wave
=
line_list
[
'Wave'
]
line_wave
=
line_list
[
'Wave'
]
line_names
=
line_list
[
'Name'
]
line_names
=
line_list
[
'Name'
]
w
=
(
line_wave
>
lam_range
[
0
])
&
(
line_wave
<
lam_range
[
1
])
w
=
(
line_wave
>
lam_range
[
0
])
&
(
line_wave
<
lam_range
[
1
])
self
.
line_names
=
line_names
[
w
]
self
.
line_names
=
line_names
[
w
]
self
.
line_wave
=
line_wave
[
w
]
self
.
line_wave
=
line_wave
[
w
]
# Make parameter grid
# Make parameter grid
grid
=
line_table
[
2
].
data
grid
=
line_table
[
2
].
data
self
.
logz_grid
=
grid
[
'logZ'
]
self
.
logz_grid
=
grid
[
'logZ'
]
# Narrow line region model of
# Narrow line region model of
if
model
==
'nlr'
:
if
model
==
'nlr'
:
# Loading emission line flux table
# Loading emission line flux table
flux_table_file
=
data_path
+
'/data/AGN.NLR.fits'
flux_table_file
=
data_path
+
'/data/AGN.NLR.fits'
line_table
=
fits
.
open
(
flux_table_file
)
line_table
=
fits
.
open
(
flux_table_file
)
...
@@ -337,19 +336,19 @@ class EmissionLineTemplate():
...
@@ -337,19 +336,19 @@ class EmissionLineTemplate():
line_list
=
line_table
[
1
].
data
line_list
=
line_table
[
1
].
data
line_wave
=
line_list
[
'Wave'
]
line_wave
=
line_list
[
'Wave'
]
line_names
=
line_list
[
'Name'
]
line_names
=
line_list
[
'Name'
]
w
=
(
line_wave
>
lam_range
[
0
])
&
(
line_wave
<
lam_range
[
1
])
w
=
(
line_wave
>
lam_range
[
0
])
&
(
line_wave
<
lam_range
[
1
])
self
.
line_names
=
line_names
[
w
]
self
.
line_names
=
line_names
[
w
]
self
.
line_wave
=
line_wave
[
w
]
self
.
line_wave
=
line_wave
[
w
]
# Make parameter grid
# Make parameter grid
grid
=
line_table
[
2
].
data
grid
=
line_table
[
2
].
data
self
.
logz_grid
=
grid
[
'logZ'
]
self
.
logz_grid
=
grid
[
'logZ'
]
# Flux ratio
# Flux ratio
flux_ratio
=
line_table
[
3
].
data
flux_ratio
=
line_table
[
3
].
data
self
.
flux_ratio
=
flux_ratio
self
.
flux_ratio
=
flux_ratio
# Make emission line
# Make emission line
nline
=
len
(
line_wave
)
nline
=
len
(
line_wave
)
for
i
in
range
(
nline
):
for
i
in
range
(
nline
):
...
@@ -389,9 +388,9 @@ class HII_Region():
...
@@ -389,9 +388,9 @@ class HII_Region():
ValueError
ValueError
The value of logZ should be between -2 and 0.5.
The value of logZ should be between -2 and 0.5.
"""
"""
def
__init__
(
self
,
config
,
temp
,
halpha
=
100.0
,
logz
=
0.0
,
vel
=
100.0
,
vdisp
=
120.0
,
ebv
=
0.1
):
def
__init__
(
self
,
config
,
temp
,
halpha
=
100.0
,
logz
=
0.0
,
vel
=
100.0
,
vdisp
=
120.0
,
ebv
=
0.1
):
# Check Input Parameters
# Check Input Parameters
# if (halpha < 0):
# if (halpha < 0):
# print("Notice: Your input Halpha flux (halpha) is < 0 erg/s/A/cm^2. ")
# print("Notice: Your input Halpha flux (halpha) is < 0 erg/s/A/cm^2. ")
...
@@ -403,25 +402,25 @@ class HII_Region():
...
@@ -403,25 +402,25 @@ class HII_Region():
# if (ebv < 0):
# if (ebv < 0):
# ebv = 0
# ebv = 0
# print('Notice: Your input dust extinction (ebv) is < 0 mag, which will be automatically adjusted to 0 mag. ')
# print('Notice: Your input dust extinction (ebv) is < 0 mag, which will be automatically adjusted to 0 mag. ')
# Make emission line spectra through adding emission lines
# Make emission line spectra through adding emission lines
emlines
=
temp
.
emission_lines
*
flux_ratio
emlines
=
temp
.
emission_lines
*
flux_ratio
flux_combine
=
np
.
sum
(
emlines
,
axis
=
1
)
flux_combine
=
np
.
sum
(
emlines
,
axis
=
1
)
flux_calibrate
=
flux_combine
*
halpha
# Units: erg/s/A/cm^2
flux_calibrate
=
flux_combine
*
halpha
# Units: erg/s/A/cm^2
# Dust attenuation
# Dust attenuation
if
np
.
isscalar
(
ebv
):
if
np
.
isscalar
(
ebv
):
flux_dust
=
reddening
(
temp
.
wave
,
flux_calibrate
,
ebv
=
ebv
)
flux_dust
=
reddening
(
temp
.
wave
,
flux_calibrate
,
ebv
=
ebv
)
# Broadening caused by Velocity Dispersion
# Broadening caused by Velocity Dispersion
velscale
=
10
velscale
=
10
lam_range
=
[
np
.
min
(
temp
.
wave
),
np
.
max
(
temp
.
wave
)]
lam_range
=
[
np
.
min
(
temp
.
wave
),
np
.
max
(
temp
.
wave
)]
flux_logwave
,
logLam
=
log_rebin
(
lam_range
,
flux_dust
,
velscale
=
velscale
)[:
2
]
flux_logwave
,
logLam
=
log_rebin
(
lam_range
,
flux_dust
,
velscale
=
velscale
)[:
2
]
sigma_gas
=
vdisp
/
velscale
# in pixel
sigma_gas
=
vdisp
/
velscale
# in pixel
sigma_LSF
=
temp
.
FWHM_inst
/
(
np
.
exp
(
logLam
))
*
3e5
/
velscale
# in pixel
sigma_LSF
=
temp
.
FWHM_inst
/
(
np
.
exp
(
logLam
))
*
3e5
/
velscale
# in pixel
if
sigma_gas
>
0
:
if
sigma_gas
>
0
:
sigma_dif
=
np
.
zeros
(
len
(
flux_logwave
))
sigma_dif
=
np
.
zeros
(
len
(
flux_logwave
))
idx
=
(
sigma_gas
>
sigma_LSF
)
idx
=
(
sigma_gas
>
sigma_LSF
)
sigma_dif
[
idx
]
=
np
.
sqrt
(
sigma_gas
**
2.
-
sigma_LSF
[
idx
]
**
2.
)
sigma_dif
[
idx
]
=
np
.
sqrt
(
sigma_gas
**
2.
-
sigma_LSF
[
idx
]
**
2.
)
...
@@ -431,12 +430,12 @@ class HII_Region():
...
@@ -431,12 +430,12 @@ class HII_Region():
else
:
else
:
print
(
'Notice: Your input velocity dispersion (vdisp) is <= 0 km/s. The nagtive value will be automatically adjusted to 0 km/s. '
)
print
(
'Notice: Your input velocity dispersion (vdisp) is <= 0 km/s. The nagtive value will be automatically adjusted to 0 km/s. '
)
flux_broad
=
flux_logwave
flux_broad
=
flux_logwave
# Redshift
# Redshift
redshift
=
vel
/
3e5
redshift
=
vel
/
3e5
wave_r
=
np
.
exp
(
logLam
)
*
(
1
+
redshift
)
wave_r
=
np
.
exp
(
logLam
)
*
(
1
+
redshift
)
flux_red
=
np
.
interp
(
config
.
wave
,
wave_r
,
flux_broad
)
flux_red
=
np
.
interp
(
config
.
wave
,
wave_r
,
flux_broad
)
self
.
wave
=
config
.
wave
self
.
wave
=
config
.
wave
self
.
flux
=
flux_red
self
.
flux
=
flux_red
...
@@ -472,45 +471,45 @@ class AGN_NLR():
...
@@ -472,45 +471,45 @@ class AGN_NLR():
ValueError
ValueError
The value of logZ should be between -2 and 0.5.
The value of logZ should be between -2 and 0.5.
"""
"""
def
__init__
(
self
,
config
,
temp
,
halpha
=
100.0
,
logz
=
0.0
,
vel
=
100.0
,
vdisp
=
120.0
,
ebv
=
0.1
):
def
__init__
(
self
,
config
,
temp
,
halpha
=
100.0
,
logz
=
0.0
,
vel
=
100.0
,
vdisp
=
120.0
,
ebv
=
0.1
):
if
(
logz
>=
-
2.3
)
&
(
logz
<=
0.54
):
if
(
logz
>=
-
2.3
)
&
(
logz
<=
0.54
):
indz
=
np
.
argmin
(
np
.
abs
(
logz
-
temp
.
logz_grid
))
indz
=
np
.
argmin
(
np
.
abs
(
logz
-
temp
.
logz_grid
))
flux_ratio
=
temp
.
flux_ratio
[
indz
,
:]
flux_ratio
=
temp
.
flux_ratio
[
indz
,
:]
else
:
else
:
raise
ValueError
(
'The value of logZ is not in the range of [-2.3, 0.54]'
)
raise
ValueError
(
'The value of logZ is not in the range of [-2.3, 0.54]'
)
# Make emission line spectra through adding emission lines
# Make emission line spectra through adding emission lines
emlines
=
temp
.
emission_lines
*
(
flux_ratio
/
flux_ratio
[
6
])
emlines
=
temp
.
emission_lines
*
(
flux_ratio
/
flux_ratio
[
6
])
flux_combine
=
np
.
sum
(
emlines
,
axis
=
1
)
flux_combine
=
np
.
sum
(
emlines
,
axis
=
1
)
flux_calibrate
=
flux_combine
*
halpha
# Units: 1e-17 erg/s/A/cm^2
flux_calibrate
=
flux_combine
*
halpha
# Units: 1e-17 erg/s/A/cm^2
# Dust attenuation
# Dust attenuation
if
np
.
isscalar
(
ebv
):
if
np
.
isscalar
(
ebv
):
flux_dust
=
reddening
(
temp
.
wave
,
flux_calibrate
,
ebv
=
ebv
)
flux_dust
=
reddening
(
temp
.
wave
,
flux_calibrate
,
ebv
=
ebv
)
# Broadening caused by Velocity Dispersion
# Broadening caused by Velocity Dispersion
velscale
=
10
velscale
=
10
lam_range
=
[
np
.
min
(
temp
.
wave
),
np
.
max
(
temp
.
wave
)]
lam_range
=
[
np
.
min
(
temp
.
wave
),
np
.
max
(
temp
.
wave
)]
flux_logwave
,
logLam
=
log_rebin
(
lam_range
,
flux_dust
,
velscale
=
velscale
)[:
2
]
flux_logwave
,
logLam
=
log_rebin
(
lam_range
,
flux_dust
,
velscale
=
velscale
)[:
2
]
sigma_gas
=
vdisp
/
velscale
# in pixel
sigma_gas
=
vdisp
/
velscale
# in pixel
sigma_LSF
=
temp
.
FWHM_inst
/
(
np
.
exp
(
logLam
))
*
3e5
/
velscale
# in pixel
sigma_LSF
=
temp
.
FWHM_inst
/
(
np
.
exp
(
logLam
))
*
3e5
/
velscale
# in pixel
if
sigma_gas
>
0
:
if
sigma_gas
>
0
:
sigma_dif
=
np
.
zeros
(
len
(
flux_logwave
))
sigma_dif
=
np
.
zeros
(
len
(
flux_logwave
))
idx
=
(
sigma_gas
>
sigma_LSF
)
idx
=
(
sigma_gas
>
sigma_LSF
)
sigma_dif
[
idx
]
=
np
.
sqrt
(
sigma_gas
**
2.
-
sigma_LSF
[
idx
]
**
2.
)
sigma_dif
[
idx
]
=
np
.
sqrt
(
sigma_gas
**
2.
-
sigma_LSF
[
idx
]
**
2.
)
idx
=
(
sigma_gas
<=
sigma_LSF
)
idx
=
(
sigma_gas
<=
sigma_LSF
)
sigma_dif
[
idx
]
=
0.1
sigma_dif
[
idx
]
=
0.1
flux_broad
=
gaussian_filter1d
(
flux_logwave
,
sigma_dif
)
flux_broad
=
gaussian_filter1d
(
flux_logwave
,
sigma_dif
)
# Redshift
# Redshift
redshift
=
vel
/
3e5
redshift
=
vel
/
3e5
wave_r
=
np
.
exp
(
logLam
)
*
(
1
+
redshift
)
wave_r
=
np
.
exp
(
logLam
)
*
(
1
+
redshift
)
flux_red
=
np
.
interp
(
config
.
wave
,
wave_r
,
flux_broad
)
flux_red
=
np
.
interp
(
config
.
wave
,
wave_r
,
flux_broad
)
self
.
wave
=
config
.
wave
self
.
wave
=
config
.
wave
self
.
flux
=
flux_red
self
.
flux
=
flux_red
...
@@ -536,42 +535,42 @@ class AGN_BLR():
...
@@ -536,42 +535,42 @@ class AGN_BLR():
Wavelength range, by default [500, 15000]
Wavelength range, by default [500, 15000]
"""
"""
def
__init__
(
self
,
config
,
hbeta_flux
=
100.0
,
hbeta_fwhm
=
2000.0
,
ebv
=
0.1
,
def
__init__
(
self
,
config
,
hbeta_flux
=
100.0
,
hbeta_fwhm
=
2000.0
,
ebv
=
0.1
,
vel
=
0.
,
lam_range
=
[
500
,
15000
]):
vel
=
0.
,
lam_range
=
[
500
,
15000
]):
wave_rest
=
np
.
arange
(
lam_range
[
0
],
lam_range
[
1
],
0.1
)
wave_rest
=
np
.
arange
(
lam_range
[
0
],
lam_range
[
1
],
0.1
)
line_names
=
[
'Hepsilon'
,
'Hdelta'
,
'Hgamma'
,
'Hbeta'
,
'Halpha'
]
line_names
=
[
'Hepsilon'
,
'Hdelta'
,
'Hgamma'
,
'Hbeta'
,
'Halpha'
]
line_waves
=
[
3970.079
,
4101.742
,
4340.471
,
4861.333
,
6562.819
]
line_waves
=
[
3970.079
,
4101.742
,
4340.471
,
4861.333
,
6562.819
]
line_ratio
=
[
0.101
,
0.208
,
0.405
,
1.000
,
2.579
]
# From Ilic et al. (2006)
line_ratio
=
[
0.101
,
0.208
,
0.405
,
1.000
,
2.579
]
# From Ilic et al. (2006)
# Make emission lines
# Make emission lines
for
i
in
range
(
len
(
line_names
)):
for
i
in
range
(
len
(
line_names
)):
if
i
==
0
:
if
i
==
0
:
emission_line
=
SingleEmissinoLine
(
wave_rest
,
line_waves
[
i
],
emission_line
=
SingleEmissinoLine
(
wave_rest
,
line_waves
[
i
],
hbeta_fwhm
/
3e5
*
line_waves
[
i
])
hbeta_fwhm
/
3e5
*
line_waves
[
i
])
emission_lines
=
emission_line
emission_lines
=
emission_line
else
:
else
:
emission_line
=
SingleEmissinoLine
(
wave_rest
,
line_waves
[
i
],
emission_line
=
SingleEmissinoLine
(
wave_rest
,
line_waves
[
i
],
hbeta_fwhm
/
3e5
*
line_waves
[
i
])
hbeta_fwhm
/
3e5
*
line_waves
[
i
])
emission_lines
=
np
.
vstack
((
emission_lines
,
emission_line
))
emission_lines
=
np
.
vstack
((
emission_lines
,
emission_line
))
emlines
=
emission_lines
.
T
*
line_ratio
emlines
=
emission_lines
.
T
*
line_ratio
flux_combine
=
np
.
sum
(
emlines
,
axis
=
1
)
flux_combine
=
np
.
sum
(
emlines
,
axis
=
1
)
# Flux callibration
# Flux callibration
flux_calibrate
=
flux_combine
*
hbeta_flux
# Units: 1e-17 erg/s/A/cm^2
flux_calibrate
=
flux_combine
*
hbeta_flux
# Units: 1e-17 erg/s/A/cm^2
# Dust attenuation
# Dust attenuation
if
np
.
isscalar
(
ebv
):
if
np
.
isscalar
(
ebv
):
flux_dust
=
reddening
(
wave_rest
,
flux_calibrate
,
ebv
=
ebv
)
flux_dust
=
reddening
(
wave_rest
,
flux_calibrate
,
ebv
=
ebv
)
else
:
else
:
flux_dust
=
flux_calibrate
flux_dust
=
flux_calibrate
# Redshift
# Redshift
redshift
=
vel
/
3e5
redshift
=
vel
/
3e5
wave_r
=
wave_rest
*
(
1
+
redshift
)
wave_r
=
wave_rest
*
(
1
+
redshift
)
flux_red
=
np
.
interp
(
config
.
wave
,
wave_r
,
flux_dust
)
flux_red
=
np
.
interp
(
config
.
wave
,
wave_r
,
flux_dust
)
self
.
wave
=
config
.
wave
self
.
wave
=
config
.
wave
self
.
flux
=
flux_red
self
.
flux
=
flux_red
...
@@ -593,39 +592,39 @@ class AGN_FeII():
...
@@ -593,39 +592,39 @@ class AGN_FeII():
ebv : float, optional
ebv : float, optional
Dust extinction, by default 0.1
Dust extinction, by default 0.1
"""
"""
def
__init__
(
self
,
config
,
hbeta_broad
=
100.0
,
r4570
=
0.4
,
ebv
=
0.1
,
vel
=
100.0
):
def
__init__
(
self
,
config
,
hbeta_broad
=
100.0
,
r4570
=
0.4
,
ebv
=
0.1
,
vel
=
100.0
):
filename
=
data_path
+
'/data/FeII.AGN.fits'
filename
=
data_path
+
'/data/FeII.AGN.fits'
# Loading FeII template
# Loading FeII template
hdulist
=
fits
.
open
(
filename
)
hdulist
=
fits
.
open
(
filename
)
data
=
hdulist
[
1
].
data
data
=
hdulist
[
1
].
data
wave_rest
=
data
[
'WAVE'
]
wave_rest
=
data
[
'WAVE'
]
flux_model
=
data
[
'FLUX'
]
flux_model
=
data
[
'FLUX'
]
# Determine the flux of FeII
# Determine the flux of FeII
Fe4570_temp
=
100
Fe4570_temp
=
100
Fe4570_model
=
hbeta_broad
*
r4570
Fe4570_model
=
hbeta_broad
*
r4570
Ratio_Fe4570
=
Fe4570_model
/
Fe4570_temp
Ratio_Fe4570
=
Fe4570_model
/
Fe4570_temp
# Flux calibration
# Flux calibration
flux_calibrate
=
flux_model
*
Ratio_Fe4570
flux_calibrate
=
flux_model
*
Ratio_Fe4570
# Dust attenuation
# Dust attenuation
if
np
.
isscalar
(
ebv
):
if
np
.
isscalar
(
ebv
):
flux_dust
=
reddening
(
wave_rest
,
flux_calibrate
,
ebv
=
ebv
)
flux_dust
=
reddening
(
wave_rest
,
flux_calibrate
,
ebv
=
ebv
)
else
:
else
:
flux_dust
=
flux_calibrate
flux_dust
=
flux_calibrate
# Redshift
# Redshift
redshift
=
vel
/
3e5
redshift
=
vel
/
3e5
wave_r
=
wave_rest
*
(
1
+
redshift
)
wave_r
=
wave_rest
*
(
1
+
redshift
)
flux_red
=
np
.
interp
(
config
.
wave
,
wave_r
,
flux_dust
)
flux_red
=
np
.
interp
(
config
.
wave
,
wave_r
,
flux_dust
)
self
.
wave
=
config
.
wave
self
.
wave
=
config
.
wave
self
.
flux
=
flux_red
self
.
flux
=
flux_red
class
AGN_Powerlaw
():
class
AGN_Powerlaw
():
...
@@ -645,29 +644,29 @@ class AGN_Powerlaw():
...
@@ -645,29 +644,29 @@ class AGN_Powerlaw():
Ebv : float, optional
Ebv : float, optional
Dust extinction, by default 0.1
Dust extinction, by default 0.1
"""
"""
def
__init__
(
self
,
config
,
m5100
=
1000.0
,
alpha
=-
1.5
,
vel
=
100.0
,
ebv
=
0.1
):
def
__init__
(
self
,
config
,
m5100
=
1000.0
,
alpha
=-
1.5
,
vel
=
100.0
,
ebv
=
0.1
):
wave_rest
=
np
.
linspace
(
1000
,
20000
,
10000
)
wave_rest
=
np
.
linspace
(
1000
,
20000
,
10000
)
flux
=
wave_rest
**
alpha
flux
=
wave_rest
**
alpha
# Flux calibration
# Flux calibration
flux_calibrate
=
calibrate
(
wave_rest
,
flux
,
m5100
,
filtername
=
'5100'
)
flux_calibrate
=
calibrate
(
wave_rest
,
flux
,
m5100
,
filtername
=
'5100'
)
# Dust attenuation
# Dust attenuation
if
np
.
isscalar
(
ebv
):
if
np
.
isscalar
(
ebv
):
flux_dust
=
reddening
(
wave_rest
,
flux_calibrate
,
ebv
=
ebv
)
flux_dust
=
reddening
(
wave_rest
,
flux_calibrate
,
ebv
=
ebv
)
else
:
else
:
flux_dust
=
flux_calibrate
flux_dust
=
flux_calibrate
# Redshift
# Redshift
redshift
=
vel
/
3e5
redshift
=
vel
/
3e5
wave_r
=
wave_rest
*
(
1
+
redshift
)
wave_r
=
wave_rest
*
(
1
+
redshift
)
flux_red
=
np
.
interp
(
config
.
wave
,
wave_r
,
flux_dust
)
flux_red
=
np
.
interp
(
config
.
wave
,
wave_r
,
flux_dust
)
self
.
wave
=
config
.
wave
self
.
wave
=
config
.
wave
self
.
flux
=
flux_red
self
.
flux
=
flux_red
class
AGN
():
class
AGN
():
...
@@ -681,7 +680,7 @@ class AGN():
...
@@ -681,7 +680,7 @@ class AGN():
nlr_template : class
nlr_template : class
Class of emission line template
Class of emission line template
bhmass : float, optional
bhmass : float, optional
Black hole mass used for calculating the luminosity of power law spectrum at 5100A,
Black hole mass used for calculating the luminosity of power law spectrum at 5100A,
by default 1e6 solar mass
by default 1e6 solar mass
edd_ratio : float, optional
edd_ratio : float, optional
Eddinton ratio used for calculating the luminosity of power law spectrum at 5100A, by default 0.05
Eddinton ratio used for calculating the luminosity of power law spectrum at 5100A, by default 0.05
...
@@ -702,10 +701,10 @@ class AGN():
...
@@ -702,10 +701,10 @@ class AGN():
dist : float, optional
dist : float, optional
Luminosity distance of AGN, by default 20.0Mpc
Luminosity distance of AGN, by default 20.0Mpc
"""
"""
def
__init__
(
self
,
config
,
nlr_template
,
bhmass
=
1e6
,
edd_ratio
=
0.05
,
def
__init__
(
self
,
config
,
nlr_template
,
bhmass
=
1e6
,
edd_ratio
=
0.05
,
halpha_broad
=
100.0
,
halpha_narrow
=
100.0
,
vdisp_broad
=
5000.0
,
vdisp_narrow
=
500.0
,
halpha_broad
=
100.0
,
halpha_narrow
=
100.0
,
vdisp_broad
=
5000.0
,
vdisp_narrow
=
500.0
,
vel
=
1000.0
,
logz
=
0.0
,
ebv
=
0.1
,
dist
=
20.0
):
vel
=
1000.0
,
logz
=
0.0
,
ebv
=
0.1
,
dist
=
20.0
):
# Check Input Parameters
# Check Input Parameters
if
(
bhmass
<
0
):
if
(
bhmass
<
0
):
raise
Exception
(
"Input black hole mass (bhmass) should be >= 0 solarmass."
)
raise
Exception
(
"Input black hole mass (bhmass) should be >= 0 solarmass."
)
...
@@ -724,17 +723,17 @@ class AGN():
...
@@ -724,17 +723,17 @@ class AGN():
raise
Exception
(
'Input metallicity of narrow lines (logz) should be < -2.3'
)
raise
Exception
(
'Input metallicity of narrow lines (logz) should be < -2.3'
)
if
(
dist
<=
0
):
if
(
dist
<=
0
):
raise
Exception
(
'Input luminosity distance (dist) should be > 0 Mpc'
)
raise
Exception
(
'Input luminosity distance (dist) should be > 0 Mpc'
)
self
.
wave
=
config
.
wave
self
.
wave
=
config
.
wave
self
.
flux
=
self
.
wave
*
0
self
.
flux
=
self
.
wave
*
0
if
(
vdisp_narrow
>
0
)
&
(
halpha_narrow
>
0
):
if
(
vdisp_narrow
>
0
)
&
(
halpha_narrow
>
0
):
NLR
=
AGN_NLR
(
config
,
nlr_template
,
halpha
=
halpha_narrow
,
logz
=
logz
,
NLR
=
AGN_NLR
(
config
,
nlr_template
,
halpha
=
halpha_narrow
,
logz
=
logz
,
vel
=
vel
,
vdisp
=
vdisp_narrow
,
ebv
=
ebv
)
vel
=
vel
,
vdisp
=
vdisp_narrow
,
ebv
=
ebv
)
self
.
flux
=
self
.
flux
+
NLR
.
flux
self
.
flux
=
self
.
flux
+
NLR
.
flux
if
(
halpha_broad
>
0
)
&
(
vdisp_broad
>
0
):
if
(
halpha_broad
>
0
)
&
(
vdisp_broad
>
0
):
BLR
=
AGN_BLR
(
config
,
hbeta_flux
=
halpha_broad
/
2.579
,
BLR
=
AGN_BLR
(
config
,
hbeta_flux
=
halpha_broad
/
2.579
,
hbeta_fwhm
=
vdisp_broad
/
2.355
,
ebv
=
ebv
,
vel
=
vel
)
hbeta_fwhm
=
vdisp_broad
/
2.355
,
ebv
=
ebv
,
vel
=
vel
)
self
.
flux
=
self
.
flux
+
BLR
.
flux
self
.
flux
=
self
.
flux
+
BLR
.
flux
...
@@ -743,7 +742,7 @@ class AGN():
...
@@ -743,7 +742,7 @@ class AGN():
PL
=
AGN_Powerlaw
(
config
,
m5100
=
m5100
,
ebv
=
ebv
,
vel
=
vel
)
PL
=
AGN_Powerlaw
(
config
,
m5100
=
m5100
,
ebv
=
ebv
,
vel
=
vel
)
Fe
=
AGN_FeII
(
config
,
hbeta_broad
=
halpha_broad
/
2.579
,
ebv
=
ebv
,
vel
=
vel
)
Fe
=
AGN_FeII
(
config
,
hbeta_broad
=
halpha_broad
/
2.579
,
ebv
=
ebv
,
vel
=
vel
)
self
.
flux
=
self
.
flux
+
PL
.
flux
+
Fe
.
flux
self
.
flux
=
self
.
flux
+
PL
.
flux
+
Fe
.
flux
def
BHmass_to_M5100
(
bhmass
,
edd_ratio
=
0.05
,
dist
=
21.0
):
def
BHmass_to_M5100
(
bhmass
,
edd_ratio
=
0.05
,
dist
=
21.0
):
"""
"""
...
@@ -763,7 +762,7 @@ def BHmass_to_M5100(bhmass, edd_ratio=0.05, dist=21.0):
...
@@ -763,7 +762,7 @@ def BHmass_to_M5100(bhmass, edd_ratio=0.05, dist=21.0):
float
float
Magnitude at 5100A
Magnitude at 5100A
"""
"""
# Calculate bolometric luminosity
# Calculate bolometric luminosity
Ledd
=
3e4
*
bhmass
Ledd
=
3e4
*
bhmass
Lbol
=
Ledd
*
edd_ratio
Lbol
=
Ledd
*
edd_ratio
...
@@ -817,7 +816,7 @@ def age_metal(filename):
...
@@ -817,7 +816,7 @@ def age_metal(filename):
class
StellarContinuumTemplate
(
object
):
class
StellarContinuumTemplate
(
object
):
"""
"""
Class of single stellar population template.
Class of single stellar population template.
Parameters
Parameters
----------
----------
...
@@ -826,17 +825,17 @@ class StellarContinuumTemplate(object):
...
@@ -826,17 +825,17 @@ class StellarContinuumTemplate(object):
velscale : array
velscale : array
velocity scale in km/s per pixels, by default 50.0km/s
velocity scale in km/s per pixels, by default 50.0km/s
pathname : string, optional
pathname : string, optional
path with wildcards returning the list files to use,
path with wildcards returning the list files to use,
by default data_path+'/data/EMILES/Ech*_baseFe.fits'
by default data_path+'/data/EMILES/Ech*_baseFe.fits'
normalize : bool, optional
normalize : bool, optional
Set to True to normalize each template to mean=1, by default False
Set to True to normalize each template to mean=1, by default False
"""
"""
def
__init__
(
self
,
config
,
velscale
=
50
,
def
__init__
(
self
,
config
,
velscale
=
50
,
pathname
=
data_path
+
'/data/EMILES/Ech*_baseFe.fits'
,
pathname
=
data_path
+
'/data/EMILES/Ech*_baseFe.fits'
,
normalize
=
False
):
normalize
=
False
):
FWHM_inst
=
config
.
inst_fwhm
FWHM_inst
=
config
.
inst_fwhm
files
=
glob
.
glob
(
pathname
)
files
=
glob
.
glob
(
pathname
)
assert
len
(
files
)
>
0
,
"Files not found %s"
%
pathname
assert
len
(
files
)
>
0
,
"Files not found %s"
%
pathname
...
@@ -857,7 +856,7 @@ class StellarContinuumTemplate(object):
...
@@ -857,7 +856,7 @@ class StellarContinuumTemplate(object):
lam_range_temp
=
h2
[
'CRVAL1'
]
+
np
.
array
([
0
,
h2
[
'CDELT1'
]
*
(
h2
[
'NAXIS1'
]
-
1
)])
lam_range_temp
=
h2
[
'CRVAL1'
]
+
np
.
array
([
0
,
h2
[
'CDELT1'
]
*
(
h2
[
'NAXIS1'
]
-
1
)])
sspNew
,
log_lam_temp
=
log_rebin
(
lam_range_temp
,
ssp
,
velscale
=
velscale
)[:
2
]
sspNew
,
log_lam_temp
=
log_rebin
(
lam_range_temp
,
ssp
,
velscale
=
velscale
)[:
2
]
# wave=((np.arange(hdr['NAXIS1'])+1.0)-hdr['CRPIX1'])*hdr['CDELT1']+hdr['CRVAL1']
# wave=((np.arange(hdr['NAXIS1'])+1.0)-hdr['CRPIX1'])*hdr['CDELT1']+hdr['CRVAL1']
templates
=
np
.
empty
((
sspNew
.
size
,
n_ages
,
n_metal
))
templates
=
np
.
empty
((
sspNew
.
size
,
n_ages
,
n_metal
))
age_grid
=
np
.
empty
((
n_ages
,
n_metal
))
age_grid
=
np
.
empty
((
n_ages
,
n_metal
))
metal_grid
=
np
.
empty
((
n_ages
,
n_metal
))
metal_grid
=
np
.
empty
((
n_ages
,
n_metal
))
...
@@ -870,7 +869,7 @@ class StellarContinuumTemplate(object):
...
@@ -870,7 +869,7 @@ class StellarContinuumTemplate(object):
# Quadratic sigma difference in pixels Vazdekis --> galaxy
# Quadratic sigma difference in pixels Vazdekis --> galaxy
# The formula below is rigorously valid if the shapes of the
# The formula below is rigorously valid if the shapes of the
# instrumental spectral profiles are well approximated by Gaussians.
# instrumental spectral profiles are well approximated by Gaussians.
# FWHM of Emiles templates
# FWHM of Emiles templates
Emile_wave
=
np
.
exp
(
log_lam_temp
)
Emile_wave
=
np
.
exp
(
log_lam_temp
)
Emile_FWHM
=
np
.
zeros
(
h2
[
'NAXIS1'
])
Emile_FWHM
=
np
.
zeros
(
h2
[
'NAXIS1'
])
...
@@ -879,9 +878,9 @@ class StellarContinuumTemplate(object):
...
@@ -879,9 +878,9 @@ class StellarContinuumTemplate(object):
Emile_FWHM
[
np
.
where
((
Emile_wave
>=
3540
)
&
(
Emile_wave
<
8950
))]
=
2.5
Emile_FWHM
[
np
.
where
((
Emile_wave
>=
3540
)
&
(
Emile_wave
<
8950
))]
=
2.5
Lwave
=
Emile_wave
[
np
.
where
(
Emile_wave
>=
8950
)]
Lwave
=
Emile_wave
[
np
.
where
(
Emile_wave
>=
8950
)]
Emile_FWHM
[
np
.
where
(
Emile_wave
>=
8950
)]
=
60
*
2.35
/
3.e5
*
Lwave
# sigma=60km/s at lambda > 8950
Emile_FWHM
[
np
.
where
(
Emile_wave
>=
8950
)]
=
60
*
2.35
/
3.e5
*
Lwave
# sigma=60km/s at lambda > 8950
LSF
=
Emile_FWHM
LSF
=
Emile_FWHM
FWHM_eff
=
Emile_FWHM
.
copy
()
# combined FWHM from stellar library and instrument(input)
FWHM_eff
=
Emile_FWHM
.
copy
()
# combined FWHM from stellar library and instrument(input)
if
np
.
isscalar
(
FWHM_inst
):
if
np
.
isscalar
(
FWHM_inst
):
FWHM_eff
[
Emile_FWHM
<
FWHM_inst
]
=
FWHM_inst
FWHM_eff
[
Emile_FWHM
<
FWHM_inst
]
=
FWHM_inst
...
@@ -918,8 +917,8 @@ class StellarContinuumTemplate(object):
...
@@ -918,8 +917,8 @@ class StellarContinuumTemplate(object):
self
.
n_metal
=
n_metal
self
.
n_metal
=
n_metal
self
.
LSF
=
log_rebin
(
lam_range_temp
,
LSF
,
velscale
=
velscale
)[
0
]
self
.
LSF
=
log_rebin
(
lam_range_temp
,
LSF
,
velscale
=
velscale
)[
0
]
self
.
velscale
=
velscale
self
.
velscale
=
velscale
def
fmass_ssp
(
self
):
def
fmass_ssp
(
self
):
isedpath
=
data_path
+
'/data/EMILES/model/'
isedpath
=
data_path
+
'/data/EMILES/model/'
massfile
=
isedpath
+
'out_mass_CH_PADOVA00'
massfile
=
isedpath
+
'out_mass_CH_PADOVA00'
...
@@ -928,7 +927,7 @@ class StellarContinuumTemplate(object):
...
@@ -928,7 +927,7 @@ class StellarContinuumTemplate(object):
# fage = self.age_grid[:,0]
# fage = self.age_grid[:,0]
fMs
=
np
.
zeros
((
n_ages
,
n_metal
))
fMs
=
np
.
zeros
((
n_ages
,
n_metal
))
Metal
,
Age
,
Ms
=
readcol
(
massfile
,
usecols
=
(
2
,
3
,
6
))
Metal
,
Age
,
Ms
=
readcol
(
massfile
,
usecols
=
(
2
,
3
,
6
))
for
i
in
range
(
n_metal
):
for
i
in
range
(
n_metal
):
for
j
in
range
(
self
.
n_ages
):
for
j
in
range
(
self
.
n_ages
):
...
@@ -936,12 +935,12 @@ class StellarContinuumTemplate(object):
...
@@ -936,12 +935,12 @@ class StellarContinuumTemplate(object):
fMs
[
j
,
i
]
=
Ms
[
locmin
]
fMs
[
j
,
i
]
=
Ms
[
locmin
]
return
fMs
return
fMs
class
StellarContinuum
():
class
StellarContinuum
():
"""
"""
The class of stellar continuum
The class of stellar continuum
Parameters
Parameters
----------
----------
config : class
config : class
...
@@ -961,9 +960,9 @@ class StellarContinuum():
...
@@ -961,9 +960,9 @@ class StellarContinuum():
ebv : float, optional
ebv : float, optional
Dust extinction, by default 0.1
Dust extinction, by default 0.1
"""
"""
def
__init__
(
self
,
config
,
template
,
mag
=
15.0
,
age
=
1.0
,
feh
=
0.0
,
def
__init__
(
self
,
config
,
template
,
mag
=
15.0
,
age
=
1.0
,
feh
=
0.0
,
vel
=
100.0
,
vdisp
=
100.0
,
ebv
=
0.1
):
vel
=
100.0
,
vdisp
=
100.0
,
ebv
=
0.1
):
# Check Input Parameters
# Check Input Parameters
if
(
mag
>
26
)
or
(
mag
<
8
):
if
(
mag
>
26
)
or
(
mag
<
8
):
print
(
"Notice: Your input magnitude (mag) is > 26 mag or < 8 mag."
)
print
(
"Notice: Your input magnitude (mag) is > 26 mag or < 8 mag."
)
...
@@ -986,19 +985,19 @@ class StellarContinuum():
...
@@ -986,19 +985,19 @@ class StellarContinuum():
minloc
=
np
.
argmin
(
abs
(
feh
-
metals
))
minloc
=
np
.
argmin
(
abs
(
feh
-
metals
))
tpls
=
SSP_temp
[:,
:,
minloc
]
tpls
=
SSP_temp
[:,
:,
minloc
]
# fmass = template.fmass_ssp()[:, minloc]
# fmass = template.fmass_ssp()[:, minloc]
# Select age bins
# Select age bins
Ages
=
template
.
age_grid
[:,
0
]
Ages
=
template
.
age_grid
[:,
0
]
minloc
=
np
.
argmin
(
abs
(
age
-
Ages
))
minloc
=
np
.
argmin
(
abs
(
age
-
Ages
))
Stellar
=
tpls
[:,
minloc
]
Stellar
=
tpls
[:,
minloc
]
wave
=
np
.
exp
(
template
.
log_lam_temp
)
wave
=
np
.
exp
(
template
.
log_lam_temp
)
# Broadening caused by Velocity Dispersion
# Broadening caused by Velocity Dispersion
sigma_gal
=
vdisp
/
template
.
velscale
# in pixel
sigma_gal
=
vdisp
/
template
.
velscale
# in pixel
sigma_LSF
=
template
.
LSF
/
template
.
velscale
# in pixel
sigma_LSF
=
template
.
LSF
/
template
.
velscale
# in pixel
if
sigma_gal
>
0
:
if
sigma_gal
>
0
:
sigma_dif
=
np
.
zeros
(
len
(
Stellar
))
sigma_dif
=
np
.
zeros
(
len
(
Stellar
))
idx
=
(
sigma_gal
>
sigma_LSF
)
idx
=
(
sigma_gal
>
sigma_LSF
)
sigma_dif
[
idx
]
=
np
.
sqrt
(
sigma_gal
**
2.
-
sigma_LSF
[
idx
]
**
2.
)
sigma_dif
[
idx
]
=
np
.
sqrt
(
sigma_gal
**
2.
-
sigma_LSF
[
idx
]
**
2.
)
...
@@ -1013,21 +1012,21 @@ class StellarContinuum():
...
@@ -1013,21 +1012,21 @@ class StellarContinuum():
# Dust Reddening
# Dust Reddening
if
np
.
isscalar
(
ebv
):
if
np
.
isscalar
(
ebv
):
flux0
=
reddening
(
wave
,
flux0
,
ebv
=
ebv
)
flux0
=
reddening
(
wave
,
flux0
,
ebv
=
ebv
)
# Redshift
# Redshift
redshift
=
vel
/
3e5
redshift
=
vel
/
3e5
wave_r
=
wave
*
(
1
+
redshift
)
wave_r
=
wave
*
(
1
+
redshift
)
flux
=
np
.
interp
(
config
.
wave
,
wave_r
,
flux0
)
flux
=
np
.
interp
(
config
.
wave
,
wave_r
,
flux0
)
# Calibration
# Calibration
if
np
.
isscalar
(
mag
):
if
np
.
isscalar
(
mag
):
flux
=
calibrate
(
config
.
wave
,
flux
,
mag
,
filtername
=
'SLOAN_SDSS.r'
)
flux
=
calibrate
(
config
.
wave
,
flux
,
mag
,
filtername
=
'SLOAN_SDSS.r'
)
# Convert to input wavelength
# Convert to input wavelength
self
.
wave
=
config
.
wave
self
.
wave
=
config
.
wave
self
.
flux
=
flux
self
.
flux
=
flux
#####################
#####################
# Single Star Spectra
# Single Star Spectra
#####################
#####################
...
@@ -1048,15 +1047,15 @@ class SingleStarTemplate():
...
@@ -1048,15 +1047,15 @@ class SingleStarTemplate():
FWHM_inst
=
config
.
inst_fwhm
FWHM_inst
=
config
.
inst_fwhm
filename
=
data_path
+
'/data/Starlib.XSL.fits'
filename
=
data_path
+
'/data/Starlib.XSL.fits'
hdulist
=
fits
.
open
(
filename
)
hdulist
=
fits
.
open
(
filename
)
lam
=
hdulist
[
1
].
data
[
'Wave'
]
lam
=
hdulist
[
1
].
data
[
'Wave'
]
flux
=
hdulist
[
2
].
data
flux
=
hdulist
[
2
].
data
par
=
hdulist
[
3
].
data
par
=
hdulist
[
3
].
data
lam_range_temp
=
np
.
array
([
3500
,
12000
])
lam_range_temp
=
np
.
array
([
3500
,
12000
])
TemNew
,
log_lam_temp
=
log_rebin
(
lam_range_temp
,
flux
[
1
,
:],
velscale
=
velscale
)[:
2
]
TemNew
,
log_lam_temp
=
log_rebin
(
lam_range_temp
,
flux
[
1
,
:],
velscale
=
velscale
)[:
2
]
# FWHM of XLS templates
# FWHM of XLS templates
Temp_wave
=
np
.
exp
(
log_lam_temp
)
Temp_wave
=
np
.
exp
(
log_lam_temp
)
Temp_FWHM
=
np
.
zeros
(
len
(
log_lam_temp
))
Temp_FWHM
=
np
.
zeros
(
len
(
log_lam_temp
))
...
@@ -1064,9 +1063,9 @@ class SingleStarTemplate():
...
@@ -1064,9 +1063,9 @@ class SingleStarTemplate():
Temp_FWHM
[(
Temp_wave
>=
5330
)
&
(
Temp_wave
<
9440
)]
=
11
*
2.35
/
3e5
*
Temp_wave
[(
Temp_wave
>=
5330
)
&
(
Temp_wave
<
9440
)]
Temp_FWHM
[(
Temp_wave
>=
5330
)
&
(
Temp_wave
<
9440
)]
=
11
*
2.35
/
3e5
*
Temp_wave
[(
Temp_wave
>=
5330
)
&
(
Temp_wave
<
9440
)]
# sigma = 13km/s at 5330 < lambda < 9440
# sigma = 13km/s at 5330 < lambda < 9440
Temp_FWHM
[(
Temp_wave
>=
9440
)]
=
16
*
2.35
/
3e5
*
Temp_wave
[(
Temp_wave
>=
9440
)]
# sigma=16km/s at lambda > 9440
Temp_FWHM
[(
Temp_wave
>=
9440
)]
=
16
*
2.35
/
3e5
*
Temp_wave
[(
Temp_wave
>=
9440
)]
# sigma=16km/s at lambda > 9440
LSF
=
Temp_FWHM
LSF
=
Temp_FWHM
FWHM_eff
=
Temp_FWHM
.
copy
()
# combined FWHM from stellar library and instrument(input)
FWHM_eff
=
Temp_FWHM
.
copy
()
# combined FWHM from stellar library and instrument(input)
if
np
.
isscalar
(
FWHM_inst
):
if
np
.
isscalar
(
FWHM_inst
):
FWHM_eff
[
Temp_FWHM
<
FWHM_inst
]
=
FWHM_inst
FWHM_eff
[
Temp_FWHM
<
FWHM_inst
]
=
FWHM_inst
...
@@ -1094,7 +1093,7 @@ class SingleStarTemplate():
...
@@ -1094,7 +1093,7 @@ class SingleStarTemplate():
self
.
logg_grid
=
par
[
'logg'
]
self
.
logg_grid
=
par
[
'logg'
]
self
.
LSF
=
Temp_FWHM
self
.
LSF
=
Temp_FWHM
self
.
velscale
=
velscale
self
.
velscale
=
velscale
class
SingleStar
():
class
SingleStar
():
...
@@ -1135,34 +1134,34 @@ class SingleStar():
...
@@ -1135,34 +1134,34 @@ class SingleStar():
feh
=
0.81
feh
=
0.81
if
(
feh
<
-
2.69
):
if
(
feh
<
-
2.69
):
raise
Exception
(
'Your input metallicity (feh) is beyond the range of stellar template [-2.69, 0.81]'
)
raise
Exception
(
'Your input metallicity (feh) is beyond the range of stellar template [-2.69, 0.81]'
)
StarTemp
=
template
.
templates
StarTemp
=
template
.
templates
# Select metal bins
# Select metal bins
idx_FeH
=
(
np
.
abs
(
template
.
feh_grid
-
feh
)
<
0.5
)
idx_FeH
=
(
np
.
abs
(
template
.
feh_grid
-
feh
)
<
0.5
)
tpls
=
StarTemp
[:,
idx_FeH
]
tpls
=
StarTemp
[:,
idx_FeH
]
# Select Teff bins
# Select Teff bins
Teff_FeH
=
template
.
teff_grid
[
idx_FeH
]
Teff_FeH
=
template
.
teff_grid
[
idx_FeH
]
minloc
=
np
.
argmin
(
abs
(
teff
-
Teff_FeH
))
minloc
=
np
.
argmin
(
abs
(
teff
-
Teff_FeH
))
starspec
=
tpls
[:,
minloc
]
starspec
=
tpls
[:,
minloc
]
wave
=
np
.
exp
(
template
.
log_lam_temp
)
wave
=
np
.
exp
(
template
.
log_lam_temp
)
# Dust Reddening
# Dust Reddening
if
np
.
isscalar
(
ebv
):
if
np
.
isscalar
(
ebv
):
starspec
=
reddening
(
wave
,
starspec
,
ebv
=
ebv
)
starspec
=
reddening
(
wave
,
starspec
,
ebv
=
ebv
)
# Redshift
# Redshift
redshift
=
vel
/
3e5
redshift
=
vel
/
3e5
wave_r
=
wave
*
(
1
+
redshift
)
wave_r
=
wave
*
(
1
+
redshift
)
flux
=
np
.
interp
(
config
.
wave
,
wave_r
,
starspec
)
flux
=
np
.
interp
(
config
.
wave
,
wave_r
,
starspec
)
# Calibration
# Calibration
if
np
.
isscalar
(
mag
):
if
np
.
isscalar
(
mag
):
flux
=
calibrate
(
config
.
wave
,
flux
,
mag
,
filtername
=
'SLOAN_SDSS.r'
)
flux
=
calibrate
(
config
.
wave
,
flux
,
mag
,
filtername
=
'SLOAN_SDSS.r'
)
# Convert to input wavelength
# Convert to input wavelength
self
.
wave
=
config
.
wave
self
.
wave
=
config
.
wave
self
.
flux
=
flux
self
.
flux
=
flux
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment