-
Notifications
You must be signed in to change notification settings - Fork 1
/
vpf_halotools.py
69 lines (54 loc) · 2.19 KB
/
vpf_halotools.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
#calculating VPF using halotools
from __future__ import print_function,division
from halotools.mock_observables import void_prob_func
import numpy as np
import time
import os
import multiprocessing as mp
#start = time.time()
N = int(1e5)
L = 2500.
radius = np.logspace(-1,1.3,30) # 0.1 - 19.98 MPc
#path = '/mnt/data4/Abhishek/mockHOD/'
path = '/mnt/data4/Abhishek/fidmock'
def voidprobfunc(rbins, n_ran, period, filename):
global path
if filename.endswith(".npy"):
sample = np.load(os.path.join(path,filename))
vpf = void_prob_func(sample,rbins=rbins,n_ran=n_ran,period=period)
np.save(os.path.join('/mnt/data4/Abhishek/fidmock/vpf','vpf_'+str(filename)),(rbins,vpf))
#np.save(os.path.join('/mnt/data4/Abhishek/VPF/random','vpf_'+str(filename)),(rbins.astype('float64'),vpf.astype('float64')))
else:
raise TypeError("File should be in .npy format")
#return None
def parallel_vpf(rbins,n_ran,period,path):
pool = mp.Pool()
filenames = [files for files in os.listdir(path) if files.endswith('.npy')]
#filenames = ['galaxies_'+f'{files:04d}'+'.npy' for files in range(10000)]
results = [pool.apply_async(voidprobfunc, args=(rbins,n_ran,period,i,)) for i in filenames]
pool.close()
pool.join()
return results
def main():
start = time.time()
parallel_vpf(rbins = radius, n_ran = N, period = L, path = path)
#voidprobfunc(rbins = radius,n_ran = N, period = L, filename = 'MDgalaxies_0100.npy')
print (f'Total time taken: {time.time() - start}')
if __name__ == "__main__":
main()
'''
for file in os.listdir(path)[:5]:
if file.endswith(".npy"):
start = time.time()
gal = np.load(os.path.join(path,file)) # coordinates of the galaxies
a = np.min(gal)
b = np.max(gal)
print (f'minimum = {a}\nmax = {b}\nNumber of particles = {len(gal)}')
vpf = void_prob_func(gal,rbins = radius,n_ran = N,period = L)
#print (f'Void Probability = {vpf}')
#print (f'Radius of the sphere = {radius} Mpc')
#print (f'Void Probability = {nvoid/N}')
np.save('test_'+ str(file),(radius,vpf))
print (f'Total time = {time.time()-start} sec')
#print (sp)
'''