import numpy as np def calctav(alfa, nr): """ Calculate average transmittance of isotropic light across a dielectric surface. Translated from MATLAB version of calctav.m. Parameters: alfa : incidence angle in degrees (scalar or array) nr : refractive index of second medium (scalar or array of same shape as alfa) Returns: tav : average transmittance (same shape as alfa) """ alfa = np.asarray(alfa) nr = np.asarray(nr) rd = np.pi / 180.0 n2 = nr ** 2 np_ = n2 + 1 nm = n2 - 1 a = ((nr + 1) ** 2) / 2 k = -((n2 - 1) ** 2) / 4 sa = np.sin(alfa * rd) b1 = np.where(alfa != 90, np.sqrt((sa ** 2 - np_ / 2) ** 2 + k), 0.0) b2 = sa ** 2 - np_ / 2 b = b1 - b2 b3 = b ** 3 a3 = a ** 3 ts = (k ** 2 / (6 * b3) + k / b - b / 2) - (k ** 2 / (6 * a3) + k / a - a / 2) tp1 = -2 * n2 * (b - a) / (np_ ** 2) tp2 = -2 * n2 * np_ * np.log(b / a) / (nm ** 2) tp3 = n2 * (1 / b - 1 / a) / 2 tp4 = 16 * n2 ** 2 * (n2 ** 2 + 1) * np.log((2 * np_ * b - nm ** 2) / (2 * np_ * a - nm ** 2)) / (np_ ** 3 * nm ** 2) tp5 = 16 * n2 ** 3 * (1 / (2 * np_ * b - nm ** 2) - 1 / (2 * np_ * a - nm ** 2)) / (np_ ** 3) tp = tp1 + tp2 + tp3 + tp4 + tp5 tav = (ts + tp) / (2 * sa ** 2) return tav