SED: Adding a option to select which physical component (plot series) be enabled or disabled.

Use the --series <series1 series2...> option to indicate one o more of this series:
stellar_attenuated,
stellar_unattenuated,
nebular,
dust,
agn,
radio,
model.

If the --seriesdisabled flag is used, then all available series will be enabled, except the ones that are indicated in the --series option. If not, then only the series indicated in the --series option will be enabled.
parent 6e647f94
......@@ -14,7 +14,7 @@ import multiprocessing as mp
from pcigale.session.configuration import Configuration
from .plot_types.chi2 import chi2 as chi2_action
from .plot_types.pdf import pdf as pdf_action
from .plot_types.sed import sed as sed_action
from .plot_types.sed import sed as sed_action, AVAILABLE_SERIES
from .plot_types.mock import mock as mock_action
__version__ = "0.2-alpha"
......@@ -70,6 +70,8 @@ def main():
sed_parser.add_argument('--yrange', dest='yrange', default=':',
type=parser_range,
help='Format [<min>]:[<max>], for plot flux axis')
sed_parser.add_argument('--series', dest='series', nargs='*')
sed_parser.add_argument('--seriesdisabled', dest='seriesdisabled', action='store_true')
sed_parser.set_defaults(parser='sed')
mock_parser = subparsers.add_parser('mock', help=mock_action.__doc__)
......@@ -93,6 +95,14 @@ def main():
elif args.parser == 'pdf':
pdf_action(config, outdir)
elif args.parser == 'sed':
sed_action(config, args.type, args.nologo, args.xrange, args.yrange, outdir)
if not args.series:
series = AVAILABLE_SERIES
else:
if args.seriesdisabled:
series = [series for series in AVAILABLE_SERIES if series not in args.series]
else:
series = args.series
sed_action(config, args.type, args.nologo, args.xrange, args.yrange,
series, outdir)
elif args.parser == 'mock':
mock_action(config, args.nologo, outdir)
......@@ -32,6 +32,16 @@ MOCK_RESULTS = "results_mock.fits"
PLOT_L_MIN = 0.1
PLOT_L_MAX = 5e5
AVAILABLE_SERIES = [
'stellar_attenuated',
'stellar_unattenuated',
'nebular',
'dust',
'agn',
'radio',
'model'
]
def pool_initializer(counter):
"""Initializer of the pool of processes to share variables between workers.
......@@ -46,7 +56,7 @@ def pool_initializer(counter):
gbl_counter = counter
def sed(config, sed_type, nologo, xrange, yrange, outdir):
def sed(config, sed_type, nologo, xrange, yrange, series, outdir):
"""Plot the best SED with associated observed and modelled fluxes.
"""
obs = read_table(path.join(path.dirname(outdir), config.configuration['data_file']))
......@@ -65,12 +75,12 @@ def sed(config, sed_type, nologo, xrange, yrange, outdir):
initargs=(counter,)) as pool:
pool.starmap(_sed_worker, zip(
obs, mod, repeat(filters), repeat(sed_type), repeat(logo),
repeat(xrange), repeat(yrange), repeat(outdir)))
repeat(xrange), repeat(yrange), repeat(series), repeat(outdir)))
pool.close()
pool.join()
def _sed_worker(obs, mod, filters, sed_type, logo, xrange, yrange, outdir):
def _sed_worker(obs, mod, filters, sed_type, logo, xrange, yrange, series, outdir):
"""Plot the best SED with the associated fluxes in bands
Parameters
......@@ -92,6 +102,7 @@ def _sed_worker(obs, mod, filters, sed_type, logo, xrange, yrange, outdir):
Do not add the logo when set to False.
xrange: tuple(float|boolean, float|boolean)
yrange: tuple(float|boolean, float|boolean)
series: list
outdir: string
The absolute path to outdir
......@@ -153,33 +164,37 @@ def _sed_worker(obs, mod, filters, sed_type, logo, xrange, yrange, outdir):
ax2 = plt.subplot(gs[1])
# Stellar emission
if 'nebular.absorption_young' in sed.columns:
ax1.loglog(wavelength_spec[wsed],
(sed['stellar.young'][wsed] +
sed['attenuation.stellar.young'][wsed] +
sed['nebular.absorption_young'][wsed] +
sed['stellar.old'][wsed] +
sed['attenuation.stellar.old'][wsed] +
sed['nebular.absorption_old'][wsed]),
label="Stellar attenuated ", color='orange',
marker=None, nonposy='clip', linestyle='-',
linewidth=0.5)
else:
if 'stellar_attenuated' in series:
if 'nebular.absorption_young' in sed.columns:
ax1.loglog(wavelength_spec[wsed],
(sed['stellar.young'][wsed] +
sed['attenuation.stellar.young'][wsed] +
sed['nebular.absorption_young'][wsed] +
sed['stellar.old'][wsed] +
sed['attenuation.stellar.old'][wsed] +
sed['nebular.absorption_old'][wsed]),
label="Stellar attenuated ", color='orange',
marker=None, nonposy='clip', linestyle='-',
linewidth=0.5)
else:
ax1.loglog(wavelength_spec[wsed],
(sed['stellar.young'][wsed] +
sed['attenuation.stellar.young'][wsed] +
sed['stellar.old'][wsed] +
sed['attenuation.stellar.old'][wsed]),
label="Stellar attenuated ", color='orange',
marker=None, nonposy='clip', linestyle='-',
linewidth=0.5)
if 'stellar_unattenuated' in series:
ax1.loglog(wavelength_spec[wsed],
(sed['stellar.young'][wsed] +
sed['attenuation.stellar.young'][wsed] +
sed['stellar.old'][wsed] +
sed['attenuation.stellar.old'][wsed]),
label="Stellar attenuated ", color='orange',
marker=None, nonposy='clip', linestyle='-',
linewidth=0.5)
ax1.loglog(wavelength_spec[wsed],
(sed['stellar.old'][wsed] +
sed['stellar.young'][wsed]),
label="Stellar unattenuated", color='b', marker=None,
nonposy='clip', linestyle='--', linewidth=0.5)
(sed['stellar.old'][wsed] +
sed['stellar.young'][wsed]),
label="Stellar unattenuated", color='b', marker=None,
nonposy='clip', linestyle='--', linewidth=0.5)
# Nebular emission
if 'nebular.lines_young' in sed.columns:
if 'nebular' in series and 'nebular.lines_young' in sed.columns:
ax1.loglog(wavelength_spec[wsed],
(sed['nebular.lines_young'][wsed] +
sed['nebular.lines_old'][wsed] +
......@@ -191,20 +206,23 @@ def _sed_worker(obs, mod, filters, sed_type, logo, xrange, yrange, outdir):
sed['attenuation.nebular.continuum_old'][wsed]),
label="Nebular emission", color='y', marker=None,
nonposy='clip', linewidth=.5)
# Dust emission Draine & Li
if 'dust.Umin_Umin' in sed.columns:
if 'dust' in series and 'dust.Umin_Umin' in sed.columns:
ax1.loglog(wavelength_spec[wsed],
(sed['dust.Umin_Umin'][wsed] +
sed['dust.Umin_Umax'][wsed]),
label="Dust emission", color='r', marker=None,
nonposy='clip', linestyle='-', linewidth=0.5)
# Dust emission Dale
if 'dust' in sed.columns:
if 'dust' in series and 'dust' in sed.columns:
ax1.loglog(wavelength_spec[wsed], sed['dust'][wsed],
label="Dust emission", color='r', marker=None,
nonposy='clip', linestyle='-', linewidth=0.5)
# AGN emission Fritz
if 'agn.fritz2006_therm' in sed.columns:
if 'agn' in series and 'agn.fritz2006_therm' in sed.columns:
ax1.loglog(wavelength_spec[wsed],
(sed['agn.fritz2006_therm'][wsed] +
sed['agn.fritz2006_scatt'][wsed] +
......@@ -212,16 +230,17 @@ def _sed_worker(obs, mod, filters, sed_type, logo, xrange, yrange, outdir):
label="AGN emission", color='g', marker=None,
nonposy='clip', linestyle='-', linewidth=0.5)
# Radio emission
if 'radio_nonthermal' in sed.columns:
if 'radio' in series and 'radio_nonthermal' in sed.columns:
ax1.loglog(wavelength_spec[wsed],
sed['radio_nonthermal'][wsed],
label="Radio nonthermal", color='brown',
marker=None, nonposy='clip', linestyle='-',
linewidth=0.5)
ax1.loglog(wavelength_spec[wsed], sed['L_lambda_total'][wsed],
label="Model spectrum", color='k', nonposy='clip',
linestyle='-', linewidth=1.5)
if 'model' in series:
ax1.loglog(wavelength_spec[wsed], sed['L_lambda_total'][wsed],
label="Model spectrum", color='k', nonposy='clip',
linestyle='-', linewidth=1.5)
ax1.set_autoscale_on(False)
s = np.argsort(filters_wl)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment