69 def run(self, sources, prior=None, expId=0):
70 """Select sources to be reserved
72 Reserved sources will be flagged in the catalog, and we will return
73 boolean arrays that identify the sources to be reserved from and
74 used in the analysis. Typically you'll want to use the sources
75 from the `use` array in your fitting, and use the sources from the
76 `reserved` array as an independent test of your fitting.
80 sources : `lsst.afw.table.Catalog` or `list` of `lsst.afw.table.Record`
81 Sources from which to select some to be reserved.
82 prior : `numpy.ndarray` of type `bool`, optional
83 Prior selection of sources. Should have the same length as
84 `sources`. If set, we will only consider for reservation sources
85 that are flagged `True` in this array.
87 Exposure identifier; used for seeding the random number generator.
91 results : `lsst.pipe.base.Struct`
92 The results in a `~lsst.pipe.base.Struct`:
95 Sources to be reserved are flagged `True` in this array.
96 (`numpy.ndarray` of type `bool`)
98 Sources the user should use in analysis are flagged `True`.
99 (`numpy.ndarray` of type `bool`)
101 if prior
is not None:
102 assert len(prior) == len(sources),
"Length mismatch: %s vs %s" % (len(prior), len(sources))
103 numSources = prior.sum()
105 numSources = len(sources)
106 selection = self.
select(numSources, expId)
107 if prior
is not None:
110 self.log.info(
"Reserved %d/%d sources", selection.sum(), len(selection))
111 return Struct(reserved=selection,
112 use=prior & ~selection
if prior
is not None else np.logical_not(selection))
115 """Randomly select some sources
117 We return a boolean array with a random selection. The fraction
118 of sources selected is specified by the config parameter `fraction`.
123 Number of sources in catalog from which to select.
125 Exposure identifier; used for seeding the random number generator.
129 selection : `numpy.ndarray` of type `bool`
130 Selected sources are flagged `True` in this array.
132 selection = np.zeros(numSources, dtype=bool)
133 if self.config.fraction <= 0:
135 reserve = int(np.round(numSources*self.config.fraction))
136 selection[:reserve] =
True
137 rng = np.random.RandomState((self.config.seed + expId) & 0xFFFFFFFF)
138 rng.shuffle(selection)