@@ -484,6 +484,173 @@ def test__simulate_imaging_data_and_fit__linear_light_profiles_and_pixelization_
484484 assert fit_linear .figure_of_merit == pytest .approx (- 86.61380401245304 , abs = 1.0e-4 )
485485
486486
487+ def test__simulate_imaging_data_and_fit__linear_light_profiles_and_pixelization__delaunay_split ():
488+
489+ grid = al .Grid2D .uniform (shape_native = (11 , 11 ), pixel_scales = 0.2 , over_sample_size = 2 )
490+
491+ psf = al .Kernel2D .from_gaussian (
492+ shape_native = (3 , 3 ), pixel_scales = 0.2 , sigma = 0.75 , normalize = True
493+ )
494+
495+ lens_galaxy = al .Galaxy (
496+ redshift = 0.5 ,
497+ light = al .lp .Sersic (centre = (0.1 , 0.1 ), intensity = 100.0 ),
498+ mass = al .mp .Isothermal (centre = (0.1 , 0.1 ), einstein_radius = 1.8 ),
499+ )
500+ source_galaxy = al .Galaxy (
501+ redshift = 1.0 ,
502+ bulge = al .lp .Sersic (intensity = 0.1 , sersic_index = 1.0 ),
503+ disk = al .lp .Sersic (intensity = 0.2 , sersic_index = 4.0 ),
504+ )
505+ tracer = al .Tracer (galaxies = [lens_galaxy , source_galaxy ])
506+
507+ dataset = al .SimulatorImaging (exposure_time = 300.0 , psf = psf , add_poisson_noise_to_data = False )
508+
509+ dataset = dataset .via_tracer_from (tracer = tracer , grid = grid )
510+ dataset .noise_map = al .Array2D .ones (
511+ shape_native = dataset .data .shape_native , pixel_scales = 0.2
512+ )
513+
514+ mask = al .Mask2D .circular (
515+ shape_native = dataset .data .shape_native , pixel_scales = 0.2 , radius = 0.81
516+ )
517+
518+ dataset = al .Imaging (
519+ data = dataset .data ,
520+ psf = dataset .psf ,
521+ noise_map = dataset .noise_map ,
522+ over_sample_size_lp = 2 ,
523+ over_sample_size_pixelization = 2
524+ )
525+
526+ masked_dataset = dataset .apply_mask (mask = mask )
527+
528+ lens_galaxy_linear = al .Galaxy (
529+ redshift = 0.5 ,
530+ light = al .lp_linear .Sersic (centre = (0.1 , 0.1 )),
531+ mass = al .mp .Isothermal (centre = (0.1 , 0.1 ), einstein_radius = 1.8 ),
532+ )
533+
534+ pixelization = al .Pixelization (
535+ mesh = al .mesh .Delaunay (),
536+ regularization = al .reg .AdaptiveBrightnessSplit (inner_coefficient = 0.01 , outer_coefficient = 0.1 , signal_scale = 0.1 ),
537+ )
538+
539+ source_galaxy_pix = al .Galaxy (redshift = 1.0 , pixelization = pixelization )
540+
541+ image_mesh = al .image_mesh .Overlay (shape = (7 , 7 ))
542+
543+ image_plane_mesh_grid = image_mesh .image_plane_mesh_grid_from (
544+ mask = masked_dataset .mask ,
545+ )
546+
547+ adapt_images = al .AdaptImages (
548+ galaxy_image_dict = {source_galaxy_pix : masked_dataset .data },
549+ galaxy_image_plane_mesh_grid_dict = {source_galaxy_pix : image_plane_mesh_grid },
550+ )
551+
552+ total_mapper_pixels = image_plane_mesh_grid .shape [0 ]
553+
554+ total_linear_light_profiles = 1
555+
556+ mapper_indices = al .mapper_indices_from (
557+ total_linear_light_profiles = total_linear_light_profiles ,
558+ total_mapper_pixels = total_mapper_pixels ,
559+ )
560+
561+ preloads = al .Preloads (
562+ mapper_indices = mapper_indices ,
563+ )
564+
565+ tracer_linear = al .Tracer (
566+ galaxies = [lens_galaxy_linear , source_galaxy_pix ]
567+ )
568+
569+ fit_linear = al .FitImaging (
570+ dataset = masked_dataset ,
571+ tracer = tracer_linear ,
572+ preloads = preloads ,
573+ adapt_images = adapt_images ,
574+ settings_inversion = al .SettingsInversion (use_positive_only_solver = False ),
575+ )
576+
577+ print (fit_linear .figure_of_merit )
578+
579+ assert fit_linear .inversion .reconstruction [0 :3 ] == pytest .approx (
580+ np .array (
581+ [
582+ 9.99646681e+01 , - 5.67132908e-01 , - 1.46698482e+00
583+ ]
584+ ),
585+ 1.0e-4 ,
586+ )
587+
588+ assert fit_linear .figure_of_merit == pytest .approx (- 180.741826 , 1.0e-4 )
589+
590+ lens_galaxy_image = lens_galaxy .blurred_image_2d_from (
591+ grid = masked_dataset .grids .lp ,
592+ blurring_grid = masked_dataset .grids .blurring ,
593+ psf = masked_dataset .psf
594+ )
595+
596+ assert fit_linear .galaxy_model_image_dict [lens_galaxy_linear ] == pytest .approx (
597+ lens_galaxy_image , 1.0e-2
598+ )
599+ assert fit_linear .model_images_of_planes_list [0 ] == pytest .approx (
600+ lens_galaxy_image , 1.0e-2
601+ )
602+
603+ assert fit_linear .galaxy_model_image_dict [source_galaxy_pix ][0 ] == pytest .approx (
604+ 0.1693805878359 , 1.0e-4
605+ )
606+
607+ assert fit_linear .model_images_of_planes_list [1 ][0 ] == pytest .approx (
608+ 0.169380587835933 , 1.0e-4
609+ )
610+
611+ assert fit_linear .subtracted_images_of_planes_list [1 ][0 ] == pytest .approx (
612+ 0.35104147050036 , 1.0e-4
613+ )
614+
615+ preloads = al .Preloads (
616+ mapper_indices = mapper_indices ,
617+ source_pixel_zeroed_indices = [2 , 4 , 5 , 7 , 8 , 9 , 12 , 14 , 17 , 19 , 21 , 22 , 24 ]
618+ )
619+
620+ fit_linear = al .FitImaging (
621+ dataset = masked_dataset ,
622+ tracer = tracer_linear ,
623+ preloads = preloads ,
624+ adapt_images = adapt_images ,
625+ settings_inversion = al .SettingsInversion (
626+ use_positive_only_solver = True ,
627+ ),
628+ )
629+
630+ assert fit_linear .inversion .reconstruction [0 :14 ] == pytest .approx (
631+ np .array (
632+ [
633+ 99.9897887 ,
634+ 1.04085235 ,
635+ 0.0 ,
636+ 0.0 ,
637+ 0.0 ,
638+ 0.0 ,
639+ 0.376454064 ,
640+ 0.0 ,
641+ 0.0 ,
642+ 0.0 ,
643+ 0.0 ,
644+ 1.58216720 ,
645+ 0.0 ,
646+ 0.4396882719985 ,
647+ ]
648+ ),
649+ 1.0e-4 ,
650+ )
651+ assert fit_linear .figure_of_merit == pytest .approx (- 180.8284970580511 , 1.0e-4 )
652+
653+
487654def test__simulate_imaging_data_and_fit__complex_fit_compare_mapping_matrix_w_tilde ():
488655
489656 grid = al .Grid2D .uniform (shape_native = (21 , 21 ), pixel_scales = 0.1 )
0 commit comments