gammasimtools 0.9.0__py3-none-any.whl → 0.11.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. {gammasimtools-0.9.0.dist-info → gammasimtools-0.11.0.dist-info}/METADATA +4 -2
  2. {gammasimtools-0.9.0.dist-info → gammasimtools-0.11.0.dist-info}/RECORD +133 -117
  3. {gammasimtools-0.9.0.dist-info → gammasimtools-0.11.0.dist-info}/WHEEL +1 -1
  4. {gammasimtools-0.9.0.dist-info → gammasimtools-0.11.0.dist-info}/entry_points.txt +6 -1
  5. simtools/_version.py +9 -4
  6. simtools/applications/calculate_trigger_rate.py +15 -38
  7. simtools/applications/convert_all_model_parameters_from_simtel.py +9 -29
  8. simtools/applications/convert_geo_coordinates_of_array_elements.py +47 -45
  9. simtools/applications/convert_model_parameter_from_simtel.py +2 -3
  10. simtools/applications/db_add_file_to_db.py +1 -3
  11. simtools/applications/db_add_simulation_model_from_repository_to_db.py +110 -0
  12. simtools/applications/db_add_value_from_json_to_db.py +1 -2
  13. simtools/applications/db_development_tools/write_array_elements_positions_to_repository.py +6 -6
  14. simtools/applications/db_get_file_from_db.py +11 -12
  15. simtools/applications/db_get_parameter_from_db.py +26 -35
  16. simtools/applications/derive_mirror_rnda.py +1 -2
  17. simtools/applications/derive_photon_electron_spectrum.py +99 -0
  18. simtools/applications/derive_psf_parameters.py +1 -0
  19. simtools/applications/docs_produce_array_element_report.py +71 -0
  20. simtools/applications/docs_produce_model_parameter_reports.py +63 -0
  21. simtools/applications/generate_array_config.py +17 -17
  22. simtools/applications/generate_corsika_histograms.py +2 -2
  23. simtools/applications/generate_regular_arrays.py +19 -17
  24. simtools/applications/generate_simtel_array_histograms.py +11 -48
  25. simtools/applications/production_derive_limits.py +95 -0
  26. simtools/applications/production_generate_simulation_config.py +37 -33
  27. simtools/applications/production_scale_events.py +4 -9
  28. simtools/applications/run_application.py +165 -0
  29. simtools/applications/simulate_light_emission.py +0 -4
  30. simtools/applications/simulate_prod.py +1 -1
  31. simtools/applications/simulate_prod_htcondor_generator.py +26 -26
  32. simtools/applications/submit_data_from_external.py +12 -4
  33. simtools/applications/submit_model_parameter_from_external.py +18 -11
  34. simtools/applications/validate_camera_efficiency.py +2 -2
  35. simtools/applications/validate_file_using_schema.py +26 -22
  36. simtools/camera/single_photon_electron_spectrum.py +168 -0
  37. simtools/configuration/commandline_parser.py +37 -1
  38. simtools/configuration/configurator.py +8 -10
  39. simtools/constants.py +10 -3
  40. simtools/corsika/corsika_config.py +19 -17
  41. simtools/corsika/corsika_histograms.py +5 -7
  42. simtools/corsika/corsika_histograms_visualize.py +2 -4
  43. simtools/data_model/data_reader.py +0 -3
  44. simtools/data_model/metadata_collector.py +20 -12
  45. simtools/data_model/metadata_model.py +8 -124
  46. simtools/data_model/model_data_writer.py +81 -75
  47. simtools/data_model/schema.py +220 -0
  48. simtools/data_model/validate_data.py +79 -68
  49. simtools/db/db_handler.py +350 -492
  50. simtools/db/db_model_upload.py +139 -0
  51. simtools/dependencies.py +112 -0
  52. simtools/io_operations/hdf5_handler.py +54 -24
  53. simtools/layout/array_layout.py +38 -32
  54. simtools/model/array_model.py +13 -7
  55. simtools/model/model_parameter.py +55 -54
  56. simtools/model/site_model.py +2 -2
  57. simtools/production_configuration/calculate_statistical_errors_grid_point.py +119 -145
  58. simtools/production_configuration/event_scaler.py +9 -35
  59. simtools/production_configuration/generate_simulation_config.py +9 -44
  60. simtools/production_configuration/interpolation_handler.py +9 -15
  61. simtools/production_configuration/limits_calculation.py +202 -0
  62. simtools/reporting/docs_read_parameters.py +310 -0
  63. simtools/runners/corsika_simtel_runner.py +4 -4
  64. simtools/schemas/{integration_tests_config.metaschema.yml → application_workflow.metaschema.yml} +61 -27
  65. simtools/schemas/array_elements.yml +8 -0
  66. simtools/schemas/input/MST_mirror_2f_measurements.schema.yml +39 -0
  67. simtools/schemas/input/single_pe_spectrum.schema.yml +38 -0
  68. simtools/schemas/model_parameter.metaschema.yml +103 -2
  69. simtools/schemas/model_parameter_and_data_schema.metaschema.yml +4 -1
  70. simtools/schemas/model_parameters/array_element_position_utm.schema.yml +1 -1
  71. simtools/schemas/model_parameters/array_window.schema.yml +37 -0
  72. simtools/schemas/model_parameters/asum_clipping.schema.yml +0 -4
  73. simtools/schemas/model_parameters/channels_per_chip.schema.yml +1 -1
  74. simtools/schemas/model_parameters/correct_nsb_spectrum_to_telescope_altitude.schema.yml +1 -1
  75. simtools/schemas/model_parameters/corsika_cherenkov_photon_bunch_size.schema.yml +2 -0
  76. simtools/schemas/model_parameters/corsika_cherenkov_photon_wavelength_range.schema.yml +2 -0
  77. simtools/schemas/model_parameters/corsika_first_interaction_height.schema.yml +2 -0
  78. simtools/schemas/model_parameters/corsika_iact_io_buffer.schema.yml +4 -2
  79. simtools/schemas/model_parameters/corsika_iact_max_bunches.schema.yml +2 -0
  80. simtools/schemas/model_parameters/corsika_iact_split_auto.schema.yml +2 -0
  81. simtools/schemas/model_parameters/corsika_longitudinal_shower_development.schema.yml +2 -0
  82. simtools/schemas/model_parameters/corsika_particle_kinetic_energy_cutoff.schema.yml +2 -0
  83. simtools/schemas/model_parameters/corsika_starting_grammage.schema.yml +2 -0
  84. simtools/schemas/model_parameters/dsum_clipping.schema.yml +0 -2
  85. simtools/schemas/model_parameters/dsum_ignore_below.schema.yml +0 -2
  86. simtools/schemas/model_parameters/dsum_offset.schema.yml +0 -2
  87. simtools/schemas/model_parameters/dsum_pedsub.schema.yml +0 -2
  88. simtools/schemas/model_parameters/dsum_pre_clipping.schema.yml +0 -2
  89. simtools/schemas/model_parameters/dsum_prescale.schema.yml +0 -2
  90. simtools/schemas/model_parameters/dsum_presum_max.schema.yml +0 -2
  91. simtools/schemas/model_parameters/dsum_presum_shift.schema.yml +0 -2
  92. simtools/schemas/model_parameters/dsum_shaping.schema.yml +0 -2
  93. simtools/schemas/model_parameters/dsum_shaping_renormalize.schema.yml +0 -2
  94. simtools/schemas/model_parameters/dsum_threshold.schema.yml +0 -2
  95. simtools/schemas/model_parameters/dsum_zero_clip.schema.yml +0 -2
  96. simtools/schemas/model_parameters/fadc_compensate_pedestal.schema.yml +1 -1
  97. simtools/schemas/model_parameters/fadc_lg_compensate_pedestal.schema.yml +1 -1
  98. simtools/schemas/model_parameters/fadc_noise.schema.yml +3 -3
  99. simtools/schemas/model_parameters/fake_mirror_list.schema.yml +33 -0
  100. simtools/schemas/model_parameters/iobuf_maximum.schema.yml +1 -1
  101. simtools/schemas/model_parameters/iobuf_output_maximum.schema.yml +1 -1
  102. simtools/schemas/model_parameters/laser_photons.schema.yml +2 -2
  103. simtools/schemas/model_parameters/lightguide_efficiency_vs_incidence_angle.schema.yml +1 -1
  104. simtools/schemas/model_parameters/lightguide_efficiency_vs_wavelength.schema.yml +1 -1
  105. simtools/schemas/model_parameters/min_photoelectrons.schema.yml +1 -1
  106. simtools/schemas/model_parameters/min_photons.schema.yml +1 -1
  107. simtools/schemas/model_parameters/random_generator.schema.yml +1 -1
  108. simtools/schemas/model_parameters/sampled_output.schema.yml +1 -1
  109. simtools/schemas/model_parameters/save_pe_with_amplitude.schema.yml +1 -1
  110. simtools/schemas/model_parameters/secondary_mirror_degraded_reflection.schema.yml +1 -1
  111. simtools/schemas/model_parameters/store_photoelectrons.schema.yml +1 -1
  112. simtools/schemas/model_parameters/tailcut_scale.schema.yml +1 -1
  113. simtools/schemas/production_configuration_metrics.schema.yml +68 -0
  114. simtools/schemas/production_tables.schema.yml +41 -0
  115. simtools/simtel/simtel_config_reader.py +1 -2
  116. simtools/simtel/simtel_config_writer.py +6 -8
  117. simtools/simtel/simtel_io_histogram.py +32 -68
  118. simtools/simtel/simtel_io_histograms.py +17 -34
  119. simtools/simtel/simulator_array.py +2 -1
  120. simtools/simtel/simulator_camera_efficiency.py +6 -3
  121. simtools/simtel/simulator_light_emission.py +5 -6
  122. simtools/simtel/simulator_ray_tracing.py +3 -4
  123. simtools/testing/configuration.py +2 -1
  124. simtools/testing/helpers.py +6 -13
  125. simtools/testing/validate_output.py +141 -47
  126. simtools/utils/general.py +114 -14
  127. simtools/utils/names.py +299 -157
  128. simtools/utils/value_conversion.py +17 -13
  129. simtools/version.py +2 -2
  130. simtools/visualization/legend_handlers.py +2 -0
  131. simtools/applications/db_add_model_parameters_from_repository_to_db.py +0 -176
  132. simtools/db/db_array_elements.py +0 -130
  133. {gammasimtools-0.9.0.dist-info → gammasimtools-0.11.0.dist-info}/LICENSE +0 -0
  134. {gammasimtools-0.9.0.dist-info → gammasimtools-0.11.0.dist-info}/top_level.txt +0 -0
  135. /simtools/{camera_efficiency.py → camera/camera_efficiency.py} +0 -0
@@ -26,7 +26,7 @@ r"""
26
26
 
27
27
  Example
28
28
  -------
29
- Get the mirror_list parameter from the DB.
29
+ Get the mirror_list parameter used for a given model_version from the DB.
30
30
 
31
31
  .. code-block:: console
32
32
 
@@ -34,18 +34,13 @@ r"""
34
34
  --site North --telescope LSTN-01 \\
35
35
  --model_version 5.0.0
36
36
 
37
- Expected final print-out message:
37
+ Get the mirror_list parameter using the parameter_version from the DB.
38
38
 
39
39
  .. code-block:: console
40
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>)}
41
+ simtools-db-get-parameter-from-db --parameter mirror_list \\
42
+ --site North --telescope LSTN-01 \\
43
+ --parameter_version 1.0.0
49
44
 
50
45
  """
51
46
 
@@ -58,6 +53,7 @@ import simtools.utils.general as gen
58
53
  from simtools.configuration import configurator
59
54
  from simtools.db import db_handler
60
55
  from simtools.io_operations import io_handler
56
+ from simtools.utils import names
61
57
 
62
58
 
63
59
  def _parse():
@@ -70,12 +66,6 @@ def _parse():
70
66
  )
71
67
 
72
68
  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
69
  config.parser.add_argument(
80
70
  "--output_file",
81
71
  help="output file name (if not given: print to stdout)",
@@ -83,7 +73,9 @@ def _parse():
83
73
  required=False,
84
74
  )
85
75
 
86
- return config.initialize(db_config=True, simulation_model=["telescope", "model_version"])
76
+ return config.initialize(
77
+ db_config=True, simulation_model=["telescope", "parameter_version", "model_version"]
78
+ )
87
79
 
88
80
 
89
81
  def main(): # noqa: D103
@@ -94,37 +86,36 @@ def main(): # noqa: D103
94
86
 
95
87
  db = db_handler.DatabaseHandler(mongo_db_config=db_config)
96
88
 
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",
89
+ # get parameter using 'parameter_version'
90
+ if args_dict["parameter_version"] is not None:
91
+ pars = db.get_model_parameter(
92
+ parameter=args_dict["parameter"],
93
+ parameter_version=args_dict["parameter_version"],
94
+ site=args_dict["site"],
95
+ array_element_name=args_dict["telescope"],
103
96
  )
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:
97
+ # get parameter using 'model_version'
98
+ elif args_dict["model_version"] is not None:
107
99
  pars = db.get_model_parameters(
108
- args_dict["site"],
109
- args_dict["telescope"],
110
- args_dict["model_version"],
111
- collection="telescopes",
100
+ site=args_dict["site"],
101
+ array_element_name=args_dict.get("telescope"),
102
+ model_version=args_dict["model_version"],
103
+ collection=names.get_collection_name_from_parameter_name(args_dict["parameter"]),
112
104
  )
113
105
  else:
114
- pars = db.get_site_parameters(args_dict["site"], args_dict["model_version"])
106
+ raise ValueError("Either 'parameter_version' or 'model_version' must be provided.")
115
107
  if args_dict["parameter"] not in pars:
116
108
  raise KeyError(f"The requested parameter, {args_dict['parameter']}, does not exist.")
117
109
  if args_dict["output_file"] is not None:
118
- _io_handler = io_handler.IOHandler()
110
+ _output_file = (
111
+ Path(io_handler.IOHandler().get_output_directory()) / args_dict["output_file"]
112
+ )
119
113
  pars[args_dict["parameter"]].pop("_id")
120
114
  pars[args_dict["parameter"]].pop("entry_date")
121
- _output_file = Path(_io_handler.get_output_directory()) / args_dict["output_file"]
122
115
  with open(_output_file, "w", encoding="utf-8") as json_file:
123
116
  json.dump(pars[args_dict["parameter"]], json_file, indent=4)
124
117
  else:
125
- print()
126
118
  pprint(pars[args_dict["parameter"]])
127
- print()
128
119
 
129
120
 
130
121
  if __name__ == "__main__":
@@ -194,8 +194,7 @@ def _parse(label):
194
194
  config.parser.add_argument(
195
195
  "--random_focal_length",
196
196
  help=(
197
- "Value of the random focal length. "
198
- "Only used if 'use_random_focal_length' is activated."
197
+ "Value of the random focal length. Only used if 'use_random_focal_length' is activated."
199
198
  ),
200
199
  default=None,
201
200
  type=float,
@@ -0,0 +1,99 @@
1
+ #!/usr/bin/python3
2
+
3
+ r"""
4
+ Derive single photon electron spectrum from a given amplitude spectrum.
5
+
6
+ Normalizes singe-p.e. amplitude distribution to mean amplitude of 1.0,
7
+ as required by sim_telarray. Allows to fold in afterpulse distribution
8
+ to prompt a spectrum. Uses the sim_telarray tool 'norm_spe' to normalize
9
+ the spectra.
10
+
11
+ Input files can be in ecsv format (preferred) or in the sim_telarray legacy format.
12
+
13
+ Two output files with identical data are written to the output directory:
14
+
15
+ - 'output_file'.ecsv: Single photon electron spectrum in ecsv format (data and metadata).
16
+ - 'output_file'.dat: Single photon electron spectrum in sim_telarray format.
17
+
18
+ Example
19
+ -------
20
+
21
+ .. code-block:: console
22
+
23
+ simtools-derive-photon-electron-spectrum \\
24
+ --input_spectrum spectrum_photon_electron.ecsv \\
25
+ --afterpulse_spectrum spectrum_afterpulse.ecsv \\
26
+ --step_size 0.02 \\
27
+ --max_amplitude 42.0 \\
28
+ --use_norm_spe \\
29
+ --output_path ./tests/output \\
30
+ --output_file spectrum_photon_electron_afterpulse.ecsv
31
+
32
+ For an example of how to plot the single photon electron spectrum, see the
33
+ integration test 'tests/integration_tests/config/plot_tabular_data_for_single_pe_data.yml'.
34
+
35
+ """
36
+
37
+ import logging
38
+ from pathlib import Path
39
+
40
+ import simtools.utils.general as gen
41
+ from simtools.camera.single_photon_electron_spectrum import SinglePhotonElectronSpectrum
42
+ from simtools.configuration import configurator
43
+
44
+
45
+ def _parse(label):
46
+ """Parse command line configuration."""
47
+ config = configurator.Configurator(
48
+ label=label,
49
+ description="Derive single photon electron spectrum from a given amplitude spectrum.",
50
+ )
51
+ config.parser.add_argument(
52
+ "--input_spectrum",
53
+ help="File with amplitude spectrum.",
54
+ type=Path,
55
+ required=True,
56
+ )
57
+ config.parser.add_argument(
58
+ "--afterpulse_spectrum",
59
+ help="File with afterpulse spectrum.",
60
+ type=Path,
61
+ required=False,
62
+ )
63
+ config.parser.add_argument(
64
+ "--step_size",
65
+ help="Step size in amplitude spectrum",
66
+ type=float,
67
+ default=0.02,
68
+ required=False,
69
+ )
70
+ config.parser.add_argument(
71
+ "--max_amplitude",
72
+ help="Maximum amplitude in amplitude spectrum",
73
+ type=float,
74
+ default=42.0,
75
+ required=False,
76
+ )
77
+ config.parser.add_argument(
78
+ "--use_norm_spe",
79
+ help="Use sim_telarray tool 'norm_spe' to normalize the spectrum.",
80
+ action="store_true",
81
+ required=False,
82
+ )
83
+
84
+ return config.initialize(db_config=False, output=True)
85
+
86
+
87
+ def main(): # noqa: D103
88
+ args_dict, _ = _parse(Path(__file__).stem)
89
+
90
+ logger = logging.getLogger()
91
+ logger.setLevel(gen.get_log_level_from_user(args_dict["log_level"]))
92
+
93
+ single_pe = SinglePhotonElectronSpectrum(args_dict)
94
+ single_pe.derive_single_pe_spectrum()
95
+ single_pe.write_single_pe_spectrum()
96
+
97
+
98
+ if __name__ == "__main__":
99
+ main()
@@ -81,6 +81,7 @@ r"""
81
81
  mirror_align_random_vertical = [0.005, 28.0, 0.0, 0.0]
82
82
 
83
83
  """
84
+
84
85
  import logging
85
86
  from collections import OrderedDict
86
87
 
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/python3
2
+
3
+ r"""
4
+ Produces a markdown file for a given array element, site, and model version.
5
+
6
+ The report includes detailed information on each parameter,
7
+ such as the parameter name, value, unit, description, and short description.
8
+ Currently only implemented for telescopes.
9
+ """
10
+
11
+ import logging
12
+
13
+ from simtools.configuration import configurator
14
+ from simtools.io_operations import io_handler
15
+ from simtools.model.telescope_model import TelescopeModel
16
+ from simtools.reporting.docs_read_parameters import ReadParameters
17
+ from simtools.utils import general as gen
18
+
19
+
20
+ def _parse(label):
21
+ """Parse command line configuration."""
22
+ config = configurator.Configurator(
23
+ label=label,
24
+ description=("Produce a markdown report for model parameters."),
25
+ )
26
+
27
+ config.parser.add_argument(
28
+ "--parameter",
29
+ action="store_true",
30
+ help="Compare all parameters across model versions for one telescope.",
31
+ )
32
+
33
+ return config.initialize(
34
+ db_config=True, simulation_model=["site", "telescope", "model_version", "parameter_version"]
35
+ )
36
+
37
+
38
+ def main(): # noqa: D103
39
+ label_name = "reports"
40
+ args, db_config = _parse(label_name)
41
+ io_handler_instance = io_handler.IOHandler()
42
+ output_path = io_handler_instance.get_output_directory(
43
+ label=label_name, sub_dir=f"productions/{args['model_version']}"
44
+ )
45
+
46
+ logger = logging.getLogger()
47
+ logger.setLevel(gen.get_log_level_from_user(args["log_level"]))
48
+
49
+ telescope_model = TelescopeModel(
50
+ site=args["site"],
51
+ telescope_name=args["telescope"],
52
+ model_version=args["model_version"],
53
+ label=label_name,
54
+ mongo_db_config=db_config,
55
+ )
56
+
57
+ ReadParameters(
58
+ db_config,
59
+ telescope_model,
60
+ output_path,
61
+ ).produce_array_element_report()
62
+
63
+ logger.info(
64
+ f"Markdown report generated for {args['site']}"
65
+ f" Telescope {args['telescope']} (v{args['model_version']}):"
66
+ f" {output_path}"
67
+ )
68
+
69
+
70
+ if __name__ == "__main__":
71
+ main()
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/python3
2
+
3
+ r"""
4
+ Produce one file per model parameter for a given array element.
5
+
6
+ The markdown reports include detailed information on each parameter,
7
+ comparing their values over various model versions.
8
+ Currently only implemented for telescopes.
9
+ """
10
+
11
+ import logging
12
+
13
+ from simtools.configuration import configurator
14
+ from simtools.io_operations import io_handler
15
+ from simtools.model.telescope_model import TelescopeModel
16
+ from simtools.reporting.docs_read_parameters import ReadParameters
17
+ from simtools.utils import general as gen
18
+
19
+
20
+ def _parse(label):
21
+ """Parse command line configuration."""
22
+ config = configurator.Configurator(
23
+ label=label,
24
+ description=("Produce a markdown report for model parameters."),
25
+ )
26
+
27
+ return config.initialize(
28
+ db_config=True, simulation_model=["site", "telescope", "model_version"]
29
+ )
30
+
31
+
32
+ def main(): # noqa: D103
33
+ label_name = "reports"
34
+ args, db_config = _parse(label_name)
35
+ io_handler_instance = io_handler.IOHandler()
36
+ output_path = io_handler_instance.get_output_directory(label=label_name, sub_dir="parameters")
37
+
38
+ logger = logging.getLogger()
39
+ logger.setLevel(gen.get_log_level_from_user(args["log_level"]))
40
+
41
+ telescope_model = TelescopeModel(
42
+ site=args["site"],
43
+ telescope_name=args["telescope"],
44
+ model_version=args["model_version"],
45
+ label=label_name,
46
+ mongo_db_config=db_config,
47
+ )
48
+
49
+ ReadParameters(
50
+ db_config,
51
+ telescope_model,
52
+ output_path,
53
+ ).produce_model_parameter_reports()
54
+
55
+ logger.info(
56
+ f"Markdown report generated for {args['site']}"
57
+ f" Telescope {args['telescope']} (v{args['model_version']}):"
58
+ f" {output_path}"
59
+ )
60
+
61
+
62
+ if __name__ == "__main__":
63
+ main()
@@ -1,28 +1,28 @@
1
1
  #!/usr/bin/python3
2
2
  """
3
- Generate sim_telarray configuration files for a given array.
3
+ Generate sim_telarray configuration files for a given array.
4
4
 
5
- The applications generates the sim_telarray configuration files for a given array, site,
6
- and model_version using the model parameters stored in the database.
5
+ The applications generates the sim_telarray configuration files for a given array, site,
6
+ and model_version using the model parameters stored in the database.
7
7
 
8
- Command line arguments
9
- ----------------------
10
- site : str
11
- Site name (e.g., North, South).
12
- array_layout_name : str
13
- Name of the layout array (e.g., test_layout, alpha, 4mst, etc.).
14
- array_element_list : list
15
- List of array elements (e.g., telescopes) to plot (e.g., ``LSTN-01 LSTN-02 MSTN``).
8
+ Command line arguments
9
+ ----------------------
10
+ site : str
11
+ Site name (e.g., North, South).
12
+ array_layout_name : str
13
+ Name of the layout array (e.g., test_layout, alpha, 4mst, etc.).
14
+ array_element_list : list
15
+ List of array elements (e.g., telescopes) to plot (e.g., ``LSTN-01 LSTN-02 MSTN``).
16
16
 
17
- Example
18
- -------
19
- North - 5.0.0:
17
+ Example
18
+ -------
19
+ North - 5.0.0:
20
20
 
21
- .. code-block:: console
21
+ .. code-block:: console
22
22
 
23
- simtools-generate-array-config --site North --array_layout_name alpha --model_version 5.0.0
23
+ simtools-generate-array-config --site North --array_layout_name alpha --model_version 5.0.0
24
24
 
25
- The output is saved in simtools-output/test/model.
25
+ The output is saved in simtools-output/test/model.
26
26
  """
27
27
 
28
28
  import logging
@@ -152,7 +152,7 @@ r"""
152
152
  .. code-block:: console
153
153
 
154
154
  simtools-generate-corsika-histograms --iact_file /workdir/external/simtools/\\
155
- testsresources/tel_output_10GeV-2-gamma-20deg-CTAO-South.corsikaio \\
155
+ tests/resources/tel_output_10GeV-2-gamma-20deg-CTAO-South.corsikaio \\
156
156
  --pdf --hdf5 \\
157
157
  --event_2d_histograms zenith azimuth --event_1d_histograms total_energy
158
158
 
@@ -208,7 +208,7 @@ def _parse(label, description):
208
208
 
209
209
  config.parser.add_argument(
210
210
  "--telescope_indices",
211
- help="Name of the CORSIKA IACT file from which to generate the histograms.",
211
+ help="List of telescope indices to be considered in the generation of the histograms",
212
212
  type=str,
213
213
  required=False,
214
214
  nargs="+",
@@ -1,27 +1,27 @@
1
1
  #!/usr/bin/python3
2
2
 
3
3
  """
4
- Make a regular array of telescopes and save it as astropy table.
4
+ Make a regular array of telescopes and save it as astropy table.
5
5
 
6
- The arrays consist of one telescope at the center of the array and or of 4 telescopes
7
- in a square grid. These arrays are used for trigger rate simulations.
6
+ The arrays consist of one telescope at the center of the array and or of 4 telescopes
7
+ in a square grid. These arrays are used for trigger rate simulations.
8
8
 
9
- The array layout files created will be available at the data/layout directory.
9
+ The array layout files created will be available at the data/layout directory.
10
10
 
11
- Command line arguments
12
- ----------------------
13
- site (str, required)
14
- observatory site (e.g., North or South).
15
- model_version (str, optional)
16
- Model version to use (e.g., 6.0.0). If not provided, the latest version is used.
11
+ Command line arguments
12
+ ----------------------
13
+ site (str, required)
14
+ observatory site (e.g., North or South).
15
+ model_version (str, optional)
16
+ Model version to use (e.g., 6.0.0). If not provided, the latest version is used.
17
17
 
18
- Example
19
- -------
20
- Runtime < 10 s.
18
+ Example
19
+ -------
20
+ Runtime < 10 s.
21
21
 
22
- .. code-block:: console
22
+ .. code-block:: console
23
23
 
24
- simtools-generate-regular-arrays --site=North
24
+ simtools-generate-regular-arrays --site=North
25
25
  """
26
26
 
27
27
  import logging
@@ -77,7 +77,9 @@ def main():
77
77
  # Single telescope at the center
78
78
  if array_name[0] == "1":
79
79
  tel_name.append(
80
- names.get_array_element_name_from_type_site_id(tel_size, args_dict["site"], "01")
80
+ names.generate_array_element_name_from_type_site_id(
81
+ tel_size, args_dict["site"], "01"
82
+ )
81
83
  )
82
84
  pos_x.append(0 * u.m)
83
85
  pos_y.append(0 * u.m)
@@ -86,7 +88,7 @@ def main():
86
88
  else:
87
89
  for i in range(1, 5):
88
90
  tel_name.append(
89
- names.get_array_element_name_from_type_site_id(
91
+ names.generate_array_element_name_from_type_site_id(
90
92
  tel_size, args_dict["site"], f"0{i}"
91
93
  )
92
94
  )
@@ -13,8 +13,6 @@ r"""
13
13
  Name of the histogram files to be plotted.
14
14
  It can be given as the histogram file names (more than one option allowed) or as a text
15
15
  file with the names of the histogram files in it.
16
- figure_name (str, required)
17
- File name for the pdf output (without extension).
18
16
  pdf (bool, optional)
19
17
  If set, histograms are saved into pdf files.
20
18
  One pdf file contains all the histograms found in the file.
@@ -29,6 +27,8 @@ r"""
29
27
  If the output output_file_name.hdf5 file already exists and hdf5 is set, the tables
30
28
  associated to hdf5 will be overwritten. The remaining tables, if any, will stay
31
29
  untouched.
30
+ test: bool
31
+ Test option. Generate only two histograms for testing purposes.
32
32
 
33
33
  Raises
34
34
  ------
@@ -108,38 +108,6 @@ def _parse(label, description):
108
108
  return config_parser
109
109
 
110
110
 
111
- def build_histogram_files(config_parser, logger):
112
- """
113
- Build a list of histogram files from command line arguments.
114
-
115
- Parameters
116
- ----------
117
- config_parser: dict
118
- Parsed command line arguments.
119
- logger: logging.Logger
120
- Logger object for logging messages.
121
-
122
- Returns
123
- -------
124
- list
125
- List of histogram file paths.
126
- """
127
- histogram_files = []
128
- for one_file in config_parser["hist_file_names"]:
129
- try:
130
- if Path(one_file).suffix in [".zst", ".simtel", ".hdata"]:
131
- histogram_files.append(one_file)
132
- else:
133
- with open(one_file, encoding="utf-8") as file:
134
- for line in file:
135
- histogram_files.append(line.strip())
136
- except FileNotFoundError as exc:
137
- msg = f"{one_file} is not a file."
138
- logger.error(msg)
139
- raise FileNotFoundError from exc
140
- return histogram_files
141
-
142
-
143
111
  def check_and_log_overwrite(config_parser, logger):
144
112
  """
145
113
  Check if the output hdf5 file already exists and log a warning if it does.
@@ -197,36 +165,31 @@ def create_pdf(simtel_histograms, output_file_name, config_parser, logger):
197
165
  logger.info(f"Wrote histograms to the pdf file {output_file_name}.pdf")
198
166
 
199
167
 
200
- def export_to_hdf5(simtel_histograms, output_file_name, overwrite, config_parser, logger):
201
- """Export histograms to an HDF5 file."""
202
- if config_parser["hdf5"]:
203
- logger.info(f"Wrote histograms to the hdf5 file {output_file_name}.hdf5")
204
- simtel_histograms.export_histograms(f"{output_file_name}.hdf5", overwrite=overwrite)
205
-
206
-
207
168
  def main(): # noqa: D103
208
169
  label = Path(__file__).stem
209
- description = "Display the simtel_array histograms."
170
+ description = "Display simtel_array histograms and/or write them into hdf5 format."
210
171
  io_handler_instance = io_handler.IOHandler()
211
172
  config_parser = _parse(label, description)
212
173
  output_path = io_handler_instance.get_output_directory(label, sub_dir="application-plots")
213
174
  logger = logging.getLogger()
214
175
  logger.setLevel(gen.get_log_level_from_user(config_parser["log_level"]))
215
- logger.info("Starting the application.")
216
176
 
217
- histogram_files = build_histogram_files(config_parser, logger)
177
+ histogram_files = gen.get_list_of_files_from_command_line(
178
+ config_parser["hist_file_names"], [".zst", ".simtel", ".hdata"]
179
+ )
218
180
 
219
181
  # If no output name is passed, the tool gets the name of the first histogram of the list
220
182
  if config_parser["output_file_name"] is None:
221
183
  config_parser["output_file_name"] = Path(histogram_files[0]).absolute().name
222
184
  output_file_name = Path(output_path).joinpath(f"{config_parser['output_file_name']}")
223
185
 
224
- # If the hdf5 output file already exists, it is overwritten
225
- overwrite = check_and_log_overwrite(config_parser, logger)
226
-
227
186
  simtel_histograms = SimtelIOHistograms(histogram_files)
228
187
  create_pdf(simtel_histograms, output_file_name, config_parser, logger)
229
- export_to_hdf5(simtel_histograms, output_file_name, overwrite, config_parser, logger)
188
+ if config_parser["hdf5"]:
189
+ simtel_histograms.export_histograms(
190
+ f"{output_file_name}.hdf5",
191
+ overwrite=check_and_log_overwrite(config_parser, logger),
192
+ )
230
193
 
231
194
 
232
195
  if __name__ == "__main__":