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 / gms_load_hyperspy.py
Last active Feb 25, 2020
Python script to load any format supported by hyperspy directly into GMS 3.4+
View gms_load_hyperspy.py
'''
Python script to load any format supported by hyperspy directly into GMS
Must be copied and pasted into Gatan DigitalMicrograph (aka Gatan Microscopy Suite) version 3.4+
Call by `load_img(filepath)` at the bottom of the script. Can not be called outside of GMS.
Does not automatically convert the data type to EELS or EDS
Written by Thomas Aarholt, see https://gist.github.com/thomasaarholt/fccf06d56ff84cf76345b44dae30871e for newer versions
Feedback and forks are very welcome.
If the script runs forever, then this is due to a bug with numpy's FFT algorithm. To fix, in hyperspy\_signals\signal2d.py, move the line `from skimage.feature.register_translation import _upsampled_dft
` into the first line in `estimate_image_shift` in the same file.
@thomasaarholt
thomasaarholt / coordconv2d.py
Last active Feb 10, 2020 — forked from Dref360/coordconv2d.py
Un-scaled version of CoordConv2D
View coordconv2d.py
import keras.backend as K
import tensorflow as tf
from keras.layers import Layer
from keras.layers import Conv2D
"""Not tested, I'll play around with GANs soon with it."""
class CoordConv2D(Layer):
def __init__(self, channel, kernel, padding='valid', activation=None, **kwargs):
@thomasaarholt
thomasaarholt / gist:5a2395307dec047208dc6c9004f993b6
Created Feb 10, 2020
Error from calling matmul on tensorflow 2.1. TensorRT errors are not the problem.
View gist:5a2395307dec047208dc6c9004f993b6
(tensor)/shared/users/thomasaar/2020Feb: python
Python 3.7.6 | packaged by conda-forge | (default, Jan 7 2020, 22:33:48)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
2020-02-10 16:54:19.147934: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libnvinfer.so.6'; dlerror: libnvinfer.so.6: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/local/cuda-10.1/lib64:/usr/local/cuda-10.1/lib64:/shared/users/thomasaar/py37/lib:/shared/users/thomasaar/compiled/fftw/lib:/shared/users/thomasaar/compiled/prismatic/lib:
2020-02-10 16:54:19.149366: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libnvinfer_plugin.so.6'; dlerror: libnvinfer_plugin.so.6: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/local/cuda-10.1/lib64:/usr/local/cuda-10.1/lib64:/shared/users/thomasaar/py37/lib:/shared/users/th
View GMS.py
# Content of script run in GMS
import sys
sys.path.append(r"C:\Users\thomasaar\Documents\GMS Scripts")
import thomas
from importlib import reload
reload(thomas)
thomas.helloworld()
# Content of thomas.py in GMS Scripts folder
@thomasaarholt
thomasaarholt / velox_k_factors.py
Created Jan 21, 2020
Export Velox EDS K-factors
View velox_k_factors.py
# In Velox, choose a dataset and select all elements in the periodic table (This is a little tedious)
# From the Velox Menu, go "EDS" -> "Export Quantification Details..."
# This exports two files, one called "... Lines" and one called "... Composition". We want the former.
import pandas as pd
df = pd.read_csv(r"exported_eds_quant-Lines.csv")
DF = df.iloc[1:] # There was a single blank line in my dataset, so I get rid of it
DF.loc[:,'K-factor'] = DF['K-factor'].astype(float) # String to float on the k-factors
# Two functions that we map across the dataset to split the header into separate elements and line
def splitelement(entry):
@thomasaarholt
thomasaarholt / Second yticks and xticks
Created Dec 10, 2019
Matplotlib plot with 1/T and second units
View Second yticks and xticks
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax2 = ax1.twiny()
X = np.linspace(1,1000,1000)
Y = np.cos(X/200)
@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 / widget_figure_workaround.py
Last active Nov 19, 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 / 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,
You can’t perform that action at this time.