Skip to content

Instantly share code, notes, and snippets.

Thomas Aarholt thomasaarholt

  • University of Oslo
  • Oslo, Norway
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
@thomasaarholt
thomasaarholt / Mn_whitelineratio
Created Apr 21, 2020 — forked from winston-song/Mn_whitelineratio
Mn L3/L2 white line ratio using gussian component plus H-S step edge
View Mn_whitelineratio
%matplotlib widget
import hyperspy.api as hs
import matplotlib.pyplot as plt
import numpy as np
ll_sum = hs.load('ll_sum.hspy')
s_sum = hs.load('s_sum.hspy')
s_sum.metadata.Acquisition_instrument.TEM.beam_energy=200
s_sum.metadata.Acquisition_instrument.TEM.convergence_angle=22.5
s_sum.metadata.Acquisition_instrument.TEM.Detector.EELS.collection_angle=37.9
@thomasaarholt
thomasaarholt / fit_Zr_whitelines.py
Created Apr 20, 2020
Curve fitting the white lines on zirconium oxide with hyperspy
View fit_Zr_whitelines.py
def fit_Zr_L(sZr, ll=None):
"Returns the model only"
print("Will produce 10 progress bars")
mZr = sZr.create_model(ll = ll, GOS="Hartree-Slater", auto_add_edges=False)
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)
#mZr["PowerLaw"].set_parameters_not_free()
@thomasaarholt
thomasaarholt / axisrotation.py
Created Apr 10, 2020
hyperspy rotation of axes calibrated
View axisrotation.py
%matplotlib widget
import hyperspy.api as hs
import numpy as np
import matplotlib.pyplot as plt
s = hs.datasets.example_signals.object_hologram()
ax0 = s.axes_manager[0]
ax1 = s.axes_manager[1]
ax0.scale=2
ax1.scale=1
@thomasaarholt
thomasaarholt / parallelspline.py
Created Apr 9, 2020
Strange behaviour with parallel map and UnivariateSpline
View parallelspline.py
import numpy as np
import matplotlib.pyplot as plt
import scipy.interpolate
from concurrent.futures import ThreadPoolExecutor
from os import cpu_count
executor = ThreadPoolExecutor(max_workers=cpu_count())
print(f"Processors available: {cpu_count()}")
# parallel=True uses the following map function
@thomasaarholt
thomasaarholt / augumented_hdf5_matrix.py
Created Apr 7, 2020 — forked from wassname/augumented_hdf5_matrix.py
How to do data augmentation on a keras HDF5Matrix
View augumented_hdf5_matrix.py
"""Another way, note this one will load the whole array into memory ."""
from keras.preprocessing.image import ImageDataGenerator
import h5py
from keras.utils.io_utils import HDF5Matrix
seed=0
batch_size=32
# we create two instances with the same arguments
data_gen_args = dict(
rotation_range=90.,
@thomasaarholt
thomasaarholt / plot_polar.py
Last active Apr 10, 2020
Plot a 4D hyperspy dataset with the signal in polar coordinates
View plot_polar.py
import hyperspy.api as hs
import numpy as np
from ipywidgets.widgets import HBox, VBox, Label, IntSlider, Output, IntRangeSlider
import matplotlib.pyplot as plt
from IPython.display import display
def plot_polar(s, clim=(10000, 100000), clim_max=(0, 250000)):
"""
Plot a 4D hyperspy dataset with the signal in polar coordinates
Arguments:
@thomasaarholt
thomasaarholt / spanplot.py
Last active Mar 20, 2020
Hyperspy function to emulate GMS behaviour on spectrum images
View spanplot.py
%matplotlib widget
import hyperspy.api as hs
import matplotlib.pyplot as plt
from ipywidgets.widgets import HBox, Label, Dropdown
# Optional, for notebook only, not lab
# from IPython.core.display import display, HTML
# display(HTML("<style>.container { width:100% !important; }</style>"))
def plot(s):
@thomasaarholt
thomasaarholt / horizontal_plot.py
Created Mar 17, 2020
Plotting horizontally in hyperspy using widgets
View horizontal_plot.py
from ipywidgets.widgets import HBox, VBox
import matplotlib.pyplot as plt
def plot(s, orientation='horizontal'):
"""
Plot hyperspy signals horizontally using the %matplotlib widget interface.
Can also plot vertically using orientation='vertical'
"""
# if 1D signal, just plot normal
View widget_error.py
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
~\.conda\envs\py5\lib\site-packages\matplotlib\backend_bases.py in _wait_cursor_for_draw_cm(self)
2772 try:
-> 2773 self.set_cursor(cursors.WAIT)
2774 yield
~\.conda\envs\py5\lib\site-packages\matplotlib\backends\backend_webagg_core.py in set_cursor(self, cursor)
380 if cursor != self.cursor:
--> 381 self.canvas.send_event("cursor", cursor=cursor)
@thomasaarholt
thomasaarholt / eels_colours.py
Last active Mar 11, 2020
Plot low-loss EELS spectra with range 1.5 - 3.4 eV filled with the visible colours, otherwise black
View eels_colours.py
import numpy as np
import matplotlib.pyplot as plt
# get electropy from thomasaarholt github
from electropy.units import eV_to_wavelength
# get colour by pip install colour-science
from colour.utilities import first_item, normalise_maximum
from colour.plotting import filter_cmfs, XYZ_to_plotting_colourspace, COLOUR_STYLE_CONSTANTS
from colour.colorimetry import wavelength_to_XYZ, ILLUMINANTS
You can’t perform that action at this time.