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
cigale
CIGALE
Commits
eed20b63
Commit
eed20b63
authored
Jan 30, 2014
by
Yannick Roehlly
Browse files
Implement context manager in database
parent
8cd6338e
Changes
11
Hide whitespace changes
Inline
Side-by-side
pcigale/analysis_modules/psum.py
View file @
eed20b63
...
...
@@ -177,12 +177,11 @@ class Psum(AnalysisModule):
if
not
name
.
endswith
(
'_err'
)]
transmission
=
{}
effective_wavelength
=
{}
base
=
Database
()
for
name
in
filter_list
:
filt
=
base
.
get_filter
(
name
)
transmission
[
name
]
=
filt
.
trans_table
effective_wavelength
[
name
]
=
filt
.
effective_wavelength
base
.
close
()
with
Database
()
as
base
:
for
name
in
filter_list
:
filt
=
base
.
get_filter
(
name
)
transmission
[
name
]
=
filt
.
trans_table
effective_wavelength
[
name
]
=
filt
.
effective_wavelength
# We get the redshift module.
redshift_module
=
get_module
(
redshift_module_name
,
...
...
pcigale/analysis_modules/savefluxes.py
View file @
eed20b63
...
...
@@ -97,9 +97,8 @@ class SaveFluxes(AnalysisModule):
# Get the filters in the database
filter_names
=
[
name
for
name
in
column_list
if
not
name
.
endswith
(
'_err'
)]
base
=
Database
()
filter_list
=
[
base
.
get_filter
(
name
)
for
name
in
filter_names
]
base
.
close
()
with
Database
()
as
base
:
filter_list
=
[
base
.
get_filter
(
name
)
for
name
in
filter_names
]
# Columns of the output table
out_columns
=
[]
...
...
pcigale/creation_modules/bc03.py
View file @
eed20b63
...
...
@@ -66,9 +66,8 @@ class BC03(CreationModule):
"""Read the SSP from the database."""
imf
=
self
.
parameters
[
"imf"
]
metallicity
=
float
(
self
.
parameters
[
"metallicity"
])
database
=
Database
()
self
.
ssp
=
database
.
get_ssp_bc03
(
imf
,
metallicity
)
database
.
session
.
close_all
()
with
Database
()
as
database
:
self
.
ssp
=
database
.
get_ssp_bc03
(
imf
,
metallicity
)
def
process
(
self
,
sed
):
"""Add the convolution of a Bruzual and Charlot SSP to the SED
...
...
pcigale/creation_modules/dale2014.py
View file @
eed20b63
...
...
@@ -66,10 +66,9 @@ class Dale2014(CreationModule):
"""
alpha
=
self
.
parameters
[
"alpha"
]
database
=
Database
()
self
.
model_sb
=
database
.
get_dale2014
(
0.00
,
alpha
)
self
.
model_quasar
=
database
.
get_dale2014
(
1.00
,
alpha
)
database
.
session
.
close_all
()
with
Database
()
as
database
:
self
.
model_sb
=
database
.
get_dale2014
(
0.00
,
alpha
)
self
.
model_quasar
=
database
.
get_dale2014
(
1.00
,
alpha
)
def
process
(
self
,
sed
):
"""Add the IR re-emission contributions
...
...
pcigale/creation_modules/dh2002.py
View file @
eed20b63
...
...
@@ -48,9 +48,8 @@ class DH2002(CreationModule):
def
_init_code
(
self
):
"""Get the template set out of the database"""
database
=
Database
()
self
.
dh2002
=
database
.
get_dh2002_infrared_templates
()
database
.
session
.
close_all
()
with
Database
()
as
database
:
self
.
dh2002
=
database
.
get_dh2002_infrared_templates
()
def
process
(
self
,
sed
):
"""Add the IR re-emission contributions
...
...
pcigale/creation_modules/dl2007.py
View file @
eed20b63
...
...
@@ -76,10 +76,9 @@ class DL2007(CreationModule):
umax
=
self
.
parameters
[
"umax"
]
gamma
=
self
.
parameters
[
"gamma"
]
database
=
Database
()
self
.
model_minmin
=
database
.
get_dl2007
(
qpah
,
umin
,
umin
)
self
.
model_minmax
=
database
.
get_dl2007
(
qpah
,
umin
,
umax
)
database
.
session
.
close_all
()
with
Database
()
as
database
:
self
.
model_minmin
=
database
.
get_dl2007
(
qpah
,
umin
,
umin
)
self
.
model_minmax
=
database
.
get_dl2007
(
qpah
,
umin
,
umax
)
# The models in memory are in W/nm for 1 kg of dust. At the same time
# we need to normalize them to 1 W here to easily scale them from the
...
...
pcigale/creation_modules/dustatt_calzleit.py
View file @
eed20b63
...
...
@@ -258,10 +258,9 @@ class CalzLeit(CreationModule):
filter_list
=
[
item
.
strip
()
for
item
in
self
.
parameters
[
"filters"
].
split
(
"&"
)]
self
.
filters
=
{}
base
=
Database
()
for
filter_name
in
filter_list
:
self
.
filters
[
filter_name
]
=
base
.
get_filter
(
filter_name
)
base
.
close
()
with
Database
()
as
base
:
for
filter_name
in
filter_list
:
self
.
filters
[
filter_name
]
=
base
.
get_filter
(
filter_name
)
def
process
(
self
,
sed
):
"""Add the CCM dust attenuation to the SED.
...
...
pcigale/creation_modules/dustatt_powerlaw.py
View file @
eed20b63
...
...
@@ -182,10 +182,9 @@ class PowerLawAtt(CreationModule):
filter_list
=
[
item
.
strip
()
for
item
in
self
.
parameters
[
"filters"
].
split
(
"&"
)]
self
.
filters
=
{}
base
=
Database
()
for
filter_name
in
filter_list
:
self
.
filters
[
filter_name
]
=
base
.
get_filter
(
filter_name
)
base
.
close
()
with
Database
()
as
base
:
for
filter_name
in
filter_list
:
self
.
filters
[
filter_name
]
=
base
.
get_filter
(
filter_name
)
def
process
(
self
,
sed
):
"""Add the CCM dust attenuation to the SED.
...
...
pcigale/creation_modules/m2005.py
View file @
eed20b63
...
...
@@ -104,9 +104,8 @@ class M2005(CreationModule):
"""Read the SSP from the database."""
imf
=
self
.
parameters
[
"imf"
]
metallicity
=
float
(
self
.
parameters
[
"metallicity"
])
database
=
Database
()
self
.
ssp
=
database
.
get_ssp_m2005
(
imf
,
metallicity
)
database
.
session
.
close_all
()
with
Database
()
as
database
:
self
.
ssp
=
database
.
get_ssp_m2005
(
imf
,
metallicity
)
def
process
(
self
,
sed
):
"""Add the convolution of a Maraston 2005 SSP to the SED
...
...
pcigale/data/__init__.py
View file @
eed20b63
...
...
@@ -217,6 +217,12 @@ class Database(object):
self
.
session
=
SESSION
()
self
.
is_writable
=
writable
def
__enter__
(
self
):
return
self
def
__exit__
(
self
,
exc_type
,
exc_val
,
exc_tb
):
self
.
close
()
def
upgrade_base
(
self
):
""" Upgrade the table schemas in the database
"""
...
...
pcigale/session/configuration.py
View file @
eed20b63
...
...
@@ -150,9 +150,8 @@ class Configuration(object):
"""
# Getting the list of the filters available in pcigale database
base
=
Database
()
filter_list
=
base
.
get_filter_list
()[
0
]
base
.
close
()
with
Database
()
as
base
:
filter_list
=
base
.
get_filter_list
()[
0
]
# Finding the known filters in the data table
obs_table
=
atpy
.
Table
(
self
.
config
[
'data_file'
],
verbose
=
False
)
...
...
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