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 20, 2024
1 parent 1394400 commit e971e83
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 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,25 @@ 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.
print("WEIRD THINGS ARE AFOOT")
print(len(data))
print(data)
print(maxPatchNum)
print(set(list(data["patch"])))
try:
_, rev = esutil.stat.histogram(data["patch"], min=0, max=maxPatchNum - 1, rev=True)
except ValueError:
rev = np.full(maxPatchNum + 2, maxPatchNum + 2)

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 e971e83

Please sign in to comment.