Maintenance will be performed on git.ligo.org, chat.ligo.org, containers.ligo.org, and docs.ligo.org on Tuesday 19th January 2021 starting at approximately 8am MST. It is expected to take around 15 minutes and there will be a short period of downtime towards the end of the maintenance window. Please direct and comments, questions, or concerns to computing-help@igwn.org.

Commit e6eb08ab authored by John Douglas Veitch's avatar John Douglas Veitch

Merge branch 'fix_python' into 'master'

Fix imports from old pylal functions that have moved

Closes #22

See merge request !79
parents 5da852ae b4cf4617
......@@ -31,7 +31,6 @@ import h5py
from lalinference import git_version
from lalinference import bayespputils as bppu
from lalinference.io import read_samples, write_samples
from cbcBayesPostProc import multipleFileCB
from lalinference import LALINFERENCE_PARAM_LINEAR as LINEAR
from lalinference import LALINFERENCE_PARAM_CIRCULAR as CIRCULAR
......@@ -42,6 +41,32 @@ __author__="Carl-Johan Haster <carl-johan.haster@ligo.org>>"
__version__= "git id %s"%git_version.id
__date__= git_version.date
def multipleFileCB(opt, opt_str, value, parser):
args=[]
def floatable(str):
try:
float(str)
return True
except ValueError:
return False
for arg in parser.rargs:
# stop on --foo like options
if arg[:2] == "--" and len(arg) > 2:
break
# stop on -a, but not on -3 or -3.0
if arg[:1] == "-" and len(arg) > 1 and not floatable(arg):
break
args.append(arg)
del parser.rargs[:len(args)]
#Append new files to list if some already specified
if getattr(parser.values, opt.dest):
oldargs = getattr(parser.values, opt.dest)
oldargs.extend(args)
args = oldargs
setattr(parser.values, opt.dest, args)
mcmc_group_id = '/lalinference/lalinference_mcmc'
......
......@@ -17,83 +17,7 @@ rc('xtick', labelsize=small)
rc('ytick', labelsize=small)
rc('text.latex', unicode=True)
def make_disk_plot(post,outpath=None):
try:
import corner
except ImportError:
print "cannot import corner. Won't plot spin disk"
return None
a1='a1'
tilt1='tilt_spin1'
a2='a2'
tilt2='tilt_spin2'
names=post.names
allin=1.0
for i in [a1,tilt1,a2,tilt2]:
if not i in names:
allin*=0.0
if allin==0.0:
print "Cannot plot spin disk plot. Not all required spin parameters exist in the posterior file. Skipping...\n"
return None
# Spin disk plot
fig, axs = plt.subplots(1, 2, sharey=True, figsize=(4, 4))
Na, Nt = 20, 30
xticks = [0., .25, .5, .75, 1.]
vmin, vmax = 0., 0.
for a, tilt in zip([a1, a2], [tilt1, tilt2]):
asamps=(post[a].samples).flatten()
tsamps=(post[tilt].samples).flatten()
H, _, _ = np.histogram2d(asamps, np.cos(tsamps), range=[[0, 1], [-1, 1]], bins=(Na, Nt), normed=False)
H /= len(asamps)
vmax = H.max() if H.max() > vmax else vmax
for ax, a, tilt, flip in zip(axs, [a1, a2], [tilt1, tilt2], [True, False]):
plt.sca(ax)
H, rs, costs = np.histogram2d(asamps, np.cos(tsamps), range=[[0, 1], [-1, 1]], bins=(Na, Nt), normed=False)
H /= len(asamps)
COSTS, RS = np.meshgrid(costs, rs)
X = RS * np.sin(np.arccos(COSTS))
Y = RS * COSTS
HS = np.column_stack((X.flatten(), Y.flatten()))
XS = np.reshape(HS[:,0], (Na+1,Nt+1))
YS = np.reshape(HS[:,1], (Na+1,Nt+1))
plt.pcolormesh(XS, YS, H, vmin=vmin, vmax=vmax, edgecolor='face', cmap='Greys')
ax.set_ylim((-1., 1.))
ax.set_xlim((0., 1.))
if flip:
ax.set_xticks(xticks[1:])
ax.invert_xaxis()
else:
ax.set_xticks(xticks)
ax.yaxis.tick_right()
ax.yaxis.set_label_position("right")
axs[0].set_xlabel(r'$|\mathbf{S_1} \times \mathbf{\hat{L}}|$')
axs[1].set_xlabel(r'$|\mathbf{S_2} \times \mathbf{\hat{L}}|$')
axs[0].set_ylabel('$\mathbf{S_1}\cdot\mathbf{\hat{L}}$')
axs[1].set_ylabel('$\mathbf{S_2}\cdot\mathbf{\hat{L}}$')
fig.subplots_adjust(wspace=0.04)
cax = fig.add_axes([0.06, -0.075, 0.9, 0.05])
cbar = plt.colorbar(orientation='horizontal', cax=cax)
cbar.formatter.set_powerlimits((-1, 1))
cbar.update_ticks()
cbar.set_label('posterior probability')
cbar.solids.set_edgecolor("face")
plt.savefig(os.path.join(outpath,"comp_spin_pos.png"), bbox_inches='tight')
plt.clf()
from lalinference.plot import make_disk_plot
USAGE='What this does is : '
......
......@@ -17,6 +17,7 @@ pymodule_PYTHON = \
marker.py \
poly.py \
pp.py \
spindisk.py \
$(END_OF_LIST)
dist_pymodule_DATA = \
......
......@@ -17,12 +17,13 @@
"""
Plotting classes and methods
"""
from . import allsky, angle, healpix, marker, poly, pp
from . import allsky, angle, healpix, marker, poly, pp, spindisk
from .allsky import *
from .angle import *
from .healpix import *
from .marker import *
from .poly import *
from .pp import *
from .spindisk import *
__all__ = (allsky.__all__ + angle.__all__ + healpix.__all__ + marker.__all__
+ poly.__all__ + pp.__all__)
+ poly.__all__ + pp.__all__ + spindisk.__all__)
# Ben Farr 2016
import numpy as np
import os
from matplotlib import pyplot as plt
from matplotlib.lines import Line2D
__all__=('make_disk_plot',)
def make_disk_plot(post,outpath=None):
from matplotlib import rc
rc('text', usetex=True)
rc('font', family='lmodern')
small, big = 10, 12
rc('axes', labelsize=big)
rc('text', fontsize=big)
rc('legend', fontsize=small)
rc('xtick', labelsize=small)
rc('ytick', labelsize=small)
rc('text.latex', unicode=True)
try:
import corner
except ImportError:
print "cannot import corner. Won't plot spin disk"
return None
a1='a1'
tilt1='tilt_spin1'
a2='a2'
tilt2='tilt_spin2'
names=post.names
allin=1.0
for i in [a1,tilt1,a2,tilt2]:
if not i in names:
allin*=0.0
if allin==0.0:
print "Cannot plot spin disk plot. Not all required spin parameters exist in the posterior file. Skipping...\n"
return None
# Spin disk plot
fig, axs = plt.subplots(1, 2, sharey=True, figsize=(4, 4))
Na, Nt = 20, 30
xticks = [0., .25, .5, .75, 1.]
vmin, vmax = 0., 0.
for a, tilt in zip([a1, a2], [tilt1, tilt2]):
asamps=(post[a].samples).flatten()
tsamps=(post[tilt].samples).flatten()
H, _, _ = np.histogram2d(asamps, np.cos(tsamps), range=[[0, 1], [-1, 1]], bins=(Na, Nt), normed=False)
H /= len(asamps)
vmax = H.max() if H.max() > vmax else vmax
for ax, a, tilt, flip in zip(axs, [a1, a2], [tilt1, tilt2], [True, False]):
plt.sca(ax)
H, rs, costs = np.histogram2d(asamps, np.cos(tsamps), range=[[0, 1], [-1, 1]], bins=(Na, Nt), normed=False)
H /= len(asamps)
COSTS, RS = np.meshgrid(costs, rs)
X = RS * np.sin(np.arccos(COSTS))
Y = RS * COSTS
HS = np.column_stack((X.flatten(), Y.flatten()))
XS = np.reshape(HS[:,0], (Na+1,Nt+1))
YS = np.reshape(HS[:,1], (Na+1,Nt+1))
plt.pcolormesh(XS, YS, H, vmin=vmin, vmax=vmax, edgecolor='face', cmap='Greys')
ax.set_ylim((-1., 1.))
ax.set_xlim((0., 1.))
if flip:
ax.set_xticks(xticks[1:])
ax.invert_xaxis()
else:
ax.set_xticks(xticks)
ax.yaxis.tick_right()
ax.yaxis.set_label_position("right")
axs[0].set_xlabel(r'$|\mathbf{S_1} \times \mathbf{\hat{L}}|$')
axs[1].set_xlabel(r'$|\mathbf{S_2} \times \mathbf{\hat{L}}|$')
axs[0].set_ylabel('$\mathbf{S_1}\cdot\mathbf{\hat{L}}$')
axs[1].set_ylabel('$\mathbf{S_2}\cdot\mathbf{\hat{L}}$')
fig.subplots_adjust(wspace=0.04)
cax = fig.add_axes([0.06, -0.075, 0.9, 0.05])
cbar = plt.colorbar(orientation='horizontal', cax=cax)
cbar.formatter.set_powerlimits((-1, 1))
cbar.update_ticks()
cbar.set_label('posterior probability')
cbar.solids.set_edgecolor("face")
plt.savefig(os.path.join(outpath,"comp_spin_pos.png"), bbox_inches='tight')
plt.clf()
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