Example #1
0
def geneateNcos_thetaFile(year):

    Nzenith_bin = 100
    N_coszenith = np.zeros((len(Defaults.map_logE_center), Nzenith_bin))

    for file in [os.path.join(icecube_data_dir, year + '-events.txt')]:

        AtmBG_file = np.loadtxt(file)
        _index_map_logE = np.searchsorted(Defaults.map_logE_edge,
                                          AtmBG_file[:, 1]) - 1
        _index_map_logE[_index_map_logE ==
                        -1] = 0  # group logE < 2 events to bin 0

        for i in np.arange(len(Defaults.map_logE_center)):
            """ use healpy convention: theta = 180 - zenith_IceCube """
            N_coszenith_i, cosZenithBinEdges =\
                np.histogram(np.cos(np.pi - AtmBG_file[:, 6][_index_map_logE == i] * np.pi / 180.), Nzenith_bin, (-1, 1))
            N_coszenith[i] += N_coszenith_i

    cosZenithBinCenters = (cosZenithBinEdges[0:-1] +
                           cosZenithBinEdges[1:]) / 2.

    figs = FigureDict()
    figs.plot_yvals('N_coszenith',
                    cosZenithBinCenters,
                    N_coszenith,
                    xlabel=r'$\cos\,\theta$',
                    ylabel='Number of counts in 2010-2012 data',
                    figsize=(8, 6))

    for i in np.arange(Defaults.NEbin):
        np.savetxt(
            os.path.join(irf_dir,
                         'Ncos_theta_' + year + '_' + str(i) + '.txt'),
            np.column_stack((cosZenithBinCenters, N_coszenith[i])))
Example #2
0
def test_PowerSpectrum():

    ns_atm = NeutrinoSample()
    ns_atm.inputData(bgpath)

    gs = GALAXY_LIBRARY.get_sample('analy')

    if MAKE_TEST_PLOTS:

        figs = FigureDict()
        color = [
            'r', 'orange', 'limegreen', 'skyblue', 'mediumslateblue', 'purple',
            'grey'
        ]

        figs.plot_cl('PowerSpectrum_atm',
                     Defaults.ell,
                     ns_atm.getPowerSpectrum(),
                     xlabel="l",
                     ylavel=r'$C_{l}$',
                     figsize=(8, 6),
                     colors=color)
        figs.plot('PowerSpectrum_atm',
                  Defaults.ell,
                  gs.analyCL[0:3 * Defaults.NSIDE],
                  color='k',
                  linestyle='--',
                  lw=2)
        figs.save_all(testfigpath, 'pdf')
Example #3
0
def atmBG_coszenith(energyBin=0):

    eg = EventGenerator()
    N_coszenith = eg.atm_gen.coszenith()[energyBin]
    recovered_values = eg.atmBG_coszenith(int(np.sum(N_coszenith[:, 1])),
                                          energyBin)

    index = np.where(np.abs(recovered_values) > 1)
    if len(index) > 1:
        print(index, recovered_values[index])

    if MAKE_TEST_PLOTS:
        figs = FigureDict()
        figkey = 'N_coszenith' + str(energyBin)
        o_dict = figs.setup_figure(figkey,
                                   xlabel=r'$\cos\,\theta$',
                                   ylabel='Number of counts',
                                   figsize=(8, 6))
        fig = o_dict['fig']
        axes = o_dict['axes']
        axes.plot(N_coszenith[:, 0], N_coszenith[:, 1], lw=2, label='data')
        axes.hist(recovered_values, N_coszenith[:, 0], label='mock')
        fig.legend()
        figs.save_all(testfigpath, 'pdf')
Example #4
0
def astroEvent_galaxy(f_diff=1.):
    gs = GALAXY_LIBRARY.get_sample('analy')
    eg = EventGenerator(year='IC86-2012', astroModel='observed_numu_fraction')
    N_astro_north_obs = np.random.poisson(eg.nevts * 1 *
                                          eg.f_astro_north_truth)
    N_astro_north_exp = [
        N_astro_north_obs[i] /
        np.sum(eg._astro_gen.prob_reject()[i] * gs.density)
        for i in range(Defaults.NEbin)
    ]
    astro_map = eg.astroEvent_galaxy(np.array(N_astro_north_exp), gs.density)
    file_utils.write_maps_to_fits(astro_map, astropath)

    if MAKE_TEST_PLOTS:
        figs = FigureDict()
        figs.mollview_maps('astro', astro_map)
        figs.save_all(testfigpath, 'pdf')
Example #5
0
def test_CrossCorrelation():
    ns_astro = NeutrinoSample()
    ns_astro.inputData(astropath)

    gs = GALAXY_LIBRARY.get_sample('analy')
    w_cross = ns_astro.getCrossCorrelation(gs.overdensityalm)

    if MAKE_TEST_PLOTS:
        figs = FigureDict()
        color = [
            'r', 'orange', 'limegreen', 'skyblue', 'mediumslateblue', 'purple',
            'grey'
        ]

        o_dict = figs.setup_figure('Wcross',
                                   xlabel="l",
                                   ylabel=r'$w$',
                                   figsize=(6, 8))
        axes = o_dict['axes']
        for i in range(Defaults.NEbin):
            axes.plot(Defaults.ell,
                      gs.analyCL[0:3 * Defaults.NSIDE] * 10**(i * 2),
                      color='k',
                      lw=2)
            w_cross[i] *= 10**(i * 2)

        figs.plot_cl('Wcross',
                     Defaults.ell,
                     np.abs(w_cross),
                     xlabel="l",
                     ylabel=r'$C_{l}$',
                     colors=color,
                     ymin=1e-7,
                     ymax=1e10,
                     lw=3)

        figs.save_all(testfigpath, 'pdf')
Example #6
0
def atmBG():
    eg = EventGenerator()
    eventmap = eg.atmEvent(1.)
    eventmap2 = np.zeros((Defaults.NEbin, Defaults.NPIXEL))

    file_utils.write_maps_to_fits(eventmap, bgpath)
    for i in range(Defaults.NEbin):
        eventmap2[i] = eventmap[i]
        eventmap2[i][Defaults.idx_muon] = hp.UNSEEN

    mask = np.zeros(Defaults.NPIXEL)
    mask[Defaults.idx_muon] = 1.
    for i in range(Defaults.NEbin):
        test = np.ma.masked_array(eventmap[i], mask=mask)
        print(test.sum())

    if MAKE_TEST_PLOTS:
        figs = FigureDict()
        figs.mollview_maps('eventmap_atm', eventmap2)
        figs.save_all(testfigpath, 'pdf')
Example #7
0
import os
import numpy as np
import healpy as hp

from scipy import stats

from KIPAC import nuXgal
from KIPAC.nuXgal import EventGenerator
from KIPAC.nuXgal import Defaults
from KIPAC.nuXgal import FigureDict
from KIPAC.nuXgal import hp_utils
from KIPAC.nuXgal import Utilityfunc

import matplotlib.pyplot as plt

figs = FigureDict()
galaxy_galaxy_cl_path = os.path.join(Defaults.NUXGAL_ANCIL_DIR, 'Cl_ggRM.dat')
galaxy_od_path = os.path.join(Defaults.NUXGAL_ANCIL_DIR,
                              'galaxySampleOverdensity.fits')

gg_cl_map = nuXgal.Map.create_from_cl(galaxy_galaxy_cl_path)

cls_od = gg_cl_map.cl()[0]

gg_overdensity = hp.sphtfunc.synfast(cls_od, Defaults.NSIDE)
gg_density = np.clip(gg_overdensity + 1, 0., np.inf)
gg_density /= gg_density.sum()

cl_density = hp.sphtfunc.anafast(gg_density)

n_events = np.logspace(1, 7, 13)
Example #8
0
import os
import numpy as np
import healpy as hp

from KIPAC import nuXgal
from KIPAC.nuXgal import Defaults
from KIPAC.nuXgal import FigureDict
from KIPAC.nuXgal import hp_utils
from KIPAC.nuXgal import Utilityfunc

import matplotlib.pyplot as plt


figs = FigureDict()

galaxy_od_path = os.path.join(Defaults.NUXGAL_ANCIL_DIR, 'galaxySampleOverdensity.fits')
galaxy_galaxy_cl_path = os.path.join(Defaults.NUXGAL_ANCIL_DIR,'Cl_ggRM.dat')
aeff_path = os.path.join(Defaults.NUXGAL_IRF_DIR, 'Aeff{i}.fits')
syn_astro_counts_path = os.path.join(Defaults.NUXGAL_SYNTHETICDATA_DIR, 'eventmap_astro{i}.fits')
syn_atm_counts_path = os.path.join(Defaults.NUXGAL_SYNTHETICDATA_DIR, 'eventmap_atm{i}.fits')

syn_map_astr = nuXgal.Map.create_from_counts_and_exposure_maps(syn_astro_counts_path, aeff_path, Defaults.NEbin)
syn_map_atm = nuXgal.Map.create_from_counts_and_exposure_maps(syn_atm_counts_path, aeff_path, Defaults.NEbin)

gg_od_map = nuXgal.Map.create_from_overdensity_maps(galaxy_od_path)
gg_cl_map = nuXgal.Map.create_from_cl(galaxy_galaxy_cl_path)


nevts_2000 = 2000.
nevts_10000 = 10000.
Example #9
0
    return hist


def plot_density_complex(hist):

    fig, axes = plt.subplots(nrows=1, ncols=1, figsize=(8, 8))
    axes.set_xlabel(r'$\mathcal{R}$')
    axes.set_ylabel(r'$\mathcal{I}$')
    extent = (hist[1][0], hist[1][-1], hist[2][0], hist[2][-1])
    img = axes.imshow(hist[0], extent=extent, interpolation='none')
    cbar = plt.colorbar(img)

    return dict(fig=fig, axes=axes, img=img, cbar=cbar)


figs = FigureDict()

galaxy_od_path = os.path.join(Defaults.NUXGAL_ANCIL_DIR,
                              'galaxySampleOverdensity.fits')
galaxy_galaxy_cl_path = os.path.join(Defaults.NUXGAL_ANCIL_DIR, 'Cl_ggRM.dat')
aeff_path = os.path.join(Defaults.NUXGAL_IRF_DIR, 'Aeff{i}.fits')
syn_astro_counts_path = os.path.join(Defaults.NUXGAL_SYNTHETICDATA_DIR,
                                     'eventmap_astro{i}.fits')
syn_atm_counts_path = os.path.join(Defaults.NUXGAL_SYNTHETICDATA_DIR,
                                   'eventmap_atm{i}.fits')

#syn_map_astr = nuXgal.Map.create_from_counts_and_exposure_maps(syn_astro_counts_path, aeff_path, Defaults.NEbin)
#syn_map_atm = nuXgal.Map.create_from_counts_and_exposure_maps(syn_atm_counts_path, aeff_path, Defaults.NEbin)

gg_od_map = nuXgal.Map.create_from_overdensity_maps(galaxy_od_path)
Example #10
0
import os
import numpy as np
import healpy as hp

from scipy import stats

from KIPAC import nuXgal
from KIPAC.nuXgal import EventGenerator
from KIPAC.nuXgal import Defaults
from KIPAC.nuXgal import FigureDict
from KIPAC.nuXgal import hp_utils
from KIPAC.nuXgal import Utilityfunc

import matplotlib.pyplot as plt

figs = FigureDict()

galaxy_od_path = os.path.join(Defaults.NUXGAL_ANCIL_DIR,
                              'galaxySampleOverdensity.fits')
galaxy_galaxy_cl_path = os.path.join(Defaults.NUXGAL_ANCIL_DIR, 'Cl_ggRM.dat')
aeff_path = os.path.join(Defaults.NUXGAL_IRF_DIR, 'Aeff{i}.fits')
syn_astro_counts_path = os.path.join(Defaults.NUXGAL_SYNTHETICDATA_DIR,
                                     'eventmap_astro{i}.fits')
syn_atm_counts_path = os.path.join(Defaults.NUXGAL_SYNTHETICDATA_DIR,
                                   'eventmap_atm{i}.fits')

syn_map_astr = nuXgal.Map.create_from_counts_and_exposure_maps(
    syn_astro_counts_path, aeff_path, Defaults.NEbin)
syn_map_atm = nuXgal.Map.create_from_counts_and_exposure_maps(
    syn_atm_counts_path, aeff_path, Defaults.NEbin)
Example #11
0
import os
import numpy as np
import healpy as hp

from KIPAC import nuXgal
from KIPAC.nuXgal import Defaults
from KIPAC.nuXgal import FigureDict
from KIPAC.nuXgal import hp_utils
from KIPAC.nuXgal import Utilityfunc

import matplotlib.pyplot as plt


figs = FigureDict()

galaxy_od_path = os.path.join(Defaults.NUXGAL_ANCIL_DIR, 'galaxySampleOverdensity.fits')
galaxy_galaxy_cl_path = os.path.join(Defaults.NUXGAL_ANCIL_DIR,'Cl_ggRM.dat')
aeff_path = os.path.join(Defaults.NUXGAL_IRF_DIR, 'Aeff{i}.fits')
syn_astro_counts_path = os.path.join(Defaults.NUXGAL_SYNTHETICDATA_DIR, 'eventmap_astro{i}.fits')
syn_atm_counts_path = os.path.join(Defaults.NUXGAL_SYNTHETICDATA_DIR, 'eventmap_atm{i}.fits')

#syn_map_astr = nuXgal.Map.create_from_counts_and_exposure_maps(syn_astro_counts_path, aeff_path, Defaults.NEbin)
#syn_map_atm = nuXgal.Map.create_from_counts_and_exposure_maps(syn_atm_counts_path, aeff_path, Defaults.NEbin)

gg_od_map = nuXgal.Map.create_from_overdensity_maps(galaxy_od_path)

gg_cl_map = nuXgal.Map.create_from_cl(galaxy_galaxy_cl_path)


mean_density = 1.
Example #12
0
import os
import numpy as np
import healpy as hp

from scipy import stats

from KIPAC import nuXgal
from KIPAC.nuXgal import EventGenerator
from KIPAC.nuXgal import Defaults
from KIPAC.nuXgal import FigureDict
from KIPAC.nuXgal import hp_utils
from KIPAC.nuXgal import Utilityfunc

import matplotlib.pyplot as plt

figs = FigureDict()

galaxy_od_path = os.path.join(Defaults.NUXGAL_ANCIL_DIR,
                              'galaxySampleOverdensity.fits')
galaxy_galaxy_cl_path = os.path.join(Defaults.NUXGAL_ANCIL_DIR, 'Cl_ggRM.dat')
aeff_path = os.path.join(Defaults.NUXGAL_IRF_DIR, 'Aeff{i}.fits')
syn_astro_counts_path = os.path.join(Defaults.NUXGAL_SYNTHETICDATA_DIR,
                                     'eventmap_astro{i}.fits')
syn_atm_counts_path = os.path.join(Defaults.NUXGAL_SYNTHETICDATA_DIR,
                                   'eventmap_atm{i}.fits')

syn_map_astr = nuXgal.Map.create_from_counts_and_exposure_maps(
    syn_astro_counts_path, aeff_path, Defaults.NEbin)
syn_map_atm = nuXgal.Map.create_from_counts_and_exposure_maps(
    syn_atm_counts_path, aeff_path, Defaults.NEbin)
Example #13
0
import os
import numpy as np
import healpy as hp

from KIPAC import nuXgal
from KIPAC.nuXgal import Defaults
from KIPAC.nuXgal import FigureDict
from KIPAC.nuXgal import Utilityfunc

import matplotlib.pyplot as plt

figs = FigureDict()

galaxy_od_path = os.path.join(Defaults.NUXGAL_ANCIL_DIR,
                              'galaxySampleOverdensity.fits')
galaxy_galaxy_cl_path = os.path.join(Defaults.NUXGAL_ANCIL_DIR, 'Cl_ggRM.dat')
aeff_path = os.path.join(Defaults.NUXGAL_IRF_DIR, 'Aeff{i}.fits')
syn_astro_counts_path = os.path.join(Defaults.NUXGAL_SYNTHETICDATA_DIR,
                                     'eventmap_astro{i}.fits')
syn_atm_counts_path = os.path.join(Defaults.NUXGAL_SYNTHETICDATA_DIR,
                                   'eventmap_atm{i}.fits')

syn_map_astr = nuXgal.Map.create_from_counts_and_exposure_maps(
    syn_astro_counts_path, aeff_path, Defaults.NEbin)
syn_map_atm = nuXgal.Map.create_from_counts_and_exposure_maps(
    syn_atm_counts_path, aeff_path, Defaults.NEbin)

gg_od_map = nuXgal.Map.create_from_overdensity_maps(galaxy_od_path)
gg_cl_map = nuXgal.Map.create_from_cl(galaxy_galaxy_cl_path)

mean_density = 1.
Example #14
0
import os
import numpy as np
import healpy as hp

from KIPAC import nuXgal
from KIPAC.nuXgal import Defaults
from KIPAC.nuXgal import FigureDict
from KIPAC.nuXgal import Utilityfunc

import matplotlib.pyplot as plt

eg = nuXgal.EventGenerator()

figs = FigureDict()

galaxy_od_path = os.path.join(Defaults.NUXGAL_ANCIL_DIR,
                              'galaxySampleOverdensity.fits')
galaxy_galaxy_cl_path = os.path.join(Defaults.NUXGAL_ANCIL_DIR, 'Cl_ggRM.dat')
aeff_path = os.path.join(Defaults.NUXGAL_IRF_DIR, 'Aeff{i}.fits')
syn_astro_counts_path = os.path.join(Defaults.NUXGAL_SYNTHETICDATA_DIR,
                                     'eventmap_astro{i}.fits')
syn_atm_counts_path = os.path.join(Defaults.NUXGAL_SYNTHETICDATA_DIR,
                                   'eventmap_atm{i}.fits')

syn_map_astr = nuXgal.Map.create_from_counts_and_exposure_maps(
    syn_astro_counts_path, aeff_path, Defaults.NEbin)
syn_map_atm = nuXgal.Map.create_from_counts_and_exposure_maps(
    syn_atm_counts_path, aeff_path, Defaults.NEbin)
gg_od_map = nuXgal.Map.create_from_overdensity_maps(galaxy_od_path)
gg_cl_map = nuXgal.Map.create_from_cl(galaxy_galaxy_cl_path)
Example #15
0
import os
import numpy as np
import healpy as hp

from KIPAC import nuXgal
from KIPAC.nuXgal import Defaults
from KIPAC.nuXgal import FigureDict
from KIPAC.nuXgal import file_utils
from KIPAC.nuXgal import Utilityfunc

from KIPAC.nuXgal.Generator import AtmGenerator, AstroGenerator

import matplotlib.pyplot as plt

figs = FigureDict()


coszenith_path = os.path.join(Defaults.NUXGAL_IRF_DIR, 'N_coszenith{i}.txt')
aeff_path = os.path.join(Defaults.NUXGAL_IRF_DIR, 'Aeff{i}.fits')
nevents_path = os.path.join(Defaults.NUXGAL_IRF_DIR, 'eventNumber_Ebin_perIC86year.txt')
gg_sample_path = os.path.join(Defaults.NUXGAL_ANCIL_DIR, 'galaxySampleOverdensity.fits')


aeff = file_utils.read_maps_from_fits(aeff_path, Defaults.NEbin)
cosz = file_utils.read_cosz_from_txt(coszenith_path, Defaults.NEbin)
nevts = np.loadtxt(nevents_path)
gg_overdensity = hp.fitsfunc.read_map(gg_sample_path)
gg_density = 1. + gg_overdensity
gg_density /= gg_density.sum()