Coverage for src/ufig/se_moment_util.py: 100%

18 statements  

« prev     ^ index     » next       coverage.py v7.10.2, created at 2025-08-07 15:17 +0000

1import numpy as np 

2from cosmic_toolbox import arraytools as at 

3from cosmic_toolbox import logger 

4 

5LOGGER = logger.get_logger(__file__) 

6 

7 

8def moments_to_distortion(x2, y2, xy): 

9 """ 

10 Convert SExtractor second moments to ellipticity parameters. 

11 

12 :param x2: Second moments in x-direction (X2WIN_IMAGE from SExtractor) 

13 :param y2: Second moments in y-direction (Y2WIN_IMAGE from SExtractor 

14 :param xy: Cross moments (XYWIN_IMAGE from SExtractor) 

15 :return: e1, e2, r50: Ellipticity components and effective radius 

16 """ 

17 x2 = np.asarray(x2) 

18 y2 = np.asarray(y2) 

19 xy = np.asarray(xy) 

20 

21 e1 = (x2 - y2) / (x2 + y2) 

22 e2 = (2.0 * xy) / (x2 + y2) 

23 r50 = np.sqrt((x2 + y2) / (2.0 * np.log(2))) 

24 return e1, e2, r50 

25 

26 

27def get_se_cols(cat): 

28 # add columns 

29 list_new_cols = ["se_mom_e1:f4", "se_mom_e2:f4", "se_mom_fwhm:f4", "se_mom_win:f4"] 

30 

31 cat = at.ensure_cols(rec=cat, names=list_new_cols) 

32 

33 # Shape from momemts 

34 ( 

35 cat["se_mom_e1"], 

36 cat["se_mom_e2"], 

37 cat["se_mom_fwhm"], 

38 ) = moments_to_distortion( 

39 x2=cat["X2WIN_IMAGE"], y2=cat["Y2WIN_IMAGE"], xy=cat["XYWIN_IMAGE"] 

40 ) 

41 cat["se_mom_win"] = cat["FLUX_RADIUS"] * 2 / np.sqrt(8 * np.log(2)) 

42 return cat