From 382d2003cf1c556abc29a8dfedc4c686cf997f64 Mon Sep 17 00:00:00 2001 From: Veronica Villa Date: Mon, 23 Sep 2019 09:56:19 -0700 Subject: [PATCH 01/31] Add mchirp_area codes --- bin/plotting/mass_area_plot.py | 121 ++++++++++++++++ bin/plotting/mchirp_plots.py | 92 ++++++++++++ pycbc/mchirp_area.py | 254 +++++++++++++++++++++++++++++++++ 3 files changed, 467 insertions(+) create mode 100644 bin/plotting/mass_area_plot.py create mode 100644 bin/plotting/mchirp_plots.py create mode 100644 pycbc/mchirp_area.py diff --git a/bin/plotting/mass_area_plot.py b/bin/plotting/mass_area_plot.py new file mode 100644 index 00000000000..06a6a7d84b0 --- /dev/null +++ b/bin/plotting/mass_area_plot.py @@ -0,0 +1,121 @@ +#!/usr/bin/env python + +#mass_area_plot.py +# +#Integration of the area laying in the different cbc regions +#By A. Curiel Barroso +#August 2019 +# +#-------------------------------------------- +#This script computes the area corresponding +#to different CBC on the m1 & m2 plane when +#given a central mchirp value and uncertainty +#-------------------------------------------- + +from pycbc import conversions +import numpy +from matplotlib import use +use("agg") +from matplotlib import pyplot +from scipy.integrate import quad +from mchirp_area import calc_areas +from mchirp_area import src_mass_from_z_det_mass +import argparse + +#ARGUMENT PARSER +parser = argparse.ArgumentParser() +parser.add_argument("--central-mc", type=float, help="Central value of mchirp") +parser.add_argument("--delta-mc", type=float, help="Uncertainty for mchirp") +parser.add_argument("--min-m2", type=float, help="Minimum value for m2") +parser.add_argument("--max-m1", type=float, help="Maximum value for m1") +parser.add_argument("--central-z", type=float, help="Central redshift value") +parser.add_argument("--delta-z", type=float, help="Redshift uncertainty") +parser.add_argument("--ns-max", type=float, help="Maximum neutron star mass") +parser.add_argument("--gap-max", type=float, help="Minimum black hole mass") + +args = parser.parse_args() + +if args.central_mc and args.delta_mc: + central_mc = float(args.central_mc) + delta_mc = float(args.delta_mc) + +if args.min_m2 and args.max_m1: + m2_min = float(args.min_m2) + m1_max = float(args.max_m1) + +if args.min_m2 and args.max_m1: + ns_max = float(args.ns_max) + gap_max = float(args.gap_max) + +if args.central_z and args.delta_z: + central_z = float(args.central_z) + delta_z = float(args.delta_z) +else: + central_z = 0.0 + delta_z = 0.0 + +mass_limits = {"max_m1": m1_max, "min_m2": m2_min} +mass_bdary = {"ns_max": ns_max, "gap_max": gap_max} +z = {"central": central_z, "delta": delta_z} +trig_mc = {"central": central_mc, "delta": delta_mc} + +areas = calc_areas(trig_mc, mass_limits, mass_bdary, z) + +print "abbh = "+str(areas["bbh"]) +print "abhg = "+str(areas["bhg"]) +print "agg = "+str(areas["gg"]) +print "ansbh = "+str(areas["nsbh"]) +print "agns = "+str(areas["gns"]) +print "abns = "+str(areas["bns"]) + +#PLOT GENERATION +src_mchirp = src_mass_from_z_det_mass(central_z, delta_z, + central_mc, delta_mc) + +mcb = src_mchirp[0] + src_mchirp[1] +mcs = src_mchirp[0] - src_mchirp[1] + +#The points where the equal mass line and a chirp mass +#curve intersect is m1 = m2 = (2**0.2)*mchirp + +mib = (2**0.2)*mcb +mis = (2**0.2)*mcs + +lim_m1b = min(m1_max, conversions.mass2_from_mchirp_mass1(mcb, m2_min)) +m1b = numpy.linspace(mib, lim_m1b, num=100) +m2b = conversions.mass2_from_mchirp_mass1(mcb, m1b) + +lim_m1s = min(m1_max, conversions.mass2_from_mchirp_mass1(mcs, m2_min)) +m1s = numpy.linspace(mis, lim_m1s, num=100) +m2s = conversions.mass2_from_mchirp_mass1(mcs, m1s) + +if mib > m1_max: + pyplot.plot( + (m1_max, m1_max), + (conversions.mass2_from_mchirp_mass1(mcs, lim_m1s), m1_max), + "b") +else: + pyplot.plot(m1b, m2b, "b") + pyplot.plot( + (m1_max, m1_max), + (conversions.mass2_from_mchirp_mass1(mcs, lim_m1s), + conversions.mass2_from_mchirp_mass1(mcb, lim_m1b)), "b") + +if mis >= m2_min: + pyplot.plot(m1s, m2s, "b") + pyplot.plot((lim_m1s, lim_m1b), (m2_min, m2_min), "b") +else: + pyplot.plot((m2_min, lim_m1b), (m2_min, m2_min), "b") + +pyplot.plot((m2_min, m1_max), (m2_min, m1_max), "k--") +pyplot.plot((ns_max, ns_max), (m2_min, ns_max), "k:") +pyplot.plot((gap_max, gap_max), (m2_min, gap_max), "k:") +pyplot.plot((ns_max, m1_max), (ns_max, ns_max), "k:") +pyplot.plot((gap_max, m1_max), (gap_max, gap_max), "k:") + +pyplot.xlabel("M1") +pyplot.ylabel("M2") +pyplot.title("MChirp = "+str((0.5) * (mcb+mcs)) + " +/- "+str((mcb-mcs) * (0.5))) +pyplot.savefig("mass_plot.png") + + diff --git a/bin/plotting/mchirp_plots.py b/bin/plotting/mchirp_plots.py new file mode 100644 index 00000000000..ee3d890f6f9 --- /dev/null +++ b/bin/plotting/mchirp_plots.py @@ -0,0 +1,92 @@ +#!/usr/bin/env python + +#mchirp_plots.py +# +#Integration of the area laying in the different cbc regions +#By A. Curiel Barroso +#August 2019 +# +#-------------------------------------------- +#This script computes the area corresponding +#to different CBC on the m1 & m2 plane as a +#function of central mchirp value +#-------------------------------------------- + +import numpy +import argparse +from matplotlib import use; use("agg") +from matplotlib import pyplot +from mchirp_area import calc_areas + +#ARGUMENT PARSER +parser = argparse.ArgumentParser() +parser.add_argument("--min-m2","--min-m2",type=float, + help="Minimum value for m2") +parser.add_argument("--max-m1","--max-m1",type=float, + help="Maximum value for m1") +parser.add_argument("--ns-max","--ns-max",type=float, + help="Maximum neutron star mass") +parser.add_argument("--gap-max","--gap-max",type=float, + help="Minimum black hole mass") +parser.add_argument("--central-z","--central-z",type=float, + help="Central redshift value") +parser.add_argument("--delta-z","--delta-z",type=float, + help="Redshift uncertainty") +args = parser.parse_args() + +if args.min_m2 and args.max_m1: + m1_max = float(args.max_m1) + m2_min = float(args.min_m2) + +if args.min_m2 and args.max_m1: + ns_max = float(args.ns_max) + gap_max = float(args.gap_max) + +if args.central_z and args.delta_z: + central_z = float(args.central_z) + delta_z = float(args.delta_z) +else: + central_z = 0.0 + delta_z = 0.0 + +mass_limits = {"max_m1": m1_max, "min_m2": m2_min} +mass_bdary = {"ns_max": ns_max, "gap_max": gap_max} +z = {"central": central_z, "delta": delta_z} +n = 1000 + +x_mc = numpy.zeros(n, float) +y_abbh = numpy.zeros(n, float) +y_abhg = numpy.zeros(n, float) +y_agg = numpy.zeros(n, float) +y_ansbh = numpy.zeros(n, float) +y_agns = numpy.zeros(n, float) +y_abns = numpy.zeros(n, float) + + +for i in range(0, n): + central_mc = 0.8 + i*(10.0 - 0.8)/(n - 1) + delta_mc = central_mc * 0.01 + trig_mc = {"central": central_mc, "delta": delta_mc} + x_mc[i] = central_mc + areas = calc_areas(trig_mc, mass_limits, mass_bdary, z) + y_abbh[i] = areas["bbh"] + y_abhg[i] = areas["bhg"] + y_agg[i] = areas["gg"] + y_ansbh[i] = areas["nsbh"] + y_agns[i] = areas["gns"] + y_abns[i] = areas["bns"] + +pyplot.plot(x_mc, y_abbh, label="Binary Black Hole") +pyplot.plot(x_mc, y_abhg, label="Black Hole + Mass Gap Object") +pyplot.plot(x_mc, y_agg, label="Binary Mass Gap Object") +pyplot.plot(x_mc, y_ansbh, label="Neutron Star + Black Hole") +pyplot.plot(x_mc, y_agns, label="Neutron Star + Mass Gap Object") +pyplot.plot(x_mc, y_abns, label="Binary Neutron Star") + +pyplot.legend() +pyplot.xlabel("Central MChirp (Solar Masses)") +pyplot.ylabel("Area (Solar Masses Squared)") +pyplot.yscale("log") +pyplot.title("Area vs MChirp (1% uncertainty)") + +pyplot.savefig("mchirp_plot.png") diff --git a/pycbc/mchirp_area.py b/pycbc/mchirp_area.py new file mode 100644 index 00000000000..93151b71b49 --- /dev/null +++ b/pycbc/mchirp_area.py @@ -0,0 +1,254 @@ +#!/usr/bin/env python + +#mchirp_area.py +# +#Integration of the area laying in the different cbc regions +#By A. Curiel Barroso +#August 2019 +# +#-------------------------------------------- +#This script computes the area corresponding +#to different CBC on the m1 & m2 plane when +#given a central mchirp value and uncertainty +#It also includes a function that calculates +#the source frame when given the detector +#frame mass and redshift +#-------------------------------------------- + +import numpy +from pycbc import conversions +from scipy.integrate import quad + +def src_mass_from_z_det_mass(z, del_z, mdet, del_mdet): + msrc = (mdet) / (1 + z) + del_msrc = msrc * ((del_mdet/mdet)**2 + (del_z/(1 + z))**2)**(0.5) + return (msrc, del_msrc) + +#Integration function +def mchange(x, mc): + return conversions.mass2_from_mchirp_mass1(mc, x) + +def intmc(mc, x_min, x_max): + integral = quad(mchange, x_min, x_max, args=mc) + return integral[0] + +def calc_areas(trig_mc_det, mass_limits, mass_bdary, z): + trig_mc = src_mass_from_z_det_mass(z["central"], z["delta"], + trig_mc_det["central"], + trig_mc_det["delta"]) + mcb = trig_mc[0] + trig_mc[1] + mcs = trig_mc[0] - trig_mc[1] + m2_min = mass_limits["min_m2"] + m1_max = mass_limits["max_m1"] + ns_max = mass_bdary["ns_max"] + gap_max = mass_bdary["gap_max"] + #The points where the equal mass line and a chirp mass + #curve intersect is m1 = m2 = 2**0.2 * mchirp + mib = (2**0.2) * mcb + mis = (2**0.2) * mcs + + #AREA FOR BBH + if mib < gap_max: + abbh = 0.0 + else: + limb_bbh = min(m1_max, + conversions.mass2_from_mchirp_mass1(mcb, gap_max)) + intb_bbh = intmc(mcb, mib, limb_bbh) + + if mis < gap_max: + lims1_bbh = gap_max + lims2_bbh = lims1_bbh + else: + lims1_bbh = mis + lims2_bbh = min(m1_max, + conversions.mass2_from_mchirp_mass1(mcs, gap_max)) + + ints_bbh = intmc(mcs, lims1_bbh, lims2_bbh) + + limdiag_bbh = max(conversions.mass2_from_mchirp_mass1(mcs, lims1_bbh), + gap_max) + intline_sup_bbh = 0.5 * (limdiag_bbh + mib) * (mib - lims1_bbh) + intline_inf_bbh = (limb_bbh - lims2_bbh) * gap_max + int_sup_bbh = intb_bbh + intline_sup_bbh + int_inf_bbh = ints_bbh + intline_inf_bbh + + abbh = int_sup_bbh - int_inf_bbh + + #AREA FOR BHG + if (conversions.mass2_from_mchirp_mass1(mcb, gap_max) < ns_max or + conversions.mass2_from_mchirp_mass1(mcs, m1_max) > gap_max): + abhg = 0.0 + else: + if conversions.mass2_from_mchirp_mass1(mcb, m1_max) > gap_max: + limb2_bhg = m1_max + limb1_bhg = limb2_bhg + else: + limb2_bhg = min(m1_max, + conversions.mass2_from_mchirp_mass1(mcb, ns_max)) + limb1_bhg = max(gap_max, + conversions.mass2_from_mchirp_mass1(mcb, gap_max)) + + intb_bhg = intmc(mcb, limb1_bhg, limb2_bhg) + + if conversions.mass2_from_mchirp_mass1(mcs, gap_max) < ns_max: + lims2_bhg = gap_max + lims1_bhg = lims2_bhg + else: + lims1_bhg = max(gap_max, + conversions.mass2_from_mchirp_mass1(mcs, gap_max)) + lims2_bhg = min(m1_max, + conversions.mass2_from_mchirp_mass1(mcs, ns_max)) + + intline_inf_bhg = (limb2_bhg - lims2_bhg) * ns_max + intline_sup_bhg = (limb1_bhg - lims1_bhg) * gap_max + ints_bhg = intmc(mcs, lims1_bhg, lims2_bhg) + int_sup_bhg = intb_bhg + intline_sup_bhg + int_inf_bhg = ints_bhg + intline_inf_bhg + + abhg = int_sup_bhg - int_inf_bhg + + #AREA FOR GG + if (conversions.mass2_from_mchirp_mass1(mcs, gap_max) > gap_max or + conversions.mass2_from_mchirp_mass1(mcb, ns_max) < ns_max): + agg = 0.0 + else: + if conversions.mass2_from_mchirp_mass1(mcb, gap_max) > gap_max: + limb2_gg = gap_max + limb1_gg = limb2_gg + else: + limb1_gg = mib + limb2_gg = min(gap_max, + conversions.mass2_from_mchirp_mass1(mcb, ns_max)) + + intb_gg = intmc(mcb, limb1_gg, limb2_gg) + + if conversions.mass2_from_mchirp_mass1(mcs, ns_max) < ns_max: + lims2_gg = ns_max + lims1_gg = lims2_gg + else: + lims1_gg = mis + lims2_gg = min(gap_max, + conversions.mass2_from_mchirp_mass1(mcs, ns_max)) + + ints_gg = intmc(mcs, lims1_gg, lims2_gg) + limdiag1_gg = max(conversions.mass2_from_mchirp_mass1(mcs, lims1_gg), + ns_max) + limdiag2_gg = min(conversions.mass2_from_mchirp_mass1(mcb, limb1_gg), + gap_max) + intline_sup_gg = (0.5 * (limb1_gg - lims1_gg) + * (limdiag1_gg + limdiag2_gg)) + intline_inf_gg = (limb2_gg - lims2_gg) * ns_max + int_sup_gg = intb_gg + intline_sup_gg + int_inf_gg = ints_gg + intline_inf_gg + + agg = int_sup_gg - int_inf_gg + + #AREA FOR BNS + if conversions.mass2_from_mchirp_mass1(mcs, ns_max) > ns_max: + abns = 0.0 + else: + if conversions.mass2_from_mchirp_mass1(mcb, ns_max) > ns_max: + limb2_bns = ns_max + limb1_bns = limb2_bns + else: + limb2_bns = min(ns_max, + conversions.mass2_from_mchirp_mass1(mcb, m2_min)) + limb1_bns = mib + + intb_bns = intmc(mcb, limb1_bns, limb2_bns) + + if mis < m2_min: + lims2_bns = m2_min + lims1_bns = lims2_bns + else: + lims2_bns = min(ns_max, + conversions.mass2_from_mchirp_mass1(mcs, m2_min)) + lims1_bns = mis + + ints_bns = intmc(mcs, lims1_bns, lims2_bns) + intline_inf_bns = (limb2_bns - lims2_bns) * m2_min + limdiag1_bns = max(conversions.mass2_from_mchirp_mass1(mcs, lims1_bns), + m2_min) + limdiag2_bns = min(conversions.mass2_from_mchirp_mass1(mcb, limb1_bns), + ns_max) + intline_sup_bns = (0.5 * (limdiag1_bns + limdiag2_bns) + * (limb1_bns - lims1_bns)) + int_sup_bns = intb_bns + intline_sup_bns + int_inf_bns = ints_bns + intline_inf_bns + + abns = int_sup_bns - int_inf_bns + + #AREA FOR GNS + if (conversions.mass2_from_mchirp_mass1(mcs, gap_max) > ns_max or + conversions.mass2_from_mchirp_mass1(mcb, ns_max) < m2_min): + agns = 0.0 + else: + if conversions.mass2_from_mchirp_mass1(mcb, gap_max) > ns_max: + limb2_gns = gap_max + limb1_gns = limb2_gns + else: + limb2_gns = min(gap_max, + conversions.mass2_from_mchirp_mass1(mcb, m2_min)) + limb1_gns = max(ns_max, + conversions.mass2_from_mchirp_mass1(mcb, ns_max)) + + intb_gns = intmc(mcb, limb1_gns, limb2_gns) + + if conversions.mass2_from_mchirp_mass1(mcs, ns_max) < m2_min: + lims2_gns = ns_max + lims1_gns = lims2_gns + else: + lims1_gns = max(ns_max, + conversions.mass2_from_mchirp_mass1(mcs, ns_max)) + lims2_gns = min(gap_max, + conversions.mass2_from_mchirp_mass1(mcs, m2_min)) + + intline_inf_gns = (limb2_gns - lims2_gns) * m2_min + intline_sup_gns = (limb1_gns - lims1_gns) *ns_max + ints_gns = intmc(mcs, lims1_gns, lims2_gns) + int_sup_gns = intb_gns + intline_sup_gns + int_inf_gns = ints_gns + intline_inf_gns + + agns = int_sup_gns - int_inf_gns + + #AREA FOR NSBH + if (conversions.mass2_from_mchirp_mass1(mcs, m1_max) > ns_max or + conversions.mass2_from_mchirp_mass1(mcb, gap_max) < m2_min): + ansbh = 0.0 + else: + if conversions.mass2_from_mchirp_mass1(mcb, m1_max) > ns_max: + limb2_nsbh = m1_max + limb1_nsbh = limb2_nsbh + else: + limb1_nsbh = max(gap_max, + conversions.mass2_from_mchirp_mass1(mcb, ns_max)) + limb2_nsbh = min(m1_max, + conversions.mass2_from_mchirp_mass1(mcb, m2_min)) + + intb_nsbh = intmc(mcb, limb1_nsbh, limb2_nsbh) + + if conversions.mass2_from_mchirp_mass1(mcs, gap_max) < m2_min: + lims1_nsbh = gap_max + lims2_nsbh = lims1_nsbh + else: + lims1_nsbh = max(gap_max, + conversions.mass2_from_mchirp_mass1(mcs, ns_max)) + lims2_nsbh = min(m1_max, + conversions.mass2_from_mchirp_mass1(mcs, m2_min)) + + intline_inf_nsbh = (limb2_nsbh - lims2_nsbh) * m2_min + intline_sup_nsbh = (limb1_nsbh - lims1_nsbh) * ns_max + ints_nsbh = intmc(mcs, lims1_nsbh, lims2_nsbh) + int_sup_nsbh = intb_nsbh + intline_sup_nsbh + int_inf_nsbh = ints_nsbh + intline_inf_nsbh + + ansbh = int_sup_nsbh - int_inf_nsbh + + return { + "bns": abns, + "gns": agns, + "nsbh": ansbh, + "gg": agg, + "bhg": abhg, + "bbh": abbh + } From 985c363972a24835b5f3c73f45f465e4f9f35a13 Mon Sep 17 00:00:00 2001 From: veronica-villa <51956991+veronica-villa@users.noreply.github.com> Date: Mon, 23 Sep 2019 19:27:05 +0200 Subject: [PATCH 02/31] Update mchirp_plots.py --- bin/plotting/mchirp_plots.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/bin/plotting/mchirp_plots.py b/bin/plotting/mchirp_plots.py index ee3d890f6f9..8d36a9f9353 100644 --- a/bin/plotting/mchirp_plots.py +++ b/bin/plotting/mchirp_plots.py @@ -20,18 +20,12 @@ #ARGUMENT PARSER parser = argparse.ArgumentParser() -parser.add_argument("--min-m2","--min-m2",type=float, - help="Minimum value for m2") -parser.add_argument("--max-m1","--max-m1",type=float, - help="Maximum value for m1") -parser.add_argument("--ns-max","--ns-max",type=float, - help="Maximum neutron star mass") -parser.add_argument("--gap-max","--gap-max",type=float, - help="Minimum black hole mass") -parser.add_argument("--central-z","--central-z",type=float, - help="Central redshift value") -parser.add_argument("--delta-z","--delta-z",type=float, - help="Redshift uncertainty") +parser.add_argument("--min-m2", type=float, help="Minimum value for m2") +parser.add_argument("--max-m1", type=float, help="Maximum value for m1") +parser.add_argument("--ns-max", type=float, help="Maximum neutron star mass") +parser.add_argument("--gap-max", type=float, help="Minimum black hole mass") +parser.add_argument("--central-z", type=float, help="Central redshift value") +parser.add_argument("--delta-z", type=float, help="Redshift uncertainty") args = parser.parse_args() if args.min_m2 and args.max_m1: From 51c3b83edac17de9f04c99eda21637fce97023b4 Mon Sep 17 00:00:00 2001 From: veronica-villa <51956991+veronica-villa@users.noreply.github.com> Date: Wed, 25 Sep 2019 17:22:06 +0200 Subject: [PATCH 03/31] Update mass_area_plot.py --- bin/plotting/mass_area_plot.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/bin/plotting/mass_area_plot.py b/bin/plotting/mass_area_plot.py index 06a6a7d84b0..2f0e2303e9c 100644 --- a/bin/plotting/mass_area_plot.py +++ b/bin/plotting/mass_area_plot.py @@ -7,13 +7,11 @@ #August 2019 # #-------------------------------------------- -#This script computes the area corresponding -#to different CBC on the m1 & m2 plane when +#This script computes the area corresponding +#to different CBC on the m1 & m2 plane when #given a central mchirp value and uncertainty #-------------------------------------------- -from pycbc import conversions -import numpy from matplotlib import use use("agg") from matplotlib import pyplot @@ -21,6 +19,8 @@ from mchirp_area import calc_areas from mchirp_area import src_mass_from_z_det_mass import argparse +from pycbc import conversions +import numpy #ARGUMENT PARSER parser = argparse.ArgumentParser() @@ -60,7 +60,7 @@ trig_mc = {"central": central_mc, "delta": delta_mc} areas = calc_areas(trig_mc, mass_limits, mass_bdary, z) - + print "abbh = "+str(areas["bbh"]) print "abhg = "+str(areas["bhg"]) print "agg = "+str(areas["gg"]) @@ -99,7 +99,7 @@ pyplot.plot( (m1_max, m1_max), (conversions.mass2_from_mchirp_mass1(mcs, lim_m1s), - conversions.mass2_from_mchirp_mass1(mcb, lim_m1b)), "b") + conversions.mass2_from_mchirp_mass1(mcb, lim_m1b)), "b") if mis >= m2_min: pyplot.plot(m1s, m2s, "b") @@ -115,7 +115,6 @@ pyplot.xlabel("M1") pyplot.ylabel("M2") -pyplot.title("MChirp = "+str((0.5) * (mcb+mcs)) + " +/- "+str((mcb-mcs) * (0.5))) +pyplot.title("MChirp = "+str((0.5) * (mcb+mcs)) + " +/- " + +str((mcb-mcs) * (0.5))) pyplot.savefig("mass_plot.png") - - From 20be3d123f9fcf394f6681364319014e11b7913d Mon Sep 17 00:00:00 2001 From: veronica-villa <51956991+veronica-villa@users.noreply.github.com> Date: Wed, 25 Sep 2019 17:28:07 +0200 Subject: [PATCH 04/31] Update mchirp_plots.py --- bin/plotting/mchirp_plots.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/bin/plotting/mchirp_plots.py b/bin/plotting/mchirp_plots.py index 8d36a9f9353..11166399541 100644 --- a/bin/plotting/mchirp_plots.py +++ b/bin/plotting/mchirp_plots.py @@ -1,24 +1,25 @@ #!/usr/bin/env python -#mchirp_plots.py +# chirp_plots.py # -#Integration of the area laying in the different cbc regions -#By A. Curiel Barroso -#August 2019 +# Integration of the area laying in the different cbc regions +# By A. Curiel Barroso +# August 2019 # -#-------------------------------------------- -#This script computes the area corresponding -#to different CBC on the m1 & m2 plane as a -#function of central mchirp value -#-------------------------------------------- +# -------------------------------------------- +# This script computes the area corresponding +# to different CBC on the m1 & m2 plane as a +# function of central mchirp value +# -------------------------------------------- -import numpy -import argparse -from matplotlib import use; use("agg") +from matplotlib import use +use("agg") from matplotlib import pyplot from mchirp_area import calc_areas +import argparse +import numpy -#ARGUMENT PARSER +# ARGUMENT PARSER parser = argparse.ArgumentParser() parser.add_argument("--min-m2", type=float, help="Minimum value for m2") parser.add_argument("--max-m1", type=float, help="Maximum value for m1") @@ -35,14 +36,14 @@ if args.min_m2 and args.max_m1: ns_max = float(args.ns_max) gap_max = float(args.gap_max) - + if args.central_z and args.delta_z: central_z = float(args.central_z) delta_z = float(args.delta_z) else: central_z = 0.0 delta_z = 0.0 - + mass_limits = {"max_m1": m1_max, "min_m2": m2_min} mass_bdary = {"ns_max": ns_max, "gap_max": gap_max} z = {"central": central_z, "delta": delta_z} @@ -56,7 +57,6 @@ y_agns = numpy.zeros(n, float) y_abns = numpy.zeros(n, float) - for i in range(0, n): central_mc = 0.8 + i*(10.0 - 0.8)/(n - 1) delta_mc = central_mc * 0.01 @@ -69,7 +69,7 @@ y_ansbh[i] = areas["nsbh"] y_agns[i] = areas["gns"] y_abns[i] = areas["bns"] - + pyplot.plot(x_mc, y_abbh, label="Binary Black Hole") pyplot.plot(x_mc, y_abhg, label="Black Hole + Mass Gap Object") pyplot.plot(x_mc, y_agg, label="Binary Mass Gap Object") From 13248b30fe5c7ca888a35c40fbcfe5d88ee9a514 Mon Sep 17 00:00:00 2001 From: veronica-villa <51956991+veronica-villa@users.noreply.github.com> Date: Wed, 25 Sep 2019 17:28:58 +0200 Subject: [PATCH 05/31] Update mass_area_plot.py --- bin/plotting/mass_area_plot.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/bin/plotting/mass_area_plot.py b/bin/plotting/mass_area_plot.py index 2f0e2303e9c..18ecb566ecc 100644 --- a/bin/plotting/mass_area_plot.py +++ b/bin/plotting/mass_area_plot.py @@ -1,16 +1,16 @@ #!/usr/bin/env python -#mass_area_plot.py +# mass_area_plot.py # -#Integration of the area laying in the different cbc regions -#By A. Curiel Barroso -#August 2019 +# Integration of the area laying in the different cbc regions +# By A. Curiel Barroso +# August 2019 # -#-------------------------------------------- -#This script computes the area corresponding -#to different CBC on the m1 & m2 plane when -#given a central mchirp value and uncertainty -#-------------------------------------------- +# -------------------------------------------- +# This script computes the area corresponding +# to different CBC on the m1 & m2 plane when +# given a central mchirp value and uncertainty +# -------------------------------------------- from matplotlib import use use("agg") @@ -22,7 +22,7 @@ from pycbc import conversions import numpy -#ARGUMENT PARSER +# ARGUMENT PARSER parser = argparse.ArgumentParser() parser.add_argument("--central-mc", type=float, help="Central value of mchirp") parser.add_argument("--delta-mc", type=float, help="Uncertainty for mchirp") @@ -68,15 +68,15 @@ print "agns = "+str(areas["gns"]) print "abns = "+str(areas["bns"]) -#PLOT GENERATION +# PLOT GENERATION src_mchirp = src_mass_from_z_det_mass(central_z, delta_z, central_mc, delta_mc) mcb = src_mchirp[0] + src_mchirp[1] mcs = src_mchirp[0] - src_mchirp[1] -#The points where the equal mass line and a chirp mass -#curve intersect is m1 = m2 = (2**0.2)*mchirp +# The points where the equal mass line and a chirp mass +# curve intersect is m1 = m2 = (2**0.2)*mchirp mib = (2**0.2)*mcb mis = (2**0.2)*mcs From 2ee0fc0788b446e7be287bad983e70dc1ea25193 Mon Sep 17 00:00:00 2001 From: veronica-villa <51956991+veronica-villa@users.noreply.github.com> Date: Wed, 25 Sep 2019 18:28:53 +0200 Subject: [PATCH 06/31] Update mchirp_area.py --- pycbc/mchirp_area.py | 66 +++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/pycbc/mchirp_area.py b/pycbc/mchirp_area.py index 93151b71b49..789849cb6e0 100644 --- a/pycbc/mchirp_area.py +++ b/pycbc/mchirp_area.py @@ -1,40 +1,44 @@ #!/usr/bin/env python -#mchirp_area.py +# mchirp_area.py # -#Integration of the area laying in the different cbc regions -#By A. Curiel Barroso -#August 2019 +# Integration of the area laying in the different cbc regions +# By A. Curiel Barroso +# August 2019 # -#-------------------------------------------- -#This script computes the area corresponding -#to different CBC on the m1 & m2 plane when -#given a central mchirp value and uncertainty -#It also includes a function that calculates -#the source frame when given the detector -#frame mass and redshift -#-------------------------------------------- - -import numpy +# -------------------------------------------- +# This script computes the area corresponding +# to different CBC on the m1 & m2 plane when +# given a central mchirp value and uncertainty +# It also includes a function that calculates +# the source frame when given the detector +# frame mass and redshift +# -------------------------------------------- + from pycbc import conversions from scipy.integrate import quad + def src_mass_from_z_det_mass(z, del_z, mdet, del_mdet): msrc = (mdet) / (1 + z) del_msrc = msrc * ((del_mdet/mdet)**2 + (del_z/(1 + z))**2)**(0.5) return (msrc, del_msrc) -#Integration function + +# Integration function def mchange(x, mc): return conversions.mass2_from_mchirp_mass1(mc, x) + def intmc(mc, x_min, x_max): integral = quad(mchange, x_min, x_max, args=mc) return integral[0] + def calc_areas(trig_mc_det, mass_limits, mass_bdary, z): trig_mc = src_mass_from_z_det_mass(z["central"], z["delta"], trig_mc_det["central"], + trig_mc_det["delta"]) mcb = trig_mc[0] + trig_mc[1] mcs = trig_mc[0] - trig_mc[1] @@ -42,12 +46,12 @@ def calc_areas(trig_mc_det, mass_limits, mass_bdary, z): m1_max = mass_limits["max_m1"] ns_max = mass_bdary["ns_max"] gap_max = mass_bdary["gap_max"] - #The points where the equal mass line and a chirp mass - #curve intersect is m1 = m2 = 2**0.2 * mchirp + '''The points where the equal mass line and a chirp mass + curve intersect is m1 = m2 = 2**0.2 * mchirp''' mib = (2**0.2) * mcb mis = (2**0.2) * mcs - #AREA FOR BBH + # AREA FOR BBH if mib < gap_max: abbh = 0.0 else: @@ -74,9 +78,9 @@ def calc_areas(trig_mc_det, mass_limits, mass_bdary, z): abbh = int_sup_bbh - int_inf_bbh - #AREA FOR BHG + # AREA FOR BHG if (conversions.mass2_from_mchirp_mass1(mcb, gap_max) < ns_max or - conversions.mass2_from_mchirp_mass1(mcs, m1_max) > gap_max): + conversions.mass2_from_mchirp_mass1(mcs, m1_max) > gap_max): abhg = 0.0 else: if conversions.mass2_from_mchirp_mass1(mcb, m1_max) > gap_max: @@ -101,16 +105,16 @@ def calc_areas(trig_mc_det, mass_limits, mass_bdary, z): intline_inf_bhg = (limb2_bhg - lims2_bhg) * ns_max intline_sup_bhg = (limb1_bhg - lims1_bhg) * gap_max - ints_bhg = intmc(mcs, lims1_bhg, lims2_bhg) + ints_bhg = intmc(mcs, lims1_bhg, lims2_bhg) int_sup_bhg = intb_bhg + intline_sup_bhg int_inf_bhg = ints_bhg + intline_inf_bhg abhg = int_sup_bhg - int_inf_bhg - #AREA FOR GG + # AREA FOR GG if (conversions.mass2_from_mchirp_mass1(mcs, gap_max) > gap_max or - conversions.mass2_from_mchirp_mass1(mcb, ns_max) < ns_max): - agg = 0.0 + conversions.mass2_from_mchirp_mass1(mcb, ns_max) < ns_max): + agg = 0.0 else: if conversions.mass2_from_mchirp_mass1(mcb, gap_max) > gap_max: limb2_gg = gap_max @@ -143,7 +147,7 @@ def calc_areas(trig_mc_det, mass_limits, mass_bdary, z): agg = int_sup_gg - int_inf_gg - #AREA FOR BNS + # AREA FOR BNS if conversions.mass2_from_mchirp_mass1(mcs, ns_max) > ns_max: abns = 0.0 else: @@ -178,9 +182,9 @@ def calc_areas(trig_mc_det, mass_limits, mass_bdary, z): abns = int_sup_bns - int_inf_bns - #AREA FOR GNS + # AREA FOR GNS if (conversions.mass2_from_mchirp_mass1(mcs, gap_max) > ns_max or - conversions.mass2_from_mchirp_mass1(mcb, ns_max) < m2_min): + conversions.mass2_from_mchirp_mass1(mcb, ns_max) < m2_min): agns = 0.0 else: if conversions.mass2_from_mchirp_mass1(mcb, gap_max) > ns_max: @@ -202,18 +206,18 @@ def calc_areas(trig_mc_det, mass_limits, mass_bdary, z): conversions.mass2_from_mchirp_mass1(mcs, ns_max)) lims2_gns = min(gap_max, conversions.mass2_from_mchirp_mass1(mcs, m2_min)) - + intline_inf_gns = (limb2_gns - lims2_gns) * m2_min - intline_sup_gns = (limb1_gns - lims1_gns) *ns_max + intline_sup_gns = (limb1_gns - lims1_gns) * ns_max ints_gns = intmc(mcs, lims1_gns, lims2_gns) int_sup_gns = intb_gns + intline_sup_gns int_inf_gns = ints_gns + intline_inf_gns agns = int_sup_gns - int_inf_gns - #AREA FOR NSBH + # AREA FOR NSBH if (conversions.mass2_from_mchirp_mass1(mcs, m1_max) > ns_max or - conversions.mass2_from_mchirp_mass1(mcb, gap_max) < m2_min): + conversions.mass2_from_mchirp_mass1(mcb, gap_max) < m2_min): ansbh = 0.0 else: if conversions.mass2_from_mchirp_mass1(mcb, m1_max) > ns_max: From c489f498aeb447a727c3e6ffba3a0ef188ecdb46 Mon Sep 17 00:00:00 2001 From: veronica-villa <51956991+veronica-villa@users.noreply.github.com> Date: Wed, 25 Sep 2019 18:38:42 +0200 Subject: [PATCH 07/31] Update mass_area_plot.py --- bin/plotting/mass_area_plot.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/bin/plotting/mass_area_plot.py b/bin/plotting/mass_area_plot.py index 18ecb566ecc..f996f06b552 100644 --- a/bin/plotting/mass_area_plot.py +++ b/bin/plotting/mass_area_plot.py @@ -1,17 +1,16 @@ #!/usr/bin/env python - -# mass_area_plot.py -# -# Integration of the area laying in the different cbc regions -# By A. Curiel Barroso -# August 2019 -# -# -------------------------------------------- -# This script computes the area corresponding -# to different CBC on the m1 & m2 plane when -# given a central mchirp value and uncertainty -# -------------------------------------------- - +"""mass_area_plot.py + +Integration of the area laying in the different cbc regions +By A. Curiel Barroso +August 2019 + +-------------------------------------------- +This script computes the area corresponding +to different CBC on the m1 & m2 plane when +given a central mchirp value and uncertainty +-------------------------------------------- +""" from matplotlib import use use("agg") from matplotlib import pyplot @@ -61,7 +60,7 @@ areas = calc_areas(trig_mc, mass_limits, mass_bdary, z) -print "abbh = "+str(areas["bbh"]) +#print "abbh = "+str(areas["bbh"]) print "abhg = "+str(areas["bhg"]) print "agg = "+str(areas["gg"]) print "ansbh = "+str(areas["nsbh"]) From e4dafca97686ec1a280c73a84691279d9dd03e44 Mon Sep 17 00:00:00 2001 From: veronica-villa <51956991+veronica-villa@users.noreply.github.com> Date: Wed, 25 Sep 2019 19:24:06 +0200 Subject: [PATCH 08/31] Update mass_area_plot.py --- bin/plotting/mass_area_plot.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/bin/plotting/mass_area_plot.py b/bin/plotting/mass_area_plot.py index f996f06b552..a12bb0b5e86 100644 --- a/bin/plotting/mass_area_plot.py +++ b/bin/plotting/mass_area_plot.py @@ -60,12 +60,12 @@ areas = calc_areas(trig_mc, mass_limits, mass_bdary, z) -#print "abbh = "+str(areas["bbh"]) -print "abhg = "+str(areas["bhg"]) -print "agg = "+str(areas["gg"]) -print "ansbh = "+str(areas["nsbh"]) -print "agns = "+str(areas["gns"]) -print "abns = "+str(areas["bns"]) +print "abbh = " + str(areas["bbh"]) +print "abhg = " + str(areas["bhg"]) +print "agg = " + str(areas["gg"]) +print "ansbh = " + str(areas["nsbh"]) +print "agns = " + str(areas["gns"]) +print "abns = " + str(areas["bns"]) # PLOT GENERATION src_mchirp = src_mass_from_z_det_mass(central_z, delta_z, @@ -114,6 +114,6 @@ pyplot.xlabel("M1") pyplot.ylabel("M2") -pyplot.title("MChirp = "+str((0.5) * (mcb+mcs)) + " +/- " - +str((mcb-mcs) * (0.5))) +pyplot.title("MChirp = " + str((0.5) * (mcb + mcs)) + " +/- " + + str((mcb - mcs) * (0.5))) pyplot.savefig("mass_plot.png") From e5ab6bc50e975f2fd7d6567abb8527138467fb05 Mon Sep 17 00:00:00 2001 From: veronica-villa <51956991+veronica-villa@users.noreply.github.com> Date: Wed, 25 Sep 2019 19:36:20 +0200 Subject: [PATCH 09/31] Update mchirp_plots.py --- bin/plotting/mchirp_plots.py | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/bin/plotting/mchirp_plots.py b/bin/plotting/mchirp_plots.py index 11166399541..8fc42d98e2d 100644 --- a/bin/plotting/mchirp_plots.py +++ b/bin/plotting/mchirp_plots.py @@ -1,23 +1,22 @@ #!/usr/bin/env python -# chirp_plots.py -# -# Integration of the area laying in the different cbc regions -# By A. Curiel Barroso -# August 2019 -# -# -------------------------------------------- -# This script computes the area corresponding -# to different CBC on the m1 & m2 plane as a -# function of central mchirp value -# -------------------------------------------- +"""chirp_plots.py -from matplotlib import use -use("agg") -from matplotlib import pyplot -from mchirp_area import calc_areas +Integration of the area laying in the different cbc regions +By A. Curiel Barroso +August 2019 + +-------------------------------------------- +This script computes the area corresponding +to different CBC on the m1 & m2 plane as a +function of central mchirp value +-------------------------------------------- +""" import argparse +from mchirp_area import calc_areas import numpy +from matplotlib import use; use("Agg") +from matplotlib import pyplot # ARGUMENT PARSER parser = argparse.ArgumentParser() From 9c67e4cb951fa450529d080dff3825c4b13f1295 Mon Sep 17 00:00:00 2001 From: veronica-villa <51956991+veronica-villa@users.noreply.github.com> Date: Wed, 25 Sep 2019 19:36:43 +0200 Subject: [PATCH 10/31] Update mchirp_plots.py --- bin/plotting/mchirp_plots.py | 1 - 1 file changed, 1 deletion(-) diff --git a/bin/plotting/mchirp_plots.py b/bin/plotting/mchirp_plots.py index 8fc42d98e2d..17e7a275cd8 100644 --- a/bin/plotting/mchirp_plots.py +++ b/bin/plotting/mchirp_plots.py @@ -1,5 +1,4 @@ #!/usr/bin/env python - """chirp_plots.py Integration of the area laying in the different cbc regions From 9f28b2f5de63c66212e675a05786c0c994b0b1b6 Mon Sep 17 00:00:00 2001 From: veronica-villa <51956991+veronica-villa@users.noreply.github.com> Date: Wed, 25 Sep 2019 19:53:52 +0200 Subject: [PATCH 11/31] Update mchirp_area.py --- pycbc/mchirp_area.py | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/pycbc/mchirp_area.py b/pycbc/mchirp_area.py index 789849cb6e0..dee2c3a06c7 100644 --- a/pycbc/mchirp_area.py +++ b/pycbc/mchirp_area.py @@ -1,20 +1,19 @@ #!/usr/bin/env python - -# mchirp_area.py -# -# Integration of the area laying in the different cbc regions -# By A. Curiel Barroso -# August 2019 -# -# -------------------------------------------- -# This script computes the area corresponding -# to different CBC on the m1 & m2 plane when -# given a central mchirp value and uncertainty -# It also includes a function that calculates -# the source frame when given the detector -# frame mass and redshift -# -------------------------------------------- - +"""mchirp_area.py + +Integration of the area laying in the different cbc regions +By A. Curiel Barroso +August 2019 + +-------------------------------------------- +This script computes the area corresponding +to different CBC on the m1 & m2 plane when +given a central mchirp value and uncertainty +It also includes a function that calculates +the source frame when given the detector +frame mass and redshift +-------------------------------------------- +""" from pycbc import conversions from scipy.integrate import quad @@ -46,8 +45,8 @@ def calc_areas(trig_mc_det, mass_limits, mass_bdary, z): m1_max = mass_limits["max_m1"] ns_max = mass_bdary["ns_max"] gap_max = mass_bdary["gap_max"] - '''The points where the equal mass line and a chirp mass - curve intersect is m1 = m2 = 2**0.2 * mchirp''' + # The points where the equal mass line and a chirp mass + # curve intersect is m1 = m2 = 2**0.2 * mchirp mib = (2**0.2) * mcb mis = (2**0.2) * mcs From 224ec18e3d5f89dfb62d9745a470e3e1f6ac5f8d Mon Sep 17 00:00:00 2001 From: veronica-villa <51956991+veronica-villa@users.noreply.github.com> Date: Wed, 25 Sep 2019 20:05:54 +0200 Subject: [PATCH 12/31] Update mass_area_plot.py --- bin/plotting/mass_area_plot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/plotting/mass_area_plot.py b/bin/plotting/mass_area_plot.py index a12bb0b5e86..3f20c86753c 100644 --- a/bin/plotting/mass_area_plot.py +++ b/bin/plotting/mass_area_plot.py @@ -58,7 +58,7 @@ z = {"central": central_z, "delta": delta_z} trig_mc = {"central": central_mc, "delta": delta_mc} -areas = calc_areas(trig_mc, mass_limits, mass_bdary, z) +#areas = calc_areas(trig_mc, mass_limits, mass_bdary, z) print "abbh = " + str(areas["bbh"]) print "abhg = " + str(areas["bhg"]) From 3579c0077a94803605d6e2419d7d17ccd27edcba Mon Sep 17 00:00:00 2001 From: veronica-villa <51956991+veronica-villa@users.noreply.github.com> Date: Wed, 25 Sep 2019 20:13:04 +0200 Subject: [PATCH 13/31] Update mass_area_plot.py --- bin/plotting/mass_area_plot.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bin/plotting/mass_area_plot.py b/bin/plotting/mass_area_plot.py index 3f20c86753c..7ca2cc8dc99 100644 --- a/bin/plotting/mass_area_plot.py +++ b/bin/plotting/mass_area_plot.py @@ -57,9 +57,7 @@ mass_bdary = {"ns_max": ns_max, "gap_max": gap_max} z = {"central": central_z, "delta": delta_z} trig_mc = {"central": central_mc, "delta": delta_mc} - -#areas = calc_areas(trig_mc, mass_limits, mass_bdary, z) - +areas = calc_areas(trig_mc, mass_limits, mass_bdary, z) print "abbh = " + str(areas["bbh"]) print "abhg = " + str(areas["bhg"]) print "agg = " + str(areas["gg"]) From e2735dee43e714e0abb29268d9a68fd000b0becb Mon Sep 17 00:00:00 2001 From: veronica-villa <51956991+veronica-villa@users.noreply.github.com> Date: Wed, 25 Sep 2019 20:20:36 +0200 Subject: [PATCH 14/31] Update mass_area_plot.py --- bin/plotting/mass_area_plot.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/bin/plotting/mass_area_plot.py b/bin/plotting/mass_area_plot.py index 7ca2cc8dc99..5ebd5e8e080 100644 --- a/bin/plotting/mass_area_plot.py +++ b/bin/plotting/mass_area_plot.py @@ -57,13 +57,15 @@ mass_bdary = {"ns_max": ns_max, "gap_max": gap_max} z = {"central": central_z, "delta": delta_z} trig_mc = {"central": central_mc, "delta": delta_mc} + areas = calc_areas(trig_mc, mass_limits, mass_bdary, z) -print "abbh = " + str(areas["bbh"]) -print "abhg = " + str(areas["bhg"]) -print "agg = " + str(areas["gg"]) -print "ansbh = " + str(areas["nsbh"]) -print "agns = " + str(areas["gns"]) -print "abns = " + str(areas["bns"]) + +print("abbh = " + str(areas["bbh"])) +print("abhg = " + str(areas["bhg"])) +print("agg = " + str(areas["gg"])) +print("ansbh = " + str(areas["nsbh"])) +print("agns = " + str(areas["gns"])) +print("abns = " + str(areas["bns"])) # PLOT GENERATION src_mchirp = src_mass_from_z_det_mass(central_z, delta_z, From b594daea1d6263df0affa3f832276cbc09484ac3 Mon Sep 17 00:00:00 2001 From: veronica-villa <51956991+veronica-villa@users.noreply.github.com> Date: Wed, 25 Sep 2019 20:28:27 +0200 Subject: [PATCH 15/31] Update mass_area_plot.py --- bin/plotting/mass_area_plot.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/bin/plotting/mass_area_plot.py b/bin/plotting/mass_area_plot.py index 5ebd5e8e080..76ca990e224 100644 --- a/bin/plotting/mass_area_plot.py +++ b/bin/plotting/mass_area_plot.py @@ -11,15 +11,13 @@ given a central mchirp value and uncertainty -------------------------------------------- """ -from matplotlib import use -use("agg") -from matplotlib import pyplot -from scipy.integrate import quad +import argparse from mchirp_area import calc_areas from mchirp_area import src_mass_from_z_det_mass -import argparse from pycbc import conversions import numpy +from matplotlib import use; use("Agg") +from matplotlib import pyplot # ARGUMENT PARSER parser = argparse.ArgumentParser() From 394436aa61c9f41d57298a1728d75c7d0bc0d00e Mon Sep 17 00:00:00 2001 From: veronica-villa <51956991+veronica-villa@users.noreply.github.com> Date: Tue, 1 Oct 2019 17:11:22 +0200 Subject: [PATCH 16/31] Update mchirp_area.py --- pycbc/mchirp_area.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/pycbc/mchirp_area.py b/pycbc/mchirp_area.py index dee2c3a06c7..22227b83c50 100644 --- a/pycbc/mchirp_area.py +++ b/pycbc/mchirp_area.py @@ -1,19 +1,17 @@ #!/usr/bin/env python -"""mchirp_area.py +# mchirp_area.py +# Integration of the area laying in the different cbc regions +# By A. Curiel Barroso +# August 2019 -Integration of the area laying in the different cbc regions -By A. Curiel Barroso -August 2019 - --------------------------------------------- -This script computes the area corresponding +"""This script computes the area corresponding to different CBC on the m1 & m2 plane when given a central mchirp value and uncertainty It also includes a function that calculates the source frame when given the detector frame mass and redshift --------------------------------------------- """ + from pycbc import conversions from scipy.integrate import quad From 3698eef092cb051d3ef4e471802abdb73d09111f Mon Sep 17 00:00:00 2001 From: veronica-villa <51956991+veronica-villa@users.noreply.github.com> Date: Thu, 3 Oct 2019 12:26:58 +0200 Subject: [PATCH 17/31] Add docstring --- pycbc/mchirp_area.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pycbc/mchirp_area.py b/pycbc/mchirp_area.py index 22227b83c50..c37968262f4 100644 --- a/pycbc/mchirp_area.py +++ b/pycbc/mchirp_area.py @@ -17,6 +17,10 @@ def src_mass_from_z_det_mass(z, del_z, mdet, del_mdet): + """This function takes values of redshift, redshift uncertainty, + detector mass and its uncertainty and computes the source mass + and its uncertainty. + """ msrc = (mdet) / (1 + z) del_msrc = msrc * ((del_mdet/mdet)**2 + (del_z/(1 + z))**2)**(0.5) return (msrc, del_msrc) @@ -24,6 +28,8 @@ def src_mass_from_z_det_mass(z, del_z, mdet, del_mdet): # Integration function def mchange(x, mc): + """This function takes the value of one component mass + """ return conversions.mass2_from_mchirp_mass1(mc, x) @@ -35,7 +41,6 @@ def intmc(mc, x_min, x_max): def calc_areas(trig_mc_det, mass_limits, mass_bdary, z): trig_mc = src_mass_from_z_det_mass(z["central"], z["delta"], trig_mc_det["central"], - trig_mc_det["delta"]) mcb = trig_mc[0] + trig_mc[1] mcs = trig_mc[0] - trig_mc[1] From 077b7fbb576f53d74f30e1043ebaf0b284b3de66 Mon Sep 17 00:00:00 2001 From: veronica-villa <51956991+veronica-villa@users.noreply.github.com> Date: Thu, 3 Oct 2019 19:00:37 +0200 Subject: [PATCH 18/31] Add docstrings and aliasing some modules --- pycbc/mchirp_area.py | 117 ++++++++++++++++++------------------------- 1 file changed, 49 insertions(+), 68 deletions(-) diff --git a/pycbc/mchirp_area.py b/pycbc/mchirp_area.py index c37968262f4..918527c3169 100644 --- a/pycbc/mchirp_area.py +++ b/pycbc/mchirp_area.py @@ -12,7 +12,7 @@ frame mass and redshift """ -from pycbc import conversions +from pycbc.conversions import mass2_from_mchirp_mass1 as m2mcm1 from scipy.integrate import quad @@ -25,20 +25,28 @@ def src_mass_from_z_det_mass(z, del_z, mdet, del_mdet): del_msrc = msrc * ((del_mdet/mdet)**2 + (del_z/(1 + z))**2)**(0.5) return (msrc, del_msrc) - # Integration function def mchange(x, mc): - """This function takes the value of one component mass + """This function returns a component mass as a function of mchirp and + the other component mass. """ - return conversions.mass2_from_mchirp_mass1(mc, x) + return m2mcm1(mc, x) def intmc(mc, x_min, x_max): + """This function returns the integral of mchange between the minimum and + maximum values of a component mass taking mchirp as an argument. + """ integral = quad(mchange, x_min, x_max, args=mc) return integral[0] def calc_areas(trig_mc_det, mass_limits, mass_bdary, z): + """This function computes the area inside the lines of the second component + mass as a function of the first component mass for the two extreme values + of mchirp: mchirp +/- mchirp_uncertainty, for each region of the source + classifying diagram. + """ trig_mc = src_mass_from_z_det_mass(z["central"], z["delta"], trig_mc_det["central"], trig_mc_det["delta"]) @@ -57,8 +65,7 @@ def calc_areas(trig_mc_det, mass_limits, mass_bdary, z): if mib < gap_max: abbh = 0.0 else: - limb_bbh = min(m1_max, - conversions.mass2_from_mchirp_mass1(mcb, gap_max)) + limb_bbh = min(m1_max, m2mcm1(mcb, gap_max)) intb_bbh = intmc(mcb, mib, limb_bbh) if mis < gap_max: @@ -66,13 +73,11 @@ def calc_areas(trig_mc_det, mass_limits, mass_bdary, z): lims2_bbh = lims1_bbh else: lims1_bbh = mis - lims2_bbh = min(m1_max, - conversions.mass2_from_mchirp_mass1(mcs, gap_max)) + lims2_bbh = min(m1_max, m2mcm1(mcs, gap_max)) ints_bbh = intmc(mcs, lims1_bbh, lims2_bbh) - limdiag_bbh = max(conversions.mass2_from_mchirp_mass1(mcs, lims1_bbh), - gap_max) + limdiag_bbh = max(m2mcm1(mcs, lims1_bbh), gap_max) intline_sup_bbh = 0.5 * (limdiag_bbh + mib) * (mib - lims1_bbh) intline_inf_bbh = (limb_bbh - lims2_bbh) * gap_max int_sup_bbh = intb_bbh + intline_sup_bbh @@ -81,29 +86,24 @@ def calc_areas(trig_mc_det, mass_limits, mass_bdary, z): abbh = int_sup_bbh - int_inf_bbh # AREA FOR BHG - if (conversions.mass2_from_mchirp_mass1(mcb, gap_max) < ns_max or - conversions.mass2_from_mchirp_mass1(mcs, m1_max) > gap_max): + if m2mcm1(mcb, gap_max) < ns_max or m2mcm1(mcs, m1_max) > gap_max: abhg = 0.0 else: - if conversions.mass2_from_mchirp_mass1(mcb, m1_max) > gap_max: + if m2mcm1(mcb, m1_max) > gap_max: limb2_bhg = m1_max limb1_bhg = limb2_bhg else: - limb2_bhg = min(m1_max, - conversions.mass2_from_mchirp_mass1(mcb, ns_max)) - limb1_bhg = max(gap_max, - conversions.mass2_from_mchirp_mass1(mcb, gap_max)) + limb2_bhg = min(m1_max, m2mcm1(mcb, ns_max)) + limb1_bhg = max(gap_max, m2mcm1(mcb, gap_max)) intb_bhg = intmc(mcb, limb1_bhg, limb2_bhg) - if conversions.mass2_from_mchirp_mass1(mcs, gap_max) < ns_max: + if m2mcm1(mcs, gap_max) < ns_max: lims2_bhg = gap_max lims1_bhg = lims2_bhg else: - lims1_bhg = max(gap_max, - conversions.mass2_from_mchirp_mass1(mcs, gap_max)) - lims2_bhg = min(m1_max, - conversions.mass2_from_mchirp_mass1(mcs, ns_max)) + lims1_bhg = max(gap_max, m2mcm1(mcs, gap_max)) + lims2_bhg = min(m1_max, m2mcm1(mcs, ns_max)) intline_inf_bhg = (limb2_bhg - lims2_bhg) * ns_max intline_sup_bhg = (limb1_bhg - lims1_bhg) * gap_max @@ -114,33 +114,28 @@ def calc_areas(trig_mc_det, mass_limits, mass_bdary, z): abhg = int_sup_bhg - int_inf_bhg # AREA FOR GG - if (conversions.mass2_from_mchirp_mass1(mcs, gap_max) > gap_max or - conversions.mass2_from_mchirp_mass1(mcb, ns_max) < ns_max): + if m2mcm1(mcs, gap_max) > gap_max or m2mcm1(mcb, ns_max) < ns_max: agg = 0.0 else: - if conversions.mass2_from_mchirp_mass1(mcb, gap_max) > gap_max: + if m2mcm1(mcb, gap_max) > gap_max: limb2_gg = gap_max limb1_gg = limb2_gg else: limb1_gg = mib - limb2_gg = min(gap_max, - conversions.mass2_from_mchirp_mass1(mcb, ns_max)) + limb2_gg = min(gap_max, m2mcm1(mcb, ns_max)) intb_gg = intmc(mcb, limb1_gg, limb2_gg) - if conversions.mass2_from_mchirp_mass1(mcs, ns_max) < ns_max: + if m2mcm1(mcs, ns_max) < ns_max: lims2_gg = ns_max lims1_gg = lims2_gg else: lims1_gg = mis - lims2_gg = min(gap_max, - conversions.mass2_from_mchirp_mass1(mcs, ns_max)) + lims2_gg = min(gap_max, m2mcm1(mcs, ns_max)) ints_gg = intmc(mcs, lims1_gg, lims2_gg) - limdiag1_gg = max(conversions.mass2_from_mchirp_mass1(mcs, lims1_gg), - ns_max) - limdiag2_gg = min(conversions.mass2_from_mchirp_mass1(mcb, limb1_gg), - gap_max) + limdiag1_gg = max(m2mcm1(mcs, lims1_gg), ns_max) + limdiag2_gg = min(m2mcm1(mcb, limb1_gg), gap_max) intline_sup_gg = (0.5 * (limb1_gg - lims1_gg) * (limdiag1_gg + limdiag2_gg)) intline_inf_gg = (limb2_gg - lims2_gg) * ns_max @@ -150,15 +145,14 @@ def calc_areas(trig_mc_det, mass_limits, mass_bdary, z): agg = int_sup_gg - int_inf_gg # AREA FOR BNS - if conversions.mass2_from_mchirp_mass1(mcs, ns_max) > ns_max: + if m2mcm1(mcs, ns_max) > ns_max: abns = 0.0 else: - if conversions.mass2_from_mchirp_mass1(mcb, ns_max) > ns_max: + if m2mcm1(mcb, ns_max) > ns_max: limb2_bns = ns_max limb1_bns = limb2_bns else: - limb2_bns = min(ns_max, - conversions.mass2_from_mchirp_mass1(mcb, m2_min)) + limb2_bns = min(ns_max, m2mcm1(mcb, m2_min)) limb1_bns = mib intb_bns = intmc(mcb, limb1_bns, limb2_bns) @@ -167,16 +161,13 @@ def calc_areas(trig_mc_det, mass_limits, mass_bdary, z): lims2_bns = m2_min lims1_bns = lims2_bns else: - lims2_bns = min(ns_max, - conversions.mass2_from_mchirp_mass1(mcs, m2_min)) + lims2_bns = min(ns_max, m2mcm1(mcs, m2_min)) lims1_bns = mis ints_bns = intmc(mcs, lims1_bns, lims2_bns) intline_inf_bns = (limb2_bns - lims2_bns) * m2_min - limdiag1_bns = max(conversions.mass2_from_mchirp_mass1(mcs, lims1_bns), - m2_min) - limdiag2_bns = min(conversions.mass2_from_mchirp_mass1(mcb, limb1_bns), - ns_max) + limdiag1_bns = max(m2mcm1(mcs, lims1_bns), m2_min) + limdiag2_bns = min(m2mcm1(mcb, limb1_bns), ns_max) intline_sup_bns = (0.5 * (limdiag1_bns + limdiag2_bns) * (limb1_bns - lims1_bns)) int_sup_bns = intb_bns + intline_sup_bns @@ -185,29 +176,24 @@ def calc_areas(trig_mc_det, mass_limits, mass_bdary, z): abns = int_sup_bns - int_inf_bns # AREA FOR GNS - if (conversions.mass2_from_mchirp_mass1(mcs, gap_max) > ns_max or - conversions.mass2_from_mchirp_mass1(mcb, ns_max) < m2_min): + if m2mcm1(mcs, gap_max) > ns_max or m2mcm1(mcb, ns_max) < m2_min: agns = 0.0 else: - if conversions.mass2_from_mchirp_mass1(mcb, gap_max) > ns_max: + if m2mcm1(mcb, gap_max) > ns_max: limb2_gns = gap_max limb1_gns = limb2_gns else: - limb2_gns = min(gap_max, - conversions.mass2_from_mchirp_mass1(mcb, m2_min)) - limb1_gns = max(ns_max, - conversions.mass2_from_mchirp_mass1(mcb, ns_max)) + limb2_gns = min(gap_max, m2mcm1(mcb, m2_min)) + limb1_gns = max(ns_max, m2mcm1(mcb, ns_max)) intb_gns = intmc(mcb, limb1_gns, limb2_gns) - if conversions.mass2_from_mchirp_mass1(mcs, ns_max) < m2_min: + if m2mcm1(mcs, ns_max) < m2_min: lims2_gns = ns_max lims1_gns = lims2_gns else: - lims1_gns = max(ns_max, - conversions.mass2_from_mchirp_mass1(mcs, ns_max)) - lims2_gns = min(gap_max, - conversions.mass2_from_mchirp_mass1(mcs, m2_min)) + lims1_gns = max(ns_max, m2mcm1(mcs, ns_max)) + lims2_gns = min(gap_max, m2mcm1(mcs, m2_min)) intline_inf_gns = (limb2_gns - lims2_gns) * m2_min intline_sup_gns = (limb1_gns - lims1_gns) * ns_max @@ -218,29 +204,24 @@ def calc_areas(trig_mc_det, mass_limits, mass_bdary, z): agns = int_sup_gns - int_inf_gns # AREA FOR NSBH - if (conversions.mass2_from_mchirp_mass1(mcs, m1_max) > ns_max or - conversions.mass2_from_mchirp_mass1(mcb, gap_max) < m2_min): + if m2mcm1(mcs, m1_max) > ns_max or m2mcm1(mcb, gap_max) < m2_min): ansbh = 0.0 else: - if conversions.mass2_from_mchirp_mass1(mcb, m1_max) > ns_max: + if m2mcm1(mcb, m1_max) > ns_max: limb2_nsbh = m1_max limb1_nsbh = limb2_nsbh else: - limb1_nsbh = max(gap_max, - conversions.mass2_from_mchirp_mass1(mcb, ns_max)) - limb2_nsbh = min(m1_max, - conversions.mass2_from_mchirp_mass1(mcb, m2_min)) + limb1_nsbh = max(gap_max, m2mcm1(mcb, ns_max)) + limb2_nsbh = min(m1_max, m2mcm1(mcb, m2_min)) intb_nsbh = intmc(mcb, limb1_nsbh, limb2_nsbh) - if conversions.mass2_from_mchirp_mass1(mcs, gap_max) < m2_min: + if m2mcm1(mcs, gap_max) < m2_min: lims1_nsbh = gap_max lims2_nsbh = lims1_nsbh else: - lims1_nsbh = max(gap_max, - conversions.mass2_from_mchirp_mass1(mcs, ns_max)) - lims2_nsbh = min(m1_max, - conversions.mass2_from_mchirp_mass1(mcs, m2_min)) + lims1_nsbh = max(gap_max, m2mcm1(mcs, ns_max)) + lims2_nsbh = min(m1_max, m2mcm1(mcs, m2_min)) intline_inf_nsbh = (limb2_nsbh - lims2_nsbh) * m2_min intline_sup_nsbh = (limb1_nsbh - lims1_nsbh) * ns_max From 526459b210b26e4c5a81235e41e4a5fbe5e5e866 Mon Sep 17 00:00:00 2001 From: veronica-villa <51956991+veronica-villa@users.noreply.github.com> Date: Thu, 3 Oct 2019 19:08:15 +0200 Subject: [PATCH 19/31] Solving codeclimate issues --- pycbc/mchirp_area.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pycbc/mchirp_area.py b/pycbc/mchirp_area.py index 918527c3169..96b73788f67 100644 --- a/pycbc/mchirp_area.py +++ b/pycbc/mchirp_area.py @@ -204,7 +204,7 @@ def calc_areas(trig_mc_det, mass_limits, mass_bdary, z): agns = int_sup_gns - int_inf_gns # AREA FOR NSBH - if m2mcm1(mcs, m1_max) > ns_max or m2mcm1(mcb, gap_max) < m2_min): + if m2mcm1(mcs, m1_max) > ns_max or m2mcm1(mcb, gap_max) < m2_min: ansbh = 0.0 else: if m2mcm1(mcb, m1_max) > ns_max: From 2bc2533488f8d705ed55b20a58dff54cbbba0445 Mon Sep 17 00:00:00 2001 From: veronica-villa <51956991+veronica-villa@users.noreply.github.com> Date: Thu, 3 Oct 2019 19:14:33 +0200 Subject: [PATCH 20/31] Solving codeclimate issue --- pycbc/mchirp_area.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pycbc/mchirp_area.py b/pycbc/mchirp_area.py index 96b73788f67..b70e4ab0bd6 100644 --- a/pycbc/mchirp_area.py +++ b/pycbc/mchirp_area.py @@ -25,6 +25,7 @@ def src_mass_from_z_det_mass(z, del_z, mdet, del_mdet): del_msrc = msrc * ((del_mdet/mdet)**2 + (del_z/(1 + z))**2)**(0.5) return (msrc, del_msrc) + # Integration function def mchange(x, mc): """This function returns a component mass as a function of mchirp and From a8afe47d66ae1444e4fd1e2944532dc2c0628c83 Mon Sep 17 00:00:00 2001 From: veronica-villa <51956991+veronica-villa@users.noreply.github.com> Date: Fri, 4 Oct 2019 11:25:52 +0200 Subject: [PATCH 21/31] Rename mass_area_plot.py to mass_area_plot --- bin/plotting/{mass_area_plot.py => mass_area_plot} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename bin/plotting/{mass_area_plot.py => mass_area_plot} (94%) diff --git a/bin/plotting/mass_area_plot.py b/bin/plotting/mass_area_plot similarity index 94% rename from bin/plotting/mass_area_plot.py rename to bin/plotting/mass_area_plot index 76ca990e224..21f6dc75103 100644 --- a/bin/plotting/mass_area_plot.py +++ b/bin/plotting/mass_area_plot @@ -112,6 +112,6 @@ pyplot.xlabel("M1") pyplot.ylabel("M2") -pyplot.title("MChirp = " + str((0.5) * (mcb + mcs)) + " +/- " - + str((mcb - mcs) * (0.5))) +pyplot.title("MChirp = " + str(0.5 * (mcb + mcs)) + " +/- " + + str((mcb - mcs) * 0.5)) pyplot.savefig("mass_plot.png") From 1bdae0568d8740461ce756ff801b3ee461164de1 Mon Sep 17 00:00:00 2001 From: veronica-villa <51956991+veronica-villa@users.noreply.github.com> Date: Fri, 4 Oct 2019 12:37:02 +0200 Subject: [PATCH 22/31] Rename mass_area_plot to pycbc_mass_area_plot Also aliased some modules --- .../{mass_area_plot => pycbc_mass_area_plot} | 38 ++++++++----------- 1 file changed, 15 insertions(+), 23 deletions(-) rename bin/plotting/{mass_area_plot => pycbc_mass_area_plot} (74%) diff --git a/bin/plotting/mass_area_plot b/bin/plotting/pycbc_mass_area_plot similarity index 74% rename from bin/plotting/mass_area_plot rename to bin/plotting/pycbc_mass_area_plot index 21f6dc75103..55101296005 100644 --- a/bin/plotting/mass_area_plot +++ b/bin/plotting/pycbc_mass_area_plot @@ -1,20 +1,17 @@ #!/usr/bin/env python -"""mass_area_plot.py +# +# Integration of the area laying in the different cbc regions +# By A. Curiel Barroso +# August 2019 -Integration of the area laying in the different cbc regions -By A. Curiel Barroso -August 2019 - --------------------------------------------- -This script computes the area corresponding -to different CBC on the m1 & m2 plane when -given a central mchirp value and uncertainty --------------------------------------------- +"""This script computes the area corresponding to different CBC on +the m1 & m2 plane when given a central mchirp value and uncertainty. """ + import argparse from mchirp_area import calc_areas from mchirp_area import src_mass_from_z_det_mass -from pycbc import conversions +from pycbc.conversions import mass2_from_mchirp_mass1 as m2mcm1 import numpy from matplotlib import use; use("Agg") from matplotlib import pyplot @@ -78,25 +75,20 @@ mcs = src_mchirp[0] - src_mchirp[1] mib = (2**0.2)*mcb mis = (2**0.2)*mcs -lim_m1b = min(m1_max, conversions.mass2_from_mchirp_mass1(mcb, m2_min)) +lim_m1b = min(m1_max, m2mcm1(mcb, m2_min)) m1b = numpy.linspace(mib, lim_m1b, num=100) -m2b = conversions.mass2_from_mchirp_mass1(mcb, m1b) +m2b = m2mcm1(mcb, m1b) -lim_m1s = min(m1_max, conversions.mass2_from_mchirp_mass1(mcs, m2_min)) +lim_m1s = min(m1_max, m2mcm1(mcs, m2_min)) m1s = numpy.linspace(mis, lim_m1s, num=100) -m2s = conversions.mass2_from_mchirp_mass1(mcs, m1s) +m2s = m2mcm1(mcs, m1s) if mib > m1_max: - pyplot.plot( - (m1_max, m1_max), - (conversions.mass2_from_mchirp_mass1(mcs, lim_m1s), m1_max), - "b") + pyplot.plot((m1_max, m1_max), (m2mcm1(mcs, lim_m1s), m1_max), "b") else: pyplot.plot(m1b, m2b, "b") - pyplot.plot( - (m1_max, m1_max), - (conversions.mass2_from_mchirp_mass1(mcs, lim_m1s), - conversions.mass2_from_mchirp_mass1(mcb, lim_m1b)), "b") + pyplot.plot((m1_max, m1_max), (m2mcm1(mcs, lim_m1s), + m2mcm1(mcb, lim_m1b)),"b") if mis >= m2_min: pyplot.plot(m1s, m2s, "b") From b0491382632cbb50f5b3a829f52e457f3cd6668b Mon Sep 17 00:00:00 2001 From: veronica-villa <51956991+veronica-villa@users.noreply.github.com> Date: Fri, 4 Oct 2019 12:41:52 +0200 Subject: [PATCH 23/31] Rename mchirp_plots.py as pycbc_mchirp_plots --- .../{mchirp_plots.py => pycbc_mchirp_plots} | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) rename bin/plotting/{mchirp_plots.py => pycbc_mchirp_plots} (85%) diff --git a/bin/plotting/mchirp_plots.py b/bin/plotting/pycbc_mchirp_plots similarity index 85% rename from bin/plotting/mchirp_plots.py rename to bin/plotting/pycbc_mchirp_plots index 17e7a275cd8..24b1b590e1c 100644 --- a/bin/plotting/mchirp_plots.py +++ b/bin/plotting/pycbc_mchirp_plots @@ -1,15 +1,11 @@ #!/usr/bin/env python -"""chirp_plots.py +# +# Integration of the area laying in the different cbc regions +# By A. Curiel Barroso +# August 2019 -Integration of the area laying in the different cbc regions -By A. Curiel Barroso -August 2019 - --------------------------------------------- -This script computes the area corresponding -to different CBC on the m1 & m2 plane as a -function of central mchirp value --------------------------------------------- +"""This script computes the area corresponding to different CBC on the m1 & m2 +plane as a function of central mchirp value. """ import argparse from mchirp_area import calc_areas From 072a6d05ba0cd8a44a6bf0e9680c59ea99260937 Mon Sep 17 00:00:00 2001 From: veronica-villa <51956991+veronica-villa@users.noreply.github.com> Date: Fri, 4 Oct 2019 12:57:01 +0200 Subject: [PATCH 24/31] Change equations spacing --- pycbc/mchirp_area.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/pycbc/mchirp_area.py b/pycbc/mchirp_area.py index b70e4ab0bd6..e13fd8531c1 100644 --- a/pycbc/mchirp_area.py +++ b/pycbc/mchirp_area.py @@ -1,15 +1,13 @@ #!/usr/bin/env python -# mchirp_area.py +# # Integration of the area laying in the different cbc regions # By A. Curiel Barroso # August 2019 -"""This script computes the area corresponding -to different CBC on the m1 & m2 plane when -given a central mchirp value and uncertainty -It also includes a function that calculates -the source frame when given the detector -frame mass and redshift +"""This script computes the area corresponding to different CBC on the m1 & m2 +plane when given a central mchirp value and uncertainty. +It also includes a function that calculates the source frame when given the +detector frame mass and redshift. """ from pycbc.conversions import mass2_from_mchirp_mass1 as m2mcm1 @@ -21,8 +19,9 @@ def src_mass_from_z_det_mass(z, del_z, mdet, del_mdet): detector mass and its uncertainty and computes the source mass and its uncertainty. """ - msrc = (mdet) / (1 + z) - del_msrc = msrc * ((del_mdet/mdet)**2 + (del_z/(1 + z))**2)**(0.5) + msrc = mdet / (1. + z) + del_msrc = msrc * ((del_mdet / mdet) ** 2. + + (del_z / (1. + z)) ** 2.) ** 0.5 return (msrc, del_msrc) @@ -59,8 +58,8 @@ def calc_areas(trig_mc_det, mass_limits, mass_bdary, z): gap_max = mass_bdary["gap_max"] # The points where the equal mass line and a chirp mass # curve intersect is m1 = m2 = 2**0.2 * mchirp - mib = (2**0.2) * mcb - mis = (2**0.2) * mcs + mib = (2.**0.2) * mcb + mis = (2.**0.2) * mcs # AREA FOR BBH if mib < gap_max: From 7cf8cb11643d00625e88e9af7197256237d52046 Mon Sep 17 00:00:00 2001 From: veronica-villa <51956991+veronica-villa@users.noreply.github.com> Date: Fri, 4 Oct 2019 15:42:23 +0200 Subject: [PATCH 25/31] Edit docstrings --- pycbc/mchirp_area.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/pycbc/mchirp_area.py b/pycbc/mchirp_area.py index e13fd8531c1..6635c1f12e0 100644 --- a/pycbc/mchirp_area.py +++ b/pycbc/mchirp_area.py @@ -1,10 +1,8 @@ -#!/usr/bin/env python -# # Integration of the area laying in the different cbc regions # By A. Curiel Barroso # August 2019 -"""This script computes the area corresponding to different CBC on the m1 & m2 +"""Functions to compute the area corresponding to different CBC on the m1 & m2 plane when given a central mchirp value and uncertainty. It also includes a function that calculates the source frame when given the detector frame mass and redshift. @@ -15,9 +13,8 @@ def src_mass_from_z_det_mass(z, del_z, mdet, del_mdet): - """This function takes values of redshift, redshift uncertainty, - detector mass and its uncertainty and computes the source mass - and its uncertainty. + """Takes values of redshift, redshift uncertainty, detector mass and its + uncertainty and computes the source mass and its uncertainty. """ msrc = mdet / (1. + z) del_msrc = msrc * ((del_mdet / mdet) ** 2. @@ -27,23 +24,23 @@ def src_mass_from_z_det_mass(z, del_z, mdet, del_mdet): # Integration function def mchange(x, mc): - """This function returns a component mass as a function of mchirp and - the other component mass. + """Returns a component mass as a function of mchirp and the other + component mass. """ return m2mcm1(mc, x) def intmc(mc, x_min, x_max): - """This function returns the integral of mchange between the minimum and - maximum values of a component mass taking mchirp as an argument. + """Returns the integral of mchange between the minimum and maximum values + of a component mass taking mchirp as an argument. """ integral = quad(mchange, x_min, x_max, args=mc) return integral[0] def calc_areas(trig_mc_det, mass_limits, mass_bdary, z): - """This function computes the area inside the lines of the second component - mass as a function of the first component mass for the two extreme values + """Computes the area inside the lines of the second component mass as a + function of the first component mass for the two extreme values of mchirp: mchirp +/- mchirp_uncertainty, for each region of the source classifying diagram. """ From 3ee168d4ed4e271e93dc89c337eeace9df70ff82 Mon Sep 17 00:00:00 2001 From: veronica-villa <51956991+veronica-villa@users.noreply.github.com> Date: Fri, 4 Oct 2019 15:53:27 +0200 Subject: [PATCH 26/31] Fixing Travis issues From 5a9a04310d0844fa2c33f62fbeb2ea89b3f32d7d Mon Sep 17 00:00:00 2001 From: veronica-villa <51956991+veronica-villa@users.noreply.github.com> Date: Fri, 4 Oct 2019 18:15:10 +0200 Subject: [PATCH 27/31] Delete pycbc_mass_area_plot --- bin/plotting/pycbc_mass_area_plot | 109 ------------------------------ 1 file changed, 109 deletions(-) delete mode 100644 bin/plotting/pycbc_mass_area_plot diff --git a/bin/plotting/pycbc_mass_area_plot b/bin/plotting/pycbc_mass_area_plot deleted file mode 100644 index 55101296005..00000000000 --- a/bin/plotting/pycbc_mass_area_plot +++ /dev/null @@ -1,109 +0,0 @@ -#!/usr/bin/env python -# -# Integration of the area laying in the different cbc regions -# By A. Curiel Barroso -# August 2019 - -"""This script computes the area corresponding to different CBC on -the m1 & m2 plane when given a central mchirp value and uncertainty. -""" - -import argparse -from mchirp_area import calc_areas -from mchirp_area import src_mass_from_z_det_mass -from pycbc.conversions import mass2_from_mchirp_mass1 as m2mcm1 -import numpy -from matplotlib import use; use("Agg") -from matplotlib import pyplot - -# ARGUMENT PARSER -parser = argparse.ArgumentParser() -parser.add_argument("--central-mc", type=float, help="Central value of mchirp") -parser.add_argument("--delta-mc", type=float, help="Uncertainty for mchirp") -parser.add_argument("--min-m2", type=float, help="Minimum value for m2") -parser.add_argument("--max-m1", type=float, help="Maximum value for m1") -parser.add_argument("--central-z", type=float, help="Central redshift value") -parser.add_argument("--delta-z", type=float, help="Redshift uncertainty") -parser.add_argument("--ns-max", type=float, help="Maximum neutron star mass") -parser.add_argument("--gap-max", type=float, help="Minimum black hole mass") - -args = parser.parse_args() - -if args.central_mc and args.delta_mc: - central_mc = float(args.central_mc) - delta_mc = float(args.delta_mc) - -if args.min_m2 and args.max_m1: - m2_min = float(args.min_m2) - m1_max = float(args.max_m1) - -if args.min_m2 and args.max_m1: - ns_max = float(args.ns_max) - gap_max = float(args.gap_max) - -if args.central_z and args.delta_z: - central_z = float(args.central_z) - delta_z = float(args.delta_z) -else: - central_z = 0.0 - delta_z = 0.0 - -mass_limits = {"max_m1": m1_max, "min_m2": m2_min} -mass_bdary = {"ns_max": ns_max, "gap_max": gap_max} -z = {"central": central_z, "delta": delta_z} -trig_mc = {"central": central_mc, "delta": delta_mc} - -areas = calc_areas(trig_mc, mass_limits, mass_bdary, z) - -print("abbh = " + str(areas["bbh"])) -print("abhg = " + str(areas["bhg"])) -print("agg = " + str(areas["gg"])) -print("ansbh = " + str(areas["nsbh"])) -print("agns = " + str(areas["gns"])) -print("abns = " + str(areas["bns"])) - -# PLOT GENERATION -src_mchirp = src_mass_from_z_det_mass(central_z, delta_z, - central_mc, delta_mc) - -mcb = src_mchirp[0] + src_mchirp[1] -mcs = src_mchirp[0] - src_mchirp[1] - -# The points where the equal mass line and a chirp mass -# curve intersect is m1 = m2 = (2**0.2)*mchirp - -mib = (2**0.2)*mcb -mis = (2**0.2)*mcs - -lim_m1b = min(m1_max, m2mcm1(mcb, m2_min)) -m1b = numpy.linspace(mib, lim_m1b, num=100) -m2b = m2mcm1(mcb, m1b) - -lim_m1s = min(m1_max, m2mcm1(mcs, m2_min)) -m1s = numpy.linspace(mis, lim_m1s, num=100) -m2s = m2mcm1(mcs, m1s) - -if mib > m1_max: - pyplot.plot((m1_max, m1_max), (m2mcm1(mcs, lim_m1s), m1_max), "b") -else: - pyplot.plot(m1b, m2b, "b") - pyplot.plot((m1_max, m1_max), (m2mcm1(mcs, lim_m1s), - m2mcm1(mcb, lim_m1b)),"b") - -if mis >= m2_min: - pyplot.plot(m1s, m2s, "b") - pyplot.plot((lim_m1s, lim_m1b), (m2_min, m2_min), "b") -else: - pyplot.plot((m2_min, lim_m1b), (m2_min, m2_min), "b") - -pyplot.plot((m2_min, m1_max), (m2_min, m1_max), "k--") -pyplot.plot((ns_max, ns_max), (m2_min, ns_max), "k:") -pyplot.plot((gap_max, gap_max), (m2_min, gap_max), "k:") -pyplot.plot((ns_max, m1_max), (ns_max, ns_max), "k:") -pyplot.plot((gap_max, m1_max), (gap_max, gap_max), "k:") - -pyplot.xlabel("M1") -pyplot.ylabel("M2") -pyplot.title("MChirp = " + str(0.5 * (mcb + mcs)) + " +/- " - + str((mcb - mcs) * 0.5)) -pyplot.savefig("mass_plot.png") From 43a492b8c439c43a2f2093619d04be624ffbf7c3 Mon Sep 17 00:00:00 2001 From: veronica-villa <51956991+veronica-villa@users.noreply.github.com> Date: Fri, 4 Oct 2019 18:15:49 +0200 Subject: [PATCH 28/31] Add pycbc_mass_area_plot --- bin/plotting/pycbc_mass_area_plot | 109 ++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 bin/plotting/pycbc_mass_area_plot diff --git a/bin/plotting/pycbc_mass_area_plot b/bin/plotting/pycbc_mass_area_plot new file mode 100644 index 00000000000..ba6b9f0ab42 --- /dev/null +++ b/bin/plotting/pycbc_mass_area_plot @@ -0,0 +1,109 @@ +#!/usr/bin/env python +# +# Integration of the area laying in the different cbc regions +# By A. Curiel Barroso +# August 2019 + +"""This script computes the area corresponding to different CBC on +the m1 & m2 plane when given a central mchirp value and uncertainty. +""" + +import argparse +from mchirp_area import calc_areas +from mchirp_area import src_mass_from_z_det_mass +from pycbc.conversions import mass2_from_mchirp_mass1 as m2mcm1 +import numpy +from matplotlib import use; use("Agg") +from matplotlib import pyplot + +# ARGUMENT PARSER +parser = argparse.ArgumentParser() +parser.add_argument("--central-mc", type=float, help="Central value of mchirp") +parser.add_argument("--delta-mc", type=float, help="Uncertainty for mchirp") +parser.add_argument("--min-m2", type=float, help="Minimum value for m2") +parser.add_argument("--max-m1", type=float, help="Maximum value for m1") +parser.add_argument("--central-z", type=float, help="Central redshift value") +parser.add_argument("--delta-z", type=float, help="Redshift uncertainty") +parser.add_argument("--ns-max", type=float, help="Maximum neutron star mass") +parser.add_argument("--gap-max", type=float, help="Minimum black hole mass") + +args = parser.parse_args() + +if args.central_mc and args.delta_mc: + central_mc = float(args.central_mc) + delta_mc = float(args.delta_mc) + +if args.min_m2 and args.max_m1: + m2_min = float(args.min_m2) + m1_max = float(args.max_m1) + +if args.min_m2 and args.max_m1: + ns_max = float(args.ns_max) + gap_max = float(args.gap_max) + +if args.central_z and args.delta_z: + central_z = float(args.central_z) + delta_z = float(args.delta_z) +else: + central_z = 0.0 + delta_z = 0.0 + +mass_limits = {"max_m1": m1_max, "min_m2": m2_min} +mass_bdary = {"ns_max": ns_max, "gap_max": gap_max} +z = {"central": central_z, "delta": delta_z} +trig_mc = {"central": central_mc, "delta": delta_mc} + +areas = calc_areas(trig_mc, mass_limits, mass_bdary, z) + +print("abbh = " + str(areas["bbh"])) +print("abhg = " + str(areas["bhg"])) +print("agg = " + str(areas["gg"])) +print("ansbh = " + str(areas["nsbh"])) +print("agns = " + str(areas["gns"])) +print("abns = " + str(areas["bns"])) + +# PLOT GENERATION +src_mchirp = src_mass_from_z_det_mass(central_z, delta_z, + central_mc, delta_mc) + +mcb = src_mchirp[0] + src_mchirp[1] +mcs = src_mchirp[0] - src_mchirp[1] + +# The points where the equal mass line and a chirp mass +# curve intersect is m1 = m2 = (2**0.2)*mchirp + +mib = (2**0.2)*mcb +mis = (2**0.2)*mcs + +lim_m1b = min(m1_max, m2mcm1(mcb, m2_min)) +m1b = numpy.linspace(mib, lim_m1b, num=100) +m2b = m2mcm1(mcb, m1b) + +lim_m1s = min(m1_max, m2mcm1(mcs, m2_min)) +m1s = numpy.linspace(mis, lim_m1s, num=100) +m2s = m2mcm1(mcs, m1s) + +if mib > m1_max: + pyplot.plot((m1_max, m1_max), (m2mcm1(mcs, lim_m1s), m1_max), "b") +else: + pyplot.plot(m1b, m2b, "b") + pyplot.plot((m1_max, m1_max), (m2mcm1(mcs, lim_m1s), + m2mcm1(mcb, lim_m1b)),"b") + +if mis >= m2_min: + pyplot.plot(m1s, m2s, "b") + pyplot.plot((lim_m1s, lim_m1b), (m2_min, m2_min), "b") +else: + pyplot.plot((m2_min, lim_m1b), (m2_min, m2_min), "b") + +pyplot.plot((m2_min, m1_max), (m2_min, m1_max), "k--") +pyplot.plot((ns_max, ns_max), (m2_min, ns_max), "k:") +pyplot.plot((gap_max, gap_max), (m2_min, gap_max), "k:") +pyplot.plot((ns_max, m1_max), (ns_max, ns_max), "k:") +pyplot.plot((gap_max, m1_max), (gap_max, gap_max), "k:") + +pyplot.xlabel("M1") +pyplot.ylabel("M2") +pyplot.title("MChirp = " + str(0.5 * (mcb + mcs)) + " +/- " + + str((mcb - mcs) * 0.5)) +pyplot.savefig("mass_plot.png") From 016aeaa0d65c6774fe51cff83ca5b80e41a36674 Mon Sep 17 00:00:00 2001 From: veronica-villa <51956991+veronica-villa@users.noreply.github.com> Date: Mon, 7 Oct 2019 18:01:56 +0200 Subject: [PATCH 29/31] Change some imports --- bin/plotting/pycbc_mass_area_plot | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/plotting/pycbc_mass_area_plot b/bin/plotting/pycbc_mass_area_plot index ba6b9f0ab42..80495f45f97 100644 --- a/bin/plotting/pycbc_mass_area_plot +++ b/bin/plotting/pycbc_mass_area_plot @@ -9,8 +9,8 @@ the m1 & m2 plane when given a central mchirp value and uncertainty. """ import argparse -from mchirp_area import calc_areas -from mchirp_area import src_mass_from_z_det_mass +from pycbc.mchirp_area import calc_areas +from pycbc.mchirp_area import src_mass_from_z_det_mass from pycbc.conversions import mass2_from_mchirp_mass1 as m2mcm1 import numpy from matplotlib import use; use("Agg") From 3a151e1d2b6c215d495a765091f7ef9ff5b0e695 Mon Sep 17 00:00:00 2001 From: veronica-villa <51956991+veronica-villa@users.noreply.github.com> Date: Mon, 7 Oct 2019 18:32:15 +0200 Subject: [PATCH 30/31] Delete pycbc_mchirp_plots --- bin/plotting/pycbc_mchirp_plots | 80 --------------------------------- 1 file changed, 80 deletions(-) delete mode 100644 bin/plotting/pycbc_mchirp_plots diff --git a/bin/plotting/pycbc_mchirp_plots b/bin/plotting/pycbc_mchirp_plots deleted file mode 100644 index 24b1b590e1c..00000000000 --- a/bin/plotting/pycbc_mchirp_plots +++ /dev/null @@ -1,80 +0,0 @@ -#!/usr/bin/env python -# -# Integration of the area laying in the different cbc regions -# By A. Curiel Barroso -# August 2019 - -"""This script computes the area corresponding to different CBC on the m1 & m2 -plane as a function of central mchirp value. -""" -import argparse -from mchirp_area import calc_areas -import numpy -from matplotlib import use; use("Agg") -from matplotlib import pyplot - -# ARGUMENT PARSER -parser = argparse.ArgumentParser() -parser.add_argument("--min-m2", type=float, help="Minimum value for m2") -parser.add_argument("--max-m1", type=float, help="Maximum value for m1") -parser.add_argument("--ns-max", type=float, help="Maximum neutron star mass") -parser.add_argument("--gap-max", type=float, help="Minimum black hole mass") -parser.add_argument("--central-z", type=float, help="Central redshift value") -parser.add_argument("--delta-z", type=float, help="Redshift uncertainty") -args = parser.parse_args() - -if args.min_m2 and args.max_m1: - m1_max = float(args.max_m1) - m2_min = float(args.min_m2) - -if args.min_m2 and args.max_m1: - ns_max = float(args.ns_max) - gap_max = float(args.gap_max) - -if args.central_z and args.delta_z: - central_z = float(args.central_z) - delta_z = float(args.delta_z) -else: - central_z = 0.0 - delta_z = 0.0 - -mass_limits = {"max_m1": m1_max, "min_m2": m2_min} -mass_bdary = {"ns_max": ns_max, "gap_max": gap_max} -z = {"central": central_z, "delta": delta_z} -n = 1000 - -x_mc = numpy.zeros(n, float) -y_abbh = numpy.zeros(n, float) -y_abhg = numpy.zeros(n, float) -y_agg = numpy.zeros(n, float) -y_ansbh = numpy.zeros(n, float) -y_agns = numpy.zeros(n, float) -y_abns = numpy.zeros(n, float) - -for i in range(0, n): - central_mc = 0.8 + i*(10.0 - 0.8)/(n - 1) - delta_mc = central_mc * 0.01 - trig_mc = {"central": central_mc, "delta": delta_mc} - x_mc[i] = central_mc - areas = calc_areas(trig_mc, mass_limits, mass_bdary, z) - y_abbh[i] = areas["bbh"] - y_abhg[i] = areas["bhg"] - y_agg[i] = areas["gg"] - y_ansbh[i] = areas["nsbh"] - y_agns[i] = areas["gns"] - y_abns[i] = areas["bns"] - -pyplot.plot(x_mc, y_abbh, label="Binary Black Hole") -pyplot.plot(x_mc, y_abhg, label="Black Hole + Mass Gap Object") -pyplot.plot(x_mc, y_agg, label="Binary Mass Gap Object") -pyplot.plot(x_mc, y_ansbh, label="Neutron Star + Black Hole") -pyplot.plot(x_mc, y_agns, label="Neutron Star + Mass Gap Object") -pyplot.plot(x_mc, y_abns, label="Binary Neutron Star") - -pyplot.legend() -pyplot.xlabel("Central MChirp (Solar Masses)") -pyplot.ylabel("Area (Solar Masses Squared)") -pyplot.yscale("log") -pyplot.title("Area vs MChirp (1% uncertainty)") - -pyplot.savefig("mchirp_plot.png") From 3865f82c26fc2d2f379b2575331a39f0a63caf66 Mon Sep 17 00:00:00 2001 From: veronica-villa <51956991+veronica-villa@users.noreply.github.com> Date: Mon, 7 Oct 2019 18:33:39 +0200 Subject: [PATCH 31/31] Add pycbc_mchirp_plots --- bin/plotting/pycbc_mchirp_plots | 81 +++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 bin/plotting/pycbc_mchirp_plots diff --git a/bin/plotting/pycbc_mchirp_plots b/bin/plotting/pycbc_mchirp_plots new file mode 100644 index 00000000000..2b19bbad13e --- /dev/null +++ b/bin/plotting/pycbc_mchirp_plots @@ -0,0 +1,81 @@ +#!/usr/bin/env python +# +# Integration of the area laying in the different cbc regions +# By A. Curiel Barroso +# August 2019 + +"""This script computes the area corresponding to different CBC on the m1 & m2 +plane as a function of central mchirp value. +""" + +import argparse +from pycbc.mchirp_area import calc_areas +import numpy +from matplotlib import use; use("Agg") +from matplotlib import pyplot + +# ARGUMENT PARSER +parser = argparse.ArgumentParser() +parser.add_argument("--min-m2", type=float, help="Minimum value for m2") +parser.add_argument("--max-m1", type=float, help="Maximum value for m1") +parser.add_argument("--ns-max", type=float, help="Maximum neutron star mass") +parser.add_argument("--gap-max", type=float, help="Minimum black hole mass") +parser.add_argument("--central-z", type=float, help="Central redshift value") +parser.add_argument("--delta-z", type=float, help="Redshift uncertainty") +args = parser.parse_args() + +if args.min_m2 and args.max_m1: + m1_max = float(args.max_m1) + m2_min = float(args.min_m2) + +if args.min_m2 and args.max_m1: + ns_max = float(args.ns_max) + gap_max = float(args.gap_max) + +if args.central_z and args.delta_z: + central_z = float(args.central_z) + delta_z = float(args.delta_z) +else: + central_z = 0.0 + delta_z = 0.0 + +mass_limits = {"max_m1": m1_max, "min_m2": m2_min} +mass_bdary = {"ns_max": ns_max, "gap_max": gap_max} +z = {"central": central_z, "delta": delta_z} +n = 1000 + +x_mc = numpy.zeros(n, float) +y_abbh = numpy.zeros(n, float) +y_abhg = numpy.zeros(n, float) +y_agg = numpy.zeros(n, float) +y_ansbh = numpy.zeros(n, float) +y_agns = numpy.zeros(n, float) +y_abns = numpy.zeros(n, float) + +for i in range(0, n): + central_mc = 0.8 + i*(10.0 - 0.8)/(n - 1) + delta_mc = central_mc * 0.01 + trig_mc = {"central": central_mc, "delta": delta_mc} + x_mc[i] = central_mc + areas = calc_areas(trig_mc, mass_limits, mass_bdary, z) + y_abbh[i] = areas["bbh"] + y_abhg[i] = areas["bhg"] + y_agg[i] = areas["gg"] + y_ansbh[i] = areas["nsbh"] + y_agns[i] = areas["gns"] + y_abns[i] = areas["bns"] + +pyplot.plot(x_mc, y_abbh, label="Binary Black Hole") +pyplot.plot(x_mc, y_abhg, label="Black Hole + Mass Gap Object") +pyplot.plot(x_mc, y_agg, label="Binary Mass Gap Object") +pyplot.plot(x_mc, y_ansbh, label="Neutron Star + Black Hole") +pyplot.plot(x_mc, y_agns, label="Neutron Star + Mass Gap Object") +pyplot.plot(x_mc, y_abns, label="Binary Neutron Star") + +pyplot.legend() +pyplot.xlabel("Central MChirp (Solar Masses)") +pyplot.ylabel("Area (Solar Masses Squared)") +pyplot.yscale("log") +pyplot.title("Area vs MChirp (1% uncertainty)") + +pyplot.savefig("mchirp_plot.png")