wbrigg

airy_abberations

Mar 12th, 2015
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.93 KB | None | 0 0
  1. from scipy.special import j1
  2. import numpy as np
  3.  
  4. def airy_pattern_theta(theta, I0=1, wavelength=5e-7, aperture_radius=0.3e-2):
  5.   """
  6.  Airy function, with maximum intensity normalised to 1.
  7.  default values for the wavelength and aperture radius are the wavelength of green light,
  8.  and an approximate radius of a pupil.
  9.  """
  10.   return I0 * np.power(wavelength * j1(aperture_radius * np.sin(theta) * 2*np.pi/wavelength) / (np.pi * aperture_radius * np.sin(theta)), 2)
  11.  
  12. def airy_pattern(x, d, I0=1, wavelength=5e-7, aperture_radius=0.2e-2):
  13.   theta = np.arctan2(x,d)
  14.   return airy_pattern_theta(theta, I0=I0, wavelength=wavelength, aperture_radius=aperture_radius)
  15.  
  16.  
  17. def gaussian(x, mu=0, sigma=1):
  18.   return np.exp(-np.power(x-mu,2) / (2*np.power(sigma,2)))
  19.  
  20.  
  21. from matplotlib import pyplot
  22. import colorpy.ciexyz
  23. import colorpy.colormodels
  24.  
  25. fig = pyplot.figure()
  26. ax = fig.add_subplot(1,1,1)
  27.  
  28. aperture_radius = 3e-3
  29. focal_distance = 3e-2
  30. n_mins = 5
  31. airy_minimum = np.arcsin(0.61 * 545e-9 / aperture_radius)
  32. r_min_max = n_mins * airy_minimum
  33.  
  34. n_rs = 10000
  35.  
  36. rs = np.linspace(-r_min_max, r_min_max, n_rs)
  37.  
  38.  
  39.  
  40. wavelengths = range(380,700)
  41. spectrums = np.zeros((len(wavelengths), n_rs))
  42.  
  43. for index, wavelength in enumerate(wavelengths):
  44.   airy = airy_pattern(rs, 1, wavelength=wavelength * 1e-9)
  45.  
  46.   spectrums[index] = airy
  47.  
  48.   ax.plot(rs, airy, color=[i/255.0 for i in colorpy.colormodels.irgb_from_xyz(colorpy.ciexyz.xyz_from_wavelength(wavelength))])
  49.  
  50.  
  51. for index, r in enumerate(rs):
  52.  
  53.   spectrum = np.array(zip(wavelengths, spectrums[:,index]))
  54.  
  55.   colour = [i/255. for i in colorpy.colormodels.irgb_from_xyz(colorpy.ciexyz.xyz_from_spectrum(spectrum))]
  56.  
  57.   ax.scatter(r, 1, color=colour)
  58.  
  59.  
  60. ax.plot(rs, gaussian(rs, sigma=airy_minimum/2.0)+0.0015, color=(1,1,1), lw=4)
  61. ax.plot(rs, gaussian(rs, sigma=airy_minimum/2.0)+0.0015, color=(0,0,0), lw=2)
  62.  
  63. ax.set_xlim(-r_min_max, r_min_max)
  64. ax.set_ylim(0, 1.01)
  65.  
  66. pyplot.show()
Advertisement
Add Comment
Please, Sign In to add comment