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 /
Last active Sep 10, 2019
Fastest found method of generating a gaussian kernel of size n x nand standard deviation std.
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 /
Created Aug 30, 2019
Check if code is running in jupyter notebook
def is_notebook():
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 /
Last active Aug 28, 2019
Temporary workaround for traditional mpl figure behaviour with the ipympl widget backend
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
w, h = plt.rcParams['figure.figsize']
fig.canvas.layout.height = str(h) + 'in'
thomasaarholt /
Created Aug 6, 2019
Zigzag scanning hyperspy example
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 /
Last active Jul 12, 2019
Gaussian filter of 2D image in Tensorflow 2.0 on GPU
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 /
Last active Jul 4, 2019
Rough approximation of our approach to odemis SI acquisition
def approx_acquisition_method():
startt = time.time()
sed_data =
# wait the last point is fully acquired
thomasaarholt /
Last active Jul 1, 2019
Matplotlib autoscale
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
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]):
thomasaarholt /
Last active Jun 17, 2019
Get DCFI shifts from a velox STEM file, then apply them to all the raw signals in the dataset.
# Script should be applied to a single Velox emd file, where the file contains a single DCFI dataset
# that has been applied to the detector signal that one wishes to apply to the other detector signals
# A good example is using DCFI on a DF image, and then applying this correction to HAADF, BF and ABF.
import hyperspy.api as hs
import json
import h5py
import numpy as np
def get_nonDCFI_signals(list_of_signals):
You can’t perform that action at this time.