-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPLB_makeseparray.py
104 lines (69 loc) · 2.88 KB
/
PLB_makeseparray.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
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python
from __future__ import absolute_import, unicode_literals, print_function
import math
import numpy as np
from scipy import integrate as integ
import sys
import time
from numpy import pi, cos
from pymultinest.solve import solve
import os
import json
#from mpi4py import MPI
Names = ['BootesI','BootesII','BootesIII','Coma','Crater','CanesI','CanesII','Draco','DracoII','Hercules','LeoI','LeoII','LeoIV','LeoV',\
'PiscesII','SagII','SegueI','SegueII','SextansI','TriII','UrsaMajorI','UrsaMajorII','UrsaMinor','WillmanI','CetusII','ColumbaI',\
'EridanusIII','Fornax','GrusI','GrusII','HoroI','HoroII','PhoenixII','PictorI','RetiII','RetiIII','TucanaII','TucanaIII','TucanaIV','TucanaV']
workdir,thisdir,pbf,pbg,spatialrundir,rundir,runnum = sys.argv[1:]
d = json.load(open(workdir+"/"+thisdir+"/dict_bf"+pbf+"bg"+pbg+".dat"))
dataloc = workdir+'/'+thisdir+'/rawxy'+runnum+'bf'+pbf+'bg'+pbg+'.dat'
rid = "run" + runnum + "_bf" + pbf +'bg'+pbg
rundir = workdir + '/' + thisdir + '/' + rundir +'/'
spatialrundir = workdir + '/' + thisdir + '/' + spatialrundir +'/'
# probability function, taken from the eggbox problem.
start_time = time.time()
print(rundir)
try: os.mkdir(rundir)
except OSError: pass
#prevparams = np.loadtxt(spatialrundir+'spatialparams'+rid+'.dat')
#pa = prevparams[0,0]
#pI0 = prevparams[1,0]
bxy = np.loadtxt(dataloc)
bx = bxy[:,0]
by = bxy[:,1]
brs = np.sqrt(bx**2 + by**2)
rp = d[Names[int(runnum)]]['Rp']
brs = brs[brs<10*rp]
def f(s,a,I0):
ans = 1/(s**3*(4*a**2 + s**2)**(5/2)) *4*a**6*I0**2 *math.pi**2*(s*(-2*a**2+s**2)*np.sqrt(4*a**2+s**2) - 2*a**2*(a**2+s**2)*(2*np.log(a)+np.log(-s + np.sqrt(4*a**2+s**2)) - np.log(s**2*(s + np.sqrt(4*a**2+s**2)) + a**2*(3*s+np.sqrt(4*a**2+s**2)))))
return(s*ans)
slenmax = 200000
if(len(bx)**2 < 200):
tbraws = np.zeros(len(bx)**2)
count = 0
for i in range(0,len(bx)):
if i%100 == 0:
print(i)
for j in range(i+1,len(by)):
tbraws[count] = np.sqrt((bx[i]-bx[j])**2 + (by[i]-by[j])**2)
count+=1
s = tbraws[tbraws>0]
print("FIRST LOOP, len(s) = " + str(len(s)))
else:
seps = 10000*np.ones(slenmax)
maxval = np.amax(seps)
maxidx = np.argmax(seps)
for i in range(0,len(bx)):
for j in range(i+1,len(bx)):
thisdist = np.sqrt((bx[i]-bx[j])**2 + (by[i]-by[j])**2)
if(thisdist<maxval):
seps[maxidx]=thisdist
maxval = np.amax(seps)
maxidx = np.argmax(seps)
ts = seps[seps<10000]
s=ts[ts>0]
print("SECOND LOOP, len(s) = " + str(len(s)))
print("The highest separation we have reached is " + str(np.amax(s)))
print("Just make sure it's more than 0.1pc")
np.savetxt(rundir+"s_arr_"+rid+".dat",s)
print("Took "+str(time.time()-start_time) + " seconds to completely finish")
np.savetxt(rundir+"MS_TIME"+rid+".dat",np.array([time.time()-start_time]))