forked from mmaus96/Lens_Modeling_Auto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
optimize_shear.py
executable file
·47 lines (38 loc) · 2.33 KB
/
optimize_shear.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from Lens_Modeling_Auto.auto_modeling_functions import optParams
from Lens_Modeling_Auto.auto_modeling_functions import removekeys
from Lens_Modeling_Auto.auto_modeling_functions import prepareFit
from Lens_Modeling_Auto.auto_modeling_functions import runFit
from lenstronomy.Workflow.fitting_sequence import FittingSequence
model_kwarg_names = {'kwargs_lens': [['theta_E','e1','e2','center_x','center_y'],['gamma1','gamma2','ra_0','dec_0']],
'kwargs_source': [['amp','R_sersic','n_sersic','center_x','center_y']],
'kwargs_lens_light':[['amp','R_sersic','n_sersic','center_x','center_y']]}
#################Optimize Positions##############################
print('I will now include external shear in the lens model')
print('\n')
#Optimize lens Position
opt_params = {'kwargs_lens': [[],['gamma1','gamma2']],
'kwargs_source': [[]],
'kwargs_lens_light': [[]]}
print('\n')
print('Free parameters:', opt_params)
kwargs_init, kwargs_fixed = optParams(kwargs_result,opt_params,model_kwarg_names)
lens_params = [kwargs_init['kwargs_lens'], kwargs_lens_sigma, kwargs_fixed['kwargs_lens'], kwargs_lower_lens, kwargs_upper_lens]
source_params = [kwargs_init['kwargs_source'], kwargs_source_sigma, kwargs_fixed['kwargs_source'], kwargs_lower_source, kwargs_upper_source]
lens_light_params = [kwargs_init['kwargs_lens_light'], kwargs_lens_light_sigma, kwargs_fixed['kwargs_lens_light'], kwargs_lower_lens_light, kwargs_upper_lens_light]
kwargs_params = {'lens_model': lens_params,
'source_model': source_params,
'lens_light_model': lens_light_params}
print('The lens, source, and lens light modeling parameters are')
print('lens model: ', kwargs_params['lens_model'])
print('\n')
print('source model: ', kwargs_params['source_model'])
print('\n')
print('lens light model: ', kwargs_params['lens_light_model'])
print('\n')
print('-------------------------------------------------------------------')
print('\n')
print('I will now begin the PSO:')
fitting_kwargs_list = [['PSO', {'sigma_scale': 1., 'n_particles': 300, 'n_iterations': 1000,'threadCount': 1}]]
chain_list, kwargs_result = runFit(fitting_kwargs_list, kwargs_params,
kwargs_likelihood, kwargs_model,
kwargs_data_joint, kwargs_constraints = {})