def model_data_from_instance(self, instance): galaxies = [] src_profiles = [] for profile in instance.profiles: if isinstance(profile, al.mp.MassProfile): galaxies.append( al.Galaxy( redshift=self.lens_redshift, mass=profile, )) else: src_profiles.append(profile) galaxies.append( al.Galaxy(redshift=self.source_redshift, light=al.lp.LightProfile())) tracer = al.Tracer.from_galaxies(galaxies=galaxies) lensed_cube = autolens_tracer_utils.lensed_cube_from_tracer( tracer=tracer, grid=self.masked_dataset.grid_3d.grid_2d, cube=self.src_model_from_profiles(profiles=src_profiles)) # plot_utils.plot_cube( # cube=lensed_cube, # ncols=8 # ) # exit() # NOTE: This is going to be used for the updated method to compute the lensed cube. # lensed_cube = self.lensed_cube_from_tracer_and_src_profiles( # src_profiles=src_profiles, # tracer=tracer # ) # plot_utils.plot_cube( # cube=lensed_cube, # ncols=8 # ) # exit() model_data = np.zeros(shape=self.masked_dataset.data.shape) for i in range(model_data.shape[0]): model_data[i] = self.transformers[i].visibilities_from_image( image=Image(array_2d=lensed_cube[i])) return model_data
cube = cube_src_model_cont + cube_src_model_line # plot_utils.plot_cube( # cube=cube, # ncols=8 # ) # exit() lensed_cube = autolens_tracer_utils.lensed_cube_from_tracer( tracer=al.Tracer.from_galaxies( galaxies=[ al.Galaxy( redshift=lens_redshift, mass=lens_mass_profile, ), al.Galaxy( redshift=source_redshift, light=al.lp.LightProfile() ) ] ), grid=grid_3d.grid_2d, cube=cube ) # plot_utils.plot_cube( # cube=lensed_cube, # ncols=8 # ) # exit() visibilities = np.zeros( shape=uv_wavelengths.shape
def model_data_from_instance(self, instance): len_profiles = [] src_profiles = [] for profile in instance.profiles: if isinstance(profile, al.mp.MassProfile): len_profiles.append(profile) else: src_profiles.append(profile) galaxies = [] for profile in len_profiles: galaxies.append( al.Galaxy( redshift=self.lens_redshift, mass=profile, )) src_cont_profiles = [] src_line_profiles = [] for profile in src_profiles: if not profile.is_3d_profile: src_cont_profiles.append(profile) else: src_line_profiles.append(profile) # tracer_cont = al.Tracer.from_galaxies( # galaxies=[ # *galaxies, # *[ # al.Galaxy( # redshift=self.source_redshift, # light=profile, # ) # for profile in src_cont_profiles # ] # ] # ) # # lensed_image = tracer_cont.profile_image_from_grid( # grid=self.masked_dataset.grid_3d.grid_2d # ) # # plt.figure() # # plt.imshow(lensed_image.in_2d_binned) # # plt.show() # # exit() # # lensed_cube = autolens_tracer_utils.lensed_cube_from_tracer( # tracer=al.Tracer.from_galaxies( # galaxies=[ # *galaxies, # al.Galaxy( # redshift=self.source_redshift, # light=al.lp.LightProfile() # ) # ] # ), # grid=self.masked_dataset.grid_3d.grid_2d, # cube=self.src_model_from_profiles( # profiles=src_line_profiles # ) # ) # # plot_utils.plot_cube( # # cube=lensed_cube, # # ncols=8 # # ) # # exit() # # # model_data_cont = self.transformer_continuum.visibilities_from_image( # image=lensed_image # ) # #print(model_data_cont.shape) # # # TODO: subtract the continuum # # return { # "continuum":model_data_cont # } lensed_cube_cont = autolens_tracer_utils.lensed_cube_from_tracer( tracer=al.Tracer.from_galaxies(galaxies=[ *galaxies, al.Galaxy(redshift=self.source_redshift, light=al.lp.LightProfile()) ]), grid=self.masked_dataset.grid_3d.grid_2d, cube=self.src_model_from_profiles(profiles=src_cont_profiles)) # plot_utils.plot_cube( # cube=lensed_cube_cont, # ncols=8 # ) # exit() model_data_cont = self.transformer_continuum.visibilities_from_image( image=Image(array_2d=lensed_cube_cont[0])) return {"continuum": model_data_cont} #exit() """
def test(dataset, xy_mask, profiles, lens_redshift, source_redshift, transformer_class=al.TransformerFINUFFT): def src_model_from_profiles(profiles, masked_dataset): return sum([ profile.profile_cube_from_grid( grid=masked_dataset.grid_3d.grid_2d, shape_3d=masked_dataset.grid_3d.shape_3d, z_step_kms=masked_dataset.z_step_kms) for profile in profiles ]) masked_dataset = MaskedDataset(dataset=dataset, xy_mask=xy_mask) transformers = [] for i in range(masked_dataset.uv_wavelengths.shape[0]): transformers.append( transformer_class( uv_wavelengths=masked_dataset.uv_wavelengths[i], grid=masked_dataset.grid_3d.grid_2d.in_radians)) len_profiles = [] src_profiles = [] for profile in profiles: if isinstance(profile, al.mp.MassProfile): len_profiles.append(profile) else: src_profiles.append(profile) galaxies = [] for profile in len_profiles: galaxies.append(al.Galaxy( redshift=lens_redshift, mass=profile, )) galaxies.append( al.Galaxy(redshift=source_redshift, light=al.lp.LightProfile())) tracer = al.Tracer.from_galaxies(galaxies=galaxies) cube = src_model_from_profiles(profiles=src_profiles, masked_dataset=masked_dataset) lensed_cube = autolens_tracer_utils.lensed_cube_from_tracer( tracer=tracer, grid=masked_dataset.grid_3d.grid_2d, cube=cube) model_data = np.zeros(shape=masked_dataset.data.shape) for i in range(model_data.shape[0]): model_data[i] = transformers[i].visibilities_from_image( image=Image(array_2d=lensed_cube[i])) # dirty_cube = autolens_plot_utils.dirty_cube_from_visibilities( # visibilities=masked_dataset.data, # transformers=transformers, # shape=masked_dataset.grid_shape_3d # ) # # dirty_model_cube = autolens_plot_utils.dirty_cube_from_visibilities( # visibilities=model_data, # transformers=transformers, # shape=masked_dataset.grid_shape_3d # ) # # # velocities = np.linspace( # -n_channels * z_step_kms / 2.0, # +n_channels * z_step_kms / 2.0, # n_channels # ) # dirty_moment_0 = spectral_utils.moment_0( # cube=dirty_cube, # velocities=velocities # ) # dirty_model_moment_0 = spectral_utils.moment_0( # cube=dirty_model_cube, # velocities=velocities # ) # plt.figure() # plt.imshow(dirty_moment_0 - dirty_model_moment_0, cmap="jet") # plt.show() # exit() fit_plots.residual_map(fit=fit.DatasetFit( masked_dataset=masked_dataset, model_data=model_data), transformers=transformers)