field-behind-dielectric.py 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/usr/bin/env python
  2. # -*- coding: UTF-8 -*-
  3. #
  4. # Copyright (C) 2016 Paul Müller (paul.mueller [at] biotec.tu-dresden.de)
  5. #
  6. # This file is part of scattnlay
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation, either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # The only additional remark is that we expect that all publications
  19. # describing work using this software, or all commercial products
  20. # using it, cite the following reference:
  21. # [1] O. Pena and U. Pal, "Scattering of electromagnetic radiation by
  22. # a multilayered sphere," Computer Physics Communications,
  23. # vol. 180, Nov. 2009, pp. 2348-2354.
  24. #
  25. # You should have received a copy of the GNU General Public License
  26. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  27. # This test case calculates the phase retardation that is introduced
  28. # by a weak dielectric sphere to an incident plane wave. Only the
  29. # x-polarized light is considered.
  30. # Note: This example computes the phase behind the sphere. In microscopy,
  31. # the focal plane during imaging is close to the center of the sphere.
  32. # To compute the phase image that corresponds to that imaged with a focal
  33. # plane at the center of the bead, numerical refocusing of the computed
  34. # field `Ex` would be required (e.g. python package nrefocus).
  35. import numpy as np
  36. import scattnlay
  37. import matplotlib.pylab as plt
  38. # weak dielectric sphere, e.g. a PMMA gel bead
  39. n1 = 1.335
  40. # refractive index of the surrounding medium (water)
  41. nm = 1.333
  42. # radius of the sphere in vacuum wavelengths
  43. radius = 0.3
  44. # extent of the simulation size in vacuum wavelengths
  45. extent = 2.0
  46. # distance where we want to have the measured field behind the sphere
  47. # in vacuum wavelengths measured from the center of the sphere
  48. distance = 0.5
  49. # pixels per vacuum wavelength in the output image
  50. resolution = 20.0
  51. # size parameters need to be multiplied by (2 PI nm) for the computation
  52. twopi = 2*np.pi*nm
  53. # There is only one sphere, no layers
  54. x = np.array([radius*twopi], dtype = np.float64)
  55. # Set the refractive index of the sphere, normalized to that of the medium
  56. m = np.array([n1/nm], dtype = np.complex128)
  57. nptsx = int(extent*resolution)
  58. nptsy = int(extent*resolution)
  59. scanx = np.linspace(-extent/2, extent/2, nptsx, endpoint=True)*twopi
  60. scany = np.linspace(-extent/2, extent/2, nptsy, endpoint=True)*twopi
  61. coordX, coordY = np.meshgrid(scanx, scany)
  62. coordX.resize(nptsx*nptsy)
  63. coordY.resize(nptsx*nptsy)
  64. coordZ = np.ones(nptsx*nptsy, dtype=np.float64)*distance*twopi
  65. terms, E, H = scattnlay.fieldnlay(x, m, coordX, coordY, coordZ)
  66. # take the x-component of the electric field
  67. Ex = E[:,0].reshape(nptsx, nptsy)
  68. # normalize by the background field (free space propagation)
  69. Ex /= np.exp(2j*np.pi*distance*nm)
  70. # plot the phase (np.angle) of the x-component of the electric field
  71. ax = plt.subplot(111)
  72. mapper = plt.imshow(np.angle(Ex))
  73. plt.colorbar(mapper, ax=ax, label="phase [rad]")
  74. plt.title("phase retardation introduced by a dielectric sphere")
  75. plt.show()