Coverage for rta_to_lstchain_formator/disp.py: 11%

14 statements  

« prev     ^ index     » next       coverage.py v7.6.9, created at 2024-12-25 05:21 +0000

1import numpy as np 

2 

3 

4# copied from https://github.com/cta-observatory/cta-lstchain/blob/v0.10.7/lstchain/reco/disp.py#L16 

5# to avoid dependency on entire lstchain 

6def disp(cog_x, cog_y, src_x, src_y, hillas_psi): 

7 """ 

8 Compute the disp parameters 

9 

10 Parameters 

11 ---------- 

12 cog_x: `numpy.ndarray` or float 

13 cog_y: `numpy.ndarray` or float 

14 src_x: `numpy.ndarray` or float 

15 src_y: `numpy.ndarray` or float 

16 hillas_psi: `numpy.ndarray` or float 

17 

18 Returns 

19 ------- 

20 (disp_dx, disp_dy, disp_norm, disp_angle, disp_sign): 

21 disp_dx: 'astropy.units.m` 

22 disp_dy: 'astropy.units.m` 

23 disp_norm: 'astropy.units.m` 

24 disp_angle: 'astropy.units.rad` 

25 disp_sign: `numpy.ndarray` 

26 """ 

27 disp_dx = src_x - cog_x 

28 disp_dy = src_y - cog_y 

29 

30 disp_norm = disp_dx * np.cos(hillas_psi) + disp_dy * np.sin(hillas_psi) 

31 disp_sign = np.sign(disp_norm) 

32 disp_norm = np.abs(disp_norm) 

33 

34 # disp_sign : indicates in which direction, "positive" or "negative", we must move along the 

35 # reconstructed image axis (with direction defined by the versor cos(hillas_psi), sin(hillas_psi)) 

36 # we must move from cog_x, cog_y to get closest to the true direction (src_x, src_y) 

37 

38 if hasattr(disp_dx, "__len__"): 

39 disp_angle = np.arctan(disp_dy / disp_dx) 

40 disp_angle[disp_dx == 0] = np.pi / 2.0 * np.sign(disp_dy[disp_dx == 0]) 

41 else: 

42 if disp_dx == 0: 

43 disp_angle = np.pi / 2.0 * np.sign(disp_dy) 

44 else: 

45 disp_angle = np.arctan(disp_dy / disp_dx) 

46 

47 return disp_dx, disp_dy, disp_norm, disp_angle, disp_sign