Skip to content

Instantly share code, notes, and snippets.

@thomasaarholt
Last active November 4, 2016 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasaarholt/b413b47d6c77311c591390dce973803b to your computer and use it in GitHub Desktop.
Save thomasaarholt/b413b47d6c77311c591390dce973803b to your computer and use it in GitHub Desktop.
Fitting linear components to hyperspy signals
# In model.py
from numpy.linalg import lstsq as linear_lstsq
(...)
elif fitter == "linear_lstsq":
signal_axis = self.axis.axis[np.where(self.channel_switches)]
component_data = np.array([component.function(signal_axis) for component in self])
print(weights)
output = linear_lstsq(component_data.T, self.signal()[np.where(self.channel_switches)], **kwargs)
self.p0 = tuple([old*factor for old, factor in zip(self.p0, output[0])])
self.fit_output = output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment