Coverage for python/lsst/sims/catUtils/mixins/CosmologyMixin.py : 63%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1from builtins import object
2import numpy
3import astropy.cosmology as cosmology
4import astropy.units as units
5from lsst.sims.catalogs.decorators import cached
6from lsst.sims.photUtils import CosmologyObject
7flatnessthresh = 1.0e-12
9__all__ = ["CosmologyMixin"]
11class CosmologyMixin(object):
12 """
13 This class is designed to operate as a mixin for InstanceCatalog classes.
14 It provides a member variable self.cosmology which is an instantiation
15 of the CosmologyObject class. self.cosmology defaults to the
16 Milliennium Simulation cosmology. This mixin also provides a method
17 self.setCosmology() which will allow the user to customize self.cosmology
18 and a getter for the column cosmologicalDistanceModulus that reflects the
19 effect of the luminosity distance on a galaxy's component magnitudes.
21 NOTE: one should only include this mixin in catalogs whose magNorm is
22 normalized to an absolute magnitude of some sort (i.e. the magnitude if
23 the galaxy was at redshift=0). The magNorms for galaxies stored on the
24 University of Washington LSSTCATSIM database do not fit this criterion.
25 magNorms on the University of Washington LSSTCATSIM database include the
26 effects of cosmological distance modulus.
27 """
29 cosmology = CosmologyObject()
31 def setCosmology(self, H0=73.0, Om0=0.25, Ok0=None, w0=None, wa=None):
32 """
33 This method customizes the member variable self.cosmology by re-instantiating
34 the CosmologyObject class
36 param [in] H0 is the Hubble parameter today in km/s/Mpc
38 param [in] Om0 is the density paramter (fraction of critical) associated with matter today
40 param [in] Ode0 is the density paratmer associated with dark energy today
42 param [in] w0 is the w0 parameter associated with the equation of state of dark energy
43 w = w0 + wa z/(1+z)
45 param [in] wa is the wa parameter usesd to set the equation of state of dark energy
46 w = w0 + wa z/(1+z)
47 """
48 self.cosmology = CosmologyObject(H0=H0, Om0=Om0, Ok0=Ok0, w0=w0, wa=wa)
50 @cached
51 def get_cosmologicalDistanceModulus(self):
52 """
53 getter for cosmologicalDistanceModulus (the effect of the luminosity
54 distance on a galaxy's component magnitudes)
55 """
56 redshift = self.column_by_name("redshift")
58 if len(redshift) == 0:
59 #newer versions of astropy do not appreciate being passed an
60 #empty numpy array of redshifts; avoid nasty exceptions by
61 #just returning an empty numpy array if we got an empty numpy array
62 return numpy.array([])
64 return self.cosmology.distanceModulus(redshift)