gammasimtools 0.19.0__py3-none-any.whl → 0.20.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 (47) hide show
  1. {gammasimtools-0.19.0.dist-info → gammasimtools-0.20.0.dist-info}/METADATA +1 -3
  2. {gammasimtools-0.19.0.dist-info → gammasimtools-0.20.0.dist-info}/RECORD +43 -41
  3. {gammasimtools-0.19.0.dist-info → gammasimtools-0.20.0.dist-info}/entry_points.txt +2 -2
  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_trigger_rates.py +91 -0
  11. simtools/applications/plot_simtel_events.py +73 -31
  12. simtools/applications/validate_file_using_schema.py +7 -4
  13. simtools/configuration/commandline_parser.py +17 -11
  14. simtools/data_model/validate_data.py +8 -3
  15. simtools/db/db_handler.py +83 -26
  16. simtools/db/db_model_upload.py +11 -16
  17. simtools/dependencies.py +10 -5
  18. simtools/layout/array_layout_utils.py +37 -5
  19. simtools/model/array_model.py +18 -1
  20. simtools/model/site_model.py +25 -0
  21. simtools/production_configuration/derive_corsika_limits.py +9 -34
  22. simtools/ray_tracing/incident_angles.py +706 -0
  23. simtools/schemas/model_parameter_and_data_schema.metaschema.yml +2 -2
  24. simtools/schemas/model_parameters/nsb_reference_spectrum.schema.yml +1 -1
  25. simtools/schemas/model_parameters/nsb_spectrum.schema.yml +22 -29
  26. simtools/schemas/model_parameters/stars.schema.yml +1 -1
  27. simtools/schemas/production_tables.schema.yml +5 -0
  28. simtools/simtel/simtel_config_writer.py +17 -19
  29. simtools/simtel/simtel_io_event_histograms.py +253 -516
  30. simtools/simtel/simtel_io_event_reader.py +51 -2
  31. simtools/simtel/simtel_io_event_writer.py +31 -11
  32. simtools/simtel/simtel_io_metadata.py +1 -1
  33. simtools/simtel/simtel_table_reader.py +3 -3
  34. simtools/telescope_trigger_rates.py +119 -0
  35. simtools/testing/log_inspector.py +13 -11
  36. simtools/utils/geometry.py +20 -0
  37. simtools/visualization/plot_incident_angles.py +431 -0
  38. simtools/visualization/plot_simtel_event_histograms.py +376 -0
  39. simtools/visualization/visualize.py +1 -3
  40. simtools/applications/calculate_trigger_rate.py +0 -187
  41. simtools/applications/generate_sim_telarray_histograms.py +0 -196
  42. simtools/simtel/simtel_io_histogram.py +0 -623
  43. simtools/simtel/simtel_io_histograms.py +0 -556
  44. {gammasimtools-0.19.0.dist-info → gammasimtools-0.20.0.dist-info}/WHEEL +0 -0
  45. {gammasimtools-0.19.0.dist-info → gammasimtools-0.20.0.dist-info}/licenses/LICENSE +0 -0
  46. {gammasimtools-0.19.0.dist-info → gammasimtools-0.20.0.dist-info}/top_level.txt +0 -0
  47. /simtools/visualization/{simtel_event_plots.py → plot_simtel_events.py} +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()