예제 #1
0
def plot_rates(rates):
    """Plot detection rates for askap surveys."""
    plot_aa_style()

    fig, (ax1) = plt.subplots(1, 1)
    cmap = plt.get_cmap('tab10')
    ax1.set_xlim((min(ALPHAS) + .1, max(ALPHAS) - .1))
    ax1.set_yscale('log', nonposy='mask')

    # Plot complex versus toy
    for i, surv in enumerate(SURVEYS):
        ax1.plot(ALPHAS,
                 rates[surv],
                 color=cmap(i + 1),
                 label=surv,
                 linestyle='dashed')

    # Plot layout options
    # Set up axes
    ax1.set_xlabel(r'$\alpha$')
    ax1.invert_xaxis()
    ax1.set_ylabel('Events / htru')

    plt.legend()
    plt.savefig(rel_path('plots/askap_rates.pdf'), bbox_inches='tight')
예제 #2
0
def main():
    """Plot expected complex rates."""
    plot_aa_style()

    rates = complex_rates()
    for surv in rates:
        rate = rates[surv]
        plt.plot(ALPHAS, rate, label=surv)

    plt.xlabel(r'$\alpha_{\text{in}}$')
    plt.ylabel(r'Events / htru')
    plt.yscale('log')
    plt.xlim((min(ALPHAS), max(ALPHAS)))
    plt.legend()
    plt.gca().invert_xaxis()
    plt.tight_layout()
    plt.grid()
    plt.savefig(rel_path('./plots/complex_rates.pdf'))
예제 #3
0
def plot_logn_logs(data):
    """Plot log N log S data in a cumlative histogram."""
    plot_aa_style()

    fig, (ax1) = plt.subplots(1, 1)

    for key in data:
        x, y = data[key]
        ax1.step(x, y, where='post', label=key)

    plt.xlabel(r'S$_{\text{min}}$ (Jy)')
    plt.ylabel(r'N(${>}\text{S}_{\text{min}}$)')
    plt.xscale('log')
    plt.yscale('log')
    plt.xlim((1e-3, 1e1))
    plt.legend()
    plt.tight_layout()
    plt.savefig(rel_path('plots/logn_logs_abc.pdf'))
예제 #4
0
def main():
    """Plot real rate regions per alpha."""
    plot_aa_style()

    rates = real_rates()

    for surv in rates:
        middle, top, bottom = rates[surv]
        left = min(ALPHAS)
        right = max(ALPHAS)
        x = [left, right, right, left]
        y = [top, top, bottom, bottom]
        plt.fill(x, y, alpha=0.25)
        plt.plot([left, right], [middle] * 2, label=surv, linestyle='dashed')

    plt.xlabel(r'$\alpha_{\text{in}}$')
    plt.ylabel(r'Events / htru')
    plt.yscale('log')
    plt.legend()
    plt.gca().invert_xaxis()
    plt.tight_layout()
    plt.savefig(rel_path('./plots/real_rates.pdf'))
예제 #5
0
def plot_dm(pops):
    """Plot resulting dispersion measure."""

    plot_aa_style()
    f, (ax1) = plt.subplots(1, 1)

    for i, beam in enumerate(pops):
        pop = pops[beam]
        dm = pop.frbs.dm
        s_peak = pop.frbs.s_peak

        limit = 1e-10
        dm = dm[(s_peak > limit)]

        print(f'{len(dm)} FRBs in graph of {pop.name}')

        n, bin_edges = np.histogram(dm, bins=75)
        n = n / max(n)
        bins = (bin_edges[:-1] + bin_edges[1:]) / 2

        # Add edges to histogram
        bin_diff = np.diff(bins)[-1]
        bins = np.insert(bins, 0, bins[0] - bin_diff)
        bins = np.insert(bins, len(bins), bins[-1] + bin_diff)
        n = np.insert(n, 0, 0)
        n = np.insert(n, len(n), 0)

        ax1.step(bins, n, where='mid', label=beam)

    ax1.set_xlabel(r'DM (pc cm$^{-3}$)')
    ax1.set_xlim([0, 3000])
    ax1.set_ylabel(r'Fraction')
    ax1.set_ylim([0, 1])
    ax1.legend()

    plt.tight_layout()
    plt.savefig(rel_path(f'./plots/dm_beams.pdf'))
    if min(bin_centres) <= min_s:
        min_s = min(bin_centres)
    if max(bin_centres) >= max_s:
        max_s = max(bin_centres)

# Add a -3/2 slope
x = np.linspace(min_s, max_s, 1000)
y = -1.5 * x
y -= min(y)
y += min(np.log10(n_gt_s))
x = x[y <= max(np.log10(n_gt_s))]
y = y[y <= max(np.log10(n_gt_s))]
ax1.step(x, y, where='mid', color='grey', alpha=0.5)

# Plot alpha over log S

# Plot a Euclidean line
x = np.linspace(min_s, max_s, 1000)
y = np.ones_like(x) * -1.5
ax2.step(x, y, where='mid', color='grey', alpha=0.5)

ax1.set_ylabel(r'log N($>$S$_{\text{peak}}$)')
ax1.legend()
ax2.set_xlabel(r'log S$_{\text{peak}}$')
ax2.set_ylabel(r'$\alpha$')
ax2.set_ylim(ax2.get_ylim()[::-1])

plt.tight_layout()
plt.savefig(rel_path(f'plots/logn_logs_si.pdf'))
예제 #7
0
f, (ax1) = plt.subplots(1, 1)

for p in BEAMPATTERNS:

    pop = pop_obs[p]
    limit = 1e-9

    s_peak = pop.frbs.s_peak
    dm_igm = pop.frbs.dm_igm

    mini = min(s_peak)
    maxi = max(s_peak)

    bins_s_peak = np.logspace(np.log10(mini), np.log10(maxi), 50)

    dm_igm = dm_igm[(s_peak > limit)]

    print(f'{len(dm_igm)} FRBs in graph of {pop.name}')

    n, bins = np.histogram(dm_igm, bins=50)
    n = n / max(n)
    bincentres = (bins[:-1] + bins[1:]) / 2
    ax1.step(bincentres, n, where='mid', label=p)

ax1.set_xlabel(r'DM$_{\text{IGM}}$')
ax1.set_ylabel(r'Fraction')
ax1.set_ylim([0, 1])
ax1.legend()
plt.tight_layout()
plt.savefig(rel_path('./plots/dm_igm_beampatterns.pdf'))
예제 #8
0
plot_aa_style()
plt.rcParams["figure.figsize"] = (5.75373, 5.75373)

f, axes = plt.subplots(2, 2)
s = survey_pop.frbs
axes[0, 0].step(*hist(s.snr, bin_type='log'), where='mid')
axes[0, 0].set_title('SNR')

axes[1, 0].step(*hist(s.T_sys, bin_type='log'), where='mid')
axes[1, 0].set_title(r'T$_{\text{sys}}$')
axes[1, 0].set_xlim(1, 1e2)
axes[1, 0].set_ylim(1e-3, 1)

axes[0, 1].step(*hist(s.s_peak, bin_type='log'), where='mid')
axes[0, 1].set_title(r'S$_{\text{peak}}$')
axes[0, 1].set_xlim(1e-3, 1)
axes[0, 1].set_ylim(1e-3, 1)

axes[1, 1].step(*hist(s.w_arr, bin_type='log'), where='mid')
axes[1, 1].set_title(r'w$_{\text{arr}}$')
axes[1, 1].set_ylim(1e-3, 1)

for x in [0, 1]:
    for y in [0, 1]:
        axes[x, y].set_xscale('log')
        axes[x, y].set_yscale('log')

plt.tight_layout()
plt.savefig(rel_path('plots/perfect.pdf'))
예제 #9
0
f, (ax1) = plt.subplots(1, 1)

for p in SIDELOBES:

    pop = pop_obs[p]
    limit = 1e-9

    s_peak = pop.frbs.s_peak
    dm_igm = pop.frbs.dm_igm

    mini = min(s_peak)
    maxi = max(s_peak)

    bins_s_peak = np.logspace(np.log10(mini), np.log10(maxi), 50)

    dm_igm = dm_igm[(s_peak > limit)]

    print(f'{len(dm_igm)} FRBs in graph of {pop.name}')

    n, bins = np.histogram(dm_igm, bins=50)
    n = n / max(n)
    bincentres = (bins[:-1] + bins[1:]) / 2
    ax1.step(bincentres, n, where='mid', label=p)

ax1.set_xlabel(r'DM$_{\text{IGM}}$')
ax1.set_ylabel(r'Fraction')
ax1.set_ylim([0, 1])
ax1.legend()
plt.tight_layout()
plt.savefig(rel_path(f'./plots/dm_igm_sidelobes.pdf'))
예제 #10
0
def plot_dists(surv_pop, telescope):
    """Plot the fluence and DM distribution of a surveyed population.

    Args:
        surv_pop (Population): Population from which to plot
        telescope (str): Name of the telescope with which to compare the
            distribution. Necessary for Frbcat.

    """
    plot_aa_style(cols=2)

    # Plot dm distribution
    f, (ax1, ax2) = plt.subplots(1, 2, sharey=True)

    dm_frbpoppy = surv_pop.frbs.dm
    pprint(f'Number of detected FRBs: {len(dm_frbpoppy)}')
    ax1.step(*hist(dm_frbpoppy), where='mid', linestyle='dashed')

    df = Frbcat().df
    dm_frbcat = df[df.telescope == telescope].dm
    ax1.step(*hist(dm_frbcat), where='mid')

    # Compare distributions
    ks = ks_2samp(dm_frbpoppy, dm_frbcat)
    text = fr'$p={round(ks[1], 2)}$'
    anchored_text = AnchoredText(text, loc=1, borderpad=1., frameon=False)
    ax1.add_artist(anchored_text)

    ax1.set_xlabel(r'DM ($\textrm{pc}\ \textrm{cm}^{-3}$)')
    ax1.set_ylabel('Fraction')
    ax1.set_ylim([0, 1.1])
    ax1.set_xlim([0, 3500])

    # Plot fluence distributions
    fluence_frbpoppy = surv_pop.frbs.fluence
    ax2.step(*hist(fluence_frbpoppy, bin_type='log'),
             where='mid',
             label='frbpoppy',
             linestyle='dashed')

    fluence_frbcat = df[df.telescope == telescope].fluence
    ax2.step(*hist(fluence_frbcat, bin_type='log'),
             where='mid',
             label='frbcat')

    # Compare distributions
    ks = ks_2samp(fluence_frbpoppy, fluence_frbcat)
    text = fr'$p={round(ks[1], 2)}$'
    anchored_text = AnchoredText(text, loc=1, borderpad=1., frameon=False)
    ax2.add_artist(anchored_text)

    ax2.set_xlabel(r'Fluence (Jy ms)')
    ax2.set_ylim([0, 1.1])
    ax2.set_xlim([5e-1, 1e4])
    plt.xscale('log')

    plt.figlegend(loc='upper center', ncol=2, framealpha=1)

    plt.tight_layout()
    plt.savefig(rel_path(f'plots/frbpoppy_{telescope}.pdf'))
    plt.clf()
예제 #11
0
n_gt_s = np.cumsum(hist[::-1])[::-1]

# Calculate alpha
alpha, alpha_err, norm = surv_pop.calc_logn_logs(parameter='fluence',
                                                 min_p=min_p,
                                                 max_p=max_p)

print(alpha, alpha_err, norm)
xs = 10**((np.log10(edges[:-1]) + np.log10(edges[1:])) / 2)
xs = xs[xs >= min_p]
xs = xs[xs <= max_p]
ys = [norm * x**(alpha) for x in xs]

plot_aa_style()
fig = plt.figure()
ax = fig.add_subplot(111)

plt.step(edges[:-1], n_gt_s, where='post')
plt.plot(xs,
         ys,
         linestyle='--',
         label=rf'$\alpha$ = {alpha:.3} $\pm$ {round(abs(alpha_err), 2)}')

plt.xlabel('Fluence (Jy ms)')
plt.ylabel(r'N(${>}\text{S}_{\text{min}}$)')
plt.xscale('log')
plt.yscale('log')
plt.legend()
plt.tight_layout()
plt.savefig(rel_path('plots/logn_logf_local.pdf'))
예제 #12
0
from convenience import plot_aa_style, rel_path

STEPSIZE = 1e-6
PLOT = True

x_range = np.arange(0, 50, STEPSIZE)
y_range = 4 * (j1(x_range) / x_range)**2
nulls = []

# Find where curve changes direction
ind = np.diff(np.sign(np.diff(y_range)))
x_null = x_range[1:-1][ind > 0]
y_null = y_range[1:-1][ind > 0]

print(x_null)

if PLOT:
    title = r"Bessel function over $\text{x}$"

    plot_aa_style()

    fig = plt.figure()
    ax = fig.add_subplot(111)
    plt.title(title)
    plt.plot(x_range[::10], y_range[::10])
    plt.scatter(x_null, y_null)
    plt.yscale('log')
    plt.tight_layout()

    plt.savefig(rel_path('./plots/null_sidelobes.pdf'))
예제 #13
0
    args = {'sidelobes': sidelobe}

    s = Survey(SURVEY, gain_pattern='airy', n_sidelobes=sidelobe)

    int_pro, offset = s.intensity_profile(shape=n)

    # Sort the values
    sorted_int = np.argsort(offset)
    int_pro = int_pro[sorted_int]
    offset = offset[sorted_int]

    # Clean up lower limit
    offset = offset[int_pro > MIN_Y]
    int_pro = int_pro[int_pro > MIN_Y]

    label = f'{sidelobe} sidelobes'
    if sidelobe == 1:
        label = label[:-1]

    # Offset in degrees
    offset = offset/60.

    plt.plot(offset, int_pro, label=label)

plt.xlabel(r'Offset ($$^{\circ}$$)')
plt.ylabel('Intensity Profile')
plt.yscale('log')
plt.legend()
plt.tight_layout()
plt.savefig(rel_path('./plots/int_pro_sidelobes.pdf'))
예제 #14
0
    # Sort the values
    sorted_int = np.argsort(offset)
    int_pro = int_pro[sorted_int]
    offset = offset[sorted_int]

    # Offset in degrees
    offset = offset / 60.

    bins = 1e2

    bin_means, bin_edges, bin_numbers = bstat(offset,
                                              int_pro,
                                              statistic='mean',
                                              bins=bins)

    bin_mins, _, _ = bstat(offset, int_pro, statistic='min', bins=bins)
    bin_maxs, _, _ = bstat(offset, int_pro, statistic='max', bins=bins)

    center = (bin_edges[:-1] + bin_edges[1:]) / 2

    plt.plot(center, bin_means, label=pattern)
    plt.fill_between(center, bin_mins, bin_maxs, alpha=0.2)

plt.xlabel(r'Offset ($$^{\circ}$$)')
plt.ylabel('Intensity Profile')
plt.yscale('log')
plt.legend()
plt.tight_layout()
plt.savefig(rel_path('plots/int_pro_surveys.pdf'))
예제 #15
0
        ns[s] = ns[s][1:]
        bins = bins[1:]

        bincentres = (bins[:-1] + bins[1:]) / 2

        title = titles[i]
        plt.step(bincentres, ns[s], where='mid', label=title)

        i += 1

    plt.xlabel('$z$')
    plt.ylabel(r'$\text{d}n_{\text{FRB}}/\text{d}z$')
    plt.yscale('log')
    plt.legend()
    plt.tight_layout()
    plt.savefig(rel_path('plots/number_frbs.pdf'))
    plt.clf()

if DENSITY_FRBS:
    plot_aa_style()

    fig = plt.figure()
    ax = fig.add_subplot(111)

    # Get dV
    import frbpoppy.precalc as pc
    d = pc.DistanceTable().lookup(z=bincentres)
    dvols = d[3]
    dens = {}
    i = 0
    for s in pop_types:
예제 #16
0
"""Check a powerlaw implementation generates the right numbers."""
import numpy as np
import matplotlib.pyplot as plt

from frbpoppy import distributions

from convenience import plot_aa_style, rel_path

POWER = -1

pl = distributions.powerlaw(1e35, 1e40, POWER, 100000)
minx = min(pl)
maxx = max(pl)
bins = 10 ** np.linspace(np.log10(minx), np.log10(maxx), 50)
hist, edges = np.histogram(pl, bins=bins)

plot_aa_style()

fig = plt.figure()
ax = fig.add_subplot(111)
plt.step(edges[:-1], hist, where='post')
plt.xscale('log')
plt.yscale('log')
plt.savefig(rel_path('plots/powerlaw.pdf'))
예제 #17
0
def plot(toy, simple, complex, real):
    """Plot rates panel."""
    surveys = SURVEYS[:-1]

    plot_aa_style(cols=2)
    fig, (ax1, ax2) = plt.subplots(1, 2, sharey=True)
    cmap = plt.get_cmap('tab10')
    ax1.set_xlim((min(ALPHAS) + .1, max(ALPHAS) - .1))
    ax2.set_xlim((min(ALPHAS) + .1, max(ALPHAS) - .1))
    ax1.set_yscale('log', nonposy='mask')
    ax2.set_yscale('log', nonposy='mask')

    # Plot simple versus toy
    for i, surv in enumerate(surveys):
        ax1.plot(ALPHAS,
                 toy[surv],
                 color=cmap(i),
                 linestyle='dotted',
                 zorder=0)
        ax1.plot(ALPHAS, simple[surv], zorder=1)

    # Plot complex expectations
    for i, surv in enumerate(surveys):
        ax2.plot(ALPHAS,
                 complex[surv],
                 color=cmap(i),
                 linestyle='dashed',
                 zorder=1)

    # Plot real event rate boxes
    ma, mi = ax2.get_xlim()
    ma -= 0.05
    mi += 0.05
    size = 0.13
    z = 0
    for i, surv in enumerate(surveys):

        central, min_r, max_r = real[surv]

        left = mi - size
        right = ma + size

        x, y = zip(*[(ma, max_r), (right, max_r), (right, min_r), (ma, min_r)])
        ax1.fill(x, y, color=cmap(i), zorder=z)
        ax1.plot([ma, right + 0.08], [central, central],
                 color=cmap(i),
                 zorder=z)

        x, y = zip(*[(mi, max_r), (left, max_r), (left, min_r), (mi, min_r)])
        ax2.fill(x, y, color=cmap(i), zorder=z)
        ax2.plot([mi, left - 0.08], [central, central],
                 color=cmap(i),
                 zorder=z)

        size -= 0.02
        z += 1

    # Plot layout options
    # Set up axes
    ax1.set_xlabel(r'$\alpha_{\text{in}}$')
    ax1.invert_xaxis()
    ax1.set_ylabel('Events / htru')
    ax1.yaxis.set_ticks_position('left')
    ax1.title.set_text(r'\textit{Simple} populations')

    ax2.set_xlabel(r'$\alpha_{\text{in}}$')
    ax2.invert_xaxis()
    ax2.yaxis.set_ticks_position('right')
    ax2.tick_params(labelright=False)
    ax2.title.set_text(r'\textit{Complex} populations')

    # Set up layout options
    fig.subplots_adjust(hspace=0)
    fig.subplots_adjust(wspace=0)

    # Add legend elements
    elements = []
    for i, surv in enumerate(surveys):
        c = cmap(i)
        line = Line2D([0], [0], color=c)
        label = surv
        elements.append((line, label))

    # Add gap in legend
    elements.append((Line2D([0], [0], color='white'), ''))

    # Add line styles
    n = 'analytical'
    elements.append((Line2D([0], [0], color='gray', linestyle='dotted'), n))
    elements.append((Line2D([0], [0], color='gray'), 'simple'))
    elements.append((Line2D([0], [0], color='gray',
                            linestyle='dashed'), 'complex'))

    # Add gap in legend
    elements.append((Line2D([0], [0], color='white'), ''))

    elements.append((Patch(facecolor='gray', edgecolor='gray',
                           alpha=0.6), 'real'))

    lines, labels = zip(*elements)
    plt.legend(lines, labels, bbox_to_anchor=(1.04, 0.5), loc="center left")

    plt.savefig(rel_path('plots/rates.pdf'), bbox_inches='tight')