Coverage for src/ufig/plugins/single_band_setup_intrinsic_only.py: 100%

28 statements  

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

1# Copyright (C) 2024 ETH Zurich 

2# Institute for Particle Physics and Astrophysics 

3# Author: Silvan Fischbacher 

4# created: Thu Aug 08 2024 

5 

6 

7import numpy as np 

8from ivy.plugin.base_plugin import BasePlugin 

9 

10from ufig.plugins.single_band_setup import initialize_shape_size_columns 

11 

12NAME = "setup single-band (intrinsic only)" 

13 

14 

15class Plugin(BasePlugin): 

16 """ 

17 Set parameters for catalogs of only intrisic properties (no image simulation) 

18 """ 

19 

20 def __call__(self): 

21 par = self.ctx.parameters 

22 

23 np.random.seed(par.seed) 

24 

25 filter_band_params = [ 

26 param_name for param_name in par if param_name.endswith("_dict") 

27 ] 

28 for param_name in filter_band_params: 

29 try: 

30 param_name_stripped = param_name[:-5] 

31 setattr( 

32 par, 

33 param_name_stripped, 

34 getattr(par, param_name)[self.ctx.current_filter], 

35 ) 

36 except KeyError: 

37 pass 

38 

39 if "galaxies" in self.ctx: 

40 add_galaxy_col = [ 

41 "gamma1", 

42 "gamma2", 

43 "kappa", 

44 "e1", 

45 "e2", 

46 "r50", 

47 "int_mag", 

48 "mag", 

49 "abs_mag", 

50 ] 

51 

52 self.ctx.galaxies.columns = list( 

53 set(self.ctx.galaxies.columns) | set(add_galaxy_col) 

54 ) 

55 

56 # Initial values for galaxy shapes 

57 initialize_shape_size_columns( 

58 self.ctx.galaxies, self.ctx.numgalaxies, precision=par.catalog_precision 

59 ) 

60 

61 # Magnitudes and numbers of photons 

62 self.ctx.galaxies.int_mag = self.ctx.galaxies.int_magnitude_dict[ 

63 self.ctx.current_filter 

64 ].astype(par.catalog_precision) 

65 self.ctx.galaxies.abs_mag = self.ctx.galaxies.abs_magnitude_dict[ 

66 self.ctx.current_filter 

67 ].astype(par.catalog_precision) 

68 self.ctx.galaxies.mag = self.ctx.galaxies.magnitude_dict[ 

69 self.ctx.current_filter 

70 ].astype(par.catalog_precision) 

71 

72 if "stars" in self.ctx: 

73 add_star_col = [ 

74 "mag", 

75 ] 

76 

77 self.ctx.stars.columns = list( 

78 set(self.ctx.stars.columns) | set(add_star_col) 

79 ) 

80 

81 # Magnitudes and numbers of photons 

82 self.ctx.stars.mag = self.ctx.stars.magnitude_dict[self.ctx.current_filter] 

83 

84 def __str__(self): 

85 return NAME