gammasimtools 0.5.1__py3-none-any.whl → 0.6.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. {gammasimtools-0.5.1.dist-info → gammasimtools-0.6.1.dist-info}/METADATA +80 -28
  2. gammasimtools-0.6.1.dist-info/RECORD +91 -0
  3. {gammasimtools-0.5.1.dist-info → gammasimtools-0.6.1.dist-info}/WHEEL +1 -1
  4. {gammasimtools-0.5.1.dist-info → gammasimtools-0.6.1.dist-info}/entry_points.txt +4 -2
  5. simtools/_version.py +14 -2
  6. simtools/applications/add_file_to_db.py +2 -1
  7. simtools/applications/compare_cumulative_psf.py +10 -15
  8. simtools/applications/db_development_tools/add_new_parameter_to_db.py +12 -6
  9. simtools/applications/derive_mirror_rnda.py +95 -71
  10. simtools/applications/generate_corsika_histograms.py +216 -131
  11. simtools/applications/generate_default_metadata.py +110 -0
  12. simtools/applications/generate_simtel_array_histograms.py +192 -0
  13. simtools/applications/get_file_from_db.py +1 -1
  14. simtools/applications/get_parameter.py +3 -3
  15. simtools/applications/make_regular_arrays.py +89 -93
  16. simtools/applications/{plot_layout_array.py → plot_array_layout.py} +15 -14
  17. simtools/applications/print_array_elements.py +81 -34
  18. simtools/applications/produce_array_config.py +2 -2
  19. simtools/applications/production.py +39 -5
  20. simtools/applications/sim_showers_for_trigger_rates.py +26 -30
  21. simtools/applications/simulate_prod.py +49 -107
  22. simtools/applications/submit_data_from_external.py +8 -10
  23. simtools/applications/tune_psf.py +16 -18
  24. simtools/applications/validate_camera_efficiency.py +63 -9
  25. simtools/applications/validate_camera_fov.py +9 -13
  26. simtools/applications/validate_file_using_schema.py +127 -0
  27. simtools/applications/validate_optics.py +13 -15
  28. simtools/camera_efficiency.py +73 -80
  29. simtools/configuration/commandline_parser.py +52 -22
  30. simtools/configuration/configurator.py +98 -33
  31. simtools/constants.py +9 -0
  32. simtools/corsika/corsika_config.py +28 -22
  33. simtools/corsika/corsika_default_config.py +282 -0
  34. simtools/corsika/corsika_histograms.py +328 -282
  35. simtools/corsika/corsika_histograms_visualize.py +162 -163
  36. simtools/corsika/corsika_runner.py +8 -4
  37. simtools/corsika_simtel/corsika_simtel_runner.py +18 -23
  38. simtools/data_model/data_reader.py +129 -0
  39. simtools/data_model/metadata_collector.py +346 -118
  40. simtools/data_model/metadata_model.py +123 -218
  41. simtools/data_model/model_data_writer.py +79 -22
  42. simtools/data_model/validate_data.py +96 -46
  43. simtools/db_handler.py +67 -42
  44. simtools/io_operations/__init__.py +0 -0
  45. simtools/io_operations/hdf5_handler.py +112 -0
  46. simtools/{io_handler.py → io_operations/io_handler.py} +51 -22
  47. simtools/job_execution/job_manager.py +1 -1
  48. simtools/layout/{layout_array.py → array_layout.py} +168 -199
  49. simtools/layout/geo_coordinates.py +196 -0
  50. simtools/layout/telescope_position.py +12 -12
  51. simtools/model/array_model.py +16 -14
  52. simtools/model/camera.py +5 -8
  53. simtools/model/mirrors.py +136 -73
  54. simtools/model/model_utils.py +1 -69
  55. simtools/model/telescope_model.py +32 -25
  56. simtools/psf_analysis.py +26 -19
  57. simtools/ray_tracing.py +54 -26
  58. simtools/schemas/data.metaschema.yml +400 -0
  59. simtools/schemas/metadata.metaschema.yml +566 -0
  60. simtools/simtel/simtel_config_writer.py +14 -5
  61. simtools/simtel/simtel_histograms.py +266 -83
  62. simtools/simtel/simtel_runner.py +8 -7
  63. simtools/simtel/simtel_runner_array.py +7 -8
  64. simtools/simtel/simtel_runner_camera_efficiency.py +48 -2
  65. simtools/simtel/simtel_runner_ray_tracing.py +61 -25
  66. simtools/simulator.py +43 -50
  67. simtools/utils/general.py +232 -286
  68. simtools/utils/geometry.py +163 -0
  69. simtools/utils/names.py +294 -142
  70. simtools/visualization/legend_handlers.py +115 -9
  71. simtools/visualization/visualize.py +13 -13
  72. gammasimtools-0.5.1.dist-info/RECORD +0 -83
  73. simtools/applications/plot_simtel_histograms.py +0 -120
  74. simtools/applications/validate_schema_files.py +0 -135
  75. simtools/corsika/corsika_output_visualize.py +0 -345
  76. simtools/data_model/validate_schema.py +0 -285
  77. {gammasimtools-0.5.1.dist-info → gammasimtools-0.6.1.dist-info}/LICENSE +0 -0
  78. {gammasimtools-0.5.1.dist-info → gammasimtools-0.6.1.dist-info}/top_level.txt +0 -0
@@ -3,43 +3,64 @@
3
3
  """
4
4
  Summary
5
5
  -------
6
- This application derives the parameter mirror_reflection_random_angle \
7
- (mirror roughness, also called rnda here) \
8
- for a given set of measured photon containment diameter (e.g. 80 percent containment) \
9
- of individual mirrors. The mean value of the measured containment diameters \
10
- in cm is required and its sigma can be given optionally but will only be used for plotting. \
11
-
12
- The individual mirror focal length can be taken into account if a mirror list which contains \
13
- this information is used from the :ref:`Model Parameters DB` or if a new mirror list is given \
14
- through the argument mirror_list. Random focal lengths can be used by turning on the argument \
15
- use_random_focal length and a new value for it can be given through the argument random_flen.
16
-
17
- The algorithm works as follow: A starting value of rnda is first defined as the one taken \
18
- from the :ref:`Model Parameters DB` \
19
- (or alternatively one may want to set it using the argument rnda).\
20
- Secondly, ray tracing simulations are performed for single mirror configurations for each \
21
- mirror given in the mirror_list. The mean simulated containment diameter for all the mirrors \
22
- is compared with the mean measured containment diameter. A new value of rnda is then defined \
23
- based on the sign of the difference between measured and simulated containment diameters and a \
24
- new set of simulations is performed. This process repeat until the sign of the \
25
- difference changes, meaning that the two final values of rnda brackets the optimal. These \
26
- two values are used to find the optimal one by a linear \
27
- interpolation. Finally, simulations are performed by using the the interpolated value \
28
- of rnda, which is defined as the desired optimal.
29
-
30
- A option no_tuning can be used if one only wants to simulate one value of rnda and compare \
31
- the results with the measured ones.
32
-
33
- The results of the tuning are plotted. See examples of the containment diameter \
34
- D80 vs rnda plot, on the left, and the D80 distributions, on the right.
35
-
36
- .. _deriva_rnda_plot:
6
+ Derive the simulation model parameter **mirror_reflection_random_angle**
7
+ (sometimes called mirror roughness) to match the measured containment diameter
8
+ of the optical point-spread function (PSF) of individual mirror panels.
9
+
10
+ Description
11
+ -----------
12
+
13
+ This application derives the value of the simulation model parameter
14
+ *mirror_reflection_random_angle* using measurements of the focal length
15
+ and PSF of individual mirror panels.
16
+
17
+ PSF measurements are provided by one of the following options:
18
+
19
+ * mean and sigma value obtained from the measurement of containment diameters of a number of
20
+ mirror panels in cm (``--psf_measurement_containment_mean`` and
21
+ ``--psf_measurement_containment_sigma``)
22
+ * file (table) with measured PSF for each mirror panel spot size (``--psf_measurement``)
23
+
24
+ The containment fraction used for the PSF diameter calculation is set through
25
+ the argument ``--containment_fraction`` (typically 0.8 = 80%).
26
+
27
+ Mirror panels are simulated individually, using one of the following options to set the
28
+ mirror panel focal length:
29
+
30
+ * file (table) with measured focal lengths per mirror panel
31
+ (provided through ``--mirror_list``)
32
+ * randomly generated focal lengths using an expected spread (value given through
33
+ ``--random_flen``) around the mean focal length (provided through the
34
+ :ref:`Model Parameters DB`). This option is switched with ``--use_random_flen``.
35
+
36
+ The tuning algorithm requires a starting value for the random reflection angle. This is either
37
+ taken from the :ref:`Model Parameters DB` (default) or can be set using the argument ``--rnda``.
38
+
39
+ Ray-tracing simulations are performed for single mirror configurations for each
40
+ mirror given in the mirror_list. The mean simulated containment diameter for all the mirrors
41
+ is compared with the mean measured containment diameter. The algorithm defines a new value for
42
+ the random reflection angle based on the sign of the difference between measured and simulated
43
+ containment diameters and a new set of simulations is performed. This process is repeated
44
+ until the sign of the difference changes, meaning that the two final values of the random
45
+ reflection angle brackets the optimal. These two values are used to find the optimal one by
46
+ a linear interpolation. Finally, simulations are performed by using the interpolated value,
47
+ which is defined as the desired optimal.
48
+
49
+ The option ``--no_tuning`` can be used if one only wants to simulate one value for the random
50
+ reflection angle and compare the results with the measured ones.
51
+
52
+ Results of the tuning are plotted. See examples of the PSF containment diameter
53
+ D80 vs random reflection angle plot, on the left, and the D80 distributions
54
+ (per mirror panel), on the right.
55
+
56
+ .. _derive_rnda_plot:
37
57
  .. image:: images/derive_mirror_rnda_North-MST-FlashCam-D.png
38
58
  :width: 49 %
39
59
  .. image:: images/derive_mirror_rnda_North-MST-FlashCam-D_D80-distributions.png
40
60
  :width: 49 %
41
61
 
42
- This application uses the following simulation software tools:
62
+ This application uses the following :ref:`SimulationSoftware` tools:
63
+
43
64
  - sim_telarray/bin/sim_telarray
44
65
  - sim_telarray/bin/rx (optional)
45
66
 
@@ -48,54 +69,53 @@
48
69
  telescope (str, required)
49
70
  Telescope name (e.g. North-LST-1, South-SST-D, ...)
50
71
  model_version (str, optional)
51
- Model version (default='Current')
72
+ Model version
52
73
  psf_measurement (str, optional)
53
- Results from PSF measurements for each mirror panel spot size
74
+ Table with results from PSF measurements for each mirror panel spot size
54
75
  psf_measurement_containment_mean (float, required)
55
76
  Mean of measured containment diameter [cm]
56
77
  psf_measurement_containment_sigma (float, optional)
57
78
  Std dev of measured containment diameter [cm]
58
79
  containment_fraction (float, required)
59
- Containment fraction for diameter calculation (typically 0.8)
80
+ Containment fraction for diameter calculation
60
81
  rnda (float, optional)
61
- Starting value of mirror_reflection_random_angle. If not given, the value from the \
62
- default model will be used.
82
+ Starting value of mirror_reflection_random_angle [deg]. If not given, the value from the
83
+ default model is read from the simulation model database.
63
84
  mirror_list (file, optional)
64
- Mirror list file to replace the default one. It should be used if measured mirror focal \
65
- lengths need to be taken into account. It contains the following information about the \
66
- mirrors: ID, panel radius, optical PSF (d80), PSF (d80) and surface reflectivity.
85
+ Table with mirror ID and panel radius.
67
86
  use_random_flen (activation mode, optional)
68
- Use random focal lengths, instead of the measured ones. The argument random_flen can be \
87
+ Use random focal lengths, instead of the measured ones. The argument random_flen can be
69
88
  used to replace the default random_focal_length from the model.
70
89
  random_flen (float, optional)
71
- Value of the random focal lengths to replace the default random_focal_length. Only used if \
90
+ Value of the random focal lengths to replace the default random_focal_length. Only used if
72
91
  use_random_flen is activated.
73
92
  no_tuning (activation mode, optional)
74
93
  Turn off the tuning - A single case will be simulated and plotted.
75
94
  test (activation mode, optional)
76
95
  If activated, application will be faster by simulating only few mirrors.
77
96
  verbosity (str, optional)
78
- Log level to print (default=INFO).
97
+ Log level to print.
79
98
 
80
99
  Example
81
100
  -------
82
- MST - Prod5
83
-
84
- Get mirror list and PSF data from DB:
85
-
86
- .. code-block:: console
87
-
88
- simtools-get-file-from-db --file_name MLTdata-preproduction.ecsv
89
-
90
- Run the application. Runtime about 4 min.
101
+ Derive mirror random reflection angle for a mid-sized telescope (MST),
102
+ simulation production Prod5.
91
103
 
92
104
  .. code-block:: console
93
105
 
94
- simtools-derive-mirror-rnda --site North --telescope MST-FlashCam-D \
95
- --containment_fraction 0.8 --mirror_list MLTdata-preproduction.ecsv
96
- --psf_measurement MLTdata-preproduction.ecsv --rnda 0.0063 --test
106
+ simtools-derive-mirror-rnda \\
107
+ --site North \\
108
+ --telescope MST-FlashCam-D \\
109
+ --containment_fraction 0.8 \\
110
+ --mirror_list MLTdata-preproduction.ecsv \\
111
+ --psf_measurement MLTdata-preproduction.ecsv \\
112
+ --rnda 0.0063 \\
113
+ --test
97
114
 
98
- The output is saved in simtools-output/derive_mirror_rnda.
115
+ Runtime about 4 min.
116
+
117
+ The output is saved in `simtools-output/derive_mirror_rnda`.
118
+ Use the parameter ``--output_path`` to change the output directory.
99
119
 
100
120
  Expected final print-out message:
101
121
 
@@ -111,11 +131,6 @@
111
131
  Previous value = 0.006300
112
132
  New value = 0.004975
113
133
 
114
-
115
- .. todo::
116
-
117
- * Change default model to default (after this feature is implemented in db_handler)
118
- * Fix the set_style. For some reason, sphinx cannot built docs with it on.
119
134
  """
120
135
 
121
136
  import logging
@@ -245,7 +260,7 @@ def _print_and_write_results(
245
260
  args_dict, rnda_start, rnda_opt, mean_d80, sig_d80, results_rnda, results_mean, results_sig
246
261
  ):
247
262
  """
248
- Print results to screen write metadata and data files
263
+ Print results to screen and write metadata and data files
249
264
  in the requested format
250
265
 
251
266
  """
@@ -287,12 +302,10 @@ def _print_and_write_results(
287
302
  f"containment_radius_sigma_D{containment_fraction_percent}",
288
303
  ),
289
304
  )
290
- file_writer = writer.ModelDataWriter(
291
- product_data_file=args_dict.get("output_file", None),
292
- product_data_format=args_dict.get("output_file_format", None),
293
- )
294
- file_writer.write(
295
- metadata=MetadataCollector(args_dict=args_dict).top_level_meta, product_data=result_table
305
+ writer.ModelDataWriter.dump(
306
+ args_dict=args_dict,
307
+ metadata=MetadataCollector(args_dict=args_dict).top_level_meta,
308
+ product_data=result_table,
296
309
  )
297
310
 
298
311
 
@@ -303,7 +316,9 @@ def _get_psf_containment(logger, args_dict):
303
316
 
304
317
  """
305
318
 
306
- _psf_list = Table.read(args_dict["psf_measurement"], format="ascii.ecsv")
319
+ # If this is a test, read just the first few lines since we only simulate those mirrors
320
+ data_end = args_dict["number_of_mirrors_to_test"] + 1 if args_dict["test"] else None
321
+ _psf_list = Table.read(args_dict["psf_measurement"], format="ascii.ecsv", data_end=data_end)
307
322
  try:
308
323
  args_dict["psf_measurement_containment_mean"] = np.nanmean(
309
324
  np.array(_psf_list["psf_opt"].to("cm").value)
@@ -333,6 +348,9 @@ def main():
333
348
 
334
349
  tel = _define_telescope_model(label, args_dict, db_config)
335
350
 
351
+ if args_dict["test"]:
352
+ args_dict["number_of_mirrors_to_test"] = 4
353
+
336
354
  if args_dict["psf_measurement"]:
337
355
  _get_psf_containment(logger, args_dict)
338
356
  if not args_dict["psf_measurement_containment_mean"]:
@@ -345,7 +363,9 @@ def main():
345
363
  ray = RayTracing.from_kwargs(
346
364
  telescope_model=tel,
347
365
  single_mirror_mode=True,
348
- mirror_numbers=list(range(1, 10)) if args_dict["test"] else "all",
366
+ mirror_numbers=list(range(1, args_dict["number_of_mirrors_to_test"] + 1))
367
+ if args_dict["test"]
368
+ else "all",
349
369
  simtel_source_path=args_dict.get("simtel_path", None),
350
370
  use_random_focal_length=args_dict["use_random_flen"],
351
371
  )
@@ -365,7 +385,7 @@ def main():
365
385
  if isinstance(rnda_start, str):
366
386
  rnda_start = float(rnda_start.split()[0])
367
387
 
368
- logger.info(f"Start value for mirror_reflection_random_angle: {rnda_start}")
388
+ logger.info(f"Start value for mirror_reflection_random_angle: {rnda_start} deg")
369
389
 
370
390
  results_rnda = []
371
391
  results_mean = []
@@ -386,6 +406,10 @@ def main():
386
406
  collect_results(rnda, mean_d80, sig_d80)
387
407
  while not stop:
388
408
  rnda = rnda - (0.1 * rnda_start * sign_delta)
409
+ if rnda < 0:
410
+ rnda = 0
411
+ collect_results(rnda, mean_d80, sig_d80)
412
+ break
389
413
  mean_d80, sig_d80 = run(rnda)
390
414
  new_sign_delta = np.sign(mean_d80 - args_dict["psf_measurement_containment_mean"])
391
415
  stop = new_sign_delta != sign_delta