Commit 53a9d0a6 authored by Yannick Roehlly's avatar Yannick Roehlly

Add plots to the outputs

Add the best SED plot and the value vs chi2 plot for each model for each
analysed variable.
parent b37be08b
......@@ -25,6 +25,7 @@ TODO: Factorise the way the analysis is done to have general methods in the
import atpy
import numpy as np
from scipy import stats
from matplotlib import pyplot as plt
from . import common
from ..sed.warehouse import create_sed
from import Database
......@@ -143,7 +144,6 @@ class Module(common.AnalysisModule):
# We loop over all the possible theoretical SEDs
for model_index, parameters in enumerate(sed_modules_params):
sed = create_sed(sed_modules, parameters)
# Compute the reduced Chi-square, the galaxy mass (normalisation
......@@ -180,7 +180,7 @@ class Module(common.AnalysisModule):
# Find the model corresponding to the least reduced Chi-square for
# each observation.
# Now we loop over the observations.
for obs_index in range([0]):
for obs_index, obs_name in enumerate(obs_table['id']):
# Find the model corresponding to the least reduced Chi-square;
# if there more than one model with the minimal chi-square value
# only the first is returned.
......@@ -194,18 +194,48 @@ class Module(common.AnalysisModule):
# Plot the best SED
best_sed_lambda_fnu = best_sed.lambda_fnu(
figure = plt.figure()
ax = figure.add_subplot(111)
best_norm_factor * best_sed_lambda_fnu[1],
ax.loglog([effective_wavelength[name] for name in filter_list],
[obs_table[name][obs_index] for name in filter_list],
ax.set_xlabel('Wavelength [nm]')
ax.set_ylabel('Flux [mJy]')
ax.set_title(obs_name +
' best fitting SED - chi2min=' +
figure.savefig(obs_name + '_bestSED.pdf')
# Compute the statistics for the desired variables.
for index, variable in enumerate(['galaxy_mass'] +
# The 'variable' axis in comp_table as chi2 and probability
# values at the beginnng.
# values at the beginning.
idx = index + 2
mean, sigma = w_mean_sigma(comp_table[:, obs_index, idx],
comp_table[:, obs_index, 1])
results[variable + '_err'].append(sigma)
# We plot all the (value, chi2min) tuples.
figure = plt.figure()
ax = figure.add_subplot(111)
ax.plot(comp_table[:, obs_index, idx],
comp_table[:, obs_index, 0],
ax.set_ylabel('reduced chi square')
figure.savefig(obs_name + '_' + variable + '_plot.pdf')
# Write the results to the fits file
result_table = atpy.Table()
for variable in (['galaxy_mass'] + analysed_variables):
# -*- coding: utf-8 -*-
Copyright (C) 2012 Centre de données Astrophysiques de Marseille
Copyright (C) 2012, 2013 Centre de données Astrophysiques de Marseille
Licensed under the CeCILL-v2 licence - see Licence_CeCILL_V2-en.txt
@author: Yannick Roehlly <>
......@@ -30,7 +30,7 @@ setup(
install_requires=['numpy', 'scipy', 'sqlalchemy'],
requires=['numpy', 'scipy', 'sqlalchemy', 'atpy'],
requires=['numpy', 'scipy', 'sqlalchemy', 'atpy', 'matplotlib'],
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment