gammasimtools 0.6.1__py3-none-any.whl → 0.8.2__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.8.2.dist-info/METADATA +173 -0
- gammasimtools-0.8.2.dist-info/RECORD +345 -0
- {gammasimtools-0.6.1.dist-info → gammasimtools-0.8.2.dist-info}/WHEEL +1 -1
- gammasimtools-0.8.2.dist-info/entry_points.txt +31 -0
- simtools/_dev_version/__init__.py +9 -0
- simtools/_version.py +2 -2
- simtools/applications/calculate_trigger_rate.py +210 -0
- simtools/applications/convert_all_model_parameters_from_simtel.py +372 -0
- simtools/applications/{print_array_elements.py → convert_geo_coordinates_of_array_elements.py} +58 -63
- simtools/applications/convert_model_parameter_from_simtel.py +119 -0
- simtools/applications/{add_file_to_db.py → db_add_file_to_db.py} +70 -60
- simtools/applications/db_add_model_parameters_from_repository_to_db.py +184 -0
- simtools/applications/db_add_value_from_json_to_db.py +105 -0
- simtools/applications/db_development_tools/write_array_elements_positions_to_repository.py +180 -0
- simtools/applications/db_get_array_layouts_from_db.py +162 -0
- simtools/applications/{get_file_from_db.py → db_get_file_from_db.py} +30 -34
- simtools/applications/db_get_parameter_from_db.py +131 -0
- simtools/applications/db_inspect_databases.py +52 -0
- simtools/applications/derive_mirror_rnda.py +39 -255
- simtools/applications/derive_psf_parameters.py +441 -0
- simtools/applications/generate_array_config.py +82 -0
- simtools/applications/generate_corsika_histograms.py +52 -52
- simtools/applications/generate_default_metadata.py +5 -8
- simtools/applications/generate_regular_arrays.py +117 -0
- simtools/applications/generate_simtel_array_histograms.py +97 -56
- simtools/applications/plot_array_layout.py +345 -115
- simtools/applications/production_generate_simulation_config.py +158 -0
- simtools/applications/production_scale_events.py +168 -0
- simtools/applications/simulate_light_emission.py +478 -0
- simtools/applications/simulate_prod.py +97 -175
- simtools/applications/submit_data_from_external.py +9 -12
- simtools/applications/submit_model_parameter_from_external.py +122 -0
- simtools/applications/validate_camera_efficiency.py +35 -102
- simtools/applications/validate_camera_fov.py +20 -19
- simtools/applications/{compare_cumulative_psf.py → validate_cumulative_psf.py} +45 -44
- simtools/applications/validate_file_using_schema.py +111 -47
- simtools/applications/validate_optics.py +17 -22
- simtools/camera_efficiency.py +193 -202
- simtools/configuration/commandline_parser.py +384 -96
- simtools/configuration/configurator.py +55 -71
- simtools/constants.py +5 -5
- simtools/corsika/corsika_config.py +482 -342
- simtools/corsika/corsika_histograms.py +226 -204
- simtools/corsika/corsika_histograms_visualize.py +23 -24
- simtools/corsika/primary_particle.py +159 -0
- simtools/data_model/data_reader.py +25 -20
- simtools/data_model/format_checkers.py +52 -0
- simtools/data_model/metadata_collector.py +211 -185
- simtools/data_model/metadata_model.py +115 -37
- simtools/data_model/model_data_writer.py +335 -26
- simtools/data_model/validate_data.py +366 -154
- simtools/db/db_array_elements.py +130 -0
- simtools/db/db_from_repo_handler.py +106 -0
- simtools/db/db_handler.py +1246 -0
- simtools/io_operations/hdf5_handler.py +3 -1
- simtools/io_operations/io_handler.py +32 -57
- simtools/job_execution/job_manager.py +82 -69
- simtools/layout/array_layout.py +325 -537
- simtools/layout/geo_coordinates.py +8 -11
- simtools/layout/telescope_position.py +163 -86
- simtools/model/array_model.py +312 -259
- simtools/model/calibration_model.py +50 -0
- simtools/model/camera.py +277 -523
- simtools/model/mirrors.py +68 -49
- simtools/model/model_parameter.py +602 -0
- simtools/model/model_utils.py +11 -39
- simtools/model/site_model.py +161 -0
- simtools/model/telescope_model.py +143 -633
- simtools/production_configuration/calculate_statistical_errors_grid_point.py +454 -0
- simtools/production_configuration/event_scaler.py +146 -0
- simtools/production_configuration/generate_simulation_config.py +193 -0
- simtools/production_configuration/interpolation_handler.py +197 -0
- simtools/ray_tracing/__init__.py +0 -0
- simtools/ray_tracing/mirror_panel_psf.py +280 -0
- simtools/{psf_analysis.py → ray_tracing/psf_analysis.py} +133 -47
- simtools/ray_tracing/ray_tracing.py +646 -0
- simtools/runners/__init__.py +0 -0
- simtools/runners/corsika_runner.py +240 -0
- simtools/runners/corsika_simtel_runner.py +225 -0
- simtools/runners/runner_services.py +307 -0
- simtools/runners/simtel_runner.py +224 -0
- simtools/schemas/array_elements.yml +137 -0
- simtools/schemas/integration_tests_config.metaschema.yml +93 -0
- simtools/schemas/metadata.metaschema.yml +6 -0
- simtools/schemas/model_parameter.metaschema.yml +78 -0
- simtools/schemas/{data.metaschema.yml → model_parameter_and_data_schema.metaschema.yml} +27 -44
- simtools/schemas/model_parameters/adjust_gain.schema.yml +37 -0
- simtools/schemas/model_parameters/altitude.schema.yml +37 -0
- simtools/schemas/model_parameters/array_coordinates.schema.yml +33 -0
- simtools/schemas/model_parameters/array_coordinates_UTM.schema.yml +77 -0
- simtools/schemas/model_parameters/array_element_position_ground.schema.yml +39 -0
- simtools/schemas/model_parameters/array_element_position_utm.schema.yml +39 -0
- simtools/schemas/model_parameters/array_layouts.schema.yml +48 -0
- simtools/schemas/model_parameters/array_triggers.schema.yml +93 -0
- simtools/schemas/model_parameters/asum_clipping.schema.yml +38 -0
- simtools/schemas/model_parameters/asum_offset.schema.yml +35 -0
- simtools/schemas/model_parameters/asum_shaping.schema.yml +35 -0
- simtools/schemas/model_parameters/asum_threshold.schema.yml +38 -0
- simtools/schemas/model_parameters/atmospheric_profile.schema.yml +32 -0
- simtools/schemas/model_parameters/atmospheric_transmission.schema.yml +35 -0
- simtools/schemas/model_parameters/axes_offsets.schema.yml +53 -0
- simtools/schemas/model_parameters/camera_body_diameter.schema.yml +40 -0
- simtools/schemas/model_parameters/camera_body_shape.schema.yml +45 -0
- simtools/schemas/model_parameters/camera_config_file.schema.yml +40 -0
- simtools/schemas/model_parameters/camera_config_rotate.schema.yml +36 -0
- simtools/schemas/model_parameters/camera_degraded_efficiency.schema.yml +43 -0
- simtools/schemas/model_parameters/camera_degraded_map.schema.yml +42 -0
- simtools/schemas/model_parameters/camera_depth.schema.yml +42 -0
- simtools/schemas/model_parameters/camera_filter.schema.yml +45 -0
- simtools/schemas/model_parameters/camera_filter_incidence_angle.schema.yml +29 -0
- simtools/schemas/model_parameters/camera_pixels.schema.yml +36 -0
- simtools/schemas/model_parameters/camera_transmission.schema.yml +41 -0
- simtools/schemas/model_parameters/channels_per_chip.schema.yml +36 -0
- simtools/schemas/model_parameters/correct_nsb_spectrum_to_telescope_altitude.schema.yml +35 -0
- simtools/schemas/model_parameters/corsika_cherenkov_photon_bunch_size.schema.yml +27 -0
- simtools/schemas/model_parameters/corsika_cherenkov_photon_wavelength_range.schema.yml +38 -0
- simtools/schemas/model_parameters/corsika_first_interaction_height.schema.yml +28 -0
- simtools/schemas/model_parameters/corsika_iact_io_buffer.schema.yml +23 -0
- simtools/schemas/model_parameters/corsika_iact_max_bunches.schema.yml +27 -0
- simtools/schemas/model_parameters/corsika_iact_split_auto.schema.yml +28 -0
- simtools/schemas/model_parameters/corsika_longitudinal_shower_development.schema.yml +27 -0
- simtools/schemas/model_parameters/corsika_observation_level.schema.yml +38 -0
- simtools/schemas/model_parameters/corsika_particle_kinetic_energy_cutoff.schema.yml +52 -0
- simtools/schemas/model_parameters/corsika_starting_grammage.schema.yml +27 -0
- simtools/schemas/model_parameters/dark_events.schema.yml +32 -0
- simtools/schemas/model_parameters/default_trigger.schema.yml +35 -0
- simtools/schemas/model_parameters/design_model.schema.yml +31 -0
- simtools/schemas/model_parameters/disc_ac_coupled.schema.yml +32 -0
- simtools/schemas/model_parameters/disc_bins.schema.yml +39 -0
- simtools/schemas/model_parameters/disc_start.schema.yml +41 -0
- simtools/schemas/model_parameters/discriminator_amplitude.schema.yml +42 -0
- simtools/schemas/model_parameters/discriminator_fall_time.schema.yml +41 -0
- simtools/schemas/model_parameters/discriminator_gate_length.schema.yml +41 -0
- simtools/schemas/model_parameters/discriminator_hysteresis.schema.yml +39 -0
- simtools/schemas/model_parameters/discriminator_output_amplitude.schema.yml +40 -0
- simtools/schemas/model_parameters/discriminator_output_var_percent.schema.yml +41 -0
- simtools/schemas/model_parameters/discriminator_pulse_shape.schema.yml +33 -0
- simtools/schemas/model_parameters/discriminator_rise_time.schema.yml +42 -0
- simtools/schemas/model_parameters/discriminator_scale_threshold.schema.yml +37 -0
- simtools/schemas/model_parameters/discriminator_sigsum_over_threshold.schema.yml +44 -0
- simtools/schemas/model_parameters/discriminator_threshold.schema.yml +36 -0
- simtools/schemas/model_parameters/discriminator_time_over_threshold.schema.yml +45 -0
- simtools/schemas/model_parameters/discriminator_var_gate_length.schema.yml +40 -0
- simtools/schemas/model_parameters/discriminator_var_sigsum_over_threshold.schema.yml +41 -0
- simtools/schemas/model_parameters/discriminator_var_threshold.schema.yml +38 -0
- simtools/schemas/model_parameters/discriminator_var_time_over_threshold.schema.yml +38 -0
- simtools/schemas/model_parameters/dish_shape_length.schema.yml +41 -0
- simtools/schemas/model_parameters/dsum_clipping.schema.yml +38 -0
- simtools/schemas/model_parameters/dsum_ignore_below.schema.yml +38 -0
- simtools/schemas/model_parameters/dsum_offset.schema.yml +37 -0
- simtools/schemas/model_parameters/dsum_pedsub.schema.yml +33 -0
- simtools/schemas/model_parameters/dsum_pre_clipping.schema.yml +39 -0
- simtools/schemas/model_parameters/dsum_prescale.schema.yml +44 -0
- simtools/schemas/model_parameters/dsum_presum_max.schema.yml +38 -0
- simtools/schemas/model_parameters/dsum_presum_shift.schema.yml +45 -0
- simtools/schemas/model_parameters/dsum_shaping.schema.yml +44 -0
- simtools/schemas/model_parameters/dsum_shaping_renormalize.schema.yml +32 -0
- simtools/schemas/model_parameters/dsum_threshold.schema.yml +43 -0
- simtools/schemas/model_parameters/dsum_zero_clip.schema.yml +42 -0
- simtools/schemas/model_parameters/effective_focal_length.schema.yml +61 -0
- simtools/schemas/model_parameters/epsg_code.schema.yml +37 -0
- simtools/schemas/model_parameters/fadc_ac_coupled.schema.yml +35 -0
- simtools/schemas/model_parameters/fadc_amplitude.schema.yml +46 -0
- simtools/schemas/model_parameters/fadc_bins.schema.yml +40 -0
- simtools/schemas/model_parameters/fadc_compensate_pedestal.schema.yml +50 -0
- simtools/schemas/model_parameters/fadc_dev_pedestal.schema.yml +38 -0
- simtools/schemas/model_parameters/fadc_err_compensate_pedestal.schema.yml +42 -0
- simtools/schemas/model_parameters/fadc_err_pedestal.schema.yml +49 -0
- simtools/schemas/model_parameters/fadc_lg_amplitude.schema.yml +47 -0
- simtools/schemas/model_parameters/fadc_lg_compensate_pedestal.schema.yml +51 -0
- simtools/schemas/model_parameters/fadc_lg_dev_pedestal.schema.yml +37 -0
- simtools/schemas/model_parameters/fadc_lg_err_compensate_pedestal.schema.yml +43 -0
- simtools/schemas/model_parameters/fadc_lg_err_pedestal.schema.yml +49 -0
- simtools/schemas/model_parameters/fadc_lg_max_signal.schema.yml +43 -0
- simtools/schemas/model_parameters/fadc_lg_max_sum.schema.yml +39 -0
- simtools/schemas/model_parameters/fadc_lg_noise.schema.yml +42 -0
- simtools/schemas/model_parameters/fadc_lg_pedestal.schema.yml +40 -0
- simtools/schemas/model_parameters/fadc_lg_sensitivity.schema.yml +50 -0
- simtools/schemas/model_parameters/fadc_lg_sysvar_pedestal.schema.yml +42 -0
- simtools/schemas/model_parameters/fadc_lg_var_pedestal.schema.yml +41 -0
- simtools/schemas/model_parameters/fadc_lg_var_sensitivity.schema.yml +42 -0
- simtools/schemas/model_parameters/fadc_max_signal.schema.yml +43 -0
- simtools/schemas/model_parameters/fadc_max_sum.schema.yml +39 -0
- simtools/schemas/model_parameters/fadc_mhz.schema.yml +31 -0
- simtools/schemas/model_parameters/fadc_noise.schema.yml +41 -0
- simtools/schemas/model_parameters/fadc_pedestal.schema.yml +40 -0
- simtools/schemas/model_parameters/fadc_pulse_shape.schema.yml +39 -0
- simtools/schemas/model_parameters/fadc_sensitivity.schema.yml +50 -0
- simtools/schemas/model_parameters/fadc_sum_bins.schema.yml +43 -0
- simtools/schemas/model_parameters/fadc_sum_offset.schema.yml +43 -0
- simtools/schemas/model_parameters/fadc_sysvar_pedestal.schema.yml +42 -0
- simtools/schemas/model_parameters/fadc_var_pedestal.schema.yml +41 -0
- simtools/schemas/model_parameters/fadc_var_sensitivity.schema.yml +42 -0
- simtools/schemas/model_parameters/flatfielding.schema.yml +37 -0
- simtools/schemas/model_parameters/focal_length.schema.yml +45 -0
- simtools/schemas/model_parameters/focal_surface_parameters.schema.yml +158 -0
- simtools/schemas/model_parameters/focal_surface_ref_radius.schema.yml +29 -0
- simtools/schemas/model_parameters/focus_offset.schema.yml +66 -0
- simtools/schemas/model_parameters/gain_variation.schema.yml +43 -0
- simtools/schemas/model_parameters/geomag_horizontal.schema.yml +34 -0
- simtools/schemas/model_parameters/geomag_rotation.schema.yml +37 -0
- simtools/schemas/model_parameters/geomag_vertical.schema.yml +34 -0
- simtools/schemas/model_parameters/hg_lg_variation.schema.yml +36 -0
- simtools/schemas/model_parameters/iobuf_maximum.schema.yml +34 -0
- simtools/schemas/model_parameters/iobuf_output_maximum.schema.yml +34 -0
- simtools/schemas/model_parameters/laser_events.schema.yml +36 -0
- simtools/schemas/model_parameters/laser_external_trigger.schema.yml +35 -0
- simtools/schemas/model_parameters/laser_photons.schema.yml +32 -0
- simtools/schemas/model_parameters/laser_pulse_exptime.schema.yml +34 -0
- simtools/schemas/model_parameters/laser_pulse_offset.schema.yml +34 -0
- simtools/schemas/model_parameters/laser_pulse_sigtime.schema.yml +33 -0
- simtools/schemas/model_parameters/laser_pulse_twidth.schema.yml +33 -0
- simtools/schemas/model_parameters/laser_var_photons.schema.yml +33 -0
- simtools/schemas/model_parameters/laser_wavelength.schema.yml +33 -0
- simtools/schemas/model_parameters/led_events.schema.yml +34 -0
- simtools/schemas/model_parameters/led_photons.schema.yml +34 -0
- simtools/schemas/model_parameters/led_pulse_offset.schema.yml +32 -0
- simtools/schemas/model_parameters/led_pulse_sigtime.schema.yml +33 -0
- simtools/schemas/model_parameters/led_var_photons.schema.yml +34 -0
- simtools/schemas/model_parameters/lightguide_efficiency_vs_incidence_angle.schema.yml +41 -0
- simtools/schemas/model_parameters/lightguide_efficiency_vs_wavelength.schema.yml +43 -0
- simtools/schemas/model_parameters/min_photoelectrons.schema.yml +35 -0
- simtools/schemas/model_parameters/min_photons.schema.yml +32 -0
- simtools/schemas/model_parameters/mirror_align_random_distance.schema.yml +36 -0
- simtools/schemas/model_parameters/mirror_align_random_horizontal.schema.yml +64 -0
- simtools/schemas/model_parameters/mirror_align_random_vertical.schema.yml +64 -0
- simtools/schemas/model_parameters/mirror_class.schema.yml +41 -0
- simtools/schemas/model_parameters/mirror_degraded_reflection.schema.yml +51 -0
- simtools/schemas/model_parameters/mirror_focal_length.schema.yml +42 -0
- simtools/schemas/model_parameters/mirror_list.schema.yml +38 -0
- simtools/schemas/model_parameters/mirror_offset.schema.yml +41 -0
- simtools/schemas/model_parameters/mirror_panel_2f_measurements.schema.yml +39 -0
- simtools/schemas/model_parameters/mirror_reflection_random_angle.schema.yml +61 -0
- simtools/schemas/model_parameters/mirror_reflectivity.schema.yml +40 -0
- simtools/schemas/model_parameters/multiplicity_offset.schema.yml +46 -0
- simtools/schemas/model_parameters/nsb_autoscale_airmass.schema.yml +51 -0
- simtools/schemas/model_parameters/nsb_gain_drop_scale.schema.yml +37 -0
- simtools/schemas/model_parameters/nsb_offaxis.schema.yml +79 -0
- simtools/schemas/model_parameters/nsb_pixel_rate.schema.yml +47 -0
- simtools/schemas/model_parameters/nsb_reference_spectrum.schema.yml +34 -0
- simtools/schemas/model_parameters/nsb_reference_value.schema.yml +33 -0
- simtools/schemas/model_parameters/nsb_scaling_factor.schema.yml +35 -0
- simtools/schemas/model_parameters/nsb_skymap.schema.yml +39 -0
- simtools/schemas/model_parameters/nsb_spectrum.schema.yml +50 -0
- simtools/schemas/model_parameters/num_gains.schema.yml +34 -0
- simtools/schemas/model_parameters/only_triggered_telescopes.schema.yml +33 -0
- simtools/schemas/model_parameters/optics_properties.schema.yml +31 -0
- simtools/schemas/model_parameters/parabolic_dish.schema.yml +32 -0
- simtools/schemas/model_parameters/pedestal_events.schema.yml +32 -0
- simtools/schemas/model_parameters/photon_delay.schema.yml +38 -0
- simtools/schemas/model_parameters/photons_per_run.schema.yml +33 -0
- simtools/schemas/model_parameters/pixel_cells.schema.yml +35 -0
- simtools/schemas/model_parameters/pixels_parallel.schema.yml +54 -0
- simtools/schemas/model_parameters/pixeltrg_time_step.schema.yml +40 -0
- simtools/schemas/model_parameters/pm_average_gain.schema.yml +34 -0
- simtools/schemas/model_parameters/pm_collection_efficiency.schema.yml +40 -0
- simtools/schemas/model_parameters/pm_gain_index.schema.yml +36 -0
- simtools/schemas/model_parameters/pm_photoelectron_spectrum.schema.yml +41 -0
- simtools/schemas/model_parameters/pm_transit_time.schema.yml +63 -0
- simtools/schemas/model_parameters/pm_voltage_variation.schema.yml +39 -0
- simtools/schemas/model_parameters/primary_mirror_degraded_map.schema.yml +42 -0
- simtools/schemas/model_parameters/primary_mirror_diameter.schema.yml +33 -0
- simtools/schemas/model_parameters/primary_mirror_hole_diameter.schema.yml +33 -0
- simtools/schemas/model_parameters/primary_mirror_incidence_angle.schema.yml +29 -0
- simtools/schemas/model_parameters/primary_mirror_parameters.schema.yml +168 -0
- simtools/schemas/model_parameters/primary_mirror_ref_radius.schema.yml +36 -0
- simtools/schemas/model_parameters/primary_mirror_segmentation.schema.yml +34 -0
- simtools/schemas/model_parameters/qe_variation.schema.yml +43 -0
- simtools/schemas/model_parameters/quantum_efficiency.schema.yml +42 -0
- simtools/schemas/model_parameters/random_focal_length.schema.yml +45 -0
- simtools/schemas/model_parameters/random_generator.schema.yml +36 -0
- simtools/schemas/model_parameters/reference_point_altitude.schema.yml +35 -0
- simtools/schemas/model_parameters/reference_point_latitude.schema.yml +36 -0
- simtools/schemas/model_parameters/reference_point_longitude.schema.yml +36 -0
- simtools/schemas/model_parameters/reference_point_utm_east.schema.yml +34 -0
- simtools/schemas/model_parameters/reference_point_utm_north.schema.yml +34 -0
- simtools/schemas/model_parameters/sampled_output.schema.yml +31 -0
- simtools/schemas/model_parameters/save_pe_with_amplitude.schema.yml +34 -0
- simtools/schemas/model_parameters/secondary_mirror_baffle.schema.yml +79 -0
- simtools/schemas/model_parameters/secondary_mirror_degraded_map.schema.yml +42 -0
- simtools/schemas/model_parameters/secondary_mirror_degraded_reflection.schema.yml +41 -0
- simtools/schemas/model_parameters/secondary_mirror_diameter.schema.yml +33 -0
- simtools/schemas/model_parameters/secondary_mirror_hole_diameter.schema.yml +36 -0
- simtools/schemas/model_parameters/secondary_mirror_incidence_angle.schema.yml +29 -0
- simtools/schemas/model_parameters/secondary_mirror_parameters.schema.yml +168 -0
- simtools/schemas/model_parameters/secondary_mirror_ref_radius.schema.yml +36 -0
- simtools/schemas/model_parameters/secondary_mirror_reflectivity.schema.yml +35 -0
- simtools/schemas/model_parameters/secondary_mirror_segmentation.schema.yml +37 -0
- simtools/schemas/model_parameters/secondary_mirror_shadow_diameter.schema.yml +40 -0
- simtools/schemas/model_parameters/secondary_mirror_shadow_offset.schema.yml +40 -0
- simtools/schemas/model_parameters/store_photoelectrons.schema.yml +41 -0
- simtools/schemas/model_parameters/tailcut_scale.schema.yml +40 -0
- simtools/schemas/model_parameters/telescope_axis_height.schema.yml +31 -0
- simtools/schemas/model_parameters/telescope_random_angle.schema.yml +35 -0
- simtools/schemas/model_parameters/telescope_random_error.schema.yml +34 -0
- simtools/schemas/model_parameters/telescope_sphere_radius.schema.yml +37 -0
- simtools/schemas/model_parameters/telescope_transmission.schema.yml +113 -0
- simtools/schemas/model_parameters/teltrig_min_sigsum.schema.yml +41 -0
- simtools/schemas/model_parameters/teltrig_min_time.schema.yml +36 -0
- simtools/schemas/model_parameters/transit_time_calib_error.schema.yml +36 -0
- simtools/schemas/model_parameters/transit_time_compensate_error.schema.yml +37 -0
- simtools/schemas/model_parameters/transit_time_compensate_step.schema.yml +38 -0
- simtools/schemas/model_parameters/transit_time_error.schema.yml +45 -0
- simtools/schemas/model_parameters/transit_time_jitter.schema.yml +36 -0
- simtools/schemas/model_parameters/trigger_current_limit.schema.yml +32 -0
- simtools/schemas/model_parameters/trigger_delay_compensation.schema.yml +53 -0
- simtools/schemas/model_parameters/trigger_pixels.schema.yml +40 -0
- simtools/simtel/simtel_config_reader.py +353 -0
- simtools/simtel/simtel_config_writer.py +244 -63
- simtools/simtel/{simtel_events.py → simtel_io_events.py} +26 -25
- simtools/simtel/simtel_io_histogram.py +661 -0
- simtools/simtel/simtel_io_histograms.py +569 -0
- simtools/simtel/simulator_array.py +145 -0
- simtools/simtel/{simtel_runner_camera_efficiency.py → simulator_camera_efficiency.py} +76 -52
- simtools/simtel/simulator_light_emission.py +473 -0
- simtools/simtel/simulator_ray_tracing.py +262 -0
- simtools/simulator.py +220 -446
- simtools/testing/__init__.py +0 -0
- simtools/testing/assertions.py +151 -0
- simtools/testing/configuration.py +226 -0
- simtools/testing/helpers.py +42 -0
- simtools/testing/validate_output.py +240 -0
- simtools/utils/general.py +340 -437
- simtools/utils/geometry.py +12 -12
- simtools/utils/names.py +257 -644
- simtools/utils/value_conversion.py +176 -0
- simtools/version.py +3 -1
- simtools/visualization/legend_handlers.py +135 -152
- simtools/visualization/plot_camera.py +379 -0
- simtools/visualization/visualize.py +346 -167
- gammasimtools-0.6.1.dist-info/METADATA +0 -180
- gammasimtools-0.6.1.dist-info/RECORD +0 -91
- gammasimtools-0.6.1.dist-info/entry_points.txt +0 -23
- simtools/_dev_version/scm_version.py +0 -10
- simtools/applications/db_development_tools/add_new_parameter_to_db.py +0 -81
- simtools/applications/db_development_tools/add_unit_to_parameter_in_db.py +0 -59
- simtools/applications/db_development_tools/mark_non_optics_parameters_non_applicable.py +0 -102
- simtools/applications/get_parameter.py +0 -92
- simtools/applications/make_regular_arrays.py +0 -160
- simtools/applications/produce_array_config.py +0 -136
- simtools/applications/production.py +0 -313
- simtools/applications/sim_showers_for_trigger_rates.py +0 -187
- simtools/applications/tune_psf.py +0 -334
- simtools/corsika/corsika_default_config.py +0 -282
- simtools/corsika/corsika_runner.py +0 -450
- simtools/corsika_simtel/corsika_simtel_runner.py +0 -197
- simtools/db_handler.py +0 -1480
- simtools/ray_tracing.py +0 -525
- simtools/simtel/simtel_histograms.py +0 -414
- simtools/simtel/simtel_runner.py +0 -244
- simtools/simtel/simtel_runner_array.py +0 -293
- simtools/simtel/simtel_runner_ray_tracing.py +0 -277
- {gammasimtools-0.6.1.dist-info → gammasimtools-0.8.2.dist-info}/LICENSE +0 -0
- {gammasimtools-0.6.1.dist-info → gammasimtools-0.8.2.dist-info}/top_level.txt +0 -0
- /simtools/{corsika_simtel → db}/__init__.py +0 -0
|
@@ -1,414 +0,0 @@
|
|
|
1
|
-
import copy
|
|
2
|
-
import logging
|
|
3
|
-
|
|
4
|
-
import numpy as np
|
|
5
|
-
from astropy import units as u
|
|
6
|
-
from ctapipe.io import write_table
|
|
7
|
-
from eventio import EventIOFile, Histograms
|
|
8
|
-
from eventio.search_utils import yield_toplevel_of_type
|
|
9
|
-
|
|
10
|
-
from simtools import version
|
|
11
|
-
from simtools.io_operations.hdf5_handler import fill_hdf5_table
|
|
12
|
-
from simtools.utils.names import sanitize_name
|
|
13
|
-
|
|
14
|
-
__all__ = ["InconsistentHistogramFormat", "SimtelHistograms"]
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
class InconsistentHistogramFormat(Exception):
|
|
18
|
-
"""Exception for bad histogram format."""
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
class SimtelHistograms:
|
|
22
|
-
"""
|
|
23
|
-
This class handle sim_telarray histograms. Histogram files are handled by using eventio library.
|
|
24
|
-
|
|
25
|
-
Parameters
|
|
26
|
-
----------
|
|
27
|
-
histogram_files: list
|
|
28
|
-
List of sim_telarray histogram files (str of Path).
|
|
29
|
-
test: bool
|
|
30
|
-
If True, only a fraction of the histograms will be processed, leading to a much shorter\
|
|
31
|
-
runtime.
|
|
32
|
-
"""
|
|
33
|
-
|
|
34
|
-
def __init__(self, histogram_files, test=False):
|
|
35
|
-
"""
|
|
36
|
-
Initialize SimtelHistograms
|
|
37
|
-
"""
|
|
38
|
-
self._logger = logging.getLogger(__name__)
|
|
39
|
-
if not isinstance(histogram_files, list):
|
|
40
|
-
histogram_files = [histogram_files]
|
|
41
|
-
self._histogram_files = histogram_files
|
|
42
|
-
self._is_test = test
|
|
43
|
-
self._list_of_histograms = None
|
|
44
|
-
self._combined_hists = None
|
|
45
|
-
self.__meta_dict = None
|
|
46
|
-
|
|
47
|
-
@property
|
|
48
|
-
def number_of_histograms(self):
|
|
49
|
-
"""Returns number of histograms."""
|
|
50
|
-
return len(self.combined_hists)
|
|
51
|
-
|
|
52
|
-
def get_histogram_title(self, i_hist):
|
|
53
|
-
"""
|
|
54
|
-
Returns the title of the histogram with index i_hist.
|
|
55
|
-
|
|
56
|
-
Parameters
|
|
57
|
-
----------
|
|
58
|
-
i_hist: int
|
|
59
|
-
Histogram index.
|
|
60
|
-
|
|
61
|
-
Returns
|
|
62
|
-
-------
|
|
63
|
-
str
|
|
64
|
-
Histogram title.
|
|
65
|
-
"""
|
|
66
|
-
return self.combined_hists[i_hist]["title"]
|
|
67
|
-
|
|
68
|
-
@property
|
|
69
|
-
def list_of_histograms(self):
|
|
70
|
-
"""
|
|
71
|
-
Returns a list with the histograms for each file.
|
|
72
|
-
|
|
73
|
-
Returns
|
|
74
|
-
-------
|
|
75
|
-
list:
|
|
76
|
-
List of histograms.
|
|
77
|
-
"""
|
|
78
|
-
if self._list_of_histograms is None:
|
|
79
|
-
self._list_of_histograms = []
|
|
80
|
-
for file in self._histogram_files:
|
|
81
|
-
with EventIOFile(file) as f:
|
|
82
|
-
for o in yield_toplevel_of_type(f, Histograms):
|
|
83
|
-
hists = o.parse()
|
|
84
|
-
self._list_of_histograms.append(hists)
|
|
85
|
-
return self._list_of_histograms
|
|
86
|
-
|
|
87
|
-
def _check_consistency(self, first_hist_file, second_hist_file):
|
|
88
|
-
"""
|
|
89
|
-
Checks whether two histograms have the same format.
|
|
90
|
-
Raises an error in case they are not consistent.
|
|
91
|
-
|
|
92
|
-
Parameters
|
|
93
|
-
----------
|
|
94
|
-
first_hist_file: dict
|
|
95
|
-
One histogram from a single file.
|
|
96
|
-
second_hist_file: dict
|
|
97
|
-
One histogram from a single file.
|
|
98
|
-
|
|
99
|
-
Raises
|
|
100
|
-
------
|
|
101
|
-
InconsistentHistogramFormat:
|
|
102
|
-
if the format of the histograms have inconsistent dimensions.
|
|
103
|
-
"""
|
|
104
|
-
for key_to_test in [
|
|
105
|
-
"lower_x",
|
|
106
|
-
"upper_x",
|
|
107
|
-
"n_bins_x",
|
|
108
|
-
"title",
|
|
109
|
-
]:
|
|
110
|
-
if first_hist_file[key_to_test] != second_hist_file[key_to_test]:
|
|
111
|
-
msg = "Trying to add histograms with inconsistent dimensions"
|
|
112
|
-
self._logger.error(msg)
|
|
113
|
-
raise InconsistentHistogramFormat(msg)
|
|
114
|
-
|
|
115
|
-
@property
|
|
116
|
-
def combined_hists(self):
|
|
117
|
-
"""Add the values of the same type of histogram from the various lists into a single
|
|
118
|
-
histogram list."""
|
|
119
|
-
# Processing and combining histograms from multiple files
|
|
120
|
-
if self._combined_hists is None:
|
|
121
|
-
self._combined_hists = []
|
|
122
|
-
for i_hist, hists_one_file in enumerate(self.list_of_histograms):
|
|
123
|
-
if i_hist == 0:
|
|
124
|
-
# First file
|
|
125
|
-
self._combined_hists = copy.copy(hists_one_file)
|
|
126
|
-
|
|
127
|
-
else:
|
|
128
|
-
for hist, this_combined_hist in zip(hists_one_file, self._combined_hists):
|
|
129
|
-
self._check_consistency(hist, this_combined_hist)
|
|
130
|
-
|
|
131
|
-
this_combined_hist["data"] = np.add(
|
|
132
|
-
this_combined_hist["data"], hist["data"]
|
|
133
|
-
)
|
|
134
|
-
|
|
135
|
-
self._logger.debug(f"End of reading {len(self.list_of_histograms)} files")
|
|
136
|
-
return self._combined_hists
|
|
137
|
-
|
|
138
|
-
@combined_hists.setter
|
|
139
|
-
def combined_hists(self, new_combined_hists):
|
|
140
|
-
"""
|
|
141
|
-
Setter for combined_hists.
|
|
142
|
-
|
|
143
|
-
Parameters
|
|
144
|
-
----------
|
|
145
|
-
new_combined_hists:
|
|
146
|
-
Combined histograms.
|
|
147
|
-
"""
|
|
148
|
-
self._combined_hists = new_combined_hists
|
|
149
|
-
|
|
150
|
-
def _derive_trigger_rate_histograms(self, livetime):
|
|
151
|
-
"""
|
|
152
|
-
Calculates the trigger rate histograms, i.e., the ratio in which the events
|
|
153
|
-
are triggered in each bin of impact distance and log energy for each histogram file for
|
|
154
|
-
the livetime defined by `livetime`.
|
|
155
|
-
The livetime gives the amount of time used in a small production to produce the histograms
|
|
156
|
-
used. It is assumed that the livetime is the same for all the histogram files used and that
|
|
157
|
-
the radius (x-axis in the histograms) is given in meters.
|
|
158
|
-
|
|
159
|
-
Parameters
|
|
160
|
-
----------
|
|
161
|
-
livetime: astropy.Quantity
|
|
162
|
-
Time used in the simulation that produced the histograms. E.g., 1*u.h.
|
|
163
|
-
|
|
164
|
-
Returns
|
|
165
|
-
-------
|
|
166
|
-
list:
|
|
167
|
-
List with the trigger rate histograms for each file.
|
|
168
|
-
"""
|
|
169
|
-
if isinstance(livetime, u.Quantity):
|
|
170
|
-
livetime = livetime.to(u.s)
|
|
171
|
-
else:
|
|
172
|
-
livetime = livetime * u.s
|
|
173
|
-
events_histogram = {}
|
|
174
|
-
trigged_events_histogram = {}
|
|
175
|
-
# Save the appropriate histograms to a dictionary
|
|
176
|
-
for i_file, hists_one_file in enumerate(self.list_of_histograms):
|
|
177
|
-
for hist in hists_one_file:
|
|
178
|
-
if hist["id"] == 1:
|
|
179
|
-
events_histogram[i_file] = hist
|
|
180
|
-
|
|
181
|
-
elif hist["id"] == 2:
|
|
182
|
-
trigged_events_histogram[i_file] = hist
|
|
183
|
-
|
|
184
|
-
list_of_trigger_rate_hists = []
|
|
185
|
-
# Calculate the event rate histograms
|
|
186
|
-
for i_file, hists_one_file in enumerate(self.list_of_histograms):
|
|
187
|
-
event_rate_histogram = copy.copy(events_histogram[i_file])
|
|
188
|
-
area_dict = np.pi * (
|
|
189
|
-
(events_histogram[i_file]["upper_x"]) ** 2
|
|
190
|
-
- (events_histogram[i_file]["lower_x"]) ** 2
|
|
191
|
-
)
|
|
192
|
-
|
|
193
|
-
event_rate_histogram["data"] = (
|
|
194
|
-
np.zeros_like(trigged_events_histogram[i_file]["data"]) / livetime.unit
|
|
195
|
-
)
|
|
196
|
-
bins_with_events = events_histogram[i_file]["data"] != 0
|
|
197
|
-
event_rate_histogram["data"][bins_with_events] = (
|
|
198
|
-
trigged_events_histogram[i_file]["data"][bins_with_events]
|
|
199
|
-
/ events_histogram[i_file]["data"][bins_with_events]
|
|
200
|
-
* area_dict
|
|
201
|
-
/ livetime
|
|
202
|
-
)
|
|
203
|
-
|
|
204
|
-
# Keeping only the necessary information for proceeding with integration
|
|
205
|
-
keys_to_keep = [
|
|
206
|
-
"data",
|
|
207
|
-
"lower_x",
|
|
208
|
-
"lower_y",
|
|
209
|
-
"upper_x",
|
|
210
|
-
"upper_y",
|
|
211
|
-
"entries",
|
|
212
|
-
"n_bins_x",
|
|
213
|
-
"n_bins_y",
|
|
214
|
-
]
|
|
215
|
-
event_rate_histogram = {
|
|
216
|
-
key: event_rate_histogram[key]
|
|
217
|
-
for key in keys_to_keep
|
|
218
|
-
if key in event_rate_histogram
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
list_of_trigger_rate_hists.append(event_rate_histogram)
|
|
222
|
-
return list_of_trigger_rate_hists
|
|
223
|
-
|
|
224
|
-
def _integrate_trigger_rate_histograms(self, hists):
|
|
225
|
-
"""
|
|
226
|
-
Integrates in energy the trigger rate histogram based on the histogram bin edges.
|
|
227
|
-
|
|
228
|
-
Parameters
|
|
229
|
-
----------
|
|
230
|
-
hists: list
|
|
231
|
-
List with the final trigger rate for each histogram.
|
|
232
|
-
"""
|
|
233
|
-
|
|
234
|
-
list_of_integrated_hists = []
|
|
235
|
-
for _, hist in enumerate(hists):
|
|
236
|
-
energy_axis = np.logspace(hist["lower_y"], hist["upper_y"], hist["n_bins_y"])
|
|
237
|
-
radius_axis = np.linspace(hist["lower_x"], hist["upper_x"], hist["n_bins_x"])
|
|
238
|
-
integrated_hist = np.zeros_like(radius_axis)
|
|
239
|
-
for i_radius, _ in enumerate(radius_axis):
|
|
240
|
-
integrated_hist[i_radius] = np.sum(
|
|
241
|
-
hist["data"][:-1, i_radius].value * np.diff(energy_axis)
|
|
242
|
-
)
|
|
243
|
-
|
|
244
|
-
list_of_integrated_hists.append(np.sum(integrated_hist) * hist["data"][0, 0].unit)
|
|
245
|
-
return list_of_integrated_hists
|
|
246
|
-
|
|
247
|
-
def trigger_rate_per_histogram(self, livetime):
|
|
248
|
-
"""
|
|
249
|
-
Estimates the trigger rate for each histogram passed.
|
|
250
|
-
|
|
251
|
-
Parameters
|
|
252
|
-
----------
|
|
253
|
-
livetime: astropy.Quantity
|
|
254
|
-
Time used in the simulation that produced the histograms.
|
|
255
|
-
"""
|
|
256
|
-
hists = self._derive_trigger_rate_histograms(livetime=livetime)
|
|
257
|
-
trigger_rates = self._integrate_trigger_rate_histograms(hists)
|
|
258
|
-
return trigger_rates
|
|
259
|
-
|
|
260
|
-
def plot_one_histogram(self, i_hist, ax):
|
|
261
|
-
"""
|
|
262
|
-
Plot a single histogram referent to the index i_hist.
|
|
263
|
-
|
|
264
|
-
Parameters
|
|
265
|
-
----------
|
|
266
|
-
i_hist: int
|
|
267
|
-
Index of the histogram to be plotted.
|
|
268
|
-
ax: matplotlib.axes.Axes
|
|
269
|
-
Instance of matplotlib.axes.Axes in which to plot the histogram.
|
|
270
|
-
"""
|
|
271
|
-
|
|
272
|
-
hist = self.combined_hists[i_hist]
|
|
273
|
-
ax.set_title(hist["title"])
|
|
274
|
-
|
|
275
|
-
def _get_bins(hist, axis=0):
|
|
276
|
-
ax_str = "x" if axis == 0 else "y"
|
|
277
|
-
return np.linspace(
|
|
278
|
-
hist["lower_" + ax_str],
|
|
279
|
-
hist["upper_" + ax_str],
|
|
280
|
-
hist["n_bins_" + ax_str] + 1,
|
|
281
|
-
)
|
|
282
|
-
|
|
283
|
-
def _get_ax_lim(hist, axis=0):
|
|
284
|
-
if np.sum(hist["data"]) == 0:
|
|
285
|
-
return 0, 1
|
|
286
|
-
|
|
287
|
-
bins = _get_bins(hist, axis=axis)
|
|
288
|
-
|
|
289
|
-
if hist["data"].ndim == 1:
|
|
290
|
-
non_zero = np.where(hist["data"] != 0)
|
|
291
|
-
else:
|
|
292
|
-
marginal = np.sum(hist["data"], axis=axis)
|
|
293
|
-
non_zero = np.where(marginal != 0)
|
|
294
|
-
|
|
295
|
-
return bins[non_zero[0][0]], bins[non_zero[0][-1] + 1]
|
|
296
|
-
|
|
297
|
-
if hist["n_bins_y"] > 0:
|
|
298
|
-
# 2D histogram
|
|
299
|
-
|
|
300
|
-
xlim = _get_ax_lim(hist, axis=0)
|
|
301
|
-
ylim = _get_ax_lim(hist, axis=1)
|
|
302
|
-
|
|
303
|
-
if np.sum(hist["data"]) == 0:
|
|
304
|
-
ax.text(
|
|
305
|
-
0.5,
|
|
306
|
-
0.5,
|
|
307
|
-
"EMPTY",
|
|
308
|
-
horizontalalignment="center",
|
|
309
|
-
verticalalignment="center",
|
|
310
|
-
transform=ax.transAxes,
|
|
311
|
-
)
|
|
312
|
-
return
|
|
313
|
-
|
|
314
|
-
x_bins = _get_bins(hist, axis=0)
|
|
315
|
-
y_bins = _get_bins(hist, axis=1)
|
|
316
|
-
|
|
317
|
-
ax.pcolormesh(x_bins, y_bins, hist["data"])
|
|
318
|
-
ax.set_xlim(xlim)
|
|
319
|
-
ax.set_ylim(ylim)
|
|
320
|
-
|
|
321
|
-
else:
|
|
322
|
-
# 1D histogram
|
|
323
|
-
|
|
324
|
-
xlim = _get_ax_lim(hist, axis=0)
|
|
325
|
-
|
|
326
|
-
if np.sum(hist["data"]) == 0:
|
|
327
|
-
ax.text(
|
|
328
|
-
0.5,
|
|
329
|
-
0.5,
|
|
330
|
-
"EMPTY",
|
|
331
|
-
horizontalalignment="center",
|
|
332
|
-
verticalalignment="center",
|
|
333
|
-
transform=ax.transAxes,
|
|
334
|
-
)
|
|
335
|
-
return
|
|
336
|
-
|
|
337
|
-
x_bins = _get_bins(hist, axis=0)
|
|
338
|
-
centers = 0.5 * (x_bins[:-1] + x_bins[1:])
|
|
339
|
-
ax.hist(centers, bins=x_bins, weights=hist["data"])
|
|
340
|
-
ax.set_xlim(xlim)
|
|
341
|
-
return
|
|
342
|
-
|
|
343
|
-
@property
|
|
344
|
-
def _meta_dict(self):
|
|
345
|
-
"""
|
|
346
|
-
Define the meta dictionary for exporting the histograms.
|
|
347
|
-
|
|
348
|
-
Returns
|
|
349
|
-
-------
|
|
350
|
-
dict
|
|
351
|
-
Meta dictionary for the hdf5 files with the histograms.
|
|
352
|
-
"""
|
|
353
|
-
|
|
354
|
-
if self.__meta_dict is None:
|
|
355
|
-
self.__meta_dict = {
|
|
356
|
-
"simtools_version": version.__version__,
|
|
357
|
-
"note": "Only lower bin edges are given.",
|
|
358
|
-
}
|
|
359
|
-
return self.__meta_dict
|
|
360
|
-
|
|
361
|
-
def export_histograms(self, hdf5_file_name, overwrite=False):
|
|
362
|
-
"""
|
|
363
|
-
Export the histograms to hdf5 files.
|
|
364
|
-
|
|
365
|
-
Parameters
|
|
366
|
-
----------
|
|
367
|
-
hdf5_file_name: str
|
|
368
|
-
Name of the file to be saved with the hdf5 tables.
|
|
369
|
-
overwrite: bool
|
|
370
|
-
If True overwrites the histograms already saved in the hdf5 file.
|
|
371
|
-
"""
|
|
372
|
-
for histogram in self.combined_hists:
|
|
373
|
-
x_bin_edges_list = np.linspace(
|
|
374
|
-
histogram["lower_x"],
|
|
375
|
-
histogram["upper_x"],
|
|
376
|
-
num=histogram["n_bins_x"] + 1,
|
|
377
|
-
endpoint=True,
|
|
378
|
-
)
|
|
379
|
-
if histogram["n_bins_y"] > 0:
|
|
380
|
-
y_bin_edges_list = np.linspace(
|
|
381
|
-
histogram["lower_y"],
|
|
382
|
-
histogram["upper_y"],
|
|
383
|
-
num=histogram["n_bins_y"] + 1,
|
|
384
|
-
endpoint=True,
|
|
385
|
-
)
|
|
386
|
-
else:
|
|
387
|
-
y_bin_edges_list = None
|
|
388
|
-
|
|
389
|
-
self._meta_dict["Title"] = sanitize_name(histogram["title"])
|
|
390
|
-
|
|
391
|
-
table = fill_hdf5_table(
|
|
392
|
-
hist=histogram["data"],
|
|
393
|
-
x_bin_edges=x_bin_edges_list,
|
|
394
|
-
y_bin_edges=y_bin_edges_list,
|
|
395
|
-
x_label=None,
|
|
396
|
-
y_label=None,
|
|
397
|
-
meta_data=self._meta_dict,
|
|
398
|
-
)
|
|
399
|
-
|
|
400
|
-
self._logger.debug(
|
|
401
|
-
f"Writing histogram with name {self._meta_dict['Title']} to " f"{hdf5_file_name}."
|
|
402
|
-
)
|
|
403
|
-
# overwrite takes precedence over append
|
|
404
|
-
if overwrite is True:
|
|
405
|
-
append = False
|
|
406
|
-
else:
|
|
407
|
-
append = True
|
|
408
|
-
write_table(
|
|
409
|
-
table,
|
|
410
|
-
hdf5_file_name,
|
|
411
|
-
f"/{self._meta_dict['Title']}",
|
|
412
|
-
append=append,
|
|
413
|
-
overwrite=overwrite,
|
|
414
|
-
)
|
simtools/simtel/simtel_runner.py
DELETED
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
import logging
|
|
2
|
-
import os
|
|
3
|
-
from pathlib import Path
|
|
4
|
-
|
|
5
|
-
import simtools.utils.general as gen
|
|
6
|
-
from simtools.model.array_model import ArrayModel
|
|
7
|
-
from simtools.model.telescope_model import TelescopeModel
|
|
8
|
-
|
|
9
|
-
__all__ = ["InvalidOutputFile", "SimtelExecutionError", "SimtelRunner"]
|
|
10
|
-
|
|
11
|
-
# pylint: disable=no-member
|
|
12
|
-
# The line above is needed because there are methods which are used in this class
|
|
13
|
-
# but are implemented in the classes inheriting from it.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
class SimtelExecutionError(Exception):
|
|
17
|
-
"""Exception for simtel_array execution error."""
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
class InvalidOutputFile(Exception):
|
|
21
|
-
"""Exception for invalid output file."""
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
class SimtelRunner:
|
|
25
|
-
"""
|
|
26
|
-
SimtelRunner is the base class of the sim_telarray interfaces.
|
|
27
|
-
|
|
28
|
-
Parameters
|
|
29
|
-
----------
|
|
30
|
-
simtel_source_path: str or Path
|
|
31
|
-
Location of sim_telarray installation.
|
|
32
|
-
label: str
|
|
33
|
-
Instance label. Important for output file naming.
|
|
34
|
-
"""
|
|
35
|
-
|
|
36
|
-
def __init__(self, simtel_source_path, label=None):
|
|
37
|
-
"""
|
|
38
|
-
Initialize SimtelRunner.
|
|
39
|
-
"""
|
|
40
|
-
|
|
41
|
-
self._logger = logging.getLogger(__name__)
|
|
42
|
-
|
|
43
|
-
self._simtel_source_path = Path(simtel_source_path)
|
|
44
|
-
self.label = label
|
|
45
|
-
self._script_dir = None
|
|
46
|
-
self._script_file = None
|
|
47
|
-
|
|
48
|
-
self.runs_per_set = 1
|
|
49
|
-
|
|
50
|
-
def __repr__(self):
|
|
51
|
-
return f"SimtelRunner(label={self.label})\n"
|
|
52
|
-
|
|
53
|
-
def _validate_telescope_model(self, tel):
|
|
54
|
-
"""Validate TelescopeModel.
|
|
55
|
-
|
|
56
|
-
Parameters
|
|
57
|
-
----------
|
|
58
|
-
tel: TelescopeModel
|
|
59
|
-
instance of TelescopeModel to validate.
|
|
60
|
-
|
|
61
|
-
Raises
|
|
62
|
-
------
|
|
63
|
-
ValueError
|
|
64
|
-
if there 'tel' is not an TelescopeModel instance.
|
|
65
|
-
"""
|
|
66
|
-
if isinstance(tel, TelescopeModel):
|
|
67
|
-
self._logger.debug("TelescopeModel is valid")
|
|
68
|
-
return tel
|
|
69
|
-
|
|
70
|
-
msg = "Invalid TelescopeModel"
|
|
71
|
-
self._logger.error(msg)
|
|
72
|
-
raise ValueError(msg)
|
|
73
|
-
|
|
74
|
-
def _validate_array_model(self, array):
|
|
75
|
-
"""Validate ArrayModel
|
|
76
|
-
|
|
77
|
-
Parameters
|
|
78
|
-
----------
|
|
79
|
-
array: ArrayModel
|
|
80
|
-
Instance of ArrayModel to validate.
|
|
81
|
-
|
|
82
|
-
Raises
|
|
83
|
-
------
|
|
84
|
-
ValueError
|
|
85
|
-
if there 'array' is not an ArrayModel instance.
|
|
86
|
-
"""
|
|
87
|
-
if isinstance(array, ArrayModel):
|
|
88
|
-
self._logger.debug("ArrayModel is valid")
|
|
89
|
-
return array
|
|
90
|
-
|
|
91
|
-
msg = "Invalid ArrayModel"
|
|
92
|
-
self._logger.error(msg)
|
|
93
|
-
raise ValueError(msg)
|
|
94
|
-
|
|
95
|
-
def prepare_run_script(self, test=False, input_file=None, run_number=None, extra_commands=None):
|
|
96
|
-
"""
|
|
97
|
-
Builds and returns the full path of the bash run script containing the sim_telarray command.
|
|
98
|
-
|
|
99
|
-
Parameters
|
|
100
|
-
----------
|
|
101
|
-
test: bool
|
|
102
|
-
Test flag for faster execution.
|
|
103
|
-
input_file: str or Path
|
|
104
|
-
Full path of the input CORSIKA file.
|
|
105
|
-
run_number: int
|
|
106
|
-
Run number.
|
|
107
|
-
extra_commands: str
|
|
108
|
-
Additional commands for running simulations given in config.yml.
|
|
109
|
-
|
|
110
|
-
Returns
|
|
111
|
-
-------
|
|
112
|
-
Path
|
|
113
|
-
Full path of the run script.
|
|
114
|
-
"""
|
|
115
|
-
self._logger.debug("Creating run bash script")
|
|
116
|
-
|
|
117
|
-
self._script_dir = self._base_directory.joinpath("scripts")
|
|
118
|
-
self._script_dir.mkdir(parents=True, exist_ok=True)
|
|
119
|
-
self._script_file = self._script_dir.joinpath(
|
|
120
|
-
f"run{run_number if run_number is not None else ''}-simtel"
|
|
121
|
-
)
|
|
122
|
-
self._logger.debug(f"Run bash script - {self._script_file}")
|
|
123
|
-
|
|
124
|
-
self._logger.debug(f"Extra commands to be added to the run script {extra_commands}")
|
|
125
|
-
|
|
126
|
-
command = self._make_run_command(input_file=input_file, run_number=run_number)
|
|
127
|
-
with self._script_file.open("w", encoding="utf-8") as file:
|
|
128
|
-
file.write("#!/usr/bin/env bash\n\n")
|
|
129
|
-
|
|
130
|
-
# Make sure to exit on failed commands and report their error code
|
|
131
|
-
file.write("set -e\n")
|
|
132
|
-
file.write("set -o pipefail\n")
|
|
133
|
-
|
|
134
|
-
# Setting SECONDS variable to measure runtime
|
|
135
|
-
file.write("\nSECONDS=0\n")
|
|
136
|
-
|
|
137
|
-
if extra_commands is not None:
|
|
138
|
-
file.write("# Writing extras\n")
|
|
139
|
-
for line in extra_commands:
|
|
140
|
-
file.write(f"{line}\n")
|
|
141
|
-
file.write("# End of extras\n\n")
|
|
142
|
-
|
|
143
|
-
n = 1 if test else self.runs_per_set
|
|
144
|
-
for _ in range(n):
|
|
145
|
-
file.write(f"{command}\n\n")
|
|
146
|
-
|
|
147
|
-
# Printing out runtime
|
|
148
|
-
file.write('\necho "RUNTIME: $SECONDS"\n')
|
|
149
|
-
|
|
150
|
-
os.system(f"chmod ug+x {self._script_file}")
|
|
151
|
-
return self._script_file
|
|
152
|
-
|
|
153
|
-
def run(self, test=False, force=False, input_file=None, run_number=None):
|
|
154
|
-
"""
|
|
155
|
-
Basic sim_telarray run method.
|
|
156
|
-
|
|
157
|
-
Parameters
|
|
158
|
-
----------
|
|
159
|
-
test: bool
|
|
160
|
-
If True, make simulations faster.
|
|
161
|
-
force: bool
|
|
162
|
-
If True, remove possible existing output files and run again.
|
|
163
|
-
"""
|
|
164
|
-
self._logger.debug("Running sim_telarray")
|
|
165
|
-
|
|
166
|
-
if not hasattr(self, "_make_run_command"):
|
|
167
|
-
msg = "run method cannot be executed without the _make_run_command method"
|
|
168
|
-
self._logger.error(msg)
|
|
169
|
-
raise RuntimeError(msg)
|
|
170
|
-
|
|
171
|
-
if not self._shall_run(run_number=run_number) and not force:
|
|
172
|
-
self._logger.info("Skipping because output exists and force = False")
|
|
173
|
-
return
|
|
174
|
-
|
|
175
|
-
command = self._make_run_command(input_file=input_file, run_number=run_number)
|
|
176
|
-
|
|
177
|
-
if test:
|
|
178
|
-
self._logger.info(f"Running (test) with command: {command}")
|
|
179
|
-
self._run_simtel_and_check_output(command)
|
|
180
|
-
else:
|
|
181
|
-
self._logger.debug(f"Running ({self.runs_per_set}x) with command: {command}")
|
|
182
|
-
self._run_simtel_and_check_output(command)
|
|
183
|
-
|
|
184
|
-
for _ in range(self.runs_per_set - 1):
|
|
185
|
-
self._run_simtel_and_check_output(command)
|
|
186
|
-
|
|
187
|
-
self._check_run_result(run_number=run_number)
|
|
188
|
-
|
|
189
|
-
@staticmethod
|
|
190
|
-
def _simtel_failed(sys_output):
|
|
191
|
-
"""Test if simtel process ended successfully.
|
|
192
|
-
|
|
193
|
-
Returns
|
|
194
|
-
-------
|
|
195
|
-
bool
|
|
196
|
-
1 if sys_output is different than 0, and 1 otherwise.
|
|
197
|
-
"""
|
|
198
|
-
return sys_output != 0
|
|
199
|
-
|
|
200
|
-
def _raise_simtel_error(self):
|
|
201
|
-
"""
|
|
202
|
-
Raise sim_telarray execution error. Final 30 lines from the log file are collected and \
|
|
203
|
-
printed.
|
|
204
|
-
|
|
205
|
-
Raises
|
|
206
|
-
------
|
|
207
|
-
SimtelExecutionError
|
|
208
|
-
"""
|
|
209
|
-
|
|
210
|
-
if hasattr(self, "_log_file"):
|
|
211
|
-
msg = gen.get_log_excerpt(self._log_file)
|
|
212
|
-
else:
|
|
213
|
-
msg = "Simtel log file does not exist."
|
|
214
|
-
|
|
215
|
-
self._logger.error(msg)
|
|
216
|
-
raise SimtelExecutionError(msg)
|
|
217
|
-
|
|
218
|
-
def _run_simtel_and_check_output(self, command):
|
|
219
|
-
"""
|
|
220
|
-
Run the sim_telarray command and check the exit code.
|
|
221
|
-
|
|
222
|
-
Raises
|
|
223
|
-
------
|
|
224
|
-
SimtelExecutionError
|
|
225
|
-
if run was not successful.
|
|
226
|
-
"""
|
|
227
|
-
sys_output = os.system(command)
|
|
228
|
-
if self._simtel_failed(sys_output):
|
|
229
|
-
self._raise_simtel_error()
|
|
230
|
-
|
|
231
|
-
def _shall_run(self, **kwargs): # pylint: disable=unused-argument; applies only to this line
|
|
232
|
-
self._logger.debug(
|
|
233
|
-
"shall_run is being called from the base class - returning False -"
|
|
234
|
-
"it should be implemented in the sub class"
|
|
235
|
-
)
|
|
236
|
-
return False
|
|
237
|
-
|
|
238
|
-
@staticmethod
|
|
239
|
-
def _config_option(par, value=None, weak_option=False):
|
|
240
|
-
"""Util function for building sim_telarray command."""
|
|
241
|
-
option_syntax = "-W" if weak_option else "-C"
|
|
242
|
-
c = f" {option_syntax} {par}"
|
|
243
|
-
c += f"={value}" if value is not None else ""
|
|
244
|
-
return c
|