aboutsummaryrefslogtreecommitdiff
path: root/utils/plot-atmospheric-oscillations
blob: c24a776c16fda1cedb11a46f109b0e0e5fb395f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.hig
#!/usr/bin/env python
"""
Script to plot the probabilities for atmospheric neutrino oscillations. To run
it:

    $ ./plot-atmospheric-oscillations nue_osc_prob.txt
"""
from __future__ import print_function, division
import numpy as np

if __name__ == '__main__':
    import argparse
    from os.path import split, splitext

    parser = argparse.ArgumentParser("script to plot atmospheric oscillations")
    parser.add_argument("filenames", nargs='+', help="oscillation probability filenames")
    parser.add_argument("--save", action="store_true", default=False, help="save plots")
    args = parser.parse_args()

    if args.save:
        # default \textwidth for a fullpage article in Latex is 16.50764 cm.
        # You can figure this out by compiling the following TeX document:
        #
        #    \documentclass{article}
        #    \usepackage{fullpage}
        #    \usepackage{layouts}
        #    \begin{document}
        #    textwidth in cm: \printinunitsof{cm}\prntlen{\textwidth}
        #    \end{document}

        width = 16.50764
        width /= 2.54 # cm -> inches
        # According to this page:
        # http://www-personal.umich.edu/~jpboyd/eng403_chap2_tuftegospel.pdf,
        # Tufte suggests an aspect ratio of 1.5 - 1.6.
        height = width/1.5
        FIGSIZE = (width,height)

        import matplotlib.pyplot as plt

        font = {'family':'serif', 'serif': ['computer modern roman']}
        plt.rc('font',**font)

        plt.rc('text', usetex=True)
    else:
        # on retina screens, the default plots are way too small
        # by using Qt5 and setting QT_AUTO_SCREEN_SCALE_FACTOR=1
        # Qt5 will scale everything using the dpi in ~/.Xresources
        import matplotlib
        matplotlib.use("Qt5Agg")

        import matplotlib.pyplot as plt

        # Default figure size. Currently set to my monitor width and height so that
        # things are properly formatted
        FIGSIZE = (13.78,7.48)

        # Make the defalt font bigger
        plt.rc('font', size=22)

    for filename in args.filenames:
        head, tail = split(filename)
        root, ext = splitext(tail)

        e, z, pnue, pnum, pnut = np.genfromtxt(filename).T

        shape0 = len(np.unique(e))

        ee = e.reshape((shape0,-1))
        zz = z.reshape((shape0,-1))
        pnue = pnue.reshape((shape0,-1))
        pnum = pnum.reshape((shape0,-1))
        pnut = pnut.reshape((shape0,-1))

        levels = np.linspace(0,1,101)

        plt.figure(figsize=FIGSIZE)
        plt.contourf(ee,zz,pnue,levels=levels)
        plt.gca().set_xscale('log')
        plt.xlabel("Energy (GeV)")
        plt.ylabel("Cos(Zenith)")
        plt.colorbar()
        plt.tight_layout()
        if args.save:
            plt.savefig("%s_nue.pdf" % root)
            plt.savefig("%s_nue.eps" % root)
        else:
            plt.title(r"Probability to oscillate to $\nu_e$")
        plt.figure(figsize=FIGSIZE)
        plt.contourf(ee,zz,pnum,levels=levels)
        plt.gca().set_xscale('log')
        plt.xlabel("Energy (GeV)")
        plt.ylabel("Cos(Zenith)")
        plt.colorbar()
        plt.tight_layout()
        if args.save:
            plt.savefig("%s_num.pdf" % root)
            plt.savefig("%s_num.eps" % root)
        else:
            plt.title(r"Probability to oscillate to $\nu_\mu$")
        plt.figure(figsize=FIGSIZE)
        plt.contourf(ee,zz,pnut,levels=levels)
        plt.gca().set_xscale('log')
        plt.xlabel("Energy (GeV)")
        plt.ylabel("Cos(Zenith)")
        plt.colorbar()
        plt.tight_layout()
        if args.save:
            plt.savefig("%s_nut.pdf" % root)
            plt.savefig("%s_nut.eps" % root)
        else:
            plt.title(r"Probability to oscillate to $\nu_\tau$")

    plt.show()