def testBasic(self): """Test basic operation of PfsConfig""" config = PfsConfig(self.pfsDesignId, self.visit0, self.raBoresight.asDegrees(), self.decBoresight.asDegrees(), self.fiberId, self.tract, self.patch, self.ra, self.dec, self.catId, self.objId, self.targetType, self.fiberStatus, self.fiberMag, self.filterNames, self.pfiCenter, self.pfiNominal) dirName = os.path.splitext(__file__)[0] if not os.path.exists(dirName): os.makedirs(dirName) filename = os.path.join(dirName, config.filename) if os.path.exists(filename): os.unlink(filename) try: config.write(dirName=dirName) other = PfsConfig.read(self.pfsDesignId, self.visit0, dirName=dirName) self.assertPfsConfig(config, other) except Exception: raise # Leave file for manual inspection else: os.unlink(filename)
def selectFiber(dirName, pfsDesignId, visit0, catId, tractId, patch, objId): """Select a fiber by its target Parameters ---------- dirName : `str` Name of directory containing the data. pfsDesignId : `int` Identifier for top-end design. visit0 : `int` Initial visit for top-end design (may be distinct from 'visit'). catId : `int` Catalog identifier. tractId : `int` Tract identifier. patch : `str` Patch identifier (typically two integers separated by a comma). objId : `int` Object identifier. Returns ------- fiberId : `int` Fiber identifier. """ config = PfsConfig.read(pfsDesignId, visit0, dirName=dirName) index = config.selectTarget(catId, tractId, patch, objId) return config.fiberId[index]
def testBasic(self): """Test basic operation of PfsConfig""" config = PfsConfig(self.pfiDesignId, self.expId, self.raBoresight.asDegrees(), self.decBoresight.asDegrees(), self.fiberId, self.tract, self.patch, self.ra, self.dec, self.catId, self.objId, self.targetType, self.fiberMag, self.filterNames, self.pfiCenter, self.pfiNominal) dirName = os.path.splitext(__file__)[0] if not os.path.exists(dirName): os.makedirs(dirName) filename = os.path.join(dirName, config.filename) if os.path.exists(filename): os.unlink(filename) try: config.write(dirName=dirName) other = PfsConfig.read(self.pfiDesignId, self.expId, dirName=dirName) self.assertPfsConfig(config, other) except Exception: raise # Leave file for manual inspection else: os.unlink(filename)
def main(pfsConfigId, tract, patch, fiberId=None, dataDir=".", objId=None, showPfsArm=False, showPfsArmSet=False, showPfsObject=False): pfsConfig = PfsConfig(pfsConfigId) pfsConfig.read(dataDir) if objId is None: if fiberId is None: fiberId = 1 else: import numpy as np import sys try: _fiberId = np.where(pfsConfig.objId == objId)[0][0] except IndexError: print >> sys.stderr, "Unable to find objId %08x in configuration with pfsConfigId 0x%08x" % \ (objId, pfsConfigId) return _fiberId += 1 # 1-indexed if fiberId is not None and fiberId != _fiberId: print >> sys.stderr, "fiberId %d doesn't match objId %08x's fiber %d" % \ (fiberId, objId, _fiberId) return fiberId = _fiberId objId = pfsConfig.objId[fiberId - 1] print "fiberId = %d, objId = 0x%x" % (fiberId, objId) #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- pfsArms = PfsArmSet(visit=1, spectrograph=1) pfsArms.read(dataDir) if showPfsArm: if True: pfsArms.data['r'].plot(fiberId=fiberId) else: pfsArms.data['r'].plot(fiberId=fiberId, showFlux=True, showSky=True, showCovar=True, showMask=True) if showPfsArmSet: if True: pfsArms.plot(fiberId=fiberId) else: pfsArms.plot(fiberId=fiberId, showFlux=True, showSky=True, showCovar=True, showMask=True) #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- pfsObject = makePfsObject(tract, patch, objId, [pfsArms]) pfsObject.write(dataDir) npfs = PfsObject(tract, patch, objId, visits=[1]) npfs.read(dataDir) if showPfsObject: if True: npfs.plot(showFluxTbl=True) else: npfs.plot(showFlux=True, showSky=True, showCovar=True, showCovar2=True) npfs.plot(showFluxTbl=True, showFluxVariance=False)
def main(pfsConfigId, tract, patch, fiberId=None, dataDir=".", objId=None, showPfsArm=False, showPfsArmSet=False, showPfsObject=False): pfsConfig = PfsConfig(pfsConfigId, tract, patch) pfsConfig.read(dataDir) if objId is None: if fiberId is None: fiberId = 1 else: import numpy as np import sys try: _fiberId = np.where(pfsConfig.objId == objId)[0][0] except IndexError: print("Unable to find objId %08x in configuration with pfsConfigId 0x%08x" % \ (objId, pfsConfigId), file=sys.stderr) return _fiberId += 1 # 1-indexed if fiberId is not None and fiberId != _fiberId: print("fiberId %d doesn't match objId %08x's fiber %d" % \ (fiberId, objId, _fiberId), file=sys.stderr) return fiberId = _fiberId objId = pfsConfig.objId[fiberId - 1] print("fiberId = %d, objId = 0x%x" % (fiberId, objId)) #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- pfsArms = PfsArmSet(visit=1, spectrograph=1, pfsConfigId=pfsConfigId) pfsArms.read(dataDir) if showPfsArm: if True: pfsArms.data['r'].plot(fiberId=fiberId) else: pfsArms.data['r'].plot(fiberId=fiberId, showFlux=True, showSky=True, showCovar=True, showMask=True) if showPfsArmSet: if True: pfsArms.plot(fiberId=fiberId) else: pfsArms.plot(fiberId=fiberId, showFlux=True, showSky=True, showCovar=True, showMask=True) #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- pfsObject = makePfsObject(objId, [pfsArms]) pfsObject.write(dataDir) npfs = PfsObject(tract, patch, objId, visits=[1]) npfs.read(dataDir) if showPfsObject: if True: npfs.plot(showFluxTbl=True) else: npfs.plot(showFlux=True, showSky=True, showCovar=True, showCovar2=True) npfs.plot(showFluxTbl=True, showFluxVariance=False)