Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-41789: Fix scaling bins from using too much memory or crashing #67

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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