Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import os
from pathlib import Path
from utils import (
parse_arguments,
get_config,
manage_submission,
get_coordinates,
)
# Argument parsera
args = parse_arguments(description="DL2 to DL3 converter",
add_job=True,
add_run=True,
add_dl3=True)
config_file = get_config(args.config)
# manage the target
ra, dec = get_coordinates(args)
# manage the cuts
if args.cut_file is not None:
cut_file = config_file['cut_folder'] + "/" + args.cut_file
print("Using cut file:", cut_file)
else:
print("Standard cuts will be used in the analysis.")
irf = config_file['irf_file']
for night in config_file['dl2_data']['night']:
# output directory
dl3_out_dir = config_file['base_dir'] + '/DL3/' + args.source_name + '/' + str(night) + '/' + config_file['dl2_data']['version'] + '/' + config_file['dl2_data']['cleaning']
if args.outdir is not None:
dl3_out_dir = args.outdir
dl2_dir = config_file['base_dir'] + '/DL2/' + args.source_name + '/' + str(night) + '/' + config_file['dl2_data']['version'] + '/' + config_file['dl2_data']['cleaning']
files = Path(dl2_dir).glob('dl2*.h5')
for file in files:
dl3_cmd = (
f'lstchain_create_dl3_file -d {file} '
f'-o {dl3_out_dir} '
f'--input-irf {irf} '
f'--source-name {args.source_name} '
f'--source-ra "{ra}deg" '
f'--source-dec "{dec}deg" '
f'{"--overwrite " if args.globber is not False else ""}'
)
if args.cut_file is not None:
dl3_cmd += f'--config {args.cut_file}'
if args.gh_cut:
dl3_cmd += f'--fixed-gh-cut {args.gh_cut}'
if args.theta_cut:
dl3_cmd += f'--fixed-theta-cut {args.theta_cut}'
if args.verbose:
print('\n')
print(dl3_cmd)
if not(args.dry):
if args.submit:
# create the script that will be submited and return the name of the script in the variable scriptname
scriptname = manage_submission(args, config_file, dl3_cmd, os.path.basename(file))
os.system("sbatch " + scriptname)
else:
print('Interactive conversion of the DL2 to DL3.')
os.system(dl3_cmd)