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

Use of shifted average histogram needed? #836

Open
juliomateoslangerak opened this issue Dec 13, 2022 · 2 comments
Open

Use of shifted average histogram needed? #836

juliomateoslangerak opened this issue Dec 13, 2022 · 2 comments

Comments

@juliomateoslangerak
Copy link
Contributor

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]
@carandraug
Copy link
Collaborator

[...] This is only to display a histogram under the image, right?

I believe so, yes. Does replacing it with something like np.histogram makes things any faster for you?

@iandobbie
Copy link
Collaborator

I suspect this is Mick's work. The histogram used to have nasty aliasing meaning at time 1 in n peaks was 1/n higher depending how the data was divided between the histogram bins. This was very ugly and the autoscaling of the histogram meant it continually changed. The newer histograms are much cleaner, but maybe we need a lazy histogram where it is only calculated and redisplayed if the image doesn't change for some period.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants