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
@thomasaarholt
thomasaarholt / widget_figure_workaround.py
Last active Oct 23, 2019
Temporary workaround for traditional mpl figure behaviour with the ipympl widget backend
View widget_figure_workaround.py
import matplotlib.pyplot as plt
def figure(figsize=None):
'Temporary workaround for traditional figure behaviour with the ipympl widget backend'
fig = plt.figure()
if figsize:
w, h = figsize
else:
w, h = plt.rcParams['figure.figsize']
fig.canvas.layout.height = str(h) + 'in'
@thomasaarholt
thomasaarholt / plot_im.py
Created Jul 6, 2018
Plot hyperspy signal nicely
View plot_im.py
def plot_im(s, ax=None, scalebar=True, label=True, clim=None, cmap=None, cbar=True, loc=4, axislabel=False, colorbar_format="scientific", colorbar_decimals=1, dont_show=False, **kwargs):
"""
Plots the HS image nicely with a scalebar. Label can be modified or turned off.
Use dont_show=True to not show a plot, but still return it.
Returns:
fig - the figure
ax - the axes
im - the image data
"""
import matplotlib.pyplot as plt
@thomasaarholt
thomasaarholt / gaussian.py
Last active Sep 10, 2019
Fastest found method of generating a gaussian kernel of size n x nand standard deviation std.
View gaussian.py
import numpy as np
from scipy import signal
def gaussian_kernel(n, std, normalised=False):
'''
Generates a n x n matrix with a centered gaussian
of standard deviation std centered on it. If normalised,
its volume equals 1.'''
gaussian1D = signal.gaussian(n, std)
gaussian2D = np.outer(gaussian1D, gaussian1D)
@thomasaarholt
thomasaarholt / is_notebook.py
Created Aug 30, 2019
Check if code is running in jupyter notebook
View is_notebook.py
def is_notebook():
try:
from IPython import get_ipython
if "IPKernelApp" not in get_ipython().config: # pragma: no cover
raise ImportError("console")
return False
if "VSCODE_PID" in os.environ: # pragma: no cover
raise ImportError("vscode")
return False
@thomasaarholt
thomasaarholt / zigzag.py
Created Aug 6, 2019
Zigzag scanning hyperspy example
View zigzag.py
import hyperspy.api as hs
import numpy as np
import matplotlib.pyplot as plt
def Gauss2D(X, Y, A=1, cx=0, cy=0, sx=1, sy=1):
return A*np.exp(-( ((X - cx)**2)/(2*sx**2) + ((Y - cy)**2)/(2*sy**2)))
def Gauss(x, A=1, c=0, s=1):
return A*np.exp(-((x - c)**2)/(2*s**2))
@thomasaarholt
thomasaarholt / gaussian_filter_tensorflow.py
Last active Jul 12, 2019
Gaussian filter of 2D image in Tensorflow 2.0 on GPU
View gaussian_filter_tensorflow.py
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
import tensorflow_probability as tfp
from time import time
def toImage(tensor):
return tensor.reshape(tensor.shape[:2])
def gaussian_kernel(size: int,
@thomasaarholt
thomasaarholt / odemis_acq.py
Last active Jul 4, 2019
Rough approximation of our approach to odemis SI acquisition
View odemis_acq.py
def approx_acquisition_method():
self.spect.data.synchronizedOn(self.escan.newPosition)
startt = time.time()
self.spect.data.subscribe(self.receive_spect_point)
sed_data = self.sed.data.get()
# wait the last point is fully acquired
self.acq_complete.wait()
@thomasaarholt
thomasaarholt / autoscale.py
Last active Jul 1, 2019
Matplotlib autoscale
View autoscale.py
def autoscale(ax=None, axis='y', margin=0.1):
'''Autoscales the x or y axis of a given matplotlib ax object
to fit the margins set by manually limits of the other axis,
with margins in fraction of the width of the plot
Defaults to current axes object if not specified.
'''
import matplotlib.pyplot as plt
import numpy as np
if ax is None:
View quantum_espresso_compilation
(/shared/users/thomasaar/py37) /shared/users/thomasaar/downloads/q-e-gpu-qe-gpu-6.4.1a1: ./configure --with-cuda=/opt/pgi/linux86-64/2018/cuda/9.2/bin --with-cuda-runtime=9.2 --with-cuda-cc=7.5 --enable-openmp --with-scalapack=no --prefix=/shared/users/thomasaar/compiled/q-e-gpu
checking build system type... x86_64-pc-linux-gnu
checking ARCH... x86_64
checking setting AR... ... /shared/users/thomasaar/py37/bin/x86_64-conda_cos6-linux-gnu-ar
checking setting ARFLAGS... ... ruv
checking whether the Fortran compiler works... yes
checking for Fortran compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
View henrik.py
import numpy as np
x = np.array([500, 500, 500, 1000, 1000, 1000, 1500])
y = np.array([1,2,3,4,5,6,7])
data = np.stack([x,y]).T
means = []
stds = []
for xi in np.unique(data[:,0]):
You can’t perform that action at this time.