class Lens1413_midIR(Quad): _xref, _yref = -0.142, 0.561 x = np.array([0., -0.744, 0.492, -0.354]) - _xref y = np.array([0., 0.168, 0.713, 1.040]) - _yref m = np.array([1., 0.84, 0.72, 0.4]) # technically flux ratios sigma_x = np.array([0.008] * 4) sigma_y = np.array([0.008] * 4) sigma_m = np.zeros_like(sigma_x) zlens, zsrc = 0.9, 2.56 data = Data(x, y, m, None, None, sigma_x=sigma_x, sigma_y=sigma_y, sigma_m=sigma_m) identifier = 'lens1413' flux_ratio_index = 0 fluximg = ['A', 'B', 'C', 'D'][flux_ratio_index] _macromodel = get_default_SIE(zlens) _macromodel.lenstronomy_args['theta_E'] = approx_theta_E(x, y) gamma_min = 1.9 gamma_max = 2.2 srcmin = 0.02 srcmax = 0.05 has_satellite = True satellite_mass_model = ['SIS'] satellite_redshift = [zlens] satellite_convention = ['phys'] # from mass center satellite_pos_mass = np.array([-1.87, 4.15]) - np.array([_xref, _yref]) satellite_pos_mass_effective = satellite_pos_mass # from light center # satellite_pos_light = [-0.1255, -1.3517] satellite_kwargs = [{ 'theta_E': 0.63, 'center_x': satellite_pos_mass_effective[0], 'center_y': satellite_pos_mass_effective[1] }]
class MockFold(Quad): x = np.array([0.71293773, 1.11756729, 0.35865728, -0.96765226]) y = np.array([-0.98422971, -0.36175659, 1.35996094, -0.2777054]) m = np.array([1., 0.98428725, 0.39814757, 0.2427231]) sigma_x = np.array([0.005] * 4) sigma_y = np.array([0.005] * 4) relative_arrival_times = np.array([13.76955768, 14.53781908, 35.69955131]) delta_time_delay = np.array([2.0, 2., 2.]) sigma_m = np.zeros_like(sigma_x) kwargs_lens_init = [{ 'theta_E': 1.2, 'center_x': 0., 'center_y': 0., 'e1': 0.06, 'e2': 0.1, 'gamma': 2.0 }, { 'gamma1': -0.07, 'gamma2': 0.05 }] amp_scale = 1000. kwargs_lens_light = [{ 'amp': amp_scale * 1.1, 'R_sersic': 0.4, 'n_sersic': 4., 'center_x': 0., 'center_y': 0. }] kwargs_source_light = [{ 'amp': amp_scale * 1.6, 'R_sersic': 0.12, 'n_sersic': 3., 'center_x': None, 'center_y': None, 'e1': -0.1, 'e2': 0.3 }] zlens, zsrc = 0.5, 1.5 data = Data(x, y, m, None, None, sigma_x=sigma_x, sigma_y=sigma_y, sigma_m=sigma_m) identifier = 'mockfold' flux_ratio_index = 0 fluximg = ['A', 'B', 'C', 'D'][flux_ratio_index] _macromodel = get_default_SIE(zlens) _macromodel.lenstronomy_args['theta_E'] = approx_theta_E(x, y) has_satellite = False gamma_min = 1.95 gamma_max = 2.2 srcmin = 0.02 srcmax = 0.05 @staticmethod def relative_time_delays(arrival_times): trel = np.array([arrival_times[0], arrival_times[1], arrival_times[3] ]) - arrival_times[2] return trel def optimize_fit(self, kwargs_fit={}, macro_init=None, print_output=False): if 'datatofit' in kwargs_fit.keys(): data = kwargs_fit['datatofit'] del kwargs_fit['datatofit'] else: data = self.data optdata, optmodel = self._fit(data, self.solver, kwargs_fit, macromodel_init=macro_init) if print_output: self._print_output(optdata[0], optmodel[0]) return optdata[0], optmodel[0] def optimize_fit_lensmodel(self, kwargs_fit={}, macro_init=None, print_output=False): kwargs_fit.update({'identifier': self.identifier}) optdata, optmodel = self._fit_lensmodel(self.data, self.solver, kwargs_fit, macromodel_init=macro_init) if print_output: self._print_output(optdata[0], optmodel[0]) return optdata[0], optmodel[0] def _print_output(self, optdata, optmodel): macromodel = optmodel.lens_components[0] print('optimized mags: ', optdata.m) print('observed mags: ', self.data.m) print('lensmodel fit: ') print('Einstein radius: ', macromodel.lenstronomy_args['theta_E']) print('shear, shear_theta:', macromodel.shear, macromodel.shear_theta) print('ellipticity, PA:', macromodel.ellip_PA_polar()[0], macromodel.ellip_PA_polar()[1]) print('centroid: ', macromodel.lenstronomy_args['center_x'], macromodel.lenstronomy_args['center_y']) print('\n') print('flux ratios w.r.t. image ' + str(self.fluximg) + ':') print('observed: ', self.data.compute_flux_ratios(index=self.flux_ratio_index)) print('recovered: ', optdata.compute_flux_ratios(index=self.flux_ratio_index))
class Lens0408(Quad): x = np.array([1.981, -1.775, -1.895, 0.141]) y = np.array([-1.495, 0.369, -0.854, 1.466]) m = np.array([1, 0.7, 0.5, 0.4]) time_delay_AB, delta_AB = 112, 2.1 time_delay_AC, delta_AC = 155.5, 12.8 time_delay_BD = 42.4 time_delay_AD, delta_AD = time_delay_AB + time_delay_BD, np.sqrt(17.6 ** 2 + 2.1**2) delta_time_delay = np.array([delta_AB, delta_AC, delta_AD]) relative_arrival_times = np.array([time_delay_AB, time_delay_AC, time_delay_AD]) sigma_x = np.array([0.003]*4) sigma_y = np.array([0.003]*4) sigma_m = np.zeros_like(sigma_x) zsrc, zlens = 2.375, 0.6 data = Data(x, y, m, None, None, sigma_x = sigma_x, sigma_y = sigma_y, sigma_m=sigma_m) identifier = 'lens0408' flux_ratio_index = 0 fluximg = ['A', 'B', 'C', 'D'][flux_ratio_index] _macromodel = get_default_SIE(zlens) _macromodel.lenstronomy_args['theta_E'] = approx_theta_E(x, y) gamma_min = 1.9 gamma_max = 2.1 has_satellite = True satellite_mass_model = ['SIS', 'SIS', 'SIS', 'SIS', 'SIS'] sat_1_z, sat_2_z = zlens, 0.769 sat_1_x, sat_1_y = -1.58, -0.95 # Satellite Einstein radii sat_1_thetaE = 0.22 sat_2_thetaE = 0.77 # OBSERVED SATELLITE POSITIONS #sat_2_x, sat_2_y = 1.08, -6.52 # PHYSICAL SATELLITE POSITIONS sat_2_x, sat_2_y = 1.13, -7.45 #satellite2_pos_mass_effective = [-3.63, -0.08] kwargs_lens_init = [{'theta_E': 1.7220357060940006, 'center_x': 0.1445702226010889, 'center_y': -3.0844186207127455e-06, 'e1': 0.16516965529124017, 'e2': 0.17318780467502645, 'gamma': 1.91894095496809}, {'gamma1': 0.10994375051894104, 'gamma2': 0.018505364037691943}, ] amp_scale = 1000 kwargs_lens_light = [{'amp': 2500, 'R_sersic': 0.4, 'n_sersic': 3.9, 'center_x': 0., 'center_y': 0.}] kwargs_satellite_light = [{'amp': 700., 'R_sersic': 0.15, 'n_sersic': 3., 'center_x': sat_1_x, 'center_y': sat_1_y}, None] #kwargs_source_light = [{'amp': 1000., 'R_sersic': 0.2, 'n_sersic': 3., 'center_x': None, 'center_y': None, # 'e1': -0.2, 'e2': 0.2}] kwargs_source_light = [{'R_sersic': 0.08, 'n_sersic': 4.9, 'center_x': None, 'center_y': None, 'amp': 1400, 'e1': 0.045, 'e2': -0.09}] satellite_redshift = [zlens, 0.769] satellite_convention = ['phys', 'phys'] satellite_kwargs = [{'theta_E': sat_1_thetaE, 'center_x': sat_1_x, 'center_y': sat_1_y}, {'theta_E': sat_2_thetaE, 'center_x': sat_2_x, 'center_y': sat_2_y}, ] @staticmethod def relative_time_delays(arrival_times): trel = arrival_times[1:] - arrival_times[0] #trel = [abs(trel[0]), abs(trel[1]), abs(trel[0]) + abs(trel[1])] return np.array(trel) def optimize_fit(self, kwargs_fit={}, macro_init = None, print_output = False): if 'datatofit' in kwargs_fit.keys(): data = kwargs_fit['datatofit'] del kwargs_fit['datatofit'] else: data = self.data if 'satellites' not in kwargs_fit.keys(): satellites = {} satellites['lens_model_name'] = self.satellite_mass_model satellites['z_satellite'] = self.satellite_redshift satellites['kwargs_satellite'] = self.satellite_kwargs satellites['position_convention'] = self.satellite_convention kwargs_fit.update({'satellites': satellites}) optdata, optmodel = self._fit(data, self.solver, kwargs_fit, macromodel_init=macro_init) if print_output: self._print_output(optdata[0], optmodel[0]) return optdata[0], optmodel[0] def optimize_fit_lensmodel(self, kwargs_fit={}, macro_init = None, print_output = False): kwargs_fit.update({'identifier': self.identifier}) optdata, optmodel = self._fit_lensmodel(self.data, self.solver, kwargs_fit, macromodel_init=macro_init) if print_output: self._print_output(optdata[0], optmodel[0]) return optdata[0], optmodel[0] def _print_output(self, optdata, optmodel): macromodel = optmodel.lens_components[0] print('optimized mags: ', optdata.m) print('observed mags: ', self.data.m) print('lensmodel fit: ') print('Einstein radius: ', macromodel.lenstronomy_args['theta_E']) print('shear, shear_theta:', macromodel.shear, macromodel.shear_theta) print('ellipticity, PA:', macromodel.ellip_PA_polar()[0], macromodel.ellip_PA_polar()[1]) print('centroid: ', macromodel.lenstronomy_args['center_x'], macromodel.lenstronomy_args['center_y']) print('\n') print('flux ratios w.r.t. image '+str(self.fluximg)+':') print('observed: ', self.data.compute_flux_ratios(index=self.flux_ratio_index)) print('recovered: ', optdata.compute_flux_ratios(index=self.flux_ratio_index))
class WFI2033_nosat(Quad): x = np.array([-0.751, -0.039, 1.445, -0.668]) y = np.array([0.953, 1.068, -0.307, -0.585]) m = np.array([1., 0.65, 0.5, 0.53]) time_delay_AB, delta_AB = 0, 100 time_delay_AC, delta_AC = -36.2, 0.8 time_delay_AD, delta_AD = 23.3, 1.4 # delta_time_delay = np.array([delta_AB, delta_AC, delta_AD]) # relative_arrival_times = np.array([time_delay_AB, time_delay_AC, time_delay_AD]) relative_arrival_times = np.array([0.01, 36.2, 23.3 + 36.2]) delta_time_delay = np.array( [delta_AB, delta_AC, np.sqrt(delta_AC**2 + delta_AD**2)]) sigma_x = np.array([0.005] * 4) sigma_y = np.array([0.005] * 4) sigma_m = np.zeros_like(sigma_x) zsrc, zlens = 1.66, 0.66 # source redshift from Motta et al data = Data(x, y, m, None, None, sigma_x=sigma_x, sigma_y=sigma_y, sigma_m=sigma_m) identifier = 'lens2033' flux_ratio_index = 0 fluximg = ['A', 'B', 'C', 'D'][flux_ratio_index] _macromodel = get_default_SIE(zlens) _macromodel.lenstronomy_args['theta_E'] = approx_theta_E(x, y) gamma_min = 1.9 gamma_max = 2.1 kwargs_lens_init = [{ 'theta_E': 1.1741434797426027, 'center_x': -0.14201456606451995, 'center_y': -0.020836241161107733, 'e1': -0.044760164290518836, 'e2': 0.3139742426542731, 'gamma': 1.95 }, { 'gamma1': 0.10751925181736302, 'gamma2': 0.011036722994634627 }] kwargs_lens_light = [{ 'amp': 2500, 'R_sersic': 0.2, 'n_sersic': 4., 'center_x': None, 'center_y': None }] kwargs_source_light = [{ 'amp': 1000, 'R_sersic': 0.08, 'n_sersic': 2.5, 'center_x': None, 'center_y': None, 'e1': 0.01, 'e2': -0.14 }] srcmin = 0.02 srcmax = 0.05 has_satellite = True satellite_mass_model = ['SIS'] satellite1_pos_mass = [0.245, 2.037] satellite_redshift = [zlens] satellite_convention = ['phys'] kwargs_satellite_light = [{ 'amp': 800, 'R_sersic': 0.1, 'n_sersic': 3., 'center_x': satellite1_pos_mass[0], 'center_y': satellite1_pos_mass[1] }] satellite_kwargs = [ { 'theta_E': 0.03, 'center_x': satellite1_pos_mass[0], 'center_y': satellite1_pos_mass[1] }, ] @staticmethod def relative_time_delays(arrival_times): trel = arrival_times[1:] - arrival_times[0] trel = [abs(trel[0]), abs(trel[1]), abs(trel[1]) + abs(trel[2])] return np.array(trel) def optimize_fit(self, kwargs_fit={}, macro_init=None, print_output=False): if 'datatofit' in kwargs_fit.keys(): data = kwargs_fit['datatofit'] del kwargs_fit['datatofit'] else: data = self.data if 'satellites' not in kwargs_fit.keys(): satellites = {} satellites['lens_model_name'] = self.satellite_mass_model satellites['z_satellite'] = self.satellite_redshift satellites['kwargs_satellite'] = self.satellite_kwargs satellites['position_convention'] = self.satellite_convention kwargs_fit.update({'satellites': satellites}) optdata, optmodel = self._fit(data, self.solver, kwargs_fit, macromodel_init=macro_init) if print_output: self._print_output(optdata[0], optmodel[0]) return optdata[0], optmodel[0] def optimize_fit_lensmodel(self, kwargs_fit={}, macro_init=None, print_output=False): kwargs_fit.update({'identifier': self.identifier}) optdata, optmodel = self._fit_lensmodel(self.data, self.solver, kwargs_fit, macromodel_init=macro_init) if print_output: self._print_output(optdata[0], optmodel[0]) return optdata[0], optmodel[0] def _print_output(self, optdata, optmodel): macromodel = optmodel.lens_components[0] print('optimized mags: ', optdata.m) print('observed mags: ', self.data.m) print('lensmodel fit: ') print('Einstein radius: ', macromodel.lenstronomy_args['theta_E']) print('shear, shear_theta:', macromodel.shear, macromodel.shear_theta) print('ellipticity, PA:', macromodel.ellip_PA_polar()[0], macromodel.ellip_PA_polar()[1]) print('centroid: ', macromodel.lenstronomy_args['center_x'], macromodel.lenstronomy_args['center_y']) print('\n') print('flux ratios w.r.t. image ' + str(self.fluximg) + ':') print('observed: ', self.data.compute_flux_ratios(index=self.flux_ratio_index)) print('recovered: ', optdata.compute_flux_ratios(index=self.flux_ratio_index))
class Lens0435(Quad): x = np.array([1.272, 0.306, -1.152, -0.384]) y = np.array([0.156, -1.092, -0.636, 1.026]) m = np.array([0.96, 0.976, 1., 0.65]) time_delay_AB, delta_AB = -8.8, 0.8 time_delay_AC, delta_AC = -1.1, 0.7 time_delay_AD, delta_AD = -13.8, 0.9 delta_time_delay = np.array([delta_AB, delta_AC, delta_AD]) relative_arrival_times = -np.array([time_delay_AB, time_delay_AC, time_delay_AD]) sigma_x = np.array([0.008]*4) sigma_y = np.array([0.008]*4) sigma_m = np.zeros_like(sigma_x) zlens, zsrc = 0.45,1.69 data = Data(x, y, m, None, None, sigma_x = sigma_x, sigma_y = sigma_y, sigma_m=sigma_m) identifier = 'lens0435' flux_ratio_index = 0 kwargs_lens_init = [{'theta_E': 1.1695276026313663, 'center_x': -0.018181247306480245, 'center_y': 0.019397076231183395, 'e1': -0.0334362651181225, 'e2': -0.011254590955755551, 'gamma': 1.93}, {'gamma1': 0.0451624454972574, 'gamma2': 0.016066946017755886}] fluximg = ['A', 'B', 'C', 'D'][flux_ratio_index] _macromodel = get_default_SIE(zlens) _macromodel.lenstronomy_args['theta_E'] = approx_theta_E(x, y) gamma_min = 1.9 gamma_max = 2.2 srcmin = 0.02 srcmax = 0.05 amp_scale = 1000 kwargs_lens_light = [{'amp': 1500, 'R_sersic': 0.3, 'n_sersic': 4., 'center_x': 0., 'center_y': 0.}] kwargs_source_light = [{'amp': 5000, 'R_sersic': 0.035, 'n_sersic': 3., 'center_x': None, 'center_y': None, 'e1': -0.05, 'e2': 0.05}] has_satellite = True satellite_mass_model = ['SIS'] satellite_redshift = [0.78] satellite_convention = ['phys'] # from mass center satellite_pos_mass_observed = np.array([-2.911, 2.339]) satellite_pos_mass = np.array([-2.27, 1.98]) kwargs_satellite_light = [None] # from light center #satellite_pos_light = [-0.1255, -1.3517] satellite_kwargs = [{'theta_E': 0.35, 'center_x': satellite_pos_mass[0], 'center_y': satellite_pos_mass[1]}] @staticmethod def relative_time_delays(arrival_times): trel = arrival_times[1:] - arrival_times[0] return np.array(trel) def optimize_fit(self, kwargs_fit={}, macro_init = None, print_output = False): if 'datatofit' in kwargs_fit.keys(): data = kwargs_fit['datatofit'] del kwargs_fit['datatofit'] else: data = self.data satellites = {} satellites['lens_model_name'] = self.satellite_mass_model satellites['z_satellite'] = self.satellite_redshift satellites['kwargs_satellite'] = self.satellite_kwargs satellites['position_convention'] = self.satellite_convention kwargs_fit.update({'satellites': satellites}) kwargs_fit.update({'multiplane': True}) optdata, optmodel = self._fit(data, self.solver, kwargs_fit, macromodel_init=macro_init, sat_pos_lensed=True) if print_output: self._print_output(optdata[0], optmodel[0]) return optdata[0], optmodel[0] def optimize_fit_lensmodel(self, kwargs_fit={}, macro_init = None, print_output = False): kwargs_fit.update({'identifier': self.identifier}) optdata, optmodel = self._fit_lensmodel(self.data, self.solver, kwargs_fit, macromodel_init=macro_init) if print_output: self._print_output(optdata[0], optmodel[0]) return optdata[0], optmodel[0] def _print_output(self, optdata, optmodel): macromodel = optmodel.lens_components[0] print('optimized mags: ', optdata.m) print('observed mags: ', self.data.m) print('lensmodel fit: ') print('Einstein radius: ', macromodel.lenstronomy_args['theta_E']) print('shear, shear_theta:', macromodel.shear, macromodel.shear_theta) print('ellipticity, PA:', macromodel.ellip_PA_polar()[0], macromodel.ellip_PA_polar()[1]) print('centroid: ', macromodel.lenstronomy_args['center_x'], macromodel.lenstronomy_args['center_y']) print('\n') print('flux ratios w.r.t. image '+str(self.fluximg)+':') print('observed: ', self.data.compute_flux_ratios(index=self.flux_ratio_index)) print('recovered: ', optdata.compute_flux_ratios(index=self.flux_ratio_index))
class Lens1413_NL(Quad): x = np.array([-0.6, -0.22, 0.137, 0.629]) y = np.array([-0.418, 0.448, -0.588, 0.117]) m = np.array([0.93, 0.94, 1, 0.41]) sigma_x = np.array([0.008] * 4) sigma_y = np.array([0.008] * 4) sigma_m = np.zeros_like(sigma_x) zlens, zsrc = 0.9, 2.56 data = Data(x, y, m, None, None, sigma_x=sigma_x, sigma_y=sigma_y, sigma_m=sigma_m) identifier = 'lens1413' flux_ratio_index = 0 fluximg = ['A', 'B', 'C', 'D'][flux_ratio_index] _macromodel = get_default_SIE(zlens) _macromodel.lenstronomy_args['theta_E'] = approx_theta_E(x, y) gamma_min = 1.9 gamma_max = 2.2 srcmin = 0.02 srcmax = 0.05 has_satellite = False #satellite_mass_model = ['SIS'] #satellite_redshift = [2] #satellite_convention = ['lensed'] # from mass center #satellite_pos_mass = np.array([2.007, 3.552]) #satellite_pos_mass_effective = np.array([-2.37, 2.08]) # from light center #satellite_pos_light = [-0.1255, -1.3517] #satellite_kwargs = [{'theta_E': 1, 'center_x': satellite_pos_mass[0], # 'center_y': satellite_pos_mass[1]}] def optimize_fit(self, kwargs_fit={}, macro_init=None, print_output=False): if 'datatofit' in kwargs_fit.keys(): data = kwargs_fit['datatofit'] del kwargs_fit['datatofit'] else: data = self.data satellites = None #satellites['lens_model_name'] = self.satellite_mass_model #satellites['z_satellite'] = self.satellite_redshift #satellites['kwargs_satellite'] = self.satellite_kwargs #satellites['position_convention'] = self.satellite_convention kwargs_fit.update({'satellites': satellites}) kwargs_fit.update({'multiplane': True}) optdata, optmodel = self._fit(data, self.solver, kwargs_fit, macromodel_init=macro_init, sat_pos_lensed=True) if print_output: self._print_output(optdata[0], optmodel[0]) return optdata[0], optmodel[0] def optimize_fit_lensmodel(self, kwargs_fit={}, macro_init=None, print_output=False): kwargs_fit.update({'identifier': self.identifier}) optdata, optmodel = self._fit_lensmodel(self.data, self.solver, kwargs_fit, macromodel_init=macro_init) if print_output: self._print_output(optdata[0], optmodel[0]) return optdata[0], optmodel[0] def _print_output(self, optdata, optmodel): macromodel = optmodel.lens_components[0] print('optimized mags: ', optdata.m) print('observed mags: ', self.data.m) print('lensmodel fit: ') print('Einstein radius: ', macromodel.lenstronomy_args['theta_E']) print('shear, shear_theta:', macromodel.shear, macromodel.shear_theta) print('ellipticity, PA:', macromodel.ellip_PA_polar()[0], macromodel.ellip_PA_polar()[1]) print('centroid: ', macromodel.lenstronomy_args['center_x'], macromodel.lenstronomy_args['center_y']) print('\n') print('flux ratios w.r.t. image ' + str(self.fluximg) + ':') print('observed: ', self.data.compute_flux_ratios(index=self.flux_ratio_index)) print('recovered: ', optdata.compute_flux_ratios(index=self.flux_ratio_index))
class Lens2038(Quad): x = np.array([-1.474, 0.832, -0.686, 0.706]) y = np.array([0.488, -1.22, -1.191, 0.869]) m = np.array([0.862069, 1., 0.793103, 0.396552]) sigma_x = np.array([0.005]*4) sigma_y = np.array([0.005]*4) # TIME DELAYS ESTIMATED FROM A FIT time_delay_AB, delta_AB = -2.6, 1.3 time_delay_AC, delta_AC = -5.73, 0.9 time_delay_AD, delta_AD = -15.0, 2.5 delta_time_delay = np.array([delta_AB, delta_AC, delta_AD]) relative_arrival_times = np.array([time_delay_AB, time_delay_AC, time_delay_AD]) sigma_m = np.zeros_like(sigma_x) zsrc, zlens = 0.78, 0.23 data = Data(x, y, m, None, None, sigma_x = sigma_x, sigma_y = sigma_y, sigma_m=sigma_m) identifier = 'lens2038' flux_ratio_index = 0 fluximg = ['A', 'B', 'C', 'D'][flux_ratio_index] _macromodel = get_default_SIE(zlens) _macromodel.lenstronomy_args['theta_E'] = approx_theta_E(x, y) has_satellite = False gamma_min = 1.9 gamma_max = 2.4 srcmin = 0.02 srcmax = 0.05 def optimize_fit(self, kwargs_fit={}, macro_init = None, print_output = False): if 'datatofit' in kwargs_fit.keys(): data = kwargs_fit['datatofit'] del kwargs_fit['datatofit'] else: data = self.data optdata, optmodel = self._fit(data, self.solver, kwargs_fit, macromodel_init=macro_init) if print_output: self._print_output(optdata[0], optmodel[0]) return optdata[0], optmodel[0] def optimize_fit_lensmodel(self, kwargs_fit={}, macro_init = None, print_output = False): kwargs_fit.update({'identifier': self.identifier}) optdata, optmodel = self._fit_lensmodel(self.data, self.solver, kwargs_fit, macromodel_init=macro_init) if print_output: self._print_output(optdata[0], optmodel[0]) return optdata[0], optmodel[0] def _print_output(self, optdata, optmodel): macromodel = optmodel.lens_components[0] print('optimized mags: ', optdata.m) print('observed mags: ', self.data.m) print('lensmodel fit: ') print('Einstein radius: ', macromodel.lenstronomy_args['theta_E']) print('shear, shear_theta:', macromodel.shear, macromodel.shear_theta) print('ellipticity, PA:', macromodel.ellip_PA_polar()[0], macromodel.ellip_PA_polar()[1]) print('centroid: ', macromodel.lenstronomy_args['center_x'], macromodel.lenstronomy_args['center_y']) print('\n') print('flux ratios w.r.t. image '+str(self.fluximg)+':') print('observed: ', self.data.compute_flux_ratios(index=self.flux_ratio_index)) print('recovered: ', optdata.compute_flux_ratios(index=self.flux_ratio_index))
class Lens1115(Quad): # x = np.array([0.947, 1.096, -0.722, -0.381]) # y = np.array([-0.69, -0.232, -0.617, 1.344]) # m = np.array([1., 0.93, 0.16, 0.21]) x = np.array([0.947, 1.096, -0.722, -0.381]) y = np.array([-0.69, -0.232, -0.617, 1.344]) m = np.array([1., 0.93, 0.16, 0.21]) # from Impey et al. 1998 # minus sign is correct group_r, group_theta = 10, (-113 + 90) * np.pi / 180 group_x, group_y = -group_r * np.cos(group_theta), group_r * np.sin( group_theta) time_delay_AB, delta_AB = 0.01, 10 time_delay_AC, delta_AC = 8.3, 1.6 time_delay_AD, delta_AD = -9.9, 1.1 relative_arrival_times = np.array([0.01, 9.9, 18.8]) delta_time_delay = np.array([10, 1.1, 1.6]) sigma_x = np.array([0.003] * 4) sigma_y = np.array([0.003] * 4) sigma_m = np.zeros_like(sigma_x) zlens, zsrc = 0.31, 1.72 data = Data(x, y, m, None, None, sigma_x=sigma_x, sigma_y=sigma_y, sigma_m=sigma_m) # From Chen et al. 2019 amp_scale = 1000 kwargs_lens_light = [{ 'amp': 1000, 'R_sersic': 0.2, 'n_sersic': 4., 'center_x': None, 'center_y': None }] kwargs_source_light = [{ 'amp': 1700, 'R_sersic': 0.125, 'n_sersic': 2., 'center_x': None, 'center_y': None, 'e1': 0.15, 'e2': -0.4 }] kwargs_lens_init = [{ 'theta_E': 1.0505876627617852, 'center_x': 0.0015838433690165622, 'center_y': 0.0039075583507097575, 'e1': -0.002140732329506273, 'e2': -0.0017325116179204988, 'gamma': 2.2 }, { 'gamma1': -0.010208269559630813, 'gamma2': -0.025988491812216158 }] identifier = 'lens1115' has_satellite = True satellite_mass_model = ['SIS'] satellite_redshift = [zlens] satellite_convention = ['phys'] satellite_pos_mass = [group_x, group_y] # From Impey et al. 1998 "Einstein ring in..." satellite_kwargs = [{ 'theta_E': 2., 'center_x': satellite_pos_mass[0], 'center_y': satellite_pos_mass[1] }] kwargs_satellite_light = [None] flux_ratio_index = 0 fluximg = ['A', 'B', 'C', 'D'][flux_ratio_index] _macromodel = get_default_SIE(zlens) _macromodel.lenstronomy_args['theta_E'] = approx_theta_E(x, y) gamma_min = 1.95 gamma_max = 2.2 srcmin = 0.005 srcmax = 0.025 @staticmethod def relative_time_delays(arrival_times): trel = arrival_times[1:] - arrival_times[0] trel = [trel[0], abs(trel[2]), trel[1] + abs(trel[2])] return np.array(trel) def optimize_fit(self, kwargs_fit={}, macro_init=None, print_output=False): if 'datatofit' in kwargs_fit.keys(): data = kwargs_fit['datatofit'] del kwargs_fit['datatofit'] else: data = self.data optdata, optmodel = self._fit(data, self.solver, kwargs_fit, macromodel_init=macro_init) if print_output: self._print_output(optdata[0], optmodel[0]) return optdata[0], optmodel[0] def optimize_fit_lensmodel(self, kwargs_fit={}, macro_init=None, print_output=False): kwargs_fit.update({'identifier': self.identifier}) optdata, optmodel = self._fit_lensmodel(self.data, self.solver, kwargs_fit, macromodel_init=macro_init) if print_output: self._print_output(optdata[0], optmodel[0]) return optdata[0], optmodel[0] def _print_output(self, optdata, optmodel): macromodel = optmodel.lens_components[0] print('optimized mags: ', optdata.m) print('observed mags: ', self.data.m) print('lensmodel fit: ') print('Einstein radius: ', macromodel.lenstronomy_args['theta_E']) print('shear, shear_theta:', macromodel.shear, macromodel.shear_theta) print('ellipticity, PA:', macromodel.ellip_PA_polar()[0], macromodel.ellip_PA_polar()[1]) print('centroid: ', macromodel.lenstronomy_args['center_x'], macromodel.lenstronomy_args['center_y']) print('\n') print('flux ratios w.r.t. image ' + str(self.fluximg) + ':') print('observed: ', self.data.compute_flux_ratios(index=self.flux_ratio_index)) print('recovered: ', optdata.compute_flux_ratios(index=self.flux_ratio_index))
class RXJ0911(Quad): x = np.array([0.688, 0.946, 0.672, -2.283]) y = np.array([-0.517, -0.112, 0.442, 0.274]) m = np.array([0.56, 1., 0.53, 0.24]) sigma_x = np.array([0.005] * 4) sigma_y = np.array([0.005] * 4) sigma_m = np.zeros_like(sigma_x) zlens, zsrc = 0.77, 2.76 data = Data(x, y, m, None, None, sigma_x=sigma_x, sigma_y=sigma_y, sigma_m=sigma_m) identifier = 'lens0911' flux_ratio_index = 1 fluximg = ['A', 'B', 'C', 'D'][flux_ratio_index] _macromodel = get_default_SIE(zlens) _macromodel.lenstronomy_args['theta_E'] = approx_theta_E(x, y) gamma_min = 1.9 gamma_max = 2.2 srcmin = 0.02 srcmax = 0.05 has_satellite = True satellite_mass_model = ['SIS'] satellite_redshift = [0.78] satellite_convention = ['phys'] satellite_pos_mass = [-0.767, 0.657] # satellite einstein radius from Blackburne et al. 2011 satellite_kwargs = [{ 'theta_E': 0.24, 'center_x': satellite_pos_mass[0], 'center_y': satellite_pos_mass[1] }] def optimize_fit(self, kwargs_fit={}, macro_init=None, print_output=False): if 'datatofit' in kwargs_fit.keys(): data = kwargs_fit['datatofit'] del kwargs_fit['datatofit'] else: data = self.data satellites = {} satellites['lens_model_name'] = self.satellite_mass_model satellites['z_satellite'] = [self.zlens] satellites['kwargs_satellite'] = self.satellite_kwargs kwargs_fit.update({'satellites': satellites}) optdata, optmodel = self._fit(data, self.solver, kwargs_fit, macromodel_init=macro_init) if print_output: self._print_output(optdata[0], optmodel[0]) return optdata[0], optmodel[0] def optimize_fit_lensmodel(self, kwargs_fit={}, macro_init=None, print_output=False): kwargs_fit.update({'identifier': self.identifier}) optdata, optmodel = self._fit_lensmodel(self.data, self.solver, kwargs_fit, macromodel_init=macro_init) if print_output: self._print_output(optdata[0], optmodel[0]) return optdata[0], optmodel[0] def _print_output(self, optdata, optmodel): macromodel = optmodel.lens_components[0] print('optimized mags: ', optdata.m) print('observed mags: ', self.data.m) print('lensmodel fit: ') print('Einstein radius: ', macromodel.lenstronomy_args['theta_E']) print('shear, shear_theta:', macromodel.shear, macromodel.shear_theta) print('ellipticity, PA:', macromodel.ellip_PA_polar()[0], macromodel.ellip_PA_polar()[1]) print('centroid: ', macromodel.lenstronomy_args['center_x'], macromodel.lenstronomy_args['center_y']) print('\n') print('flux ratios w.r.t. image ' + str(self.fluximg) + ':') print('observed: ', self.data.compute_flux_ratios(index=self.flux_ratio_index)) print('recovered: ', optdata.compute_flux_ratios(index=self.flux_ratio_index))
class Lens1608(Quad): g1x, g1y = 0.4161, -1.0581 g2x, g2y = -0.2897, -0.9243 g2x -= g1x g2y -= g1y # from Fassnacht et al. 2002 x = np.array([-0.000, -0.738, -0.7446, 1.1284]) - g1x y = np.array([0.000, -1.961, -0.4537, -1.2565]) - g1y m = np.array([1., 0.5, 0.51, 0.35]) sigma_x = np.array([0.005] * 4) sigma_y = np.array([0.005] * 4) # from Koopmans et al. 2003 time_delay_AB, delta_AB = -31.5, 1.5 time_delay_AC, delta_AC = 4.5, 1.5 time_delay_AD, delta_AD = 45.5, 2. # delta_time_delay = np.array([delta_AB, delta_AC, delta_AD]) # relative_arrival_times = np.array([time_delay_AB, time_delay_AC, time_delay_AD]) relative_arrival_times = np.array([31., 36., 76.]) delta_time_delay = np.array([2., 1.5, 2.]) sigma_m = np.zeros_like(sigma_x) kwargs_lens_init = [{ 'theta_E': 0.9036453181989341, 'center_x': 0.007600860009089998, 'center_y': -0.057685769153856994, 'e1': 0.33480085295892065, 'e2': -0.05097223221504117, 'gamma': 2.08 }, { 'gamma1': 0.06096918564904592, 'gamma2': 0.07721907911829631 }] amp_scale = 1000. kwargs_lens_light = [{ 'amp': amp_scale * 1.1, 'R_sersic': 0.4, 'n_sersic': 4., 'center_x': 0., 'center_y': 0. }] kwargs_source_light = [{ 'amp': amp_scale * 1.6, 'R_sersic': 0.12, 'n_sersic': 3., 'center_x': None, 'center_y': None, 'e1': -0.1, 'e2': 0.3 }] zlens, zsrc = 0.61, 1.4 data = Data(x, y, m, None, None, sigma_x=sigma_x, sigma_y=sigma_y, sigma_m=sigma_m) identifier = 'lens1608' flux_ratio_index = 0 fluximg = ['A', 'B', 'C', 'D'][flux_ratio_index] _macromodel = get_default_SIE(zlens) _macromodel.lenstronomy_args['theta_E'] = approx_theta_E(x, y) has_satellite = True satellite_mass_model = ['SIS'] satellite_redshift = [zlens] satellite_convention = ['phys'] satellite_pos_mass = [g2x, g2y] kwargs_satellite_light = [{ 'amp': amp_scale * 0.7, 'R_sersic': 0.2, 'n_sersic': 4., 'center_x': g2x, 'center_y': g2y }] # satellite einstein radius from Koopmans et al. 2003 satellite_kwargs = [{ 'theta_E': 0.26, 'center_x': satellite_pos_mass[0], 'center_y': satellite_pos_mass[1] }] gamma_min = 1.95 gamma_max = 2.2 srcmin = 0.02 srcmax = 0.05 @staticmethod def relative_time_delays(arrival_times): trel = arrival_times[1:] - arrival_times[0] trel = [ abs(trel[0]), abs(trel[0]) + trel[1], abs(trel[0]) + abs(trel[2]) ] return np.array(trel) def optimize_fit(self, kwargs_fit={}, macro_init=None, print_output=False): if 'datatofit' in kwargs_fit.keys(): data = kwargs_fit['datatofit'] del kwargs_fit['datatofit'] else: data = self.data optdata, optmodel = self._fit(data, self.solver, kwargs_fit, macromodel_init=macro_init) if print_output: self._print_output(optdata[0], optmodel[0]) return optdata[0], optmodel[0] def optimize_fit_lensmodel(self, kwargs_fit={}, macro_init=None, print_output=False): kwargs_fit.update({'identifier': self.identifier}) optdata, optmodel = self._fit_lensmodel(self.data, self.solver, kwargs_fit, macromodel_init=macro_init) if print_output: self._print_output(optdata[0], optmodel[0]) return optdata[0], optmodel[0] def _print_output(self, optdata, optmodel): macromodel = optmodel.lens_components[0] print('optimized mags: ', optdata.m) print('observed mags: ', self.data.m) print('lensmodel fit: ') print('Einstein radius: ', macromodel.lenstronomy_args['theta_E']) print('shear, shear_theta:', macromodel.shear, macromodel.shear_theta) print('ellipticity, PA:', macromodel.ellip_PA_polar()[0], macromodel.ellip_PA_polar()[1]) print('centroid: ', macromodel.lenstronomy_args['center_x'], macromodel.lenstronomy_args['center_y']) print('\n') print('flux ratios w.r.t. image ' + str(self.fluximg) + ':') print('observed: ', self.data.compute_flux_ratios(index=self.flux_ratio_index)) print('recovered: ', optdata.compute_flux_ratios(index=self.flux_ratio_index))
class Lens1608_nosatellite(Quad): g1x, g1y = 0.4161, -1.0581 g2x, g2y = -0.2897, -0.9243 g2x -= g1x g2y -= g1y # from Fassnacht et al. 2002 x = np.array([-0.000, -0.738, -0.7446, 1.1284]) - g1x y = np.array([0.000, -1.961, -0.4537, -1.2565]) - g1y m = np.array([1., 0.5, 0.51, 0.35]) sigma_x = np.array([0.005] * 4) sigma_y = np.array([0.005] * 4) # from Koopmans et al. 2003 time_delay_AB, delta_AB = -31.5, 1.5 time_delay_AC, delta_AC = 4.5, 1.5 time_delay_AD, delta_AD = 45.5, 2. # delta_time_delay = np.array([delta_AB, delta_AC, delta_AD]) # relative_arrival_times = np.array([time_delay_AB, time_delay_AC, time_delay_AD]) relative_arrival_times = np.array([31., 36., 76.]) delta_time_delay = np.array([2.0, 1.5, 2.]) sigma_m = np.zeros_like(sigma_x) kwargs_lens_init = [{ 'theta_E': 1.5645290570341535, 'center_x': -0.026043918948197867, 'center_y': 0.043138636998329406, 'e1': 0.6356893557901389, 'e2': -0.5567562747618204, 'gamma': 2.08 }, { 'gamma1': 0.24062025181584618, 'gamma2': -0.13850236642865676 }] amp_scale = 1000. kwargs_lens_light = [{ 'amp': amp_scale * 1.1, 'R_sersic': 0.4, 'n_sersic': 4., 'center_x': 0., 'center_y': 0. }] kwargs_source_light = [{ 'amp': amp_scale * 1.6, 'R_sersic': 0.12, 'n_sersic': 3., 'center_x': None, 'center_y': None, 'e1': -0.1, 'e2': 0.3 }] zlens, zsrc = 0.61, 1.4 data = Data(x, y, m, None, None, sigma_x=sigma_x, sigma_y=sigma_y, sigma_m=sigma_m) identifier = 'lens1608' flux_ratio_index = 0 fluximg = ['A', 'B', 'C', 'D'][flux_ratio_index] _macromodel = get_default_SIE(zlens) _macromodel.lenstronomy_args['theta_E'] = approx_theta_E(x, y) has_satellite = False gamma_min = 1.95 gamma_max = 2.2 srcmin = 0.02 srcmax = 0.05 @staticmethod def relative_time_delays(arrival_times): trel = arrival_times[1:] - arrival_times[0] trel = [ abs(trel[0]), abs(trel[0]) + trel[1], abs(trel[0]) + abs(trel[2]) ] return np.array(trel) def optimize_fit(self, kwargs_fit={}, macro_init=None, print_output=False): if 'datatofit' in kwargs_fit.keys(): data = kwargs_fit['datatofit'] del kwargs_fit['datatofit'] else: data = self.data optdata, optmodel = self._fit(data, self.solver, kwargs_fit, macromodel_init=macro_init) if print_output: self._print_output(optdata[0], optmodel[0]) return optdata[0], optmodel[0] def optimize_fit_lensmodel(self, kwargs_fit={}, macro_init=None, print_output=False): kwargs_fit.update({'identifier': self.identifier}) optdata, optmodel = self._fit_lensmodel(self.data, self.solver, kwargs_fit, macromodel_init=macro_init) if print_output: self._print_output(optdata[0], optmodel[0]) return optdata[0], optmodel[0] def _print_output(self, optdata, optmodel): macromodel = optmodel.lens_components[0] print('optimized mags: ', optdata.m) print('observed mags: ', self.data.m) print('lensmodel fit: ') print('Einstein radius: ', macromodel.lenstronomy_args['theta_E']) print('shear, shear_theta:', macromodel.shear, macromodel.shear_theta) print('ellipticity, PA:', macromodel.ellip_PA_polar()[0], macromodel.ellip_PA_polar()[1]) print('centroid: ', macromodel.lenstronomy_args['center_x'], macromodel.lenstronomy_args['center_y']) print('\n') print('flux ratios w.r.t. image ' + str(self.fluximg) + ':') print('observed: ', self.data.compute_flux_ratios(index=self.flux_ratio_index)) print('recovered: ', optdata.compute_flux_ratios(index=self.flux_ratio_index))
class Lens0128(Quad): x = np.array([-0.2046459, -0.1066459, 0.3153541, -0.0966459]) y = np.array([0.10689306, 0.20089306, -0.06510694, -0.14310694]) m = np.array([1., 0.584, 0.52, 0.506]) sigma_x = np.array([0.003] * 4) sigma_y = np.array([0.003] * 4) sigma_m = np.zeros_like(sigma_x) zlens, zsrc = 1.145, 3.12 data = Data(x, y, m, None, None, sigma_x=sigma_x, sigma_y=sigma_y, sigma_m=sigma_m) identifier = 'lens0128' has_satellite = False flux_ratio_index = 0 fluximg = ['A', 'B', 'C', 'D'][flux_ratio_index] _macromodel = get_default_SIE(zlens) _macromodel.lenstronomy_args['theta_E'] = approx_theta_E(x, y) gamma_min = 1.95 gamma_max = 2.2 srcmin = 0.005 srcmax = 0.025 def optimize_fit(self, kwargs_fit={}, macro_init=None, print_output=False): if 'datatofit' in kwargs_fit.keys(): data = kwargs_fit['datatofit'] del kwargs_fit['datatofit'] else: data = self.data optdata, optmodel = self._fit(data, self.solver, kwargs_fit, macromodel_init=macro_init) if print_output: self._print_output(optdata[0], optmodel[0]) return optdata[0], optmodel[0] def optimize_fit_lensmodel(self, kwargs_fit={}, macro_init=None, print_output=False): kwargs_fit.update({'identifier': self.identifier}) optdata, optmodel = self._fit_lensmodel(self.data, self.solver, kwargs_fit, macromodel_init=macro_init) if print_output: self._print_output(optdata[0], optmodel[0]) return optdata[0], optmodel[0] def _print_output(self, optdata, optmodel): macromodel = optmodel.lens_components[0] print('optimized mags: ', optdata.m) print('observed mags: ', self.data.m) print('lensmodel fit: ') print('Einstein radius: ', macromodel.lenstronomy_args['theta_E']) print('shear, shear_theta:', macromodel.shear, macromodel.shear_theta) print('ellipticity, PA:', macromodel.ellip_PA_polar()[0], macromodel.ellip_PA_polar()[1]) print('centroid: ', macromodel.lenstronomy_args['center_x'], macromodel.lenstronomy_args['center_y']) print('\n') print('flux ratios w.r.t. image ' + str(self.fluximg) + ':') print('observed: ', self.data.compute_flux_ratios(index=self.flux_ratio_index)) print('recovered: ', optdata.compute_flux_ratios(index=self.flux_ratio_index))
class Lens1606(Quad): x = np.array([0.838, -0.784, 0.048, -0.289]) y = np.array([0.378, -0.211, -0.527, 0.528]) m = np.array([1., 1., 0.59, 0.79]) sigma_x = np.array([0.005]*4) sigma_y = np.array([0.005]*4) sigma_m = np.zeros_like(sigma_x) zlens, zsrc = 0.31, 1.7 time_delay_AB, delta_AB = 5.6, 1.6 time_delay_AC, delta_AC = 11.2, 2.6 time_delay_AD, delta_AD = 9.2, 2.7 delta_time_delay = np.array([delta_AB, delta_AC, delta_AD]) relative_arrival_times = np.array([time_delay_AB, time_delay_AC, time_delay_AD]) data = Data(x, y, m, None, None, sigma_x = sigma_x, sigma_y = sigma_y, sigma_m=sigma_m) identifier = 'lens1606' flux_ratio_index = 0 fluximg = ['A', 'B', 'C', 'D'][flux_ratio_index] _macromodel = get_default_SIE(zlens) _macromodel.lenstronomy_args['theta_E'] = approx_theta_E(x, y) gamma_min = 1.9 gamma_max = 2.2 srcmin = 0.02 srcmax = 0.05 has_satellite = True satellite_mass_model = ['SIS'] satellite_redshift = [zlens] satellite_convention = ['phys'] # from mass center satellite_pos_mass = np.array([-0.307, -1.153]) # from light center #satellite_pos_light = [-0.1255, -1.3517] satellite_kwargs = [{'theta_E': 0.269, 'center_x': satellite_pos_mass[0], 'center_y': satellite_pos_mass[1]}] def optimize_fit(self, kwargs_fit={}, macro_init = None, print_output = False): if 'datatofit' in kwargs_fit.keys(): data = kwargs_fit['datatofit'] del kwargs_fit['datatofit'] else: data = self.data satellites = {} satellites['lens_model_name'] = self.satellite_mass_model satellites['z_satellite'] = [self.zlens] satellites['kwargs_satellite'] = self.satellite_kwargs kwargs_fit.update({'satellites': satellites}) optdata, optmodel = self._fit(data, self.solver, kwargs_fit, macromodel_init=macro_init) if print_output: self._print_output(optdata[0], optmodel[0]) return optdata[0], optmodel[0] def optimize_fit_lensmodel(self, kwargs_fit={}, macro_init = None, print_output = False): kwargs_fit.update({'identifier': self.identifier}) optdata, optmodel = self._fit_lensmodel(self.data, self.solver, kwargs_fit, macromodel_init=macro_init) if print_output: self._print_output(optdata[0], optmodel[0]) return optdata[0], optmodel[0] def _print_output(self, optdata, optmodel): macromodel = optmodel.lens_components[0] print('optimized mags: ', optdata.m) print('observed mags: ', self.data.m) print('lensmodel fit: ') print('Einstein radius: ', macromodel.lenstronomy_args['theta_E']) print('shear, shear_theta:', macromodel.shear, macromodel.shear_theta) print('ellipticity, PA:', macromodel.ellip_PA_polar()[0], macromodel.ellip_PA_polar()[1]) print('centroid: ', macromodel.lenstronomy_args['center_x'], macromodel.lenstronomy_args['center_y']) print('\n') print('flux ratios w.r.t. image '+str(self.fluximg)+':') print('observed: ', self.data.compute_flux_ratios(index=self.flux_ratio_index)) print('recovered: ', optdata.compute_flux_ratios(index=self.flux_ratio_index))
class Lens1131(Quad): # From Suyu et al. 2016 # typo in Chen et al. 2016? g1x, g1y = 4.420, 3.932 x = np.array([2.383, 2.344, 2.96, 5.494]) - g1x y = np.array([3.412, 4.594, 2.3, 4.288]) - g1y m = np.array([1., 0.613497, 0.730061, 0.06135]) sigma_x = np.array([0.003] * 4) sigma_y = np.array([0.003] * 4) time_delay_AB, delta_AB = 0.7, 1.2 time_delay_AC, delta_AC = 1.1, 1.5 time_delay_AD, delta_AD = -90.6, 1.4 delta_time_delay = np.array([delta_AB, delta_AC, delta_AD]) relative_arrival_times = -np.array( [time_delay_AB, time_delay_AC, time_delay_AD]) kwargs_lens_init = [{ 'theta_E': 1.58460356403038, 'center_x': -0.005270348888552784, 'center_y': -0.029873551296941633, 'e1': 0.028027358886809944, 'e2': 0.0693670602615151, 'gamma': 1.98 }, { 'gamma1': -0.11734572581060929, 'gamma2': -0.03232611049507928 }] sigma_m = np.zeros_like(sigma_x) zlens, zsrc = 0.3, 0.66 data = Data(x, y, m, None, None, sigma_x=sigma_x, sigma_y=sigma_y, sigma_m=sigma_m) identifier = 'lens1131' flux_ratio_index = 1 fluximg = ['A', 'B', 'C', 'D'][flux_ratio_index] _macromodel = get_default_SIE(zlens) _macromodel.lenstronomy_args['theta_E'] = approx_theta_E(x, y) has_satellite = True satellite_mass_model = ['SIS'] satellite_redshift = [zlens] satellite_convention = ['phys'] satellite_pos_mass = [4.323 - g1x, 4.546 - g1y] # From Chen et al. 2016 amp_scale = 1000 kwargs_lens_light = [{ 'amp': amp_scale * 1.5, 'R_sersic': 0.404, 'n_sersic': 2., 'center_x': 0., 'center_y': 0. }] kwargs_source_light = [{ 'amp': amp_scale * 4, 'R_sersic': 0.1, 'n_sersic': 2., 'center_x': None, 'center_y': None, 'e1': -0.2, 'e2': 0.2 }] kwargs_satellite_light = [{ 'amp': amp_scale * 2, 'R_sersic': 0.05, 'n_sersic': 2., 'center_x': satellite_pos_mass[0], 'center_y': satellite_pos_mass[1] }] # satellite einstein radius from Chen et al. 2016 satellite_kwargs = [{ 'theta_E': 0.28, 'center_x': satellite_pos_mass[0], 'center_y': satellite_pos_mass[1] }] gamma_min = 1.95 gamma_max = 2.2 srcmin = 0.02 srcmax = 0.05 @staticmethod def relative_time_delays(arrival_times): trel = arrival_times[1:] - arrival_times[0] return np.array(trel) def optimize_fit(self, kwargs_fit={}, macro_init=None, print_output=False): if 'datatofit' in kwargs_fit.keys(): data = kwargs_fit['datatofit'] del kwargs_fit['datatofit'] else: data = self.data optdata, optmodel = self._fit(data, self.solver, kwargs_fit, macromodel_init=macro_init) if print_output: self._print_output(optdata[0], optmodel[0]) return optdata[0], optmodel[0] def optimize_fit_lensmodel(self, kwargs_fit={}, macro_init=None, print_output=False): kwargs_fit.update({'identifier': self.identifier}) optdata, optmodel = self._fit_lensmodel(self.data, self.solver, kwargs_fit, macromodel_init=macro_init) if print_output: self._print_output(optdata[0], optmodel[0]) return optdata[0], optmodel[0] def _print_output(self, optdata, optmodel): macromodel = optmodel.lens_components[0] print('optimized mags: ', optdata.m) print('observed mags: ', self.data.m) print('lensmodel fit: ') print('Einstein radius: ', macromodel.lenstronomy_args['theta_E']) print('shear, shear_theta:', macromodel.shear, macromodel.shear_theta) print('ellipticity, PA:', macromodel.ellip_PA_polar()[0], macromodel.ellip_PA_polar()[1]) print('centroid: ', macromodel.lenstronomy_args['center_x'], macromodel.lenstronomy_args['center_y']) print('\n') print('flux ratios w.r.t. image ' + str(self.fluximg) + ':') print('observed: ', self.data.compute_flux_ratios(index=self.flux_ratio_index)) print('recovered: ', optdata.compute_flux_ratios(index=self.flux_ratio_index))
class J0405(Quad): x = np.array([0.708, -0.358, 0.363, -0.515]) y = np.array([-0.244, -0.567, 0.592, 0.454]) m = np.array([1., 0.65, 1.25, 1.17]) * 1.25**-1 sigma_x = np.array([0.005] * 4) sigma_y = np.array([0.005] * 4) sigma_m = np.zeros_like(sigma_x) zlens, zsrc = 0.3, 1.71 data = Data(x, y, m, None, None, sigma_x=sigma_x, sigma_y=sigma_y, sigma_m=sigma_m) identifier = 'lens0405' flux_ratio_index = 0 fluximg = ['A', 'B', 'C', 'D'][flux_ratio_index] _macromodel = get_default_SIE(zlens) _macromodel.lenstronomy_args['theta_E'] = approx_theta_E(x, y) gamma_min = 1.9 gamma_max = 2.2 has_satellite = False srcmin = 0.02 srcmax = 0.05 def optimize_fit(self, kwargs_fit={}, macro_init=None, print_output=False): if 'datatofit' in kwargs_fit.keys(): data = kwargs_fit['datatofit'] del kwargs_fit['datatofit'] else: data = self.data optdata, optmodel = self._fit(data, self.solver, kwargs_fit, macromodel_init=macro_init) if print_output: self._print_output(optdata[0], optmodel[0]) return optdata[0], optmodel[0] def optimize_fit_lensmodel(self, kwargs_fit={}, macro_init=None, print_output=False): kwargs_fit.update({'identifier': self.identifier}) optdata, optmodel = self._fit_lensmodel(self.data, self.solver, kwargs_fit, macromodel_init=macro_init) if print_output: self._print_output(optdata[0], optmodel[0]) return optdata[0], optmodel[0] def _print_output(self, optdata, optmodel): macromodel = optmodel.lens_components[0] print('optimized mags: ', optdata.m) print('observed mags: ', self.data.m) print('lensmodel fit: ') print('Einstein radius: ', macromodel.lenstronomy_args['theta_E']) print('shear, shear_theta:', macromodel.shear, macromodel.shear_theta) print('ellipticity, PA:', macromodel.ellip_PA_polar()[0], macromodel.ellip_PA_polar()[1]) print('centroid: ', macromodel.lenstronomy_args['center_x'], macromodel.lenstronomy_args['center_y']) print('\n') print('flux ratios w.r.t. image ' + str(self.fluximg) + ':') print('observed: ', self.data.compute_flux_ratios(index=self.flux_ratio_index)) print('recovered: ', optdata.compute_flux_ratios(index=self.flux_ratio_index))
def run(self, macromodel=None, tovary={'source_size_kpc': [0.01, 0.05], 'gamma': [1.95, 2.2]}, N=500, zlens=0.5, optimizer_kwargs={}, write_to_file=False, fname=None, satellite_kwargs = None, satellite_mass_model = None, satellite_redshift=None, satellite_convention=None, flux_ratio_index = None, return_physical_positions=[], z_source=None): assert flux_ratio_index is not None flux_ratio_index = int(flux_ratio_index) inds = [] for i in range(0,4): if i != flux_ratio_index: inds.append(i) inds = np.array(inds) if write_to_file is True: assert fname is not None rein, ellip, PA, shear, shearPA, gamma, source_size, cen_x, cen_y = \ [], [], [], [], [], [], [], [], [] satellite_x_1, satellite_y_1, satellite_thetaE_1, z_sat_1 = [], [], [], [] satellite_x_2, satellite_y_2, satellite_thetaE_2, z_sat_2 = [], [], [], [] fluxes = [] if macromodel is None: macromodel = get_default_SIE(zlens) n_computed = 0 while n_computed < N: if i % 100 == 0: print(str(i) + ' of ' + str(N) + '... ') args = {} for argname in optimizer_kwargs.keys(): args.update({argname: optimizer_kwargs[argname]}) macro = deepcopy(macromodel) for pname in tovary.keys(): param_names = ['satellite_theta_E_1', 'satellite_x_1', 'satellite_y_1', 'satellite_redshift_1', 'satellite_theta_E_2', 'satellite_x_2', 'satellite_y_2', 'satellite_redshift_2'] if pname in param_names: assert satellite_kwargs is not None assert satellite_mass_model is not None if pname == 'satellite_redshift_1': satellite_redshift[0] = np.random.uniform(tovary[pname][0], tovary[pname][1]) if pname == 'satellite_redshift_2': satellite_redshift[1] = np.random.uniform(tovary[pname][0], tovary[pname][1]) elif pname == 'satellite_theta_E_1': satellite_kwargs[0].update({'theta_E': np.random.uniform(max(0,tovary[pname][0]), tovary[pname][1])}) elif pname == 'satellite_x_1': satellite_kwargs[0].update({'center_x': np.random.normal(tovary[pname][0], tovary[pname][1])}) elif pname == 'satellite_y_1': satellite_kwargs[0].update({'center_y': np.random.normal(tovary[pname][0], tovary[pname][1])}) elif pname == 'satellite_redshift_2': satellite_redshift = [np.random.uniform(tovary[pname][0], tovary[pname][1])]*len(satellite_mass_model) elif pname == 'satellite_theta_E_2': satellite_kwargs[1].update({'theta_E': np.random.uniform(max(0,tovary[pname][0]), tovary[pname][1])}) elif pname == 'satellite_x_2': satellite_kwargs[1].update({'center_x': np.random.normal(tovary[pname][0], tovary[pname][1])}) elif pname == 'satellite_y_2': satellite_kwargs[1].update({'center_y': np.random.normal(tovary[pname][0], tovary[pname][1])}) else: if pname == 'fixed_param_gaussian': dictionary = tovary['fixed_param_gaussian'] name = list(dictionary.keys())[0] fixed_mean, fixed_sigma = dictionary[name][0], dictionary[name][1] fixed_param = np.random.normal(fixed_mean, fixed_sigma) if 'constrain_params' in args.keys(): args['constrain_params'].update({name: fixed_param}) else: args.update({'constrain_params': {name: fixed_param}}) elif pname == 'fixed_param_uniform': dictionary = tovary['fixed_param_uniform'] name = list(dictionary.keys())[0] fixed_low, fixed_high = dictionary[name][0], dictionary[name][1] fixed_param = np.random.uniform(fixed_low, fixed_high) if 'constrain_params' in args.keys(): args['constrain_params'].update({name: fixed_param}) else: args.update({'constrain_params': {name: fixed_param}}) elif pname == 'constrained_param_uniform': dictionary = tovary['constrained_param_uniform'] name = list(dictionary.keys())[0] pmin, pmax, tol = dictionary[name][0], dictionary[name][1], dictionary[name][2] value = np.random.uniform(pmin) if 'constrain_params' in args.keys(): args['constrain_params'].update({name: fixed_param}) else: args.update({'constrain_params': {name: [value, tol]}}) else: if pname != 'source_size_kpc': low, high = tovary[pname][0], tovary[pname][1] macro.lenstronomy_args[pname] = np.random.uniform(low, high) if 'gamma' in tovary.keys(): gammavalue = np.random.uniform(tovary['gamma'][0], tovary['gamma'][1]) macro.lenstronomy_args['gamma'] = gammavalue if 'source_size_kpc' in tovary.keys(): srcsize = np.random.uniform(tovary['source_size_kpc'][0], tovary['source_size_kpc'][1]) else: assert 'source_size_kpc' in optimizer_kwargs.keys() srcsize = optimizer_kwargs['source_size_kpc'] args.update({'source_size_kpc': srcsize}) if satellite_mass_model is not None: satellites = {'lens_model_name': satellite_mass_model, 'z_satellite': satellite_redshift, 'kwargs_satellite': satellite_kwargs, 'position_convention': satellite_convention} else: satellites = None args.update({'macromodel': macro}) args.update({'satellites': satellites}) if self.from_class: optdata, optmodel, data_fitted = self._optimize_once_fromlensclass(self.optroutine, args) else: out1, out2, data_fitted = self._optimize_once(self.optroutine, args) optdata, optmodel = out1[0][0], out2[1][0] if chi_square_img(optdata.x,optdata.y,data_fitted.x,data_fitted.y,0.001) > 1: continue if np.isnan(optdata.m[0]): continue if optmodel._has_satellites: mass_model, zsat, kwargssat, convention = optmodel.satellite_properties if return_physical_positions: coords = optmodel.get_satellite_physical_location_fromkwargs(z_source) else: coords = [] for j in range(0, len(kwargssat)): coords.append([kwargssat[j]['center_x'], kwargssat[j]['center_y']]) if 'satellite_theta_E_1' in tovary.keys(): satellite_thetaE_1.append(kwargssat[0]['theta_E']) if 'satellite_x_1' in tovary.keys(): satellite_x_1.append(coords[0][0]) if 'satellite_y_1' in tovary.keys(): satellite_y_1.append(coords[0][1]) if 'satellite_theta_E_2' in tovary.keys(): satellite_thetaE_2.append(kwargssat[1]['theta_E']) if 'satellite_x_2' in tovary.keys(): satellite_x_2.append(coords[1][0]) if 'satellite_y_2' in tovary.keys(): satellite_y_2.append(coords[1][1]) if 'satellite_redshift_1' in tovary.keys(): z_sat_1.append(zsat[0]) if 'satellite_redshift_2' in tovary.keys(): z_sat_2.append(zsat[1]) optimized_macromodel = optmodel.lens_components[0] modelargs = optimized_macromodel.lenstronomy_args rein.append(modelargs['theta_E']) ellipPA = optimized_macromodel.ellip_PA_polar() ellip.append(ellipPA[0]) PA.append(ellipPA[1]) shear.append(optimized_macromodel.shear) shearPA.append(optimized_macromodel.shear_theta) gamma.append(gammavalue) source_size.append(srcsize * 1000) cen_x.append(modelargs['center_x']) cen_y.append(modelargs['center_y']) if len(fluxes) == 0: norm = optdata.m[flux_ratio_index] fluxes = optdata.m[inds] * norm**-1 fluxes.reshape(1,3) else: norm = optdata.m[flux_ratio_index] new_ratios = optdata.m[inds] * norm**-1 fluxes = np.vstack((fluxes, new_ratios)) n_computed += 1 print('N remaining: ', N - n_computed) rein = np.round(rein, 4) ellip = np.round(ellip, 4) PA = np.round(PA, 2) shear = np.round(shear, 4) shearPA = np.round(shearPA, 3) gamma = np.round(gamma, 2) source_size = np.round(source_size, 2) cen_x, cen_y = np.round(cen_x, 4), np.round(cen_y, 4) z_sat_1 = np.round(z_sat_1, 2) z_sat_2 = np.round(z_sat_2, 2) satellite_x_1, satellite_y_1 = np.round(satellite_x_1, 4), np.round(satellite_y_1, 4) satellite_x_2, satellite_y_2 = np.round(satellite_x_2, 4), np.round(satellite_y_2, 4) satellite_thetaE_1, satellite_thetaE_2 = np.round(satellite_thetaE_1, 3), np.round(satellite_thetaE_2, 3) full_dictionary = {'Rein': rein, 'ellip': ellip, 'ellipPA': PA, 'shear': shear, 'shearPA': shearPA, 'gamma': gamma, 'srcsize': source_size, 'centroid_x': cen_x, 'centroid_y': cen_y, 'G2x1': satellite_x_1, 'G2y1': satellite_y_1, 'G2thetaE1': satellite_thetaE_1, 'G2redshift1': z_sat_1, 'G2x2': satellite_x_2, 'G2y2': satellite_y_2, 'G2thetaE2': satellite_thetaE_2, 'G2redshift2': z_sat_2} param_order = ['Rein', 'shear', 'shearPA', 'ellip', 'ellipPA', 'gamma', 'srcsize', 'centroid_x', 'centroid_y'] supp = ['G2x1', 'G2y1', 'G2thetaE1', 'G2redshift', 'G2x2', 'G2y2', 'G2thetaE2', 'G2redshif2'] for supp_param in supp: if supp_param in full_dictionary.keys() and len(full_dictionary[supp_param])>0: param_order.append(supp_param) if write_to_file: array = np.array(fluxes) #header = 'f1 f2 f3 ' for param_name in param_order: print(param_name) array = np.column_stack((array, full_dictionary[param_name])) with open(fname, mode='a') as f: for row in range(0, int(np.shape(array)[0])): for col in range(0, int(np.shape(array)[1])): f.write(str(array[row, col])+' ') f.write('\n') return fluxes, full_dictionary
class Lens1330(Quad): x = np.array([0.226, -0.188, -1.023, 0.463]) y = np.array([-0.978, -0.99, 0.189, 0.604]) m = np.array([1., 0.79, 0.41, 0.25]) sigma_x = np.array([0.005] * 4) sigma_y = np.array([0.005] * 4) sigma_m = np.zeros_like(sigma_x) zsrc, zlens = 1.38, 0.37 data = Data(x, y, m, None, None, sigma_x=sigma_x, sigma_y=sigma_y, sigma_m=sigma_m) identifier = 'lens1330' flux_ratio_index = 0 fluximg = ['A', 'B', 'C', 'D'][flux_ratio_index] _macromodel = get_default_SIE(zlens) _macromodel.lenstronomy_args['theta_E'] = approx_theta_E(x, y) gamma_min = 1.9 gamma_max = 2.2 srcmin = 0.02 srcmax = 0.05 #satellite_mass_model = ['SERSIC_ELLIPSE_KAPPA'] # from mass center satellite_pos_mass = np.array([0, 0]) has_satellite = False disk_q, disk_angle = 0.2, 180 * np.arctan(y[0] / x[0]) / np.pi disk_angle += 25 disk_angle *= np.pi / 180 e1_disk, e2_disk = phi_q2_ellipticity(disk_angle, disk_q) satellite_kwargs = [{ 'k_eff': 0.2, 'R_sersic': 0.5, 'n_sersic': 1, 'e1': e1_disk, 'e2': e2_disk, 'center_x': 0, 'center_y': 0 }] def optimize_fit(self, kwargs_fit={}, macro_init=None, print_output=False): if 'datatofit' in kwargs_fit.keys(): data = kwargs_fit['datatofit'] del kwargs_fit['datatofit'] else: data = self.data satellites = None #satellites['lens_model_name'] = self.satellite_mass_model #satellites['z_satellite'] = [self.zlens] #satellites['kwargs_satellite'] = self.satellite_kwargs kwargs_fit.update({'satellites': satellites}) optdata, optmodel = self._fit(data, self.solver, kwargs_fit, macromodel_init=macro_init) if print_output: self._print_output(optdata[0], optmodel[0]) return optdata[0], optmodel[0] def optimize_fit_lensmodel(self, kwargs_fit={}, macro_init=None, print_output=False): kwargs_fit.update({'identifier': self.identifier}) optdata, optmodel = self._fit_lensmodel(self.data, self.solver, kwargs_fit, macromodel_init=macro_init) if print_output: self._print_output(optdata[0], optmodel[0]) return optdata[0], optmodel[0] def _print_output(self, optdata, optmodel): macromodel = optmodel.lens_components[0] print('optimized mags: ', optdata.m) print('observed mags: ', self.data.m) print('lensmodel fit: ') print('Einstein radius: ', macromodel.lenstronomy_args['theta_E']) print('shear, shear_theta:', macromodel.shear, macromodel.shear_theta) print('ellipticity, PA:', macromodel.ellip_PA_polar()[0], macromodel.ellip_PA_polar()[1]) print('centroid: ', macromodel.lenstronomy_args['center_x'], macromodel.lenstronomy_args['center_y']) print('\n') print('flux ratios w.r.t. image ' + str(self.fluximg) + ':') print('observed: ', self.data.compute_flux_ratios(index=self.flux_ratio_index)) print('recovered: ', optdata.compute_flux_ratios(index=self.flux_ratio_index))
class Lens0712(Quad): x = np.array([-0.785, -0.729, 0.027, 0.389]) y = np.array([-0.142, -0.298, -0.805, 0.317]) m = np.array([1., 0.843, 0.418, 0.082]) sigma_x = np.array([0.005]*4) sigma_y = np.array([0.005]*4) sigma_m = np.zeros_like(sigma_x) zlens, zsrc = 0.5, 1.5 data = Data(x, y, m, None, None, sigma_x = sigma_x, sigma_y = sigma_y, sigma_m=sigma_m) identifier = 'lens0712' flux_ratio_index = 0 fluximg = ['A', 'B', 'C', 'D'][flux_ratio_index] _macromodel = get_default_SIE(zlens) _macromodel.lenstronomy_args['theta_E'] = approx_theta_E(x, y) gamma_min = 1.9 gamma_max = 2.2 srcmin = 0.001 srcmax = 0.02 satellite_mass_model = ['SERSIC_ELLIPSE_GAUSS_DEC'] # from mass center satellite_pos_mass = np.array([0, 0]) disk_q, disk_angle = 0.23, 90 - 59.7 disk_angle *= np.pi / 180 disk_angle *= np.pi / 180 e1_disk, e2_disk = phi_q2_ellipticity(disk_angle, disk_q) satellite_kwargs = [{'k_eff': 0.294, 'R_sersic': 0.389, 'n_sersic': 1, 'e1': e1_disk, 'e2': e2_disk, 'center_x':satellite_pos_mass[0], 'center_y':satellite_pos_mass[1]}] def optimize_fit(self, kwargs_fit={}, macro_init = None, print_output = False): if 'datatofit' in kwargs_fit.keys(): data = kwargs_fit['datatofit'] del kwargs_fit['datatofit'] else: data = self.data satellites = {} satellites['lens_model_name'] = self.satellite_mass_model satellites['z_satellite'] = [self.zlens] satellites['kwargs_satellite'] = self.satellite_kwargs kwargs_fit.update({'satellites': satellites}) optdata, optmodel = self._fit(data, self.solver, kwargs_fit, macromodel_init=macro_init) if print_output: self._print_output(optdata[0], optmodel[0]) return optdata[0], optmodel[0] def optimize_fit_lensmodel(self, kwargs_fit={}, macro_init = None, print_output = False): kwargs_fit.update({'identifier': self.identifier}) optdata, optmodel = self._fit_lensmodel(self.data, self.solver, kwargs_fit, macromodel_init=macro_init) if print_output: self._print_output(optdata[0], optmodel[0]) return optdata[0], optmodel[0] def _print_output(self, optdata, optmodel): macromodel = optmodel.lens_components[0] print('optimized mags: ', optdata.m) print('observed mags: ', self.data.m) print('lensmodel fit: ') print('Einstein radius: ', macromodel.lenstronomy_args['theta_E']) print('shear, shear_theta:', macromodel.shear, macromodel.shear_theta) print('ellipticity, PA:', macromodel.ellip_PA_polar()[0], macromodel.ellip_PA_polar()[1]) print('centroid: ', macromodel.lenstronomy_args['center_x'], macromodel.lenstronomy_args['center_y']) print('\n') print('flux ratios w.r.t. image '+str(self.fluximg)+':') print('observed: ', self.data.compute_flux_ratios(index=self.flux_ratio_index)) print('recovered: ', optdata.compute_flux_ratios(index=self.flux_ratio_index))
class WFI2033_satlocobs(Quad): x = np.array([-0.751, -0.039, 1.445, -0.668]) y = np.array([0.953, 1.068, -0.307, -0.585]) m = np.array([1., 0.65, 0.5, 0.53]) time_delay_AB, delta_AB = 0, 100 time_delay_AC, delta_AC = -36.2, 0.8 time_delay_AD, delta_AD = 23.3, 1.4 # delta_time_delay = np.array([delta_AB, delta_AC, delta_AD]) # relative_arrival_times = np.array([time_delay_AB, time_delay_AC, time_delay_AD]) relative_arrival_times = np.array([0.01, 36.2, 23.3 + 36.2]) delta_time_delay = np.array( [delta_AB, delta_AC, np.sqrt(delta_AC**2 + delta_AD**2)]) sigma_x = np.array([0.005] * 4) sigma_y = np.array([0.005] * 4) sigma_m = np.zeros_like(sigma_x) zsrc, zlens = 1.66, 0.66 # source redshift from Motta et al data = Data(x, y, m, None, None, sigma_x=sigma_x, sigma_y=sigma_y, sigma_m=sigma_m) identifier = 'lens2033' flux_ratio_index = 0 fluximg = ['A', 'B', 'C', 'D'][flux_ratio_index] _macromodel = get_default_SIE(zlens) _macromodel.lenstronomy_args['theta_E'] = approx_theta_E(x, y) gamma_min = 1.9 gamma_max = 2.1 kwargs_lens_init = [{ 'theta_E': 1.0011161129638548, 'center_x': 0.0035639468432663527, 'center_y': 0.022250277854418788, 'e1': 0.013745407369119727, 'e2': 0.04242065788101877, 'gamma': 1.95 }, { 'gamma1': 0.1849727326105099, 'gamma2': -0.07557590574285741 }] kwargs_lens_light = [{ 'amp': 2500, 'R_sersic': 0.2, 'n_sersic': 4., 'center_x': None, 'center_y': None }] kwargs_source_light = [{ 'amp': 1000, 'R_sersic': 0.08, 'n_sersic': 2.5, 'center_x': None, 'center_y': None, 'e1': 0.01, 'e2': -0.14 }] srcmin = 0.02 srcmax = 0.05 has_satellite = True satellite_mass_model = ['SIS', 'SIS'] satellite1_pos_mass = [0.245, 2.037] satellite2_pos_mass = [-3.965, -0.022] satellite2_pos_mass_effective = [-3.63, -0.08] satellite_redshift = [zlens, 0.745] satellite_convention = ['phys', 'phys'] theta_E = (0.389 * 0.334)**0.5 kwargs_satellite_light = [{ 'amp': 800, 'R_sersic': 0.1, 'n_sersic': 3., 'center_x': satellite1_pos_mass[0], 'center_y': satellite1_pos_mass[1] }, None] satellite_kwargs = [{ 'theta_E': 0.03, 'center_x': satellite1_pos_mass[0], 'center_y': satellite1_pos_mass[1] }, { 'theta_E': 0.93, 'center_x': satellite2_pos_mass[0], 'center_y': satellite2_pos_mass[1] }] @staticmethod def relative_time_delays(arrival_times): trel = arrival_times[1:] - arrival_times[0] trel = [abs(trel[0]), abs(trel[1]), abs(trel[1]) + abs(trel[2])] return np.array(trel) def optimize_fit(self, kwargs_fit={}, macro_init=None, print_output=False): if 'datatofit' in kwargs_fit.keys(): data = kwargs_fit['datatofit'] del kwargs_fit['datatofit'] else: data = self.data if 'satellites' not in kwargs_fit.keys(): satellites = {} satellites['lens_model_name'] = self.satellite_mass_model satellites['z_satellite'] = self.satellite_redshift satellites['kwargs_satellite'] = self.satellite_kwargs satellites['position_convention'] = self.satellite_convention kwargs_fit.update({'satellites': satellites}) optdata, optmodel = self._fit(data, self.solver, kwargs_fit, macromodel_init=macro_init) if print_output: self._print_output(optdata[0], optmodel[0]) return optdata[0], optmodel[0] def optimize_fit_lensmodel(self, kwargs_fit={}, macro_init=None, print_output=False): kwargs_fit.update({'identifier': self.identifier}) optdata, optmodel = self._fit_lensmodel(self.data, self.solver, kwargs_fit, macromodel_init=macro_init) if print_output: self._print_output(optdata[0], optmodel[0]) return optdata[0], optmodel[0] def _print_output(self, optdata, optmodel): macromodel = optmodel.lens_components[0] print('optimized mags: ', optdata.m) print('observed mags: ', self.data.m) print('lensmodel fit: ') print('Einstein radius: ', macromodel.lenstronomy_args['theta_E']) print('shear, shear_theta:', macromodel.shear, macromodel.shear_theta) print('ellipticity, PA:', macromodel.ellip_PA_polar()[0], macromodel.ellip_PA_polar()[1]) print('centroid: ', macromodel.lenstronomy_args['center_x'], macromodel.lenstronomy_args['center_y']) print('\n') print('flux ratios w.r.t. image ' + str(self.fluximg) + ':') print('observed: ', self.data.compute_flux_ratios(index=self.flux_ratio_index)) print('recovered: ', optdata.compute_flux_ratios(index=self.flux_ratio_index)) # lens = WFI2033() # x, y = lens.x, lens.y # col = ['k', 'r', 'm', 'g'] # import matplotlib.pyplot as plt # for l in range(0, 4): # plt.scatter(-x[l], y[l], color=col[l]) # plt.show()