Skip to content

Commit

Permalink
Fix scaling bins from using too much memory or crashing.
Browse files Browse the repository at this point in the history
  • Loading branch information
erykoff authored and mfisherlevine committed Nov 17, 2023
1 parent 39a5a12 commit b5e951b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 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, nBinsMin=256, nBinsMax=131072):
"""Return an approximate cumulative distribution function scaled to
the [0, scale] range.
Expand All @@ -945,6 +945,10 @@ def getCdf(data, scale):
The input data.
scale : `int`
The scaling range of the output.
nBinsMin : `int`, optional
Minimum number of bins to use.
nBinsMax : `int`, optional
Maximum number of bins to use.
Returns
-------
Expand All @@ -969,8 +973,10 @@ def getCdf(data, scale):
# return nans for all values
return np.nan, np.nan, np.nan

nBins = np.clip(int(maxVal) - int(minVal), nBinsMin, 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 b5e951b

Please sign in to comment.