Especially good for running on headless devices, such as supercomputers or clusters.
# remote_port should be value between 8888 and 9000
jupyter notebook --no-browser --port=remote_port
| from __future__ import annotations | |
| from collections import defaultdict | |
| from os import path | |
| from typing import DefaultDict, List, NamedTuple, Optional, Sequence, Set, Tuple, cast | |
| import requests | |
| import re | |
| from copy import copy | |
| from pyrsistent import m, s, v, PMap, PSet, PVector |
| ''' | |
| 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. | |
| MUST: First import of hyperspy (or scipy) must NOT be run with "Execute on background thread" checked. One | |
| can then swap to background thread and rerun. | |
| v. 0.3: Added delete statements to ensure python objects don't stay in memory. |
| echo 'Hello Thomas - edit PATH using "profile"' | |
| alias ls="ls --color" | |
| alias cd..='cd ../' # Go back 1 directory level (for fast typers) | |
| alias cd...='cd ../../' | |
| alias ..='cd ../' # Go back 1 directory level | |
| alias ...='cd ../../' # Go back 2 directory levels | |
| alias .3='cd ../../../' # Go back 3 directory levels | |
| alias .4='cd ../../../../' # Go back 4 directory levels |
| "\e[A": history-search-backward | |
| "\e[B": history-search-forward | |
| "\e[C": forward-char | |
| "\e[D": backward-char |
| from mpl_toolkits.axes_grid1 import make_axes_locatable | |
| def colorbar(mappable): | |
| "mappable is img = plt.imshow()" | |
| ax = mappable.axes | |
| fig = ax.figure | |
| divider = make_axes_locatable(ax) | |
| cax = divider.append_axes("right", size="5%", pad=0.05) | |
| cax.aname = 'colorbar' | |
| return fig.colorbar(mappable, cax=cax) |
| 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() |
| function X = forceFFTSymmetry(X) | |
| % forceFFTSymmetry A function to force conjugate symmetry on an FFT such that when an | |
| % IFFT is performed the result is a real signal. | |
| % The function has been written to replace MATLAB's ifft(X,'symmetric'), as this function | |
| % is not compatible with MATLAB Coder. | |
| % Licensed under Creative Commons Zero (CC0) so use freely. | |
| XStartFlipped = fliplr(X(2:floor(end/2))); |
| """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., |
| import numpy as np | |
| def bin_ndarray(ndarray, new_shape, operation='sum'): | |
| """ | |
| Bins an ndarray in all axes based on the target shape, by summing or | |
| averaging. | |
| Number of output dimensions must match number of input dimensions. | |
| Example |