Skip to content

Instantly share code, notes, and snippets.

View thomasaarholt's full-sized avatar

Thomas Aarholt thomasaarholt

View GitHub Profile
@thomasaarholt
thomasaarholt / samf_ red_chisq.py
Last active December 7, 2016 16:00
red_chisq issue with SAMFire
SAM = m.create_samfire()
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-21-edd4774a10cd> in <module>()
----> 1 SAM = m.create_samfire()
/Users/thomas/Dropbox/0_Git/GitHub/hyperspy_aar/hyperspy/model.py in create_samfire(self, workers, setup, **kwargs)
1780 from hyperspy.samfire import Samfire
1781 return Samfire(self, workers=workers,
-> 1782 setup=setup, **kwargs)
@thomasaarholt
thomasaarholt / Fit_Zr_fast.py
Created January 17, 2017 19:00
Fast but poor fitting of the zirconium L white lines
m = Zr.create_model(ll, GOS="Hartree-Slater")
Zr_L3_white = hs.model.components1D.Gaussian()
Zr_L3_white.name = "Zr L3 White Line"
Zr_L3_white.centre.bmin = 2218.0
Zr_L3_white.centre.bmax = 2240.0
Zr_L3_white.sigma.bmax=3
Zr_L3_white.A.bmin = 0
Zr_L2_white = hs.model.components1D.Gaussian()
@thomasaarholt
thomasaarholt / Fit_Zr_good.py
Last active January 17, 2017 19:00
Good, slow fitting of the zirconium L white lines
def fit_Zr_L(sZr, ll=None):
"Fits the Zr L lines, return a hyperspy model. Input is a Zr spectrum image, and optionally, the accompanying low loss SI."
print("Will produce 10 progress bars")
mZr = sZr.create_model(ll = ll, GOS="Hartree-Slater", auto_add_edges=False)
# Fit Background
mZr.fit_component(mZr["PowerLaw"], bounded=True, signal_range=[2150.,2210.], fit_independent=True, only_current=True)
mZr.assign_current_values_to_all()
mZr.fit_component(mZr["PowerLaw"], bounded=True, signal_range=[2150.,2210.], fit_independent=True, only_current=False)
>>> m.fit(fitter="L-BFGS-B", bounded=True, grad=True)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-118-e2c35f346c6e> in <module>()
50
51 #m.fit(fitter="leastsq", bounded=True, grad=True)
---> 52 m.fit(fitter="L-BFGS-B", bounded=True, grad=True)
53
54
(C:\ProgramData\Miniconda3) C:\Users\thomasaar>pip install -e M:\pc\Dokumenter\GitHub\hyperspy
Obtaining file:///M:/pc/Dokumenter/GitHub/hyperspy
Complete output from command python setup.py egg_info:
test_compilers.c
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "M:\pc\Dokumenter\GitHub\hyperspy\setup.py", line 295, in <module>
with update_version_when_dev() as version:
File "M:\pc\Dokumenter\GitHub\hyperspy\setup.py", line 273, in __enter__
@thomasaarholt
thomasaarholt / fail.py
Created April 8, 2017 10:47
Bug when installing hyperspy from loca repo
PS C:\Users\thomasaar\Downloads\hyperspy> pip install -e ./
Obtaining file:///C:/Users/thomasaar/Downloads/hyperspy
Complete output from command python setup.py egg_info:
test_compilers.c
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\thomasaar\Downloads\hyperspy\setup.py", line 294, in <module>
with update_version_when_dev() as version:
File "C:\Users\thomasaar\Downloads\hyperspy\setup.py", line 272, in __enter__
stdout=subprocess.PIPE)
@thomasaarholt
thomasaarholt / spikesbug.py
Created April 8, 2017 14:11
Spikes removal error
# When stepping through the signal looking for spikes, suddenly:
Exception occurred in traits notification handler for object: <hyperspy.signal_tools.SpikesRemoval object at 0x12835e048>, trait: ss_right_value, old value: nan, new value: 0.0
Traceback (most recent call last):
File "/Users/thomas/miniconda3/envs/hs/lib/python3.5/site-packages/traits/trait_notifiers.py", line 340, in __call__
self.handler( *args )
File "/Users/thomas/hyperspy/hyperspy/signal_tools.py", line 968, in _ss_right_value_changed
self.span_selector_changed()
File "/Users/thomas/hyperspy/hyperspy/signal_tools.py", line 1047, in span_selector_changed
self.interpolated_line.update()
@thomasaarholt
thomasaarholt / spikesbug2.py
Created April 8, 2017 14:16
"Remove spikes" at start, error
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/Users/thomas/hyperspy/hyperspy/gui_ipywidgets/tools.py in on_remove_clicked(b)
416
417 def on_remove_clicked(b):
--> 418 obj.apply()
419 remove.on_click(on_remove_clicked)
420 labeled_spline_order = labelme("Spline order", spline_order)
/Users/thomas/hyperspy/hyperspy/signal_tools.py in apply(self)
@thomasaarholt
thomasaarholt / Line2DROI_aar.py
Created April 27, 2017 13:15
Hyperspy automatic Line2DROI
def create_Line_on_DF(s, lineROI=[], hide=False):
"""
Plots a hyperspy signal and draws an interactive ROI on it on the top left tenth of the image.
Can take a list of [x1, y1, x2, y2, linewidth] to set a known intial ROI.
Returns a tuple of (roi, roi_signal). Use hide=True to not show the plot.
Please report bugs/improvements to thomasaarholt@gmail.com
"""
import hyperspy.api as hs
if s.axes_manager.navigation_dimension < 2:
@thomasaarholt
thomasaarholt / selectfile.py
Created June 1, 2017 20:43 — forked from DrDub/selectfile.py
A file selection class build for ipywidgets without any extra dependencies.
import os
import ipywidgets as widgets
class FileBrowser(object):
def __init__(self):
self.path = os.getcwd()
self._update_files()