2d fitting

24 views
Skip to first unread message

Till Wieland

unread,
Sep 18, 2017, 8:49:23 AM9/18/17
to hyperspy-users
Hi,
i am trying to fit a 2d model to larbed data, but the fit doesn't seem to work.
It would be great if somebody is able to help me with that.
I'm gonna attach the notebook (.ipynb) and the larbed-file i am trying to fit the model to (.hspy).
Thank you so much in advance!
Kind regards
Till

fit_question.ipynb
larbed_mgo_1_aligned_sum2d.hspy

Thomas Aarholt

unread,
Sep 18, 2017, 12:02:44 PM9/18/17
to hyperspy-users
Hi Till,

We're missing some information from you, namely, "what are you wanting to do"? Do you want to fit the spots and/or the background? Are you just interested in getting the position of the spots? Their intensity?

The main reason your fit isn't happening is because you're not calling fit() but creating a reference to the fit method (function) by calling "fit = m.fit". This just creates a "shortcut" to the m.fit method, rather than calling it. 

You're currently creating a single component that tries to fit both a diffraction spot and the background. I don't really understand your expression and what the three parts of it fit (the first bit is a linear plane, the second is a gaussian, but what is the third?), but hyperspy's model advantage lies in dividing these up.

Try to create one component to define the background, and one for the peaks. For the Gaussian, you're probably better off using the predefined Gaussian2D component, and also setting it's minimum intensity to zero:
"
g = hs.model.components2D.Gaussian2D(A = 10, centre_x=4.359,centre_y=2.073)
g.A.bmin = 0
g.sigma_x.bmin = 0
g.sigma_y.bmin = 0

background = hs.model.components2D.Expression("a*(x-x0)+b*(y-y0)+c", name="Background")

m.extend([g, background])
m.fit(bounded=True)
m.print_current_values()
"

However. 2D model fitting in hyperspy is still in its infancy. It might be better to see if pycrystem or atomap (both built on hyperspy) can improve your situation.

I know this was a long email response, but please keep asking questions - in particular, come join us on the gitter chat: https://gitter.im/hyperspy/hyperspy

Best,
Thomas



--
You received this message because you are subscribed to the Google Groups "hyperspy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hyperspy-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Thomas M. Aarholt

Post Doc, University of Oslo 
 
Mobile: +47 92855828
Reply all
Reply to author
Forward
0 new messages