...
 
Commits (3)
......@@ -13,6 +13,7 @@
- Some lines have been made slightly thicker in SED plots so the different components are more visible. (Médéric Boquien)
- The colours in the SED plots have been tweaked for aesthetic reasons. (Médéric Boquien)
- The markers for the observed fluxes in the SED plots have been tweaked to improve readability. (Médéric Boquien)
- The computation of all the cosmology-dependent quantities has been consolidated in pcigale/utils/cosmology.py and optimised. This leads to a slightly faster startup, in particular when there are many objects to fit, and it makes it easier to change the cosmology. (Médéric Boquien)
### Fixed
- Make sure we can plot the PDF of equivalent widths. (Médéric Boquien)
- Fix a crash when generating a mock catalogue containing intensive properties. (Médéric Boquien)
......
......@@ -8,7 +8,7 @@
from functools import lru_cache
from astropy import log
from astropy.cosmology import WMAP7 as cosmo
from ...utils.cosmology import luminosity_distance
import numpy as np
from scipy import optimize
from scipy.constants import parsec
......@@ -48,11 +48,7 @@ def compute_corr_dz(model_z, obs):
Object containing the distance and redshift of an object
"""
if model_z == 0.:
mod_distance = 10. * parsec
else:
mod_distance = cosmo.luminosity_distance(model_z).value * 1e6 * parsec
return (obs.distance / mod_distance) ** 2. * \
return (obs.distance / luminosity_distance(model_z)) ** 2. * \
(1. + model_z) / (1. + obs.redshift)
......@@ -289,13 +285,15 @@ def compute_chi2(models, obs, corr_dz, wz, lim_flag):
def weighted_param(param, weights):
"""Compute the weighted mean and standard deviation of an array of data.
Note that here we assume that the sum of the weights is normalised to 1.
This simplifies and accelerates the computation.
Parameters
----------
param: array
Values of the parameters for the entire grid of models
weights: array
Weights by which to weight the parameter values
Weights by which to weigh the parameter values
Returns
-------
......
......@@ -3,12 +3,12 @@
# Licensed under the CeCILL-v2 licence - see Licence_CeCILL_V2-en.txt
# Author: Médéric Boquien
from astropy.cosmology import WMAP7 as cosmo
from astropy.table import Column
import numpy as np
from scipy.constants import parsec
from ..utils import read_table
from ..utils.cosmology import luminosity_distance
from ..utils.io import read_table
from .utils import get_info
......@@ -299,11 +299,8 @@ class Observation(object):
if 'distance' in row.colnames and np.isfinite(row['distance']):
self.distance = row['distance'] * parsec * 1e6
else:
if self.redshift == 0.:
self.distance = 10. * parsec
elif self.redshift > 0.:
self.distance = cosmo.luminosity_distance(self.redshift).value \
* 1e6 * parsec
if self.redshift >= 0.:
self.distance = luminosity_distance(self.redshift)
else:
self.distance = np.nan
self.flux = {k: row[k] for k in cls.bands
......
......@@ -8,7 +8,7 @@ import collections
import itertools
import numpy as np
from ..utils import read_table
from ..utils.io import read_table
class ParametersManager(object):
......
......@@ -13,7 +13,7 @@ This module reads a SED spectrum from a file.
from collections import OrderedDict
from ..utils import read_table
from ..utils.io import read_table
from . import SedModule
......
......@@ -23,7 +23,7 @@ from collections import OrderedDict
import numpy as np
from scipy.constants import parsec
from scipy.special import factorial
from astropy.cosmology import WMAP7 as cosmology
from ..utils.cosmology import age, luminosity_distance
from . import SedModule
......@@ -163,13 +163,8 @@ class Redshifting(SedModule):
raise Exception(f"The redshift provided is negative "
f"({self.redshift}).")
self.universe_age = cosmology.age(self.redshift).value * 1000.
if self.redshift == 0.:
self.luminosity_distance = 10. * parsec
else:
self.luminosity_distance = (
cosmology.luminosity_distance(self.redshift).value * 1e6 *
parsec)
self.universe_age = age(self.redshift)
self.luminosity_distance = luminosity_distance(self.redshift)
# We do not define the values of the IGM attenuation component yet.
# This is because we need the wavelength grid for that first. This
# will be assigned on the first call.
......
......@@ -15,7 +15,7 @@ from collections import OrderedDict
import numpy as np
from ..utils import read_table
from ..utils.io import read_table
from . import SedModule
......
......@@ -16,7 +16,7 @@ import validate
from ..managers.parameters import ParametersManager
from ..data import Database
from ..utils import read_table
from ..utils.io import read_table
from .. import sed_modules
from .. import analysis_modules
from ..warehouse import SedWarehouse
......
# -*- coding: utf-8 -*-
# Licensed under the CeCILL-v2 licence - see Licence_CeCILL_V2-en.txt
from functools import lru_cache
from astropy.cosmology import WMAP7 as _cosmo
from scipy.constants import parsec
@lru_cache(maxsize=None)
def luminosity_distance(redshift):
"""Computes the luminosity distance in m for a given redshift. If the
redshift is 0, then we assume a distance of 10 pc.
Parameter
---------
redshift: scalar
Redshift of the object
Returns
-------
luminosity_distance: scalar
Luminosity distance to the object in m
"""
if redshift > 0:
return _cosmo.luminosity_distance(redshift).value * 1e6 * parsec
return 10. * parsec
@lru_cache(maxsize=None)
def age(redshift):
"""Computes the age of the universe in Myr at a given redshift.
Parameter
---------
redshift: scalar
Redshift of the object
Returns
-------
age: float
Age of the universe in Myr at the corresponding redshift
"""
return _cosmo.age(redshift).value * 1000.