-
Notifications
You must be signed in to change notification settings - Fork 2
/
Combiner.py
147 lines (131 loc) · 4.26 KB
/
Combiner.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Style:PEP-8
"""
Created on Thu Sep 7 10:20:35 2017
@author: anto
"""
__author__ = "Anto I Lonappan"
__copyright__ = "Copyright 2017, MB-II analysis Project, Presidency University"
__date__ = "7-Sep-2017"
__version__ = "0.4"
__email__ = "antoidicherian@gmail.com"
__status__ = "Completed"
# PYTHON LIBRARIES
import os
import sys
import glob
import numpy as np
import _pickle as pl
from configparser import ConfigParser as cnf
# CONFIGURATION
conf = cnf()
conf.read('abe.ini')
output_dir = conf.get('live', 'cat_mak_out')
output_dir_lum = conf.get('live', 'dat_anl_out')
delete = conf.get('misc', 'delete_dump')
last_program = conf.get('live', 'last_program')
mode_run = conf.get('misc', 'mode_run')
if 'lum' in sys.argv:
print('Combaining LUM')
lum = {}
lum_files = glob.glob('%s/lum*' % output_dir_lum)
for file in lum_files:
with open(file, 'rb') as reader:
dic = pl.load(reader)
lum.update(dic)
with open('%s/lum.p' % output_dir_lum, 'wb') as writer:
pl.dump(lum, writer)
if delete is 'T':
for file in lum_files:
os.remove(file)
sys.exit()
elif mode_run == 'automated':
if not last_program == 'CatalogMaker_MPI.py':
print("""
I found Last program that you have run was {}
Before running this code please run DataEditor.py.
Also see abe.ini
""".format(last_program))
raise Exception('PreviousRunError')
else:
pass
elif mode_run == 'individual':
pass
############################### bh_cat #######################################
print('Combaining bh_cat ')
i = 0
bh_cat_files = glob.glob('%s/bh*' % output_dir)
for file in bh_cat_files:
with open(file, 'rb') as reader:
globals()['data%d' % i] = pl.load(reader)
i += 1
for j in range(i):
if j == 0:
data = np.concatenate((globals()['data%d' % j],
globals()['data%d' % (j+1)]), axis=0)
elif j == 1:
pass
else:
data = np.concatenate((data, globals()['data%d' % j]), axis=0)
with open('%s/bh_cat.p' % output_dir, 'wb') as writer:
pl.dump(data, writer)
if delete is 'T':
for file in bh_cat_files:
os.remove(file)
############################### snap_cat ######################################
print('Combaining snap_cat')
snap_cat = {}
snap_cat_files = glob.glob('%s/snap*' % output_dir)
for file in snap_cat_files:
with open(file, 'rb') as reader:
dic = pl.load(reader)
snap_cat.update(dic)
with open('%s/snap_cat.p' % output_dir, 'wb') as writer:
pl.dump(snap_cat, writer)
if delete is 'T':
for file in snap_cat_files:
os.remove(file)
################################# data #######################################
print('Combaining Data')
data = {}
data_files = glob.glob('%s/data*' % output_dir)
for file in data_files:
with open(file, 'rb') as reader:
dic = pl.load(reader)
data.update(dic)
with open('%s/data.p' % output_dir, 'wb') as writer:
pl.dump(data, writer)
if delete is 'T':
for file in data_files:
os.remove(file)
################################# mass #######################################
print('Combaining Mass')
mass = {}
mass_files = glob.glob('%s/mass*' % output_dir)
for file in mass_files:
with open(file, 'rb') as reader:
dic = pl.load(reader)
mass.update(dic)
with open('%s/mass.p' % output_dir, 'wb') as writer:
pl.dump(mass, writer)
if delete is 'T':
for file in mass_files:
os.remove(file)
################################ Acc ##########################################
print('Combaining Acc')
acc = {}
acc_files = glob.glob('%s/acc*' % output_dir)
for file in acc_files:
with open(file, 'rb') as reader:
dic = pl.load(reader)
acc.update(dic)
with open('%s/acc.p' % output_dir, 'wb') as writer:
pl.dump(acc, writer)
if delete is 'T':
for file in acc_files:
os.remove(file)
###############################################################################
conf.set('live', 'last_program', 'Combiner.py')
with open('abe.ini', 'w') as fw:
conf.write(fw)