Commit 6e687ffb authored by Matthew David Pitkin's avatar Matthew David Pitkin
Browse files

pulsarpputils.py: convert distance posterior samples to kpc

parent 745ba2cf
......@@ -469,6 +469,10 @@ class posteriors:
if hasattr(self._injection_parameters, 'DEC_RAD'):
setattr(self._injection_parameters, 'DEC', self._injection_parameters['DEC_RAD'])
# if DIST is set, then use the original value in KPC as the posterior samples will be in KPC
if hasattr(self._injection_parameters, 'DIST'):
setattr(self._injection_parameters, 'DIST', self._injection_parameters['DIST_ORIGINAL'])
if 'Joint' in self._ifos: # put 'Joint' at the end
j = self._ifos.pop(self._ifos.index('Joint'))
self._ifos.append(j)
......
......@@ -2481,15 +2481,18 @@ def pulsar_nest_to_posterior(postfile, nestedsamples=False, removeuntrig=True):
nsamps = len(pos[pnames[0]].samples)
permarr = np.arange(nsamps)
np.random.shuffle(permarr)
posdist = None
posfreqs = None
for pname in pnames:
# check if all samples are the same
if pos[pname].samples.tolist().count(pos[pname].samples[0]) == len(pos[pname].samples):
if pname == 'f0_fixed':
# try getting a fixed f0 value (for calculating h0 from Q22)
posfreqs = pos[pname].samples[0]
else:
# if distance is in the file then don't remove it (for calculating h0 from Q22 if required)
if pname != 'dist':
elif pname == 'dist':
# try getting a fixed distance value (for calculating h0 from Q22 if required)
posdist = pos[pname].samples[0]
pos.pop(pname)
else:
# shuffle
......@@ -2555,9 +2558,13 @@ def pulsar_nest_to_posterior(postfile, nestedsamples=False, removeuntrig=True):
if 'q22' in pos.names:
posQ22 = pos['q22'].samples
posdist = None
if 'dist' in pos.names:
posdist = pos['dist'].samples
posdist = pos['dist'].samples # distance in metre (for use in converting Q22 to h0)
# convert distance samples to kpc
pos.pop('dist')
distpos = bppu.PosteriorOneDPDF('dist', posdist/KPC)
pos.append(distpos)
if 'f0' in pos.names:
posfreqs = pos['f0'].samples
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment