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 / 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 1, 2020
Plot a 4D hyperspy dataset with the signal in polar coordinates
View plot_polar.py
%matplotlib widget
import hyperspy.api as hs
import numpy as np
import matplotlib.pyplot as plt
from ipywidgets.widgets import HBox, VBox, Label, IntSlider, Output
# Optional, for notebook only, not lab
# from IPython.core.display import display, HTML
# display(HTML("<style>.container { width:100% !important; }</style>"))
@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
@thomasaarholt
thomasaarholt / gms_load_hyperspy.py
Last active Mar 9, 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
@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
You can’t perform that action at this time.