Commit f228e408 by Uddeepta Deka

updated with new hyp1f1 file

parent bd02a6ec
Showing with 35 additions and 60 deletions
...@@ -4,48 +4,23 @@ from scipy import special ...@@ -4,48 +4,23 @@ from scipy import special
from mpmath import hyp1f1 from mpmath import hyp1f1
import pickle import pickle
def ampfac_analytic(w, y, intrp_hyp1f1=None): def lens_ampl_function_wave_optics(w, y_l, intrp_hyp1f1=None):
""" """ frequency dependent lensing magnification """
Computes the analytic amplification factor for isolated point mass lens x_m = (y_l + np.sqrt(y_l**2 +4)) / 2.
Input params: phi_m = (x_m - y_l)**2/2. - np.log(x_m)
---------------
w : dimensionless angular frequency vector
y : impact parameter
Returns:
---------------
Complex amplification factor
"""
x_m = (y + np.sqrt(y**2 +4)) / 2.
phi_m = (x_m - y)**2/2. - np.log(x_m)
if intrp_hyp1f1==None: if intrp_hyp1f1==None:
# evaluate the hypergeometric fun using mpmath package # evaluate the hypergeometric fun using mpmath package
hyp_fn = np.vectorize(hyp1f1)(0.5*w*1j, 1., 0.5*w*y**2*1j, maxterms=1e6) hyp_fn = np.vectorize(mpmath.hyp1f1)(0.5*w*1j, 1., 0.5*w*y_l**2*1j, maxterms=1e6)
hyp_fn = np.array(hyp_fn.tolist(),dtype=complex) # convert to numpy array from mpmath format hyp_fn = np.array(hyp_fn.tolist(),dtype=complex) # convert to numpy array from mpmath format
else: else:
# evaluate the interpolated function # evaluate the interpolated function
hyp_fn = 10**intrp_hyp1f1['log_abs'](w, y)*np.exp(1j*intrp_hyp1f1['arg'](w,y)) hyp_fn = 10**intrp_hyp1f1['log_abs'](w, y_l)*np.exp(1j*intrp_hyp1f1['arg'](w, y_l))
return np.exp(np.pi*w/4.+0.5*w*1j*(np.log(w/2.)-2*phi_m))*special.gamma(np.ones(len(w))-0.5*w*1j)*hyp_fn return np.exp(np.pi*w/4.+0.5*w*1j*(np.log(w/2.)-2*phi_m))*special.gamma(np.ones(len(w))-0.5*w*1j)*hyp_fn
def ampfac_geom(w, y): def lens_ampl_function_geom_optics(w, y):
""" """ frequency dependent lensing magnification (geometric optics limit) """
Amplification factor in geometric optics limit
for unresolved images
Eqn 15, Takahashi, Nakamura 2003
Input params:
---------------
w : dimensionless angular frequency vector
y : impact parameter
Returns:
---------------
Complex amplification factor
"""
# time delay # time delay
sqrt_ysqr_p4 = np.sqrt(y**2+4) sqrt_ysqr_p4 = np.sqrt(y**2+4)
delta_Td_hat = 0.5*y*sqrt_ysqr_p4 + np.log((sqrt_ysqr_p4+y)/(sqrt_ysqr_p4-y)) # this is dimensionless delta_Td_hat = 0.5*y*sqrt_ysqr_p4 + np.log((sqrt_ysqr_p4+y)/(sqrt_ysqr_p4-y)) # this is dimensionless
...@@ -57,30 +32,30 @@ def ampfac_geom(w, y): ...@@ -57,30 +32,30 @@ def ampfac_geom(w, y):
# magnification function # magnification function
return np.sqrt(np.abs(mu_p)) - 1j*np.sqrt(np.abs(mu_m))*np.exp(1j*w*delta_Td_hat) return np.sqrt(np.abs(mu_p)) - 1j*np.sqrt(np.abs(mu_m))*np.exp(1j*w*delta_Td_hat)
def ampfac_hybrid(w, y, intrp_hyp1f1=None):
""" def lens_ampl_function(w, y_l, intrp_hyp1f1=None):
Hybrid amplification factor """ frequency dependent lensing magnification: hybrid using wave optics and geometric optics """
Input params: # if y > 3 geometric optics provides a good approximation
--------------- if y_l > 3:
w : dimensionless angular frequency vector F_f = lens_ampl_function_geom_optics(w, y_l)
y : impact parameter
# if y <= 3, use a combination of wave optics (low freq) and geom optics (high freq)
Returns: else:
--------------- w_max = 150
Complex amplification factor w_1 = w[np.where(w <= w_max)[0]]
""" w_2 = w[np.where(w > w_max)[0]]
# if y >= 1.5 geometric optics provides a good approximation if len(w_1) == 0:
if y >= 2: F_f = lens_ampl_function_geom_optics(w, y_l)
F_f = ampfac_geom(w, y)
# if y < 2, use a combination of wave optics (low freq) and geom optics (high freq) else:
else: if len(w_2) != 0:
F_f=np.zeros(len(w),dtype='complex128') F_w = lens_ampl_function_wave_optics(w, y_l, intrp_hyp1f1=intrp_hyp1f1)
wo_idx = w < 100 F_g = lens_ampl_function_geom_optics(w, y_l)
if len(w[wo_idx]) > 1: F_f = np.concatenate((F_w,F_g))
F_f[wo_idx] = ampfac_analytic(w[wo_idx], y, intrp_hyp1f1=intrp_hyp1f1)
if len(w[~wo_idx]) > 1: else:
F_f[~wo_idx] = ampfac_analytic(w[~wo_idx], y) F_f = lens_ampl_function_wave_optics(w, y_l, intrp_hyp1f1=intrp_hyp1f1)
return F_f return F_f
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment