コード例 #1
0
if redshift_uncertain:
    priors.append(limited_0_10)
    parameters.append(redshift)
priorfunction = bxa.create_prior_function(priors=priors)
assert not numpy.isnan(
    calc_stat(id)), 'NaN on calc_stat, probably a bad RMF/ARF file for PC'
if id2:
    assert not numpy.isnan(
        calc_stat(id2)), 'NaN on calc_stat, probably a bad RMF/ARF file for WT'
print('running BXA ...')
outputfiles_basename = 'spherefit3_'
if not os.path.exists(outputfiles_basename + 'params.json'):
    bxa.nested_run(id,
                   otherids=otherids,
                   prior=priorfunction,
                   parameters=parameters,
                   resume=True,
                   verbose=True,
                   n_live_points=400,
                   outputfiles_basename=outputfiles_basename)

if os.environ.get('INTERACTIVE', '0') == '1':
    print('setting to best fit ...')
    bxa.set_best_fit(id,
                     otherids=otherids,
                     parameters=parameters,
                     outputfiles_basename=outputfiles_basename)
    no_exit = True
else:
    import pymultinest
    a = pymultinest.analyse.Analyzer(n_params=len(parameters),
                                     outputfiles_basename=outputfiles_basename)
コード例 #2
0
f = invgauss.get_invgauss_func(numpy.log10(props['nhgal']), 0.15)


def limited_19_24(x):
    v = f(x)
    if v <= 19:
        v = 19
    if v >= 24:
        v = 24
    return v


priors = []
parameters = [srclevel, src.PhoIndex, srcnh, galnh]

import bxa.sherpa as bxa
priors += [bxa.create_uniform_prior_for(srclevel)]
priors += [bxa.create_uniform_prior_for(src.PhoIndex)]
priors += [bxa.create_uniform_prior_for(srcnh)]
priors += [limited_19_24]  # galnh
priorfunction = bxa.create_prior_function(priors=priors)
print 'running BXA ...'
bxa.nested_run(id,
               prior=priorfunction,
               parameters=parameters,
               resume=True,
               verbose=True,
               outputfiles_basename='superfit_')

exit()
コード例 #3
0
ファイル: example_advanced_priors.py プロジェクト: neobar/BXA
mypow.PhoIndex.max = 3

# add ancillary parameter for NH, so we can work in nice logarithmic units
from sherpa.models.parameter import Parameter
lognH = Parameter(modelname='myabs', name='logNH', val=22, min=20, max=24)
myabs.nH = 10**(lognH - 22)

# define prior
parameters = [lognH, mypow.norm, mypow.PhoIndex]
priors = [
    # jeffreys prior for nH -- is uniform in lognH
    bxa.create_uniform_prior_for(lognH),
    # jeffreys prior for scale variable
    bxa.create_jeffreys_prior_for(mypow.norm),
    # custom gaussian prior function for photon index
    bxa.create_gaussian_prior_for(mypow.PhoIndex, 1.9, 0.15),
    # and possibly many more
]
prior = bxa.create_prior_function(priors=priors)

# send it off!
bxa.nested_run(
    prior=prior,
    parameters=parameters,
    outputfiles_basename=outputfiles_basename,
    verbose=True,  # show a bit of progress
    resume=True,  # MultiNest supports resuming a crashed/aborted run
)

exit()
コード例 #4
0
f = invgauss.get_invgauss_func(numpy.log10(props['nhgal']), 0.15)

def limited_19_24(x):
	v = f(x)
	if v <= 19:
		v = 19
	if v >= 24:
		v = 24
	return v

priors = []
parameters = [srclevel, src.PhoIndex, srcnh, galnh]

import bxa.sherpa as bxa
priors += [bxa.create_uniform_prior_for(srclevel)]
priors += [bxa.create_uniform_prior_for(src.PhoIndex)]
priors += [bxa.create_uniform_prior_for(srcnh)]
priors += [limited_19_24] # galnh
priorfunction = bxa.create_prior_function(priors = priors)
print('running BXA ...')
bxa.nested_run(id, prior=priorfunction, parameters = parameters, 
	resume = True, verbose=True, 
	outputfiles_basename = 'superfit_')

exit()





コード例 #5
0
ファイル: fit.py プロジェクト: JohannesBuchner/BXA
if id2:
	otherids = (id2,)
else:
	otherids = tuple()
if redshift_uncertain:
	priors.append(limited_0_10)
	parameters.append(redshift)
priorfunction = bxa.create_prior_function(priors = priors)
assert not numpy.isnan(calc_stat(id)), 'NaN on calc_stat, probably a bad RMF/ARF file for PC'
if id2:
	assert not numpy.isnan(calc_stat(id2)), 'NaN on calc_stat, probably a bad RMF/ARF file for WT'
print('running BXA ...')
outputfiles_basename = 'spherefit3_'
if not os.path.exists(outputfiles_basename + 'params.json'):
	bxa.nested_run(id, otherids=otherids, prior=priorfunction, parameters = parameters, 
		resume = True, verbose=True, n_live_points=400,
		outputfiles_basename = outputfiles_basename)

if os.environ.get('INTERACTIVE', '0') == '1':
	print('setting to best fit ...')
	bxa.set_best_fit(id, otherids=otherids, parameters = parameters, outputfiles_basename = outputfiles_basename)
	no_exit = True
else:
	import pymultinest
	a = pymultinest.analyse.Analyzer(n_params = len(parameters), outputfiles_basename = outputfiles_basename)
	if not os.path.exists('%sfit.json' % outputfiles_basename):
		print('collecting fit plot data')
		set_analysis(id, 'ener', 'counts')
		group_counts(id, 40)
		set_stat('chi2gehrels')
		pl = get_fit_plot(id)
コード例 #6
0
set_model(xspowerlaw.mypow)

# set model parameters ranges
mypow.norm.min = 1e-10
mypow.norm.max = 10
mypow.PhoIndex.min = 1
mypow.PhoIndex.max = 3

# define prior
parameters = [mypow.PhoIndex, mypow.norm]
priors = [
	# uniform prior for Photon Index (see other example for 
	# something more advanced)
	bxa.create_uniform_prior_for(mypow.PhoIndex),
	# jeffreys prior for scale variable
	bxa.create_jeffreys_prior_for(mypow.norm),
	# and possibly many more parameters here
]
prior = bxa.create_prior_function(priors=priors)

# send it off!
bxa.nested_run(prior = prior, parameters = parameters,
	outputfiles_basename = outputfiles_basename,
	verbose=True, # show a bit of progress
	resume=True, # MultiNest supports resuming a crashed/aborted run
	)

exit()

コード例 #7
0
ファイル: xz_auto_multiple.py プロジェクト: neobar/BXA
    p = bkg_model.pars[0]
    p.max = p.val + 2
    p.min = p.val - 2
    parameters.append(p)
    priors += [bxa.create_uniform_prior_for(p)]

#################
# BXA run
priorfunction = bxa.create_prior_function(priors=priors)
print('running BXA ...')

bxa.nested_run(id=ids[0],
               otherids=tuple(ids[1:]),
               prior=priorfunction,
               parameters=parameters,
               resume=True,
               verbose=True,
               outputfiles_basename=prefix,
               n_live_points=os.environ.get('NLIVEPOINTS', 400),
               importance_nested_sampling=False)

try:
    from mpi4py import MPI
    if MPI.COMM_WORLD.Get_rank() > 0:
        sys.exit(0)
except Exception as e:
    pass

outputfiles_basename = prefix
print('getting best-fit ...')
bxa.set_best_fit(parameters=parameters,
コード例 #8
0
	priors += [bxa.create_uniform_prior_for(srclevel)]
	priors += [bxa.create_gaussian_prior_for(src.PhoIndex, 1.95, 0.15)]
	priors += [bxa.create_uniform_prior_for(srcnh)]
	priors += [bxa.create_uniform_prior_for(src.redshift)] # galnh
	priors += [bxa.create_uniform_prior_for(bkg_model.pars[0])]
	otherids = ()

	if id2:
		parameters.append(bkg_model2.pars[0])
		priors += [bxa.create_uniform_prior_for(bkg_model2.pars[0])]
		otherids = (id2,)

	priorfunction = bxa.create_prior_function(priors = priors)
	print('running BXA ...')
	bxa.nested_run(id, otherids=otherids, prior=priorfunction, parameters = parameters, 
		resume = True, verbose=True, 
		outputfiles_basename = 'wabs_noz_',
		importance_nested_sampling = False)

	m = get_bkg_fit_plot(id)
	numpy.savetxt('test_bkg.txt', numpy.transpose([m.dataplot.x, m.dataplot.y, m.modelplot.x, m.modelplot.y]))

	m = get_fit_plot(id)
	numpy.savetxt('test_src.txt', numpy.transpose([m.dataplot.x, m.dataplot.y, m.modelplot.x, m.modelplot.y]))

	if id2:
		m = get_fit_plot(id2)
		numpy.savetxt('test_src2.txt', numpy.transpose([m.dataplot.x, m.dataplot.y, m.modelplot.x, m.modelplot.y]))

	exit()