SasView / sasview

Code for the SasView application.
BSD 3-Clause "New" or "Revised" License
48 stars 41 forks source link

In-situ linear fit from plot context menu behaves oddly #1415

Open smk78 opened 4 years ago

smk78 commented 4 years ago

Testing 5.0.1RC on x64 under W10.

Right-clicking on a plot and selecting a dataset gives the option for a linear fit. The fit parameters box that opens behaves oddly.

The 'range (linear scale)' boxes aren't editable and seem to default to 0000001 and 9999984. Underneath the 'Fit range of log10(x)' boxes are editable but do not default to the Q-range of the data. Given that the data is always displayed with unlogged axis labels it is not clear what the purpose of these two sets of boxes is. Surely the fitting range is always x?

Clicking 'Fit' does however generate a linear fit and populate the fit parameter boxes. But I'm not sure I trust the values. Fitting a random normally-tailing off dataset that had an I(Q=0.007)=642 returned a=-2.52 (which was roughly the gradient) but b=-3.01! How can the intercept be so small and negative? If it was +3.01 I might have assumed it was log10(b), but not if it is -3.01.

rozyczko commented 4 years ago

I agree with you. However, the behaviour is identical in 4.x so probably should be changed in both. In 4.x the linear range text boxes are also not editable and the intercept is negative. The example below is the sphere/sphere model with default parameters with linear fit applied.

Untitled

butlerpd commented 4 years ago

There is quite a bit of confusion here I think. This is what I consider critical functionality but which we have never had resources to do well so it is a kludge done a long time ago using mostly existing stuff with minimal extra work. Hence it is clunky and ugly. However it is mostly correct I think in 4.x.

The point of this is that there are a number of useful parameters that can be extracted from a linear fit to transformed data (transformed so that the region of interest becomes a straight line). The prime example of course is the famous Guinier plot but also things like the Porod plot etc. If you choose the "appropriate" region of the transformed plot you can fit a straight line and extract useful info (the Rg for example). Using this with the log(10) log(10) scale is not transformed data and pointless as far as I can tell and likely to lead to some very silly numbers. For this to be useful you need to transform the data by using the "change scale" option first (and choose something useful like Guinier) then apply the linear fit to the appropriate region.

Thus to answer the question about why two sets of ranges, for a Guinier the range will be in q^2 units but the user may want to know what q that covers. The point of both sets of boxes was to allow the user to specify the range in whatever "units" they wished -- those boxes must however be tied!!! changing the q^2 min also must changes q min, and vice versa.

So as far as I can tell, the main problem with this feature in 5.x is that the x ranges are not tied properly? there may be some other issues but I'll have to test more to be sure.

butlerpd commented 4 years ago

After fairly thorough testing I think the implementation was hampered by some confusion as to the purpose as mentioned before. The testing was done with the ESS_GUI build of Dec 23 and compared to the 4.2.2 release version. There are really 3 issues that should be addressed. The main critical issue is:

The other two rather major issues are

There is a unique confusion with log10 transformations since it can be “transformed” graphically while keeping the non-transformed values on the scale (i.e. 10^3 instead of 3 etc.) which is extremely useful for looking at scattering data in general but a bit confusing for the crude linear fit module of SasView. That makes the intercept at log10(I)=0 (I=1) visually not so obvious but I am not aware of any utility to that intercept. The slope however provides a quick and dirty way of estimating the slope of the data - often at low q the question might be: is that a q^-2? Or q^-4? Etc… This has always been so and while it would be nice to figure out how to make more obvious, I don’t think anything needs to be done for an imminent release.

rozyczko commented 4 years ago

Added missing analysis for Guinier/Porod (code and docs). Made the text boxes more clear wrt. editability.

Currently in ESS_GUI_5.0.1_fixes

smk78 commented 4 years ago

Tested in 5.0.1 Build 321 and locally-built from ESS_GUI branch. Working a lot better now. But:

butlerpd commented 4 years ago

To answer point 2: x always goes from -inf to + inf. For Guinier and Porod there should of course be no data in the range -inf to 0 :-) I think the default for original x is the data min max while the default x (transformed) data is the plot min max ..... which will go negative if the first point is near enough to zero.

As to the last point: 4.x give the Background (which is just the slope) but it would be nice to also give the Porod Constant which I think is the intercept if I remember right? (This last is NOT currently done in 4.x as far as I can tell). As for Kratky I fear my memory fails me as to how that got added but suspect some people (maybe bio people? but then would not be linear) wanted to be able to see a quick Kratky. Interesting question: Are there useful parameters one can obtain from that? The Kuhn length maybe? I must admit I never use Kratky plots so not sure .. however I don't think 4.x does anything with a fit there either.

smk78 commented 4 years ago

Actually, on reflection:

The one we could do is a Zimm transformation: I(Q)^-1 vs Q^2 where not only does b have meaning, but a = (Rg^2/3).b

butlerpd commented 4 years ago

exactly but isn't Kp.Sv the porod constant that you need for example in the invariant calculation? Labeling it as such could be useful for the more novice user? ... or the not so novice since we had to think about it a while :-) But agree we should not worry about it for now.

smk78 commented 4 years ago

Just need to be careful about our definitions of the Porod Constant (as in, whether or not one or the other includes Sv).