Coverage for src/ufig/plugins/read_in_catalog.py: 89%

27 statements  

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

1# Copyright (c) 2015 ETH Zurich, Institute of Astronomy, Claudio Bruderer 

2# <claudio.bruderer@phys.ethz.ch> 

3""" 

4Created on May 30, 2015 

5@author: Claudio Bruderer, adapted by Silvan Fischbacher 

6""" 

7 

8import numpy as np 

9from cosmic_toolbox import file_utils 

10from ivy.plugin.base_plugin import BasePlugin 

11 

12 

13class Catalog: 

14 pass 

15 

16 

17class Plugin(BasePlugin): 

18 """ 

19 Write star and galaxy catalogs to fits tables. These catalogs are the ufig input 

20 catalog, ie. the parameters directly associated with the image. 

21 

22 :param overwrite: whether to overwrite existing image 

23 :param galaxy_catalog_name: name of output galaxy catalog 

24 :param star_catalog_name: name of output star catalog 

25 

26 :return: star and galaxy catalog 

27 

28 """ 

29 

30 def __call__(self): 

31 f = self.ctx.current_filter 

32 par = self.ctx.parameters 

33 self.ctx.galaxies = Catalog() 

34 

35 galaxy_catalog = file_utils.read_from_hdf(par.galaxy_catalog_name_dict[f]) 

36 self.ctx.galaxies.columns = list(galaxy_catalog.dtype.names) 

37 

38 for column in galaxy_catalog.dtype.names: 

39 if column == "nphot" or column == "id": 39 ↛ 40line 39 didn't jump to line 40 because the condition on line 39 was never true

40 setattr( 

41 self.ctx.galaxies, 

42 column, 

43 np.array(galaxy_catalog[column], dtype=np.int), 

44 ) 

45 else: 

46 setattr( 

47 self.ctx.galaxies, 

48 column, 

49 np.array(galaxy_catalog[column], dtype=np.float32), 

50 ) 

51 

52 self.ctx.stars = Catalog() 

53 

54 star_catalog = file_utils.read_from_hdf(par.star_catalog_name) 

55 self.ctx.stars.columns = list(star_catalog.dtype.names) 

56 

57 for column in star_catalog.dtype.names: 

58 if column == "nphot" or column == "id": 58 ↛ 59line 58 didn't jump to line 59 because the condition on line 58 was never true

59 setattr( 

60 self.ctx.stars, column, np.array(star_catalog[column], dtype=np.int) 

61 ) 

62 else: 

63 setattr( 

64 self.ctx.stars, 

65 column, 

66 np.array(star_catalog[column], dtype=np.float32), 

67 ) 

68 

69 self.ctx.numgalaxies = len(galaxy_catalog) 

70 self.ctx.numstars = len(star_catalog) 

71 

72 def __str__(self): 

73 return "read in fits catalog"