Skip to content

Commit

Permalink
Fix index error when not specifying any requiredBands.
Browse files Browse the repository at this point in the history
  • Loading branch information
erykoff committed Mar 22, 2023
1 parent dc58cc5 commit fff9ce0
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions python/lsst/fgcmcal/fgcmBuildFromIsolatedStars.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,19 +456,33 @@ def _make_all_star_obs_from_isolated_stars(
self.log.info("No good sources found in tract %d", tract)
continue

# Need to re-sum numbers of observations of each star in the required bands.
# Need to count the observations of each star after cuts, per band.
# If we have requiredBands specified, we must make sure that each star
# has the minumum number of observations in each of thos bands.
# Otherwise, we must make sure that each star has at least the minimum
# number of observations in _any_ band.
if len(self.config.requiredBands) > 0:
n_req = np.zeros((len(self.config.requiredBands), len(stars)), dtype=np.int32)
for i, band in enumerate(self.config.requiredBands):
(band_use,) = (sources[good_sources]["band"] == band).nonzero()
np.add.at(
n_req,
(i, sources[good_sources]["obj_index"][band_use]),
1,
)
loop_bands = self.config.requiredBands
else:
loop_bands = np.unique(sources['band'])

n_req = np.zeros((len(loop_bands), len(stars)), dtype=np.int32)
for i, band in enumerate(loop_bands):
(band_use,) = (sources[good_sources]["band"] == band).nonzero()
np.add.at(
n_req,
(i, sources[good_sources]["obj_index"][band_use]),
1,
)

if len(self.config.requiredBands) > 0:
# The min gives us the band with the fewest observations, which must be
# above the limit.
(good_stars,) = (n_req.min(axis=0) >= self.config.minPerBand).nonzero()
else:
good_stars = np.arange(len(stars))
# The max gives us the band with the most observations, which must be
# above the limit.
(good_stars,) = (n_req.max(axis=0) >= self.config.minPerBand).nonzero()

# With the following matching:
# sources[good_sources][b] <-> stars[good_stars[a]]
Expand Down

0 comments on commit fff9ce0

Please sign in to comment.