Commit 2def12be authored by Thomas Almeida's avatar Thomas Almeida
Browse files

Format python files with yapf (pep8)

parent e2b4d78a
......@@ -7,13 +7,13 @@ lo_filepath = sys.argv[1]
o_filepath = lo_filepath.replace(".lo", ".o")
try:
i = o_filepath.rindex("/")
lo_dir = o_filepath[0:i+1]
o_filename = o_filepath[i+1:]
i = o_filepath.rindex("/")
lo_dir = o_filepath[0:i + 1]
o_filename = o_filepath[i + 1:]
except ValueError:
lo_dir = ""
o_filename = o_filepath
lo_dir = ""
o_filename = o_filepath
local_pic_dir = ".libs/"
local_npic_dir = ""
......@@ -27,13 +27,13 @@ local_npic_filepath = local_npic_dir + o_filename
# Make lib dir
try:
os.mkdir(pic_dir)
os.mkdir(pic_dir)
except OSError:
pass
pass
# generate the command to compile the .cu for shared library
args = sys.argv[2:]
args.extend(["-Xcompiler","-fPIC"]) # position indep code
args.extend(["-Xcompiler", "-fPIC"]) # position indep code
args.append("-o")
args.append(pic_filepath)
command = " ".join(args)
......@@ -42,7 +42,7 @@ print command
# compile the .cu
rv = os.system(command)
if rv != 0:
sys.exit(1)
sys.exit(1)
# generate the command to compile the .cu for static library
args = sys.argv[2:]
......@@ -54,7 +54,7 @@ print command
# compile the .cu
rv = os.system(command)
if rv != 0:
sys.exit(1)
sys.exit(1)
# get libtool version
fd = os.popen("libtool --version")
......@@ -63,7 +63,7 @@ fd.close()
# generate the .lo file
f = open(lo_filepath, "w")
f.write("# " + lo_filepath + " - a libtool object file\n")
f.write("# " + lo_filepath + " - a libtool object file\n")
f.write("# Generated by " + libtool_version + "\n")
f.write("#\n")
f.write("# Please DO NOT delete this file!\n")
......
......@@ -10,8 +10,12 @@ import gst
# This is for parsing the ligolw file
from glue.ligolw import ligolw, lsctables, array, param, utils, types
class DefaultContentHandler(ligolw.LIGOLWContentHandler):
pass
pass
array.use_in(DefaultContentHandler)
param.use_in(DefaultContentHandler)
lsctables.use_in(DefaultContentHandler)
......@@ -23,42 +27,57 @@ from gstlal import pipeparts
import pdb
#pdb.set_trace()
def get_maxrate_from_xml(filename, contenthandler = DefaultContentHandler, verbose = False):
xmldoc = utils.load_filename(filename, contenthandler = contenthandler, verbose = verbose)
for root in (elem for elem in xmldoc.getElementsByTagName(ligolw.LIGO_LW.tagName) if elem.hasAttribute(u"Name") and elem.Name == "gstlal_iir_bank_Bank"):
def get_maxrate_from_xml(filename,
contenthandler=DefaultContentHandler,
verbose=False):
xmldoc = utils.load_filename(filename,
contenthandler=contenthandler,
verbose=verbose)
for root in (
elem
for elem in xmldoc.getElementsByTagName(ligolw.LIGO_LW.tagName)
if elem.hasAttribute(u"Name")
and elem.Name == "gstlal_iir_bank_Bank"):
sample_rates = [
int(r) for r in param.get_pyvalue(root, 'sample_rate').split(',')
]
return max(sample_rates)
sample_rates = [int(r) for r in param.get_pyvalue(root, 'sample_rate').split(',')]
return max(sample_rates)
pipeline = gst.Pipeline("test_multiratespiir")
mainloop = gobject.MainLoop()
# set the snr dump time range in GPS format
nxydump_segment = "0:1"
nxydump_segment, = segmentsUtils.from_range_strings([nxydump_segment], boundtype = LIGOTimeGPS)
nxydump_segment, = segmentsUtils.from_range_strings([nxydump_segment],
boundtype=LIGOTimeGPS)
# make the source
src = pipeparts.mkaudiotestsrc(pipeline, volume = 1, wave = "sine", freq = 10)
src = pipeparts.mkaudiotestsrc(pipeline, volume=1, wave="sine", freq=10)
# the flowing data rate is determined by the max rate of SPIIR bank
bank_fname = "H1bank.xml"
maxrate = get_maxrate_from_xml(bank_fname)
src = pipeparts.mkcapsfilter(pipeline, src, "audio/x-raw-float, width=32, channels=1, rate=%d" % maxrate)
src = pipeparts.mkcapsfilter(
pipeline, src,
"audio/x-raw-float, width=32, channels=1, rate=%d" % maxrate)
src = pipeparts.mkcudamultiratespiir(pipeline, src, bank_fname)
#sink = gst.element_factory_make("fakesink")
#pipeline.add(sink)
#src.link(sink)
pipeparts.mknxydumpsink(pipeline, src, "snr_gpu_%d_%s.dump" % (nxydump_segment[0], bank_fname[1:5]), segment = nxydump_segment)
pipeparts.mknxydumpsink(pipeline,
src,
"snr_gpu_%d_%s.dump" %
(nxydump_segment[0], bank_fname[1:5]),
segment=nxydump_segment)
if pipeline.set_state(gst.STATE_PLAYING) != gst.STATE_CHANGE_SUCCESS:
raise RuntimeError, "pipeline did not enter playing state"
raise RuntimeError, "pipeline did not enter playing state"
mainloop.run()
......@@ -8,23 +8,25 @@ import pygst
pygst.require("0.10")
import gst
from gstlal import pipeparts
pipeline = gst.Pipeline("test_postcoh")
mainloop = gobject.MainLoop()
src1 = pipeparts.mkaudiotestsrc(pipeline, wave = 9)
src1 = pipeparts.mkcapsfilter(pipeline, src1, "audio/x-raw-float, width=32, channels=2, rate=4096")
src2 = pipeparts.mkaudiotestsrc(pipeline, wave = 9)
src2 = pipeparts.mkcapsfilter(pipeline, src2, "audio/x-raw-float, width=32, channels=2, rate=4096")
src3 = pipeparts.mkaudiotestsrc(pipeline, wave = 9)
src3 = pipeparts.mkcapsfilter(pipeline, src3, "audio/x-raw-float, width=32, channels=2, rate=4096")
src1 = pipeparts.mkaudiotestsrc(pipeline, wave=9)
src1 = pipeparts.mkcapsfilter(
pipeline, src1, "audio/x-raw-float, width=32, channels=2, rate=4096")
src2 = pipeparts.mkaudiotestsrc(pipeline, wave=9)
src2 = pipeparts.mkcapsfilter(
pipeline, src2, "audio/x-raw-float, width=32, channels=2, rate=4096")
src3 = pipeparts.mkaudiotestsrc(pipeline, wave=9)
src3 = pipeparts.mkcapsfilter(
pipeline, src3, "audio/x-raw-float, width=32, channels=2, rate=4096")
postcoh = gst.element_factory_make("cuda_postcoh")
postcoh.set_property("detrsp-fname", "L1H1V1_skymap.xml")
postcoh.set_property("autocorrelation-fname", "L1:H1bank.xml.gz,H1:H1bank.xml.gz,V1:H1bank.xml.gz")
postcoh.set_property("autocorrelation-fname",
"L1:H1bank.xml.gz,H1:H1bank.xml.gz,V1:H1bank.xml.gz")
postcoh.set_property("hist-trials", 1)
postcoh.set_property("snglsnr-thresh", 1.0)
pipeline.add(postcoh)
......@@ -32,7 +34,8 @@ src1.link_pads(None, postcoh, "H1")
src2.link_pads(None, postcoh, "L1")
src3.link_pads(None, postcoh, "V1")
postcoh = pipeparts.mkcapsfilter(pipeline, postcoh, "audio/x-raw-float, width=32, channels=2, rate=4096")
postcoh = pipeparts.mkcapsfilter(
pipeline, postcoh, "audio/x-raw-float, width=32, channels=2, rate=4096")
sink = gst.element_factory_make("fakesink")
pipeline.add(sink)
postcoh.link(sink)
......@@ -40,4 +43,3 @@ postcoh.link(sink)
pipeline.set_state(gst.STATE_PLAYING)
mainloop.run()
......@@ -8,26 +8,41 @@ import pygst
pygst.require("0.10")
import gst
from gstlal import pipeparts
pipeline = gst.Pipeline("test_postcoh")
mainloop = gobject.MainLoop()
src1 = pipeparts.mkaudiotestsrc(pipeline, wave = 9)
src1 = pipeparts.mkcapsfilter(pipeline, src1, "audio/x-raw-float, width=32, channels=1, rate=4096")
src2 = pipeparts.mkaudiotestsrc(pipeline, wave = 9)
src2 = pipeparts.mkcapsfilter(pipeline, src2, "audio/x-raw-float, width=32, channels=1, rate=4096")
src3 = pipeparts.mkaudiotestsrc(pipeline, wave = 9)
src3 = pipeparts.mkcapsfilter(pipeline, src3, "audio/x-raw-float, width=32, channels=1, rate=4096")
src1 = pipeparts.mkcudamultiratespiir(pipeline, src1, "H1bank.xml.gz", gap_handle = 0, stream_id = 0)
src2 = pipeparts.mkcudamultiratespiir(pipeline, src2, "H1bank.xml.gz", gap_handle = 0, stream_id = 1)
src3 = pipeparts.mkcudamultiratespiir(pipeline, src3, "H1bank.xml.gz", gap_handle = 0, stream_id = 2)
src1 = pipeparts.mkaudiotestsrc(pipeline, wave=9)
src1 = pipeparts.mkcapsfilter(
pipeline, src1, "audio/x-raw-float, width=32, channels=1, rate=4096")
src2 = pipeparts.mkaudiotestsrc(pipeline, wave=9)
src2 = pipeparts.mkcapsfilter(
pipeline, src2, "audio/x-raw-float, width=32, channels=1, rate=4096")
src3 = pipeparts.mkaudiotestsrc(pipeline, wave=9)
src3 = pipeparts.mkcapsfilter(
pipeline, src3, "audio/x-raw-float, width=32, channels=1, rate=4096")
src1 = pipeparts.mkcudamultiratespiir(pipeline,
src1,
"H1bank.xml.gz",
gap_handle=0,
stream_id=0)
src2 = pipeparts.mkcudamultiratespiir(pipeline,
src2,
"H1bank.xml.gz",
gap_handle=0,
stream_id=1)
src3 = pipeparts.mkcudamultiratespiir(pipeline,
src3,
"H1bank.xml.gz",
gap_handle=0,
stream_id=2)
postcoh = gst.element_factory_make("cuda_postcoh")
postcoh.set_property("detrsp-fname", "L1H1V1_skymap.xml")
postcoh.set_property("autocorrelation-fname", "L1:H1bank.xml.gz,H1:H1bank.xml.gz,V1:H1bank.xml.gz")
postcoh.set_property("autocorrelation-fname",
"L1:H1bank.xml.gz,H1:H1bank.xml.gz,V1:H1bank.xml.gz")
postcoh.set_property("hist-trials", 1)
postcoh.set_property("snglsnr-thresh", 1.0)
pipeline.add(postcoh)
......@@ -44,4 +59,3 @@ postcoh.link(sink)
pipeline.set_state(gst.STATE_PLAYING)
mainloop.run()
......@@ -4,7 +4,7 @@
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
......@@ -12,9 +12,10 @@ __author__ = 'Qi Chu <qi.chu@ligo.org>'
__date__ = '$Date$'
__cvs_tag__ = '$Name$'
try:
__version__ = __cvs_tag__.split('-')[1] + '.' + __cvs_tag__.split('-')[2][0:-2]
__version__ = __cvs_tag__.split('-')[1] + '.' + __cvs_tag__.split(
'-')[2][0:-2]
except IndexError:
__version__ = ''
__version__ = ''
# The following snippet is taken from http://gstreamer.freedesktop.org/wiki/FAQ#Mypygstprogramismysteriouslycoredumping.2Chowtofixthis.3F
import pygtk
......@@ -32,136 +33,202 @@ from gstlal.pipemodules import pipe_macro
# SPIIR many instruments, many template banks
#
def mktimeshift(pipeline, src, shift):
properties = {
"shift": shift
}
return pipeparts.mkgeneric(pipeline, src, "control_timeshift", **properties)
def mkitac_spearman(pipeline, src, n, bank, autocorrelation_matrix = None, mask_matrix = None, snr_thresh = 0, sigmasq = None):
properties = {
"n": n,
"bank_filename": bank,
"snr_thresh": snr_thresh
}
if autocorrelation_matrix is not None:
properties["autocorrelation_matrix"] = pipeio.repack_complex_array_to_real(autocorrelation_matrix)
if mask_matrix is not None:
properties["autocorrelation_mask"] = mask_matrix
if sigmasq is not None:
properties["sigmasq"] = sigmasq
return pipeparts.mkgeneric(pipeline, src, "lal_itac_spearman", **properties)
def mkcudaiirbank(pipeline, src, a1, b0, delay, name = None):
properties = dict((name, value) for name, value in (("name", name), ("delay_matrix", delay)) if value is not None)
if a1 is not None:
properties["a1_matrix"] = pipeio.repack_complex_array_to_real(a1)
if b0 is not None:
properties["b0_matrix"] = pipeio.repack_complex_array_to_real(b0)
elem = pipeparts.mkgeneric(pipeline, src, "cuda_iirbank", **properties)
elem = pipeparts.mknofakedisconts(pipeline, elem) # FIXME: remove after basetransform behaviour fixed
return elem
def mkcudamultiratespiir(pipeline, src, bank_fname, gap_handle = 0, stream_id = 0, name = None):
properties = dict((name, value) for name, value in (("name", name), ("bank_fname", bank_fname), ("gap_handle", gap_handle), ("stream_id", stream_id)) if value is not None)
elem = pipeparts.mkgeneric(pipeline, src, "cuda_multiratespiir", **properties)
return elem
def mkcudapostcoh(pipeline, snr, instrument, detrsp_fname, autocorrelation_fname, sngl_tmplt_fname, hist_trials = 1, snglsnr_thresh = 4.0, cohsnr_thresh = 5.0, output_skymap = 0, detrsp_refresh_interval = 0, trial_interval = 0.1, stream_id = 0):
properties = dict((name, value) for name, value in zip(("detrsp-fname", "autocorrelation-fname", "sngl-tmplt-fname", "hist-trials", "snglsnr-thresh", "cohsnr_thresh", "output-skymap", "detrsp-refresh-interval", "trial-interval", "stream-id"), (detrsp_fname, autocorrelation_fname, sngl_tmplt_fname, hist_trials, snglsnr_thresh, cohsnr_thresh, output_skymap, detrsp_refresh_interval, trial_interval, stream_id)))
if "name" in properties:
elem = gst.element_factory_make("cuda_postcoh", properties.pop("name"))
else:
elem = gst.element_factory_make("cuda_postcoh")
# make sure stream_id go first
for name, value in properties.items():
if name == "stream-id":
elem.set_property(name.replace("_", "-"), value)
for name, value in properties.items():
if name != "stream-id":
elem.set_property(name.replace("_", "-"), value)
pipeline.add(elem)
snr.link_pads(None, elem, instrument)
return elem
def mkcohfar_accumbackground(pipeline, src, ifos= "H1L1", hist_trials = 1, snapshot_interval = 0, history_fname = None, output_prefix = None, output_name = None, source_type = pipe_macro.SOURCE_TYPE_BNS):
properties = {
"ifos": ifos,
"snapshot_interval": snapshot_interval,
"hist_trials": hist_trials,
"source_type": source_type
}
if history_fname is not None:
properties["history_fname"] = history_fname
if output_prefix is not None:
properties["output_prefix"] = output_prefix
if output_name is not None:
properties["output_name"] = output_name
print "source type %d" % source_type
if "name" in properties:
elem = gst.element_factory_make("cohfar_accumbackground", properties.pop("name"))
else:
elem = gst.element_factory_make("cohfar_accumbackground")
# make sure ifos go first
for name, value in properties.items():
if name == "ifos":
elem.set_property(name.replace("_", "-"), value)
for name, value in properties.items():
if name is not "ifos":
elem.set_property(name.replace("_", "-"), value)
pipeline.add(elem)
if isinstance(src, gst.Pad):
src.get_parent_element().link_pads(src, elem, None)
elif src is not None:
src.link(elem)
return elem
def mkcohfar_assignfar(pipeline, src, ifos= "H1L1", assignfar_refresh_interval = 14400, silent_time = 2147483647, input_fname = None):
properties = {
"ifos": ifos,
"refresh_interval": assignfar_refresh_interval,
"silent_time": silent_time,
}
if input_fname is not None:
properties["input_fname"] = input_fname
if "name" in properties:
elem = gst.element_factory_make("cohfar_assignfar", properties.pop("name"))
else:
elem = gst.element_factory_make("cohfar_assignfar")
# make sure ifos go first
for name, value in properties.items():
if name == "ifos":
elem.set_property(name.replace("_", "-"), value)
for name, value in properties.items():
if name != "ifos":
elem.set_property(name.replace("_", "-"), value)
pipeline.add(elem)
if isinstance(src, gst.Pad):
src.get_parent_element().link_pads(src, elem, None)
elif src is not None:
src.link(elem)
return elem
def mkpostcohfilesink(pipeline, postcoh, location = ".", compression = 1, snapshot_interval = 0):
properties = dict((name, value) for name, value in zip(("location", "compression", "snapshot-interval", "sync", "async"), (location, compression, snapshot_interval, False, False)))
if "name" in properties:
elem = gst.element_factory_make("postcoh_filesink", properties.pop("name"))
else:
elem = gst.element_factory_make("postcoh_filesink")
for name, value in properties.items():
elem.set_property(name.replace("_", "-"), value)
pipeline.add(elem)
postcoh.link(elem)
return elem
def mktimeshift(pipeline, src, shift):
properties = {"shift": shift}
return pipeparts.mkgeneric(pipeline, src, "control_timeshift",
**properties)
def mkitac_spearman(pipeline,
src,
n,
bank,
autocorrelation_matrix=None,
mask_matrix=None,
snr_thresh=0,
sigmasq=None):
properties = {"n": n, "bank_filename": bank, "snr_thresh": snr_thresh}
if autocorrelation_matrix is not None:
properties[
"autocorrelation_matrix"] = pipeio.repack_complex_array_to_real(
autocorrelation_matrix)
if mask_matrix is not None:
properties["autocorrelation_mask"] = mask_matrix
if sigmasq is not None:
properties["sigmasq"] = sigmasq
return pipeparts.mkgeneric(pipeline, src, "lal_itac_spearman",
**properties)
def mkcudaiirbank(pipeline, src, a1, b0, delay, name=None):
properties = dict(
(name, value)
for name, value in (("name", name), ("delay_matrix", delay))
if value is not None)
if a1 is not None:
properties["a1_matrix"] = pipeio.repack_complex_array_to_real(a1)
if b0 is not None:
properties["b0_matrix"] = pipeio.repack_complex_array_to_real(b0)
elem = pipeparts.mkgeneric(pipeline, src, "cuda_iirbank", **properties)
elem = pipeparts.mknofakedisconts(
pipeline, elem) # FIXME: remove after basetransform behaviour fixed
return elem
def mkcudamultiratespiir(pipeline,
src,
bank_fname,
gap_handle=0,
stream_id=0,
name=None):
properties = dict(
(name, value)
for name, value in (("name", name), ("bank_fname", bank_fname),
("gap_handle", gap_handle), ("stream_id",
stream_id))
if value is not None)
elem = pipeparts.mkgeneric(pipeline, src, "cuda_multiratespiir",
**properties)
return elem
def mkcudapostcoh(pipeline,
snr,
instrument,
detrsp_fname,
autocorrelation_fname,
sngl_tmplt_fname,
hist_trials=1,
snglsnr_thresh=4.0,
cohsnr_thresh=5.0,
output_skymap=0,
detrsp_refresh_interval=0,
trial_interval=0.1,
stream_id=0):
properties = dict((name, value) for name, value in zip((
"detrsp-fname", "autocorrelation-fname", "sngl-tmplt-fname",
"hist-trials", "snglsnr-thresh", "cohsnr_thresh", "output-skymap",
"detrsp-refresh-interval", "trial-interval",
"stream-id"), (detrsp_fname, autocorrelation_fname, sngl_tmplt_fname,
hist_trials, snglsnr_thresh, cohsnr_thresh,
output_skymap, detrsp_refresh_interval, trial_interval,
stream_id)))
if "name" in properties:
elem = gst.element_factory_make("cuda_postcoh", properties.pop("name"))
else:
elem = gst.element_factory_make("cuda_postcoh")
# make sure stream_id go first
for name, value in properties.items():
if name == "stream-id":
elem.set_property(name.replace("_", "-"), value)
for name, value in properties.items():
if name != "stream-id":
elem.set_property(name.replace("_", "-"), value)
pipeline.add(elem)
snr.link_pads(None, elem, instrument)
return elem
def mkcohfar_accumbackground(pipeline,
src,
ifos="H1L1",
hist_trials=1,
snapshot_interval=0,
history_fname=None,
output_prefix=None,
output_name=None,
source_type=pipe_macro.SOURCE_TYPE_BNS):
properties = {
"ifos": ifos,
"snapshot_interval": snapshot_interval,
"hist_trials": hist_trials,
"source_type": source_type
}
if history_fname is not None:
properties["history_fname"] = history_fname
if output_prefix is not None:
properties["output_prefix"] = output_prefix
if output_name is not None:
properties["output_name"] = output_name
print "source type %d" % source_type
if "name" in properties:
elem = gst.element_factory_make("cohfar_accumbackground",
properties.pop("name"))
else:
elem = gst.element_factory_make("cohfar_accumbackground")
# make sure ifos go first
for name, value in properties.items():
if name == "ifos":
elem.set_property(name.replace("_", "-"), value)
for name, value in properties.items():
if name is not "ifos":
elem.set_property(name.replace("_", "-"), value)
pipeline.add(elem)
if isinstance(src, gst.Pad):
src.get_parent_element().link_pads(src, elem, None)
elif src is not None:
src.link(elem)
return elem
def mkcohfar_assignfar(pipeline,
src,
ifos="H1L1",
assignfar_refresh_interval=14400,
silent_time=2147483647,
input_fname=None):
properties = {
"ifos": ifos,
"refresh_interval": assignfar_refresh_interval,
"silent_time": silent_time,
}
if input_fname is not None:
properties["input_fname"] = input_fname
if "name" in properties:
elem = gst.element_factory_make("cohfar_assignfar",
properties.pop("name"))
else:
elem = gst.element_factory_make("cohfar_assignfar")
# make sure ifos go first
for name, value in properties.items():
if name == "ifos":
elem.set_property(name.replace("_", "-"), value)