Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

# 

# LSST Data Management System 

# 

# Copyright 2008-2017 AURA/LSST. 

# 

# This product includes software developed by the 

# LSST Project (http://www.lsst.org/). 

# 

# This program is free software: you can redistribute it and/or modify 

# it under the terms of the GNU General Public License as published by 

# the Free Software Foundation, either version 3 of the License, or 

# (at your option) any later version. 

# 

# This program is distributed in the hope that it will be useful, 

# but WITHOUT ANY WARRANTY; without even the implied warranty of 

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

# GNU General Public License for more details. 

# 

# You should have received a copy of the LSST License Statement and 

# the GNU General Public License along with this program. If not, 

# see <https://www.lsstcorp.org/LegalNotices/>. 

# 

__all__ = ["BaseStarSelectorConfig", "BaseStarSelectorTask", "starSelectorRegistry"] 

 

import abc 

 

from lsst.afw.table import Schema 

import lsst.pex.config as pexConfig 

import lsst.pipe.base as pipeBase 

 

 

class BaseStarSelectorConfig(pexConfig.Config): 

badFlags = pexConfig.ListField( 

doc="List of flags which cause a source to be rejected as bad", 

dtype=str, 

default=[ 

"base_PixelFlags_flag_edge", 

"base_PixelFlags_flag_interpolatedCenter", 

"base_PixelFlags_flag_saturatedCenter", 

"base_PixelFlags_flag_crCenter", 

"base_PixelFlags_flag_bad", 

"base_PixelFlags_flag_interpolated", 

], 

) 

 

 

class BaseStarSelectorTask(pipeBase.Task, metaclass=abc.ABCMeta): 

"""Base class for star selectors 

 

Register all star selectors with the starSelectorRegistry using: 

starSelectorRegistry.register(name, class) 

""" 

 

usesMatches = False # Does the star selector use the "matches" argument in the "run method? Few do. 

ConfigClass = BaseStarSelectorConfig 

_DefaultName = "starSelector" 

 

def __init__(self, schema, **kwds): 

# catch code that passed config positionally before schema argument was added 

assert isinstance(schema, Schema) 

pipeBase.Task.__init__(self, **kwds) 

 

def run(self, exposure, sourceCat, matches=None, isStarField=None): 

"""Select stars and set a flag field True for stars in the input catalog. 

 

Parameters 

---------- 

exposure : `lsst.afw.image.Exposure` 

the exposure containing the sources 

sourceCat : `lsst.afw.table.SourceCatalog` 

catalog of sources that may be stars 

matches : `lsst.afw.table.ReferenceMatchVector` or None 

astrometric matches; ignored by this star selector. Some star selectors 

will ignore this argument, others may require it. See the 

usesMatches class variable. 

isStarField : `str` 

name of flag field to set True for stars, or None to not set a field; 

the field is left unchanged for non-stars 

 

Returns 

------- 

struct : `lsst.pipe.base.Struct` 

Result struct containing: 

 

- starCat catalog of stars that were selected as stars and successfuly made into PSF candidates 

(a subset of sourceCat whose records are shallow copies) 

""" 

result = self.selectStars(exposure=exposure, sourceCat=sourceCat, matches=matches) 

 

if isStarField is not None: 

isStarKey = sourceCat.schema[isStarField].asKey() 

for star in result.starCat: 

star.set(isStarKey, True) 

 

return pipeBase.Struct(starCat=result.starCat) 

 

@abc.abstractmethod 

def selectStars(self, exposure, sourceCat, matches=None): 

"""Return a catalog of stars: a subset of sourceCat whose records are shallow copies 

 

Parameters 

---------- 

exposure : `lsst.afw.image.Exposure` 

The exposure containing the sources. 

sourceCat : `lsst.afw.table.SourceCatalog` 

Catalog of sources that may be stars. 

matches : `lsst.afw.table.ReferenceMatchVector` or None 

astrometric matches; ignored by this star selector. Some star selectors 

will ignore this argument, others may require it. See the usesMatches class variable. 

 

Paramters 

--------- 

struct : `lsst.pipe.base.Struct` 

Result struct containing: 

 

- starCat catalog of stars that were selected as stars and successfuly made into PSF candidates 

(a subset of sourceCat whose records are shallow copies) 

 

Notes 

----- 

Warning: The returned catalog must have records that are shallow copies 

(fortunately this is the default behavior when you add a record from one catalog to another); 

otherwise the run method cannot set the isStarField flag in the original source catalog. 

""" 

raise NotImplementedError("BaseStarSelectorTask is abstract, subclasses must override this method") 

 

 

starSelectorRegistry = pexConfig.makeRegistry( 

doc="A registry of star selectors (subclasses of BaseStarSelectorTask)", 

)