main.py 1.0 KB

12345678910111213141516171819202122
  1. from scattnlay2.pynmie import scattcoeffs_, scattnlay_, fieldnlay_
  2. import numpy as np
  3. def scattcoeffs(x, m, nmax=-1, pl=-1, nstore=1000):
  4. if len(x.shape) != 2:
  5. raise ValueError('The size parameter (x) should be 2-D NumPy array.')
  6. if len(m.shape) != 2:
  7. raise ValueError('The relative refractive index (m) should be 2-D NumPy array.')
  8. if nmax != -1: nstore = nmax
  9. total_evaluations = len(x)
  10. terms = np.zeros((total_evaluations), dtype=int)
  11. an = np.zeros((total_evaluations, nstore), dtype =complex)
  12. bn = np.zeros((total_evaluations, nstore), dtype =complex)
  13. for i in range(total_evaluations):
  14. terms[i], a, b = scattcoeffs_(x[i], m[i], nmax=nmax, pl=pl)
  15. if terms[i] > nstore:
  16. raise ValueError('Not enougth storage was allocated to keep all terms.\n'
  17. 'Increase value of "nstore" argument in "scattcoeffs" function!')
  18. an[i,:terms[i]] = a
  19. bn[i,:terms[i]] = b
  20. return terms, an, bn
  21. #scattcoeffs()