• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

icecube / flarestack / 4536597083

pending completion
4536597083

Pull #268

github

GitHub
Merge 0d13f2846 into e550ab59c
Pull Request #268: Compliance with black v23

26 of 26 new or added lines in 11 files covered. (100.0%)

4405 of 5755 relevant lines covered (76.54%)

2.29 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.48
/flarestack/utils/create_acceptance_functions.py
1
import numpy as np
3✔
2
import os
3✔
3
import pickle
3✔
4
import logging
3✔
5
from flarestack.shared import acceptance_path, get_base_sob_plot_dir
3✔
6
from flarestack.core.energy_pdf import PowerLaw
3✔
7
from flarestack.utils.make_SoB_splines import make_plot
3✔
8

9
logger = logging.getLogger(__name__)
3✔
10

11
sin_dec_range = np.linspace(-1, 1, 101)
3✔
12
sin_edges = np.append(-1.0, (sin_dec_range[1:] + sin_dec_range[:-1]) / 2.0)
3✔
13
sin_edges = np.append(sin_edges, 1.0)
3✔
14
dec_range = np.arcsin(sin_dec_range)
3✔
15
dec_edges = np.arcsin(sin_edges)
3✔
16

17
gamma_vals = np.linspace(0.5, 5.5, 201)
3✔
18

19

20
def make_acceptance_f(all_data):
3✔
21
    for season in all_data.values():
×
22
        acc_path = acceptance_path(season)
×
23
        make_acceptance_season(season, acc_path)
×
24

25

26
def make_acceptance_season(season, acc_path):
3✔
27
    e_pdf = PowerLaw()
3✔
28

29
    mc = season.get_pseudo_mc()
3✔
30

31
    acc = np.ones((len(dec_range), len(gamma_vals)), dtype=float)
3✔
32

33
    for i, dec in enumerate(dec_range):
3✔
34
        # Sets half width of band
35
        dec_width = np.deg2rad(5.0)
3✔
36

37
        # Sets a declination band 5 degrees above and below the source
38
        min_dec = max(-np.pi / 2.0, dec - dec_width)
3✔
39
        max_dec = min(np.pi / 2.0, dec + dec_width)
3✔
40
        # Gives the solid angle coverage of the sky for the band
41
        omega = 2.0 * np.pi * (np.sin(max_dec) - np.sin(min_dec))
3✔
42

43
        band_mask = np.logical_and(
3✔
44
            np.greater(mc["trueDec"], min_dec), np.less(mc["trueDec"], max_dec)
45
        )
46

47
        cut_mc = mc[band_mask]
3✔
48

49
        for j, gamma in enumerate(gamma_vals):
3✔
50
            weights = e_pdf.weight_mc(cut_mc, gamma)
3✔
51
            acc[i][j] = np.sum(weights / omega)
3✔
52

53
    try:
3✔
54
        os.makedirs(os.path.dirname(acc_path))
3✔
55
    except OSError:
3✔
56
        pass
3✔
57

58
    logger.info(
3✔
59
        "Saving {0} acceptance values to: {1}".format(season.season_name, acc_path)
60
    )
61

62
    with open(acc_path, "wb") as f:
3✔
63
        pickle.dump([dec_range, gamma_vals, acc], f)
3✔
64

65
    del mc
3✔
66

67
    savepath = get_base_sob_plot_dir(season) + "acceptance_f.pdf"
3✔
68

69
    try:
3✔
70
        os.makedirs(os.path.dirname(savepath))
3✔
71
    except OSError:
3✔
72
        pass
3✔
73

74
    make_plot(
3✔
75
        acc,
76
        savepath,
77
        gamma_vals,
78
        np.sin(dec_range),
79
        label_x=r"$\gamma$",
80
        label_y=r"$\sin(\delta)$",
81
    )
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc