예제 #1
0
파일: chmcRun.py 프로젝트: jmrv/scandium
def runOneChain(iChain,convConn):
	# priors:
	normp = prior.uniform(10**-4,10**-2.5,isLog=True)			# powerlaw norm			
	alphap = prior.uniform(2.0,3.5)							# powerlaw power			
	nHp = prior.uniform(0.5,3.0)						# nH (absorption)	
	scareap = prior.uniform(1e-10,1e-6,isLog=True)		# Sc line area
	area1p = prior.uniform(10**-8,10**-5,isLog=True)		# nuisance line 1
	center1p = prior.uniform(3.5,3.75)					# 					
	sigma1p = prior.uniform(0.001,0.1)					# natural width 
	area2p = prior.uniform(10**-7,10**-5,isLog=True)		# nuisance line 2
	center2p = prior.uniform(3.75,4.0)					# 				
	sigma2p = prior.uniform(0.001,0.1)					# natural width 
	
	g.priors = [normp,alphap,nHp,scareap,area1p,center1p,sigma1p,area2p,center2p,sigma2p]

	# parameters ('name', x_init, isFrozen):
	names = ['norm', 'alpha', 'nH', 'Sc area', 'area1', 'center1', 'sigma1', 
				'area2', 'center2', 'sigma2']
	g.initParams = []
	for i in range(len(g.priors)):
		if i == 2:	# nH set by hwang '12
			g.initParams.append(cob.param(names[i], 2.0, True))
		else:
			g.initParams.append(cob.param(names[i], g.priors[i].sample(), False))

	for i,p in enumerate(g.initParams):
		p.setPrior(i)

	# which indices are thawed:
	for i,p in enumerate(g.initParams):
		if(not p.isFrozen):
			g.thawedIdxs.append(i)
	
	# mass vector for parameters:
	g.masses = ones(len(g.initParams))		
	g.masses[0] = 1.0		# powerlaw norm
	g.masses[1] = 1.0		# powerlaw alpha
	#g.masses[2] = 1.0		# nH
	g.masses[3] = 1.0		# Sc area
	g.masses[4] = 1.0		# area 1
	g.masses[5] = 1.0		# center 1
	g.masses[6] = 0.5		# sigma 1
	g.masses[7] = 1.0		# area 2
	g.masses[8] = 1.0		# center 2
	g.masses[9] = 0.5		# sigma 2
	
	# data and likelihood:
	epochs = ['4634','4635','4636','4637','4638']		
	#epochs = ['4637']
	datasets = []
	fnames = []
	
	for e in epochs:
		#froot = g.datadir+'cpoor'
		froot = g.datadir+'eastegg'+'-'+e
		fnames.append(froot)
		datasets.append(cob.dataset(froot, [3.4,5],
						g.datadir+'../bkgd', g.Aeastegg/g.Abkgd))

	g.likelihood = likelihood.ScLike(datasets, g.codedir+'models/phabs1e22.txt')
	
	g.dumpInfo(g.initParams, g.priors, g.masses, g.likelihood,fnames=fnames)

	# start the chain:
	fname = g.chaindir+'chain-'+str(iChain)+'.txt'
	ch = cob.chain(fname,convConn)
	
	# evolve the chain:
	# (the convergence monitor will only send anything to this end of 
	#  the pipe once all chains have converged. evolve until then.)
	while not convConn.poll():
		ch.evolve()
예제 #2
0
파일: chmcRun.py 프로젝트: jmrv/chmc
def runOneChain(iChain,convConn):
	# priors:
	normp = prior.uniform(1e-6,1e1,isLog=True)			# powerlaw norm			
	alphap = prior.uniform(1,5)							# powerlaw power			

	nHp = prior.uniform(0.5,3.0)						# nH (absorption)	
														# based on hwang+ 2012

	scareap = prior.uniform(1e-9,1e-3,isLog=True)		# Sc line area

	area1p = prior.uniform(1e-9,1e-3,isLog=True)		# nuisance line 1
	center1p = prior.uniform(3.5,3.75)					# 					
	sigma1p = prior.uniform(0.001,0.1)					# natural width 
	
	area2p = prior.uniform(1e-9,1e-2,isLog=True)		# nuisance line 2
	center2p = prior.uniform(3.75,4.0)					# 				
	sigma2p = prior.uniform(0.001,0.1)					# natural width 
	
	g.priors = [	normp,alphap, \
					nHp, \
					scareap, \
					area1p,center1p,sigma1p, \
					area2p,center2p,sigma2p]

	# parameters ('name', x_init, isFrozen):
	norm = cob.param('norm',10**-1.4,False)
	alpha = cob.param('alpha',3.3,False)

	nH = cob.param('nH',2.0,True)

	scarea = cob.param('Sc area',1e-7,False)

	area1 = cob.param('area1',10**-5.2,False)
	center1 = cob.param('center1',3.69,False)
	sigma1 = cob.param('sigma1',0.005,False)

	area2 = cob.param('area2',10**-4.5,False)
	center2 = cob.param('center2',3.86,False)
	sigma2 = cob.param('sigma2',0.01,False)
	g.initParams = [	norm,alpha, \
						nH, \
						scarea, \
						area1,center1,sigma1, \
						area2,center2,sigma2]

	for i,p in enumerate(g.initParams):
		p.setPrior(i)

	# which indexes are thawed:
	for i,p in enumerate(g.initParams):
		if(not p.isFrozen):
			g.thawedIdxs.append(i)
	
	# mass vector for parameters:
	g.masses = ones(len(g.initParams))		
	g.masses[0] = 0.2		# powerlaw norm
	g.masses[1] = 0.2		# powerlaw alpha
	#g.masses[2] = 0.1		# nH
	g.masses[3] = 0.01		# Sc area
	g.masses[4] = 0.01		# area 1
	g.masses[5] = 0.01		# center 1
	g.masses[6] = 0.01		# sigma 1
	g.masses[7] = 0.01		# area 2
	g.masses[8] = 0.01		# center 2
	g.masses[9] = 0.01		# sigma 2
	
	# data and likelihood:
	#epochs = ['4634','4635','4636','4637','4638']		
	epochs = ['4637']		
	datasets = []
	fnames = []
	
	for e in epochs:
		#froot = g.datadir+'fe'
		froot = g.datadir+'eastegg'+'-'+e
		fnames.append(froot)
		datasets.append(cob.dataset(froot, [3.4,5],
						g.datadir+'../bkgd', g.Aeastegg/g.Abkgd))
	g.likelihood = likelihood.ScLike(datasets, g.codedir+'models/phabs1e22.txt')
	
	g.dumpInfo(g.initParams, g.priors, g.masses, g.likelihood,fnames=fnames)

	# start the chain:
	fname = g.chaindir+'chain-'+str(iChain)+'.txt'
	ch = cob.chain(fname,convConn)
	
	# evolve the chain:
	# (the convergence monitor will only send anything to this end of 
	#  the pipe once all chains have converged. evolve until then.)
	while not convConn.poll():
		ch.evolve()