CORSIKA#

Support modules for running CORSIKA.

build_options#

Read and validate CORSIKA build variants.

class corsika.build_options.CorsikaBuildVariant(executable, config, atmosphere_geometry, he_hadronic_model, le_hadronic_model, hadronic_transition_energy_default_gev=None)[source]#

One executable variant declared by a CORSIKA build.

classmethod from_mapping(entry)[source]#

Create a variant from a build-options mapping.

Parameters:
entrydict

One entry from the variant list in build_opts.yml.

Returns:
CorsikaBuildVariant

Validated and normalized variant.

Raises:
ValueError

If a required field is missing or invalid.

corsika.build_options.corsika_executable(software, geometry)[source]#

Return the configured CORSIKA executable for an atmosphere geometry.

corsika.build_options.format_corsika_build_variants(variants)[source]#

Format installed CORSIKA build variants as a compact table.

Parameters:
variantsiterable of CorsikaBuildVariant

Available variants.

Returns:
str

Human-readable table.

corsika.build_options.get_corsika_build_report(corsika_path=None)[source]#

Return a report of installed CORSIKA interaction-model variants.

Parameters:
corsika_pathstr or Path, optional

CORSIKA installation directory. If omitted, use SIMTOOLS_CORSIKA_PATH and then the simtools default path.

Returns:
str

Human-readable table of installed variants.

Raises:
FileNotFoundError

If the build manifest is missing.

PermissionError

If a declared executable is not executable.

ValueError

If the manifest is invalid or declares a missing executable.

corsika.build_options.get_installed_corsika_build_variants(corsika_path)[source]#

Return build variants whose declared executables are installed.

Parameters:
corsika_pathstr or Path

CORSIKA installation directory.

Returns:
tuple of CorsikaBuildVariant

Validated installed variants.

Raises:
FileNotFoundError

If the manifest is missing.

ValueError

If the manifest declares a missing executable.

PermissionError

If a declared executable is not executable.

corsika.build_options.read_corsika_build_variants(corsika_path)[source]#

Read CORSIKA executable variants from build_opts.yml.

Parameters:
corsika_pathstr or Path

CORSIKA installation directory.

Returns:
tuple of CorsikaBuildVariant

Installed executable variants.

Raises:
FileNotFoundError

If the build-options file is unavailable.

ValueError

If the file is malformed, contains no variants, or declares duplicates.

corsika.build_options.select_corsika_build_variant(variants, he_model, le_model, geometry)[source]#

Select one CORSIKA build variant.

Parameters:
variantsiterable of CorsikaBuildVariant

Available variants.

he_modelstr

High-energy hadronic interaction model.

le_modelstr

Low-energy hadronic interaction model.

geometrystr

Atmosphere geometry (flat or curved).

Returns:
CorsikaBuildVariant

The unique matching variant.

Raises:
ValueError

If the requested combination is unavailable.

corsika.build_options.with_installed_build_variants(software)[source]#

Return software configuration enriched with installed CORSIKA variants.

input_writer#

Serialize model parameter values for CORSIKA input cards.

corsika.input_writer.format_parameter(parameter_name, value, unit=None)[source]#

Format a value using the CORSIKA format declared in its parameter schema.

corsika.input_writer.format_value(value, format_name, unit=None)[source]#

Format a value using a schema-declared CORSIKA input format.

corsika_config#

CORSIKA configuration.

class corsika.corsika_config.CorsikaConfig(array_model, run_number, label=None, context=None)[source]#

Configuration for the CORSIKA air shower simulation software.

Follows closely the CORSIKA definitions and output format (see CORSIKA manual).

The configuration is set as a dict corresponding to the command line configuration groups (especially simulation_software, simulation configuration, simulation parameters).

Parameters:
array_modelArrayModel

Array model.

run_numberint

Run number.

labelstr

Instance label.

assert_corsika_configurations_match(model_versions)[source]#

Assert that CORSIKA configurations match across all model versions.

Parameters:
model_versionslist

List of model versions to check.

Raises:
InvalidCorsikaInputError

If CORSIKA parameters are not identical across all model versions.

generate_corsika_input_file(use_multipipe, input_file, output_file)[source]#

Generate a CORSIKA input file.

Parameters:
use_multipipe: bool

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

input_file: Path

Path to the input file to be generated.

output_file: Path

Path to the output file to be generated.

get_config_parameter(par_name)[source]#

Get value of CORSIKA configuration 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.

get_corsika_telescope_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.

is_calibration_run()[source]#

Check if this simulation is a calibration run.

Returns:
bool

True if it is a calibration run, False otherwise.

property primary_particle#

Primary particle.

property simulation_parameters#

Return physical run settings without CORSIKA steering cards.

property use_curved_atmosphere#

Check if zenith angle condition for curved atmosphere usage for CORSIKA is met.

corsika.corsika_config.corsika_telescope_ids(telescope_models)[source]#

IACT telescope id of each telescope: its position in the CORSIKA TELESCOPE list.

The telescopes are listed in the order of telescope_models, as in CorsikaConfig.get_corsika_telescope_list. The ids start at 0: the telescope blocks of the CORSIKA IACT output are numbered from 0 (verified on a CORSIKA IACT file).

Parameters:
telescope_models: dict

Telescope models keyed by array element name.

Returns:
dict

IACT telescope id of each array element name.

corsika.corsika_config.get_site_config_parameters(site_model, model_directory=None)[source]#

Translate site quantities into CORSIKA7 configuration parameters.

Parameters:
site_modelSiteModel

Resolved site model with atmosphere and geomagnetic field.

model_directorypathlib.Path, optional

Directory containing the atmospheric profile.

Returns:
dict

Native CORSIKA7 site configuration.

photon_bunches#

Read photon bunches from CORSIKA IACT EventIO files.

Photon bunches (EventIO objects 1204 containing 1205 in long format) are read per event and telescope. Values are kept in the units of the file (cm, ns, nm). Files are read from a path or from an uncompressed binary stream (e.g. a pipe).

corsika.photon_bunches.iter_photon_objects(file_name, on_object=None)[source]#

Yield each input object, its raw bytes, and parsed telescope blocks if present.

The callback runs after the consumer has processed each top-level object.

corsika.photon_bunches.read_photon_bunches(file_name, on_object=None)[source]#

Read photon bunches of each event and telescope from a CORSIKA IACT EventIO file or stream.

Bunches with a wavelength of 1 nm or of 9000 nm and above are skipped and counted. The bunch id combines the event number and the index of the bunch within the telescope’s bunch array (before skipping).

Parameters:
file_name: str, Path or binary stream

CORSIKA IACT EventIO file with photon bunches in long format, or an uncompressed binary stream of such data (e.g. sys.stdin.buffer or a pipe). Streams are read once, forward only.

on_object: callable or None

Called with each top-level EventIO object after its photon bunches have been yielded and the consumer has asked for the next item, i.e. once the object is processed. Objects of other types are passed too.

Returns:
Iterator[dict]

Photon bunches of one telescope in one event with keys event_number, telescope_id, array_id (array index of the telescope block, 0 for a single array), x, y, cx, cy, time_ns, zem, size, wavelength_nm, bunch_id, skipped_bunches, wavelength_min_nm and wavelength_max_nm (event-header wavelength limits, None if absent).

Raises:
TypeError

If file_name is neither a path nor a binary stream (e.g. a text stream).

NotImplementedError

If the file contains photon bunches in compact format.

ValueError

If the file contains photo-electron bunches (negative wavelength).

corsika_histograms#

Extract Cherenkov photons from a CORSIKA IACT file and fill histograms.

class corsika.corsika_histograms.CorsikaHistograms(input_file, normalization_method='per-telescope', axis_distance=<Quantity 1000. m>)[source]#

Extract Cherenkov photons from a CORSIKA IACT file and fill histograms.

Parameters:
input_file: str or Path

CORSIKA IACT file.

axis_distance: astropy.units.Quantity or float

Distance from the axis to consider when calculating the lateral density profiles along x and y axes. If a float is given, it is assumed to be in meters.

Raises:
FileNotFoundError:

if the input file given does not exist.

fill()[source]#

Fill Cherenkov photons histograms.

get_hist_1d_projection(label, hist)[source]#

Get 1D distributions from event data or weighted histograms.

Parameters:
label: str

Histogram label.

hist: dict

Histogram dictionary.

Returns:
numpy.ndarray

Histogram counts.

numpy.array

Histogram x bin edges.

numpy.ndarray or None

Histogram uncertainties (if available).

get_hist_2d_projection(hist)[source]#

Get 2D distributions.

Parameters:
hist: histogram

Histogram with axes and a weighted or unweighted view.

Returns:
numpy.ndarray

Histogram counts.

numpy.array

Histogram x bin edges.

numpy.array

Histogram y bin edges.

numpy.ndarray or None

Histogram uncertainties (sqrt of variance) if available.