gammasimtools 0.6.0__py3-none-any.whl → 0.8.1__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 (353) hide show
  1. gammasimtools-0.8.1.dist-info/METADATA +172 -0
  2. gammasimtools-0.8.1.dist-info/RECORD +346 -0
  3. {gammasimtools-0.6.0.dist-info → gammasimtools-0.8.1.dist-info}/WHEEL +1 -1
  4. gammasimtools-0.8.1.dist-info/entry_points.txt +31 -0
  5. simtools/_version.py +2 -2
  6. simtools/applications/calculate_trigger_rate.py +210 -0
  7. simtools/applications/convert_all_model_parameters_from_simtel.py +372 -0
  8. simtools/applications/{print_array_elements.py → convert_geo_coordinates_of_array_elements.py} +58 -63
  9. simtools/applications/convert_model_parameter_from_simtel.py +119 -0
  10. simtools/applications/{add_file_to_db.py → db_add_file_to_db.py} +70 -60
  11. simtools/applications/db_add_model_parameters_from_repository_to_db.py +184 -0
  12. simtools/applications/db_add_value_from_json_to_db.py +105 -0
  13. simtools/applications/db_development_tools/write_array_elements_positions_to_repository.py +180 -0
  14. simtools/applications/db_get_array_layouts_from_db.py +162 -0
  15. simtools/applications/{get_file_from_db.py → db_get_file_from_db.py} +30 -34
  16. simtools/applications/db_get_parameter_from_db.py +131 -0
  17. simtools/applications/db_inspect_databases.py +52 -0
  18. simtools/applications/derive_mirror_rnda.py +39 -255
  19. simtools/applications/derive_psf_parameters.py +441 -0
  20. simtools/applications/generate_array_config.py +82 -0
  21. simtools/applications/generate_corsika_histograms.py +52 -52
  22. simtools/applications/generate_default_metadata.py +5 -8
  23. simtools/applications/generate_regular_arrays.py +117 -0
  24. simtools/applications/generate_simtel_array_histograms.py +97 -56
  25. simtools/applications/plot_array_layout.py +345 -115
  26. simtools/applications/production_generate_simulation_config.py +158 -0
  27. simtools/applications/production_scale_events.py +168 -0
  28. simtools/applications/simulate_light_emission.py +478 -0
  29. simtools/applications/simulate_prod.py +97 -175
  30. simtools/applications/submit_data_from_external.py +9 -12
  31. simtools/applications/submit_model_parameter_from_external.py +122 -0
  32. simtools/applications/validate_camera_efficiency.py +35 -102
  33. simtools/applications/validate_camera_fov.py +20 -19
  34. simtools/applications/{compare_cumulative_psf.py → validate_cumulative_psf.py} +45 -44
  35. simtools/applications/validate_file_using_schema.py +113 -47
  36. simtools/applications/validate_optics.py +17 -22
  37. simtools/camera_efficiency.py +193 -202
  38. simtools/configuration/commandline_parser.py +384 -96
  39. simtools/configuration/configurator.py +55 -71
  40. simtools/constants.py +5 -5
  41. simtools/corsika/corsika_config.py +482 -342
  42. simtools/corsika/corsika_histograms.py +226 -204
  43. simtools/corsika/corsika_histograms_visualize.py +23 -24
  44. simtools/corsika/primary_particle.py +159 -0
  45. simtools/data_model/data_reader.py +25 -20
  46. simtools/data_model/format_checkers.py +52 -0
  47. simtools/data_model/metadata_collector.py +210 -184
  48. simtools/data_model/metadata_model.py +115 -37
  49. simtools/data_model/model_data_writer.py +335 -26
  50. simtools/data_model/validate_data.py +366 -154
  51. simtools/db/db_array_elements.py +130 -0
  52. simtools/db/db_from_repo_handler.py +106 -0
  53. simtools/db/db_handler.py +1246 -0
  54. simtools/io_operations/hdf5_handler.py +3 -1
  55. simtools/io_operations/io_handler.py +32 -57
  56. simtools/job_execution/job_manager.py +82 -69
  57. simtools/layout/array_layout.py +329 -533
  58. simtools/layout/geo_coordinates.py +8 -11
  59. simtools/layout/telescope_position.py +163 -86
  60. simtools/model/array_model.py +305 -256
  61. simtools/model/calibration_model.py +50 -0
  62. simtools/model/camera.py +233 -496
  63. simtools/model/mirrors.py +61 -44
  64. simtools/model/model_parameter.py +602 -0
  65. simtools/model/model_utils.py +7 -103
  66. simtools/model/site_model.py +161 -0
  67. simtools/model/telescope_model.py +127 -621
  68. simtools/production_configuration/calculate_statistical_errors_grid_point.py +454 -0
  69. simtools/production_configuration/event_scaler.py +146 -0
  70. simtools/production_configuration/generate_simulation_config.py +193 -0
  71. simtools/production_configuration/interpolation_handler.py +197 -0
  72. simtools/ray_tracing/__init__.py +0 -0
  73. simtools/ray_tracing/mirror_panel_psf.py +280 -0
  74. simtools/{psf_analysis.py → ray_tracing/psf_analysis.py} +133 -47
  75. simtools/ray_tracing/ray_tracing.py +646 -0
  76. simtools/runners/__init__.py +0 -0
  77. simtools/runners/corsika_runner.py +240 -0
  78. simtools/runners/corsika_simtel_runner.py +225 -0
  79. simtools/runners/runner_services.py +307 -0
  80. simtools/runners/simtel_runner.py +224 -0
  81. simtools/schemas/array_elements.yml +137 -0
  82. simtools/schemas/integration_tests_config.metaschema.yml +93 -0
  83. simtools/schemas/metadata.metaschema.yml +6 -0
  84. simtools/schemas/model_parameter.metaschema.yml +78 -0
  85. simtools/schemas/{data.metaschema.yml → model_parameter_and_data_schema.metaschema.yml} +27 -44
  86. simtools/schemas/model_parameters/adjust_gain.schema.yml +37 -0
  87. simtools/schemas/model_parameters/altitude.schema.yml +37 -0
  88. simtools/schemas/model_parameters/array_coordinates.schema.yml +33 -0
  89. simtools/schemas/model_parameters/array_coordinates_UTM.schema.yml +77 -0
  90. simtools/schemas/model_parameters/array_element_position_ground.schema.yml +39 -0
  91. simtools/schemas/model_parameters/array_element_position_utm.schema.yml +39 -0
  92. simtools/schemas/model_parameters/array_layouts.schema.yml +48 -0
  93. simtools/schemas/model_parameters/array_triggers.schema.yml +93 -0
  94. simtools/schemas/model_parameters/asum_clipping.schema.yml +38 -0
  95. simtools/schemas/model_parameters/asum_offset.schema.yml +35 -0
  96. simtools/schemas/model_parameters/asum_shaping.schema.yml +35 -0
  97. simtools/schemas/model_parameters/asum_threshold.schema.yml +38 -0
  98. simtools/schemas/model_parameters/atmospheric_profile.schema.yml +32 -0
  99. simtools/schemas/model_parameters/atmospheric_transmission.schema.yml +35 -0
  100. simtools/schemas/model_parameters/axes_offsets.schema.yml +53 -0
  101. simtools/schemas/model_parameters/camera_body_diameter.schema.yml +40 -0
  102. simtools/schemas/model_parameters/camera_body_shape.schema.yml +45 -0
  103. simtools/schemas/model_parameters/camera_config_file.schema.yml +40 -0
  104. simtools/schemas/model_parameters/camera_config_rotate.schema.yml +36 -0
  105. simtools/schemas/model_parameters/camera_degraded_efficiency.schema.yml +43 -0
  106. simtools/schemas/model_parameters/camera_degraded_map.schema.yml +42 -0
  107. simtools/schemas/model_parameters/camera_depth.schema.yml +42 -0
  108. simtools/schemas/model_parameters/camera_filter.schema.yml +45 -0
  109. simtools/schemas/model_parameters/camera_filter_incidence_angle.schema.yml +29 -0
  110. simtools/schemas/model_parameters/camera_pixels.schema.yml +36 -0
  111. simtools/schemas/model_parameters/camera_transmission.schema.yml +41 -0
  112. simtools/schemas/model_parameters/channels_per_chip.schema.yml +36 -0
  113. simtools/schemas/model_parameters/correct_nsb_spectrum_to_telescope_altitude.schema.yml +35 -0
  114. simtools/schemas/model_parameters/corsika_cherenkov_photon_bunch_size.schema.yml +27 -0
  115. simtools/schemas/model_parameters/corsika_cherenkov_photon_wavelength_range.schema.yml +38 -0
  116. simtools/schemas/model_parameters/corsika_first_interaction_height.schema.yml +28 -0
  117. simtools/schemas/model_parameters/corsika_iact_io_buffer.schema.yml +23 -0
  118. simtools/schemas/model_parameters/corsika_iact_max_bunches.schema.yml +27 -0
  119. simtools/schemas/model_parameters/corsika_iact_split_auto.schema.yml +28 -0
  120. simtools/schemas/model_parameters/corsika_longitudinal_shower_development.schema.yml +27 -0
  121. simtools/schemas/model_parameters/corsika_observation_level.schema.yml +38 -0
  122. simtools/schemas/model_parameters/corsika_particle_kinetic_energy_cutoff.schema.yml +52 -0
  123. simtools/schemas/model_parameters/corsika_starting_grammage.schema.yml +27 -0
  124. simtools/schemas/model_parameters/dark_events.schema.yml +32 -0
  125. simtools/schemas/model_parameters/default_trigger.schema.yml +35 -0
  126. simtools/schemas/model_parameters/design_model.schema.yml +31 -0
  127. simtools/schemas/model_parameters/disc_ac_coupled.schema.yml +32 -0
  128. simtools/schemas/model_parameters/disc_bins.schema.yml +39 -0
  129. simtools/schemas/model_parameters/disc_start.schema.yml +41 -0
  130. simtools/schemas/model_parameters/discriminator_amplitude.schema.yml +42 -0
  131. simtools/schemas/model_parameters/discriminator_fall_time.schema.yml +41 -0
  132. simtools/schemas/model_parameters/discriminator_gate_length.schema.yml +41 -0
  133. simtools/schemas/model_parameters/discriminator_hysteresis.schema.yml +39 -0
  134. simtools/schemas/model_parameters/discriminator_output_amplitude.schema.yml +40 -0
  135. simtools/schemas/model_parameters/discriminator_output_var_percent.schema.yml +41 -0
  136. simtools/schemas/model_parameters/discriminator_pulse_shape.schema.yml +33 -0
  137. simtools/schemas/model_parameters/discriminator_rise_time.schema.yml +42 -0
  138. simtools/schemas/model_parameters/discriminator_scale_threshold.schema.yml +37 -0
  139. simtools/schemas/model_parameters/discriminator_sigsum_over_threshold.schema.yml +44 -0
  140. simtools/schemas/model_parameters/discriminator_threshold.schema.yml +36 -0
  141. simtools/schemas/model_parameters/discriminator_time_over_threshold.schema.yml +45 -0
  142. simtools/schemas/model_parameters/discriminator_var_gate_length.schema.yml +40 -0
  143. simtools/schemas/model_parameters/discriminator_var_sigsum_over_threshold.schema.yml +41 -0
  144. simtools/schemas/model_parameters/discriminator_var_threshold.schema.yml +38 -0
  145. simtools/schemas/model_parameters/discriminator_var_time_over_threshold.schema.yml +38 -0
  146. simtools/schemas/model_parameters/dish_shape_length.schema.yml +41 -0
  147. simtools/schemas/model_parameters/dsum_clipping.schema.yml +38 -0
  148. simtools/schemas/model_parameters/dsum_ignore_below.schema.yml +38 -0
  149. simtools/schemas/model_parameters/dsum_offset.schema.yml +37 -0
  150. simtools/schemas/model_parameters/dsum_pedsub.schema.yml +33 -0
  151. simtools/schemas/model_parameters/dsum_pre_clipping.schema.yml +39 -0
  152. simtools/schemas/model_parameters/dsum_prescale.schema.yml +44 -0
  153. simtools/schemas/model_parameters/dsum_presum_max.schema.yml +38 -0
  154. simtools/schemas/model_parameters/dsum_presum_shift.schema.yml +45 -0
  155. simtools/schemas/model_parameters/dsum_shaping.schema.yml +44 -0
  156. simtools/schemas/model_parameters/dsum_shaping_renormalize.schema.yml +32 -0
  157. simtools/schemas/model_parameters/dsum_threshold.schema.yml +43 -0
  158. simtools/schemas/model_parameters/dsum_zero_clip.schema.yml +42 -0
  159. simtools/schemas/model_parameters/effective_focal_length.schema.yml +61 -0
  160. simtools/schemas/model_parameters/epsg_code.schema.yml +37 -0
  161. simtools/schemas/model_parameters/fadc_ac_coupled.schema.yml +35 -0
  162. simtools/schemas/model_parameters/fadc_amplitude.schema.yml +46 -0
  163. simtools/schemas/model_parameters/fadc_bins.schema.yml +40 -0
  164. simtools/schemas/model_parameters/fadc_compensate_pedestal.schema.yml +50 -0
  165. simtools/schemas/model_parameters/fadc_dev_pedestal.schema.yml +38 -0
  166. simtools/schemas/model_parameters/fadc_err_compensate_pedestal.schema.yml +42 -0
  167. simtools/schemas/model_parameters/fadc_err_pedestal.schema.yml +49 -0
  168. simtools/schemas/model_parameters/fadc_lg_amplitude.schema.yml +47 -0
  169. simtools/schemas/model_parameters/fadc_lg_compensate_pedestal.schema.yml +51 -0
  170. simtools/schemas/model_parameters/fadc_lg_dev_pedestal.schema.yml +37 -0
  171. simtools/schemas/model_parameters/fadc_lg_err_compensate_pedestal.schema.yml +43 -0
  172. simtools/schemas/model_parameters/fadc_lg_err_pedestal.schema.yml +49 -0
  173. simtools/schemas/model_parameters/fadc_lg_max_signal.schema.yml +43 -0
  174. simtools/schemas/model_parameters/fadc_lg_max_sum.schema.yml +39 -0
  175. simtools/schemas/model_parameters/fadc_lg_noise.schema.yml +42 -0
  176. simtools/schemas/model_parameters/fadc_lg_pedestal.schema.yml +40 -0
  177. simtools/schemas/model_parameters/fadc_lg_sensitivity.schema.yml +50 -0
  178. simtools/schemas/model_parameters/fadc_lg_sysvar_pedestal.schema.yml +42 -0
  179. simtools/schemas/model_parameters/fadc_lg_var_pedestal.schema.yml +41 -0
  180. simtools/schemas/model_parameters/fadc_lg_var_sensitivity.schema.yml +42 -0
  181. simtools/schemas/model_parameters/fadc_max_signal.schema.yml +43 -0
  182. simtools/schemas/model_parameters/fadc_max_sum.schema.yml +39 -0
  183. simtools/schemas/model_parameters/fadc_mhz.schema.yml +31 -0
  184. simtools/schemas/model_parameters/fadc_noise.schema.yml +41 -0
  185. simtools/schemas/model_parameters/fadc_pedestal.schema.yml +40 -0
  186. simtools/schemas/model_parameters/fadc_pulse_shape.schema.yml +39 -0
  187. simtools/schemas/model_parameters/fadc_sensitivity.schema.yml +50 -0
  188. simtools/schemas/model_parameters/fadc_sum_bins.schema.yml +43 -0
  189. simtools/schemas/model_parameters/fadc_sum_offset.schema.yml +43 -0
  190. simtools/schemas/model_parameters/fadc_sysvar_pedestal.schema.yml +42 -0
  191. simtools/schemas/model_parameters/fadc_var_pedestal.schema.yml +41 -0
  192. simtools/schemas/model_parameters/fadc_var_sensitivity.schema.yml +42 -0
  193. simtools/schemas/model_parameters/flatfielding.schema.yml +37 -0
  194. simtools/schemas/model_parameters/focal_length.schema.yml +45 -0
  195. simtools/schemas/model_parameters/focal_surface_parameters.schema.yml +158 -0
  196. simtools/schemas/model_parameters/focal_surface_ref_radius.schema.yml +29 -0
  197. simtools/schemas/model_parameters/focus_offset.schema.yml +66 -0
  198. simtools/schemas/model_parameters/gain_variation.schema.yml +43 -0
  199. simtools/schemas/model_parameters/geomag_horizontal.schema.yml +34 -0
  200. simtools/schemas/model_parameters/geomag_rotation.schema.yml +37 -0
  201. simtools/schemas/model_parameters/geomag_vertical.schema.yml +34 -0
  202. simtools/schemas/model_parameters/hg_lg_variation.schema.yml +36 -0
  203. simtools/schemas/model_parameters/iobuf_maximum.schema.yml +34 -0
  204. simtools/schemas/model_parameters/iobuf_output_maximum.schema.yml +34 -0
  205. simtools/schemas/model_parameters/laser_events.schema.yml +36 -0
  206. simtools/schemas/model_parameters/laser_external_trigger.schema.yml +35 -0
  207. simtools/schemas/model_parameters/laser_photons.schema.yml +32 -0
  208. simtools/schemas/model_parameters/laser_pulse_exptime.schema.yml +34 -0
  209. simtools/schemas/model_parameters/laser_pulse_offset.schema.yml +34 -0
  210. simtools/schemas/model_parameters/laser_pulse_sigtime.schema.yml +33 -0
  211. simtools/schemas/model_parameters/laser_pulse_twidth.schema.yml +33 -0
  212. simtools/schemas/model_parameters/laser_var_photons.schema.yml +33 -0
  213. simtools/schemas/model_parameters/laser_wavelength.schema.yml +33 -0
  214. simtools/schemas/model_parameters/led_events.schema.yml +34 -0
  215. simtools/schemas/model_parameters/led_photons.schema.yml +34 -0
  216. simtools/schemas/model_parameters/led_pulse_offset.schema.yml +32 -0
  217. simtools/schemas/model_parameters/led_pulse_sigtime.schema.yml +33 -0
  218. simtools/schemas/model_parameters/led_var_photons.schema.yml +34 -0
  219. simtools/schemas/model_parameters/lightguide_efficiency_vs_incidence_angle.schema.yml +41 -0
  220. simtools/schemas/model_parameters/lightguide_efficiency_vs_wavelength.schema.yml +43 -0
  221. simtools/schemas/model_parameters/min_photoelectrons.schema.yml +35 -0
  222. simtools/schemas/model_parameters/min_photons.schema.yml +32 -0
  223. simtools/schemas/model_parameters/mirror_align_random_distance.schema.yml +36 -0
  224. simtools/schemas/model_parameters/mirror_align_random_horizontal.schema.yml +64 -0
  225. simtools/schemas/model_parameters/mirror_align_random_vertical.schema.yml +64 -0
  226. simtools/schemas/model_parameters/mirror_class.schema.yml +41 -0
  227. simtools/schemas/model_parameters/mirror_degraded_reflection.schema.yml +51 -0
  228. simtools/schemas/model_parameters/mirror_focal_length.schema.yml +42 -0
  229. simtools/schemas/model_parameters/mirror_list.schema.yml +38 -0
  230. simtools/schemas/model_parameters/mirror_offset.schema.yml +41 -0
  231. simtools/schemas/model_parameters/mirror_panel_2f_measurements.schema.yml +39 -0
  232. simtools/schemas/model_parameters/mirror_reflection_random_angle.schema.yml +61 -0
  233. simtools/schemas/model_parameters/mirror_reflectivity.schema.yml +40 -0
  234. simtools/schemas/model_parameters/multiplicity_offset.schema.yml +46 -0
  235. simtools/schemas/model_parameters/nsb_autoscale_airmass.schema.yml +51 -0
  236. simtools/schemas/model_parameters/nsb_gain_drop_scale.schema.yml +37 -0
  237. simtools/schemas/model_parameters/nsb_offaxis.schema.yml +79 -0
  238. simtools/schemas/model_parameters/nsb_pixel_rate.schema.yml +47 -0
  239. simtools/schemas/model_parameters/nsb_reference_spectrum.schema.yml +34 -0
  240. simtools/schemas/model_parameters/nsb_reference_value.schema.yml +33 -0
  241. simtools/schemas/model_parameters/nsb_scaling_factor.schema.yml +35 -0
  242. simtools/schemas/model_parameters/nsb_skymap.schema.yml +39 -0
  243. simtools/schemas/model_parameters/nsb_spectrum.schema.yml +50 -0
  244. simtools/schemas/model_parameters/num_gains.schema.yml +34 -0
  245. simtools/schemas/model_parameters/only_triggered_telescopes.schema.yml +33 -0
  246. simtools/schemas/model_parameters/optics_properties.schema.yml +31 -0
  247. simtools/schemas/model_parameters/parabolic_dish.schema.yml +32 -0
  248. simtools/schemas/model_parameters/pedestal_events.schema.yml +32 -0
  249. simtools/schemas/model_parameters/photon_delay.schema.yml +38 -0
  250. simtools/schemas/model_parameters/photons_per_run.schema.yml +33 -0
  251. simtools/schemas/model_parameters/pixel_cells.schema.yml +35 -0
  252. simtools/schemas/model_parameters/pixels_parallel.schema.yml +54 -0
  253. simtools/schemas/model_parameters/pixeltrg_time_step.schema.yml +40 -0
  254. simtools/schemas/model_parameters/pm_average_gain.schema.yml +34 -0
  255. simtools/schemas/model_parameters/pm_collection_efficiency.schema.yml +40 -0
  256. simtools/schemas/model_parameters/pm_gain_index.schema.yml +36 -0
  257. simtools/schemas/model_parameters/pm_photoelectron_spectrum.schema.yml +41 -0
  258. simtools/schemas/model_parameters/pm_transit_time.schema.yml +63 -0
  259. simtools/schemas/model_parameters/pm_voltage_variation.schema.yml +39 -0
  260. simtools/schemas/model_parameters/primary_mirror_degraded_map.schema.yml +42 -0
  261. simtools/schemas/model_parameters/primary_mirror_diameter.schema.yml +33 -0
  262. simtools/schemas/model_parameters/primary_mirror_hole_diameter.schema.yml +33 -0
  263. simtools/schemas/model_parameters/primary_mirror_incidence_angle.schema.yml +29 -0
  264. simtools/schemas/model_parameters/primary_mirror_parameters.schema.yml +168 -0
  265. simtools/schemas/model_parameters/primary_mirror_ref_radius.schema.yml +36 -0
  266. simtools/schemas/model_parameters/primary_mirror_segmentation.schema.yml +34 -0
  267. simtools/schemas/model_parameters/qe_variation.schema.yml +43 -0
  268. simtools/schemas/model_parameters/quantum_efficiency.schema.yml +42 -0
  269. simtools/schemas/model_parameters/random_focal_length.schema.yml +45 -0
  270. simtools/schemas/model_parameters/random_generator.schema.yml +36 -0
  271. simtools/schemas/model_parameters/reference_point_altitude.schema.yml +35 -0
  272. simtools/schemas/model_parameters/reference_point_latitude.schema.yml +36 -0
  273. simtools/schemas/model_parameters/reference_point_longitude.schema.yml +36 -0
  274. simtools/schemas/model_parameters/reference_point_utm_east.schema.yml +34 -0
  275. simtools/schemas/model_parameters/reference_point_utm_north.schema.yml +34 -0
  276. simtools/schemas/model_parameters/sampled_output.schema.yml +31 -0
  277. simtools/schemas/model_parameters/save_pe_with_amplitude.schema.yml +34 -0
  278. simtools/schemas/model_parameters/secondary_mirror_baffle.schema.yml +79 -0
  279. simtools/schemas/model_parameters/secondary_mirror_degraded_map.schema.yml +42 -0
  280. simtools/schemas/model_parameters/secondary_mirror_degraded_reflection.schema.yml +41 -0
  281. simtools/schemas/model_parameters/secondary_mirror_diameter.schema.yml +33 -0
  282. simtools/schemas/model_parameters/secondary_mirror_hole_diameter.schema.yml +36 -0
  283. simtools/schemas/model_parameters/secondary_mirror_incidence_angle.schema.yml +29 -0
  284. simtools/schemas/model_parameters/secondary_mirror_parameters.schema.yml +168 -0
  285. simtools/schemas/model_parameters/secondary_mirror_ref_radius.schema.yml +36 -0
  286. simtools/schemas/model_parameters/secondary_mirror_reflectivity.schema.yml +35 -0
  287. simtools/schemas/model_parameters/secondary_mirror_segmentation.schema.yml +37 -0
  288. simtools/schemas/model_parameters/secondary_mirror_shadow_diameter.schema.yml +40 -0
  289. simtools/schemas/model_parameters/secondary_mirror_shadow_offset.schema.yml +40 -0
  290. simtools/schemas/model_parameters/store_photoelectrons.schema.yml +41 -0
  291. simtools/schemas/model_parameters/tailcut_scale.schema.yml +40 -0
  292. simtools/schemas/model_parameters/telescope_axis_height.schema.yml +31 -0
  293. simtools/schemas/model_parameters/telescope_random_angle.schema.yml +35 -0
  294. simtools/schemas/model_parameters/telescope_random_error.schema.yml +34 -0
  295. simtools/schemas/model_parameters/telescope_sphere_radius.schema.yml +37 -0
  296. simtools/schemas/model_parameters/telescope_transmission.schema.yml +113 -0
  297. simtools/schemas/model_parameters/teltrig_min_sigsum.schema.yml +41 -0
  298. simtools/schemas/model_parameters/teltrig_min_time.schema.yml +36 -0
  299. simtools/schemas/model_parameters/transit_time_calib_error.schema.yml +36 -0
  300. simtools/schemas/model_parameters/transit_time_compensate_error.schema.yml +37 -0
  301. simtools/schemas/model_parameters/transit_time_compensate_step.schema.yml +38 -0
  302. simtools/schemas/model_parameters/transit_time_error.schema.yml +45 -0
  303. simtools/schemas/model_parameters/transit_time_jitter.schema.yml +36 -0
  304. simtools/schemas/model_parameters/trigger_current_limit.schema.yml +32 -0
  305. simtools/schemas/model_parameters/trigger_delay_compensation.schema.yml +53 -0
  306. simtools/schemas/model_parameters/trigger_pixels.schema.yml +40 -0
  307. simtools/simtel/simtel_config_reader.py +353 -0
  308. simtools/simtel/simtel_config_writer.py +244 -63
  309. simtools/simtel/{simtel_events.py → simtel_io_events.py} +26 -25
  310. simtools/simtel/simtel_io_histogram.py +661 -0
  311. simtools/simtel/simtel_io_histograms.py +569 -0
  312. simtools/simtel/simulator_array.py +145 -0
  313. simtools/simtel/{simtel_runner_camera_efficiency.py → simulator_camera_efficiency.py} +76 -52
  314. simtools/simtel/simulator_light_emission.py +473 -0
  315. simtools/simtel/simulator_ray_tracing.py +262 -0
  316. simtools/simulator.py +220 -446
  317. simtools/testing/__init__.py +0 -0
  318. simtools/testing/assertions.py +151 -0
  319. simtools/testing/configuration.py +226 -0
  320. simtools/testing/helpers.py +42 -0
  321. simtools/testing/validate_output.py +240 -0
  322. simtools/utils/general.py +340 -437
  323. simtools/utils/geometry.py +12 -12
  324. simtools/utils/names.py +266 -568
  325. simtools/utils/value_conversion.py +176 -0
  326. simtools/version.py +2 -0
  327. simtools/visualization/legend_handlers.py +135 -152
  328. simtools/visualization/plot_camera.py +379 -0
  329. simtools/visualization/visualize.py +346 -167
  330. gammasimtools-0.6.0.dist-info/METADATA +0 -180
  331. gammasimtools-0.6.0.dist-info/RECORD +0 -91
  332. gammasimtools-0.6.0.dist-info/entry_points.txt +0 -23
  333. simtools/applications/db_development_tools/add_new_parameter_to_db.py +0 -81
  334. simtools/applications/db_development_tools/add_unit_to_parameter_in_db.py +0 -59
  335. simtools/applications/db_development_tools/mark_non_optics_parameters_non_applicable.py +0 -102
  336. simtools/applications/get_parameter.py +0 -92
  337. simtools/applications/make_regular_arrays.py +0 -160
  338. simtools/applications/produce_array_config.py +0 -136
  339. simtools/applications/production.py +0 -313
  340. simtools/applications/sim_showers_for_trigger_rates.py +0 -187
  341. simtools/applications/tune_psf.py +0 -334
  342. simtools/corsika/corsika_default_config.py +0 -282
  343. simtools/corsika/corsika_runner.py +0 -450
  344. simtools/corsika_simtel/corsika_simtel_runner.py +0 -197
  345. simtools/db_handler.py +0 -1481
  346. simtools/ray_tracing.py +0 -525
  347. simtools/simtel/simtel_histograms.py +0 -414
  348. simtools/simtel/simtel_runner.py +0 -244
  349. simtools/simtel/simtel_runner_array.py +0 -293
  350. simtools/simtel/simtel_runner_ray_tracing.py +0 -277
  351. {gammasimtools-0.6.0.dist-info → gammasimtools-0.8.1.dist-info}/LICENSE +0 -0
  352. {gammasimtools-0.6.0.dist-info → gammasimtools-0.8.1.dist-info}/top_level.txt +0 -0
  353. /simtools/{corsika_simtel → db}/__init__.py +0 -0
simtools/db_handler.py DELETED
@@ -1,1481 +0,0 @@
1
- """ Module to handle interaction with DB. """
2
-
3
- import logging
4
- from pathlib import Path
5
- from threading import Lock
6
-
7
- import gridfs
8
- import pymongo
9
- import yaml
10
- from bson.objectid import ObjectId
11
- from pymongo import MongoClient
12
- from pymongo.errors import BulkWriteError
13
-
14
- import simtools.utils.general as gen
15
- from simtools.io_operations import io_handler
16
- from simtools.model.model_utils import get_telescope_class
17
- from simtools.utils import names
18
-
19
- __all__ = ["DatabaseHandler"]
20
-
21
-
22
- # pylint: disable=unsubscriptable-object
23
- # The above comment is because pylint does not know that DatabaseHandler.db_client is subscriptable
24
-
25
-
26
- class DatabaseHandler:
27
- """
28
- DatabaseHandler provides the interface to the DB.
29
-
30
- Parameters
31
- ----------
32
- io_handler: IOHandler
33
- Instance of IOHandler
34
- mongo_db_config: dict
35
- Dictionary with the MongoDB configuration with the following entries:
36
- "db_server" - DB server address
37
- "db_api_port" - Port to use
38
- "db_api_user" - API username
39
- "db_api_pw" - Password for the API user
40
- "db_api_authentication_database" - DB with user info (optional, default is "admin")
41
- """
42
-
43
- DB_TABULATED_DATA = "CTA-Simulation-Model"
44
- DB_CTA_SIMULATION_MODEL = "CTA-Simulation-Model"
45
- DB_CTA_SIMULATION_MODEL_DESCRIPTIONS = "CTA-Simulation-Model-Descriptions"
46
- DB_REFERENCE_DATA = "CTA-Reference-Data"
47
- DB_DERIVED_VALUES = "CTA-Simulation-Model-Derived-Values"
48
-
49
- ALLOWED_FILE_EXTENSIONS = [".dat", ".txt", ".lis", ".cfg", ".yml", ".yaml", ".ecsv"]
50
-
51
- db_client = None
52
-
53
- def __init__(self, mongo_db_config=None):
54
- """
55
- Initialize the DatabaseHandler class.
56
-
57
- Raises
58
- ------
59
- KeyError
60
- if there is non-valid key in the db_config.
61
-
62
- """
63
- self._logger = logging.getLogger(__name__)
64
- self._logger.debug("Initialize DatabaseHandler")
65
-
66
- self.mongo_db_config = mongo_db_config
67
- self._logger.debug(f"DB configuration: {self.mongo_db_config}")
68
- self.io_handler = io_handler.IOHandler()
69
-
70
- self._set_up_connection()
71
-
72
- def _set_up_connection(self):
73
- """
74
- Open the connection to MongoDB.
75
- """
76
- if self.mongo_db_config:
77
- if DatabaseHandler.db_client is None:
78
- lock = Lock()
79
- with lock:
80
- DatabaseHandler.db_client = self._open_mongo_db()
81
-
82
- def _open_mongo_db(self):
83
- """
84
- Open a connection to MongoDB and return the client to read/write to the DB with.
85
-
86
- Returns
87
- -------
88
- A PyMongo DB client
89
-
90
-
91
- """
92
- try:
93
- _db_client = MongoClient(
94
- self.mongo_db_config["db_server"],
95
- port=self.mongo_db_config["db_api_port"],
96
- username=self.mongo_db_config["db_api_user"],
97
- password=self.mongo_db_config["db_api_pw"],
98
- authSource=self.mongo_db_config.get("db_api_authentication_database", "admin"),
99
- ssl=True,
100
- tlsallowinvalidhostnames=True,
101
- tlsallowinvalidcertificates=True,
102
- )
103
- except KeyError:
104
- self._logger.error("Invalid setting of DB configuration")
105
- raise
106
-
107
- return _db_client
108
-
109
- @staticmethod
110
- def _get_telescope_model_name_for_db(site, telescope_model_name):
111
- """
112
- Make telescope name as the DB needs from site and telescope_model_name."""
113
- return site + "-" + telescope_model_name
114
-
115
- def get_model_parameters(
116
- self,
117
- site,
118
- telescope_model_name,
119
- model_version,
120
- only_applicable=False,
121
- ):
122
- """
123
- Get parameters from either MongoDB or yaml DB for a specific telescope.
124
-
125
- Parameters
126
- ----------
127
- site: str
128
- South or North.
129
- telescope_model_name: str
130
- Name of the telescope model (e.g. LST-1, MST-FlashCam-D)
131
- model_version: str
132
- Version of the model.
133
- only_applicable: bool
134
- If True, only applicable parameters will be read.
135
-
136
- Returns
137
- -------
138
- dict containing the parameters
139
-
140
- """
141
-
142
- _site_validated = names.validate_site_name(site)
143
- _tel_model_name_validated = names.validate_telescope_model_name(telescope_model_name)
144
-
145
- if self.mongo_db_config:
146
- # Only MongoDB supports tagged version
147
- _model_version = self._convert_version_to_tagged(
148
- model_version, DatabaseHandler.DB_CTA_SIMULATION_MODEL
149
- )
150
- _version_validated = names.validate_model_version_name(_model_version)
151
-
152
- _pars = self._get_model_parameters_mongo_db(
153
- DatabaseHandler.DB_CTA_SIMULATION_MODEL,
154
- _site_validated,
155
- _tel_model_name_validated,
156
- _version_validated,
157
- only_applicable,
158
- )
159
- return _pars
160
-
161
- _version_validated = names.validate_model_version_name(model_version)
162
-
163
- return self._get_model_parameters_yaml(
164
- _tel_model_name_validated,
165
- _version_validated,
166
- only_applicable,
167
- )
168
-
169
- def export_file_db(self, db_name, dest, file_name):
170
- """
171
- Get file from the DB and write to disk.
172
-
173
- Parameters
174
- ----------
175
- db_name: str
176
- Name of the DB to search in.
177
- dest: str or Path
178
- Location where to write the file to.
179
- file_name: str
180
- Name of the file to get.
181
-
182
- Returns
183
- -------
184
- file_id: GridOut._id
185
- the database ID the file was assigned when it was inserted to the DB.
186
-
187
- Raises
188
- ------
189
- FileNotFoundError
190
- If the desired file is not found.
191
-
192
- """
193
-
194
- self._logger.debug(f"Getting {file_name} from {db_name} and writing it to {dest}")
195
- file_path_instance = self._get_file_mongo_db(db_name, file_name)
196
- self._write_file_from_mongo_to_disk(db_name, dest, file_path_instance)
197
- return file_path_instance._id # pylint: disable=protected-access;
198
-
199
- def export_model_files(self, parameters, dest):
200
- """
201
- Export all the files in a model from the DB (Mongo or yaml) and write them to disk.
202
-
203
- Parameters
204
- ----------
205
- parameters: dict
206
- Dict of model parameters
207
- dest: str or Path
208
- Location where to write the files to.
209
-
210
- Raises
211
- ------
212
- FileNotFoundError
213
- if a file in parameters.values is not found
214
-
215
- """
216
-
217
- if self.mongo_db_config:
218
- self._logger.debug("Exporting model files from MongoDB")
219
- for info in parameters.values():
220
- if not info["File"]:
221
- continue
222
- if Path(dest).joinpath(info["Value"]).exists():
223
- self._logger.debug(f"File {info['Value']} already exists in {dest}")
224
- continue
225
- file = self._get_file_mongo_db(
226
- DatabaseHandler.DB_CTA_SIMULATION_MODEL, info["Value"]
227
- )
228
- self._write_file_from_mongo_to_disk(
229
- DatabaseHandler.DB_CTA_SIMULATION_MODEL, dest, file
230
- )
231
- else:
232
- self._logger.debug("Exporting model files from local model file directories")
233
- for value in parameters.values():
234
- if not self._is_file(value):
235
- continue
236
- self._write_model_file_yaml(value, dest, no_file_ok=True)
237
-
238
- @staticmethod
239
- def _is_file(value):
240
- """Verify if a parameter value is a file name."""
241
- return any(ext in str(value) for ext in DatabaseHandler.ALLOWED_FILE_EXTENSIONS)
242
-
243
- def _write_model_file_yaml(self, file_name, dest_dir, no_file_ok=False):
244
- """
245
- Find the file_name in the model files location and write a copy
246
- at the dest_dir directory.
247
-
248
- Parameters
249
- ----------
250
- file_name: str or Path
251
- File name to be found and copied.
252
- dest_dir: str or Path
253
- Path of the directory where the file will be written.
254
-
255
- """
256
-
257
- dest_file = Path(dest_dir).joinpath(file_name)
258
- try:
259
- file = gen.find_file(file_name, self.io_handler.model_path)
260
- except FileNotFoundError:
261
- if no_file_ok:
262
- self._logger.debug(f"File {file_name} not found but no_file_ok")
263
- return
264
-
265
- raise
266
-
267
- dest_file.write_text(file.read_text(encoding="utf-8"), encoding="utf-8")
268
-
269
- def _get_model_parameters_yaml(
270
- self, telescope_model_name, model_version, only_applicable=False
271
- ):
272
- """
273
- Get parameters from DB for one specific type.
274
-
275
- Parameters
276
- ----------
277
- telescope_model_name: str
278
- Telescope model name (e.g MST-FlashCam-D ...).
279
- model_version: str
280
- Version of the model.
281
- only_applicable: bool
282
- If True, only applicable parameters will be read.
283
-
284
- Returns
285
- -------
286
- dict containing the parameters
287
-
288
- """
289
-
290
- _tel_class = get_telescope_class(telescope_model_name)
291
- _tel_name_converted = names.convert_telescope_model_name_to_yaml(telescope_model_name)
292
-
293
- if _tel_class == "MST":
294
- # MST-FlashCam or MST-NectarCam
295
- _which_tel_labels = [_tel_name_converted, "MST-optics"]
296
- elif _tel_class == "SST":
297
- # SST = SST-Camera + SST-Structure
298
- _which_tel_labels = ["SST-Camera", "SST-Structure"]
299
- else:
300
- _which_tel_labels = [_tel_name_converted]
301
-
302
- # Selecting version and applicable (if on)
303
- _pars = {}
304
- for _tel in _which_tel_labels:
305
- _all_pars = self._get_all_model_parameters_yaml(_tel)
306
-
307
- # If _tel is a structure, only the applicable parameters will be collected, always.
308
- # The default ones will be covered by the camera parameters.
309
- _select_only_applicable = only_applicable or (_tel in ["MST-optics", "SST-Structure"])
310
-
311
- for par_name_in, par_info in _all_pars.items():
312
- if not par_info["Applicable"] and _select_only_applicable:
313
- continue
314
-
315
- if model_version not in par_info:
316
- continue
317
-
318
- _pars[par_name_in] = par_info[model_version]
319
-
320
- return _pars
321
-
322
- def _get_model_parameters_mongo_db(
323
- self, db_name, site, telescope_model_name, model_version, only_applicable=False
324
- ):
325
- """
326
- Get parameters from MongoDB for a specific telescope.
327
-
328
- Parameters
329
- ----------
330
- db_name: str
331
- the name of the DB
332
- site: str
333
- South or North.
334
- telescope_model_name: str
335
- Name of the telescope model (e.g. MST-FlashCam-D ...)
336
- model_version: str
337
- Version of the model.
338
- only_applicable: bool
339
- If True, only applicable parameters will be read.
340
-
341
- Returns
342
- -------
343
- dict containing the parameters
344
-
345
- """
346
-
347
- _site_validated = names.validate_site_name(site)
348
- _tel_name_db = self._get_telescope_model_name_for_db(_site_validated, telescope_model_name)
349
- _tel_class = get_telescope_class(telescope_model_name)
350
-
351
- self._logger.debug(f"Tel_name_db: {_tel_name_db}")
352
- self._logger.debug(f"Tel_class: {_tel_class}")
353
-
354
- if _tel_class == "MST":
355
- # MST-FlashCam or MST-NectarCam
356
- _which_tel_labels = [f"{_site_validated}-MST-Structure-D", _tel_name_db]
357
- elif _tel_class == "SST":
358
- # SST = SST-Camera + SST-Structure
359
- _which_tel_labels = [
360
- f"{_site_validated}-SST-Camera-D",
361
- f"{_site_validated}-SST-Structure-D",
362
- ]
363
- else:
364
- _which_tel_labels = [_tel_name_db]
365
-
366
- # Selecting version and applicable (if on)
367
- _pars = {}
368
- for _tel in _which_tel_labels:
369
- self._logger.debug(f"Getting {_tel} parameters from MongoDB")
370
-
371
- # If tel is a structure, only applicable pars will be collected, always.
372
- # The default ones will be covered by the camera pars.
373
- _select_only_applicable = only_applicable or (
374
- _tel
375
- in [
376
- f"{_site_validated}-MST-Structure-D",
377
- f"{_site_validated}-SST-Structure-D",
378
- ]
379
- )
380
-
381
- _pars.update(
382
- self.read_mongo_db(
383
- db_name,
384
- _tel,
385
- model_version,
386
- run_location=None,
387
- write_files=False,
388
- only_applicable=_select_only_applicable,
389
- )
390
- )
391
-
392
- return _pars
393
-
394
- def read_mongo_db(
395
- self,
396
- db_name,
397
- telescope_model_name_db,
398
- model_version,
399
- run_location,
400
- collection_name="telescopes",
401
- write_files=True,
402
- only_applicable=False,
403
- ):
404
- """
405
- Build and execute query to Read the MongoDB for a specific telescope.
406
- Also writes the files listed in the parameter values into the sim_telarray run location
407
-
408
- Parameters
409
- ----------
410
- db_name: str
411
- the name of the DB
412
- telescope_model_name_db: str
413
- Name of the telescope model (e.g. MST-FlashCam-D ...)
414
- model_version: str
415
- Version of the model.
416
- run_location: Path or str
417
- The sim_telarray run location to write the tabulated data files into.
418
- collection_name: str
419
- The name of the collection to read from.
420
- write_files: bool
421
- If true, write the files to the run_location.
422
- only_applicable: bool
423
- If True, only applicable parameters will be read.
424
-
425
- Returns
426
- -------
427
- dict containing the parameters
428
-
429
- Raises
430
- ------
431
- ValueError
432
- if query returned zero results.
433
-
434
- """
435
-
436
- collection = DatabaseHandler.db_client[db_name][collection_name]
437
- _parameters = {}
438
-
439
- _model_version = self._convert_version_to_tagged(
440
- model_version, DatabaseHandler.DB_CTA_SIMULATION_MODEL
441
- )
442
-
443
- query = {
444
- "Telescope": telescope_model_name_db,
445
- "Version": _model_version,
446
- }
447
-
448
- self._logger.debug(f"Trying the following query: {query}")
449
- if only_applicable:
450
- query["Applicable"] = True
451
- if collection.count_documents(query) < 1:
452
- raise ValueError(
453
- "The following query returned zero results! Check the input data and rerun.\n",
454
- query,
455
- )
456
- for post in collection.find(query):
457
- par_now = post["Parameter"]
458
- _parameters[par_now] = post
459
- _parameters[par_now].pop("Parameter", None)
460
- _parameters[par_now].pop("Telescope", None)
461
- _parameters[par_now]["entry_date"] = ObjectId(post["_id"]).generation_time
462
- if _parameters[par_now]["File"] and write_files:
463
- file = self._get_file_mongo_db(db_name, _parameters[par_now]["Value"])
464
-
465
- self._write_file_from_mongo_to_disk(db_name, run_location, file)
466
-
467
- return _parameters
468
-
469
- def _get_all_model_parameters_yaml(self, telescope_name_yaml):
470
- """
471
- Get all parameters from yaml DB for one specific type.
472
- No selection is applied.
473
-
474
- Parameters
475
- ----------
476
- telescope_name_yaml: str
477
- Telescope name as required by the yaml files.
478
-
479
- Returns
480
- -------
481
- dict containing the parameters
482
-
483
- """
484
-
485
- _file_name_db = f"parValues-{telescope_name_yaml}.yml"
486
- _yaml_file = gen.find_file(_file_name_db, self.io_handler.model_path)
487
- self._logger.debug(f"Reading DB file {_yaml_file}")
488
- with open(_yaml_file, "r", encoding="utf-8") as stream:
489
- _all_pars = yaml.safe_load(stream)
490
- return _all_pars
491
-
492
- def get_site_parameters(
493
- self,
494
- site,
495
- model_version,
496
- only_applicable=False,
497
- ):
498
- """
499
- Get parameters from either MongoDB or yaml DB for a specific site.
500
-
501
- Parameters
502
- ----------
503
- site: str
504
- South or North.
505
- model_version: str
506
- Version of the model.
507
- only_applicable: bool
508
- If True, only applicable parameters will be read.
509
-
510
- Returns
511
- -------
512
- dict containing the parameters
513
-
514
- """
515
- _site = names.validate_site_name(site)
516
- _model_version = names.validate_model_version_name(model_version)
517
-
518
- if self.mongo_db_config:
519
- _pars = self._get_site_parameters_mongo_db(
520
- DatabaseHandler.DB_CTA_SIMULATION_MODEL,
521
- _site,
522
- _model_version,
523
- only_applicable,
524
- )
525
- return _pars
526
-
527
- return self._get_site_parameters_yaml(_site, _model_version, only_applicable)
528
-
529
- def _get_site_parameters_yaml(self, site, model_version, only_applicable=False):
530
- """
531
- Get parameters from DB for a specific type.
532
-
533
- Parameters
534
- ----------
535
- site: str
536
- North or South.
537
- model_version: str
538
- Version of the model.
539
- only_applicable: bool
540
- If True, only applicable parameters will be read.
541
-
542
- Returns
543
- -------
544
- dict containing the parameters
545
-
546
- """
547
-
548
- site_yaml = "lapalma" if site == "North" else "paranal"
549
-
550
- yaml_file = gen.find_file("parValues-Sites.yml", self.io_handler.model_path)
551
- self._logger.info(f"Reading DB file {yaml_file}")
552
- with open(yaml_file, "r", encoding="utf-8") as stream:
553
- _all_pars_versions = yaml.safe_load(stream)
554
-
555
- _pars = {}
556
- for par_name, par_info in _all_pars_versions.items():
557
- if not par_info["Applicable"] and only_applicable:
558
- continue
559
- if site_yaml in par_name:
560
- par_name_in = "_".join(par_name.split("_")[1:])
561
-
562
- _pars[par_name_in] = par_info[model_version]
563
-
564
- return _pars
565
-
566
- def _get_site_parameters_mongo_db(self, db_name, site, model_version, only_applicable=False):
567
- """
568
- Get parameters from MongoDB for a specific telescope.
569
-
570
- Parameters
571
- ----------
572
- db_name: str
573
- The name of the DB.
574
- site: str
575
- South or North.
576
- model_version: str
577
- Version of the model.
578
- only_applicable: bool
579
- If True, only applicable parameters will be read.
580
-
581
- Returns
582
- -------
583
- dict containing the parameters
584
-
585
- Raises
586
- ------
587
- ValueError
588
- if query returned zero results.
589
-
590
- """
591
-
592
- _site_validated = names.validate_site_name(site)
593
- collection = DatabaseHandler.db_client[db_name].sites
594
- _parameters = {}
595
-
596
- _model_version = self._convert_version_to_tagged(
597
- model_version, DatabaseHandler.DB_CTA_SIMULATION_MODEL
598
- )
599
-
600
- query = {
601
- "Site": _site_validated,
602
- "Version": _model_version,
603
- }
604
- if only_applicable:
605
- query["Applicable"] = True
606
- if collection.count_documents(query) < 1:
607
- raise ValueError(
608
- "The following query returned zero results! Check the input data and rerun.\n",
609
- query,
610
- )
611
- for post in collection.find(query):
612
- par_now = post["Parameter"]
613
- _parameters[par_now] = post
614
- _parameters[par_now].pop("Parameter", None)
615
- _parameters[par_now].pop("Site", None)
616
- _parameters[par_now]["entry_date"] = ObjectId(post["_id"]).generation_time
617
-
618
- return _parameters
619
-
620
- @staticmethod
621
- def get_descriptions(
622
- db_name=DB_CTA_SIMULATION_MODEL_DESCRIPTIONS, collection_name="telescopes"
623
- ):
624
- """
625
- Get parameter descriptions from MongoDB
626
-
627
- Parameters
628
- ----------
629
- db_name: str
630
- The name of the DB.
631
- collection_name: str
632
- The name of the collection to read from.
633
-
634
- Returns
635
- -------
636
- dict containing the parameters with their descriptions
637
-
638
- """
639
-
640
- collection = DatabaseHandler.db_client[db_name][collection_name]
641
-
642
- _parameters = {}
643
-
644
- empty_query = {}
645
- for post in collection.find(empty_query):
646
- par_now = post["Parameter"]
647
- _parameters[par_now] = post
648
- _parameters[par_now].pop("Parameter", None)
649
- _parameters[par_now]["entry_date"] = ObjectId(post["_id"]).generation_time
650
-
651
- return _parameters
652
-
653
- def get_reference_data(self, site, model_version, only_applicable=False):
654
- """
655
- Get parameters from MongoDB for a specific telescope.
656
-
657
- Parameters
658
- ----------
659
- site: str
660
- South or North.
661
- model_version: str
662
- Version of the model.
663
- only_applicable: bool
664
- If True, only applicable parameters will be read.
665
-
666
- Returns
667
- -------
668
- dict containing the parameters
669
-
670
- Raises
671
- ------
672
- ValueError
673
- if query returned zero results.
674
-
675
- """
676
-
677
- _site_validated = names.validate_site_name(site)
678
- collection = DatabaseHandler.db_client[DatabaseHandler.DB_REFERENCE_DATA].reference_values
679
- _parameters = {}
680
-
681
- _model_version = self._convert_version_to_tagged(
682
- names.validate_model_version_name(model_version),
683
- DatabaseHandler.DB_CTA_SIMULATION_MODEL,
684
- )
685
-
686
- query = {
687
- "Site": _site_validated,
688
- "Version": _model_version,
689
- }
690
- if only_applicable:
691
- query["Applicable"] = True
692
- if collection.count_documents(query) < 1:
693
- raise ValueError(
694
- "The following query returned zero results! Check the input data and rerun.\n",
695
- query,
696
- )
697
- for post in collection.find(query):
698
- par_now = post["Parameter"]
699
- _parameters[par_now] = post
700
- _parameters[par_now].pop("Parameter", None)
701
- _parameters[par_now].pop("Site", None)
702
- _parameters[par_now]["entry_date"] = ObjectId(post["_id"]).generation_time
703
-
704
- return _parameters
705
-
706
- def get_derived_values(self, site, telescope_model_name, model_version):
707
- """
708
- Get a derived value from the DB for a specific telescope.
709
-
710
- Parameters
711
- ----------
712
- site: str
713
- South or North.
714
- telescope_model_name: str
715
- Name of the telescope model (e.g. MST-FlashCam-D ...)
716
- model_version: str
717
- Version of the model.
718
-
719
- Returns
720
- -------
721
- dict containing the parameters
722
-
723
- """
724
-
725
- _site_validated = names.validate_site_name(site)
726
- _tel_model_name_validated = names.validate_telescope_model_name(telescope_model_name)
727
- _tel_name_db = self._get_telescope_model_name_for_db(
728
- _site_validated, _tel_model_name_validated
729
- )
730
- _model_version = self._convert_version_to_tagged(
731
- names.validate_model_version_name(model_version),
732
- DatabaseHandler.DB_CTA_SIMULATION_MODEL,
733
- )
734
-
735
- self._logger.debug(f"Getting derived values for {_tel_name_db} from the DB")
736
-
737
- _pars = self.read_mongo_db(
738
- DatabaseHandler.DB_DERIVED_VALUES,
739
- _tel_name_db,
740
- _model_version,
741
- run_location=None,
742
- collection_name="derived_values",
743
- write_files=False,
744
- )
745
-
746
- return _pars
747
-
748
- @staticmethod
749
- def _get_file_mongo_db(db_name, file_name):
750
- """
751
- Extract a file from MongoDB and return GridFS file instance
752
-
753
- Parameters
754
- ----------
755
- db_name: str
756
- the name of the DB with files of tabulated data
757
- file_name: str
758
- The name of the file requested
759
-
760
- Returns
761
- -------
762
- GridOut
763
- A file instance returned by GridFS find_one
764
-
765
- Raises
766
- ------
767
- FileNotFoundError
768
- If the desired file is not found.
769
-
770
- """
771
-
772
- db = DatabaseHandler.db_client[db_name]
773
- file_system = gridfs.GridFS(db)
774
- if file_system.exists({"filename": file_name}):
775
- return file_system.find_one({"filename": file_name})
776
-
777
- raise FileNotFoundError(f"The file {file_name} does not exist in the database {db_name}")
778
-
779
- @staticmethod
780
- def _write_file_from_mongo_to_disk(db_name, path, file):
781
- """
782
- Extract a file from MongoDB and write it to disk
783
-
784
- Parameters
785
- ----------
786
- db_name: str
787
- the name of the DB with files of tabulated data
788
- path: str or Path
789
- The path to write the file to
790
- file: GridOut
791
- A file instance returned by GridFS find_one
792
- """
793
-
794
- db = DatabaseHandler.db_client[db_name]
795
- fs_output = gridfs.GridFSBucket(db)
796
- with open(Path(path).joinpath(file.filename), "wb") as output_file:
797
- fs_output.download_to_stream_by_name(file.filename, output_file)
798
-
799
- def copy_telescope(
800
- self,
801
- db_name,
802
- tel_to_copy,
803
- version_to_copy,
804
- new_tel_name,
805
- collection_name="telescopes",
806
- db_to_copy_to=None,
807
- collection_to_copy_to=None,
808
- ):
809
- """
810
- Copy a full telescope configuration to a new telescope name.
811
- Only a specific version is copied.
812
- (This function should be rarely used, probably only during "construction".)
813
-
814
- Parameters
815
- ----------
816
- db_name: str
817
- the name of the DB to copy from
818
- tel_to_copy: str
819
- The telescope to copy
820
- version_to_copy: str
821
- The version of the configuration to copy
822
- new_tel_name: str
823
- The name of the new telescope
824
- collection_name: str
825
- The name of the collection to copy from.
826
- db_to_copy_to: str
827
- The name of the DB to copy to.
828
- collection_to_copy_to: str
829
- The name of the collection to copy to.
830
-
831
- Raises
832
- ------
833
- BulkWriteError
834
-
835
- """
836
-
837
- if db_to_copy_to is None:
838
- db_to_copy_to = db_name
839
-
840
- if collection_to_copy_to is None:
841
- collection_to_copy_to = collection_name
842
-
843
- self._logger.info(
844
- f"Copying version {version_to_copy} of {tel_to_copy} "
845
- f"to the new telescope {new_tel_name} in the {db_to_copy_to} DB"
846
- )
847
-
848
- collection = DatabaseHandler.db_client[db_name][collection_name]
849
- db_entries = []
850
-
851
- _version_to_copy = self._convert_version_to_tagged(
852
- version_to_copy, DatabaseHandler.DB_CTA_SIMULATION_MODEL
853
- )
854
-
855
- query = {
856
- "Telescope": tel_to_copy,
857
- "Version": _version_to_copy,
858
- }
859
- for post in collection.find(query):
860
- post["Telescope"] = new_tel_name
861
- post.pop("_id", None)
862
- db_entries.append(post)
863
-
864
- self._logger.info(f"Creating new telescope {new_tel_name}")
865
- collection = DatabaseHandler.db_client[db_to_copy_to][collection_to_copy_to]
866
- try:
867
- collection.insert_many(db_entries)
868
- except BulkWriteError as exc:
869
- raise BulkWriteError(str(exc.details)) from exc
870
-
871
- def copy_documents(self, db_name, collection, query, db_to_copy_to, collection_to_copy_to=None):
872
- """
873
- Copy the documents matching to "query" to the DB "db_to_copy_to".
874
- The documents are copied to the same collection as in "db_name".
875
- (This function should be rarely used, probably only during "construction".)
876
-
877
- Parameters
878
- ----------
879
- db_name: str
880
- the name of the DB to copy from
881
- collection: str
882
- the name of the collection to copy from
883
- query: dict
884
- A dictionary with a query to search for documents to copy.
885
- For example, the query below would copy all entries of prod4 version
886
- from telescope North-LST-1 to "db_to_copy_to".
887
-
888
- .. code-block:: python
889
-
890
- query = {
891
- "Telescope": "North-LST-1",
892
- "Version": "prod4",
893
- }
894
- db_to_copy_to: str
895
- The name of the DB to copy to.
896
-
897
- Raises
898
- ------
899
- BulkWriteError
900
-
901
- """
902
-
903
- _collection = DatabaseHandler.db_client[db_name][collection]
904
- if collection_to_copy_to is None:
905
- collection_to_copy_to = collection
906
- db_entries = []
907
-
908
- for post in _collection.find(query):
909
- post.pop("_id", None)
910
- db_entries.append(post)
911
-
912
- self._logger.info(
913
- f"Copying documents matching the following query {query}\nto {db_to_copy_to}"
914
- )
915
- _collection = DatabaseHandler.db_client[db_to_copy_to][collection_to_copy_to]
916
- try:
917
- _collection.insert_many(db_entries)
918
- except BulkWriteError as exc:
919
- raise BulkWriteError(str(exc.details)) from exc
920
-
921
- def delete_query(self, db_name, collection, query):
922
- """
923
- Delete all entries from the DB which correspond to the provided query.
924
- (This function should be rarely used, if at all.)
925
-
926
- Parameters
927
- ----------
928
- db_name: str
929
- the name of the DB
930
- collection: str
931
- the name of the collection to copy from
932
- query: dict
933
- A dictionary listing the fields/values to delete.
934
- For example, the query below would delete the entire prod5 version
935
- from telescope North-LST-1.
936
-
937
- .. code-block:: python
938
-
939
- query = {
940
- "Telescope": "North-LST-1",
941
- "Version": "prod5",
942
- }
943
-
944
- """
945
-
946
- _collection = DatabaseHandler.db_client[db_name][collection]
947
-
948
- if "Version" in query:
949
- query["Version"] = self._convert_version_to_tagged(
950
- query["Version"], DatabaseHandler.DB_CTA_SIMULATION_MODEL
951
- )
952
-
953
- self._logger.info(f"Deleting {_collection.count_documents(query)} entries from {db_name}")
954
-
955
- _collection.delete_many(query)
956
-
957
- def update_parameter(
958
- self,
959
- db_name,
960
- telescope,
961
- version,
962
- parameter,
963
- new_value,
964
- collection_name="telescopes",
965
- file_prefix=None,
966
- ):
967
- """
968
- Update a parameter value for a specific telescope/version.
969
- (This function should be rarely used since new values
970
- should ideally have their own version.)
971
-
972
- Parameters
973
- ----------
974
- db_name: str
975
- the name of the DB
976
- telescope: str
977
- Which telescope to update
978
- version: str
979
- Which version to update
980
- parameter: str
981
- Which parameter to update
982
- new_value: type identical to the original parameter type
983
- The new value to set for the parameter
984
- collection_name: str
985
- The name of the collection in which to update the parameter.
986
- file_prefix: str or Path
987
- where to find files to upload to the DB
988
-
989
- Raises
990
- ------
991
- FileNotFoundError
992
- if file_prefix is None
993
-
994
- """
995
-
996
- collection = DatabaseHandler.db_client[db_name][collection_name]
997
-
998
- _model_version = self._convert_version_to_tagged(
999
- version, DatabaseHandler.DB_CTA_SIMULATION_MODEL
1000
- )
1001
-
1002
- query = {
1003
- "Telescope": telescope,
1004
- "Version": _model_version,
1005
- "Parameter": parameter,
1006
- }
1007
-
1008
- par_entry = collection.find_one(query)
1009
- old_value = par_entry["Value"]
1010
-
1011
- self._logger.info(
1012
- f"For telescope {telescope}, version {_model_version}\n"
1013
- f"replacing {parameter} value from {old_value} to {new_value}"
1014
- )
1015
-
1016
- files_to_add_to_db = set()
1017
- if self._is_file(new_value):
1018
- file = True
1019
- if file_prefix is None:
1020
- raise FileNotFoundError(
1021
- "The location of the file to upload, "
1022
- f"corresponding to the {parameter} parameter, must be provided."
1023
- )
1024
- file_path = Path(file_prefix).joinpath(new_value)
1025
- files_to_add_to_db.add(f"{file_path}")
1026
- self._logger.info(f"Will also add the file {file_path} to the DB")
1027
- else:
1028
- file = False
1029
-
1030
- query_update = {"$set": {"Value": new_value, "File": file}}
1031
-
1032
- collection.update_one(query, query_update)
1033
- for file_now in files_to_add_to_db:
1034
- self.insert_file_to_db(file_now, db_name)
1035
-
1036
- def update_parameter_field(
1037
- self,
1038
- db_name,
1039
- version,
1040
- parameter,
1041
- field,
1042
- new_value,
1043
- telescope=None,
1044
- site=None,
1045
- collection_name="telescopes",
1046
- ):
1047
- """
1048
- Update a parameter field value for a specific telescope/version.
1049
- This function only modifies the value of one of the following
1050
- DB entries: Applicable, units, Type, items, minimum, maximum.
1051
- These type of changes should be very rare. However they can
1052
- be done without changing the Object ID of the entry since
1053
- they are generally "harmless".
1054
-
1055
- Parameters
1056
- ----------
1057
- db_name: str
1058
- the name of the DB
1059
- version: str
1060
- Which version to update
1061
- parameter: str
1062
- Which parameter to update
1063
- field: str
1064
- Field to update (only options are Applicable, units, Type, items, minimum, maximum).
1065
- If the field does not exist, it will be added.
1066
- new_value: type identical to the original field type
1067
- The new value to set to the field given in "field".
1068
- telescope: str
1069
- Which telescope to update, if None then update a site parameter
1070
- site: str, North or South
1071
- Update a site parameter (the telescope argument must be None)
1072
- collection_name: str
1073
- The name of the collection in which to update the parameter.
1074
-
1075
- Raises
1076
- ------
1077
- ValueError
1078
- if field not in allowed fields
1079
-
1080
- """
1081
-
1082
- allowed_fields = ["Applicable", "units", "Type", "items", "minimum", "maximum"]
1083
- if field not in allowed_fields:
1084
- raise ValueError(f"The field to change must be one of {', '.join(allowed_fields)}")
1085
-
1086
- collection = DatabaseHandler.db_client[db_name][collection_name]
1087
-
1088
- _model_version = self._convert_version_to_tagged(
1089
- version, DatabaseHandler.DB_CTA_SIMULATION_MODEL
1090
- )
1091
-
1092
- query = {
1093
- "Version": _model_version,
1094
- "Parameter": parameter,
1095
- }
1096
- if telescope is not None:
1097
- query["Telescope"] = telescope
1098
- logger_info = f"telescope {telescope}"
1099
- elif site is not None and site in ["North", "South"]:
1100
- query["Site"] = site
1101
- logger_info = f"site {site}"
1102
- else:
1103
- raise ValueError("You need to specifiy if to update a telescope or a site.")
1104
-
1105
- par_entry = collection.find_one(query)
1106
- if par_entry is None:
1107
- self._logger.warning(
1108
- f"The query {query} did not return any results. I will not make any changes."
1109
- )
1110
- return
1111
-
1112
- if field in par_entry:
1113
- old_field_value = par_entry[field]
1114
-
1115
- if old_field_value == new_value:
1116
- self._logger.warning(
1117
- f"The value of the field {field} is already {new_value}. No changes necessary"
1118
- )
1119
- return
1120
-
1121
- self._logger.info(
1122
- f"For {logger_info}, version {_model_version}, parameter {parameter}, "
1123
- f"replacing field {field} value from {old_field_value} to {new_value}"
1124
- )
1125
- else:
1126
- self._logger.info(
1127
- f"For {logger_info}, version {_model_version}, parameter {parameter}, "
1128
- f"the field {field} does not exist, adding it"
1129
- )
1130
-
1131
- query_update = {"$set": {field: new_value}}
1132
-
1133
- collection.update_one(query, query_update)
1134
-
1135
- def add_parameter(
1136
- self,
1137
- db_name,
1138
- telescope,
1139
- parameter,
1140
- new_version,
1141
- new_value,
1142
- collection_name="telescopes",
1143
- file_prefix=None,
1144
- ):
1145
- """
1146
- Add a parameter value for a specific telescope.
1147
- A new document will be added to the DB,
1148
- with all fields taken from the last entry of this parameter to this telescope,
1149
- except the ones changed.
1150
-
1151
- Parameters
1152
- ----------
1153
- db_name: str
1154
- the name of the DB
1155
- telescope: str
1156
- Which telescope to update
1157
- parameter: str
1158
- Which parameter to add
1159
- new_version: str
1160
- The version of the new parameter value
1161
- new_value: type identical to the original parameter type
1162
- The new value to set for the parameter
1163
- collection_name: str
1164
- The name of the collection to which to add a parameter.
1165
- file_prefix: str or Path
1166
- where to find files to upload to the DB
1167
-
1168
- Raises
1169
- ------
1170
- FileNotFoundError
1171
- if file_prefix is None
1172
-
1173
- """
1174
-
1175
- collection = DatabaseHandler.db_client[db_name][collection_name]
1176
-
1177
- _new_version = self._convert_version_to_tagged(
1178
- new_version, DatabaseHandler.DB_CTA_SIMULATION_MODEL
1179
- )
1180
-
1181
- query = {
1182
- "Telescope": telescope,
1183
- "Parameter": parameter,
1184
- }
1185
-
1186
- par_entry = collection.find(query).sort("_id", pymongo.DESCENDING)[0]
1187
- par_entry["Value"] = new_value
1188
- par_entry["Version"] = _new_version
1189
- par_entry.pop("_id", None)
1190
-
1191
- files_to_add_to_db = set()
1192
- if self._is_file(new_value):
1193
- par_entry["File"] = True
1194
- if file_prefix is None:
1195
- raise FileNotFoundError(
1196
- "The location of the file to upload, "
1197
- f"corresponding to the {parameter} parameter, must be provided."
1198
- )
1199
- file_path = Path(file_prefix).joinpath(new_value)
1200
- files_to_add_to_db.add(f"{file_path}")
1201
- else:
1202
- par_entry["File"] = False
1203
-
1204
- self._logger.info(f"Will add the following entry to DB:\n{par_entry}")
1205
-
1206
- collection.insert_one(par_entry)
1207
- if len(files_to_add_to_db) > 0:
1208
- self._logger.info(f"Will also add the file {file_path} to the DB")
1209
- self.insert_file_to_db(files_to_add_to_db, db_name)
1210
-
1211
- def add_new_parameter(
1212
- self,
1213
- db_name,
1214
- version,
1215
- parameter,
1216
- value,
1217
- telescope=None,
1218
- site=None,
1219
- collection_name="telescopes",
1220
- file_prefix=None,
1221
- **kwargs,
1222
- ):
1223
- """
1224
- Add a parameter value for a specific telescope.
1225
- A new document will be added to the DB,
1226
- with all fields taken from the input parameters.
1227
-
1228
- Parameters
1229
- ----------
1230
- db_name: str
1231
- the name of the DB
1232
- version: str
1233
- The version of the new parameter value
1234
- parameter: str
1235
- Which parameter to add
1236
- value: can be any type, preferably given in kwargs
1237
- The value to set for the new parameter
1238
- telescope: str
1239
- The name of the telescope to add a parameter to
1240
- (only used if collection_name is "telescopes").
1241
- site: str
1242
- South or North, ignored if collection_name is "telescopes".
1243
- collection_name: str
1244
- The name of the collection to add a parameter to.
1245
- file_prefix: str or Path
1246
- where to find files to upload to the DB
1247
- kwargs: dict
1248
- Any additional fields to add to the parameter
1249
-
1250
- Raises
1251
- ------
1252
- ValueError
1253
- If key to collection_name is not valid. Valid entries are: 'telescopes' and 'sites'.
1254
-
1255
- """
1256
-
1257
- collection = DatabaseHandler.db_client[db_name][collection_name]
1258
-
1259
- db_entry = {}
1260
- if "telescopes" in collection_name:
1261
- db_entry["Telescope"] = names.validate_telescope_name_db(telescope)
1262
- elif "sites" in collection_name:
1263
- db_entry["Site"] = names.validate_site_name(site)
1264
- else:
1265
- raise ValueError("Can only add new parameters to the sites or telescopes collections")
1266
-
1267
- db_entry["Version"] = version
1268
- db_entry["Parameter"] = parameter
1269
-
1270
- _base_value, _base_unit, _base_type = gen.get_value_unit_type(value)
1271
- db_entry["Value"] = _base_value
1272
- if _base_unit is not None:
1273
- db_entry["units"] = _base_unit
1274
- db_entry["Type"] = kwargs["Type"] if "Type" in kwargs else _base_type
1275
-
1276
- files_to_add_to_db = set()
1277
- db_entry["File"] = False
1278
- if self._is_file(value):
1279
- db_entry["File"] = True
1280
- if file_prefix is None:
1281
- raise FileNotFoundError(
1282
- "The location of the file to upload, "
1283
- f"corresponding to the {parameter} parameter, must be provided."
1284
- )
1285
- file_path = Path(file_prefix).joinpath(value)
1286
- files_to_add_to_db.add(f"{file_path}")
1287
-
1288
- kwargs.pop("Type", None)
1289
- db_entry.update(kwargs)
1290
-
1291
- self._logger.info(f"Will add the following entry to DB:\n{db_entry}")
1292
-
1293
- collection.insert_one(db_entry)
1294
- for file_to_insert_now in files_to_add_to_db:
1295
- self._logger.info(f"Will also add the file {file_to_insert_now} to the DB")
1296
- self.insert_file_to_db(file_to_insert_now, db_name)
1297
-
1298
- def _convert_version_to_tagged(self, model_version, db_name):
1299
- """Convert to tagged version, if needed."""
1300
- if model_version in ["Released", "Latest"]:
1301
- return self._get_tagged_version(db_name, model_version)
1302
-
1303
- return model_version
1304
-
1305
- @staticmethod
1306
- def _get_tagged_version(db_name, version="Released"):
1307
- """
1308
- Get the tag of the "Released" or "Latest" version of the MC Model.
1309
- The "Released" is the latest stable MC Model,
1310
- the latest is the latest tag (not necessarily stable, but can be equivalent to "Released").
1311
-
1312
- Parameters
1313
- ----------
1314
- db_name: str
1315
- the name of the DB
1316
- version: str
1317
- Can be "Released" or "Latest" (default: "Released").
1318
-
1319
- Returns
1320
- -------
1321
- str
1322
- The version name in the Simulation DB of the requested tag
1323
-
1324
- Raises
1325
- ------
1326
- ValueError
1327
- if version not valid. Valid versions are: 'Released' and 'Latest'.
1328
-
1329
- """
1330
-
1331
- if version not in ["Released", "Latest"]:
1332
- raise ValueError('The only default versions are "Released" or "Latest"')
1333
-
1334
- collection = DatabaseHandler.db_client[db_name].metadata
1335
- query = {"Entry": "Simulation-Model-Tags"}
1336
-
1337
- tags = collection.find(query).sort("_id", pymongo.DESCENDING)[0]
1338
-
1339
- return tags["Tags"][version]["Value"]
1340
-
1341
- def insert_file_to_db(self, file_name, db_name=DB_CTA_SIMULATION_MODEL, **kwargs):
1342
- """
1343
- Insert a file to the DB.
1344
-
1345
- Parameters
1346
- ----------
1347
- file_name: str or Path
1348
- The name of the file to insert (full path).
1349
- db_name: str
1350
- the name of the DB
1351
- **kwargs (optional): keyword arguments for file creation.
1352
- The full list of arguments can be found in, \
1353
- https://docs.mongodb.com/manual/core/gridfs/#the-files-collection
1354
- mostly these are unnecessary though.
1355
-
1356
- Returns
1357
- -------
1358
- file_iD: GridOut._id
1359
- If the file exists, return its GridOut._id, otherwise insert the file and return its"
1360
- "newly created DB GridOut._id.
1361
-
1362
- """
1363
-
1364
- db = DatabaseHandler.db_client[db_name]
1365
- file_system = gridfs.GridFS(db)
1366
-
1367
- if "content_type" not in kwargs:
1368
- kwargs["content_type"] = "ascii/dat"
1369
-
1370
- if "filename" not in kwargs:
1371
- kwargs["filename"] = Path(file_name).name
1372
-
1373
- if file_system.exists({"filename": kwargs["filename"]}):
1374
- self._logger.warning(
1375
- f"The file {kwargs['filename']} exists in the DB. Returning its ID"
1376
- )
1377
- return file_system.find_one( # pylint: disable=protected-access
1378
- {"filename": kwargs["filename"]}
1379
- )._id
1380
- with open(file_name, "rb") as data_file:
1381
- return file_system.put(data_file, **kwargs)
1382
-
1383
- def get_all_versions(
1384
- self,
1385
- db_name,
1386
- parameter,
1387
- telescope_model_name=None,
1388
- site=None,
1389
- collection_name="telescopes",
1390
- ):
1391
- """
1392
- Get all version entries in the DB of a telescope or site for a specific parameter.
1393
-
1394
- Parameters
1395
- ----------
1396
- db_name: str
1397
- the name of the DB
1398
- parameter: str
1399
- Which parameter to get the versions of
1400
- telescope_model_name: str
1401
- Which telescope to get the versions of (in case "collection_name" is "telescopes")
1402
- site: str, North or South
1403
- In case "collection_name" is "telescopes", the site is used to build the telescope name.
1404
- In case "collection_name" is "sites",
1405
- this argument sets which site parameter get the versions of
1406
- collection_name: str
1407
- The name of the collection in which to update the parameter.
1408
-
1409
- Returns
1410
- -------
1411
- all_versions: list
1412
- List of all versions found
1413
-
1414
- Raises
1415
- ------
1416
- ValueError
1417
- If key to collection_name is not valid. Valid entries are: 'telescopes' and 'sites'.
1418
-
1419
- """
1420
-
1421
- collection = DatabaseHandler.db_client[db_name][collection_name]
1422
-
1423
- query = {
1424
- "Parameter": parameter,
1425
- }
1426
-
1427
- _site_validated = names.validate_site_name(site)
1428
- if collection_name == "telescopes":
1429
- _tel_model_name_validated = names.validate_telescope_model_name(telescope_model_name)
1430
- _tel_name_db = self._get_telescope_model_name_for_db(
1431
- _site_validated, _tel_model_name_validated
1432
- )
1433
- query["Telescope"] = _tel_name_db
1434
- elif collection_name == "sites":
1435
- query["Site"] = _site_validated
1436
- else:
1437
- raise ValueError("Can only get versions of the telescopes and sites collections.")
1438
-
1439
- _all_versions = [post["Version"] for post in collection.find(query)]
1440
-
1441
- if len(_all_versions) == 0:
1442
- self._logger.warning(f"The query {query} did not return any results. No versions found")
1443
-
1444
- return _all_versions
1445
-
1446
- def get_all_available_telescopes(
1447
- self,
1448
- db_name=DB_CTA_SIMULATION_MODEL,
1449
- model_version="Released",
1450
- ):
1451
- """
1452
- Get all available telescope names in the collection "telescopes" in the DB.
1453
-
1454
- Parameters
1455
- ----------
1456
- db_name: str
1457
- the name of the DB
1458
- model_version: str
1459
- Which version to get the telescopes of (default: "Released").
1460
-
1461
- Returns
1462
- -------
1463
- all_available_telescopes: list
1464
- List of all telescope names found
1465
-
1466
- """
1467
-
1468
- collection = DatabaseHandler.db_client[db_name]["telescopes"]
1469
-
1470
- _model_version = self._convert_version_to_tagged(
1471
- names.validate_model_version_name(model_version),
1472
- DatabaseHandler.DB_CTA_SIMULATION_MODEL,
1473
- )
1474
-
1475
- query = {
1476
- "Version": _model_version,
1477
- }
1478
-
1479
- _all_available_telescopes = collection.find(query).distinct("Telescope")
1480
-
1481
- return _all_available_telescopes