# Path: frbpoppy/misc.py
# def poisson_interval(k, sigma=1):
#     """
#     Use chi-squared info to get the poisson interval.
# 
#     Given a number of observed events, which range of observed events would
#     have been just as likely given a particular interval?
# 
#     Based off https://stackoverflow.com/questions/14813530/
#     poisson-confidence-interval-with-numpy
#     """
#     gauss = norm(0, 1).pdf
#     a = 1 - quad(gauss, -sigma, sigma, limit=1000)[0]
#     low, high = (chi2.ppf(a/2, 2*k) / 2, chi2.ppf(1-a/2, 2*k + 2) / 2)
#     if k == 0:
#         low = 0.0
# 
#     return low, high
# 
# Path: tests/convenience.py
# def plot_aa_style(cols=1):
#     """Use a plotting style specifically for Astronomy & Astrophyiscs."""
#     # Use a style file
#     dir = os.path.abspath(os.path.dirname(__file__))
#     style_file = os.path.join(dir, './aa.mplstyle')
#     plt.style.use(style_file)
# 
#     # Check whether interactive backend is present
#     if os.name == 'posix' and "DISPLAY" not in os.environ:
#         # On a cluster
#         plt.switch_backend('Agg')
#         # Use just the basic latex package allowing \text to be used
#         plt.rcParams['text.latex.preamble'] = r'\usepackage{amsmath}'
# 
#     if cols == 2:
#         plt.rcParams["figure.figsize"] = (5.75373, 3.556)
# 
# def rel_path(path):
#     """Return the relative path name for this directory."""
#     return os.path.join(os.path.abspath(os.path.dirname(__file__)), path)


import matplotlib.pyplot as plt
import numpy as np
from frbpoppy import poisson_interval
from tests.convenience import plot_aa_style, rel_path
        exp = (exp_n/exp_days) / (scale_n/scale_days)
        exp_min *= (1/exp_days) / (scale_n/scale_days)
        exp_max *= (1/exp_days) / (scale_n/scale_days)

        rates[surv] = (exp, exp_min, exp_max)

    return rates


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(rf'Events / {SURVEYS[0]}')
    plt.yscale('log')
    plt.legend()
    plt.gca().invert_xaxis()
    plt.tight_layout()

# Path: frbpoppy/misc.py
# def poisson_interval(k, sigma=1):
#     """
#     Use chi-squared info to get the poisson interval.
# 
#     Given a number of observed events, which range of observed events would
#     have been just as likely given a particular interval?
# 
#     Based off https://stackoverflow.com/questions/14813530/
#     poisson-confidence-interval-with-numpy
#     """
#     gauss = norm(0, 1).pdf
#     a = 1 - quad(gauss, -sigma, sigma, limit=1000)[0]
#     low, high = (chi2.ppf(a/2, 2*k) / 2, chi2.ppf(1-a/2, 2*k + 2) / 2)
#     if k == 0:
#         low = 0.0
# 
#     return low, high
# 
# Path: tests/convenience.py
# def plot_aa_style(cols=1):
#     """Use a plotting style specifically for Astronomy & Astrophyiscs."""
#     # Use a style file
#     dir = os.path.abspath(os.path.dirname(__file__))
#     style_file = os.path.join(dir, './aa.mplstyle')
#     plt.style.use(style_file)
# 
#     # Check whether interactive backend is present
#     if os.name == 'posix' and "DISPLAY" not in os.environ:
#         # On a cluster
#         plt.switch_backend('Agg')
#         # Use just the basic latex package allowing \text to be used
#         plt.rcParams['text.latex.preamble'] = r'\usepackage{amsmath}'
# 
#     if cols == 2:
#         plt.rcParams["figure.figsize"] = (5.75373, 3.556)
# 
# def rel_path(path):
#     """Return the relative path name for this directory."""
#     return os.path.join(os.path.abspath(os.path.dirname(__file__)), path)


# Path: tests/rates/alpha_real.py
import matplotlib.pyplot as plt
import numpy as np
from frbpoppy import poisson_interval
from tests.convenience import plot_aa_style, rel_path

        exp = (exp_n/exp_days) / (scale_n/scale_days)
        exp_min *= (1/exp_days) / (scale_n/scale_days)
        exp_max *= (1/exp_days) / (scale_n/scale_days)

        rates[surv] = (exp, exp_min, exp_max)

    return rates


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(rf'Events / {SURVEYS[0]}')
    plt.yscale('log')
    plt.legend()
    plt.gca().invert_xaxis()
    plt.tight_layout()

    plt.savefig(rel_path('./plots/rates_rm.pdf'))