Cosmic Rays

This module provides a data container for cosmic ray observables and can be used to simply share, save and load data. Also visualization of the observables can be done in a modular manner. There are two classes:

  • Cosmic rays: Basic data container for cosmic rays

  • Cosmic rays set: Provides a set of cosmic rays for simulation purposes

Contains the cosmic rays base class which allows to store arbitrary properties for the cosmic rays and makes them accesseble via key or getter function. The second class describes sets of cosmic rays as needed for larger studies.

class cosmic_rays.CosmicRaysBase(initializer=None, coord_system='gal')[source]

Bases: astrotools.container.DataContainer

Cosmic rays base class meant for inheritance

add_cosmic_rays(crs)[source]

Function to add cosmic rays to the already existing set of cosmic rays

Parameters

crs – numpy array with cosmic rays. The cosmic rays must not contain all original keys. Missing keys are set to zero. If additional keys are provided, they are ignored.

plot_energy_spectrum(**kwargs)[source]

Function to plot the energy spectrum of the cosmic rays

Parameters

kwargs – additional named arguments passed to plot_energy_spectum().

plot_eventmap(**kwargs)[source]

Function to plot a scatter skymap of the cosmic rays

Parameters

kwargs – additional named arguments passed to plot_eventmap().

plot_healpy_map(**kwargs)[source]

Forwards to function plot_heatmap()

plot_heatmap(**kwargs)[source]

Function to plot a healpy skymap of the cosmic rays

Parameters

kwargs – additional named arguments passed to plot_healpy_map().

sensitivity_2pt(niso=1000, bins=180, **kwargs)[source]

Function to calculate the sensitivity by the 2pt-auto-correlation over a scrambling of the right ascension coordinates.

Parameters
  • niso – Number of isotropic sets to calculate.

  • bins – Number of angular bins, 180 correspond to 1 degree binning (np.linspace(0, np.pi, bins+1).

  • kwargs – additional named arguments passed to obs.two_pt_auto()

Returns

pvalues in the shape (bins)

class cosmic_rays.CosmicRaysSets(nsets=None, ncrs=None)[source]

Bases: cosmic_rays.CosmicRaysBase

Set of cosmic rays

add_cosmic_rays(crs)[source]

Function to add cosmic rays to the already existing sets of cosmic rays. Number of sets must be equal.

Parameters

crs – CosmicRaysSet instance. The cosmic rays must not contain all original keys. Missing keys are set to zero. If additional keys are provided, they are ignored.

load(filename, **kwargs)[source]

Loads cosmic rays from a filename

Parameters
  • filename (str) – filename from where to load

  • kwargs – additional keyword arguments passed to numpy / pickle load functions

next()[source]

returns next element when iterating over all elements

plot_energy_spectrum(setid=0, **kwargs)[source]

Function to plot the energy spectrum of the cosmic ray set

Parameters
  • setid (int) – id of the set which is plotted (default: 0)

  • kwargs – additional named arguments pased to plot_energy_spectrum().

plot_eventmap(setid=0, **kwargs)[source]

Function to plot a scatter skymap of the cosmic rays

Parameters
  • setid (int) – id of the set which is plotted (default: 0)

  • kwargs – additional named arguments passed to plot_eventmap().

plot_healpy_map(setid=0, **kwargs)[source]

Forwards to function plot_heatmap()

plot_heatmap(setid=0, **kwargs)[source]

Function to plot a healpy map of the cosmic ray set

Parameters
  • setid (int) – id of the set which is plotted (default: 0)

  • kwargs – additional named arguments pased to plot_healpy_map().

save_readable(fname, use_keys=None, **kwargs)[source]

Saves cosmic ray class as ASCII file with general object store written to header.

Parameters
  • fname (str) – file name of the outfile

  • use_keys – list or tuple of keywords that will be used for the saved file

  • kwargs – additional named keyword arguments passed to numpy.savetxt()

sensitivity_2pt(set_idx=None, niso=1000, bins=180, **kwargs)[source]

Function to calculate the sensitivity by the 2pt-auto-correlation over a scrambling of the right ascension coordinates.

Parameters
  • set_idx – If set, only this set number will be evaluated

  • niso – Number of isotropic sets to calculate

  • bins – Number of angular bins, 180 correspond to 1 degree binning (np.linspace(0, np.pi, bins+1).

  • kwargs – additional named arguments passed to obs.two_pt_auto()

Returns

pvalues in the shape (self.nsets, bins)

shuffle_events()[source]

Independently shuffle the cosmic rays of each set.

cosmic_rays.plot_energy_spectrum(crs, xlabel='log$_{10}$(Energy / eV)', ylabel='entries', fontsize=16, bw=0.05, opath=None, **kwargs)[source]

Function to plot the energy spectrum of the cosmic ray set

Parameters
  • crs – CosmicRaysBase object

  • xlabel (str) – label for the x-axis

  • ylabel (str) – label for the y-axis

  • fontsize (int) – Scales the fontsize in the image.

  • bw (float) – bin width for the histogram

  • opath (str) – Output path for the image, default is None

  • kwargs – additional named keywords passed to matplotlib.pyplot.hist

Returns

bins of the histogram

cosmic_rays.plot_eventmap(crs, opath=None, **kwargs)[source]

Function to plot a scatter skymap of the cosmic rays

Parameters
  • crs – CosmicRaysBase object

  • opath (str) – Output path for the image, default is None

  • kwargs

    • c: quantity that is supposed to occur in colorbar, e.g. energy of the cosmic rays

    • cblabel: label for the colorbar

    • nside: Healpy resolution of the ‘pixel’ array in the cosmic ray class

    • additional named keywords passed to matplotlib.scatter

    • fontsize: Scales the fontsize in the image

Returns

figure, axis of the scatter plot

cosmic_rays.plot_heatmap(crs, opath=None, **kwargs)[source]

Function to plot a scatter skymap of the cosmic rays

Parameters
  • crs – CosmicRaysBase object

  • opath (str) – Output path for the image, default is None

  • kwargs

    • nside: Healpy resolution of the ‘pixel’ array in the cosmic ray class

    • additional named keywords passed to matplotlib.pcolormesh

Returns

figure of the heatmap, colorbar