Maintenance will be performed on git.ligo.org, chat.ligo.org, and docs.ligo.org, starting at approximately 10am CDT Tuesday 20 August 2019. The maintenance is expected to take around an hour and here will be two short periods of downtime, one at the beginning of the maintenance and another at the end.

Commit face6485 authored by Duncan Macleod's avatar Duncan Macleod Committed by James Clark

A few changes for python3

parent 425e2807
......@@ -17,6 +17,8 @@
# DAG Class definitions for bayeswave
from __future__ import print_function
import sys,os,subprocess
from glue import pipeline
......@@ -25,12 +27,18 @@ from glue.ligolw import utils as ligolw_utils
from glue.ligolw import lsctables
#import lalinspiral, lalburst
import ConfigParser
import itertools
import socket
import ast
import numpy as np
import random
try:
import configparser
except ImportError: # python < 3
import ConfigParser
else: # other python3 compatibility stuff
xrange = range
# XXX Hardcoded cvmfs frame root
CVMFS_FRAMES="/cvmfs/oasis.opensciencegrid.org/ligo/frames/"
......@@ -311,8 +319,7 @@ class eventTrigger:
try:
self.rho = event_info['extra_attributes']['MultiBurst']['snr']
except KeyError:
print >> sys.stderr, \
"graceDB UID %s has no MultiBurst snr attribute"%(graceid)
print("graceDB UID %s has no MultiBurst snr attribute"%(graceid), file=sys.stderr)
# Set time
self.trigger_time = event_info['gpstime']
......@@ -334,9 +341,8 @@ class eventTrigger:
self.flow = self.max_flow
except KeyError:
print >> sys.stderr, \
"graceDB UID %s has no MultiBurst central_freq attribute"%(graceid)
print >> sys.stderr, "...using default sample rate"
print("graceDB UID %s has no MultiBurst central_freq attribute"%(graceid), file=sys.stderr)
print("...using default sample rate", file=sys.stderr)
self.srate = self.default_srate
......@@ -390,7 +396,7 @@ class triggerList:
else:
# Fail
print >> sys.stdout, "don't know what to do."
print("don't know what to do.", file=sys.stdout)
sys.exit()
def parse_graceDB_triggers(self, cp, graceIDs):
......@@ -416,10 +422,10 @@ class triggerList:
try:
BW_chainLength=cp.getint('bayeswave_options','BW-chainLength')
except ConfigParser.NoOptionError:
except configparser.NoOptionError:
print >> sys.stdout, "Reading chainlength from files in %s"%(
cp.get('bayeswave_options','BW-path'))
print("Reading chainlength from files in %s"%(
cp.get('bayeswave_options','BW-path')), file=sys.stdout)
# O1 names:
if injtype=='glitch':
......@@ -470,12 +476,12 @@ class triggerList:
injection_times = sim_inspiral_table.get_column('geocent_end_time') + \
1e-9*sim_inspiral_table.get_column('geocent_end_time_ns')
print "..read %d injections"%len(injection_times)
print("..read %d injections"%len(injection_times))
triggers=[]
if followup_injections is None:
print 'downsampling to requested injections using events= in config'
print('downsampling to requested injections using events= in config')
# reduce to specified values
events=cp.get('injections', 'events')
......@@ -493,7 +499,7 @@ class triggerList:
# Parse the detected injections
print "downsampling to events listed in %s"%followup_injections
print("downsampling to events listed in %s"%followup_injections)
trigger_list_from_file = triggerList(cp,
trigger_file=followup_injections)
......@@ -534,19 +540,11 @@ class triggerList:
if 'V1' in ifo_list:
network+='V'
else:
print >> sys.stderr, \
"Error setting up timeslides from cWB trigger list. Please check IFO list"
# if 'H1' in ifo_list and 'L1' in ifo_list and 'V1' not in ifo_list:
# network='HL'
# elif 'H1' in ifo_list and 'L1' in ifo_list and 'V1' in ifo_list:
# network='HLV'
# else:
# print >> sys.stderr, \
# "Only HL and HLV networks currently supported for timeslides"
print >> sys.stdout, "Network: {}".format(network)
print >> sys.stdout, "Discarding rho<=%f"%rho_threshold
print("Error setting up timeslides from cWB trigger list. Please check IFO list.", file=sys.stderr)
print("Network: {}".format(network), file=sys.stdout)
print("Discarding rho<=%f"%rho_threshold, file=sys.stdout)
if network=='HL':
......@@ -694,8 +692,8 @@ class triggerList:
keepidx=random.sample(range(0,len(triggers)), nkeep)
triggers_out = [ triggers[i] for i in sorted(keepidx) ]
print >> sys.stdout, "Read %d triggers, following up %d"%(
nall, len(triggers_out))
print("Read %d triggers, following up %d"%(
nall, len(triggers_out)), file=sys.stdout)
return triggers_out
......@@ -734,16 +732,15 @@ class triggerList:
trigger_frequency=trigger_data[i,2]))
elif ncols==4:
print >> sys.stderr, \
"""WARNING: Looks like you're using an old style cwb trigger
list. Success is not guarenteed"""
print("""WARNING: Looks like you're using an old style cwb trigger
list. Success is not guarenteed""", file=sys.stderr)
# Trigger time, hl_lag, frequency, rho
try:
rho_threshold = cp.getfloat('input', 'rho-threshold')
except:
rho_threshold = rho_threshold
print >> sys.stdout, "Discarding rho<=%f"%rho_threshold
print("Discarding rho<=%f"%rho_threshold, file=sys.stdout)
for i in xrange(nrows):
# Apply rho threshold
......@@ -765,8 +762,8 @@ class triggerList:
keepidx=random.sample(range(0,len(triggers)), nkeep)
triggers_out = [ triggers[i] for i in sorted(keepidx) ]
print >> sys.stdout, "Read %d triggers, following up %d"%(
nrows, len(triggers_out))
print("Read %d triggers, following up %d"%(
nrows, len(triggers_out)), file=sys.stdout)
return triggers_out
......@@ -797,7 +794,7 @@ def condor_job_config(job_type,condor_job,config_parser):
try:
job_index = valid_job_types.index(job_type)
except ValueError:
print >> sys.stderr, "unrecognized job type"
print("unrecognized job type", file=sys.stderr)
# --- Set executable and choose singularity image
executable=config_parser.get('engine',job_type)
......@@ -815,14 +812,14 @@ def condor_job_config(job_type,condor_job,config_parser):
requires.append("(HAS_SINGULARITY=?=TRUE)")
print "Running with singularity(image={})".format(
config_parser.get('engine','singularity'))
print("Running with singularity(image={})".format(
config_parser.get('engine','singularity')))
try:
image = config_parser.get('engine','singularity').replace('"','')
except:
print """You requested a singularity run (--singularity) but did not
specify an image in the [engine] section of the config file"""
print("""You requested a singularity run (--singularity) but did not
specify an image in the [engine] section of the config file""")
sys.exit(-1)
pipeline.CondorDAGJob.__init__(condor_job,universe,executable)
......@@ -836,7 +833,7 @@ def condor_job_config(job_type,condor_job,config_parser):
condor_job.add_condor_cmd('+SingularityBindCVMFS', True)
# --- Perform file transfers
print >> sys.stdout, "Configuring file transfers (singularity requirement)"
print("Configuring file transfers (singularity requirement)", file=sys.stdout)
condor_job.add_condor_cmd('should_transfer_files', 'YES')
condor_job.add_condor_cmd('when_to_transfer_output', 'ON_EXIT_OR_EVICT')
......@@ -1465,7 +1462,7 @@ class megaskyNode(pipeline.CondorDAGNode, pipeline.AnalysisNode):
# Set eventnum if injection
def set_injevent(self, eventnum):
print 'eventnum:', eventnum
print('eventnum:', eventnum)
self.add_var_opt('eventnum', eventnum)
self.eventnum=eventnum
# Set work dir
......
......@@ -6,7 +6,7 @@ try:
import glue.ligolw.table
import glue.ligolw.lsctables
except:
print "WARNING: glue modules not found. Will not be able to read XML tables"
print("WARNING: glue modules not found. Will not be able to read XML tables")
filename = '/home/jkanner/baysewave/svn/trunk/burstinj/s6/BurstMDC-BRST_S6-Log.txt'
......@@ -30,7 +30,7 @@ class Mdc:
# -- Read a CBC XML table
if fileExtension == '.xml':
print "READING CBC XML TABLE"
print("READING CBC XML TABLE")
xmldoc = glue.ligolw.utils.load_filename(filename, verbose=False)
injs = glue.ligolw.table.get_table(xmldoc,glue.ligolw.lsctables.SimInspiralTable.tableName)
......@@ -69,7 +69,7 @@ class Mdc:
mdclog.close()
namelist = namestring.split()
print namelist
print(namelist)
data = np.recfromtxt(filename, names=namelist)
self.waveform = data['SimName']
self.hrss = data['SimHrss']
......@@ -81,9 +81,9 @@ class Mdc:
self.ecc = data['Internal_x']
def get_theta_phi(self, time):
print "Injection times:"
print self.gps
print "Trying to find this time: {0}".format(time)
print("Injection times:")
print(self.gps)
print("Trying to find this time: {0}".format(time))
n = np.where(np.abs(self.gps-time) < 0.1)
return (self.theta[n], self.phi[n])
......
......@@ -49,7 +49,7 @@ class BwbParams:
self.noise = float(spl[1])
self.noise_err = float(spl[2])
except:
print "WARNING: Could not find file evidence.dat"
print("WARNING: Could not find file evidence.dat")
# -- Read run file
......@@ -82,13 +82,13 @@ class BwbParams:
self.gps = float(cmdline[index+1])
# Determine if the job was glitchOnly, noiseOnly, or signalOnly
elif arg=='--glitchOnly':
print '\nThis run was executed with the --glitchOnly flag\n'
print('\nThis run was executed with the --glitchOnly flag\n')
self.restrictModel = 'glitch'
elif arg=='--noiseOnly':
print '\nThis run was executed with the --noiseOnly flag\n'
print('\nThis run was executed with the --noiseOnly flag\n')
self.restrictModel = 'noise'
elif arg=='--signalOnly':
print '\nThis run was executed with the --signalOnly flag\n'
print('\nThis run was executed with the --signalOnly flag\n')
self.restrictModel = 'signal'
elif arg=='--inj':
self.mdc = True
......
This diff is collapsed.
......@@ -30,9 +30,9 @@ import sys
import re
import traceback
print 'Path to megaplot: '
print sys.argv[0]
print '\n'
print('Path to megaplot: ')
print(sys.argv[0])
print('\n')
# Allow navigation into specified working directory
......@@ -173,17 +173,17 @@ def readbwb():
# Determine the job name
elif arg=='--runName':
jobName = cmdline[index+1]
print "The job name is: {0}".format(jobName)
print("The job name is: {0}".format(jobName))
jobName = jobName+'_'
# Determine if the job was glitchOnly, noiseOnly, or signalOnly
elif arg=='--glitchOnly':
print '\nThis run was executed with the --glitchOnly flag\n'
print('\nThis run was executed with the --glitchOnly flag\n')
restrictModel = 'glitch'
elif arg=='--noiseOnly':
print '\nThis run was executed with the --noiseOnly flag\n'
print('\nThis run was executed with the --noiseOnly flag\n')
restrictModel = 'noise'
elif arg=='--signalOnly':
print '\nThis run was executed with the --signalOnly flag\n'
print('\nThis run was executed with the --signalOnly flag\n')
restrictModel = 'signal'
elif arg=='--inj':
injFlag = True
......@@ -221,7 +221,7 @@ def readbwb():
info = info + 'Injected SNR in detector {0} = {1}\n'.format(ifoNames[int(ifo)],snrList[-1])
bayeswave.close()
# -- Report to user
print "{0}".format(info)
print("{0}".format(info))
return(jobName, restrictModel, mdc, injFlag, bayeswaverunfile, ifoList, ifoNames, gps, snrList, info)
# --------------------------------------------------
......@@ -444,9 +444,9 @@ def plot_evidence(jobName, plotsDir):
err_sig_gl += err_sig_si
err_sig_gl = math.sqrt(err_sig_gl)
# -- Report to the user
print
print ' log( E_signal / E_noise ) =', sig_noise
print ' log( E_signal / E_glitch ) =', sig_gl
print()
print(' log( E_signal / E_noise ) =', sig_noise)
print(' log( E_signal / E_glitch ) =', sig_gl)
# -- Plot the data point
plt.figure()
plt.errorbar(sig_gl, sig_noise, 2*err_sig_gl, 2*err_sig_noise, color='black')
......@@ -486,7 +486,7 @@ def plot_waveform(jobName, postDir, ifo, plotsDir, worc, mdc, model, axwinner, t
inj_median_waveform, inj_up_vec, inj_down_vec = get_waveform_bigfile(filename)
plt.plot(time, inj_median_waveform, color = '0.75', linewidth=2, alpha=0.25)
except:
print "I couldn't find the file {0}".format(filename)
print("I couldn't find the file {0}".format(filename))
if model == 'glitch':
colour = gcolor
......@@ -1114,7 +1114,7 @@ def plot_likelihood_1(modelList, plotsDir):
names = ['temp','likehood','error']
data = np.recfromtxt(str(jobName)+"{0}_evidence.dat".format(mod), names=names)
except:
print 'No noise evidence'
print('No noise evidence')
#error = np.zeros(likehood.shape)
plt.semilogx(data['temp'], data['likehood'], label=mod, linewidth=2, color=colour)
plt.errorbar(data['temp'], data['likehood'], 2*data['error'], color=colour)
......@@ -2113,9 +2113,9 @@ if not restrictModel == '':
else:
model = 'signal'
restrictModel = ('signal', 'glitch', 'noise')
print "The mdc status is: {0}\n".format(mdc)
print("The mdc status is: {0}\n".format(mdc))
if injFlag:
print "The injection was performed via an xml table\n"
print("The injection was performed via an xml table\n")
if len(restrictModel) == 1:
restrictModel = restrictModel[0]
......@@ -2134,7 +2134,7 @@ time = np.loadtxt(str(jobName)+postDir+'timesamp.dat')
freq = np.loadtxt(str(jobName)+postDir+'freqsamp.dat')
for mod in modelList:
print "Analyzing the {0} model\n".format(mod)
print("Analyzing the {0} model\n".format(mod))
# -- Loop over interferometers to create plots
for ifo in ifoList:
......@@ -2157,7 +2157,7 @@ for mod in modelList:
#median_waveform, up_vec, down_vec = get_waveform_bigfile(filename, ifo)
timesamp,median_waveform, high_50, low_50, high_90, low_90 = get_waveform(filename)
print 'ifo {0}'.format(ifoNames[int(ifo)])
print('ifo {0}'.format(ifoNames[int(ifo)]))
# -- Plot the median waveform and injected waveform (if present)
plot_waveform(jobName, postDir, ifo, plotsDir, worc, mdc, mod, axwinner, time, low_50, high_50, low_90, high_90, median_waveform)
......@@ -2327,7 +2327,7 @@ try:
plot_likelihood_1(modelList, plotsDir)
plot_likelihood_2(modelList, plotsDir)
except:
print "Failed to plot temp vs. likelihood. This may be due to a change in file format for files like signal_evidence.dat"
print("Failed to plot temp vs. likelihood. This may be due to a change in file format for files like signal_evidence.dat")
# -- Plot the evolution of the dimensions of each model; do it only if signal and/or glitch model are present
......@@ -2341,13 +2341,13 @@ for mod in modelList:
try:
whitened_residual_plots(mod,ifoList,ifoNames)
except Exception as e:
print "Error producing %s residual histograms"%mod
print traceback.format_exc()
print("Error producing %s residual histograms"%mod)
print(traceback.format_exc())
try:
whitened_residual_plots('noise',ifoList,ifoNames)
except Exception as e:
print "Error producing noise residual histograms"
print traceback.format_exc()
print("Error producing noise residual histograms")
print(traceback.format_exc())
# -- Create directory that will contain all webpage code
......@@ -2360,4 +2360,4 @@ make_webpage(htmlDir, model, mdc, gps, ifoList, ifoNames, modelList, snrList, si
# Move back to original dir
os.chdir(topdir)
print "\nWebpage script ran to completion with the above exceptions"
print("\nWebpage script ran to completion with the above exceptions")
#!/usr/bin/env python
from __future__ import print_function
import lal
import matplotlib
matplotlib.use('Agg')
......@@ -49,10 +52,10 @@ def parser():
(opts,args) = parser.parse_args()
if len(args)==0:
print >> sys.stderr, "ERROR: require BW directory"
print("ERROR: require BW directory", file=sys.stderr)
sys.exit()
if not os.path.isdir(args[0]):
print >> sys.stderr, "ERROR: BW dir %s does not exist"%args[0]
print("ERROR: BW dir %s does not exist"%args[0], file=sys.stderr)
sys.exit()
......@@ -148,14 +151,14 @@ def make_skyview(directory='.', mdc=None, NSIDE=128, inj=None, npost=5000):
# Read S6 MDC log file
# -----------------
if mdc is None:
print "No MDC log provided."
print("No MDC log provided.")
# -- Save PWD for future reference
topdir = os.getcwd()
# -- Enter requested directory
os.chdir(directory)
print "Entered", os.getcwd()
print("Entered", os.getcwd())
try:
jobname = 'bayeswave.run'
......@@ -197,18 +200,18 @@ def make_skyview(directory='.', mdc=None, NSIDE=128, inj=None, npost=5000):
# --------------------------------
# -- Input skymap data
print "Extracting RA/DEC samples"
print("Extracting RA/DEC samples")
filename = './chains/' + 'signal_params_h0.dat.0'
data = np.loadtxt(filename, unpack=True,usecols=(0,1,2))
ralist = data[1]
sin_dec = data[2]
print "Total samples are {0}".format(ralist.size)
print("Total samples are {0}".format(ralist.size))
# -- Remove burn in samples
burnin = ralist.size/4
ralist = ralist[burnin:]
sin_dec = sin_dec[burnin:]
print "After removing burn-in samples are {0}".format(ralist.size)
print("After removing burn-in samples are {0}".format(ralist.size))
declist = np.arcsin(sin_dec)
thetalist = np.pi/2.0 - declist
......@@ -221,16 +224,16 @@ def make_skyview(directory='.', mdc=None, NSIDE=128, inj=None, npost=5000):
kde = sky.ClusteredSkyKDEPosterior(radec)
# -- Get the sidereal time
print "Finding sidereal time"
print "Using GPS {0}".format(gps)
print("Finding sidereal time")
print("Using GPS {0}".format(gps))
trigtime = float(gps)
lalgps = lal.LIGOTimeGPS(trigtime)
sidtime = GreenwichSiderealTime(lalgps, 0)
sidtime = sidtime % (np.pi*2)
# -- Get the injection location
print "GOT MDC?"
print mdc
print("GOT MDC?")
print(mdc)
if mdc is None:
injtheta = 0
injphi = 0
......@@ -240,8 +243,8 @@ def make_skyview(directory='.', mdc=None, NSIDE=128, inj=None, npost=5000):
injtheta, injphi = mdc.get_theta_phi(trigtime)
injra = injphi + sidtime
injdec = np.pi/2 - injtheta
print "GOT INJECTION PARAMTERS"
print injtheta, injra
print("GOT INJECTION PARAMTERS")
print(injtheta, injra)
# -- Make plots directory, if needed
plotsDir = './plots'
......@@ -282,28 +285,28 @@ def make_skyview(directory='.', mdc=None, NSIDE=128, inj=None, npost=5000):
# -- Calculate the 50 and 90% credible intervals
sq_deg = (180.0/np.pi)**2
print "Calculating sky area ..."
print("Calculating sky area ...")
(area50, area90) = kde.sky_area( [0.5, 0.9] )*sq_deg
print "Got area50 of {0}".format(area50)
print("Got area50 of {0}".format(area50))
# -- Get the found contour and searched areas
if mdc is not None:
print "Calculating p value of injection"
print("Calculating p value of injection")
injcontour = kde.p_values( np.array([[injra, injdec]]) )[0]
print "Got contour of {0}".format(injcontour)
print("Got contour of {0}".format(injcontour))
print "Calculating searched area..."
print("Calculating searched area...")
searcharea = (kde.searched_area( np.array([[injra, injdec]]) )*sq_deg)[0]
print "Got searched area of {0}".format(searcharea)
print("Got searched area of {0}".format(searcharea))
elif (inj is not None):
print "Calculating p value of command line injection"
print("Calculating p value of command line injection")
injcontour = kde.p_values( np.array([inj['ra'], inj['dec']]) )[0]
print "Got contour of {0}".format(injcontour)
print("Got contour of {0}".format(injcontour))
print "Calculating searched area..."
print("Calculating searched area...")
searcharea = (kde.searched_area( np.array([inj['ra'], inj['dec']]) )*sq_deg)[0]
print "Got searched area of {0}".format(searcharea)
print("Got searched area of {0}".format(searcharea))
else:
injcontour = 0
......@@ -343,9 +346,9 @@ if __name__ == "__main__":
# If present, check if event id is provided
# If yes, proceed. If no, throw error message and exit
if(opts.eventnum is None):
print >> sys.stderr, "Provide event num if giving injfile"
print("Provide event num if giving injfile", file=sys.stderr)
sys.exit()
print "Loading xml"
print("Loading xml")
xmldoc = utils.load_filename(
opts.inj, contenthandler=LIGOLWContentHandler)
try:
......@@ -371,11 +374,11 @@ if __name__ == "__main__":
# If md log provided, use that. Currently,
# there is no scheme to assert exclusivity of injection and mdcs
if mdc is not None:
print 'Reading mdc log {0}'.format(mdc)
print('Reading mdc log {0}'.format(mdc))
try:
mdc = ft.Mdc(arg)
except:
print 'Warning! Failed to read mdc'
print('Warning! Failed to read mdc')
mdc = None
......
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