Ray Tracing#

The ray-tracing modules handle ray tracing simulations, PSF analysis and I/O.

ray_tracing#

Ray tracing simulations and analysis.

class ray_tracing.ray_tracing.RayTracing(telescope_model, simtel_path, label=None, zenith_angle=<Quantity 20. deg>, off_axis_angle=<Quantity [0.] deg>, source_distance=<Quantity 10. km>, single_mirror_mode=False, use_random_focal_length=False, mirror_numbers='all')[source]#

Ray tracing simulations and analysis.

Parameters:
telescope_model: TelescopeModel

telescope model

simtel_path: str (or Path)

Location of sim_telarray installation.

label: str

label used for output file naming.

zenith_angle: astropy.units.Quantity

Zenith angle.

off_axis_angle: list of astropy.units.Quantity

Off-axis angles.

source_distance: astropy.units.Quantity

Source distance.

single_mirror_mode: bool

Single mirror mode flag.

use_random_focal_length: bool

Use random focal length flag.

mirror_numbers: list, str

List of mirror numbers (or ‘all’).

analyze(export=True, force=False, use_rx=False, no_tel_transmission=False, containment_fraction=0.8)[source]#

Ray tracing analysis.

Involves the following: read simtel files, compute PSFs and eff areas, store the results in _results.

Parameters:
export: bool

If True, results will be exported to a file automatically. Alternatively, export_results function can be used.

force: bool

If True, existing results files will be removed and analysis will be done again.

use_rx: bool

If True, calculations are done using the rx binary provided by sim_telarray. If False, calculations are done internally, by the module psf_analysis.

no_tel_transmission: bool

If True, the telescope transmission is not applied.

containment_fraction: float

Containment fraction for PSF containment calculation. Allowed values are in the interval [0,1]

export_results()[source]#

Export results to a csv file.

get_mean(key)[source]#

Get mean value of key.

Parameters:
key: str

d80_cm, d80_deg, eff_area or eff_flen

Returns:
float

Mean value of key.

Raises:
KeyError

If key is not among the valid options.

get_std_dev(key)[source]#

Get std dev of key.

Parameters:
key: str

d80_cm, d80_deg, eff_area or eff_flen

Returns:
float

Std deviation of key.

Raises:
KeyError

If key is not among the valid options.

images()[source]#

Get list of PSFImages.

Returns:
List of PSFImages
plot(key, save=False, d80=None, **kwargs)[source]#

Plot key vs off-axis angle and save the figure in pdf.

Parameters:
key: str

d80_cm, d80_deg, eff_area or eff_flen

save: bool

If True, figure will be saved.

d80: float

d80 for cumulative PSF plot.

**kwargs:

kwargs for plt.plot

Raises:
KeyError

If key is not among the valid options.

plot_histogram(key, **kwargs)[source]#

Plot histogram of key.

Parameters:
key: str

d80_cm, d80_deg, eff_area or eff_flen

**kwargs:

kwargs for plt.hist

Raises:
KeyError

If key is not among the valid options.

simulate(test=False, force=False)[source]#

Simulate RayTracing using SimulatorRayTracing.

Parameters:
test: bool

Test flag will make it faster by simulating much fewer photons.

force: bool

Force flag will remove existing files and simulate again.

psf_analysis#

Module to analyse psf images (e.g. results from ray tracing simulations).

Main functionalities are: computing centroids, psf containers etc.

class ray_tracing.psf_analysis.PSFImage(focal_length=None, total_scattered_area=None, containment_fraction=None, simtel_path=None)[source]#

Image composed of list of photon positions (2D).

Load photon list from sim_telarray file and compute centroids, psf containers, effective area, as well as plot the image as a 2D histogram. Internal units: photon positions in cm internally.

Parameters:
focal_length: float

Focal length of the system in cm. If not given, PSF can only be computed in cm.

total_scattered_area: float

Scatter area of all photons in cm^2. If not given, effective area cannot be computed.

containment_fraction: float

Containment fraction for PSF calculation.

simtel_path: str

Path to sim_telarray installation.

get_cumulative_data(radius=None)[source]#

Provide cumulative data (intensity vs radius).

Parameters:
radius: array

Array with radius calculate the cumulative PSF in distance units.

Returns:
(radius, intensity)
get_effective_area(tel_transmission=1.0)[source]#

Return effective area pre calculated.

Parameters:
telescope_transmissionfloat

Telescope transmission parameter.

Returns:
float

Pre-calculated effective area. None if it could not be calculated (e.g because the total scattering area was not set).

get_image_data(centralized=True)[source]#

Provide image data (2D photon positions in cm) as lists.

Parameters:
centralized: bool

Centroid of the image is set to (0, 0) if True.

Returns:
(x, y), the photons positions in cm.
get_psf(fraction=0.8, unit='cm')[source]#

Return PSF.

Parameters:
fraction: float

Fraction of photons within the containing radius.

unit: str

‘cm’ or ‘deg’. ‘deg’ will not work if focal length was not set.

Returns:
float:

Containing diameter for a certain intensity fraction (PSF).

plot_cumulative(file_name=None, d80=None, **kwargs)[source]#

Plot cumulative data (intensity vs radius).

Parameters:
**kwargs:

image_* for the histogram plot and psf_* for the psf circle.

plot_image(centralized=True, file_name=None, **kwargs)[source]#

Plot 2D image as histogram (in cm).

Parameters:
centralized: bool

Centroid of the image is set to (0, 0) if True.

**kwargs:

image_* for the histogram plot and psf_* for the psf circle.

process_photon_list(photon_file, use_rx)[source]#

Read and process a photon list file generated by sim_telarray.

Parameters:
photons_file: str

Name of sim_telarray file with photon list.

use_rx: bool

Use the RX method for analysis.

read_photon_list_from_simtel_file(photons_file)[source]#

Read photon list file generated by sim_telarray and store the photon positions (2D).

Parameters:
photons_file: str

Name of sim_telarray file with photon list.

Raises:
RuntimeError

If photon positions X and Y are not compatible or are empty.

set_effective_area(value)[source]#

Set effective area.

Parameters:
value: float

Effective area

set_psf(value, fraction=0.8, unit='cm')[source]#

Set PSF calculated from other methods.

Parameters:
value: float

PSF value to be set

fraction: float

Fraction of photons within the containing radius.

unit: str

‘cm’ or ‘deg’. ‘deg’ will not work if focal length was not set.

mirror_panel_psf#

Mirror panel PSF calculation.

class ray_tracing.mirror_panel_psf.MirrorPanelPSF(label, args_dict, db_config)[source]#

Mirror panel PSF and random reflection angle calculation.

This class is used to derive the random reflection angle for the mirror panels in the telescope.

Known limitations: single Gaussian PSF model, no support for multiple PSF components (as allowed in the model parameters).

Parameters:
label: str

Application label.

args_dict: dict

Dictionary with input arguments.

db_config:

Dictionary with database configuration.

derive_random_reflection_angle(save_figures=False)[source]#

Minimize the difference between measured and simulated PSF for reflection angle.

Main loop of the optimization process. The method iterates over different values of the random reflection angle until the difference in the mean value of the D80 containment is minimal.

print_results()[source]#

Print results to stdout.

run_simulations_and_analysis(rnda, save_figures=False)[source]#

Run ray tracing simulations and analysis for one given value of rnda.

Parameters:
rnda: float

Random reflection angle in degrees.

save_figures: bool

Save figures.

Returns:
mean_d80: float

Mean value of D80 in cm.

sig_d80: float

Standard deviation of D80 in cm.

write_optimization_data()[source]#

Write optimization results to an astropy table (ecsv file).

Used mostly for debugging of the optimization process. The first entry of the table is the best fit result.