1
+ from exotic .exotic import LimbDarkening
2
+ from exotic .api .elca import transit , lc_fitter
3
+ from ldtk .filters import create_tess
4
+ import matplotlib .pyplot as plt
5
+ import numpy as np
6
+
7
+ if __name__ == "__main__" :
8
+ prior = {
9
+ 'rprs' : 0.02 , # Rp/Rs
10
+ 'ars' : 14.25 , # a/Rs
11
+ 'per' : 3.33 , # Period [day]
12
+ 'inc' : 88.5 , # Inclination [deg]
13
+ 'u0' : 0 , 'u1' : 0 , 'u2' : 0 , 'u3' : 0 , # limb darkening (nonlinear)
14
+ 'ecc' : 0.5 , # Eccentricity
15
+ 'omega' : 120 , # Arg of periastron
16
+ 'tmid' : 0.75 , # Time of mid transit [day],
17
+ 'a1' : 50 , # Airmass coefficients
18
+ 'a2' : 0. , # trend = a1 * np.exp(a2 * airmass)
19
+
20
+ 'teff' :5000 ,
21
+ 'tefferr' :50 ,
22
+ 'met' : 0 ,
23
+ 'meterr' : 0 ,
24
+ 'logg' : 3.89 ,
25
+ 'loggerr' : 0.01
26
+ }
27
+
28
+ # example generating LD coefficients
29
+ tessfilter = create_tess ()
30
+
31
+ ld_obj = LimbDarkening (
32
+ teff = prior ['teff' ], teffpos = prior ['tefferr' ], teffneg = prior ['tefferr' ],
33
+ met = prior ['met' ], metpos = prior ['meterr' ], metneg = prior ['meterr' ],
34
+ logg = prior ['logg' ], loggpos = prior ['loggerr' ], loggneg = prior ['loggerr' ],
35
+ wl_min = tessfilter .wl .min (), wl_max = tessfilter .wl .max (), filter_type = "Clear" )
36
+
37
+ ld0 , ld1 , ld2 , ld3 , filt , wlmin , wlmax = ld_obj .nonlinear_ld ()
38
+
39
+ prior ['u0' ],prior ['u1' ],prior ['u2' ],prior ['u3' ] = [ld0 [0 ], ld1 [0 ], ld2 [0 ], ld3 [0 ]]
40
+
41
+ time = np .linspace (0.7 , 0.8 , 1000 ) # [day]
42
+
43
+ # simulate extinction from airmass
44
+ stime = time - time [0 ]
45
+ alt = 90 * np .cos (4 * stime - np .pi / 6 )
46
+ #airmass = 1./np.cos(np.deg2rad(90-alt))
47
+ airmass = np .zeros (time .shape [0 ])
48
+
49
+ # GENERATE NOISY DATA
50
+ data = transit (time , prior )* prior ['a1' ]* np .exp (prior ['a2' ]* airmass )
51
+ data += np .random .normal (0 , prior ['a1' ]* 250e-6 , len (time ))
52
+ dataerr = np .random .normal (300e-6 , 50e-6 , len (time )) + np .random .normal (300e-6 , 50e-6 , len (time ))
53
+
54
+ # add bounds for free parameters only
55
+ mybounds = {
56
+ 'rprs' : [0 , 0.1 ],
57
+ 'tmid' : [prior ['tmid' ]- 0.01 , prior ['tmid' ]+ 0.01 ],
58
+ 'ars' : [13 , 15 ],
59
+ #'a2': [0, 0.3] # uncomment if you want to fit for airmass
60
+ # never list 'a1' in bounds, it is perfectly correlated to exp(a2*airmass)
61
+ # and is solved for during the fit
62
+ }
63
+
64
+ myfit = lc_fitter (time , data , dataerr , airmass , prior , mybounds , mode = 'ns' )
65
+
66
+ for k in myfit .bounds .keys ():
67
+ print (f"{ myfit .parameters [k ]:.6f} +- { myfit .errors [k ]} " )
68
+
69
+ fig , axs = myfit .plot_bestfit ()
70
+ plt .tight_layout ()
71
+ plt .show ()
72
+
73
+ fig = myfit .plot_triangle ()
74
+ plt .tight_layout ()
75
+ plt .show ()
0 commit comments