-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremoveGeom.py
85 lines (59 loc) · 2.53 KB
/
removeGeom.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
import os
import shutil
import numpy as np
# import glob
# import tarfile
# from multiprocessing import Pool
def removeGeom(geom):
path = 'GeomData/geom%d'%geom
if os.path.exists(path):
shutil.rmtree(path)
print('Directory %s successfully removed'%path)
else:
print("Directory %s doesn't exists"%path)
# use the below to only delete the wfu from inside the tar file
# path to this geom archive, hardcoded for simplicity, change according to use
# path = 'GeomData/geom%d/multi1.tar.bz2'%geom
# if not os.path.exists(path) :
# print("File %s doesn't exists. You may haven't archived yet"%path)
# return
# dPath = path.strip('.tar.bz2').strip('/') # directory path to extract
# # unarchive directory exists
# if os.path.exists(dPath):
# print("Folder %s exists, this should not have happened. Check this geom."%dPath)
# return
# os.makedirs(dPath)
# def nowfu(mem): # extract everything except for the wfu file
# for t in mem:
# if not t.name.endswith('wfu'):
# yield t
# with tarfile.open(path) as tar: # extract the file in that directory
# for i in tar.getnames(): # check if the archive contains wfu file
# if i.endswith('wfu') :
# break
# else:
# print('No wfu file found for %s'%path)
# return
# tar.extractall(path=dPath, members=nowfu(tar))
# os.remove(path) # delete older archive
# shutil.make_archive(dPath, 'bztar', root_dir=dPath, base_dir='./') # create new archive
# shutil.rmtree(dPath) # remove extracted directory
# print('wfu successfully removed from %s'%path)
# sample the geomdatas to delete
data = np.loadtxt('./geomdata.txt', usecols=(0,))
data = np.array(data, dtype=np.int)
ind = data%3==0 # keep geomid divisible by 3
ind[:2] = True # also keep the first two geometries as they are 0 phi (0,0),(1,0), just such
indToDelete = data[~ind]# these geomids will be deleted
print('Geometries with geomid not divisible by 3 will be deleted except geomid = 0 and 1.')
print('The following %d no of geometries from GeomData will be removed'%len(indToDelete))
print(indToDelete)
try: # python2
choice = raw_input('Do you want to proceed (y/n)? ')
except NameError: #pytho3 and above
choice = input('Do you want to proceed (y/n)? ')
if choice.strip().lower()[0]=='y':
# delete them in parallel
# p = Pool(4)
# p.map(removeGeom, indToDelete)
for i in indToDelete : removeGeom(i)