22"""Task to make a flexible and repeatable selection of reserve stars.
25__all__ = [
'ReserveIsolatedStarsConfig',
26 'ReserveIsolatedStarsTask']
32import lsst.pipe.base
as pipeBase
36 """Configuration for ReserveIsolatedStarsTask."""
37 reserve_name = pexConfig.Field(
38 doc=
'Name to use for random seed selection hash.',
42 reserve_fraction = pexConfig.RangeField(
43 doc=
'Fraction of stars to reserve. None if == 0.',
54 """Reserve isolated stars with repeatable hash."""
55 ConfigClass = ReserveIsolatedStarsConfig
56 _DefaultName =
'reserve_isolated_stars'
58 def run(self, nstar, extra=''):
59 """Retrieve a selection of reserved stars.
64 Number of stars to select from.
65 extra : `str`, optional
66 Extra name to appended to reserve_name, often tract
or pixel,
67 and may be combined
with band name.
71 selection : `np.ndarray` (N,)
72 Boolean index array,
with ``
True``
for reserved stars.
74 selection = np.zeros(nstar, dtype=bool)
76 if self.config.reserve_fraction == 0.0:
80 name = self.config.reserve_name +
'_' + extra
83 hex_hash = hashlib.sha256(name.encode(
'UTF-8')).hexdigest()
84 seed = int(
'0x' + hex_hash, 0) & 0xFFFFFFFF
86 rng = np.random.default_rng(seed)
88 selection[:int(nstar*self.config.reserve_fraction)] =
True
89 rng.shuffle(selection)