def deflections(self, xin, yin): from numpy import ones, arctan as atan, arctanh as atanh from math import cos, sin, pi from numpy import arcsin as asin, arcsinh as asinh x, y = self.align_coords(xin, yin) q = self.q if q == 1.: q = 1. - 1e-7 # Avoid divide-by-zero errors eps = (1. - q**2)**0.5 if self.eta == 1.: # SIE models r = (x**2 + y**2)**0.5 r[r == 0.] = 1e-9 xout = self.b * asinh(eps * x / q / r) * q**0.5 / eps yout = self.b * asin(eps * y / r) * q**0.5 / eps else: from powerlaw import powerlawdeflections as pld b, eta = self.b, self.eta s = 1e-7 if x.ndim > 1: yout, xout = pld(-1 * y.ravel(), x.ravel(), b, eta, s, q) xout, yout = xout.reshape(x.shape), -1 * yout.reshape(y.shape) else: yout, xout = pld(-1 * y, x, b, eta, s, q) yout = -1 * yout theta = -(self.theta - pi / 2.) ctheta = cos(theta) stheta = sin(theta) x = xout * ctheta + yout * stheta y = yout * ctheta - xout * stheta return x, y
def deflections(self, xin, yin, d=1): b = self.b * d from numpy import ones, arctan as atan, arctanh as atanh from math import cos, sin, pi from numpy import arcsin as asin, arcsinh as asinh x, y = self.align_coords(xin, yin, False) q = self.q if q == 1.: q = 1. - 1e-7 # Avoid divide-by-zero errors eps = (1. - q**2)**0.5 if self.eta == 1.: # SIE models r = (x**2 + y**2)**0.5 r[r == 0.] = 1e-9 # xout = self.b*asinh(eps*x/q/r)*q**0.5/eps # yout = self.b*asin(eps*y/r)*q**0.5/eps xout = b * asinh(eps * y / q / r) * q**0.5 / eps yout = b * asin(eps * -x / r) * q**0.5 / eps xout, yout = -yout, xout x, y = self.align_coords(xout, yout, False, revert=True) return x - self.x, y - self.y theta = 2 - self.theta #-(self.theta - pi/2.) ctheta = cos(theta) stheta = sin(theta) x = xout * ctheta + yout * stheta y = yout * ctheta - xout * stheta return x, y else: from powerlaw import powerlawdeflections as pld b, eta = b, self.eta s = 1e-4 if x.ndim > 1: # yout,xout = pld(-1*y.ravel(),x.ravel(),b,eta,s,q) # xout,yout = xout.reshape(x.shape),-1*yout.reshape(y.shape) xout, yout = pld(x.ravel(), y.ravel(), b, eta, s, q) xout, yout = xout.reshape(x.shape), yout.reshape(y.shape) else: xout, yout = pld(x, y, b, eta, s, q) # yout,xout = pld(-1*y,x,b,eta,s,q) # yout = -1*yout # theta = -(self.theta - pi/2.) # ctheta = cos(theta) # stheta = sin(theta) # x = xout*ctheta+yout*stheta # y = yout*ctheta-xout*stheta # return x,y x, y = self.align_coords(xout, yout, False, revert=True) return x - self.x, y - self.y
def deflections(self, xin, yin): if self.NoFreeParams == True: try: return self.deflx, self.defly except: pass x, y = self.align_coords(xin, yin) q = self.q if q == 1.: q = 1. - 1e-7 # Avoid divide-by-zero errors eps = (1. - q**2)**0.5 if self.eta == 1.: # SIE models r = (x**2 + y**2)**0.5 r[r == 0.] = 1e-9 xout = self.b * np.arcsinh(eps * x / q / r) * q**0.5 / eps yout = self.b * np.arcsin(eps * y / r) * q**0.5 / eps else: from powerlaw import powerlawdeflections as pld b, eta = self.b, self.eta s = 1e-7 if x.ndim > 1: yout, xout = pld(-1 * y.ravel(), x.ravel(), b, eta, s, q) xout, yout = xout.reshape(x.shape), -1 * yout.reshape(y.shape) else: yout, xout = pld(-1 * y, x, b, eta, s, q) yout = -1 * yout theta = -(self.theta - np.pi / 2.) ctheta = np.cos(theta) stheta = np.sin(theta) x = xout * ctheta + yout * stheta y = yout * ctheta - xout * stheta self.deflx = x self.defly = y return x, y
def caustic(self): if self.eta != 1: from powerlaw import powerlawmag as plm, powerlawdeflections as pld import numpy from scipy import interpolate q = self.q b, eta = self.b, self.eta gam = eta * 0.5 q0 = (1.0 - gam) * b**(2.0 * gam) / (q**gam) r = numpy.linspace(q0 / 2., q0 * 2, 100) x0, y0, mag = plm(r, r * 0., b, eta, 1e-4, q) if mag[0] > 0: r = numpy.linspace(1e-7, q0 * 2, 200) x0, y0, mag = plm(r, r * 0., b, eta, 1e-4, q) while mag[-1] < 0: q0 *= 2 r = numpy.linspace(q0 / 2., q0 * 2, 100) x0, y0, mag = plm(r, r * 0., b, eta, 1e-4, q) tmp = interpolate.splrep(r, mag) root = interpolate.sproot(tmp, 1)[0] theta = numpy.linspace(0, numpy.pi / 2, 500) ctheta = numpy.cos(theta) stheta = numpy.sin(theta) rvals = theta * 0. + root for i in range(1, theta.size): r = numpy.linspace(root * 0.9, root * 1.1, 20) x = r * ctheta[i] y = r * stheta[i] x0, y0, mag = plm(x, y, b, eta, 1e-4, q) while mag[0] > 0: root *= 0.9 r = numpy.linspace(root * 0.9, root * 1.1, 20) x = r * ctheta[i] y = r * stheta[i] x0, y0, mag = plm(x, y, b, eta, 1e-4, q) while mag[-1] < 0: root *= 1.1 r = numpy.linspace(root * 0.9, root * 1.1, 20) x = r * ctheta[i] y = r * stheta[i] x0, y0, mag = plm(x, y, b, eta, 1e-4, q) tmp = interpolate.splrep(r, mag) root = interpolate.sproot(tmp, 1)[0] rvals[i] = root x, y = rvals * ctheta, rvals * stheta x = numpy.concatenate( (x, -1 * x[::-1][1:], -1 * x[1:], x[::-1][1:])) y = numpy.concatenate( (y, y[::-1][1:], -1 * y[1:], -1 * y[::-1][1:])) x0, y0 = pld(x, y, b, eta, 1e-4, q) x0, y0 = self.align_coords(x - x0, y - y0, False, revert=True) return x0, y0 from numpy import ones, arctan as atan, arctanh as atanh from numpy import cos, sin, pi, linspace from numpy import arcsin as asin, arcsinh as asinh q = self.q if q == 1.: q = 1. - 1e-7 # Avoid divide-by-zero errors eps = (1. - q**2)**0.5 theta = linspace(0, 2 * pi, 5000) ctheta = cos(theta) stheta = sin(theta) delta = (ctheta**2 + q**2 * stheta**2)**0.5 xout = ctheta * q**0.5 / delta - asinh(eps * ctheta / q) * q**0.5 / eps yout = stheta * q**0.5 / delta - asin(eps * stheta) * q**0.5 / eps xout, yout = xout * self.b, yout * self.b theta = -(self.theta - pi / 2.) ctheta = cos(theta) stheta = sin(theta) x = xout * ctheta + yout * stheta y = yout * ctheta - xout * stheta return x + self.x, y + self.y