Skip to content

Commit

Permalink
blck
Browse files Browse the repository at this point in the history
  • Loading branch information
Jammy2211 committed Mar 8, 2024
1 parent ae08a84 commit e5ef3cd
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 53 deletions.
5 changes: 3 additions & 2 deletions autolens/lens/plot/tracer_plotters.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ def figures_2d_of_planes(
plane_indexes = self.plane_indexes_from(plane_index=plane_index)

for plane_index in plane_indexes:

galaxies_plotter = self.galaxies_plotter_from(plane_index=plane_index)

if plane_index == 1:
Expand Down Expand Up @@ -432,5 +431,7 @@ def subplot_galaxies_images(self):
plane_image=True, title_suffix=f" Of Plane {plane_index}"
)

self.mat_plot_2d.output.subplot_to_figure(auto_filename=f"subplot_galaxies_images")
self.mat_plot_2d.output.subplot_to_figure(
auto_filename=f"subplot_galaxies_images"
)
self.close_subplot_figure()
6 changes: 2 additions & 4 deletions autolens/lens/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(
different calculations.
"""

self.galaxies = galaxies=galaxies
self.galaxies = galaxies = galaxies

self.cosmology = cosmology

Expand Down Expand Up @@ -189,9 +189,7 @@ def sliced_tracer_from(
The cosmology used to perform ray-tracing calculations.
"""

lens_redshifts = tracer_util.plane_redshifts_from(
galaxies=lens_galaxies
)
lens_redshifts = tracer_util.plane_redshifts_from(galaxies=lens_galaxies)

plane_redshifts = tracer_util.ordered_plane_redshifts_with_slicing_from(
lens_redshifts=lens_redshifts,
Expand Down
13 changes: 6 additions & 7 deletions autolens/lens/tracer_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import autoarray as aa
import autogalaxy as ag

def plane_redshifts_from(galaxies : List[ag.Galaxy]) -> List[float]:

def plane_redshifts_from(galaxies: List[ag.Galaxy]) -> List[float]:
"""
Returns a list of plane redshifts from a list of galaxies, using the redshifts of the galaxies to determine the
unique redshifts of the planes.
Expand Down Expand Up @@ -34,7 +35,9 @@ def plane_redshifts_from(galaxies : List[ag.Galaxy]) -> List[float]:
return list(dict.fromkeys(plane_redshifts))


def planes_from(galaxies : List[ag.Galaxy], plane_redshifts : Optional[List[float]] = None) -> List[List[ag.Galaxy]]:
def planes_from(
galaxies: List[ag.Galaxy], plane_redshifts: Optional[List[float]] = None
) -> List[List[ag.Galaxy]]:
"""
Returns a list of list of galaxies grouped into their planes, where planes contained all galaxies at the same
unique redshift.
Expand Down Expand Up @@ -219,9 +222,7 @@ def grid_2d_at_redshift_from(
if redshift <= plane_redshifts[0]:
return grid.copy()

planes = planes_from(
galaxies=galaxies, plane_redshifts=plane_redshifts
)
planes = planes_from(galaxies=galaxies, plane_redshifts=plane_redshifts)

plane_index_with_redshift = [
plane_index
Expand Down Expand Up @@ -249,8 +250,6 @@ def grid_2d_at_redshift_from(
return traced_grid_list[plane_index_insert]




def ordered_plane_redshifts_with_slicing_from(
lens_redshifts, planes_between_lenses, source_plane_redshift
):
Expand Down
7 changes: 2 additions & 5 deletions test_autolens/lens/test_operate.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ def test__operate_image__blurred_images_2d_via_convolver_from__for_tracer_gives_
blurring_grid=source_blurring_grid_2d_7x7,
)

tracer = al.Tracer(
galaxies=[g0, g1], cosmology=al.cosmo.Planck15()
)
tracer = al.Tracer(galaxies=[g0, g1], cosmology=al.cosmo.Planck15())

blurred_image = tracer.blurred_image_2d_from(
grid=sub_grid_2d_7x7,
Expand Down Expand Up @@ -115,8 +113,7 @@ def test__operate_image__visibilities_of_planes_from_grid_and_transformer(
grid=sub_grid_2d_7x7, transformer=transformer_7x7_7
)

tracer = al.Tracer(galaxies=[g0, g1], cosmology=al.cosmo.Planck15()
)
tracer = al.Tracer(galaxies=[g0, g1], cosmology=al.cosmo.Planck15())

visibilities = tracer.visibilities_list_from(
grid=sub_grid_2d_7x7, transformer=transformer_7x7_7
Expand Down
5 changes: 2 additions & 3 deletions test_autolens/lens/test_tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,6 @@ def test__extract_plane_index_of_profile():


def test__sliced_tracer_from(sub_grid_2d_7x7, sub_grid_2d_7x7_simple):

lens_g0 = al.Galaxy(redshift=0.5)
source_g0 = al.Galaxy(redshift=2.0)
los_g0 = al.Galaxy(redshift=0.1)
Expand All @@ -780,7 +779,6 @@ def test__sliced_tracer_from(sub_grid_2d_7x7, sub_grid_2d_7x7_simple):


def test__regression__centre_of_profile_in_right_place():

grid = al.Grid2D.uniform(shape_native=(7, 7), pixel_scales=1.0)

g0 = al.Galaxy(
Expand Down Expand Up @@ -873,6 +871,7 @@ def test__decorators__grid_iterate_in__iterates_array_result_correctly(gal_x1_lp

assert image[0] == image_sub_4[0]


def test__decorators__grid_iterate_in__method_returns_array_list__uses_highest_sub_size_of_iterate(
gal_x1_lp,
):
Expand Down Expand Up @@ -1003,4 +1002,4 @@ def test__output_to_and_load_from_json():
assert tracer_from_json.galaxies[1].redshift == 1.0
assert tracer_from_json.galaxies[0].mass_profile.einstein_radius == 1.0

assert isinstance(tracer_from_json.cosmology, al.cosmo.wrap.Planck15)
assert isinstance(tracer_from_json.cosmology, al.cosmo.wrap.Planck15)
43 changes: 11 additions & 32 deletions test_autolens/lens/test_tracer_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,13 @@
import autolens as al


def test__xtraced_grid_2d_list_from(
sub_grid_2d_7x7_simple
):
g0 = al.Galaxy(
redshift=2.0, mass_profile=al.mp.IsothermalSph(einstein_radius=1.0)
)
g1 = al.Galaxy(
redshift=2.0, mass_profile=al.mp.IsothermalSph(einstein_radius=1.0)
)
g2 = al.Galaxy(
redshift=0.1, mass_profile=al.mp.IsothermalSph(einstein_radius=1.0)
)
g3 = al.Galaxy(
redshift=3.0, mass_profile=al.mp.IsothermalSph(einstein_radius=1.0)
)
g4 = al.Galaxy(
redshift=1.0, mass_profile=al.mp.IsothermalSph(einstein_radius=1.0)
)
g5 = al.Galaxy(
redshift=3.0, mass_profile=al.mp.IsothermalSph(einstein_radius=1.0)
)
def test__xtraced_grid_2d_list_from(sub_grid_2d_7x7_simple):
g0 = al.Galaxy(redshift=2.0, mass_profile=al.mp.IsothermalSph(einstein_radius=1.0))
g1 = al.Galaxy(redshift=2.0, mass_profile=al.mp.IsothermalSph(einstein_radius=1.0))
g2 = al.Galaxy(redshift=0.1, mass_profile=al.mp.IsothermalSph(einstein_radius=1.0))
g3 = al.Galaxy(redshift=3.0, mass_profile=al.mp.IsothermalSph(einstein_radius=1.0))
g4 = al.Galaxy(redshift=1.0, mass_profile=al.mp.IsothermalSph(einstein_radius=1.0))
g5 = al.Galaxy(redshift=3.0, mass_profile=al.mp.IsothermalSph(einstein_radius=1.0))

galaxies = [g0, g1, g2, g3, g4, g5]

Expand Down Expand Up @@ -55,9 +41,7 @@ def test__xtraced_grid_2d_list_from(
defl11 = g0.deflections_yx_2d_from(
grid=np.array([[(1.0 - beta_01 * val), (1.0 - beta_01 * val)]])
)
defl12 = g0.deflections_yx_2d_from(
grid=np.array([[(1.0 - beta_01 * 1.0), 0.0]])
)
defl12 = g0.deflections_yx_2d_from(grid=np.array([[(1.0 - beta_01 * 1.0), 0.0]]))

assert traced_grid_list[2][0] == pytest.approx(
np.array(
Expand Down Expand Up @@ -155,9 +139,8 @@ def test__grid_2d_at_redshift_from(sub_grid_2d_7x7):

assert grid_at_redshift == pytest.approx(traced_grid_list[4], 1.0e-4)

def test__grid_2d_at_redshift_from__redshift_between_planes(
sub_grid_2d_7x7
):

def test__grid_2d_at_redshift_from__redshift_between_planes(sub_grid_2d_7x7):
sub_grid_2d_7x7[0] = np.array([[1.0, -1.0]])
sub_grid_2d_7x7[1] = np.array([[1.0, 0.0]])

Expand Down Expand Up @@ -188,8 +171,4 @@ def test__grid_2d_at_redshift_from__redshift_between_planes(
redshift=0.3,
)

assert (
grid_at_redshift == sub_grid_2d_7x7.mask.derive_grid.all_false_sub_1
).all()


assert (grid_at_redshift == sub_grid_2d_7x7.mask.derive_grid.all_false_sub_1).all()

0 comments on commit e5ef3cd

Please sign in to comment.