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.
- {gammasimtools-0.5.1.dist-info → gammasimtools-0.6.1.dist-info}/METADATA +80 -28
- gammasimtools-0.6.1.dist-info/RECORD +91 -0
- {gammasimtools-0.5.1.dist-info → gammasimtools-0.6.1.dist-info}/WHEEL +1 -1
- {gammasimtools-0.5.1.dist-info → gammasimtools-0.6.1.dist-info}/entry_points.txt +4 -2
- simtools/_version.py +14 -2
- simtools/applications/add_file_to_db.py +2 -1
- simtools/applications/compare_cumulative_psf.py +10 -15
- simtools/applications/db_development_tools/add_new_parameter_to_db.py +12 -6
- simtools/applications/derive_mirror_rnda.py +95 -71
- simtools/applications/generate_corsika_histograms.py +216 -131
- simtools/applications/generate_default_metadata.py +110 -0
- simtools/applications/generate_simtel_array_histograms.py +192 -0
- simtools/applications/get_file_from_db.py +1 -1
- simtools/applications/get_parameter.py +3 -3
- simtools/applications/make_regular_arrays.py +89 -93
- simtools/applications/{plot_layout_array.py → plot_array_layout.py} +15 -14
- simtools/applications/print_array_elements.py +81 -34
- simtools/applications/produce_array_config.py +2 -2
- simtools/applications/production.py +39 -5
- simtools/applications/sim_showers_for_trigger_rates.py +26 -30
- simtools/applications/simulate_prod.py +49 -107
- simtools/applications/submit_data_from_external.py +8 -10
- simtools/applications/tune_psf.py +16 -18
- simtools/applications/validate_camera_efficiency.py +63 -9
- simtools/applications/validate_camera_fov.py +9 -13
- simtools/applications/validate_file_using_schema.py +127 -0
- simtools/applications/validate_optics.py +13 -15
- simtools/camera_efficiency.py +73 -80
- simtools/configuration/commandline_parser.py +52 -22
- simtools/configuration/configurator.py +98 -33
- simtools/constants.py +9 -0
- simtools/corsika/corsika_config.py +28 -22
- simtools/corsika/corsika_default_config.py +282 -0
- simtools/corsika/corsika_histograms.py +328 -282
- simtools/corsika/corsika_histograms_visualize.py +162 -163
- simtools/corsika/corsika_runner.py +8 -4
- simtools/corsika_simtel/corsika_simtel_runner.py +18 -23
- simtools/data_model/data_reader.py +129 -0
- simtools/data_model/metadata_collector.py +346 -118
- simtools/data_model/metadata_model.py +123 -218
- simtools/data_model/model_data_writer.py +79 -22
- simtools/data_model/validate_data.py +96 -46
- simtools/db_handler.py +67 -42
- simtools/io_operations/__init__.py +0 -0
- simtools/io_operations/hdf5_handler.py +112 -0
- simtools/{io_handler.py → io_operations/io_handler.py} +51 -22
- simtools/job_execution/job_manager.py +1 -1
- simtools/layout/{layout_array.py → array_layout.py} +168 -199
- simtools/layout/geo_coordinates.py +196 -0
- simtools/layout/telescope_position.py +12 -12
- simtools/model/array_model.py +16 -14
- simtools/model/camera.py +5 -8
- simtools/model/mirrors.py +136 -73
- simtools/model/model_utils.py +1 -69
- simtools/model/telescope_model.py +32 -25
- simtools/psf_analysis.py +26 -19
- simtools/ray_tracing.py +54 -26
- simtools/schemas/data.metaschema.yml +400 -0
- simtools/schemas/metadata.metaschema.yml +566 -0
- simtools/simtel/simtel_config_writer.py +14 -5
- simtools/simtel/simtel_histograms.py +266 -83
- simtools/simtel/simtel_runner.py +8 -7
- simtools/simtel/simtel_runner_array.py +7 -8
- simtools/simtel/simtel_runner_camera_efficiency.py +48 -2
- simtools/simtel/simtel_runner_ray_tracing.py +61 -25
- simtools/simulator.py +43 -50
- simtools/utils/general.py +232 -286
- simtools/utils/geometry.py +163 -0
- simtools/utils/names.py +294 -142
- simtools/visualization/legend_handlers.py +115 -9
- simtools/visualization/visualize.py +13 -13
- gammasimtools-0.5.1.dist-info/RECORD +0 -83
- simtools/applications/plot_simtel_histograms.py +0 -120
- simtools/applications/validate_schema_files.py +0 -135
- simtools/corsika/corsika_output_visualize.py +0 -345
- simtools/data_model/validate_schema.py +0 -285
- {gammasimtools-0.5.1.dist-info → gammasimtools-0.6.1.dist-info}/LICENSE +0 -0
- {gammasimtools-0.5.1.dist-info → gammasimtools-0.6.1.dist-info}/top_level.txt +0 -0
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
Submit model parameter (value, table) through the command line.
|
|
6
6
|
|
|
7
7
|
Input data and metadata is validated, and if necessary enriched
|
|
8
|
-
and converted following a
|
|
8
|
+
and converted following a pre-described schema.
|
|
9
9
|
|
|
10
10
|
Command line arguments
|
|
11
11
|
----------------------
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
|
|
34
34
|
.. code-block:: console
|
|
35
35
|
|
|
36
|
-
INFO::model_data_writer(l70)::write_data::Writing data to\
|
|
36
|
+
INFO::model_data_writer(l70)::write_data::Writing data to \
|
|
37
37
|
/simtools/simtools-output/d-2023-07-31/TEST-submit_data_from_external.ecsv
|
|
38
38
|
|
|
39
39
|
"""
|
|
@@ -78,7 +78,7 @@ def _parse(label, description):
|
|
|
78
78
|
"--input",
|
|
79
79
|
help="input data file",
|
|
80
80
|
type=str,
|
|
81
|
-
required=
|
|
81
|
+
required=True,
|
|
82
82
|
)
|
|
83
83
|
config.parser.add_argument(
|
|
84
84
|
"--schema",
|
|
@@ -101,16 +101,14 @@ def main():
|
|
|
101
101
|
_metadata = MetadataCollector(args_dict=args_dict)
|
|
102
102
|
|
|
103
103
|
data_validator = validate_data.DataValidator(
|
|
104
|
-
schema_file=
|
|
104
|
+
schema_file=_metadata.get_data_model_schema_file_name(),
|
|
105
105
|
data_file=args_dict["input"],
|
|
106
106
|
)
|
|
107
107
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
file_writer.write(
|
|
113
|
-
metadata=_metadata.top_level_meta, product_data=data_validator.validate_and_transform()
|
|
108
|
+
writer.ModelDataWriter.dump(
|
|
109
|
+
args_dict=args_dict,
|
|
110
|
+
metadata=_metadata.top_level_meta,
|
|
111
|
+
product_data=data_validator.validate_and_transform(),
|
|
114
112
|
)
|
|
115
113
|
|
|
116
114
|
|
|
@@ -37,11 +37,11 @@
|
|
|
37
37
|
telescope (str, required)
|
|
38
38
|
Telescope model name (e.g. LST-1, SST-D, ...).
|
|
39
39
|
model_version (str, optional)
|
|
40
|
-
Model version
|
|
40
|
+
Model version.
|
|
41
41
|
src_distance (float, optional)
|
|
42
|
-
Source distance in km
|
|
42
|
+
Source distance in km.
|
|
43
43
|
zenith (float, optional)
|
|
44
|
-
Zenith angle in deg
|
|
44
|
+
Zenith angle in deg.
|
|
45
45
|
data (str, optional)
|
|
46
46
|
Name of the data file with the measured cumulative PSF.
|
|
47
47
|
plot_all (activation mode, optional)
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
test (activation mode, optional)
|
|
52
52
|
If activated, application will be faster by simulating fewer photons.
|
|
53
53
|
verbosity (str, optional)
|
|
54
|
-
Log level to print
|
|
54
|
+
Log level to print.
|
|
55
55
|
|
|
56
56
|
Example
|
|
57
57
|
-------
|
|
@@ -94,8 +94,8 @@ import numpy as np
|
|
|
94
94
|
from matplotlib.backends.backend_pdf import PdfPages
|
|
95
95
|
|
|
96
96
|
import simtools.utils.general as gen
|
|
97
|
-
from simtools import io_handler
|
|
98
97
|
from simtools.configuration import configurator
|
|
98
|
+
from simtools.io_operations import io_handler
|
|
99
99
|
from simtools.model.model_utils import split_simtel_parameter
|
|
100
100
|
from simtools.model.telescope_model import TelescopeModel
|
|
101
101
|
from simtools.ray_tracing import RayTracing
|
|
@@ -127,13 +127,11 @@ def main():
|
|
|
127
127
|
)
|
|
128
128
|
config.parser.add_argument(
|
|
129
129
|
"--src_distance",
|
|
130
|
-
help="Source distance in km
|
|
130
|
+
help="Source distance in km",
|
|
131
131
|
type=float,
|
|
132
132
|
default=10,
|
|
133
133
|
)
|
|
134
|
-
config.parser.add_argument(
|
|
135
|
-
"--zenith", help="Zenith angle in deg (default=20)", type=float, default=20
|
|
136
|
-
)
|
|
134
|
+
config.parser.add_argument("--zenith", help="Zenith angle in deg", type=float, default=20)
|
|
137
135
|
config.parser.add_argument(
|
|
138
136
|
"--data", help="Data file name with the measured PSF vs radius [cm]", type=str
|
|
139
137
|
)
|
|
@@ -159,7 +157,7 @@ def main():
|
|
|
159
157
|
|
|
160
158
|
# Output directory to save files related directly to this app
|
|
161
159
|
_io_handler = io_handler.IOHandler()
|
|
162
|
-
output_dir = _io_handler.get_output_directory(label,
|
|
160
|
+
output_dir = _io_handler.get_output_directory(label, sub_dir="application-plots")
|
|
163
161
|
|
|
164
162
|
tel_model = TelescopeModel(
|
|
165
163
|
site=args_dict["site"],
|
|
@@ -211,11 +209,11 @@ def main():
|
|
|
211
209
|
mar_0 = split_simtel_parameter(raw_par)[0]
|
|
212
210
|
|
|
213
211
|
logger.debug(
|
|
214
|
-
"Previous parameter values
|
|
215
|
-
"MRRA =
|
|
216
|
-
"MRF =
|
|
217
|
-
"MRRA2 =
|
|
218
|
-
"MAR =
|
|
212
|
+
"Previous parameter values:\n"
|
|
213
|
+
f"MRRA = {str(mrra_0)}\n"
|
|
214
|
+
f"MRF = {str(mfr_0)}\n"
|
|
215
|
+
f"MRRA2 = {str(mrra2_0)}\n"
|
|
216
|
+
f"MAR = {str(mar_0)}\n"
|
|
219
217
|
)
|
|
220
218
|
|
|
221
219
|
if args_dict["fixed"]:
|
|
@@ -224,8 +222,8 @@ def main():
|
|
|
224
222
|
# Drawing parameters randonly
|
|
225
223
|
# Range around the previous values are hardcoded
|
|
226
224
|
# Number of runs is hardcoded
|
|
227
|
-
|
|
228
|
-
for _ in range(
|
|
225
|
+
n_runs = 50
|
|
226
|
+
for _ in range(n_runs):
|
|
229
227
|
mrra_range = 0.004 if not args_dict["fixed"] else 0
|
|
230
228
|
mrf_range = 0.1
|
|
231
229
|
mrra2_range = 0.03
|
|
@@ -285,7 +283,7 @@ def main():
|
|
|
285
283
|
)
|
|
286
284
|
|
|
287
285
|
if plot:
|
|
288
|
-
fig = visualize.
|
|
286
|
+
fig = visualize.plot_1d(
|
|
289
287
|
data_to_plot,
|
|
290
288
|
plot_difference=True,
|
|
291
289
|
no_markers=True,
|
|
@@ -22,9 +22,21 @@
|
|
|
22
22
|
telescope (str, required)
|
|
23
23
|
Telescope model name (e.g. LST-1, SST-D, ...)
|
|
24
24
|
model_version (str, optional)
|
|
25
|
-
Model version (default='
|
|
25
|
+
Model version (default='Released')
|
|
26
|
+
zenith_angle (float, optional)
|
|
27
|
+
Zenith angle in degrees (between 0 and 180).
|
|
28
|
+
azimuth_angle (float, optional)
|
|
29
|
+
Telescope pointing direction in azimuth. It can be in degrees between 0 and 360 or
|
|
30
|
+
one of north, south, east or west (case insensitive). Note that North is 0 degrees
|
|
31
|
+
and the azimuth grows clockwise, so East is 90 degrees.
|
|
32
|
+
nsb_spectrum (str, optional)
|
|
33
|
+
File with NSB spectrum to use for the efficiency simulation.
|
|
34
|
+
The expected format is two columns with wavelength in nm and
|
|
35
|
+
NSB flux with the units: [1e9 * ph/m2/s/sr/nm].
|
|
36
|
+
If the file has more than two columns, the first and third are used,
|
|
37
|
+
and the second is ignored (native sim_telarray behaviour).
|
|
26
38
|
verbosity (str, optional)
|
|
27
|
-
Log level to print
|
|
39
|
+
Log level to print
|
|
28
40
|
|
|
29
41
|
Example
|
|
30
42
|
-------
|
|
@@ -35,6 +47,8 @@
|
|
|
35
47
|
.. code-block:: console
|
|
36
48
|
|
|
37
49
|
simtools-validate-camera-efficiency --site North \
|
|
50
|
+
--azimuth_angle 0 --zenith_angle 20 \
|
|
51
|
+
--nsb_spectrum average_nsb_spectrum_CTAO-N_ze20_az0.txt \
|
|
38
52
|
--telescope MST-NectarCam-D --model_version prod5
|
|
39
53
|
|
|
40
54
|
The output is saved in simtools-output/validate_camera_efficiency.
|
|
@@ -47,19 +61,16 @@
|
|
|
47
61
|
simtools/simtools-output/validate_camera_efficiency/application-plots/validate_camera\
|
|
48
62
|
_efficiency_MST-NectarCam-D_nsb
|
|
49
63
|
|
|
50
|
-
.. todo::
|
|
51
|
-
|
|
52
|
-
* Change default model to default (after this feature is implemented in db_handler)
|
|
53
|
-
* Fix the set_style. For some reason, sphinx cannot built docs with it on.
|
|
54
64
|
"""
|
|
55
65
|
|
|
56
66
|
import logging
|
|
57
67
|
from pathlib import Path
|
|
58
68
|
|
|
59
69
|
import simtools.utils.general as gen
|
|
60
|
-
from simtools import io_handler
|
|
61
70
|
from simtools.camera_efficiency import CameraEfficiency
|
|
62
71
|
from simtools.configuration import configurator
|
|
72
|
+
from simtools.configuration.commandline_parser import CommandLineParser
|
|
73
|
+
from simtools.io_operations import io_handler
|
|
63
74
|
from simtools.model.telescope_model import TelescopeModel
|
|
64
75
|
|
|
65
76
|
|
|
@@ -75,7 +86,44 @@ def _parse(label):
|
|
|
75
86
|
"Plot the camera efficiency vs wavelength for cherenkov and NSB light."
|
|
76
87
|
),
|
|
77
88
|
)
|
|
78
|
-
|
|
89
|
+
config.parser.add_argument(
|
|
90
|
+
"--azimuth_angle",
|
|
91
|
+
help=(
|
|
92
|
+
"Telescope pointing direction in azimuth. "
|
|
93
|
+
"It can be in degrees between 0 and 360 or one of north, south, east or west "
|
|
94
|
+
"(case insensitive). Note that North is 0 degrees and "
|
|
95
|
+
"the azimuth grows clockwise, so East is 90 degrees."
|
|
96
|
+
),
|
|
97
|
+
type=CommandLineParser.azimuth_angle,
|
|
98
|
+
default=0,
|
|
99
|
+
required=False,
|
|
100
|
+
)
|
|
101
|
+
config.parser.add_argument(
|
|
102
|
+
"--zenith_angle",
|
|
103
|
+
help="Zenith angle in degrees (between 0 and 180).",
|
|
104
|
+
type=CommandLineParser.zenith_angle,
|
|
105
|
+
default=20,
|
|
106
|
+
required=False,
|
|
107
|
+
)
|
|
108
|
+
config.parser.add_argument(
|
|
109
|
+
"--nsb_spectrum",
|
|
110
|
+
help=(
|
|
111
|
+
"File with NSB spectrum to use for the efficiency simulation."
|
|
112
|
+
"The expected format is two columns with wavelength in nm and "
|
|
113
|
+
"NSB flux with the units: [1e9 * ph/m2/s/sr/nm]."
|
|
114
|
+
"If the file has more than two columns, the first and third are used,"
|
|
115
|
+
"and the second is ignored (native sim_telarray behaviour)."
|
|
116
|
+
),
|
|
117
|
+
type=str,
|
|
118
|
+
default=None,
|
|
119
|
+
required=False,
|
|
120
|
+
)
|
|
121
|
+
_args_dict, _db_config = config.initialize(db_config=True, telescope_model=True)
|
|
122
|
+
if _args_dict["site"] is None or _args_dict["telescope"] is None:
|
|
123
|
+
config.parser.print_help()
|
|
124
|
+
print("\n\nSite and telescope must be provided\n\n")
|
|
125
|
+
raise RuntimeError("Site and telescope must be provided")
|
|
126
|
+
return _args_dict, _db_config
|
|
79
127
|
|
|
80
128
|
|
|
81
129
|
def main():
|
|
@@ -87,7 +135,7 @@ def main():
|
|
|
87
135
|
|
|
88
136
|
# Output directory to save files related directly to this app
|
|
89
137
|
_io_handler = io_handler.IOHandler()
|
|
90
|
-
output_dir = _io_handler.get_output_directory(label,
|
|
138
|
+
output_dir = _io_handler.get_output_directory(label, sub_dir="application-plots")
|
|
91
139
|
|
|
92
140
|
tel_model = TelescopeModel(
|
|
93
141
|
site=args_dict["site"],
|
|
@@ -105,6 +153,12 @@ def main():
|
|
|
105
153
|
ce = CameraEfficiency(
|
|
106
154
|
telescope_model=tel_model,
|
|
107
155
|
simtel_source_path=args_dict["simtel_path"],
|
|
156
|
+
label=label,
|
|
157
|
+
config_data={
|
|
158
|
+
"zenith_angle": args_dict["zenith_angle"],
|
|
159
|
+
"azimuth_angle": args_dict["azimuth_angle"],
|
|
160
|
+
"nsb_spectrum": args_dict["nsb_spectrum"],
|
|
161
|
+
},
|
|
108
162
|
)
|
|
109
163
|
ce.simulate(force=True)
|
|
110
164
|
ce.analyze(force=True)
|
|
@@ -20,16 +20,16 @@
|
|
|
20
20
|
telescope (str, required)
|
|
21
21
|
Telescope model name (e.g. LST-1, SST-D, ...)
|
|
22
22
|
model_version (str, optional)
|
|
23
|
-
Model version
|
|
23
|
+
Model version
|
|
24
24
|
camera_in_sky_coor (bool, optional)
|
|
25
25
|
Plot the camera layout in sky coordinates akin to looking at it from behind for single \
|
|
26
|
-
mirror telescopes
|
|
26
|
+
mirror telescopes
|
|
27
27
|
print_pixels_id (bool, optional)
|
|
28
|
-
Up to which pixel ID to print
|
|
28
|
+
Up to which pixel ID to print. To suppress printing of pixel IDs, set to zero\
|
|
29
29
|
(--print_pixels_id 0). To print all pixels, set to 'All'."
|
|
30
30
|
|
|
31
31
|
verbosity (str, optional)
|
|
32
|
-
Log level to print
|
|
32
|
+
Log level to print
|
|
33
33
|
|
|
34
34
|
Example
|
|
35
35
|
-------
|
|
@@ -49,18 +49,14 @@
|
|
|
49
49
|
Saved camera plot in /workdir/external/simtools/simtools-output/validate_camera_fov\
|
|
50
50
|
/application-plots/validate_camera_fov_LST-1_pixel_layout.png
|
|
51
51
|
|
|
52
|
-
.. todo::
|
|
53
|
-
|
|
54
|
-
* Change default model to default (after this feature is implemented in db_handler)
|
|
55
|
-
* Fix the set_style. For some reason, sphinx cannot built docs with it on.
|
|
56
52
|
"""
|
|
57
53
|
|
|
58
54
|
import logging
|
|
59
55
|
from pathlib import Path
|
|
60
56
|
|
|
61
57
|
import simtools.utils.general as gen
|
|
62
|
-
from simtools import io_handler
|
|
63
58
|
from simtools.configuration import configurator
|
|
59
|
+
from simtools.io_operations import io_handler
|
|
64
60
|
from simtools.model.telescope_model import TelescopeModel
|
|
65
61
|
|
|
66
62
|
|
|
@@ -84,7 +80,7 @@ def main():
|
|
|
84
80
|
config.parser.add_argument(
|
|
85
81
|
"--print_pixels_id",
|
|
86
82
|
help=(
|
|
87
|
-
"Up to which pixel ID to print
|
|
83
|
+
"Up to which pixel ID to print. "
|
|
88
84
|
"To suppress printing of pixel IDs, set to zero (--print_pixels_id 0). "
|
|
89
85
|
"To print all pixels, set to 'All'."
|
|
90
86
|
),
|
|
@@ -99,7 +95,7 @@ def main():
|
|
|
99
95
|
|
|
100
96
|
# Output directory to save files related directly to this app
|
|
101
97
|
_io_handler = io_handler.IOHandler()
|
|
102
|
-
output_dir = _io_handler.get_output_directory(label,
|
|
98
|
+
output_dir = _io_handler.get_output_directory(label, sub_dir="application-plots")
|
|
103
99
|
|
|
104
100
|
tel_model = TelescopeModel(
|
|
105
101
|
site=args_dict["site"],
|
|
@@ -126,14 +122,14 @@ def main():
|
|
|
126
122
|
pixel_ids_to_print = int(args_dict["print_pixels_id"])
|
|
127
123
|
if pixel_ids_to_print == 0:
|
|
128
124
|
pixel_ids_to_print = -1 # so not print the zero pixel
|
|
129
|
-
except ValueError:
|
|
125
|
+
except ValueError as exc:
|
|
130
126
|
if args_dict["print_pixels_id"].lower() == "all":
|
|
131
127
|
pixel_ids_to_print = camera.get_number_of_pixels()
|
|
132
128
|
else:
|
|
133
129
|
raise ValueError(
|
|
134
130
|
f"The value provided to --print_pixels_id ({args_dict['print_pixels_id']}) "
|
|
135
131
|
"should be an integer or All"
|
|
136
|
-
)
|
|
132
|
+
) from exc
|
|
137
133
|
fig = camera.plot_pixel_layout(args_dict["camera_in_sky_coor"], pixel_ids_to_print)
|
|
138
134
|
plot_file_prefix = output_dir.joinpath(f"{label}_{tel_model.name}_pixel_layout")
|
|
139
135
|
for suffix in ["pdf", "png"]:
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
#!/usr/bin/python3
|
|
2
|
+
"""
|
|
3
|
+
Summary
|
|
4
|
+
-------
|
|
5
|
+
Validate yaml, json, or ecsv file using a json schema file.
|
|
6
|
+
|
|
7
|
+
Command line arguments
|
|
8
|
+
----------------------
|
|
9
|
+
file_name (str)
|
|
10
|
+
input file to be validated
|
|
11
|
+
schema (str)
|
|
12
|
+
schema file (jsonschema format) used for validation
|
|
13
|
+
|
|
14
|
+
Raises
|
|
15
|
+
------
|
|
16
|
+
FileNotFoundError
|
|
17
|
+
if file to be validated is not found
|
|
18
|
+
|
|
19
|
+
Example
|
|
20
|
+
-------
|
|
21
|
+
|
|
22
|
+
.. code-block:: console
|
|
23
|
+
|
|
24
|
+
simtools-validate-file-using-schema \
|
|
25
|
+
--file_name tests/resources/MLTdata-preproduction.meta.yml \
|
|
26
|
+
--schema simtools/schemas/metadata.metaschema.yml
|
|
27
|
+
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
import logging
|
|
31
|
+
from pathlib import Path
|
|
32
|
+
|
|
33
|
+
import simtools.utils.general as gen
|
|
34
|
+
from simtools.configuration import configurator
|
|
35
|
+
from simtools.data_model import data_reader, metadata_collector, validate_data
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _parse(label, description):
|
|
39
|
+
"""
|
|
40
|
+
Parse command line configuration
|
|
41
|
+
|
|
42
|
+
Parameters
|
|
43
|
+
----------
|
|
44
|
+
label (str)
|
|
45
|
+
application label
|
|
46
|
+
description (str)
|
|
47
|
+
application description
|
|
48
|
+
|
|
49
|
+
Returns
|
|
50
|
+
-------
|
|
51
|
+
config (Configurator)
|
|
52
|
+
application configuration
|
|
53
|
+
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
config = configurator.Configurator(label=label, description=description)
|
|
57
|
+
config.parser.add_argument("--file_name", help="file to be validated", required=True)
|
|
58
|
+
config.parser.add_argument("--schema", help="json schema file", required=False)
|
|
59
|
+
config.parser.add_argument(
|
|
60
|
+
"--validate_metadata",
|
|
61
|
+
help="validate metadata",
|
|
62
|
+
action="store_true",
|
|
63
|
+
default=False,
|
|
64
|
+
)
|
|
65
|
+
return config.initialize(paths=False)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _validate_yaml_or_json_file(args_dict, logger):
|
|
69
|
+
"""
|
|
70
|
+
Validate a yaml or json file.
|
|
71
|
+
Schema is either given as command line argument, read from the meta_schema_url or from
|
|
72
|
+
the metadata section of the data dictionary.
|
|
73
|
+
|
|
74
|
+
"""
|
|
75
|
+
|
|
76
|
+
data_reader.read_value_from_file(
|
|
77
|
+
file_name=args_dict["file_name"],
|
|
78
|
+
schema_file=args_dict["schema"],
|
|
79
|
+
validate=True,
|
|
80
|
+
)
|
|
81
|
+
logger.debug("Successful validation of json/yaml file")
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def _validate_ecsv_file(args_dict, logger):
|
|
85
|
+
"""
|
|
86
|
+
Validate an ecsv file
|
|
87
|
+
|
|
88
|
+
"""
|
|
89
|
+
|
|
90
|
+
data_validator = validate_data.DataValidator(
|
|
91
|
+
schema_file=args_dict["schema"],
|
|
92
|
+
data_file=args_dict["file_name"],
|
|
93
|
+
)
|
|
94
|
+
data_validator.validate_and_transform()
|
|
95
|
+
logger.debug("Successful validation of escv file")
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def _validate_metadata(args_dict, logger):
|
|
99
|
+
"""
|
|
100
|
+
Validate metadata.
|
|
101
|
+
|
|
102
|
+
"""
|
|
103
|
+
|
|
104
|
+
# metadata_collector runs the metadata validation by default, no need to do anything else
|
|
105
|
+
metadata_collector.MetadataCollector(None, metadata_file_name=args_dict["file_name"])
|
|
106
|
+
logger.debug("Successful validation of metadata")
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def main():
|
|
110
|
+
label = Path(__file__).stem
|
|
111
|
+
args_dict, _ = _parse(label, description="Validate yaml or ecsv file using a json schema file.")
|
|
112
|
+
|
|
113
|
+
logger = logging.getLogger()
|
|
114
|
+
logger.setLevel(gen.get_log_level_from_user(args_dict["log_level"]))
|
|
115
|
+
|
|
116
|
+
if args_dict["validate_metadata"]:
|
|
117
|
+
_validate_metadata(args_dict, logger)
|
|
118
|
+
elif any(args_dict["file_name"].endswith(ext) for ext in (".yml", ".yaml", ".json")):
|
|
119
|
+
_validate_yaml_or_json_file(args_dict, logger)
|
|
120
|
+
elif args_dict["file_name"].endswith(".ecsv"):
|
|
121
|
+
_validate_ecsv_file(args_dict, logger)
|
|
122
|
+
else:
|
|
123
|
+
logger.error(f"File extension not supported for {args_dict['file_name']}")
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
if __name__ == "__main__":
|
|
127
|
+
main()
|
|
@@ -32,21 +32,21 @@
|
|
|
32
32
|
telescope (str, required)
|
|
33
33
|
Telescope model name (e.g. LST-1, SST-D, ...).
|
|
34
34
|
model_version (str, optional)
|
|
35
|
-
Model version
|
|
35
|
+
Model version.
|
|
36
36
|
src_distance (float, optional)
|
|
37
|
-
Source distance in km
|
|
37
|
+
Source distance in km.
|
|
38
38
|
zenith (float, optional)
|
|
39
|
-
Zenith angle in deg
|
|
39
|
+
Zenith angle in deg.
|
|
40
40
|
max_offset (float, optional)
|
|
41
|
-
Maximum offset angle in deg
|
|
41
|
+
Maximum offset angle in deg.
|
|
42
42
|
offset_steps (float, optional)
|
|
43
|
-
Offset angle step size
|
|
43
|
+
Offset angle step size.
|
|
44
44
|
plot_images (activation mode, optional)
|
|
45
45
|
Produce a multiple pages pdf file with the image plots.
|
|
46
46
|
test (activation mode, optional)
|
|
47
47
|
If activated, application will be faster by simulating fewer photons.
|
|
48
48
|
verbosity (str, optional)
|
|
49
|
-
Log level to print
|
|
49
|
+
Log level to print.
|
|
50
50
|
|
|
51
51
|
Example
|
|
52
52
|
-------
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
.. code-block:: console
|
|
56
56
|
|
|
57
57
|
simtools-validate-optics --site North --telescope LST-1 --max_offset 1.0 \
|
|
58
|
-
--zenith 20 --src_distance
|
|
58
|
+
--zenith 20 --src_distance 10 --test
|
|
59
59
|
|
|
60
60
|
The output is saved in simtools-output/validate_optics
|
|
61
61
|
|
|
@@ -77,8 +77,8 @@ import numpy as np
|
|
|
77
77
|
from matplotlib.backends.backend_pdf import PdfPages
|
|
78
78
|
|
|
79
79
|
import simtools.utils.general as gen
|
|
80
|
-
from simtools import io_handler
|
|
81
80
|
from simtools.configuration import configurator
|
|
81
|
+
from simtools.io_operations import io_handler
|
|
82
82
|
from simtools.model.telescope_model import TelescopeModel
|
|
83
83
|
from simtools.ray_tracing import RayTracing
|
|
84
84
|
|
|
@@ -99,22 +99,20 @@ def _parse(label):
|
|
|
99
99
|
|
|
100
100
|
config.parser.add_argument(
|
|
101
101
|
"--src_distance",
|
|
102
|
-
help="Source distance in km
|
|
102
|
+
help="Source distance in km",
|
|
103
103
|
type=float,
|
|
104
104
|
default=10,
|
|
105
105
|
)
|
|
106
|
-
config.parser.add_argument(
|
|
107
|
-
"--zenith", help="Zenith angle in deg (default=20)", type=float, default=20
|
|
108
|
-
)
|
|
106
|
+
config.parser.add_argument("--zenith", help="Zenith angle in deg", type=float, default=20)
|
|
109
107
|
config.parser.add_argument(
|
|
110
108
|
"--max_offset",
|
|
111
|
-
help="Maximum offset angle in deg
|
|
109
|
+
help="Maximum offset angle in deg",
|
|
112
110
|
type=float,
|
|
113
111
|
default=4,
|
|
114
112
|
)
|
|
115
113
|
config.parser.add_argument(
|
|
116
114
|
"--offset_steps",
|
|
117
|
-
help="Offset angle step size
|
|
115
|
+
help="Offset angle step size",
|
|
118
116
|
type=float,
|
|
119
117
|
default=0.25,
|
|
120
118
|
)
|
|
@@ -134,7 +132,7 @@ def main():
|
|
|
134
132
|
logger.setLevel(gen.get_log_level_from_user(args_dict["log_level"]))
|
|
135
133
|
|
|
136
134
|
_io_handler = io_handler.IOHandler()
|
|
137
|
-
output_dir = _io_handler.get_output_directory(label,
|
|
135
|
+
output_dir = _io_handler.get_output_directory(label, sub_dir="application-plots")
|
|
138
136
|
|
|
139
137
|
tel_model = TelescopeModel(
|
|
140
138
|
site=args_dict["site"],
|