forked from jdeast/EXOFASTv2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexofast_recenter.pro
79 lines (68 loc) · 2.02 KB
/
exofast_recenter.pro
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
pro printerr, logname
printandlog, 'This usually means the transit time ran away and requires some bound', logname
printandlog, 'Consider a wide, uniform prior on Tc and/or set REJECTFLATMODEL', logname
printandlog, 'Returning without recentering the distribution', logname
printandlog, '***THIS RESULT SHOULD ONLY BE USED TO DEBUG THE PROBLEM!***', logname
end
;+
; NAME:
; EXOFAST_RECENTER
;
; PURPOSE:
; Recenters a distribution of periodic parameters to the domain
; (mode-period/2,mode+period/2]
;
; CALLING SEQUENCE:
; par = recenter(par,period)
;
; INPUTS:
; PAR = An array of parameters
; PERIOD = The period of the parameter distribution
;
; EXAMPLE:
;
; MODIFICATION HISTORY
; 2012/06 -- Jason Eastman (LCOGT)
;-
function exofast_recenter, par, period, logname=logname
hist = histogram(par,nbins=100,locations=x)
max = max(hist,modendx)
mode = x[modendx]
if n_elements(period) eq 1 then per = replicate(period,n_elements(par)) $
else if n_elements(period) eq n_elements(par) then per = period $
else begin
printandlog, "period must have 1 or npar elements", logname
stop
endelse
bad = where(mode - period/2d0 - mode eq 0d0, nbad)
if nbad ne 0 then begin
printandlog, 'ERROR: the period is negligible compared to the value', logname
printerr,logname
return, par
endif
nper = round((mode - par)/per,/L64)
par -= nper*per
nrepeat=0L
repeat begin
toohigh = where(par gt (mode + period/2d0))
if toohigh[0] ne -1 then par[toohigh] -= per[toohigh]
nrepeat++
if nrepeat gt 10 then begin
printandlog, 'ERROR: recentering about the mode is not converging.', logname
printerr,logname
return, par
endif
endrep until toohigh[0] eq -1
nrepeat=0L
repeat begin
toolow = where(par le (mode - period/2d0))
if toolow[0] ne -1 then par[toolow] += period[toolow]
nrepeat++
if nrepeat gt 10 then begin
printandlog, 'ERROR: recentering about the mode is not converging.', logname
printerr,logname
return, par
endif
endrep until toolow[0] eq -1
return, par
end