def test__6_galaxies_producing_4_planes(self): g0 = g.Galaxy(redshift=1.0) g1 = g.Galaxy(redshift=1.0) g2 = g.Galaxy(redshift=0.1) g3 = g.Galaxy(redshift=1.05) g4 = g.Galaxy(redshift=0.95) g5 = g.Galaxy(redshift=1.05) galaxies = [g0, g1, g2, g3, g4, g5] ordered_plane_redshifts = lens_util.ordered_plane_redshifts_from_galaxies( galaxies=galaxies) assert ordered_plane_redshifts == [0.1, 0.95, 1.0, 1.05] ordered_galaxies = lens_util.galaxies_in_redshift_ordered_planes_from_galaxies( galaxies=galaxies, plane_redshifts=ordered_plane_redshifts) assert ordered_galaxies[0][0].redshift == 0.1 assert ordered_galaxies[1][0].redshift == 0.95 assert ordered_galaxies[2][0].redshift == 1.0 assert ordered_galaxies[2][1].redshift == 1.0 assert ordered_galaxies[3][0].redshift == 1.05 assert ordered_galaxies[3][1].redshift == 1.05 assert ordered_galaxies[0] == [g2] assert ordered_galaxies[1] == [g4] assert ordered_galaxies[2] == [g0, g1] assert ordered_galaxies[3] == [g3, g5]
def from_galaxies(cls, galaxies, cosmology=cosmo.Planck15): plane_redshifts = lens_util.ordered_plane_redshifts_from_galaxies( galaxies=galaxies) galaxies_in_planes = lens_util.galaxies_in_redshift_ordered_planes_from_galaxies( galaxies=galaxies, plane_redshifts=plane_redshifts) planes = [] for plane_index in range(0, len(plane_redshifts)): planes.append( pl.Plane(galaxies=galaxies_in_planes[plane_index], cosmology=cosmology)) return Tracer(planes=planes, cosmology=cosmology)
def test__3_galaxies_reordered_in_ascending_redshift(self): galaxies = [ g.Galaxy(redshift=2.0), g.Galaxy(redshift=1.0), g.Galaxy(redshift=0.1) ] ordered_plane_redshifts = lens_util.ordered_plane_redshifts_from_galaxies( galaxies=galaxies) assert ordered_plane_redshifts == [0.1, 1.0, 2.0] ordered_galaxies = lens_util.galaxies_in_redshift_ordered_planes_from_galaxies( galaxies=galaxies, plane_redshifts=ordered_plane_redshifts) assert ordered_galaxies[0][0].redshift == 0.1 assert ordered_galaxies[1][0].redshift == 1.0 assert ordered_galaxies[2][0].redshift == 2.0
def test_3_galaxies_two_same_redshift_planes_redshift_order_is_size_2_with_redshifts( self): galaxies = [ g.Galaxy(redshift=1.0), g.Galaxy(redshift=1.0), g.Galaxy(redshift=0.1) ] ordered_plane_redshifts = lens_util.ordered_plane_redshifts_from_galaxies( galaxies=galaxies) assert ordered_plane_redshifts == [0.1, 1.0] ordered_galaxies = lens_util.galaxies_in_redshift_ordered_planes_from_galaxies( galaxies=galaxies, plane_redshifts=ordered_plane_redshifts) assert ordered_galaxies[0][0].redshift == 0.1 assert ordered_galaxies[1][0].redshift == 1.0 assert ordered_galaxies[1][1].redshift == 1.0
def sliced_tracer_from_lens_line_of_sight_and_source_galaxies( cls, lens_galaxies, line_of_sight_galaxies, source_galaxies, planes_between_lenses, cosmology=cosmo.Planck15, ): """Ray-tracer for a lens system with any number of planes. The redshift of these planes are specified by the input parameters *lens_redshifts* and \ *slices_between_main_planes*. Every galaxy is placed in its closest plane in redshift-space. To perform multi-plane ray-tracing, a cosmology must be supplied so that deflection-angles can be rescaled \ according to the lens-geometry of the multi-plane system. All galaxies input to the tracer must therefore \ have redshifts. This tracer has only one grid (see gridStack) which is used for ray-tracing. Parameters ---------- lens_galaxies : [Galaxy] The list of galaxies in the ray-tracing calculation. image_plane_grid : grid_stacks.GridStack The image-plane al.ogrid which is traced. (includes the grid, sub-grid, blurring-grid, etc.). planes_between_lenses : [int] The number of slices between each main plane. The first entry in this list determines the number of slices \ between Earth (redshift 0.0) and main plane 0, the next between main planes 0 and 1, etc. border : masks.GridBorder The border of the grid, which is used to relocate demagnified traced pixels to the \ source-plane borders. cosmology : astropy.cosmology The cosmology of the ray-tracing calculation. """ lens_redshifts = lens_util.ordered_plane_redshifts_from_galaxies( galaxies=lens_galaxies) plane_redshifts = lens_util.ordered_plane_redshifts_from_lens_source_plane_redshifts_and_slice_sizes( lens_redshifts=lens_redshifts, planes_between_lenses=planes_between_lenses, source_plane_redshift=source_galaxies[0].redshift, ) galaxies_in_planes = lens_util.galaxies_in_redshift_ordered_planes_from_galaxies( galaxies=lens_galaxies + line_of_sight_galaxies, plane_redshifts=plane_redshifts, ) plane_redshifts.append(source_galaxies[0].redshift) galaxies_in_planes.append(source_galaxies) planes = [] for plane_index in range(0, len(plane_redshifts)): planes.append( pl.Plane( redshift=plane_redshifts[plane_index], galaxies=galaxies_in_planes[plane_index], cosmology=cosmology, )) return Tracer(planes=planes, cosmology=cosmology)
def __init__(self, galaxies, image_plane_grid_stacks, borders=None, cosmology=cosmo.Planck15): """Ray-tracer for a lens system with any number of planes. To perform multi-plane ray-tracing, the cosmology that is input is used to rescale deflection-angles \ according to the lens-geometry of the multi-plane system. All galaxies input to the tracer must therefore \ have redshifts. This tracer has a list of grid-stacks (see grid_stack.GridStack) which are all used for ray-tracing. Parameters ---------- galaxies : [Galaxy] The list of galaxies in the ray-tracing calculation. image_plane_grid_stacks : [grid_stacks.GridStack] The image-plane grid stacks which are traced. (each stack includes the regular-grid, sub-grid, \ blurring-grid, etc.). borders : [masks.RegularGridBorder] The border of each grid-stacks's regular-grid, which is used to relocate demagnified traced pixels to the \ source-plane border. cosmology : astropy.cosmology The cosmology of the ray-tracing calculation. """ ordered_redshifts = lens_util.ordered_plane_redshifts_from_galaxies( galaxies=galaxies) galaxies_in_redshift_ordered_lists = \ lens_util.galaxies_in_redshift_ordered_planes_from_galaxies(galaxies=galaxies, plane_redshifts=ordered_redshifts) image_plane_grid_stacks = list( map( lambda grid_stack: pix. setup_image_plane_pixelization_grid_from_galaxies_and_grid_stack( galaxies=galaxies, grid_stack=grid_stack), image_plane_grid_stacks)) planes = [] for plane_index in range(0, len(ordered_redshifts)): if plane_index < len(ordered_redshifts) - 1: compute_deflections = True elif plane_index == len(ordered_redshifts) - 1: compute_deflections = False else: raise exc.RayTracingException( 'A galaxy was not correctly allocated its previous / next redshifts' ) new_grid_stacks = image_plane_grid_stacks if plane_index > 0: for previous_plane_index in range(plane_index): scaling_factor = lens_util.scaling_factor_between_redshifts_for_cosmology( z1=ordered_redshifts[previous_plane_index], z2=ordered_redshifts[plane_index], z_final=ordered_redshifts[-1], cosmology=cosmology) def scale(grid): return np.multiply(scaling_factor, grid) if planes[ previous_plane_index].deflection_stacks is not None: scaled_deflections = list( map( lambda deflection_stack: deflection_stack. apply_function(scale), planes[previous_plane_index].deflection_stacks) ) else: scaled_deflections = None if scaled_deflections is not None: def minus(grid, deflections): return grid - deflections new_grid_stacks = list( map( lambda grid, deflections: grid.map_function( minus, deflections), new_grid_stacks, scaled_deflections)) planes.append( plane_stack.PlaneStack( galaxies=galaxies_in_redshift_ordered_lists[plane_index], grid_stacks=new_grid_stacks, borders=borders, compute_deflections=compute_deflections, cosmology=cosmology)) super(TracerMultiPlanesStack, self).__init__(planes=planes, cosmology=cosmology)
def __init__(self, galaxies, image_plane_positions, cosmology=cosmo.Planck15): """Positional ray-tracer for a lens system with any number of planes. To perform multi-plane ray-tracing, a cosmology must be supplied so that deflection-angles can be rescaled \ according to the lens-geometry of the multi-plane system. Parameters ---------- galaxies : [Galaxy] The list of galaxies in the ray-tracing calculation. image_plane_positions : [[[]]] The (y,x) arc-second coordinates of image-plane pixels which (are expected to) mappers to the same location(s) \ in the final source-plane. cosmology : astropy.cosmology The cosmology of the ray-tracing calculation. """ ordered_redshifts = lens_util.ordered_plane_redshifts_from_galaxies( galaxies=galaxies) galaxies_in_redshift_ordered_lists = \ lens_util.galaxies_in_redshift_ordered_planes_from_galaxies(galaxies=galaxies, plane_redshifts=ordered_redshifts) if not galaxies: raise exc.RayTracingException( 'No galaxies have been input into the Tracer (TracerImageSourcePlanes)' ) planes = [] for plane_index in range(0, len(ordered_redshifts)): if plane_index < len(ordered_redshifts) - 1: compute_deflections = True elif plane_index == len(ordered_redshifts) - 1: compute_deflections = False else: raise exc.RayTracingException( 'A galaxy was not correctly allocated its previous / next redshifts' ) new_positions = image_plane_positions if plane_index > 0: for previous_plane_index in range(plane_index): scaling_factor = lens_util.scaling_factor_between_redshifts_for_cosmology( z1=ordered_redshifts[previous_plane_index], z2=ordered_redshifts[plane_index], z_final=ordered_redshifts[-1], cosmology=cosmology) scaled_deflections = list( map( lambda deflections: np.multiply( scaling_factor, deflections), planes[previous_plane_index].deflections)) new_positions = list( map( lambda positions, deflections: np.subtract( positions, deflections), new_positions, scaled_deflections)) planes.append( pl.PlanePositions( galaxies=galaxies_in_redshift_ordered_lists[plane_index], positions=new_positions, compute_deflections=compute_deflections)) super(TracerMultiPlanesPositions, self).__init__(planes=planes, cosmology=cosmology)
def __init__(self, galaxies, image_plane_grid_stack, border=None, cosmology=cosmo.Planck15): """Ray-tracer for a lens system with any number of planes. To perform multi-plane ray-tracing, a cosmology must be supplied so that deflection-angles can be rescaled \ according to the lens-geometry of the multi-plane system. All galaxies input to the tracer must therefore \ have redshifts. This tracer has only one grid-stack (see grid_stack.GridStack) which is used for ray-tracing. Parameters ---------- galaxies : [Galaxy] The list of galaxies in the ray-tracing calculation. image_plane_grid_stack : grid_stacks.GridStack The image-plane grid stack which is traced. (includes the regular-grid, sub-grid, blurring-grid, etc.). border : masks.RegularGridBorder The border of the regular-grid, which is used to relocate demagnified traced pixels to the \ source-plane borders. cosmology : astropy.cosmology The cosmology of the ray-tracing calculation. """ plane_redshifts = lens_util.ordered_plane_redshifts_from_galaxies( galaxies=galaxies) galaxies_in_planes = \ lens_util.galaxies_in_redshift_ordered_planes_from_galaxies(galaxies=galaxies, plane_redshifts=plane_redshifts) image_plane_grid_stack = pix.setup_image_plane_pixelization_grid_from_galaxies_and_grid_stack( galaxies=galaxies, grid_stack=image_plane_grid_stack) planes = [] for plane_index in range(0, len(plane_redshifts)): compute_deflections = lens_util.compute_deflections_at_next_plane( plane_index=plane_index, total_planes=len(plane_redshifts)) new_grid_stack = image_plane_grid_stack if plane_index > 0: for previous_plane_index in range(plane_index): scaling_factor = lens_util.scaling_factor_between_redshifts_for_cosmology( z1=plane_redshifts[previous_plane_index], z2=plane_redshifts[plane_index], z_final=plane_redshifts[-1], cosmology=cosmology) scaled_deflection_stack = lens_util.scaled_deflection_stack_from_plane_and_scaling_factor( plane=planes[previous_plane_index], scaling_factor=scaling_factor) new_grid_stack = \ lens_util.grid_stack_from_deflection_stack(grid_stack=new_grid_stack, deflection_stack=scaled_deflection_stack) planes.append( pl.Plane(galaxies=galaxies_in_planes[plane_index], grid_stack=new_grid_stack, border=border, compute_deflections=compute_deflections, cosmology=cosmology)) super(TracerMultiPlanes, self).__init__(planes=planes, cosmology=cosmology)