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
fortune = 500_000_000 | |
total_americans = 327_000_000 | |
americans_lives_changed = 0 | |
for american in range(total_americans): | |
if fortune - 1_000_000 >= 0: | |
fortune -= 1_000_000 | |
americans_lives_changed += 1 | |
else: | |
raise ValueError(f"Uh oh! He ran out of money! Lives changed: {americans_lives_changed}") |
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 random | |
number_of_hens = 100 | |
repeats = 1000 # repeat many times so that we get some decent statistics | |
sums = [] | |
for _ in range(repeats): | |
hens = np.zeros(number_of_hens, dtype=bool) # reset an array of False | |
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
x_ = np.linspace(0, 12, 1000) | |
die_y = die_fit_func(x_, *guess) | |
fig, ax = plt.subplots() | |
ax.plot(x_, die_y.real) | |
ax2 = ax.twinx() | |
ax2.plot(x_, die_y.imag, color='red') | |
ax.set(xlabel='Energy', ylabel='Real') |
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 P1(P0=(0,0), Pc=(2,2), step=1): | |
"Get the point P1, the point to which one moves from P0 with a fixed step in the direction of Pc" | |
X0, Y0 = P0 | |
Xc, Yc = Pc | |
diffX = Xc - X0 | |
diffY = Yc - Y0 | |
magnitude = (diffX**2 + diffY**2)**0.5 | |
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
from pprint import pprint | |
import temscript as ts | |
from math import pi | |
dwelltime = 1e-5 # seconds | |
tem = ts.Microscope() | |
illumination = tem._tem_illumination | |
instrument = ts.GetInstrument() |
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(abs(x - center) < radius, A, 0)" | |
tophat = hs.model.components1D.Expression(expr, 'Top Hat', position="center", A=1, center=0, radius=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 hyperspy.api as hs | |
expr = "where(sqrt((x - xc)**2 + (y - yc)**2) < radius, A, 0)" | |
tophat = hs.model.components2D.Expression(expr, 'Top Hat', position=("xc", "yc"), A=1, xc=0, yc=0, radius=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 hyperspy.api as hs | |
expr = "where(And(left < x, x < right), A, 0)" | |
tophat = hs.model.components1D.Expression(expr, 'Top Hat', position="left", A=1, left=0, right=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
def loadXRD(filename): | |
with open(filename, 'r') as f: | |
lines = f.readlines() | |
angles = [] | |
intensity = [] | |
for line in lines[1:-2]: | |
x, y = line.split('\n')[0].split(",")[:-1] | |
angles.append(float(x)) | |
intensity.append(float(y)) | |
x = np.array(angles) |
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 | |
from scipy.signal import convolve2d, gaussian | |
from scipy.misc import face | |
import matplotlib.pyplot as plt | |
def convolve2d_fft(arr1, arr2): | |
s0, s1 = arr1.shape | |
conv = np.fft.irfft2( | |
np.fft.rfft2(arr1) * np.fft.rfft2(arr2), |