Commit 35d6d820 authored by georgios.voutsinas's avatar georgios.voutsinas
Browse files

python script that parses Corsika directories and creates configs on the fly + config template

parent a6e84349
Pipeline #3825017 passed with stages
in 30 minutes and 17 seconds
# Configuration file for IACT simulations configured for CI in docker container
[environment]
[environment.submission]
run_directory = "/tmp/sim_runner"
tool = "slurm" # Either local, sge or slurm are supported
job_template = "/home/georgios.voutsinas/ws/AllSky/run_directory/sim_runner/sim_runner/templates/sim_telarray_slurm.job"
[environment.corsika]
version = "6.9"
temporary_local_configuration_path = '/tmp/corsika-config'
[environment.sim_telarray]
software_intallation_path = '/opt/sim_telarray/bin'
version = "2020-06-29"
temporary_local_configuration_path = '/tmp/sim_telarray-config'
configuration_repository = 'https://github.com/cta-observatory/lst-sim-config.git'
tag = "sim-telarray-lst-magic-prod2-v1.3"
# Main configuration file in the tagged configuration, which links the rest configuration files together
entry_point = "array.cfg"
input_path = @input_path@
output_path = @output_path@
# Expert-only options
# Change this option to use non-versionned config
# Use at your own risk. Not recommended.
# The config has to be placed under temporary_local_configuration_path
use_non_tagged_configuration = false
[process]
#dry_run = true # Read all configurations, generate job log header but do not run actual simulation
dry_run = false # Read all configurations, generate job log header but do not run actual simulation
stage = 'sim_telarray' # could be either corsika or sim_telarray. For the moment only latter is supported
production_type = "gamma"
extract_calibration = false
[process.parameter_scan]
particle_type = 'gamma'
parameter_block = 'trigger'
parameter = 'asum_threshold'
initial = 0
final = 0
step = 0
[corsika]
placeholder = true # corsika running is not supported yet
[sim_telarray]
[sim_telarray.preprocessor]
NUM_TELESCOPES = 3
NO_STEREO_TRIGGER = 1
power_law = 2.68
[sim_telarray.telescope]
telescope_phi = @phi@
telescope_zenith_angle = @theta@ # commonly named θ
[sim_telarray.global_parameters]
altitude = 2158
random_state = 'auto'
ATMOSPHERIC_TRANSMISSION = 'atm_trans_2158_1_3_2_0_0_0.1_0.1.dat'
maximum_telescopes = 3
show = 'all' # Show all parameters at the beginning of each job
[meta]
telescope_array_name = "LST-MAGIC-PROD2"
import os
list_of_parameters = ["theta", "phi"]
# input file
ifile = "/home/voutsi/Work/testarea/ParsingDirTree/test_parameter_card_slurm.toml"
rootdir = "/home/voutsi/Work/testarea/ParsingDirTree/GammaDiffuse/Corsika/"
def find_parameter_value(input_file_name, first, last="_"):
"""
function that allows simtelarray to grep the value of the parameter
used to create the corsika file, from the filename
:param str input_file_name: the corsika input file name
:param str first: the name of the parameter + character '_'
:param str last: the character following the parameter value, which is '_' with the current naming.
"""
try:
start = input_file_name.index(first) + len(first)
end = input_file_name.index(last, start)
return input_file_name[start:end]
except ValueError:
# TODO issue warning message or throw an exception
return ""
def replace_strings_in_file_2(ifile, idir, odir, zd, az):
"""
reads the template config file into a string
updates fields according to files in the Corsika directory
writes string into a new config file and copies it in the relevant directory
:param str ifile: path & name of template config
:param str idir: directory with Corsika files
:param str odir: the directory where the simtel files will be written
:param str zd: zenith angle, set on the fly
:param str az: azimuth angle, set on the fly
"""
fin = open(ifile, "rt")
# output file to write the result to
fout = open(odir + "/test.toml", "w+")
template_config = fin.read()
upd_config = template_config
upd_config = upd_config.replace("@input_path@", idir)
upd_config = upd_config.replace("@output_path@", odir + "/simtel_")
upd_config = upd_config.replace("@theta@", zd)
upd_config = upd_config.replace("@phi@", az)
fout.write(upd_config)
fin.close()
fout.close()
for root, dirs, files in os.walk(rootdir):
for c in dirs:
print("directory", c)
idir = rootdir + c
odir = "/home/voutsi/Work/testarea/ParsingDirTree/GammaDiffuse/Simtel/" + c
os.makedirs(odir, exist_ok=True)
for par in list_of_parameters:
value = find_parameter_value(str(c), str(par) + "_", "_")
print("parameter", par, "value", value)
if str(par) == "theta":
zd = value
if str(par) == "phi":
az = value
replace_strings_in_file_2(ifile, idir, odir, zd, az)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment