From 62a52c86a8d57d92678ca2cec51e19d2bcaaa10a Mon Sep 17 00:00:00 2001 From: Matt Hilton Date: Sun, 23 Jul 2023 15:30:51 +0200 Subject: [PATCH] Allow both faint and bright abs mag cuts --- bin/zCluster | 16 +++++++++++++--- zCluster/PhotoRedshiftEngine.py | 7 ++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/bin/zCluster b/bin/zCluster index 5938540..bcf7a7d 100644 --- a/bin/zCluster +++ b/bin/zCluster @@ -444,8 +444,11 @@ def makeParser(): default = None) parser.add_argument("-Z", "--z-prior-max", dest="zPriorMax", help="Set maximum redshift of prior.", default = None) - parser.add_argument("-b", "--brighter-absmag-cut", dest="absMagCut", help="Set bright absolute magnitude cut.", - default = -24., type = float) + parser.add_argument("-b", "--absmag-cut", dest="absMagCut", + help="Set absolute (r-band) magnitude cut to use in magnitude-based prior. If a single number\ + is given, p(z) for objects brighter than this limit will be set to 0. If a\ + list of numbers is given (e.g., [-15,-24]), p(z) will be set to 0\ + for objects outside of the absolute magnitude range.", default = -24.) parser.add_argument("-n", "--name", dest="name", help="Find photo-z of only the named cluster in the catalog.") parser.add_argument("-t", "--templates-directory", dest="templatesDir", help="Specify a directory containing\ a custom set of spectral templates.", default = None) @@ -494,7 +497,14 @@ if __name__ == '__main__': MPIEnabled=args.MPIEnabled maxMagError=float(args.maxMagError) #magsBrighterMStarCut=float(args.magsBrighterMStarCut) - absMagCut=float(args.absMagCut) + try: + absMagCut=float(args.absMagCut) + except: + vals=args.absMagCut.replace("[", "").replace("]", "").split(",") + if len(vals) != 2: + raise Exception("If you want to give a range for --absmag-cut, write as e.g. [-15,-23]") + absMagCut=[float(vals[0]), float(vals[1])] + absMagCut.sort() # Bright mag comes first writeGalaxyCatalogs=args.writeGalaxyCatalogs writePlots=args.writePlots maskPath=args.mask diff --git a/zCluster/PhotoRedshiftEngine.py b/zCluster/PhotoRedshiftEngine.py index e5c0366..5d21ebf 100644 --- a/zCluster/PhotoRedshiftEngine.py +++ b/zCluster/PhotoRedshiftEngine.py @@ -328,7 +328,12 @@ def calcPhotoRedshifts(self, galaxyCatalog, calcMLRedshiftAndOdds = False, retur pz=np.max(chiSqProb, axis = 0) # Mag prior absMag=magAB[self.magPriorBand]-5.0*np.log10(1e5*self.dlRange) - pPrior=np.array(np.greater(absMag, self.magPriorCut), dtype = float) + if type(self.magPriorCut) == float: + pPrior=np.array(np.greater(absMag, self.magPriorCut), dtype = float) + elif len(self.magPriorCut) == 2: + pPrior=np.array(np.logical_and(np.greater(absMag, self.magPriorCut[0]), np.less(absMag, self.magPriorCut[1]), dtype = float)) + else: + raise Exception("magPriorCut should have only 1 or 2 elements") pz=pz*pPrior # Normalise pzNorm=np.trapz(pz, self.zRange)