Commit 8b9b6113 authored by Médéric Boquien's avatar Médéric Boquien

Small changes to stick closer to PEP8.

parent 6d0dc5d6
......@@ -260,5 +260,6 @@ class PdfAnalysis(AnalysisModule):
print("Run completed!")
# AnalysisModule to be returned by get_module
Module = PdfAnalysis
......@@ -21,11 +21,8 @@ import multiprocessing as mp
from multiprocessing.sharedctypes import RawArray
import time
import numpy as np
from .. import AnalysisModule
from ..utils import backup_dir, save_fluxes
from ...utils import read_table
from .workers import init_fluxes as init_worker_fluxes
from .workers import fluxes as worker_fluxes
from ...handlers.parameters_handler import ParametersHandler
......@@ -104,5 +101,6 @@ class SaveFluxes(AnalysisModule):
save_fluxes(model_fluxes, model_parameters, filters, info)
# AnalysisModule to be returned by get_module
Module = SaveFluxes
......@@ -8,8 +8,6 @@ Various utility functions for pcigale analysis modules
"""
from datetime import datetime
import collections
import itertools
import os
import shutil
......@@ -72,10 +70,10 @@ def save_fluxes(model_fluxes, model_parameters, filters, names,
def nothread():
"""Some libraries such as Intel's MKL have automatic threading. This is good
when having only one process. However we already do our own parallelisation.
The additional threads created by the MKL increase in excess the pressure on
the CPU and on the RAM slowing everything down.
"""Some libraries such as Intel's MKL have automatic threading. This is
good when having only one process. However we already do our own
parallelisation. The additional threads created by the MKL increase in
excess the pressure on the CPU and on the RAM slowing everything down.
Parameters
----------
......
......@@ -236,22 +236,24 @@ class _NebularContinuum(BASE):
self.wave = nebular_continuum.wave
self.lumin = nebular_continuum.lumin
class _Schreiber2016(BASE):
"""Storage for Schreiber et al (2016) infra-red templates
"""
__tablename__ = 'schreiber2016_templates'
type = Column(Float, primary_key=True)
tdust = Column(String, primary_key=True)
wave = Column(PickleType)
lumin = Column(PickleType)
def __init__(self, ir):
self.type = ir.type
self.tdust = ir.tdust
self.wave = ir.wave
self.lumin = ir.lumin
class Database(object):
"""Object giving access to pcigale database."""
......@@ -441,7 +443,6 @@ class Database(object):
else:
raise Exception('The database is not writable.')
def get_dl2007(self, qpah, umin, umax):
"""
Get the Draine and Li (2007) model corresponding to the given set of
......@@ -627,8 +628,6 @@ class Database(object):
dictionary of parameters and their values
"""
return self._get_parameters(_Dale2014)
def add_fritz2006(self, models):
"""
......@@ -813,13 +812,13 @@ class Database(object):
def add_schreiber2016(self, models):
"""
Add Schreiber et al (2016) templates the collection.
Parameters
----------
models: list of pcigale.data.Schreiber2016 objects
"""
if self.is_writable:
for model in models:
self.session.add(_Schreiber2016(model))
......@@ -834,33 +833,33 @@ class Database(object):
def get_schreiber2016(self, type, tdust):
"""
Get the Schreiber et al (2016) template corresponding to the given set of
parameters.
Get the Schreiber et al (2016) template corresponding to the given set
of parameters.
Parameters
----------
type: float
Dust template or PAH template
tdust: float
Dust temperature
Returns
-------
template: pcigale.data.Schreiber2016
The Schreiber et al. (2016) IR template.
Raises
------
DatabaseLookupError: if the requested template is not in the database.
"""
result = (self.session.query(_Schreiber2016).
filter(_Schreiber2016.type == type).
filter(_Schreiber2016.tdust == tdust).
first())
filter(_Schreiber2016.type == type).
filter(_Schreiber2016.tdust == tdust).
first())
if result:
return Schreiber2016(result.type, result.tdust, result.wave,
result.lumin)
result.lumin)
else:
raise DatabaseLookupError(
"The Schreiber2016 template for type <{0}> and tdust <{1}> "
......@@ -868,7 +867,7 @@ class Database(object):
def get_schreiber2016_parameters(self):
"""Get parameters for the Scnreiber 2016 models.
Returns
-------
paramaters: dictionary
......
......@@ -99,9 +99,9 @@ class BC03(object):
"""
# We cut the SSP to the maximum age considered to simplify the
# computation. We take only the first three elements from the info_table
# as the others do not make sense when convolved with the SFH (break
# strength).
# computation. We take only the first three elements from the
# info_table as the others do not make sense when convolved with the
# SFH (break strength).
info_table = self.info_table[:3, :sfh.size]
spec_table = self.spec_table[:, :sfh.size]
......
......@@ -54,8 +54,8 @@ class M2005(object):
if imf in ['salp', 'krou']:
self.imf = imf
else:
raise ValueError("IMF must be either salp for Salpeter or krou for "
"Kroupa.")
raise ValueError("IMF must be either salp for Salpeter or krou "
"for Kroupa.")
self.metallicity = metallicity
self.time_grid = time_grid
self.wavelength_grid = wavelength_grid
......@@ -102,8 +102,8 @@ class M2005(object):
# As both the SFH and the SSP (limited to the age of the SFH) data now
# share the same time grid, the convolution is just a matter of
# reverting one and computing the sum of the one to one product; this
# is done using the dot product. The 1e6 factor is because the SFH is in
# solar mass per year.
# is done using the dot product. The 1e6 factor is because the SFH is
# in solar mass per year.
info_young = 1e6 * np.dot(info_table[:, :separation_age],
sfh[-separation_age:][::-1])
spec_young = 1e6 * np.dot(spec_table[:, :separation_age],
......
......@@ -8,8 +8,6 @@ import collections
import itertools
import numpy as np
from astropy.table import Table
from ..utils import read_table
......@@ -175,7 +173,7 @@ class ParametersHandlerFile(object):
parname = colname.split('.', 1)[1]
if type(table[colname][0]) is np.str_:
dict_params[parname] = [str(val) for val in
table[colname]]
table[colname]]
else:
dict_params[parname] = list(table[colname])
self.parameters.append(dict_params)
......
......@@ -8,6 +8,7 @@ from collections import OrderedDict
from astropy.table import Table, Column
import numpy as np
def save_sed_to_fits(sed, prefix, norm=1.):
"""
Save a SED object to fits files
......@@ -35,7 +36,7 @@ def save_sed_to_fits(sed, prefix, norm=1.):
table['L_lambda_total'] = Column(norm * sed.luminosity, unit="W/nm")
for name in sed.contribution_names:
table[name] = Column(norm * sed.get_lumin_contribution(name),
unit="W/nm")
unit="W/nm")
table.write("{}_best_model.fits".format(prefix))
if sed.sfh is not None:
......
......@@ -6,6 +6,7 @@
from astropy.io.votable.tree import VOTableFile, Resource, Table, Field, Info
import numpy as np
def save_sed_to_vo(sed, filename, norm=1.):
"""
Save a SED object to a VO-Table file
......
......@@ -109,5 +109,6 @@ class BC03(SedModule):
sed.add_contribution("stellar.old", wave, spec_old)
sed.add_contribution("stellar.young", wave, spec_young)
# SedModule to be returned by get_module
Module = BC03
......@@ -105,11 +105,11 @@ class Casey2012(SedModule):
sed.add_info("dust.beta", self.beta)
sed.add_info("dust.alpha", self.alpha)
sed.add_contribution('dust.powerlaw', self.wave,
luminosity * self.lumin_powerlaw)
sed.add_contribution('dust.blackbody', self.wave,
luminosity * self.lumin_blackbody)
# SedModule to be returned by get_module
Module = Casey2012
......@@ -104,5 +104,6 @@ class Dale2014(SedModule):
sed.add_contribution('agn', self.model_quasar.wave,
L_AGN * self.model_quasar.lumin)
# SedModule to be returned by get_module
Module = Dale2014
......@@ -120,5 +120,6 @@ class DL2007(SedModule):
sed.add_contribution('dust.Umin_Umax', self.model_minmax.wave,
luminosity * self.model_minmax.lumin)
# SedModule to be returned by get_module
Module = DL2007
......@@ -128,5 +128,6 @@ class DL2014(SedModule):
sed.add_contribution('dust.Umin_Umax', self.model_minmax.wave,
luminosity * self.model_minmax.lumin)
# SedModule to be returned by get_module
Module = DL2014
......@@ -217,5 +217,6 @@ class TwoPowerLawAtt(SedModule):
sed.add_info("attenuation." + filt,
-2.5 * np.log10(flux_att[filt] / flux_noatt[filt]))
# CreationModule to be returned by get_module
Module = TwoPowerLawAtt
......@@ -314,5 +314,6 @@ class CalzLeit(SedModule):
sed.add_info('attenuation.uv_bump_amplitude', self.uv_bump_amplitude)
sed.add_info('attenuation.powerlaw_slope', self.powerlaw_slope)
# SedModule to be returned by get_module
Module = CalzLeit
......@@ -229,5 +229,6 @@ class PowerLawAtt(SedModule):
sed.add_info("attenuation." + filt,
-2.5 * np.log10(flux_att[filt] / flux_noatt[filt]))
# SedModule to be returned by get_module
Module = PowerLawAtt
......@@ -115,8 +115,6 @@ class Fritz2006(SedModule):
sed.add_info('dust.luminosity', 1., True)
luminosity = sed.info['dust.luminosity']
sed.add_module(self.name, self.parameters)
sed.add_info('agn.r_ratio', self.r_ratio)
sed.add_info('agn.tau', self.tau)
......@@ -152,5 +150,6 @@ class Fritz2006(SedModule):
sed.add_contribution('agn.fritz2006_agn', self.fritz2006.wave,
agn_power * self.fritz2006.lumin_agn)
# SedModule to be returned by get_module
Module = Fritz2006
......@@ -60,5 +60,6 @@ class LoadSpecFile(SedModule):
table[self.parameters['l_lambda_column']]
)
# SedModule to be returned by get_module
Module = LoadSpecFile
......@@ -13,8 +13,6 @@ This module implements the Maraston (2005) Single Stellar Populations.
from collections import OrderedDict
import numpy as np
from . import SedModule
from ..data import Database
......@@ -104,5 +102,6 @@ class M2005(SedModule):
sed.add_contribution("stellar.young", self.ssp.wavelength_grid,
spec_young)
# SedModule to be returned by get_module
Module = M2005
......@@ -129,6 +129,7 @@ class MBB(SedModule):
# We add the contribution of the MBB to L_dust.
sed.add_contribution('dust.mbb', self.wave,
luminosity * self.epsilon * self.lumin_mbb)
#
# SedModule to be returned by get_module
Module = MBB
......@@ -171,5 +171,6 @@ class NebularEmission(SedModule):
sed.add_contribution('nebular.continuum_young', cont.wave,
cont.lumin * NLy_young * self.corr)
# SedModule to be returned by get_module
Module = NebularEmission
......@@ -104,8 +104,8 @@ class Param(SedModule):
w_D4000blue = np.where((wavelength >= 385.0 * (1. + redshift)) &
(wavelength <= 395.0 * (1. + redshift)))
w_D4000red = np.where((wavelength >= 400.0 * (1. + redshift)) &
(wavelength <= 410.0 * (1. + redshift)))
w_D4000red = np.where((wavelength >= 400.0 * (1. + redshift)) &
(wavelength <= 410.0 * (1. + redshift)))
regression_calz94 = np.polyfit(np.log10(10.*wavelength[w_calz94]),
np.log10(1e7/10.*luminosity[w_calz94]),
......@@ -133,5 +133,6 @@ class Param(SedModule):
True
)
# SedModule to be returned by get_module
Module = Param
......@@ -80,5 +80,6 @@ class Radio(SedModule):
sed.add_contribution('radio_nonthermal', self.wave,
self.lumin_nonthermal * luminosity)
# SedModule to be returned by get_module
Module = Radio
......@@ -216,5 +216,6 @@ class Redshifting(SedModule):
self.igm_attenuation[key] * sed.luminosity)
sed.add_module(self.name, self.parameters)
# SedModule to be returned by get_module
Module = Redshifting
......@@ -104,5 +104,6 @@ class Schreiber2016(SedModule):
sed.add_contribution('dust.pah', self.model_pah.wave,
luminosity * self.model_pah.lumin)
# SedModule to be returned by get_module
Module = Schreiber2016
......@@ -84,7 +84,8 @@ class Sfh2Exp(SedModule):
sfr_burst = np.exp(-time_grid_burst / self.tau_burst)
# Height of the late burst to have the desired produced mass fraction
sfr_burst *= self.f_burst / (1.-self.f_burst) * np.sum(self.sfr) / np.sum(sfr_burst)
sfr_burst *= (self.f_burst / (1.-self.f_burst) * np.sum(self.sfr) /
np.sum(sfr_burst))
# We add the age burst exponential for ages superior to age -
# burst_age
......@@ -119,5 +120,6 @@ class Sfh2Exp(SedModule):
sed.add_info("sfh.f_burst", self.f_burst)
sed.add_info("sfh.burst_age", self.burst_age)
# SedModule to be returned by get_module
Module = Sfh2Exp
......@@ -109,5 +109,6 @@ class SfhBuat08(SedModule):
sed.add_info("sfh.integrated", self.sfr_integrated, True)
sed.add_info("sfh.velocity", self.velocity)
# SedModule to be returned by get_module
Module = SfhBuat08
......@@ -95,5 +95,6 @@ class SfhQuenchSmooth(SedModule):
sed.add_info("sfh.quenching_time", self.quenching_age)
sed.add_info("sfh.quenching_factor", self.quenching_factor)
# SedModule to be returned by get_module
Module = SfhQuenchSmooth
......@@ -92,5 +92,6 @@ class SfhQuenchTrunk(SedModule):
sed.add_info("sfh.quenching_age", self.quenching_age)
sed.add_info("sfh.quenching_factor", self.quenching_factor)
# SedModule to be returned by get_module
Module = SfhQuenchTrunk
......@@ -60,8 +60,8 @@ class SFHDelayed(SedModule):
# Time grid and SFR
time_grid = np.arange(age)
self.sfr = time_grid * np.exp(-time_grid / self.tau_main) / \
self.tau_main**2
self.sfr = (time_grid * np.exp(-time_grid / self.tau_main) /
self.tau_main**2)
# Compute the galaxy mass and normalise the SFH to 1 solar mass
# produced if asked to.
......@@ -87,5 +87,6 @@ class SFHDelayed(SedModule):
sed.add_info("sfh.integrated", self.sfr_integrated, True)
sed.add_info("sfh.tau_main", self.tau_main)
# SedModule to be returned by get_module
Module = SFHDelayed
......@@ -98,5 +98,6 @@ class SfhFromFile(SedModule):
sed.add_info("sfh.integrated", self.sfr_integrated, True)
sed.add_info("sfh.index", self.sfr_column_number)
# SedModule to be returned by get_module
Module = SfhFromFile
......@@ -122,5 +122,6 @@ class SfhPeriodic(SedModule):
sed.add_info("sfh.delta_bursts", self.delta_bursts)
sed.add_info("sfh.tau_bursts", self.tau_bursts)
# SedModule to be returned by get_module
Module = SfhPeriodic
......@@ -3,8 +3,7 @@
# Licensed under the CeCILL-v2 licence - see Licence_CeCILL_V2-en.txt
# Author: Yannick Roehlly
import pkgutil
from collections import Iterable, OrderedDict
from collections import OrderedDict
import multiprocessing as mp
import os.path
import sys
......@@ -12,7 +11,6 @@ from textwrap import wrap
import configobj
from glob import glob # To allow the use of glob() in "eval..."
import pkg_resources
import numpy as np
import validate
......
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