gammasimtools 0.22.0__py3-none-any.whl → 0.24.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 (128) hide show
  1. {gammasimtools-0.22.0.dist-info → gammasimtools-0.24.0.dist-info}/METADATA +2 -1
  2. {gammasimtools-0.22.0.dist-info → gammasimtools-0.24.0.dist-info}/RECORD +128 -125
  3. simtools/_version.py +2 -2
  4. simtools/application_control.py +118 -0
  5. simtools/applications/calculate_incident_angles.py +17 -22
  6. simtools/applications/convert_all_model_parameters_from_simtel.py +28 -43
  7. simtools/applications/convert_geo_coordinates_of_array_elements.py +26 -45
  8. simtools/applications/convert_model_parameter_from_simtel.py +21 -41
  9. simtools/applications/db_add_file_to_db.py +13 -14
  10. simtools/applications/db_add_simulation_model_from_repository_to_db.py +20 -33
  11. simtools/applications/db_add_value_from_json_to_db.py +29 -24
  12. simtools/applications/db_development_tools/write_array_elements_positions_to_repository.py +20 -35
  13. simtools/applications/db_generate_compound_indexes.py +11 -13
  14. simtools/applications/db_get_array_layouts_from_db.py +20 -40
  15. simtools/applications/db_get_file_from_db.py +15 -17
  16. simtools/applications/db_get_parameter_from_db.py +33 -35
  17. simtools/applications/db_inspect_databases.py +13 -12
  18. simtools/applications/db_upload_model_repository.py +13 -31
  19. simtools/applications/derive_ctao_array_layouts.py +16 -21
  20. simtools/applications/derive_mirror_rnda.py +9 -14
  21. simtools/applications/derive_photon_electron_spectrum.py +7 -10
  22. simtools/applications/derive_psf_parameters.py +13 -20
  23. simtools/applications/derive_trigger_rates.py +6 -9
  24. simtools/applications/docs_produce_array_element_report.py +22 -23
  25. simtools/applications/docs_produce_calibration_reports.py +26 -24
  26. simtools/applications/docs_produce_model_parameter_reports.py +15 -22
  27. simtools/applications/docs_produce_simulation_configuration_report.py +21 -22
  28. simtools/applications/generate_array_config.py +14 -33
  29. simtools/applications/generate_corsika_histograms.py +22 -43
  30. simtools/applications/generate_default_metadata.py +15 -36
  31. simtools/applications/generate_regular_arrays.py +11 -15
  32. simtools/applications/generate_simtel_event_data.py +23 -33
  33. simtools/applications/maintain_simulation_model_add_production.py +20 -37
  34. simtools/applications/maintain_simulation_model_compare_productions.py +10 -12
  35. simtools/applications/maintain_simulation_model_verify_production_tables.py +8 -11
  36. simtools/applications/merge_tables.py +14 -23
  37. simtools/applications/plot_array_layout.py +77 -54
  38. simtools/applications/plot_simtel_events.py +11 -13
  39. simtools/applications/plot_tabular_data.py +17 -38
  40. simtools/applications/plot_tabular_data_for_model_parameter.py +16 -23
  41. simtools/applications/print_version.py +14 -42
  42. simtools/applications/production_derive_corsika_limits.py +5 -9
  43. simtools/applications/production_derive_statistics.py +12 -25
  44. simtools/applications/production_generate_grid.py +20 -48
  45. simtools/applications/production_merge_corsika_limits.py +17 -21
  46. simtools/applications/run_application.py +12 -32
  47. simtools/applications/simulate_flasher.py +21 -25
  48. simtools/applications/simulate_illuminator.py +7 -14
  49. simtools/applications/simulate_pedestals.py +13 -13
  50. simtools/applications/simulate_prod.py +21 -33
  51. simtools/applications/simulate_prod_htcondor_generator.py +11 -25
  52. simtools/applications/submit_array_layouts.py +16 -19
  53. simtools/applications/submit_data_from_external.py +18 -34
  54. simtools/applications/submit_model_parameter_from_external.py +27 -40
  55. simtools/applications/validate_camera_efficiency.py +23 -21
  56. simtools/applications/validate_camera_fov.py +21 -26
  57. simtools/applications/validate_cumulative_psf.py +27 -35
  58. simtools/applications/validate_file_using_schema.py +15 -33
  59. simtools/applications/validate_optics.py +27 -33
  60. simtools/camera/camera_efficiency.py +0 -2
  61. simtools/configuration/commandline_parser.py +39 -13
  62. simtools/configuration/configurator.py +1 -6
  63. simtools/corsika/corsika_config.py +2 -9
  64. simtools/data_model/data_reader.py +0 -2
  65. simtools/data_model/metadata_collector.py +0 -2
  66. simtools/data_model/model_data_writer.py +1 -3
  67. simtools/data_model/schema.py +36 -34
  68. simtools/data_model/validate_data.py +0 -2
  69. simtools/db/db_handler.py +61 -296
  70. simtools/db/db_model_upload.py +1 -1
  71. simtools/db/mongo_db.py +535 -0
  72. simtools/dependencies.py +33 -8
  73. simtools/io/hdf5_handler.py +0 -5
  74. simtools/io/legacy_data_handler.py +0 -5
  75. simtools/job_execution/job_manager.py +0 -3
  76. simtools/layout/array_layout.py +7 -9
  77. simtools/layout/array_layout_utils.py +3 -3
  78. simtools/layout/telescope_position.py +0 -2
  79. simtools/model/array_model.py +38 -71
  80. simtools/model/calibration_model.py +12 -11
  81. simtools/model/camera.py +0 -2
  82. simtools/model/mirrors.py +0 -2
  83. simtools/model/model_parameter.py +200 -140
  84. simtools/model/model_repository.py +159 -35
  85. simtools/model/model_utils.py +3 -8
  86. simtools/model/site_model.py +59 -29
  87. simtools/model/telescope_model.py +21 -15
  88. simtools/production_configuration/calculate_statistical_uncertainties_grid_point.py +0 -2
  89. simtools/production_configuration/derive_production_statistics.py +0 -2
  90. simtools/production_configuration/interpolation_handler.py +0 -2
  91. simtools/ray_tracing/mirror_panel_psf.py +4 -4
  92. simtools/ray_tracing/psf_analysis.py +0 -2
  93. simtools/ray_tracing/psf_parameter_optimisation.py +1 -1
  94. simtools/ray_tracing/ray_tracing.py +0 -2
  95. simtools/reporting/docs_auto_report_generator.py +109 -1
  96. simtools/reporting/docs_read_parameters.py +4 -9
  97. simtools/runners/corsika_runner.py +0 -2
  98. simtools/runners/corsika_simtel_runner.py +0 -2
  99. simtools/runners/simtel_runner.py +0 -2
  100. simtools/schemas/model_parameters/transit_time_random.schema.yml +29 -0
  101. simtools/schemas/simulation_models_info.schema.yml +2 -1
  102. simtools/simtel/simtel_config_reader.py +0 -2
  103. simtools/simtel/simtel_config_writer.py +128 -33
  104. simtools/simtel/simtel_io_metadata.py +3 -3
  105. simtools/simtel/simulator_array.py +9 -21
  106. simtools/simtel/simulator_camera_efficiency.py +0 -2
  107. simtools/simtel/simulator_light_emission.py +1 -3
  108. simtools/simtel/simulator_ray_tracing.py +0 -2
  109. simtools/simulator.py +2 -6
  110. simtools/testing/assertions.py +52 -8
  111. simtools/testing/configuration.py +17 -4
  112. simtools/testing/validate_output.py +4 -8
  113. simtools/utils/general.py +5 -13
  114. simtools/utils/geometry.py +0 -5
  115. simtools/utils/names.py +1 -13
  116. simtools/utils/value_conversion.py +10 -5
  117. simtools/version.py +85 -0
  118. simtools/visualization/plot_array_layout.py +129 -23
  119. simtools/visualization/plot_incident_angles.py +0 -2
  120. simtools/visualization/plot_pixels.py +1 -1
  121. simtools/visualization/plot_psf.py +1 -1
  122. simtools/visualization/plot_simtel_events.py +0 -11
  123. simtools/visualization/plot_tables.py +1 -1
  124. simtools/visualization/visualize.py +0 -12
  125. {gammasimtools-0.22.0.dist-info → gammasimtools-0.24.0.dist-info}/WHEEL +0 -0
  126. {gammasimtools-0.22.0.dist-info → gammasimtools-0.24.0.dist-info}/entry_points.txt +0 -0
  127. {gammasimtools-0.22.0.dist-info → gammasimtools-0.24.0.dist-info}/licenses/LICENSE +0 -0
  128. {gammasimtools-0.22.0.dist-info → gammasimtools-0.24.0.dist-info}/top_level.txt +0 -0
@@ -76,19 +76,18 @@ Examples
76
76
 
77
77
  """
78
78
 
79
- import logging
80
79
  from pathlib import Path
81
80
 
82
81
  import simtools.utils.general as gen
82
+ from simtools.application_control import get_application_label, startup_application
83
83
  from simtools.configuration import configurator
84
- from simtools.io import io_handler
85
84
  from simtools.visualization.plot_simtel_events import PLOT_CHOICES, generate_and_save_plots
86
85
 
87
86
 
88
- def _parse(label: str):
87
+ def _parse():
89
88
  """Parse command line configuration."""
90
89
  config = configurator.Configurator(
91
- label=label,
90
+ label=get_application_label(__file__),
92
91
  description=(
93
92
  "Create diagnostic plots from sim_telarray files using simtools visualization."
94
93
  ),
@@ -178,17 +177,16 @@ def _parse(label: str):
178
177
 
179
178
  def main():
180
179
  """Generate plots from sim_telarray files."""
181
- label = Path(__file__).stem
182
- args, _db = _parse(label)
180
+ app_context = startup_application(_parse)
183
181
 
184
- logger = logging.getLogger()
185
- logger.setLevel(gen.get_log_level_from_user(args.get("log_level", "INFO")))
182
+ simtel_files = [
183
+ Path(p).expanduser() for p in gen.ensure_iterable(app_context.args["simtel_files"])
184
+ ]
185
+ plots = list(gen.ensure_iterable(app_context.args.get("plots")))
186
186
 
187
- ioh = io_handler.IOHandler()
188
- simtel_files = [Path(p).expanduser() for p in gen.ensure_iterable(args["simtel_files"])]
189
- plots = list(gen.ensure_iterable(args.get("plots")))
190
-
191
- generate_and_save_plots(simtel_files=simtel_files, plots=plots, args=args, ioh=ioh)
187
+ generate_and_save_plots(
188
+ simtel_files=simtel_files, plots=plots, args=app_context.args, ioh=app_context.io_handler
189
+ )
192
190
 
193
191
 
194
192
  if __name__ == "__main__":
@@ -23,37 +23,24 @@ Plot tabular data using a configuration file.
23
23
 
24
24
  """
25
25
 
26
- import logging
27
- from pathlib import Path
28
-
29
26
  import simtools.utils.general as gen
27
+ from simtools.application_control import get_application_label, startup_application
30
28
  from simtools.configuration import configurator
31
29
  from simtools.constants import PLOT_CONFIG_SCHEMA
32
30
  from simtools.data_model import schema
33
31
  from simtools.data_model.metadata_collector import MetadataCollector
34
- from simtools.io import ascii_handler, io_handler
32
+ from simtools.io import ascii_handler
35
33
  from simtools.visualization import plot_tables
36
34
 
37
35
 
38
- def _parse(label, description, usage):
39
- """
40
- Parse command line configuration.
41
-
42
- Parameters
43
- ----------
44
- label : str
45
- Label describing the application.
46
- description : str
47
- Description of the application.
48
- usage : str
49
- Example on how to use the application.
50
-
51
- Returns
52
- -------
53
- CommandLineParser
54
- Command line parser object.
55
- """
56
- config = configurator.Configurator(label=label, description=description, usage=usage)
36
+ def _parse():
37
+ """Parse command line configuration."""
38
+ config = configurator.Configurator(
39
+ label=get_application_label(__file__),
40
+ description="Plots tabular data.",
41
+ usage="""simtools-plot-tabular-data --plot_config config_file_name "
42
+ --output_file output_file_name""",
43
+ )
57
44
 
58
45
  config.parser.add_argument(
59
46
  "--plot_config",
@@ -79,33 +66,25 @@ def _parse(label, description, usage):
79
66
 
80
67
  def main():
81
68
  """Plot tabular data."""
82
- args_dict, db_config_ = _parse(
83
- label=Path(__file__).stem,
84
- description="Plots tabular data.",
85
- usage="""simtools-plot-tabular-data --plot_config config_file_name "
86
- --output_file output_file_name""",
87
- )
88
- logger = logging.getLogger()
89
- logger.setLevel(gen.get_log_level_from_user(args_dict.get("log_level", "INFO")))
90
- io_handler_instance = io_handler.IOHandler()
69
+ app_context = startup_application(_parse)
91
70
 
92
71
  plot_config = gen.convert_keys_in_dict_to_lowercase(
93
72
  schema.validate_dict_using_schema(
94
- ascii_handler.collect_data_from_file(args_dict["plot_config"]),
73
+ ascii_handler.collect_data_from_file(app_context.args["plot_config"]),
95
74
  PLOT_CONFIG_SCHEMA,
96
75
  )
97
76
  )
98
77
 
99
78
  plot_tables.plot(
100
79
  config=plot_config["plot"],
101
- output_file=io_handler_instance.get_output_file(args_dict["output_file"]),
102
- db_config=db_config_,
103
- data_path=args_dict.get("table_data_path"),
80
+ output_file=app_context.io_handler.get_output_file(app_context.args["output_file"]),
81
+ db_config=app_context.db_config,
82
+ data_path=app_context.args.get("table_data_path"),
104
83
  )
105
84
 
106
85
  MetadataCollector.dump(
107
- args_dict,
108
- io_handler_instance.get_output_file(args_dict["output_file"]),
86
+ app_context.args,
87
+ app_context.io_handler.get_output_file(app_context.args["output_file"]),
109
88
  add_activity_name=True,
110
89
  )
111
90
 
@@ -46,19 +46,18 @@ Plot tabular data for all types defined in the schema file:
46
46
 
47
47
  """
48
48
 
49
- import logging
50
- from pathlib import Path
51
-
52
- import simtools.utils.general as gen
49
+ from simtools.application_control import get_application_label, startup_application
53
50
  from simtools.configuration import configurator
54
51
  from simtools.data_model.metadata_collector import MetadataCollector
55
- from simtools.io import io_handler
56
52
  from simtools.visualization import plot_tables
57
53
 
58
54
 
59
- def _parse(label, description):
55
+ def _parse():
60
56
  """Parse command line configuration."""
61
- config = configurator.Configurator(label=label, description=description)
57
+ config = configurator.Configurator(
58
+ label=get_application_label(__file__),
59
+ description="Plots tabular data for a model parameter.",
60
+ )
62
61
 
63
62
  config.parser.add_argument("--parameter", type=str, required=True, help="Parameter name.")
64
63
  config.parser.add_argument(
@@ -73,31 +72,25 @@ def _parse(label, description):
73
72
 
74
73
  def main():
75
74
  """Plot tabular data."""
76
- args_dict, db_config = _parse(
77
- label=Path(__file__).stem,
78
- description="Plots tabular data for a model parameter.",
79
- )
80
- logger = logging.getLogger()
81
- logger.setLevel(gen.get_log_level_from_user(args_dict.get("log_level", "INFO")))
82
- io_handler_instance = io_handler.IOHandler()
75
+ app_context = startup_application(_parse)
83
76
 
84
77
  plot_configs, output_files = plot_tables.generate_plot_configurations(
85
- parameter=args_dict["parameter"],
86
- parameter_version=args_dict["parameter_version"],
87
- site=args_dict["site"],
88
- telescope=args_dict.get("telescope"),
89
- output_path=io_handler_instance.get_output_directory(),
90
- plot_type=args_dict["plot_type"],
91
- db_config=db_config,
78
+ parameter=app_context.args["parameter"],
79
+ parameter_version=app_context.args["parameter_version"],
80
+ site=app_context.args["site"],
81
+ telescope=app_context.args.get("telescope"),
82
+ output_path=app_context.io_handler.get_output_directory(),
83
+ plot_type=app_context.args["plot_type"],
84
+ db_config=app_context.db_config,
92
85
  )
93
86
 
94
87
  for plot_config, output_file in zip(plot_configs, output_files):
95
88
  plot_tables.plot(
96
89
  config=plot_config,
97
90
  output_file=output_file,
98
- db_config=db_config,
91
+ db_config=app_context.db_config,
99
92
  )
100
- MetadataCollector.dump(args_dict, output_file=output_file, add_activity_name=True)
93
+ MetadataCollector.dump(app_context.args, output_file=output_file, add_activity_name=True)
101
94
 
102
95
 
103
96
  if __name__ == "__main__":
@@ -6,55 +6,27 @@ The versions of simtools, the DB, sim_telarray, and CORSIKA are printed.
6
6
 
7
7
  """
8
8
 
9
- import logging
10
- from pathlib import Path
11
-
12
9
  from simtools import dependencies, version
10
+ from simtools.application_control import get_application_label, startup_application
13
11
  from simtools.configuration import configurator
14
- from simtools.io import ascii_handler, io_handler
15
- from simtools.utils import general as gen
16
-
17
-
18
- def _parse(label, description, usage):
19
- """
20
- Parse command line configuration.
12
+ from simtools.io import ascii_handler
21
13
 
22
- No command line arguments are required for this application,
23
- but the configurator is called to set up the DB connection and
24
- the structure with _parse is kept from other applications for consistency.
25
-
26
- Parameters
27
- ----------
28
- label : str
29
- Label describing the application.
30
- description : str
31
- Description of the application.
32
- usage : str
33
- Example on how to use the application.
34
-
35
- Returns
36
- -------
37
- CommandLineParser
38
- Command line parser object.
39
- """
40
- config = configurator.Configurator(label=label, description=description, usage=usage)
41
14
 
15
+ def _parse():
16
+ """Parse command line configuration."""
17
+ config = configurator.Configurator(
18
+ label=get_application_label(__file__),
19
+ description="Print the versions of simtools, the DB, sim_telarray and CORSIKA.",
20
+ usage="simtools-print-version",
21
+ )
42
22
  return config.initialize(db_config=True, output=True, require_command_line=False)
43
23
 
44
24
 
45
25
  def main():
46
26
  """Print the versions of the simtools software."""
47
- label = Path(__file__).stem
48
- args_dict, db_config = _parse(
49
- label=label,
50
- description="Print the versions of simtools, the DB, sim_telarray and CORSIKA.",
51
- usage="simtools-print-version",
52
- )
53
- logger = logging.getLogger()
54
- logger.setLevel(gen.get_log_level_from_user(args_dict["log_level"]))
55
- io_handler_instance = io_handler.IOHandler()
27
+ app_context = startup_application(_parse)
56
28
 
57
- version_string = dependencies.get_version_string(db_config)
29
+ version_string = dependencies.get_version_string(app_context.db_config)
58
30
  version_dict = {"simtools version": version.__version__}
59
31
 
60
32
  print()
@@ -68,11 +40,11 @@ def main():
68
40
  key, value = version_entry.split(": ", 1)
69
41
  version_dict[key] = value
70
42
 
71
- if not args_dict.get("output_file_from_default", False):
43
+ if not app_context.args.get("output_file_from_default", False):
72
44
  ascii_handler.write_data_to_file(
73
45
  data=version_dict,
74
- output_file=io_handler_instance.get_output_file(
75
- args_dict.get("output_file", "simtools_version.json")
46
+ output_file=app_context.io_handler.get_output_file(
47
+ app_context.args.get("output_file", "simtools_version.json")
76
48
  ),
77
49
  )
78
50
 
@@ -82,9 +82,7 @@ Derive limits for a given file for custom defined array layouts:
82
82
  --output_file corsika_simulation_limits_lookup.ecsv
83
83
  """
84
84
 
85
- import logging
86
-
87
- import simtools.utils.general as gen
85
+ from simtools.application_control import get_application_label, startup_application
88
86
  from simtools.configuration import configurator
89
87
  from simtools.production_configuration.derive_corsika_limits import (
90
88
  generate_corsika_limits_grid,
@@ -94,7 +92,8 @@ from simtools.production_configuration.derive_corsika_limits import (
94
92
  def _parse():
95
93
  """Parse command line configuration."""
96
94
  config = configurator.Configurator(
97
- description="Derive limits for energy, radial distance, and viewcone."
95
+ label=get_application_label(__file__),
96
+ description="Derive limits for energy, radial distance, and viewcone.",
98
97
  )
99
98
  config.parser.add_argument(
100
99
  "--event_data_file",
@@ -133,12 +132,9 @@ def _parse():
133
132
 
134
133
  def main():
135
134
  """Derive limits for energy, radial distance, and viewcone."""
136
- args_dict, db_config = _parse()
137
-
138
- logger = logging.getLogger()
139
- logger.setLevel(gen.get_log_level_from_user(args_dict.get("log_level", "info")))
135
+ app_context = startup_application(_parse)
140
136
 
141
- generate_corsika_limits_grid(args_dict, db_config)
137
+ generate_corsika_limits_grid(app_context.args, app_context.db_config)
142
138
 
143
139
 
144
140
  if __name__ == "__main__":
@@ -50,27 +50,21 @@ The output will be a file containing the grid points with the derived number of
50
50
  added.
51
51
  """
52
52
 
53
- import logging
54
- from pathlib import Path
55
-
53
+ from simtools.application_control import get_application_label, startup_application
56
54
  from simtools.configuration import configurator
57
- from simtools.io import io_handler
58
55
  from simtools.production_configuration.derive_production_statistics_handler import (
59
56
  ProductionStatisticsHandler,
60
57
  )
61
- from simtools.utils import general as gen
62
-
63
58
 
64
- def _parse(label, description):
65
- """
66
- Parse command line arguments for the statistical error evaluator application.
67
59
 
68
- Returns
69
- -------
70
- argparse.Namespace
71
- Parsed command line arguments.
72
- """
73
- config = configurator.Configurator(label=label, description=description)
60
+ def _parse():
61
+ """Parse command line arguments."""
62
+ config = configurator.Configurator(
63
+ label=get_application_label(__file__),
64
+ description=(
65
+ "Evaluate statistical uncertainties from DL2 MC event files and interpolate results."
66
+ ),
67
+ )
74
68
 
75
69
  config.parser.add_argument(
76
70
  "--grid_points_production_file",
@@ -139,18 +133,11 @@ def _parse(label, description):
139
133
 
140
134
  def main():
141
135
  """Run the ProductionStatisticsHandler."""
142
- label = Path(__file__).stem
136
+ app_context = startup_application(_parse)
143
137
 
144
- args_dict, _ = _parse(
145
- label,
146
- "Evaluate statistical uncertainties from DL2 MC event files and interpolate results.",
138
+ manager = ProductionStatisticsHandler(
139
+ app_context.args, output_path=app_context.io_handler.get_output_directory()
147
140
  )
148
- logger = logging.getLogger()
149
- logger.setLevel(gen.get_log_level_from_user(args_dict["log_level"]))
150
-
151
- _io_handler = io_handler.IOHandler()
152
-
153
- manager = ProductionStatisticsHandler(args_dict, output_path=_io_handler.get_output_directory())
154
141
  manager.run()
155
142
 
156
143
 
@@ -42,46 +42,24 @@ To generate a grid of simulation points, execute the script as follows:
42
42
  --telescope_ids 1
43
43
  """
44
44
 
45
- import logging
46
45
  from pathlib import Path
47
46
 
48
47
  from astropy.coordinates import EarthLocation
49
48
  from astropy.time import Time
50
49
 
50
+ from simtools.application_control import get_application_label, startup_application
51
51
  from simtools.configuration import configurator
52
- from simtools.io import io_handler
53
52
  from simtools.io.ascii_handler import collect_data_from_file
54
53
  from simtools.model.site_model import SiteModel
55
54
  from simtools.production_configuration.generate_production_grid import GridGeneration
56
55
 
57
56
 
58
- def _parse(label, description):
59
- """
60
- Parse command line configuration.
61
-
62
- Parameters
63
- ----------
64
- axes (str, required)
65
- Path to a YAML or JSON file defining the axes of the grid.
66
- coordinate_system (str, optional, default='zenith_azimuth')
67
- The coordinate system for the grid generation ('zenith_azimuth' or 'ra_dec').
68
- observing_time (str, optional, default=now)
69
- Time of the observation (format: 'YYYY-MM-DD HH:MM:SS').
70
- lookup_table (str, required)
71
- Path to the lookup table for simulation limits. The table should contain
72
- varying azimuth and/or zenith angles.
73
- telescope_ids (list of int, optional)
74
- List of telescope IDs as used in sim_telarray to filter the events.
75
- output_file (str, optional, default='grid_output.json')
76
- Output file for the generated grid points (default: 'grid_output.json').
77
-
78
-
79
- Returns
80
- -------
81
- CommandLineParser
82
- Command line parser object.
83
- """
84
- config = configurator.Configurator(label=label, description=description)
57
+ def _parse():
58
+ """Parse command line configuration."""
59
+ config = configurator.Configurator(
60
+ label=get_application_label(__file__),
61
+ description="Generate a grid of simulation points using flexible axes definitions.",
62
+ )
85
63
 
86
64
  config.parser.add_argument(
87
65
  "--axes",
@@ -148,23 +126,15 @@ def load_axes(file_path: str):
148
126
 
149
127
  def main():
150
128
  """Run the Grid Generation application."""
151
- label = Path(__file__).stem
152
- args_dict, db_config = _parse(
153
- label,
154
- "Generate a grid of simulation points using flexible axes definitions.",
155
- )
156
-
157
- _logger = logging.getLogger()
158
- _logger.setLevel(logging.INFO)
129
+ app_context = startup_application(_parse)
159
130
 
160
- output_path = io_handler.IOHandler().get_output_directory()
161
- output_filepath = Path(output_path).joinpath(f"{args_dict['output_file']}")
131
+ output_filepath = app_context.io_handler.get_output_file(app_context.args["output_file"])
162
132
 
163
- axes = load_axes(args_dict["axes"])
133
+ axes = load_axes(app_context.args["axes"])
164
134
  site_model = SiteModel(
165
- mongo_db_config=db_config,
166
- model_version=args_dict["model_version"],
167
- site=args_dict["site"],
135
+ db_config=app_context.db_config,
136
+ model_version=app_context.args["model_version"],
137
+ site=app_context.args["site"],
168
138
  )
169
139
 
170
140
  ref_lat = site_model.get_parameter_value_with_unit("reference_point_latitude")
@@ -174,21 +144,23 @@ def main():
174
144
  observing_location = EarthLocation(lat=ref_lat, lon=ref_long, height=altitude)
175
145
 
176
146
  observing_time = (
177
- Time(args_dict["observing_time"]) if args_dict.get("observing_time") else Time.now()
147
+ Time(app_context.args["observing_time"])
148
+ if app_context.args.get("observing_time")
149
+ else Time.now()
178
150
  )
179
151
 
180
152
  grid_gen = GridGeneration(
181
153
  axes=axes,
182
- coordinate_system=args_dict["coordinate_system"],
154
+ coordinate_system=app_context.args["coordinate_system"],
183
155
  observing_location=observing_location,
184
156
  observing_time=observing_time,
185
- lookup_table=args_dict["lookup_table"],
186
- telescope_ids=args_dict["telescope_ids"],
157
+ lookup_table=app_context.args["lookup_table"],
158
+ telescope_ids=app_context.args["telescope_ids"],
187
159
  )
188
160
 
189
161
  grid_points = grid_gen.generate_grid()
190
162
 
191
- if args_dict["coordinate_system"] == "ra_dec":
163
+ if app_context.args["coordinate_system"] == "ra_dec":
192
164
  grid_points = grid_gen.convert_coordinates(grid_points)
193
165
  grid_gen.serialize_grid_points(grid_points, output_file=output_filepath)
194
166
 
@@ -77,22 +77,20 @@ Examples
77
77
  --output_file merged_limits.ecsv
78
78
  """
79
79
 
80
- import logging
81
80
  from pathlib import Path
82
81
 
83
- import simtools.utils.general as gen
82
+ from simtools.application_control import get_application_label, startup_application
84
83
  from simtools.configuration import configurator
85
84
  from simtools.data_model import data_reader
86
85
  from simtools.io import ascii_handler
87
86
  from simtools.production_configuration.merge_corsika_limits import CorsikaMergeLimits
88
87
 
89
- _logger = logging.getLogger(__name__)
90
-
91
88
 
92
89
  def _parse():
93
90
  """Parse command line configuration."""
94
91
  config = configurator.Configurator(
95
- description="Merge CORSIKA limit tables and check grid completeness."
92
+ label=get_application_label(__file__),
93
+ description="Merge CORSIKA limit tables and check grid completeness.",
96
94
  )
97
95
  config.parser.add_argument(
98
96
  "--input_files",
@@ -142,29 +140,27 @@ def _parse():
142
140
 
143
141
  def main():
144
142
  """Merge CORSIKA limit tables and check grid completeness."""
145
- args_dict, _ = _parse()
146
- logger = logging.getLogger()
147
- logger.setLevel(gen.get_log_level_from_user(args_dict.get("log_level", "info")))
143
+ app_context = startup_application(_parse)
148
144
 
149
145
  merger = CorsikaMergeLimits()
150
146
  grid_definition = (
151
- ascii_handler.collect_data_from_file(args_dict["grid_definition"])
152
- if args_dict.get("grid_definition")
147
+ ascii_handler.collect_data_from_file(app_context.args["grid_definition"])
148
+ if app_context.args.get("grid_definition")
153
149
  else None
154
150
  )
155
151
 
156
- if args_dict.get("merged_table"):
152
+ if app_context.args.get("merged_table"):
157
153
  # Case 3: Check coverage on an existing merged table
158
- merged_table_path = Path(args_dict["merged_table"]).expanduser()
154
+ merged_table_path = Path(app_context.args["merged_table"]).expanduser()
159
155
  merged_table = data_reader.read_table_from_file(merged_table_path)
160
156
  input_files = [merged_table_path]
161
- elif args_dict.get("input_files") or args_dict.get("input_files_list"):
157
+ elif app_context.args.get("input_files") or app_context.args.get("input_files_list"):
162
158
  # Case 1 & 2: Merge files
163
159
  input_files = []
164
160
 
165
161
  # Process input_files argument
166
- if args_dict.get("input_files"):
167
- raw_paths = args_dict.get("input_files")
162
+ if app_context.args.get("input_files"):
163
+ raw_paths = app_context.args.get("input_files")
168
164
  if len(raw_paths) == 1 and Path(raw_paths[0]).expanduser().is_dir():
169
165
  input_dir = Path(raw_paths[0]).expanduser()
170
166
  input_files.extend(input_dir.glob("*.ecsv"))
@@ -172,8 +168,8 @@ def main():
172
168
  input_files.extend(Path(f).expanduser() for f in raw_paths)
173
169
 
174
170
  # Process input_files_list argument
175
- if args_dict.get("input_files_list"):
176
- files_from_list = merger.read_file_list(args_dict["input_files_list"])
171
+ if app_context.args.get("input_files_list"):
172
+ files_from_list = merger.read_file_list(app_context.args["input_files_list"])
177
173
  input_files.extend(files_from_list)
178
174
 
179
175
  if not input_files:
@@ -188,15 +184,15 @@ def main():
188
184
 
189
185
  is_complete, grid_completeness = merger.check_grid_completeness(merged_table, grid_definition)
190
186
 
191
- if args_dict.get("plot_grid_coverage"):
187
+ if app_context.args.get("plot_grid_coverage"):
192
188
  merger.plot_grid_coverage(merged_table, grid_definition)
193
189
 
194
- if args_dict.get("plot_limits"):
190
+ if app_context.args.get("plot_limits"):
195
191
  merger.plot_limits(merged_table)
196
192
 
197
- if not args_dict.get("merged_table"):
193
+ if not app_context.args.get("merged_table"):
198
194
  # Write output file only when merging
199
- output_file = merger.output_dir / args_dict["output_file"]
195
+ output_file = merger.output_dir / app_context.args["output_file"]
200
196
  merger.write_merged_table(
201
197
  merged_table,
202
198
  output_file,
@@ -62,33 +62,18 @@ step 2 and 3 (useful for debugging):
62
62
 
63
63
  """
64
64
 
65
- import logging
66
- from pathlib import Path
67
-
68
- import simtools.utils.general as gen
65
+ from simtools.application_control import get_application_label, startup_application
69
66
  from simtools.configuration import configurator
70
67
  from simtools.runners import simtools_runner
71
68
 
72
69
 
73
- def _parse(label, description, usage):
74
- """
75
- Parse command line configuration.
76
-
77
- Parameters
78
- ----------
79
- label : str
80
- Label describing the application.
81
- description : str
82
- Description of the application.
83
- usage : str
84
- Example on how to use the application.
85
-
86
- Returns
87
- -------
88
- CommandLineParser
89
- Command line parser object.
90
- """
91
- config = configurator.Configurator(label=label, description=description, usage=usage)
70
+ def _parse():
71
+ """Parse command line configuration."""
72
+ config = configurator.Configurator(
73
+ label=get_application_label(__file__),
74
+ description="Run simtools applications using a configuration file.",
75
+ usage="simtools-run-application --config_file config_file_name",
76
+ )
92
77
 
93
78
  config.parser.add_argument(
94
79
  "--configuration_file",
@@ -112,16 +97,11 @@ def _parse(label, description, usage):
112
97
  return config.initialize(db_config=True)
113
98
 
114
99
 
115
- def main(): # noqa: D103
116
- args_dict, db_config = _parse(
117
- Path(__file__).stem,
118
- description="Run simtools applications using a configuration file.",
119
- usage="simtools-run-application --config_file config_file_name",
120
- )
121
- logger = logging.getLogger()
122
- logger.setLevel(gen.get_log_level_from_user(args_dict["log_level"]))
100
+ def main():
101
+ """Run several simtools applications using a configuration file."""
102
+ app_context = startup_application(_parse, setup_io_handler=False)
123
103
 
124
- simtools_runner.run_applications(args_dict, db_config, logger)
104
+ simtools_runner.run_applications(app_context.args, app_context.db_config, app_context.logger)
125
105
 
126
106
 
127
107
  if __name__ == "__main__":