zCluster 0.6.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- zCluster/PhotoRedshiftEngine.py +559 -0
- zCluster/SED/BR07/default_sed1.dat +4566 -0
- zCluster/SED/BR07/default_sed2.dat +4566 -0
- zCluster/SED/BR07/default_sed3.dat +4566 -0
- zCluster/SED/BR07/default_sed4.dat +4566 -0
- zCluster/SED/BR07/default_sed5.dat +4566 -0
- zCluster/SED/BR07/goods_sed1.dat +4566 -0
- zCluster/SED/BR07/goods_sed2.dat +4566 -0
- zCluster/SED/BR07/goods_sed3.dat +4566 -0
- zCluster/SED/BR07/goods_sed4.dat +4566 -0
- zCluster/SED/BR07/goods_sed5.dat +4566 -0
- zCluster/SED/BR07/lrg1_sed1.dat +4566 -0
- zCluster/SED/CWW/CWW_E_ext.sed +867 -0
- zCluster/SED/CWW/CWW_Im_ext.sed +867 -0
- zCluster/SED/CWW/CWW_Sbc_ext.sed +896 -0
- zCluster/SED/CWW/CWW_Scd_ext.sed +896 -0
- zCluster/SED/CWW/SB2_kin.sed +2942 -0
- zCluster/SED/CWW/SB3_kin.sed +2802 -0
- zCluster/SED/DECaLSDR10_learned_N20/DECaLSDR10_template_01.sed +451 -0
- zCluster/SED/DECaLSDR10_learned_N20/DECaLSDR10_template_02.sed +451 -0
- zCluster/SED/DECaLSDR10_learned_N20/DECaLSDR10_template_03.sed +451 -0
- zCluster/SED/DECaLSDR10_learned_N20/DECaLSDR10_template_04.sed +451 -0
- zCluster/SED/DECaLSDR10_learned_N20/DECaLSDR10_template_05.sed +451 -0
- zCluster/SED/DECaLSDR10_learned_N20/DECaLSDR10_template_06.sed +451 -0
- zCluster/SED/DECaLSDR10_learned_N20/DECaLSDR10_template_07.sed +451 -0
- zCluster/SED/DECaLSDR10_learned_N20/DECaLSDR10_template_08.sed +451 -0
- zCluster/SED/DECaLSDR10_learned_N20/DECaLSDR10_template_09.sed +451 -0
- zCluster/SED/DECaLSDR10_learned_N20/DECaLSDR10_template_10.sed +451 -0
- zCluster/SED/DECaLSDR10_learned_N20/DECaLSDR10_template_11.sed +451 -0
- zCluster/SED/DECaLSDR10_learned_N20/DECaLSDR10_template_12.sed +451 -0
- zCluster/SED/DECaLSDR10_learned_N20/DECaLSDR10_template_13.sed +451 -0
- zCluster/SED/DECaLSDR10_learned_N20/DECaLSDR10_template_14.sed +451 -0
- zCluster/SED/DECaLSDR10_learned_N20/DECaLSDR10_template_15.sed +451 -0
- zCluster/SED/DECaLSDR10_learned_N20/DECaLSDR10_template_16.sed +451 -0
- zCluster/SED/DECaLSDR10_learned_N20/DECaLSDR10_template_17.sed +451 -0
- zCluster/SED/DECaLSDR10_learned_N20/DECaLSDR10_template_18.sed +451 -0
- zCluster/SED/DECaLSDR10_learned_N20/DECaLSDR10_template_19.sed +451 -0
- zCluster/SED/DECaLSDR10_learned_N20/DECaLSDR10_template_20.sed +451 -0
- zCluster/SED/EAZY_v1.0/eazy_v1.0_sed1.dat +1221 -0
- zCluster/SED/EAZY_v1.0/eazy_v1.0_sed2.dat +1221 -0
- zCluster/SED/EAZY_v1.0/eazy_v1.0_sed3.dat +1221 -0
- zCluster/SED/EAZY_v1.0/eazy_v1.0_sed4.dat +1221 -0
- zCluster/SED/EAZY_v1.0/eazy_v1.0_sed5.dat +1221 -0
- zCluster/SED/EAZY_v1.0/eazy_v1.0_sed6.dat +1221 -0
- zCluster/__init__.py +14 -0
- zCluster/_version.py +21 -0
- zCluster/catalogs.py +272 -0
- zCluster/clusters.py +786 -0
- zCluster/data/redmapper_dr8_public_v5.10_catalog.fits +59302 -0
- zCluster/data/tau0p1Gyr_m62.20 +6906 -0
- zCluster/passbands/K_2MASS.res +79 -0
- zCluster/passbands/RSR-W1.EE.txt +400 -0
- zCluster/passbands/RSR-W2.EE.txt +550 -0
- zCluster/passbands/RSR-W3.EE.txt +2561 -0
- zCluster/passbands/RSR-W4.EE.txt +2561 -0
- zCluster/passbands/VISTA_Filters_at80K_forETC_H.dat +2176 -0
- zCluster/passbands/VISTA_Filters_at80K_forETC_J.dat +2176 -0
- zCluster/passbands/VISTA_Filters_at80K_forETC_Ks.dat +2176 -0
- zCluster/passbands/VISTA_Filters_at80K_forETC_Y.dat +2439 -0
- zCluster/passbands/VISTA_Filters_at80K_forETC_Z.dat +9801 -0
- zCluster/passbands/decam.g.am1p4.dat.txt +806 -0
- zCluster/passbands/decam.i.am1p4.dat.txt +806 -0
- zCluster/passbands/decam.r.am1p4.dat.txt +806 -0
- zCluster/passbands/decam.z.am1p4.dat.txt +806 -0
- zCluster/passbands/gDES.res +1441 -0
- zCluster/passbands/gLSST.res +7805 -0
- zCluster/passbands/gPS1.res +721 -0
- zCluster/passbands/g_CFHTLS.res +61 -0
- zCluster/passbands/g_SDSS.res +22 -0
- zCluster/passbands/g_SDSS3.res +89 -0
- zCluster/passbands/i2_CFHTLS.res +38 -0
- zCluster/passbands/iDES.res +1441 -0
- zCluster/passbands/iLSST.res +7805 -0
- zCluster/passbands/iPS1.res +721 -0
- zCluster/passbands/i_CFHTLS.res +65 -0
- zCluster/passbands/i_SDSS.res +22 -0
- zCluster/passbands/i_SDSS3.res +89 -0
- zCluster/passbands/rDES.res +1441 -0
- zCluster/passbands/rLSST.res +7805 -0
- zCluster/passbands/rPS1.res +721 -0
- zCluster/passbands/r_CFHTLS.res +55 -0
- zCluster/passbands/r_SDSS.res +23 -0
- zCluster/passbands/r_SDSS3.res +75 -0
- zCluster/passbands/uLSST.res +7805 -0
- zCluster/passbands/u_CFHTLS.res +61 -0
- zCluster/passbands/u_SDSS.res +20 -0
- zCluster/passbands/u_SDSS3.res +47 -0
- zCluster/passbands/yDES.res +1441 -0
- zCluster/passbands/yLSST.res +7805 -0
- zCluster/passbands/yPS1.res +721 -0
- zCluster/passbands/zDES.res +1441 -0
- zCluster/passbands/zLSST.res +7805 -0
- zCluster/passbands/zPS1.res +721 -0
- zCluster/passbands/z_CFHTLS.res +63 -0
- zCluster/passbands/z_SDSS.res +27 -0
- zCluster/passbands/z_SDSS3.res +141 -0
- zCluster/retrievers.py +1823 -0
- zCluster/stellarmass.py +286 -0
- zcluster-0.6.0.data/scripts/zCluster +740 -0
- zcluster-0.6.0.data/scripts/zClusterBCG +477 -0
- zcluster-0.6.0.data/scripts/zClusterComparisonPlot +348 -0
- zcluster-0.6.0.data/scripts/zField +259 -0
- zcluster-0.6.0.dist-info/METADATA +87 -0
- zcluster-0.6.0.dist-info/RECORD +107 -0
- zcluster-0.6.0.dist-info/WHEEL +5 -0
- zcluster-0.6.0.dist-info/licenses/COPYING +674 -0
- zcluster-0.6.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,559 @@
|
|
|
1
|
+
"""
|
|
2
|
+
|
|
3
|
+
This module contains a class for estimating galaxy photometric redshifts using a template fitting method.
|
|
4
|
+
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import os
|
|
8
|
+
import numpy as np
|
|
9
|
+
import zCluster
|
|
10
|
+
from zCluster import stellarmass as sm
|
|
11
|
+
from astLib import *
|
|
12
|
+
from scipy import stats
|
|
13
|
+
from scipy import interpolate
|
|
14
|
+
import string
|
|
15
|
+
import glob
|
|
16
|
+
import pickle
|
|
17
|
+
import time
|
|
18
|
+
|
|
19
|
+
# Limits on input photometry used in PhotoRedshiftEngine.calcPhotoRedshifts. Values outside these are not
|
|
20
|
+
# physical (they are sentinels for missing data, or junk), and would overflow the magnitude -> flux conversion.
|
|
21
|
+
MIN_MAG=-100.0 # Galaxies with any magnitude <= this (e.g., -999 for missing data) cannot be fitted
|
|
22
|
+
MAX_MAG=200.0 # Galaxies with any magnitude >= this cannot be fitted (99 for missing data is fine)
|
|
23
|
+
MAX_MAG_ERROR=100.0 # Bands with |magnitude uncertainty| >= this are treated as missing (99 is fine)
|
|
24
|
+
|
|
25
|
+
class PhotoRedshiftEngine:
|
|
26
|
+
"""A class that calculates galaxy photo-zs, adding photo-z info to a catalog (list of dictionaries)
|
|
27
|
+
in place.
|
|
28
|
+
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
# Built-in template sets: name -> list of (subdirectory of zCluster/SED, file glob pattern)
|
|
32
|
+
DEFAULT_TEMPLATE_SETS={'EAZY_v1.0+CWW': [('EAZY_v1.0', '*.dat'), ('CWW', '*.sed')],
|
|
33
|
+
'DECaLSDR10_learned_N20': [('DECaLSDR10_learned_N20', '*.sed')]}
|
|
34
|
+
|
|
35
|
+
def __init__(self, absMagCut, passbandSet = 'SDSS+Ks', zMin = 0.01, zMax = 3.0, zStep = 0.01,
|
|
36
|
+
ZPError = 0.0, ZPOffsets = None, templatesDir = None, templateSet = 'EAZY_v1.0+CWW',
|
|
37
|
+
EBMinusVList = [0.0],
|
|
38
|
+
emLinesScaleList = [0.0]):
|
|
39
|
+
# EBMinusVList = [0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.4, 0.5],
|
|
40
|
+
# emLinesScaleList = [0.0, 1.0, 2.0, 4.0, 6.0, 8.0, 10.0]):
|
|
41
|
+
# EBMinusVList = list(np.linspace(0, 0.48, 13))):
|
|
42
|
+
# EBMinusVList = list(np.linspace(0, 1.5, 16)),):
|
|
43
|
+
"""Sets up the stuff we would otherwise calculate every time, i.e., the templates.
|
|
44
|
+
|
|
45
|
+
Args:
|
|
46
|
+
templatesDir (str, optional): Path to a directory containing a custom set of SED templates.
|
|
47
|
+
If given, this overrides ``templateSet``.
|
|
48
|
+
templateSet (str, optional): Which built-in template set to use when ``templatesDir`` is not
|
|
49
|
+
given. One of the keys of :attr:`DEFAULT_TEMPLATE_SETS` (default: 'EAZY_v1.0+CWW', which is
|
|
50
|
+
the template set used for every passbandSet in zCluster v0.5.1 and earlier).
|
|
51
|
+
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
if zStep < 0:
|
|
55
|
+
print("... WARNING: zStep was negative - forced to be positive")
|
|
56
|
+
zStep=abs(zStep)
|
|
57
|
+
self.zRange=np.linspace(zMin, zMax, int(((zMax+zStep)-zMin)/zStep))
|
|
58
|
+
|
|
59
|
+
# Set up passbands
|
|
60
|
+
passbandsDir=zCluster.__path__[0]+os.path.sep+"passbands"+os.path.sep
|
|
61
|
+
self.passbandsList=[]
|
|
62
|
+
if passbandSet == 'SDSS+Ks':
|
|
63
|
+
self.bands=['u', 'g', 'r', 'i', 'z', 'Ks']
|
|
64
|
+
for band in self.bands:
|
|
65
|
+
if band == 'Ks':
|
|
66
|
+
self.passbandsList.append(astSED.Passband(passbandsDir+"K_2MASS.res"))
|
|
67
|
+
else:
|
|
68
|
+
self.passbandsList.append(astSED.Passband(passbandsDir+band+"_SDSS.res"))
|
|
69
|
+
elif passbandSet == 'KiDS-VIKING':
|
|
70
|
+
self.bands=['u', 'g', 'r', 'i', 'Z', 'Y', 'J', 'H', 'Ks']
|
|
71
|
+
for band in self.bands:
|
|
72
|
+
if band in ['Z', 'Y', 'J', 'H', 'Ks']:
|
|
73
|
+
self.passbandsList.append(astSED.Passband(passbandsDir+"VISTA_Filters_at80K_forETC_%s.dat" % (band),
|
|
74
|
+
inputUnits = 'nanometres'))
|
|
75
|
+
else:
|
|
76
|
+
self.passbandsList.append(astSED.Passband(passbandsDir+band+"_SDSS.res"))
|
|
77
|
+
elif passbandSet == 'WIRDS':
|
|
78
|
+
self.bands=['u', 'g', 'r', 'i', 'z', 'J', 'H', 'Ks']
|
|
79
|
+
for band in self.bands:
|
|
80
|
+
if band in ['J', 'H', 'Ks']:
|
|
81
|
+
self.passbandsList.append(astSED.Passband(passbandsDir+"VISTA_Filters_at80K_forETC_%s.dat" % (band),
|
|
82
|
+
inputUnits = 'nanometres'))
|
|
83
|
+
else:
|
|
84
|
+
self.passbandsList.append(astSED.Passband(passbandsDir+band+"_SDSS.res"))
|
|
85
|
+
elif passbandSet == 'PS1':
|
|
86
|
+
self.bands=['g', 'r', 'i', 'z']#, 'y']
|
|
87
|
+
for band in self.bands:
|
|
88
|
+
self.passbandsList.append(astSED.Passband(passbandsDir+band+"PS1.res"))
|
|
89
|
+
elif passbandSet == 'DES':
|
|
90
|
+
self.bands=['g', 'r', 'i', 'z']
|
|
91
|
+
for band in self.bands:
|
|
92
|
+
self.passbandsList.append(astSED.Passband(passbandsDir+band+"DES.res"))
|
|
93
|
+
elif passbandSet == 'DECaLS':
|
|
94
|
+
# NOTE: WISE passbands from here: http://wise2.ipac.caltech.edu/docs/release/allsky/expsup/sec4_4h.html
|
|
95
|
+
# DR10 adds i-band
|
|
96
|
+
self.bands=['g', 'r', 'i', 'z', "w1", "w2"]
|
|
97
|
+
for band in self.bands:
|
|
98
|
+
if band[0] != "w":
|
|
99
|
+
self.passbandsList.append(astSED.Passband(passbandsDir+"decam.%s.am1p4.dat.txt" % (band)))
|
|
100
|
+
else:
|
|
101
|
+
self.passbandsList.append(astSED.Passband(passbandsDir+"RSR-%s.EE.txt" % (band.upper()), inputUnits = "microns"))
|
|
102
|
+
elif passbandSet == 'LSST':
|
|
103
|
+
self.bands=['u', 'g', 'r', 'i', 'z', 'y']
|
|
104
|
+
for band in self.bands:
|
|
105
|
+
self.passbandsList.append(astSED.Passband(passbandsDir+band+"LSST.res"))
|
|
106
|
+
else:
|
|
107
|
+
raise Exception("Unknown passbandSet '%s'" % (passbandSet))
|
|
108
|
+
|
|
109
|
+
# Allow a global photometric calibration error, in magnitudes, (across all bands)
|
|
110
|
+
# This gets added to photometric errors in catalog in quadrature
|
|
111
|
+
# This helps to get catalogs with extremely small photometric errors to behave
|
|
112
|
+
self.ZPError=ZPError
|
|
113
|
+
|
|
114
|
+
# This probably doesn't gain us much
|
|
115
|
+
self.effectiveWavelength=[]
|
|
116
|
+
for p in self.passbandsList:
|
|
117
|
+
self.effectiveWavelength.append(p.effectiveWavelength())
|
|
118
|
+
self.effectiveWavelength=np.array(self.effectiveWavelength)
|
|
119
|
+
self.effLMicron2=(self.effectiveWavelength*(1e-10/1e-6))*(self.effectiveWavelength*(1e-10/1e-6))
|
|
120
|
+
|
|
121
|
+
# SED templates
|
|
122
|
+
# Mostly lifted from those included with EAZY. CWW is CWW+Kinney, used in BPZ etc..
|
|
123
|
+
# EAZY_v1.0 is a NMF derived (basically a PCA) minimal template set from the PEGASE2.0 SEDs
|
|
124
|
+
# BR07 is a NMF derived (basically a PCA) minimal template set derived from a load of BC03 models, designed
|
|
125
|
+
# to reproduce the colours of galaxies in SDSS.
|
|
126
|
+
self.modelSEDDictList=[]
|
|
127
|
+
if templatesDir is None:
|
|
128
|
+
if templateSet not in self.DEFAULT_TEMPLATE_SETS:
|
|
129
|
+
raise Exception("Unknown template set '%s' - options are: %s"
|
|
130
|
+
% (templateSet, ", ".join(self.DEFAULT_TEMPLATE_SETS.keys())))
|
|
131
|
+
print(">>> Using default %s templates" % (templateSet))
|
|
132
|
+
pickleFileName=None
|
|
133
|
+
SEDDir=zCluster.__path__[0]+os.path.sep+'SED'
|
|
134
|
+
self.SEDFiles=[]
|
|
135
|
+
for subDir, pattern in self.DEFAULT_TEMPLATE_SETS[templateSet]:
|
|
136
|
+
self.SEDFiles=self.SEDFiles+glob.glob(SEDDir+os.path.sep+subDir+os.path.sep+pattern)
|
|
137
|
+
#self.SEDFiles=glob.glob(zCluster.__path__[0]+os.path.sep+"SED/uvista_nmf/*.dat")+glob.glob(zCluster.__path__[0]+os.path.sep+"SED/CWW/*.sed")+glob.glob(zCluster.__path__[0]+os.path.sep+"SED/EAZY_v1.0/*.dat")
|
|
138
|
+
#self.SEDFiles=glob.glob(zCluster.__path__[0]+os.path.sep+"SED/EAZY_v1.1_lines/*.dat")+glob.glob(zCluster.__path__[0]+os.path.sep+"SED/CWW/*.sed")+glob.glob(zCluster.__path__[0]+os.path.sep+"SED/uvista_nmf/*.dat")
|
|
139
|
+
#self.SEDFiles=glob.glob(zCluster.__path__[0]+os.path.sep+"SED/BC03Templates/*.res")#+glob.glob(zCluster.__path__[0]+os.path.sep+"SED/CWW/*.sed")
|
|
140
|
+
else:
|
|
141
|
+
# We'll try a few different extensions
|
|
142
|
+
print(">>> Using custom template set from %s" % (templatesDir))
|
|
143
|
+
pickleFileName=templatesDir+os.path.sep+"templates_%s.pkl" % (passbandSet)
|
|
144
|
+
self.SEDFiles=glob.glob(templatesDir+os.path.sep+"*.res")
|
|
145
|
+
self.SEDFiles=self.SEDFiles+glob.glob(templatesDir+os.path.sep+"*.dat")
|
|
146
|
+
self.SEDFiles=self.SEDFiles+glob.glob(templatesDir+os.path.sep+"*.sed")
|
|
147
|
+
self.SEDFiles=self.SEDFiles+glob.glob(templatesDir+os.path.sep+"*spec.txt")
|
|
148
|
+
if len(self.SEDFiles) == 0:
|
|
149
|
+
raise Exception("No SED templates found - check path")
|
|
150
|
+
# Because getting EOF errors under MPI
|
|
151
|
+
pickleFileName=None
|
|
152
|
+
if pickleFileName is not None and os.path.exists(pickleFileName):
|
|
153
|
+
with open(pickleFileName, "rb") as pickleFile:
|
|
154
|
+
unpickler=pickle.Unpickler(pickleFile)
|
|
155
|
+
self.numModels=unpickler.load()
|
|
156
|
+
self.modelFlux=unpickler.load()
|
|
157
|
+
self.templateIndex=unpickler.load()
|
|
158
|
+
self.modelFlux2=self.modelFlux**2
|
|
159
|
+
else:
|
|
160
|
+
self.numModels=len(self.SEDFiles)*len(EBMinusVList)*len(emLinesScaleList)
|
|
161
|
+
i=0
|
|
162
|
+
t=0
|
|
163
|
+
self.templateIndex=[]
|
|
164
|
+
for f in self.SEDFiles:
|
|
165
|
+
s=astSED.SED()
|
|
166
|
+
s.loadFromFile(f)
|
|
167
|
+
t=t+1
|
|
168
|
+
for emScaleFactor in emLinesScaleList:
|
|
169
|
+
if emScaleFactor > 0:
|
|
170
|
+
s.addEmissionLines(emScaleFactor)
|
|
171
|
+
for EBMinusV in EBMinusVList:
|
|
172
|
+
if EBMinusV > 0:
|
|
173
|
+
s.extinctionCalzetti(EBMinusV) # modifies z0flux, so this should be okay
|
|
174
|
+
for z in self.zRange:
|
|
175
|
+
s.redshift(z)
|
|
176
|
+
modelSEDDict=s.getSEDDict(self.passbandsList)
|
|
177
|
+
modelSEDDict['E(B-V)']=EBMinusV
|
|
178
|
+
modelSEDDict['ageGyr']=0.0
|
|
179
|
+
modelSEDDict['z']=z
|
|
180
|
+
modelSEDDict['fileName']=f
|
|
181
|
+
modelSEDDict['modelListIndex']=i
|
|
182
|
+
# modelSEDDict['SED']=s.copy() # Only add this if we need [e.g. rest frame colours] - uses lots of RAM
|
|
183
|
+
self.modelSEDDictList.append(modelSEDDict)
|
|
184
|
+
self.templateIndex.append(t)
|
|
185
|
+
i=i+1
|
|
186
|
+
del s
|
|
187
|
+
self.templateIndex=np.array(self.templateIndex)
|
|
188
|
+
modelFlux=[]
|
|
189
|
+
for modelSEDDict in self.modelSEDDictList:
|
|
190
|
+
modelFlux.append(modelSEDDict['flux'])
|
|
191
|
+
self.modelFlux=np.array(modelFlux)
|
|
192
|
+
self.modelFlux2=self.modelFlux**2
|
|
193
|
+
|
|
194
|
+
# We can pickle if give a custom templates dir
|
|
195
|
+
if templatesDir is not None and pickleFileName is not None:
|
|
196
|
+
with open(pickleFileName, "wb") as pickleFile:
|
|
197
|
+
pickler=pickle.Pickler(pickleFile)
|
|
198
|
+
pickler.dump(self.numModels)
|
|
199
|
+
pickler.dump(self.modelFlux)
|
|
200
|
+
pickler.dump(self.templateIndex)
|
|
201
|
+
|
|
202
|
+
# These can be fitted for on the fly or just specified as an argument
|
|
203
|
+
self.ZPOffsets=np.zeros(self.modelFlux.shape[1])
|
|
204
|
+
if ZPOffsets is not None:
|
|
205
|
+
self.ZPOffsets=ZPOffsets
|
|
206
|
+
|
|
207
|
+
# We might use these...
|
|
208
|
+
dlRange=[]
|
|
209
|
+
for z in self.zRange:
|
|
210
|
+
dlRange.append(astCalc.dl(z))
|
|
211
|
+
self.dlRange=np.array(dlRange)
|
|
212
|
+
|
|
213
|
+
# More sophisticated mag prior... doesn't seem to help
|
|
214
|
+
# Using m* in i-band at z = 0.1 from Popesso et al. and BC03 tau = 0.1 Gyr, solar metallicity, zf = 3
|
|
215
|
+
#MStar=-21.5
|
|
216
|
+
#MStarBand='r'
|
|
217
|
+
#magsBrighterMStarCut=3 # Needs to be a little brighter to leave in BCGs
|
|
218
|
+
#bc03=astSED.BC03Model(zCluster.__path__[0]+os.path.sep+"data"+os.path.sep+"tau0p1Gyr_m62.20")
|
|
219
|
+
#passband=self.passbandsList[self.bands.index(MStarBand)]
|
|
220
|
+
#m=MStar+5.*np.log10(astCalc.dl(0.1)*1e5)
|
|
221
|
+
#magEvo=bc03.getMagEvolution(passband, m, 0.1, 3.0, zStepSize=0.05, magType='AB')
|
|
222
|
+
#tck=interpolate.splrep(magEvo['z'], magEvo['mag'])
|
|
223
|
+
#self.magPriorCut=interpolate.splev(self.zRange, tck)-5.*np.log10(self.dlRange*1e5)-magsBrighterMStarCut
|
|
224
|
+
#self.magPriorBand=self.bands.index(MStarBand)
|
|
225
|
+
|
|
226
|
+
# Less sophisticated mag prior...
|
|
227
|
+
self.magPriorCut=absMagCut
|
|
228
|
+
self.magPriorBand=self.bands.index('r')
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def _prepareFluxes(self, galaxyCatalog, applyZPOffsets = True):
|
|
232
|
+
"""Converts the photometry in galaxyCatalog into the fluxes and inverse variance weights used in SED
|
|
233
|
+
fitting, identifying galaxies that cannot be fitted. Used by :meth:`calcPhotoRedshifts` and
|
|
234
|
+
:meth:`calcZeroPointOffsets`.
|
|
235
|
+
|
|
236
|
+
Args:
|
|
237
|
+
galaxyCatalog (:obj:`list`): Galaxy catalog (list of dictionaries).
|
|
238
|
+
applyZPOffsets (:obj:`bool`, optional): If True, subtract self.ZPOffsets from the magnitudes.
|
|
239
|
+
|
|
240
|
+
Returns:
|
|
241
|
+
A dictionary with keys (all arrays have one row per galaxy, one column per band in self.bands):
|
|
242
|
+
- 'inputMagAB': magnitudes as given (99 for bands not in the catalog)
|
|
243
|
+
- 'magAB': magnitudes used in the fit (after the treatment of bad/missing bands, and zero
|
|
244
|
+
point offsets if applyZPOffsets is True)
|
|
245
|
+
- 'sedFlux', 'sedFluxErr2', 'weights': fluxes, squared flux uncertainties, and
|
|
246
|
+
1/sedFluxErr2
|
|
247
|
+
- 'unfittable': boolean array, True for galaxies that cannot be fitted (one per galaxy)
|
|
248
|
+
|
|
249
|
+
"""
|
|
250
|
+
|
|
251
|
+
ten23=(10**23.0)
|
|
252
|
+
|
|
253
|
+
# If we don't have a band, include a ridiculous mag with ridiculous error so zero weight in fit
|
|
254
|
+
magAB=np.array([[galaxy[k] if k in galaxy else 99.0 for k in self.bands] for galaxy in galaxyCatalog],
|
|
255
|
+
dtype = float)
|
|
256
|
+
magErrAB=np.array([[galaxy['%sErr' % (k)] if k in galaxy else 99.0 for k in self.bands]
|
|
257
|
+
for galaxy in galaxyCatalog], dtype = float)
|
|
258
|
+
inputMagAB=magAB.copy()
|
|
259
|
+
|
|
260
|
+
# Galaxies that cannot be fitted: those with any non-finite magnitude, NaN uncertainty, or magnitude
|
|
261
|
+
# outside (MIN_MAG, MAX_MAG) - e.g., -999 sentinel values for missing data, if these haven't been cut
|
|
262
|
+
# already. These get p(z) = 0 everywhere (previously this happened because the fit gave NaN or
|
|
263
|
+
# meaningless chi-squared values). Their photometry is replaced with placeholder values, so that the
|
|
264
|
+
# calculations below are well defined for every galaxy - the placeholder results are then discarded.
|
|
265
|
+
badBand=np.logical_or(np.logical_not(np.isfinite(magAB)), np.isnan(magErrAB))
|
|
266
|
+
badBand=np.logical_or(badBand, np.logical_or(np.less_equal(magAB, MIN_MAG), np.greater_equal(magAB, MAX_MAG)))
|
|
267
|
+
magAB[badBand]=99.0
|
|
268
|
+
magErrAB[badBand]=99.0
|
|
269
|
+
|
|
270
|
+
# Bands with absurdly large (including infinite) uncertainties are treated as missing, as above
|
|
271
|
+
# (otherwise the flux conversion below overflows - previously this gave such bands zero weight anyway)
|
|
272
|
+
missingBand=np.greater_equal(np.abs(magErrAB), MAX_MAG_ERROR)
|
|
273
|
+
magAB[missingBand]=99.0
|
|
274
|
+
magErrAB[missingBand]=99.0
|
|
275
|
+
|
|
276
|
+
if applyZPOffsets == True:
|
|
277
|
+
magAB=magAB-self.ZPOffsets
|
|
278
|
+
|
|
279
|
+
# Incorporate a global photometric calibration error (applied to all bands)
|
|
280
|
+
# Helps to get catalogs with tiny errors to behave
|
|
281
|
+
magErrAB=np.sqrt(magErrAB**2+self.ZPError**2)
|
|
282
|
+
|
|
283
|
+
fluxJy=ten23*np.power(10, (-(magAB+48.6)/2.5))
|
|
284
|
+
sedFlux=3e-13*fluxJy/self.effLMicron2
|
|
285
|
+
fluxJyErr=ten23*np.power(10, (-(magAB-magErrAB+48.6)/2.5))
|
|
286
|
+
sedFluxErr=(3e-13*fluxJyErr/self.effLMicron2)-sedFlux
|
|
287
|
+
sedFluxErr2=sedFluxErr**2
|
|
288
|
+
# A zero flux uncertainty (zero magnitude uncertainty with no ZPError, or one too small to change the
|
|
289
|
+
# flux) would give infinite weight, so these galaxies cannot be fitted either
|
|
290
|
+
zeroErr=np.equal(sedFluxErr2, 0)
|
|
291
|
+
sedFluxErr2[zeroErr]=1.0
|
|
292
|
+
weights=1.0/sedFluxErr2
|
|
293
|
+
unfittable=np.logical_or(badBand, zeroErr).any(axis = 1)
|
|
294
|
+
|
|
295
|
+
return {'inputMagAB': inputMagAB, 'magAB': magAB, 'sedFlux': sedFlux, 'sedFluxErr2': sedFluxErr2,
|
|
296
|
+
'weights': weights, 'unfittable': unfittable}
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
def calcZeroPointOffsets(self, galaxyCatalog, zSpecColumn = 'z_spec'):
|
|
300
|
+
"""If the galaxyCatalog contains zSpecColumn, fit SEDs at given spec-zs to determine
|
|
301
|
+
zero point offsets. After this is done, they will automatically be applied by calcPhotoRedshifts.
|
|
302
|
+
|
|
303
|
+
For each galaxy with a spec-z, every template is fitted at the grid redshift closest to the spec-z,
|
|
304
|
+
and the model magnitudes are averaged over templates (weighted by fit probability). The offset in each
|
|
305
|
+
band is the median difference between observed and model magnitudes (ignoring differences > 1 mag,
|
|
306
|
+
which come from missing data).
|
|
307
|
+
|
|
308
|
+
Galaxies that cannot be fitted (see :meth:`_prepareFluxes`), or for which every template has zero
|
|
309
|
+
probability, are not used. If no usable galaxies have data in a band, the offset for that band is set
|
|
310
|
+
to 0.
|
|
311
|
+
|
|
312
|
+
"""
|
|
313
|
+
print("... calculating zero point offsets for each band using objects with spec-zs ...")
|
|
314
|
+
specZCatalog=[galaxy for galaxy in galaxyCatalog if zSpecColumn in galaxy.keys() and galaxy[zSpecColumn] > 0]
|
|
315
|
+
if len(specZCatalog) == 0:
|
|
316
|
+
raise Exception("No objects with spec-zs (column '%s' > 0) found - can't fit for zero point offsets" % (zSpecColumn))
|
|
317
|
+
|
|
318
|
+
# NOTE: Offsets are fitted to the photometry as given (i.e., any existing self.ZPOffsets are not applied)
|
|
319
|
+
fluxDict=self._prepareFluxes(specZCatalog, applyZPOffsets = False)
|
|
320
|
+
fittable=np.logical_not(fluxDict['unfittable'])
|
|
321
|
+
magAB=fluxDict['inputMagAB'][fittable]
|
|
322
|
+
sedFlux=fluxDict['sedFlux'][fittable]
|
|
323
|
+
sedFluxErr2=fluxDict['sedFluxErr2'][fittable]
|
|
324
|
+
zSpec=np.array([galaxy[zSpecColumn] for galaxy in specZCatalog], dtype = float)[fittable]
|
|
325
|
+
|
|
326
|
+
# Model fluxes for every template, at the redshift grid point closest to each galaxy's spec-z
|
|
327
|
+
# (arrays below are galaxies x templates x bands)
|
|
328
|
+
zIndices=np.argmin(np.abs(zSpec.reshape(-1, 1)-self.zRange), axis = 1)
|
|
329
|
+
numBands=len(self.bands)
|
|
330
|
+
modelFlux=self.modelFlux.reshape([self.numModels, self.zRange.shape[0], numBands])[:, zIndices, :]
|
|
331
|
+
modelFlux=modelFlux.transpose([1, 0, 2])
|
|
332
|
+
modelFlux2=self.modelFlux2.reshape([self.numModels, self.zRange.shape[0], numBands])[:, zIndices, :]
|
|
333
|
+
modelFlux2=modelFlux2.transpose([1, 0, 2])
|
|
334
|
+
sedFlux=sedFlux.reshape([-1, 1, numBands])
|
|
335
|
+
sedFluxErr2=sedFluxErr2.reshape([-1, 1, numBands])
|
|
336
|
+
|
|
337
|
+
# Best-fit normalisation and chi-squared for each template - models with zero flux in every band
|
|
338
|
+
# (only possible with custom templates) can't be fitted, so get zero probability
|
|
339
|
+
normNumerator=np.sum((modelFlux*sedFlux)/(sedFluxErr2), axis = 2)
|
|
340
|
+
normDenominator=np.sum(modelFlux2/sedFluxErr2, axis = 2)
|
|
341
|
+
fittableModel=np.greater(normDenominator, 0)
|
|
342
|
+
norm=np.divide(normNumerator, normDenominator, where = fittableModel, out = np.zeros(normNumerator.shape))
|
|
343
|
+
modFlux=norm.reshape(list(norm.shape)+[1])*modelFlux
|
|
344
|
+
chiSq=np.sum(((sedFlux-modFlux)**2)/sedFluxErr2, axis = 2)
|
|
345
|
+
chiSqProb=np.exp(-chiSq/2)
|
|
346
|
+
chiSqProb[np.logical_not(fittableModel)]=0.0
|
|
347
|
+
|
|
348
|
+
# Probability-weighted average model flux - only for galaxies where some template has non-zero
|
|
349
|
+
# probability (i.e., not those that are a terrible fit to every template)
|
|
350
|
+
probSum=np.sum(chiSqProb, axis = 1)
|
|
351
|
+
useGalaxy=np.greater(probSum, 0)
|
|
352
|
+
modFlux=np.sum(modFlux[useGalaxy]*chiSqProb[useGalaxy].reshape([-1, self.numModels, 1]), axis = 1)
|
|
353
|
+
modFlux=modFlux/probSum[useGalaxy].reshape([-1, 1])
|
|
354
|
+
modFluxJy=(modFlux*self.effLMicron2)/3e-13
|
|
355
|
+
# Galaxies that fit every template extremely badly (chi-squared ~1500 or more) have template
|
|
356
|
+
# probabilities that are all zero, or tiny subnormal numbers (e.g., 1e-320), in which case the weighted
|
|
357
|
+
# average model flux underflows to zero. These galaxies are not used either.
|
|
358
|
+
# (Previously, these gave -inf magnitude differences, which were included in the median.)
|
|
359
|
+
positiveFlux=np.greater(modFluxJy, 0).all(axis = 1)
|
|
360
|
+
modFluxJy=modFluxJy[positiveFlux]
|
|
361
|
+
modMags=-2.5*np.log10(modFluxJy/1e23)-48.6
|
|
362
|
+
diffMags=magAB[useGalaxy][positiveFlux]-modMags
|
|
363
|
+
print("... using %d/%d objects with spec-zs ..." % (diffMags.shape[0], len(specZCatalog)))
|
|
364
|
+
|
|
365
|
+
# Average after taking out differenced 99 values for missing data
|
|
366
|
+
ZPOffsets=[]
|
|
367
|
+
for i in range(numBands):
|
|
368
|
+
d=diffMags[:, i]
|
|
369
|
+
d=d[np.less(d, 1)]
|
|
370
|
+
if len(d) > 0:
|
|
371
|
+
ZPOffsets.append(np.median(d))
|
|
372
|
+
else:
|
|
373
|
+
print("... WARNING: no usable objects with spec-zs have data in band %s - setting zero point offset to 0 ..." % (self.bands[i]))
|
|
374
|
+
ZPOffsets.append(0.0)
|
|
375
|
+
self.ZPOffsets=np.array(ZPOffsets)
|
|
376
|
+
print("... offsets found: %s mag." % (str(self.ZPOffsets)))
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
def calcPhotoRedshifts(self, galaxyCatalog, calcMLRedshiftAndOdds = False, returnPZ = True,
|
|
380
|
+
storeBestFitSEDModels = False):
|
|
381
|
+
"""Calculates photometric redshifts and adds to the galaxy catalog in place.
|
|
382
|
+
|
|
383
|
+
NOTE: since normally we're normally only interested in p(z), this only returns
|
|
384
|
+
the maximum likelihood z and BPZ-style odds parameter if calcMLRedshiftAndOdds = True.
|
|
385
|
+
|
|
386
|
+
"""
|
|
387
|
+
|
|
388
|
+
# Note that we now aren't checking for junk/bad bands in the catalogue
|
|
389
|
+
# That should have been dealt with before getting to this stage
|
|
390
|
+
# Galaxies are fitted in batches using matrix products, rather than one at a time. For each galaxy,
|
|
391
|
+
# with fluxes f, inverse variance weights w, and model fluxes M (one row per template/z combination):
|
|
392
|
+
# norm = sum(f*w*M)/sum(w*M^2)
|
|
393
|
+
# chiSq = sum(w*(f - norm*M)^2) = sum(w*f^2) - sum(f*w*M)^2/sum(w*M^2)
|
|
394
|
+
# so both sums over bands can be done for a whole batch of galaxies in one matrix multiplication.
|
|
395
|
+
if len(galaxyCatalog) == 0:
|
|
396
|
+
return None
|
|
397
|
+
if self.ZPOffsets.sum() != 0:
|
|
398
|
+
print("... applying zero-point offsets:", self.ZPOffsets, "...")
|
|
399
|
+
fluxDict=self._prepareFluxes(galaxyCatalog)
|
|
400
|
+
magAB=fluxDict['magAB']
|
|
401
|
+
sedFlux=fluxDict['sedFlux']
|
|
402
|
+
weights=fluxDict['weights']
|
|
403
|
+
unfittable=fluxDict['unfittable']
|
|
404
|
+
|
|
405
|
+
# Mag prior (one row per galaxy)
|
|
406
|
+
absMag=magAB[:, self.magPriorBand].reshape(-1, 1)-5.0*np.log10(1e5*self.dlRange)
|
|
407
|
+
if np.ndim(self.magPriorCut) == 0:
|
|
408
|
+
pPrior=np.greater(absMag, self.magPriorCut)
|
|
409
|
+
elif len(self.magPriorCut) == 2:
|
|
410
|
+
pPrior=np.logical_and(np.greater(absMag, self.magPriorCut[0]), np.less(absMag, self.magPriorCut[1]))
|
|
411
|
+
else:
|
|
412
|
+
raise Exception("magPriorCut should have only 1 or 2 elements")
|
|
413
|
+
|
|
414
|
+
# Batch size chosen to keep the (galaxies x models) work arrays to ~1 Mb each, so they stay in CPU cache
|
|
415
|
+
# (in testing, this was ~3x faster than batches of ~40 Mb)
|
|
416
|
+
numModelRows=self.modelFlux.shape[0]
|
|
417
|
+
batchSize=max(1, int(1e5/numModelRows))
|
|
418
|
+
modelFluxT=self.modelFlux.T
|
|
419
|
+
modelFlux2T=self.modelFlux2.T
|
|
420
|
+
numGals=len(galaxyCatalog)
|
|
421
|
+
pzArray=np.zeros([numGals, self.zRange.shape[0]])
|
|
422
|
+
for start in range(0, numGals, batchSize):
|
|
423
|
+
end=min(start+batchSize, numGals)
|
|
424
|
+
f=sedFlux[start:end]
|
|
425
|
+
w=weights[start:end]
|
|
426
|
+
fw=f*w
|
|
427
|
+
num=fw @ modelFluxT
|
|
428
|
+
den=w @ modelFlux2T
|
|
429
|
+
# den = sum(w*M^2) is only zero for a model with zero flux in every band (possible with custom
|
|
430
|
+
# templates) - these models can't be fitted, so get chiSq = 1e6 (i.e., zero probability)
|
|
431
|
+
fittableModel=np.greater(den, 0)
|
|
432
|
+
chiSq=np.sum(fw*f, axis = 1).reshape(-1, 1)-np.divide(num*num, den, where = fittableModel,
|
|
433
|
+
out = np.zeros(den.shape))
|
|
434
|
+
chiSq[np.logical_not(fittableModel)]=1e6
|
|
435
|
+
chiSq[unfittable[start:end]]=1e6
|
|
436
|
+
|
|
437
|
+
# This is useful if we want to add rest frame color calculation
|
|
438
|
+
if storeBestFitSEDModels == True:
|
|
439
|
+
bestIndices=np.argmin(chiSq, axis = 1)
|
|
440
|
+
for i, bestIndex in enumerate(bestIndices):
|
|
441
|
+
galaxyCatalog[start+i]['bestFitSED']=self.modelSEDDictList[self.templateIndex[bestIndex]]['SED']
|
|
442
|
+
|
|
443
|
+
# This uses all templates at once - take max probability over templates at each z
|
|
444
|
+
# NOTE: max(exp(-chiSq/2)) == exp(-min(chiSq)/2), so take the min first (far fewer exp calls)
|
|
445
|
+
chiSq=chiSq.reshape([end-start, self.numModels, self.zRange.shape[0]])
|
|
446
|
+
pzArray[start:end]=np.exp(-np.min(chiSq, axis = 1)/2)
|
|
447
|
+
|
|
448
|
+
pzArray=pzArray*pPrior
|
|
449
|
+
# Normalise
|
|
450
|
+
pzNorm=np.trapezoid(pzArray, self.zRange, axis = 1)
|
|
451
|
+
nonZero=pzNorm != 0
|
|
452
|
+
pzArray[nonZero]=pzArray[nonZero]/pzNorm[nonZero].reshape(-1, 1)
|
|
453
|
+
|
|
454
|
+
for galaxy, pz in zip(galaxyCatalog, pzArray):
|
|
455
|
+
if calcMLRedshiftAndOdds == True:
|
|
456
|
+
zp, odds=self.calculateMLRedshiftAndOdds(pz, dzOdds = 0.2)
|
|
457
|
+
galaxy['zPhot']=zp
|
|
458
|
+
galaxy['odds']=odds
|
|
459
|
+
if returnPZ == True:
|
|
460
|
+
galaxy['pz']=pz
|
|
461
|
+
galaxy['pz_z']=self.zRange
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
def calculateMLRedshiftAndOdds(self, pz, dzOdds = 0.2, method = 'max'):
|
|
465
|
+
"""Calculates maximum likelihood z and BPZ/EAZY style odds for given pz, zArray
|
|
466
|
+
|
|
467
|
+
Method == 'max' finds z based on max peak in pz
|
|
468
|
+
Method == 'odds' finds z based on z at which odds is maximised
|
|
469
|
+
|
|
470
|
+
"""
|
|
471
|
+
|
|
472
|
+
# zRange is a uniform grid, so z -> index is linear (this replaces a spline fit made on every call)
|
|
473
|
+
zGridStep=self.zRange[1]-self.zRange[0]
|
|
474
|
+
def zToIndex(zs):
|
|
475
|
+
return (np.array(zs)-self.zRange[0])/zGridStep
|
|
476
|
+
z=self.zRange[np.argmax(pz)]
|
|
477
|
+
|
|
478
|
+
if method == 'max':
|
|
479
|
+
zMin=z-dzOdds
|
|
480
|
+
zMax=z+dzOdds
|
|
481
|
+
indexMin, indexMax=zToIndex([zMin, zMax])
|
|
482
|
+
indexMin=int(round(indexMin))
|
|
483
|
+
indexMax=int(round(indexMax))
|
|
484
|
+
if indexMin < 0:
|
|
485
|
+
indexMin=0
|
|
486
|
+
if indexMax > pz.shape[0]-1:
|
|
487
|
+
indexMax=pz.shape[0]-1
|
|
488
|
+
odds=np.trapezoid(pz[indexMin:indexMax], self.zRange[indexMin:indexMax])
|
|
489
|
+
|
|
490
|
+
elif method == 'odds':
|
|
491
|
+
zOdds=[]
|
|
492
|
+
for zi in self.zRange:
|
|
493
|
+
zMin=zi-dzOdds
|
|
494
|
+
zMax=zi+dzOdds
|
|
495
|
+
indexMin, indexMax=zToIndex([zMin, zMax])
|
|
496
|
+
indexMin=int(round(indexMin))
|
|
497
|
+
indexMax=int(round(indexMax))
|
|
498
|
+
if indexMin < 0:
|
|
499
|
+
indexMin=0
|
|
500
|
+
if indexMax > pz.shape[0]-1:
|
|
501
|
+
indexMax=pz.shape[0]-1
|
|
502
|
+
odds=np.trapezoid(pz[indexMin:indexMax], self.zRange[indexMin:indexMax])
|
|
503
|
+
zOdds.append(odds)
|
|
504
|
+
zOdds=np.array(zOdds)
|
|
505
|
+
z=self.zRange[zOdds.tolist().index(zOdds.max())]
|
|
506
|
+
odds=zOdds[zOdds.tolist().index(zOdds.max())]
|
|
507
|
+
|
|
508
|
+
return [z, odds]
|
|
509
|
+
|
|
510
|
+
|
|
511
|
+
def estimateStellarMasses(self, galaxyCatalog, stellarMassModelDir, z = None):
|
|
512
|
+
"""Given a directory containing BC03-format stellar population models, estimate
|
|
513
|
+
the stellar mass of galaxies in the given catalog.
|
|
514
|
+
|
|
515
|
+
Args:
|
|
516
|
+
galaxyCatalog (:obj:`list`): Galaxy catalog as a list of dictionaries, i.e.,
|
|
517
|
+
in the format returned by self.calcPhotoRedshifts().
|
|
518
|
+
stellarMassModelDir (:obj:`str`): Path to a directory containing the stellar
|
|
519
|
+
population models (BC03 format for now).
|
|
520
|
+
z (:obj:`float`, optional): If given, the redshift will be fixed to this value
|
|
521
|
+
and applied to all the galaxies in the catalog (this is what you want for
|
|
522
|
+
galaxy clusters, and is quicker). If None, then the maximum likelihood
|
|
523
|
+
redshift of each individual galaxy will be used (this will be very slow,
|
|
524
|
+
but actually isn't implemented yet...).
|
|
525
|
+
|
|
526
|
+
Returns:
|
|
527
|
+
None ['log10StellarMass' key is added in-place to each galaxy in galaxyCatalog]
|
|
528
|
+
|
|
529
|
+
"""
|
|
530
|
+
|
|
531
|
+
if z is None:
|
|
532
|
+
raise Exception("Stellar mass estimation at individual galaxy maximum likelihood redshifts is not implemented yet.")
|
|
533
|
+
|
|
534
|
+
# Make model SEDs - this is very time consuming and needs a lot of speeding up...
|
|
535
|
+
modelSEDDictList=sm.setUpStellarMassSEDs(stellarMassModelDir, self.passbandsList, z)
|
|
536
|
+
|
|
537
|
+
# Fit each observed SED
|
|
538
|
+
wantedKeys=['log10StellarMass']
|
|
539
|
+
count=0
|
|
540
|
+
DL=astCalc.dl(z)
|
|
541
|
+
print(">>> Estimating stellar masses")
|
|
542
|
+
for objDict in galaxyCatalog:
|
|
543
|
+
count=count+1
|
|
544
|
+
print("... %d/%d ..." % (count, len(galaxyCatalog)))
|
|
545
|
+
mags=[]
|
|
546
|
+
magErrs=[]
|
|
547
|
+
for band in self.bands:
|
|
548
|
+
if band in list(objDict.keys()):
|
|
549
|
+
mags.append(objDict[band])
|
|
550
|
+
magErrs.append(objDict[band+"Err"])
|
|
551
|
+
else:
|
|
552
|
+
mags.append(99)
|
|
553
|
+
magErrs.append(99)
|
|
554
|
+
obsSEDDict=astSED.mags2SEDDict(mags, magErrs, self.passbandsList)
|
|
555
|
+
distNorm=4*np.pi*np.power(DL*3.08567758e24, 2)
|
|
556
|
+
fitResult=sm.fitSEDDictAndCalcStellarMass(obsSEDDict, modelSEDDictList, distNorm)
|
|
557
|
+
# Insert monte-carlo error estimation here...
|
|
558
|
+
for key in wantedKeys:
|
|
559
|
+
objDict[key]=fitResult[key]
|