field-behind-dielectric.py 3.4 KB

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