Commit 9f11896b authored by Médéric Boquien's avatar Médéric Boquien Committed by Yannick Roehlly

PEP8-ification.

parent 529766a9
......@@ -319,6 +319,7 @@ def build_dh2002(base):
base.add_dh2002_infrared_templates(data)
def build_dale2014(base):
dh2002_dir = os.path.join(os.path.dirname(__file__), 'dh2002/')
......@@ -332,13 +333,15 @@ def build_dale2014(base):
first_template = np.genfromtxt(dale2014_dir + 'spectra.0.00AGN.dat')
wave = first_template[:, 0] * 1E3
# Getting the stellar emission and interpolate it at the same wavelength grid
stell_emission_file = np.genfromtxt(dale2014_dir + 'stellar_SED_age13Gyr_tau10Gyr.spec')
# Getting the stellar emission and interpolate it at the same wavelength
# grid
stell_emission_file = np.genfromtxt(dale2014_dir +
'stellar_SED_age13Gyr_tau10Gyr.spec')
# A -> to nm
wave_stell = stell_emission_file[:,0] * 0.1
wave_stell = stell_emission_file[:, 0] * 0.1
# W/A -> W/nm
stell_emission = stell_emission_file[:,1] * 10
stell_emission_interp = np.interp(wave,wave_stell,stell_emission)
stell_emission = stell_emission_file[:, 1] * 10
stell_emission_interp = np.interp(wave, wave_stell, stell_emission)
# The models are in nuFnu and contain stellar emission.
# We convert this to W/nm and remove the stellar emission.
......@@ -351,14 +354,15 @@ def build_dale2014(base):
data = "".join(datafile.readlines())
datafile.close()
for al in range(1,len(alpha_grid),1):
lumin_with_stell = np.genfromtxt(io.BytesIO(data.encode()), usecols=(al))
lumin_with_stell = pow(10,lumin_with_stell) / wave
for al in range(1, len(alpha_grid), 1):
lumin_with_stell = np.genfromtxt(io.BytesIO(data.encode()),
usecols=(al))
lumin_with_stell = pow(10, lumin_with_stell) / wave
constant = lumin_with_stell[7] / stell_emission_interp[7]
lumin = lumin_with_stell - stell_emission_interp * constant
lumin[lumin<0] = 0
lumin[wave<2E3] = 0
norm = np.trapz(lumin, x = wave)
lumin[lumin < 0] = 0
lumin[wave < 2E3] = 0
norm = np.trapz(lumin, x=wave)
lumin = lumin/norm
base.add_dale2014(Dale2014(fraction, alpha_grid[al-1], wave, lumin))
......@@ -371,14 +375,15 @@ def build_dale2014(base):
data = "".join(datafile.readlines())
datafile.close()
for al in range(1,len(alpha_grid),1):
for al in range(1, len(alpha_grid), 1):
lumin_quasar = np.genfromtxt(io.BytesIO(data.encode()), usecols=(al))
lumin_quasar = pow(10,lumin_quasar) / wave
lumin_quasar[lumin_quasar<0] = 0
norm = np.trapz(lumin_quasar, x = wave)
lumin_quasar = lumin_quasar/norm
lumin_quasar = pow(10, lumin_quasar) / wave
lumin_quasar[lumin_quasar < 0] = 0
norm = np.trapz(lumin_quasar, x=wave)
lumin_quasar = lumin_quasar / norm
base.add_dale2014(Dale2014(fraction, alpha_grid[al-1], wave, lumin_quasar))
base.add_dale2014(Dale2014(fraction, alpha_grid[al-1], wave,
lumin_quasar))
def build_dl2007(base):
......
# -*- coding: utf-8 -*-
# Adjust Python path to load the module
import sys, os
import os
import sys
sys.path.insert(0, os.path.abspath('..'))
# Use astropy Sphinx configuration
......@@ -36,7 +37,7 @@ version = pcigale.__version__.split('-', 1)[0]
# The full version, including alpha/beta/rc tags.
release = pcigale.__version__
# -- Options for HTML output ---------------------------------------------------
# -- Options for HTML output --------------------------------------------------
# A NOTE ON HTML THEMES
# The global astropy configuration uses a custom theme, 'bootstrap-astropy',
......@@ -74,7 +75,7 @@ html_title = '{0} v{1}'.format(project, release)
htmlhelp_basename = project + 'doc'
# -- Options for LaTeX output --------------------------------------------------
# -- Options for LaTeX output -------------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
......@@ -88,7 +89,8 @@ latex_elements = {
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
# (source start file, target name, title, author, documentclass
# [howto/manual]).
latex_documents = [
('index', 'pcigale.tex', u'pcigale Documentation',
u'pcigale team', 'manual'),
......@@ -115,7 +117,7 @@ latex_documents = [
#latex_domain_indices = True
# -- Options for manual page output --------------------------------------------
# -- Options for manual page output -------------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
......@@ -128,7 +130,7 @@ man_pages = [
#man_show_urls = False
# -- Options for Texinfo output ------------------------------------------------
# -- Options for Texinfo output -----------------------------------------------
# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
......@@ -152,7 +154,7 @@ texinfo_documents = [
#texinfo_no_detailmenu = False
# -- Options for Epub output ---------------------------------------------------
# -- Options for Epub output --------------------------------------------------
# Bibliographic Dublin Core info.
epub_title = u'pcigale documentation'
......@@ -209,7 +211,7 @@ epub_copyright = u'Laboratoire d\'Astrophysique de Marseille'
# If false, no index is generated.
#epub_use_index = True
## -- Options for the edit_on_github extension ----------------------------------------
## -- Options for the edit_on_github extension --------------------------------
#
#extensions += ['astropy.sphinx.ext.edit_on_github']
#
......@@ -224,4 +226,3 @@ epub_copyright = u'Laboratoire d\'Astrophysique de Marseille'
#
#edit_on_github_source_root = ""
#edit_on_github_doc_root = "docs"
......@@ -29,8 +29,8 @@ def check(config):
"Check the configuration."
# TODO : Check if all the parameters that don't have default values are
# given for each module.
print ("With this configuration, pcigale must compute {} "
"SEDs.".format(len(config.creation_modules_conf_array)))
print("With this configuration, pcigale must compute {} "
"SEDs.".format(len(config.creation_modules_conf_array)))
def run(config):
......
......@@ -49,8 +49,8 @@ class AnalysisModule(object):
creation_modules_params : array of array of dictionaries
Array containing all the possible combinations of configurations
for the creation_modules. Each 'inner' array has the same length as
the creation_modules array and contains the configuration dictionary
for the corresponding module.
the creation_modules array and contains the configuration
dictionary for the corresponding module.
parameters : dictionary
Configuration for the module.
......@@ -109,7 +109,8 @@ class AnalysisModule(object):
# unexpected one was given.
if not set(parameters) == set(self.parameter_list):
missing_parameters = (set(self.parameter_list) - set(parameters))
unexpected_parameters = (set(parameters) - set(self.parameter_list))
unexpected_parameters = (set(parameters) -
set(self.parameter_list))
message = ""
if missing_parameters:
message += ("Missing parameters: " +
......
......@@ -59,7 +59,6 @@ class Casey2012(CreationModule):
("alpha", "Mid-infrared powerlaw slope.")
])
def _init_code(self):
"""Build the model for a given set of parameters."""
......@@ -78,16 +77,16 @@ class Casey2012(CreationModule):
lambda_c = 0.75e3 / ((b1 + b2 * alpha) ** -2. + (b3 + b4 * alpha) * T)
lambda_0 = 200e3
Npl = ((1. - np.exp(-(lambda_0 / lambda_c) ** beta)) * (c / lambda_c)
** 3. / (np.exp(cst.h * c / (lambda_c * cst.k * T)) - 1.))
** 3. / (np.exp(cst.h * c / (lambda_c * cst.k * T)) - 1.))
self.wave = np.logspace(3., 6., 1000.)
conv = c / (self.wave * self.wave)
self.lumin_blackbody = conv * (1. - np.exp(-(lambda_0 / self.wave)
** beta)) * (c / self.wave) ** 3. / (np.exp(
cst.h * c / (self.wave * cst.k * T)) - 1.)
self.lumin_blackbody = (conv * (1. - np.exp(-(lambda_0 / self.wave)
** beta)) * (c / self.wave) ** 3. / (np.exp(
cst.h * c / (self.wave * cst.k * T)) - 1.))
self.lumin_powerlaw = (conv * Npl * (self.wave / lambda_c) ** alpha *
np.exp(-(self.wave / lambda_c) ** 2.))
np.exp(-(self.wave / lambda_c) ** 2.))
# TODO, save the right normalisation factor to retrieve the dust mass
norm = np.trapz(self.lumin_powerlaw + self.lumin_blackbody,
......@@ -96,7 +95,6 @@ class Casey2012(CreationModule):
self.lumin_blackbody /= norm
self.lumin = self.lumin_powerlaw + self.lumin_blackbody
def process(self, sed):
"""Add the IR re-emission contributions.
......@@ -114,7 +112,8 @@ class Casey2012(CreationModule):
self.parameters["attenuation_value_keys"].split("&")]
sed.add_module(name, self.parameters)
sed.add_info("temperature" + self.postfix, self.parameters["temperature"])
sed.add_info("temperature" + self.postfix,
self.parameters["temperature"])
sed.add_info("alpha" + self.postfix, self.parameters["alpha"])
sed.add_info("beta" + self.postfix, self.parameters["beta"])
......
......@@ -90,7 +90,7 @@ def igm_transmission_meiksin(wavelength, redshift):
# The redshift must be strictly positive
if redshift <= 0.:
raise Exception("The redshift provided must be strictly positive "
"<{}>.".format(redshift))
"<{}>.".format(redshift))
n_transitions_low = 10
n_transitions_max = 32
......
......@@ -51,13 +51,13 @@ class Redshifting(CreationModule):
# If the SED is already redshifted, raise an error.
if sed.redshift > 0:
raise Exception("The SED is already redshifted <z={}>."
.format(sed.redshift))
.format(sed.redshift))
# Raise an error when applying a negative redshift. This module is
# not for blue-shifting.
if redshift < 0:
raise Exception("The redshift provided is negative <{}>."
.format(redshift))
.format(redshift))
# We redshift directly the SED wavelength grid
sed.wavelength_grid *= 1. + redshift
......
......@@ -50,7 +50,6 @@ class DatabaseInsertError(Exception):
"""
class _Filter(BASE):
""" Storage for filters
"""
......
......@@ -3,14 +3,12 @@
# Licensed under the CeCILL-v2 licence - see Licence_CeCILL_V2-en.txt
# Author: Yannick Roehlly
from astropy.table import Table
import configobj
import pkg_resources
import pkgutil
import collections
import itertools
import numpy as np
from glob import glob # To allow the use of glob() in "eval..."
from textwrap import wrap
from .tools import param_dict_combine
from ..data import Database
......@@ -161,8 +159,8 @@ class Configuration(object):
for column in column_list:
if column.endswith('_err') and (column[:-4] not in column_list):
raise Exception("The observation table as a {} column "
"but no {} column.".format(column,
column[:-4]))
"but no {} column.".format(column,
column[:-4]))
self.config['column_list'] = column_list
self.config.comments['column_list'] = [""] + wrap(
......
......@@ -34,7 +34,7 @@ def param_dict_combine(dictionary):
string_type = basestring
except NameError:
string_type = str
for key, value in dictionary.items():
if ((not isinstance(value, collections.Iterable)) or
isinstance(value, string_type)):
......
......@@ -38,6 +38,6 @@ def read_table(file_):
table = Table.read(file_, format="ascii")
except InconsistentTableError:
raise Exception("The file <{}> can not be parsed as a data "
"table.".format(file_))
"table.".format(file_))
return table
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