Skip to content

Instantly share code, notes, and snippets.

View thomasaarholt's full-sized avatar

Thomas Aarholt thomasaarholt

View GitHub Profile
@thomasaarholt
thomasaarholt / jupyterlab.py
Created July 25, 2018 08:05
Copypasta for installing juyterlab, ipywidgets and ipympl in a fresh environment
# Need nodejs version 9, not latest, as of July 2018
conda install jupyterlab ipywidgets ipympl nodejs=9
jupyter labextension install @jupyter-widgets/jupyterlab-manager
@thomasaarholt
thomasaarholt / zanetta_after_pull_upstream
Created September 23, 2018 06:11
Error message after pulling hyperspy upstream into @ZanettaPM's background branch
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-4-825396d5c1d6> in <module>()
----> 1 m.plot()
c:\users\me\documents\github\hyperspy\hyperspy\models\model1d.py in plot(self, plot_components, **kwargs)
668 # Add the line to the figure
669 _plot.signal_plot.add_line(l2)
--> 670 l2.plot()
671 _plot.signal_plot.events.closed.connect(self._close_plot, [])
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-39-840bfeb05f2a> in <module>()
----> 1 m.fit_background(bounded=True)
c:\users\me\documents\github\hyperspy\hyperspy\models\edsmodel.py in fit_background(self, start_energy, end_energy, windows_sigma, kind, **kwargs)
445 windows_sigma[1] * component.sigma.value)
446 if kind == 'single':
--> 447 self.fit(**kwargs)
448 if kind == 'multi':
@thomasaarholt
thomasaarholt / savefig_no_whitespace.py
Last active March 17, 2022 03:07
Save matplotlib figures with no whitespace
import matplotlib.pyplot as plt
def save(filepath="image.png", fig=None):
'''Save the current image with no whitespace
Example filepath: "myfig.png" or r"C:\myfig.pdf"
Based on answers from https://stackoverflow.com/questions/11837979/
'''
import matplotlib.pyplot as plt
if not fig:
fig = plt.gcf()
@thomasaarholt
thomasaarholt / ssh_add_to_remote.bash
Created January 8, 2019 18:41
How to add your ssh public key to a remote
# Open terminal, locally call:
ssh-copy-id -i ~/.ssh/id_rsa.pub user@somehost
@thomasaarholt
thomasaarholt / cmake_make_error.sh
Created January 9, 2019 10:54
cmake make error
$ make
[ 5%] Building CXX object src/CMakeFiles/stemsalabim_lib.dir/classes/Crystal.cpp.o
In file included from /usit/abel/u1/thomasaar/software/STEMsalabim/src/classes/Slice.hpp(28),
from /usit/abel/u1/thomasaar/software/STEMsalabim/src/classes/Crystal.cpp(29):
/usit/abel/u1/thomasaar/software/STEMsalabim/src/classes/../utilities/Wave.hpp(110): error: namespace "std" has no member "complex"
typedef std::vector<std::complex<float>, fftwAllocator<std::complex<float>>> data_type;
^
In file included from /usit/abel/u1/thomasaar/software/STEMsalabim/src/classes/Slice.hpp(28),
from /usit/abel/u1/thomasaar/software/STEMsalabim/src/classes/Crystal.cpp(29):
Project Name: stemsalabim_test
2019-01-10 05:45:34.431 [compute-7-22.local, 0] Hello from compute-7-22.local, MPI rank 0/16, about to spawn 1 threads.
2019-01-10 05:45:34.431 [compute-7-22.local, 1] Hello from compute-7-22.local, MPI rank 1/16, about to spawn 1 threads.
2019-01-10 05:45:34.431 [compute-7-22.local, 2] Hello from compute-7-22.local, MPI rank 2/16, about to spawn 1 threads.
2019-01-10 05:45:34.431 [compute-7-22.local, 3] Hello from compute-7-22.local, MPI rank 3/16, about to spawn 1 threads.
2019-01-10 05:45:34.431 [compute-7-22.local, 4] Hello from compute-7-22.local, MPI rank 4/16, about to spawn 1 threads.
2019-01-10 05:45:34.431 [compute-7-22.local, 5] Hello from compute-7-22.local, MPI rank 5/16, about to spawn 1 threads.
2019-01-10 05:45:34.431 [compute-7-22.local, 6] Hello from compute-7-22.local, MPI rank 6/16, about to spawn 1 threads.
2019-01-10 05:45:34.431 [compute-7-22.local, 7] Hello from compute-7-22.local, MPI rank 7/16, about to spawn 1 threads.
2019-01-10 05:45:34.431 [compute-
@thomasaarholt
thomasaarholt / zsh_arrow_history
Created January 21, 2019 15:36
Make arrows navigate "alphabetical" history in zsh
# Add to ~/.zshrc
autoload -U up-line-or-beginning-search
autoload -U down-line-or-beginning-search
zle -N up-line-or-beginning-search
zle -N down-line-or-beginning-search
bindkey "^[[A" up-line-or-beginning-search # Up
bindkey "^[[B" down-line-or-beginning-search # Down
@thomasaarholt
thomasaarholt / Remote_Notebook.md
Last active March 21, 2019 14:51
Remote Jupyter Notebook through ssh tunnel

Using Jupyter notebook remotely via a ssh tunnel.

Especially good for running on headless devices, such as supercomputers or clusters.

Remotely:

# remote_port should be value between 8888 and 9000
jupyter notebook --no-browser --port=remote_port

Locally, new terminal window

screen -aAxR -S x # Connect without disconnecting
screen -dRaA -S x # Connect and disconnect others