Coverage for hiperta_stream/scripts/offline_alt_az_dl1_maker.py: 0%

26 statements  

« prev     ^ index     » next       coverage.py v7.4.3, created at 2024-07-16 10:16 +0000

1#!/usr/bin/env python 

2# S. Caroff 

3 

4""" 

5OFFLINE analysis: 

6Looks into a drive log file the AltAz of the DL1 events, and updates them on the DL1 file. 

7 

8Usage: 

9$> rta_fake_alt_az 

10 --input-file "./dl1_5202_0_10000evt.h5" 

11 --drive-log "/fefs/aswg/data/real/monitoring/DrivePositioning/drive_log2_21_07_08.txt" 

12""" 

13 

14import argparse 

15import numpy as np 

16import tables 

17import os 

18 

19 

20def main(): 

21 parser = argparse.ArgumentParser(description="Offline AltAz DL1 maker") 

22 

23 # Required arguments 

24 parser.add_argument('--input-file', '-f', type=str, 

25 dest='input_file', 

26 help='DL1 file, example : "dl1_5202_0_10000evt.h5"', 

27 default=None, required=True 

28 ) 

29 

30 parser.add_argument('--drive-log', '-d', type=str, 

31 dest='drive_log', 

32 help='Path to log drive, ' 

33 'example : "/fefs/aswg/data/real/monitoring/DrivePositioning/drive_log_21_07_08.txt"', 

34 default="/fefs/aswg/data/real/monitoring/DrivePositioning/drive_log_21_07_08.txt", 

35 required=False 

36 ) 

37 

38 args = parser.parse_args() 

39 

40 input_file = args.input_file # "dl3_LST-1.Run04190.*.fits" 

41 drive_log = args.drive_log 

42 

43 hfile = tables.open_file(input_file, mode="r+") 

44 

45 Trigger_time = hfile.root.dl1.event.telescope.parameters.tel_001.col("trigger_time") 

46 test = np.genfromtxt(drive_log) 

47 

48 tabAz_Tel = np.interp(Trigger_time, test[:, 5], test[:, 7]) 

49 tabAlt_Tel = np.interp(Trigger_time, test[:, 5], 90.-test[:, 12]) 

50 tabAz_Tel = np.deg2rad(tabAz_Tel) 

51 tabAlt_Tel = np.deg2rad(tabAlt_Tel) 

52 for i in range(len(tabAlt_Tel)): 

53 hfile.root.dl1.event.telescope.parameters.tel_001.cols.alt_tel[i] = tabAlt_Tel[i] 

54 hfile.root.dl1.event.telescope.parameters.tel_001.cols.az_tel[i] = tabAz_Tel[i] 

55 

56 print(f"{os.path.basename(input_file)} - Last AltAz value added to the file: {tabAz_Tel[-1]}") 

57 

58 hfile.close() 

59 

60 

61if __name__ == '__main__': 

62 main()