Skip to content

Commit

Permalink
Replace onPatch selection with more efficient reverse indices.
Browse files Browse the repository at this point in the history
  • Loading branch information
erykoff authored and sr525 committed Sep 19, 2024
1 parent 2dae677 commit 250ebea
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions python/lsst/analysis/tools/actions/plot/plotUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

from typing import TYPE_CHECKING, Iterable, List, Mapping, Tuple

import esutil
import matplotlib
import numpy as np
from lsst.geom import Box2D, SpherePoint, degrees
Expand Down Expand Up @@ -74,13 +75,17 @@ def generateSummaryStats(data, skymap, plotInfo):
patchInfoDict = {}
maxPatchNum = tractInfo.num_patches.x * tractInfo.num_patches.y
patches = np.arange(0, maxPatchNum, 1)

# Histogram (group) the patch values, and return an array of
# "reverse indices" which is a specially encoded array of where
# every patch is in the overall array.
_, rev = esutil.stat.histogram(data["patch"], min=0, max=maxPatchNum - 1, rev=True)

for patch in patches:
if patch is None:
continue
# Once the objectTable_tract catalogues are using gen 3 patches
# this will go away
onPatch = data["patch"] == patch
if sum(onPatch) == 0:
# Pull out the onPatch indices
onPatch = rev[rev[patch]: rev[patch + 1]]

if len(onPatch) == 0:
stat = np.nan
else:
stat = nanMedian(data[yCol][onPatch])
Expand Down

0 comments on commit 250ebea

Please sign in to comment.