Skip to content

Commit

Permalink
Merge branch 'feature/SIM-1230/separate_utils_and_mixins'
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsf committed Jul 21, 2015
2 parents 76d04b8 + 50f1c27 commit c034e70
Show file tree
Hide file tree
Showing 18 changed files with 286 additions and 3,875 deletions.
59 changes: 2 additions & 57 deletions python/lsst/sims/photUtils/CosmologyObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@
import numpy
import astropy.cosmology as cosmology
import astropy.units as units
from lsst.sims.catalogs.measures.instance import cached

flatnessthresh = 1.0e-12

__all__ = ["CosmologyObject", "CosmologyWrapper"]
__all__ = ["CosmologyObject"]

class CosmologyObject(object):

Expand Down Expand Up @@ -362,58 +362,3 @@ def distanceModulus(self, redshift=0.0):
return mod
else:
return numpy.where(mod>0.0, mod, 0.0)

class CosmologyWrapper(object):
"""
This class is designed to operate as a mixin for InstanceCatalog classes.
It provides a member variable self.cosmology which is an instantiation
of the CosmologyObject class. self.cosmology defaults to the
Milliennium Simulation cosmology. This mixin also provides a method
self.setCosmology() which will allow the user to customize self.cosmology
and a getter for the column cosmologicalDistanceModulus that reflects the
effect of the luminosity distance on a galaxy's component magnitudes.
NOTE: one should only include this mixin in catalogs whose magNorm is
normalized to an absolute magnitude of some sort (i.e. the magnitude if
the galaxy was at redshift=0). The magNorms for galaxies stored on the
University of Washington LSST database do not fit this criterion.
magNorms on the University of Washington LSST database include the
effects of cosmological distance modulus.
"""

cosmology = CosmologyObject()

def setCosmology(self, H0=73.0, Om0=0.25, Ok0=None, w0=None, wa=None):
"""
This method customizes the member variable self.cosmology by re-instantiating
the CosmologyObject class
param [in] H0 is the Hubble parameter today in km/s/Mpc
param [in] Om0 is the density paramter (fraction of critical) associated with matter today
param [in] Ode0 is the density paratmer associated with dark energy today
param [in] w0 is the w0 parameter associated with the equation of state of dark energy
w = w0 + wa z/(1+z)
param [in] wa is the wa parameter usesd to set the equation of state of dark energy
w = w0 + wa z/(1+z)
"""
self.cosmology = CosmologyObject(H0=H0, Om0=Om0, Ok0=Ok0, w0=w0, wa=wa)

@cached
def get_cosmologicalDistanceModulus(self):
"""
getter for cosmologicalDistanceModulus (the effect of the luminosity
distance on a galaxy's component magnitudes)
"""
redshift = self.column_by_name("redshift")

if len(redshift) == 0:
#newer versions of astropy do not appreciate being passed an
#empty numpy array of redshifts; avoid nasty exceptions by
#just returning an empty numpy array if we got an empty numpy array
return numpy.array([])

return self.cosmology.distanceModulus(redshift)
34 changes: 1 addition & 33 deletions python/lsst/sims/photUtils/EBV.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
import numpy
import os

from lsst.sims.catalogs.measures.instance import cached
from lsst.sims.utils import galacticFromEquatorial

__all__ = ["EBVmap", "EBVbase", "EBVmixin"]
__all__ = ["EBVmap", "EBVbase"]

def interp1D(z1 , z2, offset):
""" 1D interpolation on a grid"""
Expand Down Expand Up @@ -296,34 +295,3 @@ def calculateEbv(self, galacticCoordinates=None, equatorialCoordinates=None, nor


return ebv


class EBVmixin(EBVbase):
"""
This mixin class contains the getters which a catalog object will use to call
calculateEbv in the EBVbase class
"""


#and finally, here is the getter
@cached
def get_EBV(self):
"""
Getter for the InstanceCatalog framework
"""

galacticCoordinates=numpy.array([self.column_by_name('glon'),self.column_by_name('glat')])

EBV_out=numpy.array(self.calculateEbv(galacticCoordinates=galacticCoordinates,interp=True))
return EBV_out

@cached
def get_galacticRv(self):
"""
Returns galactic RV by getting galacticAv and EBV and assuming Rv = Av/EBV"
"""
Av=self.column_by_name('galacticAv')
EBV=self.column_by_name('EBV')
return numpy.array(Av/EBV)


Loading

0 comments on commit c034e70

Please # to comment.