2 A script to run lalpulsar_parameter_estimation_nested with increasing amplitude prior
3 ranges. Samples supposedly generated from the prior will be output and checked using a KS test
4 to see if they match the expected flat prior across the range.
10 import subprocess
as sp
11 import scipy.stats
as ss
14 if os.environ[
"LALINFERENCE_ENABLED"] ==
"false":
15 print(
"Skipping test: requires LALInference")
20 execu =
"./lalpulsar_parameter_estimation_nested"
23 os.environ[
"LAL_DEBUG_LEVEL"] = os.environ[
"LAL_DEBUG_LEVEL"].replace(
"memdbg",
"")
24 print(
"Modified LAL_DEBUG_LEVEL='%s'" % os.environ[
"LAL_DEBUG_LEVEL"])
42 datafile =
"data.txt.gz"
43 ds = np.zeros((1440, 3))
44 ds[:, 0] = np.linspace(900000000.0, 900000000.0 + 86400.0 - 60.0, 1440)
45 ds[:, -2:] = 1.0e-24 * np.random.randn(1440, 2)
48 np.savetxt(datafile, ds, fmt=
"%.12e")
51 h0uls = [1e-22, 1e-21, 1e-20, 1e-19, 1e-18, 1e-17]
58 outfile_SNR =
"test_SNR"
59 outfile_Znoise =
"test_Znoise"
62 for h, h0ul
in enumerate(h0uls):
63 print(
"--- h0=%i/%i ---" % (h + 1, len(h0uls)), flush=
True)
70 PSI uniform 0 %f""" % (
83 "%s --detectors %s --par-file %s --input-files %s --outfile %s --prior-file %s --Nlive %s --Nmcmcinitial %s --sampleprior %s"
97 sp.check_call(commandline, shell=
True)
100 f = h5py.File(outfile,
"r")
101 a = f[
"lalinference"]
102 h0samps = a[
"lalinference_nest"][
"nested_samples"][
"H0"][:]
105 [n, nedges] = np.histogram(h0samps, bins=20, range=(0.0, h0ul), density=
True)
106 nc = np.cumsum(n) * (nedges[1] - nedges[0])
108 stat, p = ss.kstest(nc,
"uniform")
110 print(
"K-S test p-value for upper range of %e = %f" % (h0ul, p))
113 print(
"There might be a problem for this prior distribution")
115 import matplotlib
as mpl
118 import matplotlib.pyplot
as pl
119 except ModuleNotFoundError:
120 print(
"matplotlib unavailable; skipping plot")
123 fig, ax = pl.subplots(1, 1)
129 histtype=
"stepfilled",
132 ax.plot([0.0, h0ul], [0.0, 1],
"k--")
133 ax.set_xlim((0.0, h0ul))
134 ax.set_ylim((0.0, 1.0))
136 ax.set_ylabel(
"Cumulative probability")
137 fig.savefig(
"h0samps.png")
138 print(
"Saved plot to 'h0samps.png'")
143 for fs
in (outfile, outfile_SNR, outfile_Znoise):
147 for fs
in (priorf, parf, datafile):