Beispiel #1
0
def runABC(chain_ID='',core_index=int):

    print('trying to find paramdictionary file... ')
    chain_keys,chain_keys_to_vary,output_path,run, readout_best = initialize(chain_ID,core_index)

    if run is False:
        return

    # Initialize data
    datatofit = Data(x=chain_keys['x_to_fit'], y=chain_keys['y_to_fit'], m=chain_keys['flux_to_fit'],
                     t=chain_keys['t_to_fit'], source=chain_keys['source'])

    rein_main = approx_theta_E(datatofit.x, datatofit.y)

    chain_keys.update({'R_ein_main': rein_main})
    chain_keys.update({'cone_opening_angle': chain_keys['opening_angle_factor'] * rein_main})

    write_data(output_path + 'lensdata.txt',[datatofit], mode='write')

    print('lens redshift: ', chain_keys['zlens'])
    print('source redshift: ', chain_keys['zsrc'])
    print('opening angle: ', chain_keys['opening_angle_factor']*approx_theta_E(datatofit.x, datatofit.y))

    if run is False:
        return

    param_names_tovary = chain_keys_to_vary.keys()
    write_info_file(chainpath + chain_keys['output_folder'] + 'simulation_info.txt',
                    chain_keys, chain_keys_to_vary, param_names_tovary)
    #copy_directory(chain_ID + '/R_index_config.txt', chainpath + chain_keys['output_folder'])

    prior = ParamSample(params_to_vary=chain_keys_to_vary, Nsamples=1)

    run_lenstronomy(datatofit, prior, chain_keys, chain_keys_to_vary, output_path,
                        chain_keys['write_header'], readout_best)
Beispiel #2
0
    def _fit_lensmodel(self,
                       data_class,
                       solver_class,
                       kwargs_fit,
                       macromodel_init=None):

        if macromodel_init is None:
            macromodel_init = get_default_SIE_random(solver_class.zmain)
            macromodel_init.lenstronomy_args['theta_E'] = approx_theta_E(
                data_class.x, data_class.y)

        fit_args = {}

        for key in self.default_kwargs_fit_lensmodel.keys():
            fit_args.update({key: self.default_kwargs_fit_lensmodel[key]})
        for key in kwargs_fit.keys():
            fit_args.update({key: kwargs_fit[key]})

        optdata, opt_model = solver_class.two_step_optimize(
            macromodel=macromodel_init, datatofit=data_class, **fit_args)

        os.system('rm best.sm')
        os.system('rm chitmp.dat')
        os.system('rm grid.dat')
        os.system('rm crit.dat')

        return optdata, opt_model
Beispiel #3
0
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]
    }]
Beispiel #4
0
    def __init__(self):

        theta_E = approx_theta_E(self.reference_lens.x, self.reference_lens.y)
        kwargs_reference = [{
            'theta_E': theta_E,
            'center_x': 0.,
            'center_y': 0.,
            'e1': 0.1,
            'e2': -0.2,
            'gamma': 2.
        }, {
            'gamma1': 0.05,
            'gamma2': 0.
        }]
        source_x, source_y = 0.04, -0.12

        super(Lens1115AnalogFold, self).__init__(source_x, source_y,
                                                 kwargs_reference)
Beispiel #5
0
    def _fit(self,
             data_class,
             solver_class,
             kwargs_fit,
             macromodel_init=None,
             sat_pos_lensed=False):

        if macromodel_init is None:
            macromodel_init = get_default_SIE_random(solver_class.zmain)
            macromodel_init.lenstronomy_args['theta_E'] = approx_theta_E(
                data_class.x, data_class.y)

        fit_args = {}

        for key in self.default_kwargs_fit.keys():
            fit_args.update({key: self.default_kwargs_fit[key]})
        for key in kwargs_fit.keys():
            fit_args.update({key: kwargs_fit[key]})

        optdata, opt_model = solver_class.optimize_4imgs_lenstronomy(
            datatofit=data_class, macromodel=macromodel_init, **fit_args)

        return optdata, opt_model
Beispiel #6
0
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))
Beispiel #7
0
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))
Beispiel #8
0
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))
Beispiel #9
0
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))
Beispiel #10
0
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))
Beispiel #11
0
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))
Beispiel #12
0
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))
Beispiel #13
0
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))
Beispiel #14
0
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))
Beispiel #15
0
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_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))
Beispiel #17
0
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))
Beispiel #18
0
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))
Beispiel #19
0
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))
Beispiel #20
0
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))
Beispiel #21
0
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))
Beispiel #22
0
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()