gammasimtools 0.12.0__py3-none-any.whl → 0.14.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (276) hide show
  1. {gammasimtools-0.12.0.dist-info → gammasimtools-0.14.0.dist-info}/METADATA +3 -3
  2. {gammasimtools-0.12.0.dist-info → gammasimtools-0.14.0.dist-info}/RECORD +257 -263
  3. {gammasimtools-0.12.0.dist-info → gammasimtools-0.14.0.dist-info}/WHEEL +1 -1
  4. {gammasimtools-0.12.0.dist-info → gammasimtools-0.14.0.dist-info}/entry_points.txt +4 -1
  5. simtools/_version.py +2 -2
  6. simtools/applications/convert_all_model_parameters_from_simtel.py +77 -88
  7. simtools/applications/convert_geo_coordinates_of_array_elements.py +1 -1
  8. simtools/applications/db_add_file_to_db.py +15 -0
  9. simtools/applications/db_add_value_from_json_to_db.py +18 -1
  10. simtools/applications/db_get_parameter_from_db.py +52 -22
  11. simtools/applications/derive_ctao_array_layouts.py +120 -0
  12. simtools/applications/derive_photon_electron_spectrum.py +30 -2
  13. simtools/applications/docs_produce_array_element_report.py +42 -26
  14. simtools/applications/docs_produce_model_parameter_reports.py +28 -21
  15. simtools/applications/generate_simtel_event_data.py +117 -0
  16. simtools/applications/plot_tabular_data.py +14 -2
  17. simtools/applications/print_version.py +81 -0
  18. simtools/applications/production_derive_corsika_limits.py +240 -0
  19. simtools/applications/production_scale_events.py +59 -36
  20. simtools/applications/run_application.py +47 -18
  21. simtools/applications/simulate_light_emission.py +115 -247
  22. simtools/applications/simulate_prod_htcondor_generator.py +2 -2
  23. simtools/applications/submit_data_from_external.py +1 -1
  24. simtools/applications/submit_model_parameter_from_external.py +2 -1
  25. simtools/camera/single_photon_electron_spectrum.py +169 -17
  26. simtools/constants.py +7 -0
  27. simtools/data_model/metadata_collector.py +159 -61
  28. simtools/data_model/model_data_writer.py +18 -61
  29. simtools/data_model/schema.py +2 -1
  30. simtools/data_model/validate_data.py +5 -3
  31. simtools/db/db_handler.py +123 -33
  32. simtools/dependencies.py +38 -3
  33. simtools/layout/array_layout.py +1 -0
  34. simtools/layout/ctao_array_layouts.py +172 -0
  35. simtools/model/array_model.py +3 -4
  36. simtools/model/model_parameter.py +30 -118
  37. simtools/production_configuration/derive_corsika_limits.py +328 -0
  38. simtools/production_configuration/event_scaler.py +2 -2
  39. simtools/ray_tracing/mirror_panel_psf.py +1 -1
  40. simtools/reporting/docs_auto_report_generator.py +217 -0
  41. simtools/reporting/docs_read_parameters.py +298 -143
  42. simtools/schemas/application_workflow.metaschema.yml +3 -0
  43. simtools/schemas/metadata.metaschema.yml +7 -6
  44. simtools/schemas/model_parameter.metaschema.yml +13 -4
  45. simtools/schemas/model_parameter_and_data_schema.metaschema.yml +19 -5
  46. simtools/schemas/model_parameters/adjust_gain.schema.yml +1 -1
  47. simtools/schemas/model_parameters/altitude.schema.yml +1 -1
  48. simtools/schemas/model_parameters/array_coordinates.schema.yml +1 -1
  49. simtools/schemas/model_parameters/array_coordinates_UTM.schema.yml +3 -3
  50. simtools/schemas/model_parameters/array_element_position_ground.schema.yml +3 -3
  51. simtools/schemas/model_parameters/array_element_position_utm.schema.yml +3 -3
  52. simtools/schemas/model_parameters/array_layouts.schema.yml +3 -0
  53. simtools/schemas/model_parameters/array_window.schema.yml +1 -1
  54. simtools/schemas/model_parameters/asum_clipping.schema.yml +1 -1
  55. simtools/schemas/model_parameters/asum_offset.schema.yml +1 -1
  56. simtools/schemas/model_parameters/asum_shaping.schema.yml +1 -1
  57. simtools/schemas/model_parameters/asum_threshold.schema.yml +1 -1
  58. simtools/schemas/model_parameters/atmospheric_profile.schema.yml +1 -1
  59. simtools/schemas/model_parameters/axes_offsets.schema.yml +2 -2
  60. simtools/schemas/model_parameters/camera_body_diameter.schema.yml +1 -1
  61. simtools/schemas/model_parameters/camera_body_shape.schema.yml +1 -1
  62. simtools/schemas/model_parameters/camera_config_file.schema.yml +1 -1
  63. simtools/schemas/model_parameters/camera_config_rotate.schema.yml +1 -1
  64. simtools/schemas/model_parameters/camera_degraded_efficiency.schema.yml +1 -1
  65. simtools/schemas/model_parameters/camera_degraded_map.schema.yml +1 -1
  66. simtools/schemas/model_parameters/camera_depth.schema.yml +1 -1
  67. simtools/schemas/model_parameters/camera_filter.schema.yml +1 -1
  68. simtools/schemas/model_parameters/camera_pixels.schema.yml +1 -1
  69. simtools/schemas/model_parameters/camera_transmission.schema.yml +1 -1
  70. simtools/schemas/model_parameters/channels_per_chip.schema.yml +1 -1
  71. simtools/schemas/model_parameters/corsika_iact_io_buffer.schema.yml +1 -1
  72. simtools/schemas/model_parameters/corsika_iact_max_bunches.schema.yml +1 -1
  73. simtools/schemas/model_parameters/corsika_iact_split_auto.schema.yml +1 -1
  74. simtools/schemas/model_parameters/corsika_observation_level.schema.yml +1 -1
  75. simtools/schemas/model_parameters/dark_events.schema.yml +1 -1
  76. simtools/schemas/model_parameters/disc_bins.schema.yml +1 -1
  77. simtools/schemas/model_parameters/disc_start.schema.yml +1 -1
  78. simtools/schemas/model_parameters/discriminator_amplitude.schema.yml +1 -1
  79. simtools/schemas/model_parameters/discriminator_fall_time.schema.yml +1 -1
  80. simtools/schemas/model_parameters/discriminator_gate_length.schema.yml +1 -1
  81. simtools/schemas/model_parameters/discriminator_hysteresis.schema.yml +1 -1
  82. simtools/schemas/model_parameters/discriminator_output_amplitude.schema.yml +1 -1
  83. simtools/schemas/model_parameters/discriminator_output_var_percent.schema.yml +1 -1
  84. simtools/schemas/model_parameters/discriminator_rise_time.schema.yml +1 -1
  85. simtools/schemas/model_parameters/discriminator_scale_threshold.schema.yml +1 -1
  86. simtools/schemas/model_parameters/discriminator_sigsum_over_threshold.schema.yml +1 -1
  87. simtools/schemas/model_parameters/discriminator_threshold.schema.yml +1 -1
  88. simtools/schemas/model_parameters/discriminator_time_over_threshold.schema.yml +1 -1
  89. simtools/schemas/model_parameters/discriminator_var_gate_length.schema.yml +1 -1
  90. simtools/schemas/model_parameters/discriminator_var_sigsum_over_threshold.schema.yml +1 -1
  91. simtools/schemas/model_parameters/discriminator_var_threshold.schema.yml +1 -1
  92. simtools/schemas/model_parameters/discriminator_var_time_over_threshold.schema.yml +1 -1
  93. simtools/schemas/model_parameters/dish_shape_length.schema.yml +1 -1
  94. simtools/schemas/model_parameters/dsum_clipping.schema.yml +1 -1
  95. simtools/schemas/model_parameters/dsum_ignore_below.schema.yml +1 -1
  96. simtools/schemas/model_parameters/dsum_offset.schema.yml +1 -1
  97. simtools/schemas/model_parameters/dsum_pre_clipping.schema.yml +1 -1
  98. simtools/schemas/model_parameters/dsum_prescale.schema.yml +2 -2
  99. simtools/schemas/model_parameters/dsum_presum_max.schema.yml +1 -1
  100. simtools/schemas/model_parameters/dsum_presum_shift.schema.yml +1 -1
  101. simtools/schemas/model_parameters/dsum_shaping.schema.yml +1 -1
  102. simtools/schemas/model_parameters/dsum_threshold.schema.yml +1 -1
  103. simtools/schemas/model_parameters/dsum_zero_clip.schema.yml +1 -1
  104. simtools/schemas/model_parameters/effective_focal_length.schema.yml +5 -5
  105. simtools/schemas/model_parameters/epsg_code.schema.yml +1 -1
  106. simtools/schemas/model_parameters/fadc_amplitude.schema.yml +1 -1
  107. simtools/schemas/model_parameters/fadc_bins.schema.yml +1 -1
  108. simtools/schemas/model_parameters/fadc_compensate_pedestal.schema.yml +1 -1
  109. simtools/schemas/model_parameters/fadc_dev_pedestal.schema.yml +2 -2
  110. simtools/schemas/model_parameters/fadc_err_compensate_pedestal.schema.yml +1 -1
  111. simtools/schemas/model_parameters/fadc_err_pedestal.schema.yml +1 -1
  112. simtools/schemas/model_parameters/fadc_lg_amplitude.schema.yml +1 -1
  113. simtools/schemas/model_parameters/fadc_lg_compensate_pedestal.schema.yml +1 -1
  114. simtools/schemas/model_parameters/fadc_lg_dev_pedestal.schema.yml +2 -2
  115. simtools/schemas/model_parameters/fadc_lg_err_compensate_pedestal.schema.yml +1 -1
  116. simtools/schemas/model_parameters/fadc_lg_err_pedestal.schema.yml +1 -1
  117. simtools/schemas/model_parameters/fadc_lg_max_signal.schema.yml +1 -1
  118. simtools/schemas/model_parameters/fadc_lg_max_sum.schema.yml +4 -4
  119. simtools/schemas/model_parameters/fadc_lg_noise.schema.yml +1 -1
  120. simtools/schemas/model_parameters/fadc_lg_pedestal.schema.yml +1 -1
  121. simtools/schemas/model_parameters/fadc_lg_sensitivity.schema.yml +1 -1
  122. simtools/schemas/model_parameters/fadc_lg_sysvar_pedestal.schema.yml +1 -1
  123. simtools/schemas/model_parameters/fadc_lg_var_pedestal.schema.yml +1 -1
  124. simtools/schemas/model_parameters/fadc_lg_var_sensitivity.schema.yml +1 -1
  125. simtools/schemas/model_parameters/fadc_max_signal.schema.yml +1 -1
  126. simtools/schemas/model_parameters/fadc_max_sum.schema.yml +4 -4
  127. simtools/schemas/model_parameters/fadc_mhz.schema.yml +1 -1
  128. simtools/schemas/model_parameters/fadc_noise.schema.yml +1 -1
  129. simtools/schemas/model_parameters/fadc_pedestal.schema.yml +1 -1
  130. simtools/schemas/model_parameters/fadc_sensitivity.schema.yml +1 -1
  131. simtools/schemas/model_parameters/fadc_sum_bins.schema.yml +1 -1
  132. simtools/schemas/model_parameters/fadc_sum_offset.schema.yml +1 -1
  133. simtools/schemas/model_parameters/fadc_sysvar_pedestal.schema.yml +1 -1
  134. simtools/schemas/model_parameters/fadc_var_pedestal.schema.yml +1 -1
  135. simtools/schemas/model_parameters/fadc_var_sensitivity.schema.yml +1 -1
  136. simtools/schemas/model_parameters/fake_mirror_list.schema.yml +1 -1
  137. simtools/schemas/model_parameters/focal_length.schema.yml +1 -1
  138. simtools/schemas/model_parameters/focal_surface_parameters.schema.yml +20 -20
  139. simtools/schemas/model_parameters/focal_surface_ref_radius.schema.yml +1 -1
  140. simtools/schemas/model_parameters/focus_offset.schema.yml +4 -4
  141. simtools/schemas/model_parameters/gain_variation.schema.yml +1 -1
  142. simtools/schemas/model_parameters/geomag_horizontal.schema.yml +1 -1
  143. simtools/schemas/model_parameters/geomag_rotation.schema.yml +1 -1
  144. simtools/schemas/model_parameters/geomag_vertical.schema.yml +1 -1
  145. simtools/schemas/model_parameters/hg_lg_variation.schema.yml +1 -1
  146. simtools/schemas/model_parameters/iobuf_maximum.schema.yml +1 -1
  147. simtools/schemas/model_parameters/iobuf_output_maximum.schema.yml +1 -1
  148. simtools/schemas/model_parameters/laser_events.schema.yml +1 -1
  149. simtools/schemas/model_parameters/laser_external_trigger.schema.yml +1 -1
  150. simtools/schemas/model_parameters/laser_photons.schema.yml +1 -1
  151. simtools/schemas/model_parameters/laser_pulse_exptime.schema.yml +1 -1
  152. simtools/schemas/model_parameters/laser_pulse_offset.schema.yml +1 -1
  153. simtools/schemas/model_parameters/laser_pulse_sigtime.schema.yml +1 -1
  154. simtools/schemas/model_parameters/laser_pulse_twidth.schema.yml +1 -1
  155. simtools/schemas/model_parameters/laser_var_photons.schema.yml +1 -1
  156. simtools/schemas/model_parameters/laser_wavelength.schema.yml +1 -1
  157. simtools/schemas/model_parameters/led_events.schema.yml +1 -1
  158. simtools/schemas/model_parameters/led_photons.schema.yml +1 -1
  159. simtools/schemas/model_parameters/led_pulse_offset.schema.yml +1 -1
  160. simtools/schemas/model_parameters/led_pulse_sigtime.schema.yml +1 -1
  161. simtools/schemas/model_parameters/led_var_photons.schema.yml +1 -1
  162. simtools/schemas/model_parameters/lightguide_efficiency_vs_incidence_angle.schema.yml +1 -1
  163. simtools/schemas/model_parameters/lightguide_efficiency_vs_wavelength.schema.yml +1 -1
  164. simtools/schemas/model_parameters/min_photoelectrons.schema.yml +1 -1
  165. simtools/schemas/model_parameters/min_photons.schema.yml +1 -1
  166. simtools/schemas/model_parameters/mirror_align_random_distance.schema.yml +1 -1
  167. simtools/schemas/model_parameters/mirror_align_random_horizontal.schema.yml +4 -4
  168. simtools/schemas/model_parameters/mirror_align_random_vertical.schema.yml +4 -4
  169. simtools/schemas/model_parameters/mirror_class.schema.yml +1 -1
  170. simtools/schemas/model_parameters/mirror_degraded_reflection.schema.yml +1 -1
  171. simtools/schemas/model_parameters/mirror_focal_length.schema.yml +1 -1
  172. simtools/schemas/model_parameters/mirror_list.schema.yml +1 -1
  173. simtools/schemas/model_parameters/mirror_offset.schema.yml +1 -1
  174. simtools/schemas/model_parameters/mirror_panel_2f_measurements.schema.yml +3 -3
  175. simtools/schemas/model_parameters/mirror_reflection_random_angle.schema.yml +3 -3
  176. simtools/schemas/model_parameters/multiplicity_offset.schema.yml +1 -1
  177. simtools/schemas/model_parameters/muon_mono_threshold.schema.yml +45 -0
  178. simtools/schemas/model_parameters/nsb_autoscale_airmass.schema.yml +2 -2
  179. simtools/schemas/model_parameters/nsb_gain_drop_scale.schema.yml +1 -1
  180. simtools/schemas/model_parameters/nsb_offaxis.schema.yml +5 -5
  181. simtools/schemas/model_parameters/nsb_pixel_rate.schema.yml +1 -1
  182. simtools/schemas/model_parameters/nsb_reference_spectrum.schema.yml +1 -1
  183. simtools/schemas/model_parameters/nsb_reference_value.schema.yml +1 -1
  184. simtools/schemas/model_parameters/nsb_scaling_factor.schema.yml +1 -1
  185. simtools/schemas/model_parameters/{nsb_skymap.schema.yml → nsb_sky_map.schema.yml} +1 -1
  186. simtools/schemas/model_parameters/nsb_spectrum.schema.yml +2 -2
  187. simtools/schemas/model_parameters/num_gains.schema.yml +1 -1
  188. simtools/schemas/model_parameters/pedestal_events.schema.yml +1 -1
  189. simtools/schemas/model_parameters/photon_delay.schema.yml +1 -1
  190. simtools/schemas/model_parameters/photons_per_run.schema.yml +1 -1
  191. simtools/schemas/model_parameters/pixel_cells.schema.yml +1 -1
  192. simtools/schemas/model_parameters/pixels_parallel.schema.yml +1 -1
  193. simtools/schemas/model_parameters/pixeltrg_time_step.schema.yml +1 -1
  194. simtools/schemas/model_parameters/pm_average_gain.schema.yml +1 -1
  195. simtools/schemas/model_parameters/pm_collection_efficiency.schema.yml +1 -1
  196. simtools/schemas/model_parameters/pm_gain_index.schema.yml +1 -1
  197. simtools/schemas/model_parameters/pm_transit_time.schema.yml +4 -4
  198. simtools/schemas/model_parameters/pm_voltage_variation.schema.yml +1 -1
  199. simtools/schemas/model_parameters/primary_mirror_degraded_map.schema.yml +8 -4
  200. simtools/schemas/model_parameters/primary_mirror_diameter.schema.yml +1 -1
  201. simtools/schemas/model_parameters/primary_mirror_hole_diameter.schema.yml +1 -1
  202. simtools/schemas/model_parameters/primary_mirror_parameters.schema.yml +20 -20
  203. simtools/schemas/model_parameters/primary_mirror_ref_radius.schema.yml +1 -1
  204. simtools/schemas/model_parameters/primary_mirror_segmentation.schema.yml +1 -1
  205. simtools/schemas/model_parameters/qe_variation.schema.yml +1 -1
  206. simtools/schemas/model_parameters/random_focal_length.schema.yml +2 -2
  207. simtools/schemas/model_parameters/random_mono_probability.schema.yml +38 -0
  208. simtools/schemas/model_parameters/reference_point_altitude.schema.yml +1 -1
  209. simtools/schemas/model_parameters/reference_point_latitude.schema.yml +4 -1
  210. simtools/schemas/model_parameters/reference_point_longitude.schema.yml +4 -1
  211. simtools/schemas/model_parameters/reference_point_utm_east.schema.yml +1 -1
  212. simtools/schemas/model_parameters/reference_point_utm_north.schema.yml +1 -1
  213. simtools/schemas/model_parameters/secondary_mirror_baffle.schema.yml +5 -5
  214. simtools/schemas/model_parameters/secondary_mirror_degraded_map.schema.yml +1 -1
  215. simtools/schemas/model_parameters/secondary_mirror_degraded_reflection.schema.yml +1 -1
  216. simtools/schemas/model_parameters/secondary_mirror_diameter.schema.yml +1 -1
  217. simtools/schemas/model_parameters/secondary_mirror_hole_diameter.schema.yml +1 -1
  218. simtools/schemas/model_parameters/secondary_mirror_parameters.schema.yml +20 -20
  219. simtools/schemas/model_parameters/secondary_mirror_ref_radius.schema.yml +1 -1
  220. simtools/schemas/model_parameters/secondary_mirror_segmentation.schema.yml +1 -1
  221. simtools/schemas/model_parameters/secondary_mirror_shadow_diameter.schema.yml +1 -1
  222. simtools/schemas/model_parameters/secondary_mirror_shadow_offset.schema.yml +1 -1
  223. simtools/schemas/model_parameters/stars.schema.yml +36 -0
  224. simtools/schemas/model_parameters/store_photoelectrons.schema.yml +1 -1
  225. simtools/schemas/model_parameters/tailcut_scale.schema.yml +1 -1
  226. simtools/schemas/model_parameters/telescope_axis_height.schema.yml +1 -1
  227. simtools/schemas/model_parameters/telescope_random_angle.schema.yml +1 -1
  228. simtools/schemas/model_parameters/telescope_random_error.schema.yml +1 -1
  229. simtools/schemas/model_parameters/telescope_sphere_radius.schema.yml +1 -1
  230. simtools/schemas/model_parameters/telescope_transmission.schema.yml +6 -6
  231. simtools/schemas/model_parameters/teltrig_min_sigsum.schema.yml +1 -1
  232. simtools/schemas/model_parameters/teltrig_min_time.schema.yml +1 -1
  233. simtools/schemas/model_parameters/transit_time_calib_error.schema.yml +1 -1
  234. simtools/schemas/model_parameters/transit_time_compensate_error.schema.yml +1 -1
  235. simtools/schemas/model_parameters/transit_time_compensate_step.schema.yml +1 -1
  236. simtools/schemas/model_parameters/transit_time_error.schema.yml +1 -1
  237. simtools/schemas/model_parameters/transit_time_jitter.schema.yml +1 -1
  238. simtools/schemas/model_parameters/trigger_current_limit.schema.yml +1 -1
  239. simtools/schemas/model_parameters/trigger_delay_compensation.schema.yml +4 -4
  240. simtools/schemas/model_parameters/trigger_pixels.schema.yml +1 -1
  241. simtools/schemas/plot_configuration.metaschema.yml +162 -0
  242. simtools/schemas/production_tables.schema.yml +1 -1
  243. simtools/simtel/simtel_config_reader.py +85 -34
  244. simtools/simtel/simtel_config_writer.py +70 -38
  245. simtools/simtel/simtel_io_event_reader.py +278 -0
  246. simtools/simtel/simtel_io_event_writer.py +317 -0
  247. simtools/simtel/simtel_table_reader.py +4 -0
  248. simtools/simtel/simulator_light_emission.py +181 -67
  249. simtools/simulator.py +2 -2
  250. simtools/testing/configuration.py +17 -0
  251. simtools/utils/general.py +83 -16
  252. simtools/utils/geometry.py +19 -0
  253. simtools/utils/names.py +14 -3
  254. simtools/visualization/plot_tables.py +25 -20
  255. simtools/visualization/visualize.py +73 -25
  256. simtools/_dev_version/__init__.py +0 -9
  257. simtools/applications/__init__.py +0 -0
  258. simtools/applications/production_derive_limits.py +0 -95
  259. simtools/configuration/__init__.py +0 -0
  260. simtools/corsika/__init__.py +0 -0
  261. simtools/data_model/__init__.py +0 -0
  262. simtools/db/__init__.py +0 -0
  263. simtools/io_operations/__init__.py +0 -0
  264. simtools/job_execution/__init__.py +0 -0
  265. simtools/layout/__init__.py +0 -0
  266. simtools/model/__init__.py +0 -0
  267. simtools/production_configuration/limits_calculation.py +0 -202
  268. simtools/ray_tracing/__init__.py +0 -0
  269. simtools/runners/__init__.py +0 -0
  270. simtools/simtel/__init__.py +0 -0
  271. simtools/simtel/simtel_io_events.py +0 -265
  272. simtools/testing/__init__.py +0 -0
  273. simtools/utils/__init__.py +0 -0
  274. simtools/visualization/__init__.py +0 -0
  275. {gammasimtools-0.12.0.dist-info → gammasimtools-0.14.0.dist-info/licenses}/LICENSE +0 -0
  276. {gammasimtools-0.12.0.dist-info → gammasimtools-0.14.0.dist-info}/top_level.txt +0 -0
@@ -1,202 +0,0 @@
1
- """Calculate the thresholds for energy, radial distance, and viewcone."""
2
-
3
- import astropy.units as u
4
- import numpy as np
5
-
6
-
7
- class LimitCalculator:
8
- """
9
- Compute thresholds/limits for energy, radial distance, and viewcone.
10
-
11
- Histograms are generated with simtools-generate-simtel-array-histograms with --hdf5 flag.
12
-
13
- Event data is read from the generated HDF5 file from the following tables:
14
- - angle_to_observing_position__triggered_showers_ for the viewcone limit.
15
- - event_weight__ra3d__log10_e__ for the energy and radial distance limit.
16
-
17
-
18
- Parameters
19
- ----------
20
- event_data_file : list of astropy.table.Table
21
- The list of tables containing the event data.
22
- """
23
-
24
- def __init__(self, event_data_file_tables):
25
- """
26
- Initialize the LimitCalculator with the given event data file.
27
-
28
- Parameters
29
- ----------
30
- event_data_file : list of astropy.table.Table
31
- The list of tables containing the event data.
32
- """
33
- self.angle_to_observing_position__triggered_showers_ = None
34
- self.event_weight__ra3d__log10_e__ = None
35
-
36
- for table in event_data_file_tables:
37
- if (
38
- "Title" in table.meta
39
- and table.meta["Title"] == "angle_to_observing_position__triggered_showers_"
40
- ):
41
- self.angle_to_observing_position__triggered_showers_ = table
42
- elif "Title" in table.meta and table.meta["Title"] == "event_weight__ra3d__log10_e__":
43
- self.event_weight__ra3d__log10_e__ = table
44
-
45
- def _compute_limits(
46
- self, event_weight_array, bin_edges, loss_fraction, axis=0, limit_type="lower"
47
- ):
48
- """
49
- Compute the limits based on the loss fraction.
50
-
51
- Parameters
52
- ----------
53
- event_weight_array : np.ndarray
54
- Array of event weights.
55
- bin_edges : np.ndarray
56
- Array of bin edges.
57
- loss_fraction : float
58
- Fraction of events to be lost.
59
- axis : int, optional
60
- Axis along which to sum the event weights. Default is 0.
61
- limit_type : str, optional
62
- Type of limit ('lower' or 'upper'). Default is 'lower'.
63
-
64
- Returns
65
- -------
66
- int
67
- Bin index where the threshold is reached.
68
- float
69
- Bin edge value corresponding to the threshold.
70
- """
71
- projection = np.sum(event_weight_array, axis=axis)
72
- bin_edge_value = None
73
- cumulative_sum = None
74
- if limit_type == "upper":
75
- cumulative_sum = np.cumsum(projection)
76
-
77
- elif limit_type == "lower":
78
- cumulative_sum = np.cumsum(projection[::-1])
79
-
80
- total_events = np.sum(projection)
81
- threshold = (1 - loss_fraction) * total_events
82
- bin_index = np.searchsorted(cumulative_sum, threshold)
83
- if limit_type == "upper":
84
- bin_edge_value = bin_edges[bin_index]
85
- elif limit_type == "lower":
86
- bin_edge_value = bin_edges[-bin_index]
87
- return bin_index, bin_edge_value
88
-
89
- def get_bin_edges_and_units(self, table, axis="x"):
90
- """
91
- Extract bin edges and units from the table metadata.
92
-
93
- Parameters
94
- ----------
95
- table : astropy.table.Table
96
- Table containing the event data.
97
-
98
- Returns
99
- -------
100
- tuple
101
- Tuple containing the bin edges and their units.
102
- """
103
- bin_edges = table.meta[f"{axis}_bin_edges"]
104
- try:
105
- bin_edges_unit = table.meta[f"{axis}_bin_edges_unit"]
106
- except KeyError:
107
- bin_edges_unit = ""
108
- return bin_edges, bin_edges_unit
109
-
110
- def compute_lower_energy_limit(self, loss_fraction):
111
- """
112
- Compute the lower energy limit in TeV based on the event loss fraction.
113
-
114
- Parameters
115
- ----------
116
- loss_fraction : float
117
- Fraction of events to be lost.
118
-
119
- Returns
120
- -------
121
- astropy.units.Quantity
122
- Lower energy limit.
123
- """
124
- event_weight_array = np.column_stack(
125
- [
126
- self.event_weight__ra3d__log10_e__[name]
127
- for name in self.event_weight__ra3d__log10_e__.dtype.names
128
- ]
129
- )
130
- bin_edges, bin_edges_unit = self.get_bin_edges_and_units(
131
- self.event_weight__ra3d__log10_e__, axis="y"
132
- )
133
- if bin_edges_unit == "":
134
- bin_edges_unit = "TeV"
135
- _, lower_bin_edge_value = self._compute_limits(
136
- event_weight_array, bin_edges, loss_fraction, axis=0, limit_type="lower"
137
- )
138
- return (10**lower_bin_edge_value) * u.Unit(bin_edges_unit)
139
-
140
- def compute_upper_radial_distance(self, loss_fraction):
141
- """
142
- Compute the upper radial distance based on the event loss fraction.
143
-
144
- Parameters
145
- ----------
146
- loss_fraction : float
147
- Fraction of events to be lost.
148
-
149
- Returns
150
- -------
151
- astropy.units.Quantity
152
- Upper radial distance in m.
153
- """
154
- event_weight_array = np.column_stack(
155
- [
156
- self.event_weight__ra3d__log10_e__[name]
157
- for name in self.event_weight__ra3d__log10_e__.dtype.names
158
- ]
159
- )
160
- bin_edges, bin_edges_unit = self.get_bin_edges_and_units(
161
- self.event_weight__ra3d__log10_e__, axis="x"
162
- )
163
- if bin_edges_unit == "":
164
- bin_edges_unit = "m"
165
- _, upper_bin_edge_value = self._compute_limits(
166
- event_weight_array, bin_edges, loss_fraction, axis=1, limit_type="upper"
167
- )
168
- return upper_bin_edge_value * u.Unit(bin_edges_unit)
169
-
170
- def compute_viewcone(self, loss_fraction):
171
- """
172
- Compute the viewcone based on the event loss fraction.
173
-
174
- Parameters
175
- ----------
176
- loss_fraction : float
177
- Fraction of events to be lost.
178
-
179
- Returns
180
- -------
181
- astropy.units.Quantity
182
- Viewcone radius in degrees.
183
- """
184
- angle_to_observing_position__triggered_showers = np.column_stack(
185
- [
186
- self.angle_to_observing_position__triggered_showers_[name]
187
- for name in self.angle_to_observing_position__triggered_showers_.dtype.names
188
- ]
189
- )
190
- bin_edges, bin_edges_unit = self.get_bin_edges_and_units(
191
- self.angle_to_observing_position__triggered_showers_, axis="x"
192
- )
193
- if bin_edges_unit == "":
194
- bin_edges_unit = "deg"
195
- _, upper_bin_edge_value = self._compute_limits(
196
- angle_to_observing_position__triggered_showers,
197
- bin_edges,
198
- loss_fraction,
199
- axis=0,
200
- limit_type="upper",
201
- )
202
- return upper_bin_edge_value * u.Unit(bin_edges_unit)
File without changes
File without changes
File without changes
@@ -1,265 +0,0 @@
1
- """Read sim_telarray events from file."""
2
-
3
- import logging
4
- import math
5
- from copy import copy
6
-
7
- import astropy.units as u
8
- import numpy as np
9
- from eventio.simtel import SimTelFile
10
-
11
- __all__ = ["InconsistentInputFileError", "SimtelIOEvents"]
12
-
13
-
14
- class InconsistentInputFileError(Exception):
15
- """Exception for inconsistent input file."""
16
-
17
-
18
- class SimtelIOEvents:
19
- """
20
- Read sim_telarray events from file.
21
-
22
- sim_telarray files are read with eventio package.
23
-
24
- Parameters
25
- ----------
26
- input_files: list
27
- List of sim_telarray output files (str of Path).
28
- """
29
-
30
- def __init__(self, input_files=None):
31
- """Initialize SimtelIOEvents."""
32
- self._logger = logging.getLogger(__name__)
33
- self.load_input_files(input_files)
34
- if self.number_of_files > 0:
35
- self.load_header_and_summary()
36
-
37
- def load_input_files(self, files=None):
38
- """
39
- Store list of input files into input_files attribute.
40
-
41
- Parameters
42
- ----------
43
- files: list
44
- List of sim_telarray files (str or Path).
45
- """
46
- if not hasattr(self, "input_files"):
47
- self.input_files = []
48
-
49
- if files is None:
50
- msg = "No input file was given"
51
- self._logger.debug(msg)
52
- return
53
-
54
- if not isinstance(files, list):
55
- files = [files]
56
-
57
- for file in files:
58
- self.input_files.append(file)
59
-
60
- @property
61
- def number_of_files(self):
62
- """Return number of files loaded.
63
-
64
- Returns
65
- -------
66
- int
67
- Number of files loaded.
68
- """
69
- return len(self.input_files) if hasattr(self, "input_files") else 0
70
-
71
- def load_header_and_summary(self):
72
- """
73
- Read MC header from sim_telarray files and store it into _mc_header.
74
-
75
- Also fills summary_events with energy and core radius of triggered events.
76
- """
77
- self._number_of_files = len(self.input_files)
78
- keys_to_grab = [
79
- "obsheight",
80
- "n_showers",
81
- "n_use",
82
- "core_range",
83
- "diffuse",
84
- "viewcone",
85
- "E_range",
86
- "spectral_index",
87
- "B_total",
88
- ]
89
- self._mc_header = {}
90
-
91
- def _are_headers_consistent(header0, header1):
92
- comparison = {}
93
- for k in keys_to_grab:
94
- value = header0[k] == header1[k]
95
- comparison[k] = value if isinstance(value, bool) else all(value)
96
-
97
- return all(comparison)
98
-
99
- is_first_file = True
100
- number_of_triggered_events = 0
101
- summary_energy, summary_rcore = [], []
102
- for file in self.input_files:
103
- with SimTelFile(file) as f:
104
- for event in f:
105
- en = event["mc_shower"]["energy"]
106
- rc = math.sqrt(
107
- math.pow(event["mc_event"]["xcore"], 2)
108
- + math.pow(event["mc_event"]["ycore"], 2)
109
- )
110
-
111
- summary_energy.append(en)
112
- summary_rcore.append(rc)
113
- number_of_triggered_events += 1
114
-
115
- if is_first_file:
116
- # First file - grabbing parameters
117
- self._mc_header.update({k: copy(f.mc_run_headers[0][k]) for k in keys_to_grab})
118
- else:
119
- # Remaining files - Checking whether the parameters are consistent
120
- if not _are_headers_consistent(self._mc_header, f.mc_run_headers[0]):
121
- msg = "MC header pamameters from different files are inconsistent"
122
- self._logger.error(msg)
123
- raise InconsistentInputFileError(msg)
124
-
125
- is_first_file = False
126
-
127
- self.summary_events = {
128
- "energy": np.array(summary_energy),
129
- "r_core": np.array(summary_rcore),
130
- }
131
-
132
- # Calculating number of events
133
- self._mc_header["n_events"] = (
134
- self._mc_header["n_use"] * self._mc_header["n_showers"] * self._number_of_files
135
- )
136
- self._mc_header["n_triggered"] = number_of_triggered_events
137
-
138
- @u.quantity_input(core_max=u.m)
139
- def count_triggered_events(self, energy_range=None, core_max=None):
140
- """
141
- Count number of triggered events within a certain energy range and core radius.
142
-
143
- Parameters
144
- ----------
145
- energy_range: Tuple with len 2
146
- Max and min energy of energy range, e.g. energy_range=(100 * u.GeV, 10 * u.TeV).
147
- core_max: astropy.Quantity distance
148
- Maximum core radius for selecting showers, e.g. core_max=1000 * u.m.
149
-
150
- Returns
151
- -------
152
- int
153
- Number of triggered events.
154
- """
155
- energy_range = self._validate_energy_range(energy_range)
156
- core_max = self._validate_core_max(core_max)
157
-
158
- is_in_energy_range = [
159
- energy_range[0] < e < energy_range[1] for e in self.summary_events["energy"]
160
- ]
161
- is_in_core_range = [r < core_max for r in self.summary_events["r_core"]]
162
- return np.sum(np.array(is_in_energy_range) * np.array(is_in_core_range))
163
-
164
- @u.quantity_input(core_max=u.m)
165
- def select_events(self, energy_range=None, core_max=None):
166
- """
167
- Select sim_telarray events within a certain energy range and core radius.
168
-
169
- Parameters
170
- ----------
171
- energy_range: Tuple len 2
172
- Max and min energy of energy range, e.g. energy_range=(100 * u.GeV, 10 * u.TeV).
173
- core_max: astropy.Quantity distance
174
- Maximum core radius for selecting showers, e.g. core_max=1000 * u.m.
175
-
176
- Returns
177
- -------
178
- list
179
- List of events.
180
- """
181
- energy_range = self._validate_energy_range(energy_range)
182
- core_max = self._validate_core_max(core_max)
183
-
184
- selected_events = []
185
- for file in self.input_files:
186
- with SimTelFile(file) as f:
187
- for event in f:
188
- energy = event["mc_shower"]["energy"]
189
- if energy < energy_range[0] or energy > energy_range[1]:
190
- continue
191
-
192
- x_core = event["mc_event"]["xcore"]
193
- y_core = event["mc_event"]["ycore"]
194
- r_core = math.sqrt(math.pow(x_core, 2) + math.pow(y_core, 2))
195
- if r_core > core_max:
196
- continue
197
-
198
- selected_events.append(event)
199
- return selected_events
200
-
201
- @u.quantity_input(core_max=u.m)
202
- def count_simulated_events(self, energy_range=None, core_max=None):
203
- """
204
- Determine number of simulated events within a certain energy range and core radius.
205
-
206
- Use the simulated power law.
207
- This calculation assumes the simulated spectrum is given by a single power law.
208
-
209
- Parameters
210
- ----------
211
- energy_range: Tuple len 2
212
- Max and min energy of energy range, e.g. energy_range=(100 * u.GeV, 10 * u.TeV).
213
- core_max: astropy.Quantity distance
214
- Maximum core radius for selecting showers, e.g. core_max=1000 * u.m.
215
-
216
- Returns
217
- -------
218
- int
219
- Number of simulated events.
220
- """
221
- energy_range = self._validate_energy_range(energy_range)
222
- core_max = self._validate_core_max(core_max)
223
-
224
- # energy factor
225
- def integral(erange):
226
- power = self._mc_header["spectral_index"] + 1
227
- return math.pow(erange[0], power) - math.pow(erange[1], power)
228
-
229
- energy_factor = integral(energy_range) / integral(self._mc_header["E_range"])
230
-
231
- # core factor
232
- core_factor = math.pow(core_max, 2) / math.pow(self._mc_header["core_range"][1], 2)
233
-
234
- return self._mc_header["n_events"] * energy_factor * core_factor
235
-
236
- def _validate_energy_range(self, energy_range):
237
- """
238
- Return the default energy range from mc_header in case energy_range=None.
239
-
240
- Check units, convert it to TeV and return it in the right format, otherwise.
241
- """
242
- if energy_range is None:
243
- return self._mc_header["E_range"]
244
-
245
- if not isinstance(energy_range[0], u.Quantity) or not isinstance(
246
- energy_range[1], u.Quantity
247
- ):
248
- msg = "energy_range must be given as u.Quantity in units of energy"
249
- self._logger.error(msg)
250
- raise TypeError(msg)
251
-
252
- try:
253
- return (energy_range[0].to(u.TeV).value, energy_range[1].to(u.TeV).value)
254
- except u.core.UnitConversionError as e:
255
- msg = "energy_range must be in units of energy"
256
- self._logger.error(msg)
257
- raise TypeError(msg) from e
258
-
259
- def _validate_core_max(self, core_max):
260
- """
261
- Return the default core_max from mc_header in case core_max=None.
262
-
263
- Check units, convert it to m and return it in the right format, otherwise.
264
- """
265
- return self._mc_header["core_range"][1] if core_max is None else core_max.to(u.m).value
File without changes
File without changes
File without changes