Skip to content

Use of shifted average histogram needed? #836

@juliomateoslangerak

Description

@juliomateoslangerak

After running some CPU profiling tool it seems that this function is taking, by large, a good deal of the CPU. Presumably iterating over m to get a shifted average histogram is eating a lot of CPU.
Do we really need a shifted average histogram? This is only to display a histogram under the image, right?

def setData(self, data):
    # Calculate histogram.
    # Use shifted average histogram to avoid binning artefacts.
    # generate set of m histograms
    #   each has class width h
    #   start points 0, h/m, 2h/m, ..., (m-1)h/m
    # 1 < m < 64
    # sum to average
    if self.lbound is None:
        self.lbound = data.min()
    if self.ubound is None:
        self.ubound = data.max()
    if self.lthresh is None:
        self.lthresh = self.lbound
    if self.uthresh is None:
        self.uthresh = self.ubound
    nbins = 64
    m = 4
    self.bins = np.linspace(data.min(), data.max(), nbins)
    self.counts = np.zeros(nbins)
    h = self.bins[1] - self.bins[0]
    for i in range(m):
        these = np.bincount(np.digitize(data.flat, self.bins + i*h/m, right=True), minlength=nbins)
        self.counts += these[0:nbins]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions