-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathann_random.py
50 lines (45 loc) · 1.31 KB
/
ann_random.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
#!/usr/bin/env python
#encoding=utf-8
import numpy as np
import os
from optparse import OptionParser
"""
Now path must have generate.all_xsf which was total xsf file
You can use ann_random.py 300 to random generate 300 data in generate.in
You can change the file name by yourself
"""
__author__ = "Guanjie Wang"
__email__ = "[email protected]"
__date__ = "Jan 22, 2018"
def read(filename,number):
f = open(filename,'r')
lines = f.readlines()
f.close()
a = np.random.randint(13,len(lines),number)
head = lines[:12]
head.append(str(len(a)) + '\n')
for i in a:
head.append(lines[i])
return head
def write(filename,content):
f = open(filename,'a')
for i in content:
f.write(i)
f.close()
def parse_option():
usage = "%prog arg1 eg:%prog 3000"
parse = OptionParser(usage)
(option,args) = parse.parse_args()
print('The number of random XSF file was {0}'.format(int(args[0])))
return int(args[0])
def _remove_path(path):
if os.path.exists(path):
os.remove(path)
print('******* " {0}" file path exists, removed'.format(path))
if __name__ == '__main__':
filename = 'generate.all_xsf'
number = parse_option()
gogalname = 'generate.in'
head = read(filename,number)
_remove_path(gogalname)
write(gogalname,head)