This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
N = 600 | |
probe_positions = np.arange(N) | |
def probe_function(probe_positions): | |
return np.sin(2*np.pi*probe_positions / 150)**2 | |
strength = 3 | |
period = 50 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hyperspy.api as hs | |
import numpy as np | |
import matplotlib.pyplot as plt | |
def cell2sig(cell, pixel_size = 0.05, sigma=0.25): | |
Signal2D = hs.signals.Signal2D | |
Gaussian2D = hs.model.components2D.Gaussian2D | |
XLEN, YLEN = (cell.cell.diagonal()[:2] // pixel_size).astype(int) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hyperspy.api as hs | |
expr = "where(Eg < x, A*(x-Eg)*n, 0)" | |
bandgap = hs.model.components1D.Expression(expr, 'Bandgap', Eg=3.0, n=1, A=1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%matplotlib widget | |
import hyperspy.api as hs | |
import matplotlib.pyplot as plt | |
import numpy as np | |
ll_sum = hs.load('ll_sum.hspy') | |
s_sum = hs.load('s_sum.hspy') | |
s_sum.metadata.Acquisition_instrument.TEM.beam_energy=200 | |
s_sum.metadata.Acquisition_instrument.TEM.convergence_angle=22.5 | |
s_sum.metadata.Acquisition_instrument.TEM.Detector.EELS.collection_angle=37.9 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fit_Zr_L(sZr, ll=None): | |
"Returns the model only" | |
print("Will produce 10 progress bars") | |
mZr = sZr.create_model(ll = ll, GOS="Hartree-Slater", auto_add_edges=False) | |
mZr.fit_component(mZr["PowerLaw"], bounded=True, signal_range=[2150.,2210.], fit_independent=True, only_current=True) | |
mZr.assign_current_values_to_all() | |
mZr.fit_component(mZr["PowerLaw"], bounded=True, signal_range=[2150.,2210.], fit_independent=True, only_current=False) | |
#mZr["PowerLaw"].set_parameters_not_free() | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%matplotlib widget | |
import hyperspy.api as hs | |
import numpy as np | |
import matplotlib.pyplot as plt | |
s = hs.datasets.example_signals.object_hologram() | |
ax0 = s.axes_manager[0] | |
ax1 = s.axes_manager[1] | |
ax0.scale=2 | |
ax1.scale=1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""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., |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hyperspy.api as hs | |
import numpy as np | |
from ipywidgets.widgets import HBox, VBox, Label, IntSlider, Output, IntRangeSlider | |
import matplotlib.pyplot as plt | |
from IPython.display import display | |
def plot_polar(s, clim=(10000, 100000), clim_max=(0, 250000)): | |
""" | |
Plot a 4D hyperspy dataset with the signal in polar coordinates | |
Arguments: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%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): |