KIDS  ver-0.0.1
KIDS : Kernel Integrated Dynamics Simulator
Loading...
Searching...
No Matches
select_init.py
Go to the documentation of this file.
1import numpy as np
2import pandas as pd
3import os
4import sys
5import re
6
7def getfiles(path):
8 f_list_raw = os.listdir(path)
9 f_list = []
10 for i in f_list_raw:
11 if os.path.splitext(i)[1] == '.ds':
12 f_list += [i]
13 return f_list
14
15if __name__ == '__main__':
16 path = sys.argv[1]
17 out_path = sys.argv[2]
18 from_size = int(sys.argv[3])
19 samp_size = int(sys.argv[4])
20
21 #files = getfiles(path)
22 #Nf = len(files)
23 Nf=from_size
24 file_id = np.arange(Nf)
25 np.random.shuffle(file_id)
26 print(file_id)
27
28 frp = []
29 E1 = []
30 E2 = []
31 cnt = 0
32 for i in file_id:
33 print(cnt)
34 cnt+=1
35
36 frps = re.split("[ |\n]+", os.popen(
37 "cat %s | grep -A2 f_rp | tail -n 1"%(path + '/samp%d.ds'%i)
38 ).read().strip() )
39 frp += [float(frps[1])]
40
41 Es = re.split("[ |\n]+", os.popen(
42 "cat %s | grep -A2 model.rep.E | tail -n 1"%(path + '/samp%d.ds'%i)
43 ).read().strip() )
44 E1 += [float(Es[0])]
45 E2 += [float(Es[1])]
46
47 frp = np.array(frp)
48 E1 = np.array(E1)
49 E2 = np.array(E2)
50 v = frp / (E2-E1)**2
51
52 pd.DataFrame(np.vstack([file_id, frp, E1, E2, v]).T).to_csv(
53 out_path + '_dat.csv',
54 header=['id', 'frp', 'E1', 'E2', 'v'],
55 index=None
56 )
57
58 maxv = np.max(v)
59
60 samp_files = []
61 while len(samp_files) < samp_size:
62 print('#'*10)
63
64 r = np.random.random(size=(Nf))
65 idx = np.where(v > r*maxv)[0]
66 samp_files += list(file_id[idx])
67
68 samp_files = samp_files[:samp_size]
69 print(samp_files)
70
71 os.popen('mkdir %s'%out_path)
72 cnt = 0
73 for i in samp_files:
74 os.popen('cp %s %s'%(path + '/samp%d.ds'%i, out_path + '/init%d.ds'%cnt))
75 cnt += 1
76
getfiles(path)
Definition select_init.py:7