gammasimtools 0.19.0__py3-none-any.whl → 0.21.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 (59) hide show
  1. {gammasimtools-0.19.0.dist-info → gammasimtools-0.21.0.dist-info}/METADATA +1 -3
  2. {gammasimtools-0.19.0.dist-info → gammasimtools-0.21.0.dist-info}/RECORD +54 -51
  3. {gammasimtools-0.19.0.dist-info → gammasimtools-0.21.0.dist-info}/entry_points.txt +3 -3
  4. simtools/_version.py +2 -2
  5. simtools/applications/calculate_incident_angles.py +182 -0
  6. simtools/applications/db_add_simulation_model_from_repository_to_db.py +17 -14
  7. simtools/applications/db_add_value_from_json_to_db.py +6 -9
  8. simtools/applications/db_generate_compound_indexes.py +7 -3
  9. simtools/applications/db_get_file_from_db.py +11 -23
  10. simtools/applications/derive_psf_parameters.py +58 -39
  11. simtools/applications/derive_trigger_rates.py +91 -0
  12. simtools/applications/generate_corsika_histograms.py +7 -184
  13. simtools/applications/maintain_simulation_model_add_production.py +105 -0
  14. simtools/applications/plot_simtel_events.py +5 -189
  15. simtools/applications/print_version.py +8 -7
  16. simtools/applications/validate_file_using_schema.py +7 -4
  17. simtools/configuration/commandline_parser.py +17 -11
  18. simtools/corsika/corsika_histograms.py +81 -0
  19. simtools/data_model/validate_data.py +8 -3
  20. simtools/db/db_handler.py +122 -31
  21. simtools/db/db_model_upload.py +51 -30
  22. simtools/dependencies.py +10 -5
  23. simtools/layout/array_layout_utils.py +37 -5
  24. simtools/model/array_model.py +18 -1
  25. simtools/model/model_repository.py +118 -63
  26. simtools/model/site_model.py +25 -0
  27. simtools/production_configuration/derive_corsika_limits.py +9 -34
  28. simtools/ray_tracing/incident_angles.py +706 -0
  29. simtools/ray_tracing/psf_parameter_optimisation.py +999 -565
  30. simtools/schemas/model_parameter_and_data_schema.metaschema.yml +2 -2
  31. simtools/schemas/model_parameters/nsb_reference_spectrum.schema.yml +1 -1
  32. simtools/schemas/model_parameters/nsb_spectrum.schema.yml +22 -29
  33. simtools/schemas/model_parameters/stars.schema.yml +1 -1
  34. simtools/schemas/production_tables.schema.yml +5 -0
  35. simtools/simtel/simtel_config_writer.py +18 -20
  36. simtools/simtel/simtel_io_event_histograms.py +253 -516
  37. simtools/simtel/simtel_io_event_reader.py +51 -2
  38. simtools/simtel/simtel_io_event_writer.py +31 -11
  39. simtools/simtel/simtel_io_metadata.py +1 -1
  40. simtools/simtel/simtel_table_reader.py +3 -3
  41. simtools/simulator.py +1 -4
  42. simtools/telescope_trigger_rates.py +119 -0
  43. simtools/testing/log_inspector.py +13 -11
  44. simtools/utils/geometry.py +20 -0
  45. simtools/version.py +89 -0
  46. simtools/{corsika/corsika_histograms_visualize.py → visualization/plot_corsika_histograms.py} +109 -0
  47. simtools/visualization/plot_incident_angles.py +431 -0
  48. simtools/visualization/plot_psf.py +673 -0
  49. simtools/visualization/plot_simtel_event_histograms.py +376 -0
  50. simtools/visualization/{simtel_event_plots.py → plot_simtel_events.py} +284 -87
  51. simtools/visualization/visualize.py +1 -3
  52. simtools/applications/calculate_trigger_rate.py +0 -187
  53. simtools/applications/generate_sim_telarray_histograms.py +0 -196
  54. simtools/applications/maintain_simulation_model_add_production_table.py +0 -71
  55. simtools/simtel/simtel_io_histogram.py +0 -623
  56. simtools/simtel/simtel_io_histograms.py +0 -556
  57. {gammasimtools-0.19.0.dist-info → gammasimtools-0.21.0.dist-info}/WHEEL +0 -0
  58. {gammasimtools-0.19.0.dist-info → gammasimtools-0.21.0.dist-info}/licenses/LICENSE +0 -0
  59. {gammasimtools-0.19.0.dist-info → gammasimtools-0.21.0.dist-info}/top_level.txt +0 -0
@@ -1,196 +0,0 @@
1
- #!/usr/bin/python3
2
-
3
- r"""
4
- Write sim_telarray histograms into pdf and hdf5 files.
5
-
6
- It accepts multiple lists of histograms files, a single list or a histogram file.
7
- Each histogram is plotted in a page of the pdf file if the --pdf option is activated.
8
-
9
-
10
- Command line arguments
11
- ----------------------
12
- hist_file_names (str, optional)
13
- Name of the histogram files to be plotted.
14
- It can be given as the histogram file names (more than one option allowed) or as a text
15
- file with the names of the histogram files in it.
16
- pdf (bool, optional)
17
- If set, histograms are saved into pdf files.
18
- One pdf file contains all the histograms found in the file.
19
- The name of the file is controlled via output_file_name.
20
- hdf5: bool
21
- If true, histograms are saved into hdf5 files.
22
- At least one of pdf and hdf5 has to be activated.
23
- output_file_name (str, optional)
24
- The name of the output hdf5 (and/or pdf) files (without the path).
25
- If not given, output_file_name takes the name from the (first) input file
26
- (hist_file_names).
27
- If the output output_file_name.hdf5 file already exists and hdf5 is set, the tables
28
- associated to hdf5 will be overwritten. The remaining tables, if any, will stay
29
- untouched.
30
- test: bool
31
- Test option. Generate only two histograms for testing purposes.
32
-
33
- Raises
34
- ------
35
- TypeError:
36
- if argument passed through hist_file_names is not a file.
37
-
38
- Example
39
- -------
40
- .. code-block:: console
41
-
42
- simtools-generate-sim-telarray-histograms --hist_file_names tests/resources/ \\
43
- run2_gamma_za20deg_azm0deg-North-Prod5_test-production-5.hdata.zst \\
44
- --output_file_name test_hist_hdata --hdf5 --pdf
45
-
46
- """
47
-
48
- import logging
49
- from pathlib import Path
50
-
51
- import matplotlib.pyplot as plt
52
- from matplotlib.backends.backend_pdf import PdfPages
53
-
54
- import simtools.utils.general as gen
55
- from simtools.configuration import configurator
56
- from simtools.io import io_handler
57
- from simtools.simtel.simtel_io_histograms import SimtelIOHistograms
58
-
59
-
60
- def _parse(label, description):
61
- """
62
- Parse command line configuration.
63
-
64
- Parameters
65
- ----------
66
- label: str
67
- Label describing the application.
68
- description: str
69
- Description of the application.
70
-
71
- Returns
72
- -------
73
- CommandLineParser
74
- Command line parser object
75
-
76
- """
77
- config = configurator.Configurator(label=label, description=description)
78
-
79
- config.parser.add_argument(
80
- "--hist_file_names",
81
- help="Name of the histogram files to be plotted or the text file containing the list of "
82
- "histogram files.",
83
- nargs="+",
84
- required=True,
85
- type=str,
86
- )
87
-
88
- config.parser.add_argument(
89
- "--hdf5", help="Save histograms into a hdf5 file.", action="store_true", required=False
90
- )
91
-
92
- config.parser.add_argument(
93
- "--pdf", help="Save histograms into a pdf file.", action="store_true", required=False
94
- )
95
-
96
- config.parser.add_argument(
97
- "--output_file_name",
98
- help="Name of the hdf5 (and/or pdf) file where to save the histograms.",
99
- type=str,
100
- required=False,
101
- default=None,
102
- )
103
-
104
- config_parser, _ = config.initialize(db_config=False, paths=True)
105
- if not config_parser["pdf"] and not config_parser["hdf5"]:
106
- config.parser.error("At least one argument is required: --pdf or --hdf5.")
107
-
108
- return config_parser
109
-
110
-
111
- def check_and_log_overwrite(config_parser, logger):
112
- """
113
- Check if the output hdf5 file already exists and log a warning if it does.
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
- bool
125
- True if the hdf5 file exists and should be overwritten.
126
- """
127
- if Path(f"{config_parser['output_file_name']}.hdf5").exists() and config_parser["hdf5"]:
128
- msg = (
129
- f"Output hdf5 file {config_parser['output_file_name']}.hdf5 already exists. "
130
- f"Overwriting it."
131
- )
132
- logger.warning(msg)
133
- return True
134
- return False
135
-
136
-
137
- def create_pdf(simtel_histograms, output_file_name, config_parser, logger):
138
- """
139
- Create a PDF file containing histograms.
140
-
141
- Parameters
142
- ----------
143
- simtel_histograms: SimtelIOHistograms
144
- SimtelIOHistograms object containing histograms to plot.
145
- output_file_name: str
146
- Base name for the output PDF file.
147
- config_parser: dict
148
- Parsed command line arguments.
149
- logger: logging.Logger
150
- Logger object for logging messages.
151
- """
152
- if config_parser["pdf"]:
153
- logger.debug(f"Creating the pdf file {output_file_name}.pdf")
154
- pdf_pages = PdfPages(f"{output_file_name}.pdf")
155
- number_of_histograms = 2 if config_parser["test"] else len(simtel_histograms.combined_hists)
156
- for i_hist in range(number_of_histograms):
157
- logger.debug(f"Processing: {i_hist + 1} histogram.")
158
- fig, ax = plt.subplots(1, 1, figsize=(6, 6))
159
- simtel_histograms.plot_one_histogram(i_hist, ax)
160
- plt.tight_layout()
161
- pdf_pages.savefig(fig)
162
- plt.clf()
163
- plt.close()
164
- pdf_pages.close()
165
- logger.info(f"Wrote histograms to the pdf file {output_file_name}.pdf")
166
-
167
-
168
- def main(): # noqa: D103
169
- label = Path(__file__).stem
170
- description = "Display sim_telarray histograms and/or write them into hdf5 format."
171
- io_handler_instance = io_handler.IOHandler()
172
- config_parser = _parse(label, description)
173
- output_path = io_handler_instance.get_output_directory(label, sub_dir="application-plots")
174
- logger = logging.getLogger()
175
- logger.setLevel(gen.get_log_level_from_user(config_parser["log_level"]))
176
-
177
- histogram_files = gen.get_list_of_files_from_command_line(
178
- config_parser["hist_file_names"], [".zst", ".simtel", ".hdata"]
179
- )
180
-
181
- # If no output name is passed, the tool gets the name of the first histogram of the list
182
- if config_parser["output_file_name"] is None:
183
- config_parser["output_file_name"] = Path(histogram_files[0]).absolute().name
184
- output_file_name = Path(output_path).joinpath(f"{config_parser['output_file_name']}")
185
-
186
- simtel_histograms = SimtelIOHistograms(histogram_files)
187
- create_pdf(simtel_histograms, output_file_name, 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
- )
193
-
194
-
195
- if __name__ == "__main__":
196
- main()
@@ -1,71 +0,0 @@
1
- r"""
2
- Generate new simulation model production tables by copying existing table and apply modifications.
3
-
4
- This script should be used to maintain the simulation model repository. It allow to create a
5
- new production table by copying an existing base version and apply modification defined in a YAML
6
- file (see the example file listed below).
7
-
8
- Example
9
- -------
10
- .. code-block:: console
11
-
12
- simtools-maintain-simulation-model-add-production-table \\
13
- --simulation_models_path ../simulation-models-dev/simulation-models/ \\
14
- --source_prod_table_dir 6.0.0 \\
15
- --modifications tests/resources/production_tables_changes_for_threshold_study_6.2.0.yml
16
-
17
- """
18
-
19
- import logging
20
- from pathlib import Path
21
-
22
- import simtools.utils.general as gen
23
- from simtools.configuration import configurator
24
- from simtools.model import model_repository
25
-
26
-
27
- def _parse(label, description):
28
- """
29
- Parse command line arguments.
30
-
31
- Returns
32
- -------
33
- dict
34
- Parsed command-line arguments.
35
- """
36
- config = configurator.Configurator(label=label, description=description)
37
- config.parser.add_argument(
38
- "--simulation_models_path",
39
- type=str,
40
- required=True,
41
- help="Path to the simulation models repository.",
42
- )
43
- config.parser.add_argument(
44
- "--source_prod_table_dir",
45
- type=str,
46
- required=True,
47
- help="The source production table directory to copy from.",
48
- )
49
- config.parser.add_argument(
50
- "--modifications",
51
- type=str,
52
- required=True,
53
- help="File containing the list of changes to apply.",
54
- )
55
-
56
- return config.initialize(db_config=False, output=False)
57
-
58
-
59
- def main(): # noqa: D103
60
- label = Path(__file__).stem
61
- args_dict, _ = _parse(
62
- label=label, description=("Copy and update simulation model production tables.")
63
- )
64
- logger = logging.getLogger()
65
- logger.setLevel(gen.get_log_level_from_user(args_dict["log_level"]))
66
-
67
- model_repository.copy_and_update_production_table(args_dict)
68
-
69
-
70
- if __name__ == "__main__":
71
- main()