Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cigale
CIGALE
Commits
16147565
Commit
16147565
authored
Mar 11, 2014
by
Médéric Boquien
Browse files
Cleanup of the Fritz modules to make things more readable and respect the PEP8.
parent
6c5f54d8
Changes
4
Hide whitespace changes
Inline
Side-by-side
database_builder/__init__.py
View file @
16147565
...
...
@@ -459,25 +459,21 @@ def build_dl2007(base):
def
build_fritz2006
(
base
):
fritz2006_dir
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'fritz2006/'
)
# Parameters of Fritz+2006
psy
=
[
0.001
,
10.100
,
20.100
,
30.100
,
40.100
,
50.100
,
60.100
,
70.100
,
80.100
,
89.990
]
# Viewing angle in degrees
opening_angle
=
[
"20"
,
"40"
,
"60"
]
# Theta = 2*(90 - opening_angle)
80.100
,
89.990
]
# Viewing angle in degrees
opening_angle
=
[
"20"
,
"40"
,
"60"
]
# Theta = 2*(90 - opening_angle)
gamma
=
[
"0.0"
,
"2.0"
,
"4.0"
,
"6.0"
]
beta
=
[
"-1.00"
,
"-0.75"
,
"-0.50"
,
"-0.25"
,
"0.00"
]
tau
=
[
"0.1"
,
"0.3"
,
"0.6"
,
"1.0"
,
"2.0"
,
"3.0"
,
"6.0"
,
"10.0"
]
r_ratio
=
[
"10"
,
"30"
,
"60"
,
"100"
,
"150"
]
r_ratio
=
[
"10"
,
"30"
,
"60"
,
"100"
,
"150"
]
# Read and convert the wavelength
datafile
=
open
(
fritz2006_dir
+
"ct{}al{}be{}ta{}rm{}.tot"
.
format
(
opening_angle
[
0
],
gamma
[
0
],
beta
[
0
],
tau
[
0
],
r_ratio
[
0
]))
datafile
=
open
(
fritz2006_dir
+
"ct{}al{}be{}ta{}rm{}.tot"
.
format
(
opening_angle
[
0
],
gamma
[
0
],
beta
[
0
],
tau
[
0
],
r_ratio
[
0
]))
data
=
""
.
join
(
datafile
.
readlines
()[
-
178
:])
datafile
.
close
()
wave
=
np
.
genfromtxt
(
io
.
BytesIO
(
data
.
encode
()),
usecols
=
(
0
))
...
...
@@ -486,55 +482,47 @@ def build_fritz2006(base):
nskip
=
28
blocksize
=
178
for
oa
in
opening_angle
:
for
gam
in
gamma
:
for
be
in
beta
:
for
ta
in
tau
:
for
rm
in
r_ratio
:
filename
=
fritz2006_dir
+
"ct{}al{}be{}ta{}rm{}.tot"
.
format
(
oa
,
gam
,
be
,
ta
,
rm
)
print
(
"Importing {}..."
.
format
(
filename
))
try
:
datafile
=
open
(
filename
)
except
IOError
:
continue
data
=
datafile
.
readlines
()
datafile
.
close
()
for
n
in
range
(
len
(
psy
)):
block
=
data
[
nskip
+
blocksize
*
n
+
4
*
(
n
+
1
)
-
1
:
nskip
+
blocksize
*
(
n
+
1
)
+
4
*
(
n
+
1
)
-
1
]
lumin_therm
,
lumin_scatt
,
lumin_agn
=
np
.
genfromtxt
(
io
.
BytesIO
(
""
.
join
(
block
).
encode
()),
usecols
=
(
2
,
3
,
4
),
unpack
=
True
)
# Remove NaN
lumin_therm
=
np
.
nan_to_num
(
lumin_therm
)
lumin_scatt
=
np
.
nan_to_num
(
lumin_scatt
)
lumin_agn
=
np
.
nan_to_num
(
lumin_agn
)
# Conversion from erg/s/microns to W/nm
lumin_therm
*=
1e-4
lumin_scatt
*=
1e-4
lumin_agn
*=
1e-4
# Normalization of the lumin_therm to 1W
norm
=
np
.
trapz
(
lumin_therm
,
x
=
wave
)
lumin_therm
=
lumin_therm
/
norm
lumin_scatt
=
lumin_scatt
/
norm
lumin_agn
=
lumin_agn
/
norm
base
.
add_fritz2006
(
Fritz2006
(
rm
,
ta
,
be
,
gam
,
oa
,
psy
[
n
],
wave
,
lumin_therm
,
lumin_scatt
,
lumin_agn
))
iter_params
=
((
oa
,
gam
,
be
,
ta
,
rm
)
for
oa
in
opening_angle
for
gam
in
gamma
for
be
in
beta
for
ta
in
tau
for
rm
in
r_ratio
)
for
params
in
iter_params
:
filename
=
fritz2006_dir
+
"ct{}al{}be{}ta{}rm{}.tot"
.
format
(
*
params
)
print
(
"Importing {}..."
.
format
(
filename
))
try
:
datafile
=
open
(
filename
)
except
IOError
:
continue
data
=
datafile
.
readlines
()
datafile
.
close
()
for
n
in
range
(
len
(
psy
)):
block
=
data
[
nskip
+
blocksize
*
n
+
4
*
(
n
+
1
)
-
1
:
nskip
+
blocksize
*
(
n
+
1
)
+
4
*
(
n
+
1
)
-
1
]
lumin_therm
,
lumin_scatt
,
lumin_agn
=
np
.
genfromtxt
(
io
.
BytesIO
(
""
.
join
(
block
).
encode
()),
usecols
=
(
2
,
3
,
4
),
unpack
=
True
)
# Remove NaN
lumin_therm
=
np
.
nan_to_num
(
lumin_therm
)
lumin_scatt
=
np
.
nan_to_num
(
lumin_scatt
)
lumin_agn
=
np
.
nan_to_num
(
lumin_agn
)
# Conversion from erg/s/microns to W/nm
lumin_therm
*=
1e-4
lumin_scatt
*=
1e-4
lumin_agn
*=
1e-4
# Normalization of the lumin_therm to 1W
norm
=
np
.
trapz
(
lumin_therm
,
x
=
wave
)
lumin_therm
=
lumin_therm
/
norm
lumin_scatt
=
lumin_scatt
/
norm
lumin_agn
=
lumin_agn
/
norm
base
.
add_fritz2006
(
Fritz2006
(
params
[
4
],
params
[
3
],
params
[
2
],
params
[
1
],
params
[
0
],
psy
[
n
],
wave
,
lumin_therm
,
lumin_scatt
,
lumin_agn
))
def
build_nebular
(
base
):
lines_dir
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'nebular/'
)
...
...
pcigale/creation_modules/fritz2006.py
View file @
16147565
...
...
@@ -65,14 +65,6 @@ class Fritz2006(CreationModule):
"Contribution of the AGN"
""
,
None
)),
(
'attenuation_value_keys'
,
(
'string'
,
"Keys of the SED information dictionary where the module will "
"look for the attenuation (in W) to re-emit. You can give several "
"keys separated with a & (don't use commas), a re-emission "
"contribution will be added for each key."
,
"attenuation"
))
])
...
...
@@ -81,7 +73,6 @@ class Fritz2006(CreationModule):
(
'L_AGN'
,
'Luminosity of the AGN contribution'
)
])
def
_init_code
(
self
):
"""Get the template set out of the database"""
r_ratio
=
self
.
parameters
[
"r_ratio"
]
...
...
@@ -93,9 +84,7 @@ class Fritz2006(CreationModule):
with
Database
()
as
base
:
self
.
fritz2006
=
base
.
get_fritz2006
(
r_ratio
,
tau
,
beta
,
gamma
,
opening_angle
,
psy
)
opening_angle
,
psy
)
def
process
(
self
,
sed
):
"""Add the IR re-emission contributions
...
...
@@ -108,10 +97,9 @@ class Fritz2006(CreationModule):
"""
if
'dust.luminosity'
not
in
sed
.
info
.
keys
():
sed
.
add_info
(
'dust.luminosity'
,
1.
,
True
)
sed
.
add_info
(
'dust.luminosity'
,
1.
,
True
)
luminosity
=
sed
.
info
[
'dust.luminosity'
]
fracAGN
=
self
.
parameters
[
"fracAGN"
]
sed
.
add_module
(
self
.
name
,
self
.
parameters
)
...
...
@@ -123,27 +111,15 @@ class Fritz2006(CreationModule):
sed
.
add_info
(
'psy'
,
self
.
parameters
[
"psy"
])
sed
.
add_info
(
'fracAGN'
,
self
.
parameters
[
"fracAGN"
])
# Compute the AGN luminosity
L_AGN
=
fracAGN
*
(
luminosity
+
1
)
#sed.add_info("L_AGN" + self.postfix, self.parameters["L_AGN"])
sed
.
add_contribution
(
'agn_fritz2006_therm'
,
self
.
fritz2006
.
wave
,
L_AGN
*
self
.
fritz2006
.
lumin_therm
)
sed
.
add_contribution
(
'agn_fritz2006_scatt'
,
self
.
fritz2006
.
wave
,
L_AGN
*
self
.
fritz2006
.
lumin_scatt
)
sed
.
add_contribution
(
'agn_fritz2006_agn'
,
self
.
fritz2006
.
wave
,
L_AGN
*
self
.
fritz2006
.
lumin_agn
)
sed
.
add_contribution
(
'agn_fritz2006_therm'
,
self
.
fritz2006
.
wave
,
L_AGN
*
self
.
fritz2006
.
lumin_therm
)
sed
.
add_contribution
(
'agn_fritz2006_scatt'
,
self
.
fritz2006
.
wave
,
L_AGN
*
self
.
fritz2006
.
lumin_scatt
)
sed
.
add_contribution
(
'agn_fritz2006_agn'
,
self
.
fritz2006
.
wave
,
L_AGN
*
self
.
fritz2006
.
lumin_agn
)
# CreationModule to be returned by get_module
Module
=
Fritz2006
pcigale/data/__init__.py
View file @
16147565
...
...
@@ -17,7 +17,7 @@ SqlAlchemy ORM to store the data in a unique SQLite3 database.
import
pkg_resources
from
sqlalchemy
import
(
create_engine
,
exc
,
Column
,
String
,
Text
,
Float
,
Integer
,
PickleType
)
Float
,
PickleType
)
from
sqlalchemy.ext.declarative
import
declarative_base
from
sqlalchemy.orm
import
class_mapper
,
sessionmaker
import
numpy
as
np
...
...
@@ -187,7 +187,7 @@ class _Fritz2006(BASE):
wave
=
Column
(
PickleType
)
lumin_therm
=
Column
(
PickleType
)
lumin_scatt
=
Column
(
PickleType
)
lumin_agn
=
Column
(
PickleType
)
lumin_agn
=
Column
(
PickleType
)
def
__init__
(
self
,
agn
):
self
.
r_ratio
=
agn
.
r_ratio
...
...
@@ -201,6 +201,7 @@ class _Fritz2006(BASE):
self
.
lumin_scatt
=
agn
.
lumin_scatt
self
.
lumin_agn
=
agn
.
lumin_agn
class
_NebularLines
(
BASE
):
"""Storage for line templates
"""
...
...
@@ -645,7 +646,7 @@ class Database(object):
lumin_therm : array of float
Luminosity density of the dust torus at each wavelength in W/nm.
lumin_scatt : array of float
Luminosity density of the scattered emission at each wavelength
Luminosity density of the scattered emission at each wavelength
in W/nm.
lumin_agn : array of float
Luminosity density of the central AGN at each wavelength in W/nm.
...
...
@@ -668,12 +669,12 @@ class Database(object):
filter
(
_Fritz2006
.
gamma
==
gamma
).
filter
(
_Fritz2006
.
opening_angle
==
opening_angle
).
filter
(
_Fritz2006
.
psy
==
psy
).
first
())
first
())
if
result
:
return
Fritz2006
(
result
.
r_ratio
,
result
.
tau
,
result
.
beta
,
result
.
gamma
,
result
.
opening_angle
,
result
.
psy
,
result
.
wave
,
result
.
lumin_therm
,
result
.
lumin_scatt
,
result
.
lumin_agn
)
result
.
gamma
,
result
.
opening_angle
,
result
.
psy
,
result
.
wave
,
result
.
lumin_therm
,
result
.
lumin_scatt
,
result
.
lumin_agn
)
else
:
raise
DatabaseLookupError
(
"The Fritz2006 model is not in the database."
)
...
...
pcigale/data/fritz2006.py
View file @
16147565
...
...
@@ -12,7 +12,8 @@ class Fritz2006(object):
"""
def
__init__
(
self
,
r_ratio
,
tau
,
beta
,
gamma
,
opening_angle
,
psy
,
wave
,
lumin_therm
,
lumin_scatt
,
lumin_agn
):
def
__init__
(
self
,
r_ratio
,
tau
,
beta
,
gamma
,
opening_angle
,
psy
,
wave
,
lumin_therm
,
lumin_scatt
,
lumin_agn
):
"""Create a new AGN model
Parameters
...
...
@@ -30,7 +31,7 @@ class Fritz2006(object):
psy : float
Angle between AGN axis and line of sight.
"""
self
.
r_ratio
=
r_ratio
self
.
tau
=
tau
self
.
beta
=
beta
...
...
@@ -40,4 +41,4 @@ class Fritz2006(object):
self
.
wave
=
wave
self
.
lumin_therm
=
lumin_therm
self
.
lumin_scatt
=
lumin_scatt
self
.
lumin_agn
=
lumin_agn
\ No newline at end of file
self
.
lumin_agn
=
lumin_agn
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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