def effective_einstein_radius(self, kwargs_lens_list, k=None, spacing=1000): """ computes the radius with mean convergence=1 :param kwargs_lens: :param spacing: number of annular bins to compute the convergence (resolution of the Einstein radius estimate) :return: """ if 'center_x' in kwargs_lens_list[0]: center_x = kwargs_lens_list[0]['center_x'] center_y = kwargs_lens_list[0]['center_y'] elif self._lensModel.lens_model_list[0] in ['INTERPOL', 'INTERPOL_SCALED']: center_x, center_y = 0, 0 else: center_x, center_y = 0, 0 numPix = 200 deltaPix = 0.05 x_grid, y_grid = util.make_grid(numPix=numPix, deltapix=deltaPix) x_grid += center_x y_grid += center_y kappa = self._lensModel.kappa(x_grid, y_grid, kwargs_lens_list, k=k) if self._lensModel.lens_model_list[0] in ['INTERPOL', 'INTERPOL_SCALED']: center_x = x_grid[kappa == np.max(kappa)] center_y = y_grid[kappa == np.max(kappa)] kappa = util.array2image(kappa) r_array = np.linspace(0.0001, numPix*deltaPix/2., spacing) for r in r_array: mask = np.array(1 - mask_util.mask_center_2d(center_x, center_y, r, x_grid, y_grid)) sum_mask = np.sum(mask) if sum_mask > 0: kappa_mean = np.sum(kappa*mask)/np.sum(mask) if kappa_mean < 1: return r print(kwargs_lens_list, "Warning, no Einstein radius computed!") return r_array[-1]
def effective_einstein_radius(self, kwargs_lens_list, k=None): """ computes the radius with mean convergence=1 :param kwargs_lens: :return: """ center_x = kwargs_lens_list[0]['center_x'] center_y = kwargs_lens_list[0]['center_y'] numPix = 100 deltaPix = 0.05 x_grid, y_grid = util.make_grid(numPix=numPix, deltapix=deltaPix) x_grid += center_x y_grid += center_y kappa = self.kappa(x_grid, y_grid, kwargs_lens_list, k=k) kappa = util.array2image(kappa) r_array = np.linspace(0.0001, numPix*deltaPix/2., 1000) for r in r_array: mask = np.array(1 - mask_util.mask_center_2d(center_x, center_y, r, x_grid, y_grid)) sum_mask = np.sum(mask) if sum_mask > 0: kappa_mean = np.sum(kappa*mask)/np.sum(mask) if kappa_mean < 1: return r print(kwargs_lens_list, "Warning, no Einstein radius computed!") return r_array[-1]
def test_get_mask(): x = np.linspace(0, 10, 100) y = np.linspace(0, 10, 100) center_x = 5 center_y = 5 r = 1 mask = mask_util.mask_center_2d(center_x, center_y, r, x, y) assert mask[0][0] == 1 assert mask[5][5] == 0
def effective_einstein_radius(self, kwargs_lens, k=None, spacing=1000, get_precision=False, verbose=True): """ computes the radius with mean convergence=1 :param kwargs_lens: list of lens model keyword arguments :param spacing: number of annular bins to compute the convergence (resolution of the Einstein radius estimate) :param get_precision: If `True`, return the precision of estimated Einstein radius :return: estimate of the Einstein radius """ if 'center_x' in kwargs_lens[0]: center_x = kwargs_lens[0]['center_x'] center_y = kwargs_lens[0]['center_y'] elif self._lensModel.lens_model_list[0] in [ 'INTERPOL', 'INTERPOL_SCALED' ]: center_x, center_y = 0, 0 else: center_x, center_y = 0, 0 numPix = 200 deltaPix = 0.05 x_grid, y_grid = util.make_grid(numPix=numPix, deltapix=deltaPix) x_grid += center_x y_grid += center_y kappa = self._lensModel.kappa(x_grid, y_grid, kwargs_lens, k=k) if self._lensModel.lens_model_list[0] in [ 'INTERPOL', 'INTERPOL_SCALED' ]: center_x = x_grid[kappa == np.max(kappa)] center_y = y_grid[kappa == np.max(kappa)] kappa = util.array2image(kappa) r_array = np.linspace(0.0001, numPix * deltaPix / 2., spacing) for r in r_array: mask = np.array(1 - mask_util.mask_center_2d( center_x, center_y, r, x_grid, y_grid)) sum_mask = np.sum(mask) if sum_mask > 0: kappa_mean = np.sum(kappa * mask) / np.sum(mask) if kappa_mean < 1: if get_precision: return r, r_array[1] - r_array[0] else: return r if verbose: print(kwargs_lens, "Warning, no Einstein radius computed!") return np.nan #r_array[-1]