gammasimtools 0.6.1__py3-none-any.whl → 0.8.2__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 (355) hide show
  1. gammasimtools-0.8.2.dist-info/METADATA +173 -0
  2. gammasimtools-0.8.2.dist-info/RECORD +345 -0
  3. {gammasimtools-0.6.1.dist-info → gammasimtools-0.8.2.dist-info}/WHEEL +1 -1
  4. gammasimtools-0.8.2.dist-info/entry_points.txt +31 -0
  5. simtools/_dev_version/__init__.py +9 -0
  6. simtools/_version.py +2 -2
  7. simtools/applications/calculate_trigger_rate.py +210 -0
  8. simtools/applications/convert_all_model_parameters_from_simtel.py +372 -0
  9. simtools/applications/{print_array_elements.py → convert_geo_coordinates_of_array_elements.py} +58 -63
  10. simtools/applications/convert_model_parameter_from_simtel.py +119 -0
  11. simtools/applications/{add_file_to_db.py → db_add_file_to_db.py} +70 -60
  12. simtools/applications/db_add_model_parameters_from_repository_to_db.py +184 -0
  13. simtools/applications/db_add_value_from_json_to_db.py +105 -0
  14. simtools/applications/db_development_tools/write_array_elements_positions_to_repository.py +180 -0
  15. simtools/applications/db_get_array_layouts_from_db.py +162 -0
  16. simtools/applications/{get_file_from_db.py → db_get_file_from_db.py} +30 -34
  17. simtools/applications/db_get_parameter_from_db.py +131 -0
  18. simtools/applications/db_inspect_databases.py +52 -0
  19. simtools/applications/derive_mirror_rnda.py +39 -255
  20. simtools/applications/derive_psf_parameters.py +441 -0
  21. simtools/applications/generate_array_config.py +82 -0
  22. simtools/applications/generate_corsika_histograms.py +52 -52
  23. simtools/applications/generate_default_metadata.py +5 -8
  24. simtools/applications/generate_regular_arrays.py +117 -0
  25. simtools/applications/generate_simtel_array_histograms.py +97 -56
  26. simtools/applications/plot_array_layout.py +345 -115
  27. simtools/applications/production_generate_simulation_config.py +158 -0
  28. simtools/applications/production_scale_events.py +168 -0
  29. simtools/applications/simulate_light_emission.py +478 -0
  30. simtools/applications/simulate_prod.py +97 -175
  31. simtools/applications/submit_data_from_external.py +9 -12
  32. simtools/applications/submit_model_parameter_from_external.py +122 -0
  33. simtools/applications/validate_camera_efficiency.py +35 -102
  34. simtools/applications/validate_camera_fov.py +20 -19
  35. simtools/applications/{compare_cumulative_psf.py → validate_cumulative_psf.py} +45 -44
  36. simtools/applications/validate_file_using_schema.py +111 -47
  37. simtools/applications/validate_optics.py +17 -22
  38. simtools/camera_efficiency.py +193 -202
  39. simtools/configuration/commandline_parser.py +384 -96
  40. simtools/configuration/configurator.py +55 -71
  41. simtools/constants.py +5 -5
  42. simtools/corsika/corsika_config.py +482 -342
  43. simtools/corsika/corsika_histograms.py +226 -204
  44. simtools/corsika/corsika_histograms_visualize.py +23 -24
  45. simtools/corsika/primary_particle.py +159 -0
  46. simtools/data_model/data_reader.py +25 -20
  47. simtools/data_model/format_checkers.py +52 -0
  48. simtools/data_model/metadata_collector.py +211 -185
  49. simtools/data_model/metadata_model.py +115 -37
  50. simtools/data_model/model_data_writer.py +335 -26
  51. simtools/data_model/validate_data.py +366 -154
  52. simtools/db/db_array_elements.py +130 -0
  53. simtools/db/db_from_repo_handler.py +106 -0
  54. simtools/db/db_handler.py +1246 -0
  55. simtools/io_operations/hdf5_handler.py +3 -1
  56. simtools/io_operations/io_handler.py +32 -57
  57. simtools/job_execution/job_manager.py +82 -69
  58. simtools/layout/array_layout.py +325 -537
  59. simtools/layout/geo_coordinates.py +8 -11
  60. simtools/layout/telescope_position.py +163 -86
  61. simtools/model/array_model.py +312 -259
  62. simtools/model/calibration_model.py +50 -0
  63. simtools/model/camera.py +277 -523
  64. simtools/model/mirrors.py +68 -49
  65. simtools/model/model_parameter.py +602 -0
  66. simtools/model/model_utils.py +11 -39
  67. simtools/model/site_model.py +161 -0
  68. simtools/model/telescope_model.py +143 -633
  69. simtools/production_configuration/calculate_statistical_errors_grid_point.py +454 -0
  70. simtools/production_configuration/event_scaler.py +146 -0
  71. simtools/production_configuration/generate_simulation_config.py +193 -0
  72. simtools/production_configuration/interpolation_handler.py +197 -0
  73. simtools/ray_tracing/__init__.py +0 -0
  74. simtools/ray_tracing/mirror_panel_psf.py +280 -0
  75. simtools/{psf_analysis.py → ray_tracing/psf_analysis.py} +133 -47
  76. simtools/ray_tracing/ray_tracing.py +646 -0
  77. simtools/runners/__init__.py +0 -0
  78. simtools/runners/corsika_runner.py +240 -0
  79. simtools/runners/corsika_simtel_runner.py +225 -0
  80. simtools/runners/runner_services.py +307 -0
  81. simtools/runners/simtel_runner.py +224 -0
  82. simtools/schemas/array_elements.yml +137 -0
  83. simtools/schemas/integration_tests_config.metaschema.yml +93 -0
  84. simtools/schemas/metadata.metaschema.yml +6 -0
  85. simtools/schemas/model_parameter.metaschema.yml +78 -0
  86. simtools/schemas/{data.metaschema.yml → model_parameter_and_data_schema.metaschema.yml} +27 -44
  87. simtools/schemas/model_parameters/adjust_gain.schema.yml +37 -0
  88. simtools/schemas/model_parameters/altitude.schema.yml +37 -0
  89. simtools/schemas/model_parameters/array_coordinates.schema.yml +33 -0
  90. simtools/schemas/model_parameters/array_coordinates_UTM.schema.yml +77 -0
  91. simtools/schemas/model_parameters/array_element_position_ground.schema.yml +39 -0
  92. simtools/schemas/model_parameters/array_element_position_utm.schema.yml +39 -0
  93. simtools/schemas/model_parameters/array_layouts.schema.yml +48 -0
  94. simtools/schemas/model_parameters/array_triggers.schema.yml +93 -0
  95. simtools/schemas/model_parameters/asum_clipping.schema.yml +38 -0
  96. simtools/schemas/model_parameters/asum_offset.schema.yml +35 -0
  97. simtools/schemas/model_parameters/asum_shaping.schema.yml +35 -0
  98. simtools/schemas/model_parameters/asum_threshold.schema.yml +38 -0
  99. simtools/schemas/model_parameters/atmospheric_profile.schema.yml +32 -0
  100. simtools/schemas/model_parameters/atmospheric_transmission.schema.yml +35 -0
  101. simtools/schemas/model_parameters/axes_offsets.schema.yml +53 -0
  102. simtools/schemas/model_parameters/camera_body_diameter.schema.yml +40 -0
  103. simtools/schemas/model_parameters/camera_body_shape.schema.yml +45 -0
  104. simtools/schemas/model_parameters/camera_config_file.schema.yml +40 -0
  105. simtools/schemas/model_parameters/camera_config_rotate.schema.yml +36 -0
  106. simtools/schemas/model_parameters/camera_degraded_efficiency.schema.yml +43 -0
  107. simtools/schemas/model_parameters/camera_degraded_map.schema.yml +42 -0
  108. simtools/schemas/model_parameters/camera_depth.schema.yml +42 -0
  109. simtools/schemas/model_parameters/camera_filter.schema.yml +45 -0
  110. simtools/schemas/model_parameters/camera_filter_incidence_angle.schema.yml +29 -0
  111. simtools/schemas/model_parameters/camera_pixels.schema.yml +36 -0
  112. simtools/schemas/model_parameters/camera_transmission.schema.yml +41 -0
  113. simtools/schemas/model_parameters/channels_per_chip.schema.yml +36 -0
  114. simtools/schemas/model_parameters/correct_nsb_spectrum_to_telescope_altitude.schema.yml +35 -0
  115. simtools/schemas/model_parameters/corsika_cherenkov_photon_bunch_size.schema.yml +27 -0
  116. simtools/schemas/model_parameters/corsika_cherenkov_photon_wavelength_range.schema.yml +38 -0
  117. simtools/schemas/model_parameters/corsika_first_interaction_height.schema.yml +28 -0
  118. simtools/schemas/model_parameters/corsika_iact_io_buffer.schema.yml +23 -0
  119. simtools/schemas/model_parameters/corsika_iact_max_bunches.schema.yml +27 -0
  120. simtools/schemas/model_parameters/corsika_iact_split_auto.schema.yml +28 -0
  121. simtools/schemas/model_parameters/corsika_longitudinal_shower_development.schema.yml +27 -0
  122. simtools/schemas/model_parameters/corsika_observation_level.schema.yml +38 -0
  123. simtools/schemas/model_parameters/corsika_particle_kinetic_energy_cutoff.schema.yml +52 -0
  124. simtools/schemas/model_parameters/corsika_starting_grammage.schema.yml +27 -0
  125. simtools/schemas/model_parameters/dark_events.schema.yml +32 -0
  126. simtools/schemas/model_parameters/default_trigger.schema.yml +35 -0
  127. simtools/schemas/model_parameters/design_model.schema.yml +31 -0
  128. simtools/schemas/model_parameters/disc_ac_coupled.schema.yml +32 -0
  129. simtools/schemas/model_parameters/disc_bins.schema.yml +39 -0
  130. simtools/schemas/model_parameters/disc_start.schema.yml +41 -0
  131. simtools/schemas/model_parameters/discriminator_amplitude.schema.yml +42 -0
  132. simtools/schemas/model_parameters/discriminator_fall_time.schema.yml +41 -0
  133. simtools/schemas/model_parameters/discriminator_gate_length.schema.yml +41 -0
  134. simtools/schemas/model_parameters/discriminator_hysteresis.schema.yml +39 -0
  135. simtools/schemas/model_parameters/discriminator_output_amplitude.schema.yml +40 -0
  136. simtools/schemas/model_parameters/discriminator_output_var_percent.schema.yml +41 -0
  137. simtools/schemas/model_parameters/discriminator_pulse_shape.schema.yml +33 -0
  138. simtools/schemas/model_parameters/discriminator_rise_time.schema.yml +42 -0
  139. simtools/schemas/model_parameters/discriminator_scale_threshold.schema.yml +37 -0
  140. simtools/schemas/model_parameters/discriminator_sigsum_over_threshold.schema.yml +44 -0
  141. simtools/schemas/model_parameters/discriminator_threshold.schema.yml +36 -0
  142. simtools/schemas/model_parameters/discriminator_time_over_threshold.schema.yml +45 -0
  143. simtools/schemas/model_parameters/discriminator_var_gate_length.schema.yml +40 -0
  144. simtools/schemas/model_parameters/discriminator_var_sigsum_over_threshold.schema.yml +41 -0
  145. simtools/schemas/model_parameters/discriminator_var_threshold.schema.yml +38 -0
  146. simtools/schemas/model_parameters/discriminator_var_time_over_threshold.schema.yml +38 -0
  147. simtools/schemas/model_parameters/dish_shape_length.schema.yml +41 -0
  148. simtools/schemas/model_parameters/dsum_clipping.schema.yml +38 -0
  149. simtools/schemas/model_parameters/dsum_ignore_below.schema.yml +38 -0
  150. simtools/schemas/model_parameters/dsum_offset.schema.yml +37 -0
  151. simtools/schemas/model_parameters/dsum_pedsub.schema.yml +33 -0
  152. simtools/schemas/model_parameters/dsum_pre_clipping.schema.yml +39 -0
  153. simtools/schemas/model_parameters/dsum_prescale.schema.yml +44 -0
  154. simtools/schemas/model_parameters/dsum_presum_max.schema.yml +38 -0
  155. simtools/schemas/model_parameters/dsum_presum_shift.schema.yml +45 -0
  156. simtools/schemas/model_parameters/dsum_shaping.schema.yml +44 -0
  157. simtools/schemas/model_parameters/dsum_shaping_renormalize.schema.yml +32 -0
  158. simtools/schemas/model_parameters/dsum_threshold.schema.yml +43 -0
  159. simtools/schemas/model_parameters/dsum_zero_clip.schema.yml +42 -0
  160. simtools/schemas/model_parameters/effective_focal_length.schema.yml +61 -0
  161. simtools/schemas/model_parameters/epsg_code.schema.yml +37 -0
  162. simtools/schemas/model_parameters/fadc_ac_coupled.schema.yml +35 -0
  163. simtools/schemas/model_parameters/fadc_amplitude.schema.yml +46 -0
  164. simtools/schemas/model_parameters/fadc_bins.schema.yml +40 -0
  165. simtools/schemas/model_parameters/fadc_compensate_pedestal.schema.yml +50 -0
  166. simtools/schemas/model_parameters/fadc_dev_pedestal.schema.yml +38 -0
  167. simtools/schemas/model_parameters/fadc_err_compensate_pedestal.schema.yml +42 -0
  168. simtools/schemas/model_parameters/fadc_err_pedestal.schema.yml +49 -0
  169. simtools/schemas/model_parameters/fadc_lg_amplitude.schema.yml +47 -0
  170. simtools/schemas/model_parameters/fadc_lg_compensate_pedestal.schema.yml +51 -0
  171. simtools/schemas/model_parameters/fadc_lg_dev_pedestal.schema.yml +37 -0
  172. simtools/schemas/model_parameters/fadc_lg_err_compensate_pedestal.schema.yml +43 -0
  173. simtools/schemas/model_parameters/fadc_lg_err_pedestal.schema.yml +49 -0
  174. simtools/schemas/model_parameters/fadc_lg_max_signal.schema.yml +43 -0
  175. simtools/schemas/model_parameters/fadc_lg_max_sum.schema.yml +39 -0
  176. simtools/schemas/model_parameters/fadc_lg_noise.schema.yml +42 -0
  177. simtools/schemas/model_parameters/fadc_lg_pedestal.schema.yml +40 -0
  178. simtools/schemas/model_parameters/fadc_lg_sensitivity.schema.yml +50 -0
  179. simtools/schemas/model_parameters/fadc_lg_sysvar_pedestal.schema.yml +42 -0
  180. simtools/schemas/model_parameters/fadc_lg_var_pedestal.schema.yml +41 -0
  181. simtools/schemas/model_parameters/fadc_lg_var_sensitivity.schema.yml +42 -0
  182. simtools/schemas/model_parameters/fadc_max_signal.schema.yml +43 -0
  183. simtools/schemas/model_parameters/fadc_max_sum.schema.yml +39 -0
  184. simtools/schemas/model_parameters/fadc_mhz.schema.yml +31 -0
  185. simtools/schemas/model_parameters/fadc_noise.schema.yml +41 -0
  186. simtools/schemas/model_parameters/fadc_pedestal.schema.yml +40 -0
  187. simtools/schemas/model_parameters/fadc_pulse_shape.schema.yml +39 -0
  188. simtools/schemas/model_parameters/fadc_sensitivity.schema.yml +50 -0
  189. simtools/schemas/model_parameters/fadc_sum_bins.schema.yml +43 -0
  190. simtools/schemas/model_parameters/fadc_sum_offset.schema.yml +43 -0
  191. simtools/schemas/model_parameters/fadc_sysvar_pedestal.schema.yml +42 -0
  192. simtools/schemas/model_parameters/fadc_var_pedestal.schema.yml +41 -0
  193. simtools/schemas/model_parameters/fadc_var_sensitivity.schema.yml +42 -0
  194. simtools/schemas/model_parameters/flatfielding.schema.yml +37 -0
  195. simtools/schemas/model_parameters/focal_length.schema.yml +45 -0
  196. simtools/schemas/model_parameters/focal_surface_parameters.schema.yml +158 -0
  197. simtools/schemas/model_parameters/focal_surface_ref_radius.schema.yml +29 -0
  198. simtools/schemas/model_parameters/focus_offset.schema.yml +66 -0
  199. simtools/schemas/model_parameters/gain_variation.schema.yml +43 -0
  200. simtools/schemas/model_parameters/geomag_horizontal.schema.yml +34 -0
  201. simtools/schemas/model_parameters/geomag_rotation.schema.yml +37 -0
  202. simtools/schemas/model_parameters/geomag_vertical.schema.yml +34 -0
  203. simtools/schemas/model_parameters/hg_lg_variation.schema.yml +36 -0
  204. simtools/schemas/model_parameters/iobuf_maximum.schema.yml +34 -0
  205. simtools/schemas/model_parameters/iobuf_output_maximum.schema.yml +34 -0
  206. simtools/schemas/model_parameters/laser_events.schema.yml +36 -0
  207. simtools/schemas/model_parameters/laser_external_trigger.schema.yml +35 -0
  208. simtools/schemas/model_parameters/laser_photons.schema.yml +32 -0
  209. simtools/schemas/model_parameters/laser_pulse_exptime.schema.yml +34 -0
  210. simtools/schemas/model_parameters/laser_pulse_offset.schema.yml +34 -0
  211. simtools/schemas/model_parameters/laser_pulse_sigtime.schema.yml +33 -0
  212. simtools/schemas/model_parameters/laser_pulse_twidth.schema.yml +33 -0
  213. simtools/schemas/model_parameters/laser_var_photons.schema.yml +33 -0
  214. simtools/schemas/model_parameters/laser_wavelength.schema.yml +33 -0
  215. simtools/schemas/model_parameters/led_events.schema.yml +34 -0
  216. simtools/schemas/model_parameters/led_photons.schema.yml +34 -0
  217. simtools/schemas/model_parameters/led_pulse_offset.schema.yml +32 -0
  218. simtools/schemas/model_parameters/led_pulse_sigtime.schema.yml +33 -0
  219. simtools/schemas/model_parameters/led_var_photons.schema.yml +34 -0
  220. simtools/schemas/model_parameters/lightguide_efficiency_vs_incidence_angle.schema.yml +41 -0
  221. simtools/schemas/model_parameters/lightguide_efficiency_vs_wavelength.schema.yml +43 -0
  222. simtools/schemas/model_parameters/min_photoelectrons.schema.yml +35 -0
  223. simtools/schemas/model_parameters/min_photons.schema.yml +32 -0
  224. simtools/schemas/model_parameters/mirror_align_random_distance.schema.yml +36 -0
  225. simtools/schemas/model_parameters/mirror_align_random_horizontal.schema.yml +64 -0
  226. simtools/schemas/model_parameters/mirror_align_random_vertical.schema.yml +64 -0
  227. simtools/schemas/model_parameters/mirror_class.schema.yml +41 -0
  228. simtools/schemas/model_parameters/mirror_degraded_reflection.schema.yml +51 -0
  229. simtools/schemas/model_parameters/mirror_focal_length.schema.yml +42 -0
  230. simtools/schemas/model_parameters/mirror_list.schema.yml +38 -0
  231. simtools/schemas/model_parameters/mirror_offset.schema.yml +41 -0
  232. simtools/schemas/model_parameters/mirror_panel_2f_measurements.schema.yml +39 -0
  233. simtools/schemas/model_parameters/mirror_reflection_random_angle.schema.yml +61 -0
  234. simtools/schemas/model_parameters/mirror_reflectivity.schema.yml +40 -0
  235. simtools/schemas/model_parameters/multiplicity_offset.schema.yml +46 -0
  236. simtools/schemas/model_parameters/nsb_autoscale_airmass.schema.yml +51 -0
  237. simtools/schemas/model_parameters/nsb_gain_drop_scale.schema.yml +37 -0
  238. simtools/schemas/model_parameters/nsb_offaxis.schema.yml +79 -0
  239. simtools/schemas/model_parameters/nsb_pixel_rate.schema.yml +47 -0
  240. simtools/schemas/model_parameters/nsb_reference_spectrum.schema.yml +34 -0
  241. simtools/schemas/model_parameters/nsb_reference_value.schema.yml +33 -0
  242. simtools/schemas/model_parameters/nsb_scaling_factor.schema.yml +35 -0
  243. simtools/schemas/model_parameters/nsb_skymap.schema.yml +39 -0
  244. simtools/schemas/model_parameters/nsb_spectrum.schema.yml +50 -0
  245. simtools/schemas/model_parameters/num_gains.schema.yml +34 -0
  246. simtools/schemas/model_parameters/only_triggered_telescopes.schema.yml +33 -0
  247. simtools/schemas/model_parameters/optics_properties.schema.yml +31 -0
  248. simtools/schemas/model_parameters/parabolic_dish.schema.yml +32 -0
  249. simtools/schemas/model_parameters/pedestal_events.schema.yml +32 -0
  250. simtools/schemas/model_parameters/photon_delay.schema.yml +38 -0
  251. simtools/schemas/model_parameters/photons_per_run.schema.yml +33 -0
  252. simtools/schemas/model_parameters/pixel_cells.schema.yml +35 -0
  253. simtools/schemas/model_parameters/pixels_parallel.schema.yml +54 -0
  254. simtools/schemas/model_parameters/pixeltrg_time_step.schema.yml +40 -0
  255. simtools/schemas/model_parameters/pm_average_gain.schema.yml +34 -0
  256. simtools/schemas/model_parameters/pm_collection_efficiency.schema.yml +40 -0
  257. simtools/schemas/model_parameters/pm_gain_index.schema.yml +36 -0
  258. simtools/schemas/model_parameters/pm_photoelectron_spectrum.schema.yml +41 -0
  259. simtools/schemas/model_parameters/pm_transit_time.schema.yml +63 -0
  260. simtools/schemas/model_parameters/pm_voltage_variation.schema.yml +39 -0
  261. simtools/schemas/model_parameters/primary_mirror_degraded_map.schema.yml +42 -0
  262. simtools/schemas/model_parameters/primary_mirror_diameter.schema.yml +33 -0
  263. simtools/schemas/model_parameters/primary_mirror_hole_diameter.schema.yml +33 -0
  264. simtools/schemas/model_parameters/primary_mirror_incidence_angle.schema.yml +29 -0
  265. simtools/schemas/model_parameters/primary_mirror_parameters.schema.yml +168 -0
  266. simtools/schemas/model_parameters/primary_mirror_ref_radius.schema.yml +36 -0
  267. simtools/schemas/model_parameters/primary_mirror_segmentation.schema.yml +34 -0
  268. simtools/schemas/model_parameters/qe_variation.schema.yml +43 -0
  269. simtools/schemas/model_parameters/quantum_efficiency.schema.yml +42 -0
  270. simtools/schemas/model_parameters/random_focal_length.schema.yml +45 -0
  271. simtools/schemas/model_parameters/random_generator.schema.yml +36 -0
  272. simtools/schemas/model_parameters/reference_point_altitude.schema.yml +35 -0
  273. simtools/schemas/model_parameters/reference_point_latitude.schema.yml +36 -0
  274. simtools/schemas/model_parameters/reference_point_longitude.schema.yml +36 -0
  275. simtools/schemas/model_parameters/reference_point_utm_east.schema.yml +34 -0
  276. simtools/schemas/model_parameters/reference_point_utm_north.schema.yml +34 -0
  277. simtools/schemas/model_parameters/sampled_output.schema.yml +31 -0
  278. simtools/schemas/model_parameters/save_pe_with_amplitude.schema.yml +34 -0
  279. simtools/schemas/model_parameters/secondary_mirror_baffle.schema.yml +79 -0
  280. simtools/schemas/model_parameters/secondary_mirror_degraded_map.schema.yml +42 -0
  281. simtools/schemas/model_parameters/secondary_mirror_degraded_reflection.schema.yml +41 -0
  282. simtools/schemas/model_parameters/secondary_mirror_diameter.schema.yml +33 -0
  283. simtools/schemas/model_parameters/secondary_mirror_hole_diameter.schema.yml +36 -0
  284. simtools/schemas/model_parameters/secondary_mirror_incidence_angle.schema.yml +29 -0
  285. simtools/schemas/model_parameters/secondary_mirror_parameters.schema.yml +168 -0
  286. simtools/schemas/model_parameters/secondary_mirror_ref_radius.schema.yml +36 -0
  287. simtools/schemas/model_parameters/secondary_mirror_reflectivity.schema.yml +35 -0
  288. simtools/schemas/model_parameters/secondary_mirror_segmentation.schema.yml +37 -0
  289. simtools/schemas/model_parameters/secondary_mirror_shadow_diameter.schema.yml +40 -0
  290. simtools/schemas/model_parameters/secondary_mirror_shadow_offset.schema.yml +40 -0
  291. simtools/schemas/model_parameters/store_photoelectrons.schema.yml +41 -0
  292. simtools/schemas/model_parameters/tailcut_scale.schema.yml +40 -0
  293. simtools/schemas/model_parameters/telescope_axis_height.schema.yml +31 -0
  294. simtools/schemas/model_parameters/telescope_random_angle.schema.yml +35 -0
  295. simtools/schemas/model_parameters/telescope_random_error.schema.yml +34 -0
  296. simtools/schemas/model_parameters/telescope_sphere_radius.schema.yml +37 -0
  297. simtools/schemas/model_parameters/telescope_transmission.schema.yml +113 -0
  298. simtools/schemas/model_parameters/teltrig_min_sigsum.schema.yml +41 -0
  299. simtools/schemas/model_parameters/teltrig_min_time.schema.yml +36 -0
  300. simtools/schemas/model_parameters/transit_time_calib_error.schema.yml +36 -0
  301. simtools/schemas/model_parameters/transit_time_compensate_error.schema.yml +37 -0
  302. simtools/schemas/model_parameters/transit_time_compensate_step.schema.yml +38 -0
  303. simtools/schemas/model_parameters/transit_time_error.schema.yml +45 -0
  304. simtools/schemas/model_parameters/transit_time_jitter.schema.yml +36 -0
  305. simtools/schemas/model_parameters/trigger_current_limit.schema.yml +32 -0
  306. simtools/schemas/model_parameters/trigger_delay_compensation.schema.yml +53 -0
  307. simtools/schemas/model_parameters/trigger_pixels.schema.yml +40 -0
  308. simtools/simtel/simtel_config_reader.py +353 -0
  309. simtools/simtel/simtel_config_writer.py +244 -63
  310. simtools/simtel/{simtel_events.py → simtel_io_events.py} +26 -25
  311. simtools/simtel/simtel_io_histogram.py +661 -0
  312. simtools/simtel/simtel_io_histograms.py +569 -0
  313. simtools/simtel/simulator_array.py +145 -0
  314. simtools/simtel/{simtel_runner_camera_efficiency.py → simulator_camera_efficiency.py} +76 -52
  315. simtools/simtel/simulator_light_emission.py +473 -0
  316. simtools/simtel/simulator_ray_tracing.py +262 -0
  317. simtools/simulator.py +220 -446
  318. simtools/testing/__init__.py +0 -0
  319. simtools/testing/assertions.py +151 -0
  320. simtools/testing/configuration.py +226 -0
  321. simtools/testing/helpers.py +42 -0
  322. simtools/testing/validate_output.py +240 -0
  323. simtools/utils/general.py +340 -437
  324. simtools/utils/geometry.py +12 -12
  325. simtools/utils/names.py +257 -644
  326. simtools/utils/value_conversion.py +176 -0
  327. simtools/version.py +3 -1
  328. simtools/visualization/legend_handlers.py +135 -152
  329. simtools/visualization/plot_camera.py +379 -0
  330. simtools/visualization/visualize.py +346 -167
  331. gammasimtools-0.6.1.dist-info/METADATA +0 -180
  332. gammasimtools-0.6.1.dist-info/RECORD +0 -91
  333. gammasimtools-0.6.1.dist-info/entry_points.txt +0 -23
  334. simtools/_dev_version/scm_version.py +0 -10
  335. simtools/applications/db_development_tools/add_new_parameter_to_db.py +0 -81
  336. simtools/applications/db_development_tools/add_unit_to_parameter_in_db.py +0 -59
  337. simtools/applications/db_development_tools/mark_non_optics_parameters_non_applicable.py +0 -102
  338. simtools/applications/get_parameter.py +0 -92
  339. simtools/applications/make_regular_arrays.py +0 -160
  340. simtools/applications/produce_array_config.py +0 -136
  341. simtools/applications/production.py +0 -313
  342. simtools/applications/sim_showers_for_trigger_rates.py +0 -187
  343. simtools/applications/tune_psf.py +0 -334
  344. simtools/corsika/corsika_default_config.py +0 -282
  345. simtools/corsika/corsika_runner.py +0 -450
  346. simtools/corsika_simtel/corsika_simtel_runner.py +0 -197
  347. simtools/db_handler.py +0 -1480
  348. simtools/ray_tracing.py +0 -525
  349. simtools/simtel/simtel_histograms.py +0 -414
  350. simtools/simtel/simtel_runner.py +0 -244
  351. simtools/simtel/simtel_runner_array.py +0 -293
  352. simtools/simtel/simtel_runner_ray_tracing.py +0 -277
  353. {gammasimtools-0.6.1.dist-info → gammasimtools-0.8.2.dist-info}/LICENSE +0 -0
  354. {gammasimtools-0.6.1.dist-info → gammasimtools-0.8.2.dist-info}/top_level.txt +0 -0
  355. /simtools/{corsika_simtel → db}/__init__.py +0 -0
@@ -1,8 +1,6 @@
1
1
  #!/usr/bin/python3
2
2
 
3
3
  """
4
- Summary
5
- -------
6
4
  Get a file from the DB.
7
5
 
8
6
  The name of the file is required.
@@ -17,8 +15,6 @@
17
15
  output_path (str)
18
16
  Name of the local output directory where to save the files.
19
17
  Default it $CWD.
20
- verbosity (str, optional)
21
- Log level to print.
22
18
 
23
19
  Example
24
20
  -------
@@ -26,13 +22,13 @@
26
22
 
27
23
  .. code-block:: console
28
24
 
29
- simtools-get-file-from-db --file_name mirror_CTA-N-LST1_v2019-03-31.dat
25
+ simtools-db-get-file-from-db --file_name mirror_CTA-N-LST1_v2019-03-31.dat
30
26
 
31
27
  Expected final print-out message:
32
28
 
33
29
  .. code-block:: console
34
30
 
35
- INFO::get_file_from_db(l82)::main::Got file mirror_CTA-N-LST1_v2019-03-31.dat from DB \
31
+ INFO::db_get_file_from_db(l82)::main::Got file mirror_CTA-N-LST1_v2019-03-31.dat from DB \
36
32
  CTA-Simulation-Model and saved into .
37
33
 
38
34
  """
@@ -40,11 +36,12 @@
40
36
  import logging
41
37
 
42
38
  import simtools.utils.general as gen
43
- from simtools import db_handler
44
39
  from simtools.configuration import configurator
40
+ from simtools.db import db_handler
41
+ from simtools.io_operations import io_handler
45
42
 
46
43
 
47
- def main():
44
+ def _parse():
48
45
  config = configurator.Configurator(
49
46
  description="Get file(s) from the DB.",
50
47
  usage="simtools-get-file-from-db --file_name mirror_CTA-S-LST_v2020-04-07.dat",
@@ -52,47 +49,46 @@ def main():
52
49
 
53
50
  config.parser.add_argument(
54
51
  "--file_name",
55
- help=("The name of the file to be downloaded."),
52
+ help="The name of the file to be downloaded.",
56
53
  type=str,
57
54
  required=True,
58
55
  )
59
- args_dict, db_config = config.initialize(db_config=True)
56
+ return config.initialize(db_config=True, output=True)
57
+
58
+
59
+ def main(): # noqa: D103
60
+ args_dict, db_config = _parse()
60
61
 
61
62
  logger = logging.getLogger()
62
63
  logger.setLevel(gen.get_log_level_from_user(args_dict["log_level"]))
64
+ _io_handler = io_handler.IOHandler()
63
65
 
64
66
  db = db_handler.DatabaseHandler(mongo_db_config=db_config)
65
67
  available_dbs = [
66
- db.DB_TABULATED_DATA,
67
- db.DB_CTA_SIMULATION_MODEL,
68
+ db_config["db_simulation_model"],
68
69
  db.DB_CTA_SIMULATION_MODEL_DESCRIPTIONS,
69
- db.DB_REFERENCE_DATA,
70
70
  db.DB_DERIVED_VALUES,
71
71
  "sandbox",
72
- "test-data",
73
72
  ]
74
73
  file_id = None
75
- if args_dict["output_path"].exists():
76
- for db_name in available_dbs:
77
- try:
78
- file_id = db.export_file_db(
79
- db_name, args_dict["output_path"], args_dict["file_name"]
80
- )
81
- logger.info(
82
- f"Got file {args_dict['file_name']} from DB {db_name} "
83
- f"and saved into {args_dict['output_path']}"
84
- )
85
- break
86
- except FileNotFoundError:
87
- continue
88
-
89
- if file_id is None:
90
- logger.error(
91
- f"The file {args_dict['file_name']} was not found in any of the available DBs."
74
+ for db_name in available_dbs:
75
+ try:
76
+ file_id = db.export_file_db(
77
+ db_name, _io_handler.get_output_directory(), args_dict["file_name"]
78
+ )
79
+ logger.info(
80
+ f"Got file {args_dict['file_name']} from DB {db_name} "
81
+ f"and saved into {_io_handler.get_output_directory()}"
92
82
  )
93
- raise FileNotFoundError
94
- else:
95
- logger.error(f"Aborted, directory {args_dict['output_path']} does not exist")
83
+ break
84
+ except FileNotFoundError:
85
+ continue
86
+
87
+ if file_id is None:
88
+ logger.error(
89
+ f"The file {args_dict['file_name']} was not found in any of the available DBs."
90
+ )
91
+ raise FileNotFoundError
96
92
 
97
93
 
98
94
  if __name__ == "__main__":
@@ -0,0 +1,131 @@
1
+ #!/usr/bin/python3
2
+
3
+ r"""
4
+ Get a parameter entry from DB for a specific telescope or a site.
5
+
6
+ The application receives a parameter name, a site, a telescope (if applicable) and \
7
+ a version. It then prints out the parameter entry.
8
+
9
+ Command line arguments
10
+ ----------------------
11
+ parameter (str, required)
12
+ Parameter name
13
+
14
+ site (str, required)
15
+ South or North.
16
+
17
+ telescope (str, optional)
18
+ Telescope model name (e.g. LST-1, SST-D, ...)
19
+
20
+ log_level (str, optional)
21
+ Log level to print.
22
+
23
+ Raises
24
+ ------
25
+ KeyError in case the parameter requested does not exist in the model parameters.
26
+
27
+ Example
28
+ -------
29
+ Get the mirror_list parameter from the DB.
30
+
31
+ .. code-block:: console
32
+
33
+ simtools-db-get-parameter-from-db --parameter mirror_list \\
34
+ --site North --telescope LSTN-01 \\
35
+ --model_version 5.0.0
36
+
37
+ Expected final print-out message:
38
+
39
+ .. code-block:: console
40
+
41
+ {'Applicable': True,
42
+ 'File': True,
43
+ 'Type': 'str',
44
+ 'Value': 'mirror_CTA-N-LST1_v2019-03-31.dat',
45
+ 'Version': '5.0.0',
46
+ '_id': ObjectId('608834f257df2db2531b8e78'),
47
+ 'entry_date': datetime.datetime(2021, 4, 27, 15, 59, 46, tzinfo=<bson.tz_util.FixedOffset \
48
+ object at 0x7f601dd51d80>)}
49
+
50
+ """
51
+
52
+ import json
53
+ import logging
54
+ from pathlib import Path
55
+ from pprint import pprint
56
+
57
+ import simtools.utils.general as gen
58
+ from simtools.configuration import configurator
59
+ from simtools.db import db_handler
60
+ from simtools.io_operations import io_handler
61
+
62
+
63
+ def _parse():
64
+ config = configurator.Configurator(
65
+ description=(
66
+ "Get a parameter entry from DB for a specific telescope or a site. "
67
+ "The application receives a parameter name, a site, a telescope (if applicable), "
68
+ "and a version. It then prints out the parameter entry. "
69
+ )
70
+ )
71
+
72
+ config.parser.add_argument("--parameter", help="Parameter name", type=str, required=True)
73
+ config.parser.add_argument(
74
+ "--db_collection",
75
+ help="DB collection to which to add the file",
76
+ default="telescopes",
77
+ required=False,
78
+ )
79
+ config.parser.add_argument(
80
+ "--output_file",
81
+ help="output file name (if not given: print to stdout)",
82
+ type=str,
83
+ required=False,
84
+ )
85
+
86
+ return config.initialize(db_config=True, simulation_model="telescope")
87
+
88
+
89
+ def main(): # noqa: D103
90
+ args_dict, db_config = _parse()
91
+
92
+ logger = logging.getLogger()
93
+ logger.setLevel(gen.get_log_level_from_user(args_dict["log_level"]))
94
+
95
+ db = db_handler.DatabaseHandler(mongo_db_config=db_config)
96
+
97
+ if args_dict["db_collection"] == "configuration_sim_telarray":
98
+ pars = db.get_model_parameters(
99
+ args_dict["site"],
100
+ args_dict["telescope"],
101
+ args_dict["model_version"],
102
+ collection="configuration_sim_telarray",
103
+ )
104
+ elif args_dict["db_collection"] == "configuration_corsika":
105
+ pars = db.get_corsika_configuration_parameters(args_dict["model_version"])
106
+ elif args_dict["telescope"] is not None:
107
+ pars = db.get_model_parameters(
108
+ args_dict["site"],
109
+ args_dict["telescope"],
110
+ args_dict["model_version"],
111
+ collection="telescopes",
112
+ )
113
+ else:
114
+ pars = db.get_site_parameters(args_dict["site"], args_dict["model_version"])
115
+ if args_dict["parameter"] not in pars:
116
+ raise KeyError(f"The requested parameter, {args_dict['parameter']}, does not exist.")
117
+ if args_dict["output_file"] is not None:
118
+ _io_handler = io_handler.IOHandler()
119
+ pars[args_dict["parameter"]].pop("_id")
120
+ pars[args_dict["parameter"]].pop("entry_date")
121
+ _output_file = Path(_io_handler.get_output_directory()) / args_dict["output_file"]
122
+ with open(_output_file, "w", encoding="utf-8") as json_file:
123
+ json.dump(pars[args_dict["parameter"]], json_file, indent=4)
124
+ else:
125
+ print()
126
+ pprint(pars[args_dict["parameter"]])
127
+ print()
128
+
129
+
130
+ if __name__ == "__main__":
131
+ main()
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/python3
2
+
3
+ """
4
+ Inspect databases and print (available database names and collections).
5
+
6
+ Command line arguments
7
+ ----------------------
8
+ db_name (str, optional)
9
+ Inspect a specific database.
10
+ """
11
+
12
+ import logging
13
+
14
+ import simtools.utils.general as gen
15
+ from simtools.configuration import configurator
16
+ from simtools.db import db_handler
17
+
18
+
19
+ def _parse():
20
+ config = configurator.Configurator(description="Inspect databases")
21
+ config.parser.add_argument(
22
+ "--db_name",
23
+ help="Inspect a specific database (use all to print all databases)",
24
+ default="all",
25
+ required=True,
26
+ )
27
+ return config.initialize(db_config=True, simulation_model="telescope")
28
+
29
+
30
+ def main(): # noqa: D103
31
+ args_dict, db_config = _parse()
32
+
33
+ logger = logging.getLogger()
34
+ logger.setLevel(gen.get_log_level_from_user(args_dict["log_level"]))
35
+
36
+ db = db_handler.DatabaseHandler(mongo_db_config=db_config)
37
+
38
+ databases = db.db_client.list_database_names()
39
+
40
+ for db_name in databases:
41
+ if args_dict["db_name"] != "all" and db_name != args_dict["db_name"]:
42
+ continue
43
+ # missing admin rights; skip config and admin
44
+ if db_name in ("config", "admin", "local"):
45
+ continue
46
+ print("Database:", db_name)
47
+ collections = db.get_collections(db_name=db_name)
48
+ print(" Collections:", collections)
49
+
50
+
51
+ if __name__ == "__main__":
52
+ main()
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/python3
2
2
 
3
- """
4
- Summary
5
- -------
6
- Derive the simulation model parameter **mirror_reflection_random_angle**
7
- (sometimes called mirror roughness) to match the measured containment diameter
8
- of the optical point-spread function (PSF) of individual mirror panels.
3
+ r"""
4
+ Derive the simulation model parameter mirror_reflection_random_angle.
5
+
6
+ This parameter, often referred to as "mirror roughness," is used to align the simulation
7
+ with the measured containment diameter of the optical point-spread function (PSF) for
8
+ individual mirror panels.
9
9
 
10
10
  Description
11
11
  -----------
@@ -30,11 +30,11 @@
30
30
  * file (table) with measured focal lengths per mirror panel
31
31
  (provided through ``--mirror_list``)
32
32
  * randomly generated focal lengths using an expected spread (value given through
33
- ``--random_flen``) around the mean focal length (provided through the
34
- :ref:`Model Parameters DB`). This option is switched with ``--use_random_flen``.
33
+ ``--random_focal_length``) around the mean focal length (provided through the
34
+ Model Parameters DB). This option is switched with ``--use_random_focal_length``.
35
35
 
36
36
  The tuning algorithm requires a starting value for the random reflection angle. This is either
37
- taken from the :ref:`Model Parameters DB` (default) or can be set using the argument ``--rnda``.
37
+ taken from the Model Parameters DB (default) or can be set using the argument ``--rnda``.
38
38
 
39
39
  Ray-tracing simulations are performed for single mirror configurations for each
40
40
  mirror given in the mirror_list. The mean simulated containment diameter for all the mirrors
@@ -83,76 +83,59 @@
83
83
  default model is read from the simulation model database.
84
84
  mirror_list (file, optional)
85
85
  Table with mirror ID and panel radius.
86
- use_random_flen (activation mode, optional)
87
- Use random focal lengths, instead of the measured ones. The argument random_flen can be
88
- used to replace the default random_focal_length from the model.
89
- random_flen (float, optional)
86
+ use_random_focal_length (activation mode, optional)
87
+ Use random focal lengths, instead of the measured ones. The argument random_focal_length
88
+ can be used to replace the default random_focal_length from the model.
89
+ random_focal_length (float, optional)
90
90
  Value of the random focal lengths to replace the default random_focal_length. Only used if
91
- use_random_flen is activated.
91
+ 'use_random_focal_length' is activated.
92
92
  no_tuning (activation mode, optional)
93
93
  Turn off the tuning - A single case will be simulated and plotted.
94
94
  test (activation mode, optional)
95
95
  If activated, application will be faster by simulating only few mirrors.
96
- verbosity (str, optional)
97
- Log level to print.
98
96
 
99
97
  Example
100
98
  -------
101
99
  Derive mirror random reflection angle for a mid-sized telescope (MST),
102
- simulation production Prod5.
100
+ simulation production 5.0.0
103
101
 
104
102
  .. code-block:: console
105
103
 
106
104
  simtools-derive-mirror-rnda \\
107
- --site North \\
108
- --telescope MST-FlashCam-D \\
105
+ --site South \\
106
+ --telescope LSTS-design \\
107
+ --model_version 6.0.0 \\
109
108
  --containment_fraction 0.8 \\
110
- --mirror_list MLTdata-preproduction.ecsv \\
111
- --psf_measurement MLTdata-preproduction.ecsv \\
112
- --rnda 0.0063 \\
113
- --test
114
-
115
- Runtime about 4 min.
116
-
117
- The output is saved in `simtools-output/derive_mirror_rnda`.
118
- Use the parameter ``--output_path`` to change the output directory.
109
+ --mirror_list ./tests/resources/mirror_list_CTA-N-LST1_v2019-03-31_rotated.ecsv
110
+ --rnda 0.003 \\
111
+ --psf_measurement_containment_mean 1.4 \\
119
112
 
120
113
  Expected final print-out message:
121
114
 
122
115
  .. code-block:: console
123
116
 
124
117
  Measured D80:
125
- Mean = 1.403 cm, StdDev = 0.163 cm
118
+ Mean = 1.400 cm
126
119
 
127
120
  Simulated D80:
128
- Mean = 1.404 cm, StdDev = 0.608 cm
121
+ Mean = 1.406 cm, StdDev = 0.005 cm
129
122
 
130
123
  mirror_random_reflection_angle
131
- Previous value = 0.006300
132
- New value = 0.004975
124
+ Previous value = 0.003000
125
+ New value = 0.003824
133
126
 
134
127
  """
135
128
 
136
129
  import logging
137
130
  from pathlib import Path
138
131
 
139
- import astropy.units as u
140
- import numpy as np
141
- from astropy.table import QTable, Table
142
-
143
- import simtools.data_model.model_data_writer as writer
144
132
  import simtools.utils.general as gen
145
133
  from simtools.configuration import configurator
146
- from simtools.data_model.metadata_collector import MetadataCollector
147
- from simtools.model.telescope_model import TelescopeModel
148
- from simtools.ray_tracing import RayTracing
134
+ from simtools.ray_tracing.mirror_panel_psf import MirrorPanelPSF
149
135
 
150
136
 
151
137
  def _parse(label):
152
- """
153
- Parse command line configuration
154
- """
155
-
138
+ """Parse command line configuration."""
156
139
  config = configurator.Configurator(
157
140
  description="Derive mirror random reflection angle.", label=label
158
141
  )
@@ -196,14 +179,17 @@ def _parse(label):
196
179
  required=False,
197
180
  )
198
181
  config.parser.add_argument(
199
- "--use_random_flen",
182
+ "--use_random_focal_length",
200
183
  help=("Use random focal lengths."),
201
184
  action="store_true",
202
185
  required=False,
203
186
  )
204
187
  config.parser.add_argument(
205
- "--random_flen",
206
- help="Value of the random focal length. Only used if use_random_flen is activated.",
188
+ "--random_focal_length",
189
+ help=(
190
+ "Value of the random focal length. "
191
+ "Only used if 'use_random_focal_length' is activated."
192
+ ),
207
193
  default=None,
208
194
  type=float,
209
195
  required=False,
@@ -214,131 +200,10 @@ def _parse(label):
214
200
  action="store_true",
215
201
  required=False,
216
202
  )
217
- return config.initialize(db_config=True, output=True, telescope_model=True)
218
-
203
+ return config.initialize(db_config=True, output=True, simulation_model="telescope")
219
204
 
220
- def _define_telescope_model(label, args_dict, db_config):
221
- """
222
- Define telescope model and update configuration
223
- with mirror list and/or random focal length given
224
- as input
225
-
226
- Attributes
227
- ----------
228
- label: str
229
- Application label.
230
- args_dict: dict
231
- Dictionary with configuration parameters.
232
- db_config:
233
- Dictionary with database configuration.
234
-
235
- Returns
236
- -------
237
- tel TelescopeModel
238
- telescope model
239
205
 
240
- """
241
-
242
- tel = TelescopeModel(
243
- site=args_dict["site"],
244
- telescope_model_name=args_dict["telescope"],
245
- model_version=args_dict["model_version"],
246
- mongo_db_config=db_config,
247
- label=label,
248
- )
249
- if args_dict["mirror_list"] is not None:
250
- mirror_list_file = gen.find_file(name=args_dict["mirror_list"], loc=args_dict["model_path"])
251
- tel.change_parameter("mirror_list", args_dict["mirror_list"])
252
- tel.add_parameter_file("mirror_list", mirror_list_file)
253
- if args_dict["random_flen"] is not None:
254
- tel.change_parameter("random_focal_length", str(args_dict["random_flen"]))
255
-
256
- return tel
257
-
258
-
259
- def _print_and_write_results(
260
- args_dict, rnda_start, rnda_opt, mean_d80, sig_d80, results_rnda, results_mean, results_sig
261
- ):
262
- """
263
- Print results to screen and write metadata and data files
264
- in the requested format
265
-
266
- """
267
-
268
- containment_fraction_percent = int(args_dict["containment_fraction"] * 100)
269
-
270
- # Printing results to stdout
271
- print(f"\nMeasured D{containment_fraction_percent}:")
272
- if args_dict["psf_measurement_containment_sigma"] is not None:
273
- print(
274
- f"Mean = {args_dict['psf_measurement_containment_mean']:.3f} cm, "
275
- f"StdDev = {args_dict['psf_measurement_containment_sigma']:.3f} cm"
276
- )
277
- else:
278
- print(f"Mean = {args_dict['psf_measurement_containment_mean']:.3f} cm")
279
- print(f"\nSimulated D{containment_fraction_percent}:")
280
- print(f"Mean = {mean_d80:.3f} cm, StdDev = {sig_d80:.3f} cm")
281
- print("\nmirror_random_reflection_angle")
282
- print(f"Previous value = {rnda_start:.6f}")
283
- print(f"New value = {rnda_opt:.6f}\n")
284
-
285
- # Result table written to ecsv file using file_writer
286
- # First entry is always the best fit result
287
- result_table = QTable(
288
- [
289
- [True] + [False] * len(results_rnda),
290
- ([rnda_opt] + results_rnda) * u.deg,
291
- ([0.0] * (len(results_rnda) + 1)),
292
- ([0.0] * (len(results_rnda) + 1)) * u.deg,
293
- ([mean_d80] + results_mean) * u.cm,
294
- ([sig_d80] + results_sig) * u.cm,
295
- ],
296
- names=(
297
- "best_fit",
298
- "mirror_reflection_random_angle_sigma1",
299
- "mirror_reflection_random_angle_fraction2",
300
- "mirror_reflection_random_angle_sigma2",
301
- f"containment_radius_D{containment_fraction_percent}",
302
- f"containment_radius_sigma_D{containment_fraction_percent}",
303
- ),
304
- )
305
- writer.ModelDataWriter.dump(
306
- args_dict=args_dict,
307
- metadata=MetadataCollector(args_dict=args_dict).top_level_meta,
308
- product_data=result_table,
309
- )
310
-
311
-
312
- def _get_psf_containment(logger, args_dict):
313
- """
314
- Read measured single-mirror point-spread function (containment)
315
- from file and return mean and sigma
316
-
317
- """
318
-
319
- # If this is a test, read just the first few lines since we only simulate those mirrors
320
- data_end = args_dict["number_of_mirrors_to_test"] + 1 if args_dict["test"] else None
321
- _psf_list = Table.read(args_dict["psf_measurement"], format="ascii.ecsv", data_end=data_end)
322
- try:
323
- args_dict["psf_measurement_containment_mean"] = np.nanmean(
324
- np.array(_psf_list["psf_opt"].to("cm").value)
325
- )
326
- args_dict["psf_measurement_containment_sigma"] = np.nanstd(
327
- np.array(_psf_list["psf_opt"].to("cm").value)
328
- )
329
- except KeyError:
330
- logger.debug(
331
- f"Missing column for psf measurement (psf_opt) in {args_dict['psf_measurement']}"
332
- )
333
- raise
334
-
335
- logger.info(
336
- f"Determined PSF containment to {args_dict['psf_measurement_containment_mean']:.4} "
337
- f"+- {args_dict['psf_measurement_containment_sigma']:.4} cm"
338
- )
339
-
340
-
341
- def main():
206
+ def main(): # noqa: D103
342
207
  label = Path(__file__).stem
343
208
 
344
209
  args_dict, db_config = _parse(label)
@@ -346,91 +211,10 @@ def main():
346
211
  logger = logging.getLogger()
347
212
  logger.setLevel(gen.get_log_level_from_user(args_dict["log_level"]))
348
213
 
349
- tel = _define_telescope_model(label, args_dict, db_config)
350
-
351
- if args_dict["test"]:
352
- args_dict["number_of_mirrors_to_test"] = 4
353
-
354
- if args_dict["psf_measurement"]:
355
- _get_psf_containment(logger, args_dict)
356
- if not args_dict["psf_measurement_containment_mean"]:
357
- logger.error("Missing PSF measurement")
358
- raise ValueError
359
-
360
- def run(rnda):
361
- """Runs the simulations for one given value of rnda"""
362
- tel.change_parameter("mirror_reflection_random_angle", str(rnda))
363
- ray = RayTracing.from_kwargs(
364
- telescope_model=tel,
365
- single_mirror_mode=True,
366
- mirror_numbers=list(range(1, args_dict["number_of_mirrors_to_test"] + 1))
367
- if args_dict["test"]
368
- else "all",
369
- simtel_source_path=args_dict.get("simtel_path", None),
370
- use_random_focal_length=args_dict["use_random_flen"],
371
- )
372
- ray.simulate(test=False, force=True) # force has to be True, always
373
- ray.analyze(force=True)
374
-
375
- return (
376
- ray.get_mean("d80_cm").to(u.cm).value,
377
- ray.get_std_dev("d80_cm").to(u.cm).value,
378
- )
379
-
380
- # First - rnda from previous model or from command line
381
- if args_dict["rnda"] != 0:
382
- rnda_start = args_dict["rnda"]
383
- else:
384
- rnda_start = tel.get_parameter("mirror_reflection_random_angle")["Value"]
385
- if isinstance(rnda_start, str):
386
- rnda_start = float(rnda_start.split()[0])
387
-
388
- logger.info(f"Start value for mirror_reflection_random_angle: {rnda_start} deg")
389
-
390
- results_rnda = []
391
- results_mean = []
392
- results_sig = []
393
- if args_dict["no_tuning"]:
394
- rnda_opt = rnda_start
395
- else:
396
-
397
- def collect_results(rnda, mean, sig):
398
- results_rnda.append(rnda)
399
- results_mean.append(mean)
400
- results_sig.append(sig)
401
-
402
- stop = False
403
- mean_d80, sig_d80 = run(rnda_start)
404
- rnda = rnda_start
405
- sign_delta = np.sign(mean_d80 - args_dict["psf_measurement_containment_mean"])
406
- collect_results(rnda, mean_d80, sig_d80)
407
- while not stop:
408
- rnda = rnda - (0.1 * rnda_start * sign_delta)
409
- if rnda < 0:
410
- rnda = 0
411
- collect_results(rnda, mean_d80, sig_d80)
412
- break
413
- mean_d80, sig_d80 = run(rnda)
414
- new_sign_delta = np.sign(mean_d80 - args_dict["psf_measurement_containment_mean"])
415
- stop = new_sign_delta != sign_delta
416
- sign_delta = new_sign_delta
417
- collect_results(rnda, mean_d80, sig_d80)
418
-
419
- # Linear interpolation using two last rnda values
420
- results_rnda, results_mean, results_sig = gen.sort_arrays(
421
- results_rnda, results_mean, results_sig
422
- )
423
- rnda_opt = np.interp(
424
- x=args_dict["psf_measurement_containment_mean"],
425
- xp=results_mean,
426
- fp=results_rnda,
427
- )
428
-
429
- mean_d80, sig_d80 = run(rnda_opt)
430
-
431
- _print_and_write_results(
432
- args_dict, rnda_start, rnda_opt, mean_d80, sig_d80, results_rnda, results_mean, results_sig
433
- )
214
+ panel_psf = MirrorPanelPSF(label, args_dict, db_config)
215
+ panel_psf.derive_random_reflection_angle(save_figures=True)
216
+ panel_psf.print_results()
217
+ panel_psf.write_optimization_data()
434
218
 
435
219
 
436
220
  if __name__ == "__main__":