gammasimtools 0.8.2__py3-none-any.whl → 0.10.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 (122) hide show
  1. {gammasimtools-0.8.2.dist-info → gammasimtools-0.10.0.dist-info}/METADATA +4 -4
  2. {gammasimtools-0.8.2.dist-info → gammasimtools-0.10.0.dist-info}/RECORD +119 -105
  3. {gammasimtools-0.8.2.dist-info → gammasimtools-0.10.0.dist-info}/WHEEL +1 -1
  4. {gammasimtools-0.8.2.dist-info → gammasimtools-0.10.0.dist-info}/entry_points.txt +4 -1
  5. simtools/_version.py +2 -2
  6. simtools/applications/calculate_trigger_rate.py +15 -38
  7. simtools/applications/convert_all_model_parameters_from_simtel.py +9 -28
  8. simtools/applications/convert_geo_coordinates_of_array_elements.py +54 -53
  9. simtools/applications/convert_model_parameter_from_simtel.py +2 -2
  10. simtools/applications/db_add_file_to_db.py +1 -2
  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 +2 -11
  13. simtools/applications/db_development_tools/write_array_elements_positions_to_repository.py +6 -6
  14. simtools/applications/db_get_array_layouts_from_db.py +3 -1
  15. simtools/applications/db_get_file_from_db.py +11 -12
  16. simtools/applications/db_get_parameter_from_db.py +44 -32
  17. simtools/applications/derive_mirror_rnda.py +10 -1
  18. simtools/applications/derive_photon_electron_spectrum.py +99 -0
  19. simtools/applications/derive_psf_parameters.py +1 -1
  20. simtools/applications/generate_array_config.py +18 -22
  21. simtools/applications/generate_regular_arrays.py +24 -21
  22. simtools/applications/generate_simtel_array_histograms.py +11 -48
  23. simtools/applications/plot_array_layout.py +3 -1
  24. simtools/applications/plot_tabular_data.py +84 -0
  25. simtools/applications/production_generate_simulation_config.py +25 -7
  26. simtools/applications/production_scale_events.py +3 -4
  27. simtools/applications/simulate_light_emission.py +2 -2
  28. simtools/applications/simulate_prod.py +25 -60
  29. simtools/applications/simulate_prod_htcondor_generator.py +95 -0
  30. simtools/applications/submit_data_from_external.py +12 -4
  31. simtools/applications/submit_model_parameter_from_external.py +8 -6
  32. simtools/applications/validate_camera_efficiency.py +3 -3
  33. simtools/applications/validate_camera_fov.py +3 -7
  34. simtools/applications/validate_cumulative_psf.py +3 -7
  35. simtools/applications/validate_file_using_schema.py +38 -24
  36. simtools/applications/validate_optics.py +3 -4
  37. simtools/{camera_efficiency.py → camera/camera_efficiency.py} +1 -4
  38. simtools/camera/single_photon_electron_spectrum.py +168 -0
  39. simtools/configuration/commandline_parser.py +14 -13
  40. simtools/configuration/configurator.py +6 -19
  41. simtools/constants.py +10 -3
  42. simtools/corsika/corsika_config.py +8 -7
  43. simtools/corsika/corsika_histograms.py +1 -1
  44. simtools/data_model/data_reader.py +0 -3
  45. simtools/data_model/metadata_collector.py +21 -4
  46. simtools/data_model/metadata_model.py +8 -111
  47. simtools/data_model/model_data_writer.py +18 -64
  48. simtools/data_model/schema.py +213 -0
  49. simtools/data_model/validate_data.py +73 -51
  50. simtools/db/db_handler.py +395 -790
  51. simtools/db/db_model_upload.py +139 -0
  52. simtools/io_operations/hdf5_handler.py +54 -24
  53. simtools/io_operations/legacy_data_handler.py +61 -0
  54. simtools/job_execution/htcondor_script_generator.py +133 -0
  55. simtools/job_execution/job_manager.py +77 -50
  56. simtools/layout/array_layout.py +33 -28
  57. simtools/model/array_model.py +13 -7
  58. simtools/model/camera.py +4 -2
  59. simtools/model/model_parameter.py +61 -63
  60. simtools/model/site_model.py +3 -3
  61. simtools/production_configuration/calculate_statistical_errors_grid_point.py +119 -144
  62. simtools/production_configuration/event_scaler.py +7 -17
  63. simtools/production_configuration/generate_simulation_config.py +5 -32
  64. simtools/production_configuration/interpolation_handler.py +8 -11
  65. simtools/ray_tracing/mirror_panel_psf.py +47 -27
  66. simtools/runners/corsika_runner.py +14 -3
  67. simtools/runners/corsika_simtel_runner.py +3 -1
  68. simtools/runners/runner_services.py +3 -3
  69. simtools/runners/simtel_runner.py +27 -8
  70. simtools/schemas/input/MST_mirror_2f_measurements.schema.yml +39 -0
  71. simtools/schemas/input/single_pe_spectrum.schema.yml +38 -0
  72. simtools/schemas/integration_tests_config.metaschema.yml +23 -3
  73. simtools/schemas/model_parameter.metaschema.yml +95 -2
  74. simtools/schemas/model_parameter_and_data_schema.metaschema.yml +2 -0
  75. simtools/schemas/model_parameters/array_element_position_utm.schema.yml +1 -1
  76. simtools/schemas/model_parameters/array_window.schema.yml +37 -0
  77. simtools/schemas/model_parameters/asum_clipping.schema.yml +0 -4
  78. simtools/schemas/model_parameters/channels_per_chip.schema.yml +1 -1
  79. simtools/schemas/model_parameters/corsika_iact_io_buffer.schema.yml +2 -2
  80. simtools/schemas/model_parameters/dsum_clipping.schema.yml +0 -2
  81. simtools/schemas/model_parameters/dsum_ignore_below.schema.yml +0 -2
  82. simtools/schemas/model_parameters/dsum_offset.schema.yml +0 -2
  83. simtools/schemas/model_parameters/dsum_pedsub.schema.yml +0 -2
  84. simtools/schemas/model_parameters/dsum_pre_clipping.schema.yml +0 -2
  85. simtools/schemas/model_parameters/dsum_prescale.schema.yml +0 -2
  86. simtools/schemas/model_parameters/dsum_presum_max.schema.yml +0 -2
  87. simtools/schemas/model_parameters/dsum_presum_shift.schema.yml +0 -2
  88. simtools/schemas/model_parameters/dsum_shaping.schema.yml +0 -2
  89. simtools/schemas/model_parameters/dsum_shaping_renormalize.schema.yml +0 -2
  90. simtools/schemas/model_parameters/dsum_threshold.schema.yml +0 -2
  91. simtools/schemas/model_parameters/dsum_zero_clip.schema.yml +0 -2
  92. simtools/schemas/model_parameters/effective_focal_length.schema.yml +31 -1
  93. simtools/schemas/model_parameters/fadc_compensate_pedestal.schema.yml +1 -1
  94. simtools/schemas/model_parameters/fadc_lg_compensate_pedestal.schema.yml +1 -1
  95. simtools/schemas/model_parameters/fadc_noise.schema.yml +3 -3
  96. simtools/schemas/model_parameters/fake_mirror_list.schema.yml +33 -0
  97. simtools/schemas/model_parameters/laser_photons.schema.yml +2 -2
  98. simtools/schemas/model_parameters/secondary_mirror_degraded_reflection.schema.yml +1 -1
  99. simtools/schemas/production_configuration_metrics.schema.yml +68 -0
  100. simtools/schemas/production_tables.schema.yml +41 -0
  101. simtools/simtel/simtel_config_writer.py +5 -6
  102. simtools/simtel/simtel_io_histogram.py +32 -67
  103. simtools/simtel/simtel_io_histograms.py +15 -30
  104. simtools/simtel/simtel_table_reader.py +410 -0
  105. simtools/simtel/simulator_array.py +2 -1
  106. simtools/simtel/simulator_camera_efficiency.py +11 -4
  107. simtools/simtel/simulator_light_emission.py +5 -3
  108. simtools/simtel/simulator_ray_tracing.py +2 -2
  109. simtools/simulator.py +80 -33
  110. simtools/testing/configuration.py +12 -8
  111. simtools/testing/helpers.py +9 -16
  112. simtools/testing/validate_output.py +152 -68
  113. simtools/utils/general.py +149 -12
  114. simtools/utils/names.py +25 -21
  115. simtools/utils/value_conversion.py +9 -1
  116. simtools/visualization/plot_tables.py +106 -0
  117. simtools/visualization/visualize.py +43 -5
  118. simtools/applications/db_add_model_parameters_from_repository_to_db.py +0 -184
  119. simtools/db/db_array_elements.py +0 -130
  120. simtools/db/db_from_repo_handler.py +0 -106
  121. {gammasimtools-0.8.2.dist-info → gammasimtools-0.10.0.dist-info}/LICENSE +0 -0
  122. {gammasimtools-0.8.2.dist-info → gammasimtools-0.10.0.dist-info}/top_level.txt +0 -0
@@ -6,6 +6,8 @@ r"""
6
6
  ready to be submitted to the model database. Prints out parameters which are not found
7
7
  in simtel configuration file and parameters which are not found in simtools schema files.
8
8
 
9
+ Note that all parameters are assigned the same parameter version.
10
+
9
11
  Command line arguments
10
12
  ----------------------
11
13
  simtel_cfg_file (str)
@@ -30,7 +32,7 @@ r"""
30
32
  --simtel_cfg_file all_telescope_config_la_palma.cfg\\
31
33
  --simtel_telescope_name CT1\\
32
34
  --telescope LSTN-01\\
33
- --model_version "2024-03-06"
35
+ --parameter_version "1.0.0"
34
36
 
35
37
  The export of the model parameters from sim_telarray for 6.0.0 can be done e.g., as follows:
36
38
 
@@ -59,7 +61,7 @@ import numpy as np
59
61
  import simtools.data_model.model_data_writer as writer
60
62
  import simtools.utils.general as gen
61
63
  from simtools.configuration import configurator
62
- from simtools.constants import MODEL_PARAMETER_SCHEMA_PATH
64
+ from simtools.data_model import schema
63
65
  from simtools.io_operations.io_handler import IOHandler
64
66
  from simtools.simtel.simtel_config_reader import SimtelConfigReader
65
67
 
@@ -103,27 +105,7 @@ def _parse(label=None, description=None):
103
105
  type=str,
104
106
  required=True,
105
107
  )
106
- return config.initialize(simulation_model="telescope")
107
-
108
-
109
- def get_list_of_parameters_and_schema_files(schema_directory):
110
- """
111
- Return list of parameters and schema files located in schema file directory.
112
-
113
- Returns
114
- -------
115
- list
116
- List of parameters found in schema file directory.
117
- list
118
- List of schema files found in schema file directory.
119
-
120
- """
121
- schema_files = sorted(Path(schema_directory).rglob("*.schema.yml"))
122
- parameters = []
123
- for schema_file in schema_files:
124
- schema_dict = gen.collect_data_from_file(file_name=schema_file)
125
- parameters.append(schema_dict.get("name"))
126
- return parameters, schema_files
108
+ return config.initialize(simulation_model=["telescope", "parameter_version"])
127
109
 
128
110
 
129
111
  def get_list_of_simtel_parameters(simtel_config_file, logger):
@@ -203,7 +185,7 @@ def get_number_of_camera_pixel(args_dict, logger):
203
185
  """
204
186
  try:
205
187
  simtel_config_reader = SimtelConfigReader(
206
- schema_file=MODEL_PARAMETER_SCHEMA_PATH / "camera_pixels.schema.yml",
188
+ schema_file=schema.get_model_parameter_schema_file("camera_pixels"),
207
189
  simtel_config_file=args_dict["simtel_cfg_file"],
208
190
  simtel_telescope_name=args_dict["simtel_telescope_name"],
209
191
  )
@@ -219,7 +201,6 @@ def read_and_export_parameters(args_dict, logger):
219
201
  """
220
202
  Read and export parameters from simtel configuration file to json files.
221
203
 
222
- Only applicable parameters are exported to json.
223
204
  Provide extensive logging information on the parameters found in the simtel
224
205
  configuration file.
225
206
 
@@ -238,8 +219,8 @@ def read_and_export_parameters(args_dict, logger):
238
219
  List of simtools parameter not found in simtel configuration file.
239
220
 
240
221
  """
241
- _parameters, _schema_files = get_list_of_parameters_and_schema_files(
242
- args_dict.get("schema_directory", MODEL_PARAMETER_SCHEMA_PATH)
222
+ _parameters, _schema_files = schema.get_get_model_parameter_schema_files(
223
+ args_dict.get("schema_directory")
243
224
  )
244
225
  _simtel_parameters = get_list_of_simtel_parameters(args_dict["simtel_cfg_file"], logger)
245
226
 
@@ -266,7 +247,7 @@ def read_and_export_parameters(args_dict, logger):
266
247
  parameter_name=_parameter,
267
248
  value=simtel_config_reader.parameter_dict.get(args_dict["simtel_telescope_name"]),
268
249
  instrument=args_dict["telescope"],
269
- model_version=args_dict["model_version"],
250
+ parameter_version=args_dict["parameter_version"],
270
251
  output_file=io_handler.get_output_file(f"{_parameter}.json"),
271
252
  )
272
253
 
@@ -1,56 +1,56 @@
1
1
  #!/usr/bin/python3
2
2
  """Convert and print a list of array element positions in different coordinate systems.
3
3
 
4
- Description
5
- -----------
6
-
7
- Convert array element positions in different CTAO coordinate systems.
8
- Available coordinate systems are:
9
-
10
- 1. UTM system
11
- 2. ground system (similar to sim_telarray system with x-axis pointing toward geographic north
12
- and y-axis pointing towards the west); altitude relative to the CORSIKA observation level.
13
- Altitude is the height of the elevation rotation axis (plus some possible mirror offset).
14
- 3. Mercator system
15
-
16
- Command line arguments
17
- ----------------------
18
- input (str)
19
- File name with list of array element positions.
20
- Input can be given as astropy table file (ecsv) or a single array element in
21
- a json file.
22
- print (str)
23
- Print in requested coordinate system; possible are ground, utm, mercator
24
- export (str)
25
- Export array element list to file in requested coordinate system;
26
- possible are ground, utm, mercator
27
- select_assets (str)
28
- Select a subset of array elements / telescopes (e.g., MSTN, LSTN)
29
-
30
- Example
31
- -------
32
- Convert a list of array elements using a list of telescope positions in UTM coordinates.
4
+ Description
5
+ -----------
6
+
7
+ Convert array element positions in different CTAO coordinate systems.
8
+ Available coordinate systems are:
9
+
10
+ 1. UTM system
11
+ 2. ground system (similar to sim_telarray system with x-axis pointing toward geographic north
12
+ and y-axis pointing towards the west); altitude relative to the CORSIKA observation level.
13
+ Altitude is the height of the elevation rotation axis (plus some possible mirror offset).
14
+ 3. Mercator system
15
+
16
+ Command line arguments
17
+ ----------------------
18
+ input (str)
19
+ File name with list of array element positions.
20
+ Input can be given as astropy table file (ecsv) or a single array element in
21
+ a json file.
22
+ print (str)
23
+ Print in requested coordinate system; possible are ground, utm, mercator
24
+ export (str)
25
+ Export array element list to file in requested coordinate system;
26
+ possible are ground, utm, mercator
27
+ select_assets (str)
28
+ Select a subset of array elements / telescopes (e.g., MSTN, LSTN)
29
+
30
+ Example
31
+ -------
32
+ Convert a list of array elements using a list of telescope positions in UTM coordinates.
33
33
 
34
- .. code-block:: console
34
+ .. code-block:: console
35
35
 
36
- simtools-convert-geo-coordinates-of-array-elements
37
- --input tests/resources/telescope_positions-North-utm.ecsv
38
- --print ground
36
+ simtools-convert-geo-coordinates-of-array-elements
37
+ --input tests/resources/telescope_positions-North-utm.ecsv
38
+ --print ground
39
39
 
40
- The converted list of telescope positions in ground coordinates is printed to the screen.
40
+ The converted list of telescope positions in ground coordinates is printed to the screen.
41
41
 
42
- The following example converts a list of telescope positions in UTM coordinates
43
- and writes the output to a file in ground (sim_telarray) coordinates. Also selects
44
- only a subset of the array elements (telescopes; ignore calibration devices):
42
+ The following example converts a list of telescope positions in UTM coordinates
43
+ and writes the output to a file in ground (sim_telarray) coordinates. Also selects
44
+ only a subset of the array elements (telescopes; ignore calibration devices):
45
45
 
46
- .. code-block:: console
46
+ .. code-block:: console
47
47
 
48
- simtools-convert-geo-coordinates-of-array-elements
49
- --input tests/resources/telescope_positions-North-utm.ecsv
50
- --export ground
51
- --select_assets LSTN
48
+ simtools-convert-geo-coordinates-of-array-elements
49
+ --input tests/resources/telescope_positions-North-utm.ecsv
50
+ --export ground
51
+ --select_assets LSTN
52
52
 
53
- Expected output is a ecsv file in the directory printed to the screen.
53
+ Expected output is a ecsv file in the directory printed to the screen.
54
54
 
55
55
  """
56
56
 
@@ -130,7 +130,10 @@ def _parse(label=None, description=None):
130
130
  action="store_true",
131
131
  )
132
132
  return config.initialize(
133
- output=True, require_command_line=True, db_config=True, simulation_model=["version", "site"]
133
+ output=True,
134
+ require_command_line=True,
135
+ db_config=True,
136
+ simulation_model=["model_version", "parameter_version", "site"],
134
137
  )
135
138
 
136
139
 
@@ -146,16 +149,12 @@ def main():
146
149
  logger = logging.getLogger()
147
150
  logger.setLevel(gen.get_log_level_from_user(args_dict["log_level"]))
148
151
 
149
- json_type = args_dict.get("input", "").endswith(".json")
150
- # simplified metadata treatment for model parameter json files
151
- if json_type:
152
+ if args_dict.get("input", "").endswith(".json"):
152
153
  site = args_dict.get("site", None)
153
- top_level_meta = None
154
- validate_schema_file = None
154
+ metadata, validate_schema_file = None, None
155
155
  else:
156
156
  metadata = MetadataCollector(args_dict=args_dict, data_model_name=data_model_name)
157
157
  site = metadata.get_site(from_input_meta=True)
158
- top_level_meta = metadata.top_level_meta
159
158
  validate_schema_file = metadata.get_data_model_schema_file_name()
160
159
 
161
160
  layout = array_layout.ArrayLayout(
@@ -171,13 +170,15 @@ def main():
171
170
 
172
171
  if args_dict["export"] is not None:
173
172
  product_data = (
174
- layout.export_one_telescope_as_json(crs_name=args_dict["export"])
175
- if json_type
173
+ layout.export_one_telescope_as_json(
174
+ crs_name=args_dict["export"], parameter_version=args_dict.get("parameter_version")
175
+ )
176
+ if args_dict.get("input", "").endswith(".json")
176
177
  else layout.export_telescope_list_table(crs_name=args_dict["export"])
177
178
  )
178
179
  writer.ModelDataWriter.dump(
179
180
  args_dict=args_dict,
180
- metadata=top_level_meta,
181
+ metadata=metadata.get_top_level_metadata() if metadata else None,
181
182
  product_data=product_data,
182
183
  validate_schema_file=validate_schema_file,
183
184
  )
@@ -78,7 +78,7 @@ def _parse(label=None, description=None):
78
78
  type=str,
79
79
  required=True,
80
80
  )
81
- return config.initialize(simulation_model="telescope", output=True)
81
+ return config.initialize(simulation_model=["telescope", "parameter_version"], output=True)
82
82
 
83
83
 
84
84
  def main(): # noqa: D103
@@ -107,7 +107,7 @@ def main(): # noqa: D103
107
107
  parameter_name=simtel_config_reader.parameter_name,
108
108
  value=simtel_config_reader.parameter_dict.get(args_dict["simtel_telescope_name"]),
109
109
  instrument=args_dict["telescope"],
110
- model_version=args_dict["model_version"],
110
+ parameter_version=args_dict["parameter_version"],
111
111
  output_file=args_dict["output_file"],
112
112
  output_path=args_dict.get("output_path"),
113
113
  use_plain_output_path=args_dict.get("use_plain_output_path"),
@@ -18,8 +18,7 @@
18
18
  A directory with files to upload to the DB. \
19
19
  All files in the directory with a predefined list of extensions will be uploaded.
20
20
  db (str)
21
- The DB to insert the files to. \
22
- The choices are either the default CTA simulation DB or a sandbox for testing.
21
+ The DB to insert the files to.
23
22
 
24
23
  Example
25
24
  -------
@@ -0,0 +1,110 @@
1
+ #!/usr/bin/python3
2
+ r"""
3
+ Add parameters and production tables from a simulation model repository to a new database.
4
+
5
+ Generates a new database with all required collections.
6
+ Follows the structure of the CTAO gitlab simulation model repository.
7
+
8
+ This is an application for experts and should not be used by the general user.
9
+
10
+ Command line arguments
11
+
12
+ input_path (str, required)
13
+ Path of local copy of model parameter repository.
14
+ db_name (str, required)
15
+ Name of new DB to be created.
16
+ type (str, optional)
17
+ Type of data to be uploaded to the DB. Options are: model_parameters, production_tables.
18
+
19
+ Examples
20
+ --------
21
+ Upload model data repository to the DB:
22
+
23
+ .. code-block:: console
24
+
25
+ simtools-db-simulation-model-from-repository-to-db \
26
+ --input_path /path/to/repository \
27
+ --db_name new_db_name \
28
+ --type model_parameters
29
+
30
+ Upload production tables to the DB:
31
+
32
+ .. code-block:: console
33
+
34
+ simtools-db-simulation-model-from-repository-to-db \
35
+ --input_path /path/to/repository \
36
+ --db_name new_db_name \
37
+ --type production_tables
38
+
39
+ """
40
+
41
+ import logging
42
+ from pathlib import Path
43
+
44
+ import simtools.utils.general as gen
45
+ from simtools.configuration import configurator
46
+ from simtools.db import db_handler, db_model_upload
47
+
48
+
49
+ def _parse(label=None, description=None):
50
+ """
51
+ Parse command line configuration.
52
+
53
+ Parameters
54
+ ----------
55
+ label : str
56
+ Label describing application.
57
+ description : str
58
+ Description of application.
59
+
60
+ Returns
61
+ -------
62
+ CommandLineParser
63
+ Command line parser object.
64
+ """
65
+ config = configurator.Configurator(label=label, description=description)
66
+ config.parser.add_argument(
67
+ "--input_path",
68
+ help="Path to simulation model repository.",
69
+ type=Path,
70
+ required=True,
71
+ )
72
+ config.parser.add_argument(
73
+ "--db_name",
74
+ help="Name of the new simulation model database to be created.",
75
+ type=str.strip,
76
+ required=True,
77
+ )
78
+ config.parser.add_argument(
79
+ "--type",
80
+ help="Type of data to be uploaded to the database.",
81
+ type=str,
82
+ required=False,
83
+ default="model_parameters",
84
+ choices=["model_parameters", "production_tables"],
85
+ )
86
+
87
+ args_dict, db_config = config.initialize(output=True, require_command_line=True, db_config=True)
88
+ db_config["db_simulation_model"] = args_dict["db_name"] # overwrite explicitly DB configuration
89
+ return args_dict, db_config
90
+
91
+
92
+ def main():
93
+ """Application main."""
94
+ label = Path(__file__).stem
95
+ args_dict, db_config = _parse(
96
+ label, description="Add or update a model parameter database to the DB"
97
+ )
98
+ logger = logging.getLogger()
99
+ logger.setLevel(gen.get_log_level_from_user(args_dict["log_level"]))
100
+
101
+ db = db_handler.DatabaseHandler(mongo_db_config=db_config)
102
+
103
+ if args_dict.get("type") == "model_parameters":
104
+ db_model_upload.add_model_parameters_to_db(args_dict, db)
105
+ elif args_dict.get("type") == "production_tables":
106
+ db_model_upload.add_production_tables_to_db(args_dict, db)
107
+
108
+
109
+ if __name__ == "__main__":
110
+ main()
@@ -10,8 +10,7 @@ r"""
10
10
  db_collection (str, required)
11
11
  The DB collection to which to add the file.
12
12
  db (str)
13
- The DB to insert the files to. \
14
- The choices are either the default CTA simulation DB or a sandbox for testing.
13
+ The DB to insert the files to.
15
14
 
16
15
  Example
17
16
  -------
@@ -81,16 +80,8 @@ def main(): # noqa: D103
81
80
  logger.info(f"Adding the following parameter to the DB: {par_dict['parameter']}")
82
81
  db.add_new_parameter(
83
82
  db_name=db_config["db_simulation_model"],
84
- array_element_name=par_dict["instrument"],
85
- parameter=par_dict["parameter"],
86
- version=par_dict["version"],
87
- value=par_dict["value"],
88
- site=par_dict["site"],
89
- type=par_dict["type"],
83
+ par_dict=par_dict,
90
84
  collection_name=args_dict["db_collection"],
91
- applicable=par_dict["applicable"],
92
- file=par_dict["file"],
93
- unit=par_dict.get("unit", None),
94
85
  file_prefix="./",
95
86
  )
96
87
  logger.info(
@@ -11,8 +11,8 @@
11
11
  File containing a table of array element positions.
12
12
  repository_path : str
13
13
  Path of local copy of model parameter repository.
14
- model_version : str
15
- Model version.
14
+ parameter_version : str
15
+ Parameter version.
16
16
  site : str
17
17
  Observatory site.
18
18
  coordinate_system : str
@@ -27,7 +27,7 @@
27
27
  simtools-write-array-element-positions-to-repository \
28
28
  --input /path/to/positions.txt \
29
29
  --repository_path /path/to/repository \
30
- --model_version 1.0.0 \
30
+ --parameter_version 0.1.0 \
31
31
  --coordinate_system ground \
32
32
  --site North
33
33
 
@@ -82,7 +82,7 @@ def _parse(label=None, description=None):
82
82
  choices=["ground", "utm"],
83
83
  )
84
84
 
85
- return config.initialize(db_config=True, simulation_model="site")
85
+ return config.initialize(db_config=True, simulation_model=["site", "parameter_version"])
86
86
 
87
87
 
88
88
  def write_utm_array_elements_to_repository(args_dict, logger):
@@ -115,7 +115,7 @@ def write_utm_array_elements_to_repository(args_dict, logger):
115
115
  parameter_name="array_element_position_utm",
116
116
  instrument=instrument,
117
117
  value=f"{row['utm_east']} {row['utm_north']} {row['altitude']}",
118
- model_version=args_dict["model_version"],
118
+ parameter_version=args_dict["parameter_version"],
119
119
  output_path=output_path,
120
120
  output_file="array_element_position_utm.json",
121
121
  )
@@ -137,7 +137,7 @@ def write_ground_array_elements_to_repository(args_dict, db_config, logger):
137
137
  """
138
138
  array_model = ArrayModel(
139
139
  mongo_db_config=db_config,
140
- model_version=args_dict["model_version"],
140
+ model_version=None,
141
141
  site=args_dict["site"],
142
142
  array_elements=args_dict["input"],
143
143
  )
@@ -94,7 +94,9 @@ def _parse(label, description):
94
94
  default="ground",
95
95
  choices=["ground", "utm"],
96
96
  )
97
- return config.initialize(db_config=True, simulation_model=["site", "layout"], output=True)
97
+ return config.initialize(
98
+ db_config=True, simulation_model=["site", "layout", "model_version"], output=True
99
+ )
98
100
 
99
101
 
100
102
  def _layout_from_db(args_dict, db_config):
@@ -49,8 +49,9 @@ def _parse():
49
49
 
50
50
  config.parser.add_argument(
51
51
  "--file_name",
52
- help="The name of the file to be downloaded.",
52
+ help="The name of the file(s) to be downloaded (single file or space-separated list).",
53
53
  type=str,
54
+ nargs="+",
54
55
  required=True,
55
56
  )
56
57
  return config.initialize(db_config=True, output=True)
@@ -66,15 +67,14 @@ def main(): # noqa: D103
66
67
  db = db_handler.DatabaseHandler(mongo_db_config=db_config)
67
68
  available_dbs = [
68
69
  db_config["db_simulation_model"],
69
- db.DB_CTA_SIMULATION_MODEL_DESCRIPTIONS,
70
- db.DB_DERIVED_VALUES,
71
- "sandbox",
72
70
  ]
73
- file_id = None
71
+ file_id = {}
74
72
  for db_name in available_dbs:
75
73
  try:
76
- file_id = db.export_file_db(
77
- db_name, _io_handler.get_output_directory(), args_dict["file_name"]
74
+ file_id = db.export_model_files(
75
+ db_name=db_name,
76
+ dest=_io_handler.get_output_directory(),
77
+ file_names=args_dict["file_name"],
78
78
  )
79
79
  logger.info(
80
80
  f"Got file {args_dict['file_name']} from DB {db_name} "
@@ -84,11 +84,10 @@ def main(): # noqa: D103
84
84
  except FileNotFoundError:
85
85
  continue
86
86
 
87
- if file_id is None:
88
- logger.error(
89
- f"The file {args_dict['file_name']} was not found in any of the available DBs."
90
- )
91
- raise FileNotFoundError
87
+ for key, value in file_id.items():
88
+ if value is None:
89
+ logger.error(f"The file {key} was not found in any of the available DBs.")
90
+ raise FileNotFoundError
92
91
 
93
92
 
94
93
  if __name__ == "__main__":
@@ -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
 
@@ -73,7 +68,6 @@ def _parse():
73
68
  config.parser.add_argument(
74
69
  "--db_collection",
75
70
  help="DB collection to which to add the file",
76
- default="telescopes",
77
71
  required=False,
78
72
  )
79
73
  config.parser.add_argument(
@@ -83,7 +77,9 @@ def _parse():
83
77
  required=False,
84
78
  )
85
79
 
86
- return config.initialize(db_config=True, simulation_model="telescope")
80
+ return config.initialize(
81
+ db_config=True, simulation_model=["telescope", "parameter_version", "model_version"]
82
+ )
87
83
 
88
84
 
89
85
  def main(): # noqa: D103
@@ -94,37 +90,53 @@ def main(): # noqa: D103
94
90
 
95
91
  db = db_handler.DatabaseHandler(mongo_db_config=db_config)
96
92
 
97
- if args_dict["db_collection"] == "configuration_sim_telarray":
98
- pars = db.get_model_parameters(
99
- args_dict["site"],
100
- args_dict["telescope"],
101
- args_dict["model_version"],
102
- collection="configuration_sim_telarray",
103
- )
104
- elif args_dict["db_collection"] == "configuration_corsika":
105
- pars = db.get_corsika_configuration_parameters(args_dict["model_version"])
106
- elif args_dict["telescope"] is not None:
107
- pars = db.get_model_parameters(
108
- args_dict["site"],
109
- args_dict["telescope"],
110
- args_dict["model_version"],
111
- collection="telescopes",
93
+ # get parameter using 'parameter_version'
94
+ if args_dict["parameter_version"] is not None:
95
+ pars = db.get_model_parameter(
96
+ parameter=args_dict["parameter"],
97
+ parameter_version=args_dict["parameter_version"],
98
+ site=args_dict["site"],
99
+ array_element_name=args_dict["telescope"],
100
+ collection=(
101
+ args_dict["db_collection"] if args_dict.get("db_collection") else "telescopes"
102
+ ),
112
103
  )
104
+ # get parameter using 'model_version'
105
+ elif args_dict["model_version"] is not None:
106
+ if args_dict["telescope"]:
107
+ pars = db.get_model_parameters(
108
+ site=args_dict["site"],
109
+ array_element_name=args_dict["telescope"],
110
+ model_version=args_dict["model_version"],
111
+ collection=(
112
+ "configuration_sim_telarray"
113
+ if args_dict.get("db_collection") == "configuration_sim_telarray"
114
+ else "telescopes"
115
+ ),
116
+ )
117
+ else:
118
+ pars = db.get_model_parameters(
119
+ site=args_dict.get("site"),
120
+ model_version=args_dict["model_version"],
121
+ collection=(
122
+ args_dict["db_collection"] if args_dict.get("db_collection") else "sites"
123
+ ),
124
+ array_element_name=None,
125
+ )
113
126
  else:
114
- pars = db.get_site_parameters(args_dict["site"], args_dict["model_version"])
127
+ raise ValueError("Either 'parameter_version' or 'model_version' must be provided.")
115
128
  if args_dict["parameter"] not in pars:
116
129
  raise KeyError(f"The requested parameter, {args_dict['parameter']}, does not exist.")
117
130
  if args_dict["output_file"] is not None:
118
- _io_handler = io_handler.IOHandler()
131
+ _output_file = (
132
+ Path(io_handler.IOHandler().get_output_directory()) / args_dict["output_file"]
133
+ )
119
134
  pars[args_dict["parameter"]].pop("_id")
120
135
  pars[args_dict["parameter"]].pop("entry_date")
121
- _output_file = Path(_io_handler.get_output_directory()) / args_dict["output_file"]
122
136
  with open(_output_file, "w", encoding="utf-8") as json_file:
123
137
  json.dump(pars[args_dict["parameter"]], json_file, indent=4)
124
138
  else:
125
- print()
126
139
  pprint(pars[args_dict["parameter"]])
127
- print()
128
140
 
129
141
 
130
142
  if __name__ == "__main__":
@@ -178,6 +178,13 @@ def _parse(label):
178
178
  type=str,
179
179
  required=False,
180
180
  )
181
+ config.parser.add_argument(
182
+ "--rtol_psf_containment",
183
+ help="Relative tolerance for the containment diameter (default is 0.1).",
184
+ type=float,
185
+ required=False,
186
+ default=0.1,
187
+ )
181
188
  config.parser.add_argument(
182
189
  "--use_random_focal_length",
183
190
  help=("Use random focal lengths."),
@@ -200,7 +207,9 @@ def _parse(label):
200
207
  action="store_true",
201
208
  required=False,
202
209
  )
203
- return config.initialize(db_config=True, output=True, simulation_model="telescope")
210
+ return config.initialize(
211
+ db_config=True, output=True, simulation_model=["telescope", "model_version"]
212
+ )
204
213
 
205
214
 
206
215
  def main(): # noqa: D103