CORSIKA

Contents

CORSIKA#

Support modules for running CORSIKA.

corsika_config#

class corsika.corsika_config.CorsikaConfig(array_model, label=None, corsika_config_data=None, corsika_config_file=None, corsika_parameters_file=None, simtel_source_path=None)[source]#

CorsikaConfig deals with configuration for running CORSIKA. User parameters must be given by the corsika_config_data or corsika_config_file arguments. An example of corsika_config_data follows below.

corsika_config_data = {
    'data_directory': .
    'primary': 'proton',
    'nshow': 10000,
    'nrun': 1,
    'zenith': 20 * u.deg,
    'viewcone': 5 * u.deg,
    'erange': [10 * u.GeV, 100 * u.TeV],
    'eslope': -2,
    'phi': 0 * u.deg,
    'cscat': [10, 1500 * u.m, 0]
}
Parameters:
array_model: ArrayModel

Array model.

label: str

Instance label.

corsika_config_data: dict

CORSIKA user parameters.

corsika_config_file: str

Name of the yaml configuration file. If not provided, data/parameters/corsika_parameters.yml will be used.

corsika_parameters_file: str

Name of the yaml file to set remaining CORSIKA parameters.

simtel_source_path: str or Path

Location of source of the sim_telarray/CORSIKA package.

export_input_file(use_multipipe=False)[source]#

Create and export CORSIKA input file.

Parameters:
use_multipipe: bool

Whether to set the CORSIKA Inputs file to pipe the output directly to sim_telarray or not.

get_corsika_input_list()[source]#

List of telescope positions in the format required for the CORSIKA input file.

Returns:
str

Piece of text to be added to the CORSIKA input file.

get_file_name(file_type, run_number=None)[source]#

Get a CORSIKA config style file name for various file types.

Parameters:
file_type: str

The type of file (determines the file suffix). Choices are config_tmp, config or output_generic.

run_number: int

Run number.

Returns:
str
for file_type=”config_tmp”:

Get the CORSIKA input file for one specific run. This is the input file after being pre-processed by sim_telarray (pfp).

for file_type=”config”:

Get a general CORSIKA config inputs file.

for file_type=”output_generic”

Get a generic file name for the TELFIL option in the CORSIKA inputs file.

for file_type=”multipipe”

Get a multipipe “file name” for the TELFIL option in the CORSIKA inputs file.

Raises:
ValueError

If file_type is unknown or if the run number is not given for file_type==config_tmp.

get_input_file(use_multipipe=False)[source]#

Get the full path of the CORSIKA input file.

Returns:
Path:

Full path of the CORSIKA input file.

get_user_parameter(par_name)[source]#

Get the value of a user parameter.

Parameters:
par_name: str

Name of the parameter as used in the CORSIKA input file (e.g. PRMPAR, THETAP …)

Returns:
list

Value(s) of the parameter.

Raises:
KeyError

When par_name is not a valid parameter name.

static load_corsika_parameters_file(corsika_parameters_file)[source]#

Load CORSIKA parameters from the provided corsika_parameters_file.

Parameters:
corsika_parameters_file: str or Path

File with CORSIKA parameters.

Returns:
corsika_parameters: dict

Dictionary with CORSIKA parameters.

print_user_parameters()[source]#

Print user parameters for inspection.

set_user_parameters(corsika_config_data)[source]#

Set user parameters from a dict.

Parameters:
corsika_config_data: dict

Contains the user parameters. Ex.

corsika_config_data = {
    'primary': 'proton',
    'nshow': 10000,
    'nrun': 1,
    'zenith': 20 * u.deg,
    'viewcone': 5 * u.deg,
    'erange': [10 * u.GeV, 100 * u.TeV],
    'eslope': -2,
    'phi': 0 * u.deg,
    'cscat': [10, 1500 * u.m, 0]
}
Raises:
InvalidCorsikaInputError

If any parameter given as input has wrong len, unit or an invalid name.

MissingRequiredInputInCorsikaConfigDataError

If any required user parameter is missing.

exception corsika.corsika_config.InvalidCorsikaInputError[source]#

Exception for invalid corsika input.

exception corsika.corsika_config.MissingRequiredInputInCorsikaConfigDataError[source]#

Exception for missing required input in corsika config data.

corsika_default_config#

class corsika.corsika_default_config.CorsikaDefaultConfig(primary=None, zenith_angle=None)[source]#

This class contains the default configuration for CORSIKA parameters for the various primary particles. It includes all basic dependencies on zenith angles, etc. The default values defined in this class assume the full CTAO arrays are simulated, including full CTAO energy range and number of events optimized to run for roughly 24 hours on a single node on the grid.

energy_range_for_primary()[source]#

Get the energy range for the primary particle for the given zenith angle.

Returns:
energy_range: list

List with the energy range for the primary particle for the given zenith angle.

property energy_slope#

Energy slope.

Returns:
energy_slope: float
static interpolate_to_zenith_angle(zenith_angle, zenith_angles_to_interpolate, values_to_interpolate)[source]#

Interpolate values like energy range or number of showers to the provided zenith angle.

Parameters:
zenith_angle: astropy.units.Quantity

Which zenith angle to interpolate to (in degrees).

zenith_angles_to_interpolate: list

List of zenith angles for which we have values to interpolate between.

values_to_interpolate: list

List of values to interpolate between.

Returns:
float

Interpolated value.

number_of_showers_for_primary()[source]#

Get the number of showers for the primary particle for the given zenith angle.

Returns:
number_of_showers: int

Number of showers for the primary particle for the given zenith angle.

property primary#

Primary particle.

Returns:
primary: str
view_cone_for_primary()[source]#

Get the view cone for the primary particle. All diffuse primaries have a view cone of 10 deg by default.

Returns:
view_cone: list

List with the view cone for the primary particle.

property zenith_angle#

Zenith angle.

Returns:
zenith_angle: astropy.units.Quantity

corsika_histograms#

class corsika.corsika_histograms.CorsikaHistograms(input_file, label=None, output_path=None, hdf5_file_name=None)[source]#
CorsikaHistograms extracts the Cherenkov photons information from a CORSIKA IACT file

using pyeventio.

Parameters:
input_file: str or Path

CORSIKA IACT file provided by the CORSIKA simulation.

label: str

Instance label.

output_path: str

Path where to save the output of the class methods.

hdf5_file_name: str

HDF5 file name for histogram storage.

Raises:
FileNotFoundError:

if the input file given does not exist.

property corsika_version#

Get the version of the CORSIKA IACT file.

Returns:
float:

The version of CORSIKA used to produce the CORSIKA IACT file given by self.input_file.

property dict_1d_distributions#

Dictionary to label the 1D distributions according to the class methods.

Returns:
dict:

The dictionary with information about the 1D distributions.

property dict_2d_distributions#

Dictionary to label the 2D distributions according to the class methods.

Returns:
dict:

The dictionary with information about the 2D distributions.

event_1d_histogram(key, bins=50, hist_range=None)[source]#

Create a histogram for the all events using key as parameter. Valid keys are stored in self.all_event_keys (CORSIKA defined).

Parameters:
key: str

The information from which to build the histogram, e.g. total_energy, zenith or first_interaction_height.

bins: float

Number of bins for the histogram.

hist_range: 2-tuple

Tuple to define the range of the histogram.

Returns:
numpy.ndarray

The counts of the histogram.

numpy.array

Edges of the histogram.

Raises:
KeyError:

If key is not valid.

event_2d_histogram(key_1, key_2, bins=50, hist_range=None)[source]#

Create a 2D histogram for the all events using key_1 and key_2 as parameters. Valid keys are stored in self.all_event_keys (CORSIKA defined).

Parameters:
key_1: str

The information from which to build the histogram, e.g. total_energy, zenith or first_interaction_height.

key_2: str

The information from which to build the histogram, e.g. total_energy, zenith or first_interaction_height.

bins: float

Number of bins for the histogram.

hist_range: 2-tuple

Tuple to define the range of the histogram.

Returns:
numpy.ndarray

The counts of the histogram.

numpy.array

x Edges of the histogram.

numpy.array

y Edges of the histogram.

Raises:
KeyError:

If at least one of the keys is not valid.

property event_azimuth_angles#

Get the azimuth angles of the simulated events in astropy units of degrees.

Returns:
astropy.Quantity

The azimuth angles for each event, usually in degrees.

property event_energies#

Get the energy of the simulated events in astropy units of TeV.

Returns:
astropy.Quantity

The total energies of the incoming particles for each event, usually in TeV.

property event_first_interaction_heights#

Get the height of the first interaction in astropy units of km. If negative, tracking starts at margin of atmosphere, see TSTART in the CORSIKA 7 user guide .

Returns:
astropy.Quantity

The first interaction height for each event, usually in km.

property event_zenith_angles#

Get the zenith angles of the simulated events in astropy units of degrees.

Returns:
astropy.Quantity

The zenith angles for each event.

export_event_header_1d_histogram(event_header_element, bins=50, hist_range=None, overwrite=False)[source]#

Export to a hdf5 file the 1D histogram for the key ‘event_header_element’ from the CORSIKA event header.

Parameters:
event_header_element: str

The key to the CORSIKA event header element. Possible choices are stored in ‘self.all_event_keys’.

bins: float

Number of bins for the histogram.

hist_range: 2-tuple

Tuple to define the range of the histogram.

overwrite: bool

If True overwrites the histograms already saved in the hdf5 file.

export_event_header_2d_histogram(event_header_element_1, event_header_element_2, bins=50, hist_range=None, overwrite=False)[source]#

Export to a hdf5 file the 2D histogram for the key ‘event_header_element_1’ and ‘event_header_element_2’from the CORSIKA event header.

Parameters:
event_header_element_1: str

The key to the CORSIKA event header element.

event_header_element_2: str

The key to the CORSIKA event header element. Possible choices for ‘event_header_element_1’ and ‘event_header_element_2’ are stored in ‘self.all_event_keys’.

bins: float

Number of bins for the histogram.

hist_range: 2-tuple

Tuple to define the range of the histogram.

overwrite: bool

If True overwrites the histograms already saved in the hdf5 file.

export_histograms(overwrite=False)[source]#

Export the histograms to hdf5 files.

Parameters:
overwrite: bool

If True overwrites the histograms already saved in the hdf5 file.

get_2d_num_photons_distr()[source]#

Get the distribution of Cherenkov photons per event per telescope. It returns the 2D array accounting for the events from the telescopes given by self.telescope_indices.

Returns:
numpy.ndarray

The counts of the histogram.

numpy.array

An array that counts the telescopes in self.telescope_indices

numpy.array

Number of photons per event per telescope in self.telescope_indices.

get_2d_photon_density_distr()[source]#

Get 2D histograms of position of the Cherenkov photons on the ground. It returns the photon density per square meter.

Returns:
numpy.ndarray

The values of the histogram, usually in $m^{-2}$

numpy.array

The x bin edges of the density/count histograms in x, usually in meters.

numpy.array

The y bin edges of the density/count histograms in y, usually in meters.

get_2d_photon_direction_distr()[source]#

Get 2D histograms of incoming direction of the Cherenkov photons on the ground.

Returns:
numpy.ndarray

The counts of the histogram.

numpy.array

The x bin edges of the direction histograms in cos(x).

numpy.array

The y bin edges of the direction histograms in cos(y)

get_2d_photon_position_distr()[source]#

Get 2D histograms of position of the Cherenkov photons on the ground.

Returns:
numpy.ndarray

The counts of the histogram.

numpy.array

The x bin edges of the count histograms in x, usually in meters.

numpy.array

The y bin edges of the count histograms in y, usually in meters.

get_2d_photon_time_altitude_distr()[source]#

Get 2D histograms of the time and altitude of the photon production.

Returns:
numpy.ndarray

The counts of the histogram.

numpy.array

The x bin edges of the time_altitude histograms, usually in ns.

numpy.array

The y bin edges of the time_altitude histograms, usually in km.

get_event_parameter_info(parameter)[source]#

Get specific information (i.e. any parameter) of the events. The parameter is passed through the key word parameter. Available options are to be found under self.all_event_keys. The unit of the parameter, if any, is given according to the CORSIKA version (please see user guide in this case).

Parameters:
parameter: str

The parameter of interest. Available options are to be found under self.all_event_keys.

Returns:
astropy.Quantity

The array with the event information as required by the parameter.

Raises:
KeyError:

If parameter is not valid.

get_num_photons_per_event_distr(bins=50, hist_range=None)[source]#

Get the distribution of photons per event.

Parameters:
bins: float

Number of bins for the histogram.

hist_range: 2-tuple

Tuple to define the range of the histogram.

Returns:
numpy.ndarray

The counts of the histogram.

numpy.array

Number of photons per event.

get_num_photons_per_telescope_distr(bins=50, hist_range=None)[source]#

Get the distribution of photons per telescope.

Parameters:
bins: float

Number of bins for the histogram.

hist_range: 2-tuple

Tuple to define the range of the histogram.

Returns:
numpy.ndarray

The counts of the histogram.

numpy.array

Number of photons per telescope.

get_photon_altitude_distr()[source]#

Get the emission altitude of the Cherenkov photons.

Returns:
numpy.ndarray

The counts of the histogram.

numpy.array

The bin edges of the photon altitude histograms in km.

get_photon_density_distr(bins=None, max_dist=None)[source]#

Get the density distribution of the photons on the ground in relation to the center of the array.

Parameters:
bins: float

Number of bins of the radial distribution.

max_dist: float

Maximum distance to consider in the 1D histogram (in meters).

Returns:
np.array

The density distribution of the 1D histogram with size = int(max_dist/bin_size), usually in $m^{-2}$.

np.array

The bin edges of the 1D histogram in meters with size = int(max_dist/bin_size) + 1, usually in meter.

get_photon_radial_distr(bins=None, max_dist=None)[source]#

Get the radial distribution of the photons on the ground in relation to the center of the array.

Parameters:
bins: float

Number of bins of the radial distribution.

max_dist: float

Maximum distance to consider in the 1D histogram (in meters).

Returns:
np.array

The counts of the 1D histogram with size = int(max_dist/bin_size).

np.array

The bin edges of the 1D histogram in meters with size = int(max_dist/bin_size) + 1, usually in meter.

get_photon_time_of_emission_distr()[source]#
Get the distribution of the emitted time of the Cherenkov photons. The clock starts when the

particle crosses the top of the atmosphere (CORSIKA-defined) if self.event_first_interaction_heights is positive or at first interaction if otherwise.

Returns:
numpy.ndarray

The counts of the histogram.

numpy.array

The bin edges of the time histograms in ns.

get_photon_wavelength_distr()[source]#

Get histograms with the wavelengths of the photon bunches.

Returns:
np.array

The counts of the wavelength histogram.

np.array

The bin edges of the wavelength histogram in nanometers.

get_run_info(parameter)[source]#

Get specific information (i.e. any parameter) of the run. The parameter is passed through the key word parameter. Available options are to be found under self.all_run_keys. The unit of the parameter, if any, is given according to the CORSIKA version (please see user guide in this case).

Parameters:
parameter: str

The parameter of interest. Available options are to be found under self.all_run_keys.

Raises:
KeyError:

If parameter is not valid.

property hdf5_file_name#

Property for the hdf5 file name. The idea of this property is to allow setting (or changing) the name of the hdf5 file even after creating the class instance.

property header#

Get the run header.

Returns:
dict:

The run header.

property hist_config#

The configuration of the histograms.

Returns:
dict:

the dictionary with the histogram configuration.

hist_config_to_yaml(file_name=None)[source]#

Save the histogram configuration dictionary to a yaml file.

Parameters:
file_name: str

Name of the output file, in which to save the histogram configuration.

property individual_telescopes#

Return the individual telescopes as property.

property magnetic_field#

Get the Earth magnetic field from the events header in astropy units of microT. A tuple with Earth’s magnetic field in the x and z directions are returned.

Returns:
astropy.Quantity

The Earth magnetic field in the x direction used for each event.

astropy.Quantity

The Earth magnetic field in the z direction used for each event.

property num_photons_per_event#
Get the distribution of the number of photons amongst the events,

including the telescopes indicated by self.telescope_indices.

Returns:
numpy.array

Number of photons per event.

property num_photons_per_event_per_telescope#

The number of photons per event per telescope.

property num_photons_per_telescope#

The number of photons per event, considering the telescopes given by self.telescope_indices.

Returns:
numpy.array

Number of photons per telescope.

read_event_information()[source]#

Read the information about the events from their headers and save as a class instance. The main information can also be fetched individually through the functions below. For the remaining information (such as px, py, pz), use this function.

set_histograms(telescope_indices=None, individual_telescopes=None, hist_config=None)[source]#
Extract the information of the Cherenkov photons from a CORSIKA output IACT file, create

and fill the histograms

Parameters:
telescope_indices: int or list of int

The indices of the specific telescopes to be inspected.

individual_telescopes: bool

if False, the histograms are supposed to be filled for all telescopes. Default is False. if True, one histogram is set for each telescope separately.

hist_config:

yaml file with the configuration parameters to create the histograms. For the correct format, please look at the docstring of _create_histogram_default_config. Alternatively, it can be a dictionary with the configuration parameters to create the histograms.

Returns:
list: list of boost_histogram.Histogram instances.
Raises:
AttributeError:

if event has not photon saved.

property telescope_indices#

The telescope index (or indices), which are considered for the production of the histograms.

Returns:
list:

The indices of the telescopes of interest.

property telescope_positions#

The telescope positions found in the CORSIKA output file. It does not depend on the telescope_indices attribute.

Returns:
numpy.ndarray

x, y and z positions of the telescopes and their radius according to the CORSIKA spherical representation of the telescopes.

property total_num_photons#

The total number of photons.

Returns:
float

Total number photons.

exception corsika.corsika_histograms.HistogramNotCreatedError[source]#

Exception for histogram not created.

corsika_histograms_visualize#

corsika.corsika_histograms_visualize.plot_1d_event_header_distribution(histograms_instance, event_header_element, log_y=True, bins=50, hist_range=None)[source]#

Plots the distribution of the quantity given by .

Parameters:
histograms_instance: corsika.corsika_histograms.CorsikaHistograms

instance of corsika.corsika_histograms.CorsikaHistograms.

event_header_element: str

The key to the CORSIKA event header element.

log_y: bool

if True, the intensity of the Y axis is given in logarithmic scale.

bins: float

Number of bins for the histogram.

hist_range: 2-tuple

Tuple to define the range of the histogram.

Returns:
list

List of figures for the given telescopes.

corsika.corsika_histograms_visualize.plot_2d_counts(histograms_instance, log_z=True)[source]#

Plot the 2D histogram of the photon positions on the ground.

Parameters:
histograms_instance: corsika.corsika_histograms.CorsikaHistograms

instance of corsika.corsika_histograms.CorsikaHistograms.

log_z: bool

if True, the intensity of the color bar is given in logarithmic scale.

Returns:
list

List of figures for the given telescopes.

corsika.corsika_histograms_visualize.plot_2d_density(histograms_instance, log_z=True)[source]#

Plot the 2D histogram of the photon density distribution on the ground.

Parameters:
histograms_instance: corsika.corsika_histograms.CorsikaHistograms

instance of corsika.corsika_histograms.CorsikaHistograms.

log_z: bool

if True, the intensity of the color bar is given in logarithmic scale.

Returns:
list

List of figures for the given telescopes.

corsika.corsika_histograms_visualize.plot_2d_direction(histograms_instance, log_z=True)[source]#

Plot the 2D histogram of the incoming direction of photons.

Parameters:
histograms_instance: corsika.corsika_histograms.CorsikaHistograms

instance of corsika.corsika_histograms.CorsikaHistograms.

log_z: bool

if True, the intensity of the color bar is given in logarithmic scale.

Returns:
list

List of figures for the given telescopes.

corsika.corsika_histograms_visualize.plot_2d_event_header_distribution(histograms_instance, event_header_element_1, event_header_element_2, log_z=True, bins=50, hist_range=None)[source]#

Plots the distribution of the quantity given by .

Parameters:
histograms_instance: corsika.corsika_histograms.CorsikaHistograms

instance of corsika.corsika_histograms.CorsikaHistograms.

event_header_element_1: str

The first key to the CORSIKA event header element

event_header_element_2: str

The second key to the CORSIKA event header element.

log_z: bool

if True, the intensity of the Y axis is given in logarithmic scale.

bins: float

Number of bins for the histogram.

hist_range: 2-tuple

Tuple to define the range of the histogram.

Returns:
list

List of figures for the given telescopes.

corsika.corsika_histograms_visualize.plot_2d_num_photons_per_telescope(histograms_instance, log_z=True)[source]#

Plot the 2D histogram of the number of photons per event and per telescope.

Parameters:
histograms_instance: corsika.corsika_histograms.CorsikaHistograms

instance of corsika.corsika_histograms.CorsikaHistograms.

log_z: bool

if True, the intensity of the color bar is given in logarithmic scale.

Returns:
list

List of figures for the given telescopes.

corsika.corsika_histograms_visualize.plot_2d_time_altitude(histograms_instance, log_z=True)[source]#

Plot the 2D histogram of the time and altitude where the photon was produced.

Parameters:
histograms_instance: corsika.corsika_histograms.CorsikaHistograms

instance of corsika.corsika_histograms.CorsikaHistograms.

log_z: bool

if True, the intensity of the color bar is given in logarithmic scale.

Returns:
list

List of figures for the given telescopes.

corsika.corsika_histograms_visualize.plot_altitude_distr(histograms_instance, log_y=True)[source]#

Plots the distribution of altitude in which the photons were generated in km.

Parameters:
histograms_instance: corsika.corsika_histograms.CorsikaHistograms

instance of corsika.corsika_histograms.CorsikaHistograms.

log_y: bool

if True, the intensity of the Y axis is given in logarithmic scale.

Returns:
list

List of figures for the given telescopes.

corsika.corsika_histograms_visualize.plot_counts_distr(histograms_instance, log_y=True)[source]#

Plots the 1D distribution, i.e. the radial distribution, of the photons on the ground.

Parameters:
histograms_instance: corsika.corsika_histograms.CorsikaHistograms

instance of corsika.corsika_histograms.CorsikaHistograms.

log_y: bool

if True, the intensity of the Y axis is given in logarithmic scale.

Returns:
list

List of figures for the given telescopes.

corsika.corsika_histograms_visualize.plot_density_distr(histograms_instance, log_y=True)[source]#

Plots the photon density distribution on the ground.

Parameters:
histograms_instance: corsika.corsika_histograms.CorsikaHistograms

instance of corsika.corsika_histograms.CorsikaHistograms.

log_y: bool

if True, the intensity of the Y axis is given in logarithmic scale.

Returns:
list

List of figures for the given telescopes.

corsika.corsika_histograms_visualize.plot_photon_per_event_distr(histograms_instance, log_y=True)[source]#

Plots the distribution of the number of Cherenkov photons per event.

Parameters:
histograms_instance: corsika.corsika_histograms.CorsikaHistograms

instance of corsika.corsika_histograms.CorsikaHistograms.

log_y: bool

if True, the intensity of the Y axis is given in logarithmic scale.

Returns:
list

List of figures for the given telescopes.

corsika.corsika_histograms_visualize.plot_photon_per_telescope_distr(histograms_instance, log_y=True)[source]#

Plots the distribution of the number of Cherenkov photons per telescope.

Parameters:
histograms_instance: corsika.corsika_histograms.CorsikaHistograms

instance of corsika.corsika_histograms.CorsikaHistograms.

log_y: bool

if True, the intensity of the Y axis is given in logarithmic scale.

Returns:
list

List of figures for the given telescopes.

corsika.corsika_histograms_visualize.plot_time_distr(histograms_instance, log_y=True)[source]#

Plots the distribution times in which the photons were generated in ns.

Parameters:
histograms_instance: corsika.corsika_histograms.CorsikaHistograms

instance of corsika.corsika_histograms.CorsikaHistograms.

log_y: bool

if True, the intensity of the Y axis is given in logarithmic scale.

Returns:
list

List of figures for the given telescopes.

corsika.corsika_histograms_visualize.plot_wavelength_distr(histograms_instance, log_y=True)[source]#

Plots the 1D distribution of the photon wavelengths

Parameters:
histograms_instance: corsika.corsika_histograms.CorsikaHistograms

instance of corsika.corsika_histograms.CorsikaHistograms.

log_y: bool

if True, the intensity of the Y axis is given in logarithmic scale.

Returns:
list

List of figures for the given telescopes.

corsika.corsika_histograms_visualize.save_figs_to_pdf(figs, pdf_file_name)[source]#

Save figures from corsika histograms to an output pdf file.

Parameters:
figs: list or numpy.array

List with the figures output by corsika_output_visualize.py.

pdf_file_name: str or Path

Name of the pdf file.

corsika_runner#

class corsika.corsika_runner.CorsikaRunner(array_model, simtel_source_path, label=None, keep_seeds=False, corsika_parameters_file=None, corsika_config_data=None, use_multipipe=False)[source]#

CorsikaRunner is responsible for running CORSIKA, through the corsika_autoinputs program provided by the sim_telarray package. It provides shell scripts to be run externally or by the module simulator. Same instance can be used to generate scripts for any given run number.

It uses CorsikaConfig to manage the CORSIKA configuration. User parameters must be given by the corsika_config_data or corsika_config_file arguments. An example of corsika_config_data follows below.

corsika_config_data = {
    'data_directory': .
    'primary': 'proton',
    'nshow': 10000,
    'nrun': 1,
    'zenith': 20 * u.deg,
    'viewcone': 5 * u.deg,
    'erange': [10 * u.GeV, 100 * u.TeV],
    'eslope': -2,
    'phi': 0 * u.deg,
    'cscat': [10, 1500 * u.m, 0]
}

The remaining CORSIKA parameters can be set as a yaml file, using the argument corsika_parameters_file. When not given, corsika_parameters will be loaded from data/parameters/corsika_parameters.yml.

The CORSIKA output directory must be set by the data_directory entry. The following directories will be created to store the logs and input file: {data_directory}/corsika/$site/$primary/logs {data_directory}/corsika/$site/$primary/scripts

Parameters:
array_model: ArrayModel

Array model instance.

simtel_source_path: str or Path

Location of source of the sim_telarray/CORSIKA package.

label: str

Instance label.

keep_seeds: bool

Use seeds based on run number and primary particle. If False, use sim_telarray seeds.

corsika_parameters_file: str or Path

Path to yaml file containing CORSIKA parameters.

corsika_config_data: dict

Dict with CORSIKA config data.

use_multipipe: bool

Use multipipe to run CORSIKA and sim_telarray.

get_file_name(file_type, **kwargs)[source]#

Get a CORSIKA style file name for various file types.

Parameters:
file_type: str

The type of file (determines the file suffix). Choices are corsika_autoinputs_log, corsika_log, script, output or sub_log.

kwargs: dict
The dictionary must include the following parameters (unless listed as optional):
run: int

Run number.

primary: str

Primary particle (e.g gamma, proton etc).

site: str

Site name (usually North/South or Paranal/LaPalma).

array_name: str

Array name.

label: str

Instance label (optional).

mode: str

out or err (optional, relevant only for sub_log).

Returns:
str

File name with full path.

Raises:
ValueError

If file_type is unknown.

get_info_for_file_name(run_number)[source]#

Get a dictionary with the info necessary for building the CORSIKA runner file names.

Returns:
dict

Dictionary with the keys necessary for building the CORSIKA runner file names.

get_resources(run_number=None)[source]#

Read run time of job from last line of submission log file.

Parameters:
run_number: int

Run number.

Returns:
dict

run time and number of simulated events

has_file(file_type, run_number=None, mode='out')[source]#

Checks that the file of file_type for the specified run number exists.

Parameters:
file_type: str

File type to check. Choices are corsika_autoinputs_log, corsika_log, script, output or sub_log.

run_number: int

Run number.

prepare_run_script(use_pfp=True, **kwargs)[source]#

Get the full path of the run script file for a given run number.

Parameters:
use_pfp: bool

Whether to use the preprocessor in preparing the CORSIKA input file

kwargs: dict
The following optional parameters can be provided:
run_number: int

Run number.

extra_commands: str

Additional commands for running simulations.

Returns:
Path:

Full path of the run script file.

exception corsika.corsika_runner.MissingRequiredEntryInCorsikaConfigError[source]#

Exception for missing required entry in corsika config.