Skip to content

Instantly share code, notes, and snippets.

@haltugyildirim
Created July 20, 2021 19:04
Show Gist options
  • Save haltugyildirim/f435e53cac58816025200303379204b8 to your computer and use it in GitHub Desktop.
Save haltugyildirim/f435e53cac58816025200303379204b8 to your computer and use it in GitHub Desktop.
creating a circularly polarized light for left and right circular polarizations to use in images
def gaussian(t, sigma, t_0):
"""
This is a standart gaussian.
Returns gaussian array.
t -> the time array. If you supply the function with a float or integer, it might
cause an error. Try to give an array, even for single numbers
sigma -> sigma-value of Gaussian, where we extract the FWHM of cross-correlation.
t_0 -> time-zero where time is zero, a singularity where nothing happens.
"""
# C is the offset
# t_0 is t zero
f = np.zeros(t.size)
for i in range(t.size):
val = np.exp(-(t[i])**2/(2*sigma**2))
f[i] = val
return f
from mpl_toolkits import mplot3d
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(8, 8))
ax = plt.axes(projection='3d')
md = 0.6
sigma = 7
t_0 = 0
polarization = 'right'
x = np.linspace(-25, 25, 2000)
z = np.sin(x/md)
if polarization == 'left':
y = np.cos(x/md-np.pi)
else:
y = np.cos(x/md)
g = gaussian(x, sigma, t_0)
ax.plot3D(x, g*y, g*z, 'gray')
#ax.get_proj = lambda: np.dot(Axes3D.get_proj(ax), np.diag([0.6, 1, 0.8, 1]))
ax.view_init(15, 65)
fig.savefig("circular_pulse_%s.svg" % polarization)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment