Skip to content

Commit

Permalink
Merge pull request #67 from lsst-sitcom/tickets/DM-41789
Browse files Browse the repository at this point in the history
DM-41789: Fix scaling bins from using too much memory or crashing
  • Loading branch information
mfisherlevine authored Nov 17, 2023
2 parents 39a5a12 + 42a4708 commit e558b7b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions python/lsst/summit/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ def getFilterSeeingCorrection(filterName):
raise ValueError(f"Unknown filter name: {filterName}")


def getCdf(data, scale):
def getCdf(data, scale, nBinsMax=131072):
"""Return an approximate cumulative distribution function scaled to
the [0, scale] range.
Expand All @@ -945,6 +945,8 @@ def getCdf(data, scale):
The input data.
scale : `int`
The scaling range of the output.
nBinsMax : `int`, optional
Maximum number of bins to use.
Returns
-------
Expand All @@ -969,8 +971,10 @@ def getCdf(data, scale):
# return nans for all values
return np.nan, np.nan, np.nan

nBins = np.clip(int(maxVal) - int(minVal), 1, nBinsMax)

hist, binEdges = np.histogram(
flatData, bins=int(maxVal - minVal), range=(minVal, maxVal)
flatData, bins=nBins, range=(int(minVal), int(maxVal))
)

cdf = (scale*np.cumsum(hist)/size).astype(np.int64)
Expand Down

0 comments on commit e558b7b

Please sign in to comment.