Skip to content

Multiple improvements for log scale support#646

Closed
diorcety wants to merge 22 commits intopyqtgraph:masterfrom
diorcety:log2018
Closed

Multiple improvements for log scale support#646
diorcety wants to merge 22 commits intopyqtgraph:masterfrom
diorcety:log2018

Conversation

@diorcety
Copy link
Copy Markdown

Support log in HistogramLUTItem
Add minLevel, maxLevel edit box in GradientEditor
Small improvements in the behaviours
Replace #411

@diorcety diorcety force-pushed the log2018 branch 2 times, most recently from 7f0d367 to 52ec289 Compare August 6, 2018 12:02
rng = 1 if rng == 0 else rng
d2 = (data - float(minVal)) * scale / (rng)
else:
rng = np.log10(maxVal)-np.log10(minVal)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if dealing with singular values, math.log10 is far faster than np.log10

@j9ac9k j9ac9k changed the base branch from develop to master January 29, 2021 06:05
@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Feb 6, 2021

This PR is a doozy due to the size of the diff, and the number of conflicts. I've resolved them locally, but the diff is way too large to just squash on merge IMO. I'm going to leave this open, but highly recommend not merging. Meanwhile I'll try and submit a series of PRs that replicate the functionality/fixes that this PR brings.

Sorry @diorcety for not getting to this earlier. The size of this PR made it so we kept pushing back. Thanks for the submission, I'll try and cherry pick your commits in the construction of a series of smaller PRs once I get the test suite to pass.

@j9ac9k j9ac9k marked this pull request as draft February 6, 2021 07:01
@j9ac9k j9ac9k self-assigned this Feb 15, 2021
@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Feb 20, 2021

I think this is as far as I can carry this PR with respect to the test suite, pyside pipelines are passing, pyqt pipelines are failing some of the test_ref_counts tests (for some reason, PlotItem's seem to be getting deleted prematurely on PyQt from the looks of things).

Once I verify behavior/functionality is there, I'm going to start taking bits and pieces of this PR into smaller, easier to manage PRs.

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Feb 20, 2021

and by shear-dumb-luck I came across the line that is breaking test_ref_cycles

          self.vb.sigLogChanged.connect(lambda x: self.setLogMode(x.xLog(), x.yLog()))

I've always heard that connecting lambdas to signals wasn't a great idea, guess now I can see that first-hand...

@pijyoi
Copy link
Copy Markdown
Contributor

pijyoi commented Feb 20, 2021

      self.vb.sigLogChanged.connect(lambda x: self.setLogMode(x.xLog(), x.yLog()))

I am not very familiar with the way lambda capturing works, so I would normally code lambdas this way:

self.vb.sigLogChanged.connect(lambda x, self=self: self.setLogMode(x.xLog(), x.yLog()))

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Feb 20, 2021

      self.vb.sigLogChanged.connect(lambda x: self.setLogMode(x.xLog(), x.yLog()))

I am not very familiar with the way lambda capturing works, so I would normally code lambdas this way:

self.vb.sigLogChanged.connect(lambda x, self=self: self.setLogMode(x.xLog(), x.yLog()))

I hadn't seen that pattern before, tried it ultimately to the same result...

Doing some quick searching yields this, suggesting it's not garbage collected https://stackoverflow.com/a/48501804

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Feb 20, 2021

Now all tests pass, no warnings are emitted... can finally start evaluating how well this all works 😆

The diff isn't actually that large. If anyone here is interested in log-mode, I would encourage you all to take a look at this PR.

@dgoeries I think you had an interest in log-mode stuff.

rng = maxVal-minVal
rng = 1 if rng == 0 else rng
data = rescaleData(data, scale/rng, minVal, dtype=dtype)
data = rescaleData(data, scale/rng, minVal, dtype=dtype, log=log)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these two changes will be insufficient to have makeARGB properly support log-scale image processing. Are the lut and levels args assumed to have already been adjusted to account for the log scale? I think we should omit changes to this method entirely, rather than implement them halfway and imply otherwise.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though this may be more sufficient than I understand. Providing an example use or test would help me. For now, though, if a user wants to process the image with log10, my first impulse would be to recommend they do so before sending it to makeARGB, and they could, at that time, adjust lut and levels to match their expectations.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not that familiar with how the processing in ImageItem works, but my understanding is that moving the log10 inside rescaleData would also require a recalculation of the logarithm on each re-render, even if the image hasn't changed. I suspect that this would make interactive adjustments to the LUT slower than necessary.

if log:
with np.errstate(invalid='ignore', divide='ignore'):
np.log10(d2, out=d2)
d2 -= math.log10(offset)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about when offset is 0? This would raise a ValueError.

return matrix

def rescaleData(data, scale, offset, dtype=None, clip=None):
def rescaleData(data, scale, offset, dtype=None, clip=None, log=False):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof; log can also refer to logging. I think renaming it to something more specific would be helpful. logScale, log10, logarithmic come to mind.

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Feb 21, 2021

Ok, I'm leaning on scraping this PR then. It's a shame, there is a lot of good stuff here, but between no docs, no tests, no examples, the size of the diff, and not addressing any of the current open issues; I think we should leave this guy perhaps in draft form (or close it out entirely) and make a series of smaller PRs that perhaps use bits of this code while addressing some of the currently open issues.

@diorcety diorcety closed this Feb 21, 2021
@diorcety
Copy link
Copy Markdown
Author

Sorry for the noise. The changes are too heavy and I have no time to add tests and other work ( and I have no more need of this also)

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Feb 21, 2021

Hi @diorcety

I just realized you must have been getting pinged for updates on your PR, sorry about that, I didn't actually intend to bug you about it. So much time had passed since you submitted it since we got to looking more closely at it, that we didn't expect you to address issues like merge conflicts and such.

Unfortunately you submitted this PR at a time when the library was more or less on life support. Since development picked up, we have been looking to get the outstanding PR count down; which meant larger PRs such as this one kept getting postponed in their evaluation.

Thanks for the PR, I'll likely use some of the diff here as a starting place as I look to address outstanding issues involving log-support, as that functionality clearly doesn't work as well as it should.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants