field-behind-dielectric.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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.ones((1, 1), dtype = np.float64)
  55. x[0, 0] = radius*twopi
  56. # Set the refractive index of the sphere, normalized to that of the medium
  57. m = np.ones((1, 1), dtype = np.complex128)
  58. m[0, 0] = n1/nm
  59. nptsx = extent*resolution
  60. nptsy = extent*resolution
  61. scanx = np.linspace(-extent/2, extent/2, nptsx, endpoint=True)*twopi
  62. scany = np.linspace(-extent/2, extent/2, nptsy, endpoint=True)*twopi
  63. coordX, coordY = np.meshgrid(scanx, scany)
  64. coordX.resize(nptsx*nptsy)
  65. coordY.resize(nptsx*nptsy)
  66. coordZ = np.ones(nptsx*nptsy, dtype=np.float64)*distance*twopi
  67. coord = np.vstack((coordX, coordY, coordZ)).transpose()
  68. terms, E, H = scattnlay.fieldnlay(x, m, coord)
  69. # take the x-component of the electric field
  70. Ex = E[:,:,0].reshape(nptsx, nptsy)
  71. # normalize by the background field (free space propagation)
  72. Ex /= np.exp(1j*2*np.pi*distance*nm)
  73. # plot the phase (np.angle) of the x-component of the electric field
  74. ax = plt.subplot(111)
  75. mapper = plt.imshow(np.angle(Ex))
  76. plt.colorbar(mapper, ax=ax, label="phase [rad]")
  77. plt.title("phase retardation introduced by a dielectric sphere")
  78. plt.show()