def deflections_2d_from_grid(self, grid): if self.preload_grid is not None and self.preload_deflections is not None: if grid.sub_shape_slim == self.preload_grid.sub_shape_slim: if np.allclose(grid, self.preload_grid, 1e-8): return self.normalization_scale * self.preload_deflections if (self.preload_blurring_grid is not None and self.preload_blurring_deflections is not None): if grid.sub_shape_slim == self.preload_blurring_grid.sub_shape_slim: if np.allclose(grid, self.preload_blurring_grid, 1e-8): return self.normalization_scale * self.preload_blurring_deflections deflections_y = self.normalization_scale * griddata( points=self.image_plane_grid, values=self.deflections_y, xi=grid) deflections_x = self.normalization_scale * griddata( points=self.image_plane_grid, values=self.deflections_x, xi=grid) if np.isnan(deflections_y).any() or np.isnan(deflections_x).any(): raise exc.ProfileException( "The grid input into the DefectionsInput.deflections_2d_from_grid() method has (y,x)" "coodinates extending beyond the input image_plane_grid." "" "Update the image_plane_grid to include deflection angles reaching to larger" "radii or reduce the input grid. ") return np.stack((deflections_y, deflections_x), axis=-1)
def normalization_via_mass_angular_from( self, mass_angular, radius, normalization_min=1e-15, normalization_max=1e15, bins=200, ): normalization_list = np.logspace(np.log10(normalization_min), np.log10(normalization_max), bins) mass_angulars = [ self.mass_angular_via_normalization_from( normalization=normalization, radius=radius) for normalization in normalization_list ] normalization_list = [ normalization for normalization, mass in zip(normalization_list, mass_angulars) if mass is not None ] mass_angulars = list(filter(None, mass_angulars)) if ((len(mass_angulars) < 2) or (mass_angulars[0] > mass_angular) or (mass_angulars[-1] < mass_angular)): raise exc.ProfileException( "The normalization could not be computed from the Einstein Radius via the average of the convergence. " "" "The input einstein_radius may be too small or large to feasibly be computed by integrating the " "convergence. Alternative the normalization range or number of bins may need to be changed to " "capture the true einstein_radius value.") def func(normalization, mass_angular_root, radius): mass_angular = self.mass_angular_via_normalization_from( normalization=normalization, radius=radius) return mass_angular - mass_angular_root return root_scalar( func, bracket=[normalization_list[0], normalization_list[-1]], args=(mass_angular, radius), ).root
def normalization_via_einstein_radius_from(self, einstein_radius, normalization_min=1e-9, normalization_max=1e9, bins=100): normalization_list = np.logspace(np.log10(normalization_min), np.log10(normalization_max), bins) einstein_radii = [ self.einstein_radius_via_normalization_from( normalization=normalization) for normalization in normalization_list ] normalization_list = [ normalization for normalization, radii in zip(normalization_list, einstein_radii) if radii is not None ] einstein_radii = list(filter(None, einstein_radii)) if ((len(einstein_radii) < 2) or (einstein_radii[0] > einstein_radius) or (einstein_radii[-1] < einstein_radius)): raise exc.ProfileException( "The normalization could not be computed from the Einstein Radius via the average of the convergence. " "" "The input einstein_radius may be too small or large to feasibly be computed by integrating the " "convergence. Alternative the normalization range or number of bins may need to be changed to " "capture the true einstein_radius value.") def func(normalization, einstein_radius_root): einstein_radius = self.einstein_radius_via_normalization_from( normalization=normalization) return einstein_radius - einstein_radius_root return root_scalar( func, bracket=[normalization_list[0], normalization_list[-1]], args=(einstein_radius, ), ).root