Skip to content

Instantly share code, notes, and snippets.

Thomas Aarholt thomasaarholt

  • University of Oxford
  • Oxford, UK
Block or report user

Report or block thomasaarholt

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:d8fa0a53c7cca210d857
import hyperspy.api as hs
%matplotlib qt4
s = hs.load("EELS 0eV.dm3")
s.plot() # This works!
import traitsui
traitsui.__version__
'5.0.0'
View gist:805a2e120ca00669fe6c
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-1-efe73691b2de> in <module>()
2 matplotlib.use("Qt4Agg")
3
----> 4 import hyperspy.api as hs
5
6 get_ipython().magic(u'matplotlib')
View gist:607c33992bcbbae497fa
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/Users/thomas/anaconda/lib/python2.7/site-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
57 def draw_wrapper(artist, renderer, *args, **kwargs):
58 before(artist, renderer)
---> 59 draw(artist, renderer, *args, **kwargs)
60 after(artist, renderer)
61
/Users/thomas/anaconda/lib/python2.7/site-packages/matplotlib/figure.pyc in draw(self, renderer)
View natsort_bug.py
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-5084803b0409> in <module>()
----> 1 import hyperspy.api as hs
2
3 path = "/Users/thomas/Dropbox/0_DPhil/0_Data/00_TEM Data/0_Other/Test/Image"
4 name = "EELS Metal 0eV"
5
/Users/thomas/anaconda/envs/c3/lib/python3.5/site-packages/hyperspy/api.py in <module>()
View test2.py
import hyperspy.api as hs
s = hs.load("MO")
# Get peak energy
Zr_Peak = 330.
O_peak = 532.
# Create signals with enough background and signal length to fit the components.
s_Zr = s.isig[Zr_Peak - 40.:Zr_Peak + 60.]
s_O = s.isig[O_peak - 40.:O_peak + 60.]
View ioerror.py
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
<ipython-input-14-240ac4daefae> in <module>()
1 spectra[0].save("test2.hdf5")
----> 2 abc = hs.load("test2.hdf5")
/Users/thomas/Dropbox/0_Git/GitHub Desktop/hyperspy/hyperspy/io.py in load(filenames, record_by, signal_type, signal_origin, stack, stack_axis, new_axis_name, mmap, mmap_dir, **kwds)
212 objects = [load_single_file(filename,
213 **kwds)
--> 214 for filename in filenames]
@thomasaarholt
thomasaarholt / Hyperspy Windows Error.py
Last active May 23, 2016
Error with a fresh single-user 64-bit install of Hyperspy 0.8.4
View Hyperspy Windows Error.py
>>> %matplotlib
RuntimeError Traceback (most recent call last)
<ipython-input-3-fc39d5fd4eba> in <module>()
----> 1 get_ipython().magic('matplotlib')
C:\Users\EMGroup\AppData\Local\HyperSpy WinPython Bundle 0.8.4\python-3.4.4.amd64\lib\site-packages\IPython\core\interactiveshell.py in magic(self, arg_s)
2161 magic_name, _, magic_arg_s = arg_s.partition(' ')
2162 magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2163 return self.run_line_magic(magic_name, magic_arg_s)
@thomasaarholt
thomasaarholt / spikeremoval.py
Created Jun 1, 2016
Functions to remove high-energy cosmic ray spikes in EELS data
View spikeremoval.py
def median_from_neighbors(energy_slice, x, y=""):
"""Takes the median of the value of the list neighbors"""
import numpy as np
return(np.median(find_cell_neighbors(energy_slice, x,y)))
def find_cell_neighbors(data, X, Y, r=1):
"""Finds value of neighbors of a index in the SI, excluding the centre and any values outside the edges of the SI"""
adjacent = []
if Y == "":
@thomasaarholt
thomasaarholt / binning.py
Created Jun 7, 2016
Function for binning a Hyperspy Signal
View binning.py
def mybin(s, xbin=1, ybin=1, sbin=1):
"""Return spectrum s binned by factors xbin, ybin, sbin"""
if (xbin < 1) or (ybin < 1) or (sbin < 1):
raise ValueError("One of your binnings is smaller than 1. For signal axis to remain constant, leave as 1")
if all(n==1 for n in (xbin, ybin, sbin)):
print("Not binning because all binnings == 1")
return s # End Early
# Get signal channels
@thomasaarholt
thomasaarholt / make_same_dispersion.py
Created Jun 7, 2016
Part of my script to make two signals the same length
View make_same_dispersion.py
SI_dispersion = check_energy_dispersion(bss_spectra[0])
bin_mlls = False
bin_factor = 1
for s in mlls_objects:
mlls_dispersion = check_energy_dispersion(s)
if SI_dispersion > mlls_dispersion:
bin_mlls = True
if SI_dispersion / mlls_dispersion > bin_factor:
bin_factor = int(SI_dispersion / mlls_dispersion)
print(bin_factor)
You can’t perform that action at this time.