sim_telarray#

Support modules for running sim_telarray.

simtel_config_reader#

Read model parameters and configuration from sim_telarray configuration files.

class simtel.simtel_config_reader.SimtelConfigReader(schema_file=None, simtel_config_file=None, simtel_telescope_name=None, parameter_name=None, camera_pixels=None)[source]#

Reads model parameters from configuration files and converts to the simtools representation.

The output format are simtool-db-style json dicts. Model parameters are read from sim_telarray configuration files. The sim_telarray configuration can be generated using e.g., the following sim_telarray command:

… code-block:: console

sim_telarray/bin/sim_telarray -c sim_telarray/cfg/CTA/CTA-PROD6-LaPalma.cfg -C limits=no-internal -C initlist=no-internal -C list=no-internal -C typelist=no-internal -C maximum_telescopes=30 -DNSB_AUTOSCALE -DNECTARCAM -DHYPER_LAYOUT -DNUM_TELESCOPES=30 /dev/null 2>|/dev/null | grep ‘(@cfg)’ | sed ‘s/^(@cfg)

Parameters:
schema_file: str

Schema file describing the model parameter.

simtel_config_file: str or Path

Path of the file to read from.

simtel_telescope_name: str

Telescope name (sim_telarray convention)

parameter_name: str

Parameter name (default: read from schema file)

camera_pixels: int

Number of camera pixels

compare_simtel_config_with_schema()[source]#

Compare limits and defaults reported by sim_telarray with schema.

This is mostly for debugging purposes and includes simple printing. Check for differences in ‘default’ and ‘limits’ entries.

extract_value_from_sim_telarray_column(column, dtype=None, n_dim=1, default=None, is_limit=False)[source]#

Extract value(s) from sim_telarray configuration file columns.

This function is fine-tuned to the sim_telarray configuration output.

Parameters:
column: list

List of strings to extract value from.

dtype: str

Data type to convert value to.

n_dim: int

Length of array to be returned.

default: object

Default value to extend array to required length.

Returns:
object, int

Values extracted from column. Of object is a list of array, return length of array.

read_simtel_config_file(simtel_config_file, simtel_telescope_name)[source]#

Read sim_telarray configuration file and return a dictionary with the parameter values.

Parameters:
simtel_config_file: str or Path

Path of the file to read from.

simtel_telescope_name: str

Telescope name (sim_telarray convention)

Returns:
dict

Dictionary with the parameter values.

simtel_config_writer#

Configuration file writer for sim_telarray.

class simtel.simtel_config_writer.SimtelConfigWriter(site, model_version, layout_name=None, telescope_model_name=None, label=None)[source]#

SimtelConfigWriter writes sim_telarray configuration files.

It is designed to be used by model classes (TelescopeModel and ArrayModel) only.

Parameters:
site: str

South or North.

model_version: str

Model version.

telescope_model_name: str

Telescope model name.

layout_name: str

Layout name.

label: str

Instance label. Important for output file naming.

write_array_config_file(config_file_path, telescope_model, site_model, sim_telarray_seeds=None)[source]#

Write the sim_telarray config file for an array of telescopes.

Parameters:
config_file_path: str or Path

Path of the file to write on.

telescope_model: dict of TelescopeModel

Dictionary of TelescopeModel’s instances as used by the ArrayModel instance.

site_model: Site model

Site model.

sim_telarray_seeds: dict

Dictionary with configuration for sim_telarray random instrument setup.

write_dummy_telescope_configuration_file(parameters, config_file_path, telescope_name)[source]#

Write ‘dummy’ telescope configuration file used as zeroth telescope in sim_telarray.

Replaces key telescope configuration values with dummy values.

Parameters:
parameters: dict

Telescope parameters used as template.

config_file_path: str or Path

Path of the dummy configuration file to write on.

telescope_name: str

Name of the telescope.

write_single_mirror_list_file(mirror_number, mirrors, single_mirror_list_file, set_focal_length_to_zero=False)[source]#

Write the sim_telarray mirror list file for a single mirror.

Parameters:
mirror_number: int

Mirror number.

mirrors: Mirrors

Instance of Mirrors.

single_mirror_list_file: str or Path

Path of the file to write on.

set_focal_length_to_zero: bool

Flag to set the focal length to zero.

write_telescope_config_file(config_file_path, parameters, telescope_name=None, write_dummy_config=False)[source]#

Write the sim_telarray config file for a single telescope.

Parameters:
config_file_path: str or Path

Path of the file to write on.

parameters: dict

Model parameters

telescope_name: str

Name of the telescope (use self._telescope_model_name if None)

write_dummy_config: bool

Flag to write a dummy telescope configuration file.

simtel_table_reader#

Read tabular data in sim_telarray format and return as astropy table.

simtel.simtel_table_reader.read_simtel_table(parameter_name, file_path)[source]#

Read sim_telarray table file for a given parameter.

Parameters:
parameter_name: str

Model parameter name.

file_path: Path

Name (full path) of the sim_telarray table file.

Returns:
Table

Astropy table.

simtel_io_event_reader#

Read a reduced dataset from file.

Allow to filter the events based on the triggered telescopes. Provide functionality to list events, e.g. through

from simtools.simtel.simtel_io_event_reader import SimtelIOEventDataReader
reader = SimtelIOEventDataReader("gamma_diffuse_60deg.hdf5", [1,2,3,4])
reader.print_event_table()
class simtel.simtel_io_event_reader.SimtelIOEventDataReader(event_data_file, telescope_list=None)[source]#

Read reduced MC data set from file.

Calculate some standard derivation like core position in shower coordinates.

Parameters:
event_data_filestr

Path to the HDF5 file containing the event data.

telescope_listlist, optional

List of telescope IDs to filter the events (default is None).

print_dataset_information(n_events=1)[source]#

Print information about the datasets.

print_event_table(lines_per_page=20)[source]#

Print event table with pagination.

Parameters:
lines_per_pageint

Number of lines to display before pausing (default: 20)

read_event_data(event_data_file)[source]#

Read event data from the reduced MC event data file.

Parameters:
event_data_filestr, Path

Path to the HDF5 file containing the event data.

Returns:
ShowerEventData, TriggeredEventData

Event data and triggered event data.

simtel_io_event_writer#

Generate a reduced dataset from given simulation event list and save the output to file.

class simtel.simtel_io_event_writer.ShowerEventData(simulated_energy: list = <factory>, x_core: list = <factory>, y_core: list = <factory>, shower_azimuth: list = <factory>, shower_altitude: list = <factory>, shower_id: list = <factory>, area_weight: list = <factory>, x_core_shower: list = <factory>, y_core_shower: list = <factory>, core_distance_shower: list = <factory>)[source]#

Shower event data.

class simtel.simtel_io_event_writer.SimtelIOEventDataWriter(input_files, output_file, max_files=100)[source]#

Generate a reduced dataset from given simulation event list and save the output to file.

Attributes:
input_fileslist

List of input file paths to process.

output_filestr

Path to the output file.

max_filesint, optional

Maximum number of files to process.

get_event_data()[source]#

Return shower and triggered event data.

Returns:
ShowerEventData, TriggeredEventData

Shower and triggered event data.

process_files()[source]#

Process the input files and store them in an file.

class simtel.simtel_io_event_writer.TriggeredEventData(triggered_id: list = <factory>, array_altitudes: list = <factory>, array_azimuths: list = <factory>, trigger_telescope_list_list: list = <factory>, angular_distance: list = <factory>)[source]#

Triggered event data.

simtel_io_histograms#

Reads the content of multiples files from sim_telarray.

class simtel.simtel_io_histograms.SimtelIOHistograms(histogram_files, test=False, area_from_distribution=False, energy_range=None, view_cone=None)[source]#

Read the content of either multiple histogram (.hdata, or .hdata.zst) or sim_telarray files.

Allow both the .hdata.zst histogram and the .simtel.zst output file type. It uses the SimtelIOHistogram class to deal with individual files. Histogram files are ultimately handled by using eventio library.

Parameters:
histogram_files: list

List of sim_telarray histogram files (str of Path).

test: bool

If True, only a fraction of the histograms will be processed, leading to a much shorter runtime.

area_from_distribution: bool

If true, the area thrown (the area in which the simulated events are distributed) in the trigger rate calculation is estimated based on the event distribution. The expected shape of the distribution of events as function of the core distance is triangular up to the maximum distance. The weighted mean radius of the triangular distribution is 2/3 times the upper edge. Therefore, when using the area_from_distribution flag, the mean distance times 3/2, returns just the position of the upper edge in the triangle distribution with little impact of the binning and little dependence on the scatter area defined in the simulation. This is special useful when calculating trigger rate for individual telescopes. If false, the area thrown is estimated based on the maximum distance as given in the simulation configuration.

energy_range: list

The energy range used in the simulation. It must be passed as a list of floats and the energy must be in TeV (as in the CORSIKA configuration). This argument is only needed and used if histogram_file is a .hdata file, in which case the energy range cannot be retrieved directly from the file.

view_cone: list

The view cone used in the simulation. It must be passed as a list of floats and the view cone must be in deg (as in the CORSIKA configuration). This argument is only needed and used if histogram_file is a .hdata file, in which case the view cone cannot be retrieved directly from the file.

calculate_trigger_rates(print_info=False, stack_files=False)[source]#

Calculate the triggered and simulated event rate considering the histograms in each file.

It returns also a list with the tables where the energy dependent trigger rate for each file can be found.

Parameters:
print_info: bool

if True, prints out the information about the histograms such as energy range, area, etc.

stack_files: bool

if True, stack the histograms from the different files into single histograms. Useful to increase event statistics when calculating the trigger rate.

Returns:
sim_event_rates: list of astropy.Quantity[1/time]

The simulated event rates.

triggered_event_rates: list of astropy.Quantity[1/time]

The triggered event rates.

triggered_event_rate_uncertainties: list of astropy.Quantity[1/time]

The uncertainties in the triggered event rates.

trigger_rate_in_tables: list of astropy.QTable

The energy dependent trigger rates. Only filled if stack_files is False.

property combined_hists#

Combine histograms of same type of histogram.

Histograms are read from various lists into a single histogram list.

export_histograms(hdf5_file_name, overwrite=False)[source]#

Export sim_telarray histograms to hdf5 files.

Parameters:
hdf5_file_name: str

Name of the file to be saved with the hdf5 tables.

overwrite: bool

If True overwrites histograms already saved in the hdf5 file.

get_stacked_num_events()[source]#

Return stacked number of simulated events and triggered events.

Returns:
int:

total number of simulated events for the stacked dataset.

int:

total number of triggered events for the stacked dataset.

property list_of_histograms#

Returns a list with the histograms for each file.

Returns:
list:

List of histograms.

property number_of_files#

Returns number of histograms.

plot_one_histogram(histogram_index, ax)[source]#

Plot a single histogram referent to the index histogram_index.

Parameters:
histogram_index: int

Index of the histogram to be plotted.

ax: matplotlib.axes.Axes

Instance of matplotlib.axes.Axes in which to plot the histogram.

simtel_io_metadata#

Read metadata from sim_telarray files.

simtel.simtel_io_metadata.get_sim_telarray_telescope_id(telescope_name, file)[source]#

Return the telescope ID for a given telescope name in a sim_telarray file.

Translates e.g. ‘LSTN-01’ to the corresponding telescope ID.

Parameters:
telescope_name: str

Name of the telescope.

file: str

Path to the sim_telarray file.

Returns:
int, None

Telescope ID. Returns None if not found.

simtel.simtel_io_metadata.read_sim_telarray_metadata(file, encoding='utf8')[source]#

Return global and per-telescope metadata from sim_telarray file.

Cached to avoid re-reading the file multiple times.

Parameters:
file: str

Path to the sim_telarray file.

encoding: str

Encoding to use for decoding metadata. Default is ‘utf8’.

Returns:
global_meta: dict

Global metadata dictionary.

telescope_meta: dict

Dictionary of telescope metadata, keyed by telescope ID.

simtel_io_file_info#

Read file info and run headers from sim_telarray files.

simtel.simtel_io_file_info.get_corsika_run_header(file)[source]#

Return the CORSIKA run header information from a sim_telarray file.

Reads both RunHeader and MCRunHeader object from file and returns a merged dictionary. Adds primary id from the first event.

Parameters:
file: str

Path to the sim_telarray file.

Returns:
dict, None

CORSIKA run header. Returns None if not found.

simtel.simtel_io_file_info.get_corsika_run_number(file)[source]#

Return the CORSIKA run number from a sim_telarray file.

Parameters:
file: str

Path to the sim_telarray file.

Returns:
int, None

CORSIKA run number. Returns None if not found.

simulator_array#

Simulation runner for array simulations.

class simtel.simulator_array.SimulatorArray(corsika_config, simtel_path, label=None, use_multipipe=False, sim_telarray_seeds=None)[source]#

SimulatorArray is the interface with sim_telarray to perform array simulations.

Parameters:
corsika_config_data: CorsikaConfig

CORSIKA configuration.

simtel_path: str or Path

Location of source of the sim_telarray/CORSIKA package.

label: str

Instance label.

use_multipipe: bool

Use multipipe to run CORSIKA and sim_telarray.

sim_telarray_seeds: dict

Dictionary with configuration for sim_telarray random instrument setup.

static get_power_law_for_sim_telarray_histograms(primary)[source]#

Get the power law index for sim_telarray.

Events will be histogrammed in sim_telarray with a weight according to the difference between this exponent and the one used for the shower simulations.

Parameters:
primary: str

Primary particle.

Returns:
float

Power law index.

make_run_command(run_number=None, input_file=None, weak_pointing=None)[source]#

Build and return the command to run sim_telarray.

Parameters:
input_file: str

Full path of the input CORSIKA file

run_number: int (optional)

run number

weak_pointing: bool (optional)

Specify weak pointing option for sim_telarray.

Returns:
str

Command to run sim_telarray.

simulator_camera_efficiency#

Simulation runner for camera efficiency calculations.

class simtel.simulator_camera_efficiency.SimulatorCameraEfficiency(telescope_model, site_model, label=None, simtel_path=None, file_simtel=None, file_log=None, zenith_angle=None, nsb_spectrum=None, skip_correction_to_nsb_spectrum=False)[source]#

Interface with the testeff tool of sim_telarray to perform camera efficiency simulations.

Parameters:
telescope_model: TelescopeModel

Instance of TelescopeModel class.

site_model: SiteModel

Instance of SiteModel class.

label: str

Instance label. Important for output file naming.

simtel_path: str or Path

Location of sim_telarray installation.

file_simtel: str or Path

Location of the sim_telarray testeff tool output file.

zenith_angle: float

Zenith angle given in the config to CameraEfficiency.

nsb_spectrum: str or Path

Path to the nsb spectrum file.

skip_correction_to_nsb_spectrum: bool

If True, skip the correction to the original altitude where the NSB spectrum was derived.

property nsb_spectrum#

nsb_spectrum property.

simulator_light_emission#

Simulation using the light emission package for calibration.

class simtel.simulator_light_emission.SimulatorLightEmission(telescope_model, calibration_model, site_model, light_emission_config, le_application, simtel_path, light_source_type, label=None, test=False)[source]#

Interface with sim_telarray to perform light emission package simulations.

The light emission package is used to simulate an artificial light source, used for calibration.

calculate_distance_telescope_calibration_device()[source]#

Calculate the distance(s) between the telescope and the calibration device.

Returns:
list of astropy.Quantity

A list of distances for variable positions or a single distance for layout positions.

calibration_pointing_direction()[source]#

Calculate the pointing of the calibration device towards the telescope.

Returns:
list

The pointing vector from the calibration device to the telescope.

distance_list(arg)[source]#

Convert distance list to astropy quantities.

Parameters:
arg: list

List of distances.

Returns:
values: list

List of distances as astropy quantities.

static light_emission_default_configuration()[source]#

Get default light emission configuration.

Returns:
dict

Default configuration light emission.

prepare_script(generate_postscript=False, **kwargs)[source]#

Build and return bash run script containing the light-emission command.

Parameters:
plot: bool

If output should be plotted.

generate_postscript: bool

If postscript should be generated with read_cta.

Returns:
Path

Full path of the run script.

process_simulation_output(args_dict, figures)[source]#

Process the simulation output, including plotting and saving figures.

run_simulation(args_dict, figures)[source]#

Run the light emission simulation.

save_figures_to_pdf(figures, telescope)[source]#

Save the generated figures to a PDF file.

simulate_layout_positions(args_dict)[source]#

Simulate light emission for layout positions.

simulate_variable_distances(args_dict)[source]#

Simulate light emission for variable distances.

update_light_emission_config(key: str, value)[source]#

Update the light emission configuration.

Parameters:
keystr

The key in the configuration to update.

valueAny

The new value to set for the key.

simulator_ray_tracing#

Simulation runner for ray tracing simulations.

class simtel.simulator_ray_tracing.SimulatorRayTracing(telescope_model, site_model, label=None, simtel_path=None, config_data=None, force_simulate=False, test=False)[source]#

Perform ray tracing simulations with sim_telarray.

Parameters:
telescope_model: TelescopeModel

telescope model

site_model: SiteModel

site model

label: str

label used for output file naming.

simtel_path: str or Path

Location of sim_telarray installation.

config_data: namedtuple

namedtuple containing the configurable parameters as values (expected units in brackets): zenith_angle (deg), off_axis_angle (deg), source_distance (km), single_mirror_mode, use_random_focal_length, mirror_numbers.

force_simulate: bool

Remove existing files and force re-running of the ray-tracing simulation.