-
Notifications
You must be signed in to change notification settings - Fork 0
/
des_catjoinmy.py
61 lines (44 loc) · 1.62 KB
/
des_catjoinmy.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
import time
import atpy
import asciitable
#import astropy
#from astropy.io import ascii
starttime=time.time()
verbose=0
infile='snc3_cdfs.input'
tab=atpy.Table('snc3_cdfs.input',type='ascii',Reader=asciitable.NoHeader,delimiter=' ')
# use ascitable to read table into numpy record array
#help(table)
nfiles=len(tab.col1) -1
print 'Number of file to process: ', nfiles
print 'shape: ', tab.shape
#print 'dtype: ', tab.dtype
for row_vals in tab: # iterate over table rows
print row_vals # print list of vals in each row
filters=[_[:-1] for _ in tab.col1[1:]] #remove the last character
files= tab.col2[1:]
inpath=tab.col2[0]
tables = [atpy.Table(inpath+x,hdu=2) for x in files]
print "Elapsed time %.3f seconds" % (time.time() - starttime)
spec_columns= ['number', 'ALPHAWIN_J2000','DELTAWIN_J2000']
spec_columns = [str.lower(x) for x in spec_columns]
print 'Number or rows: ', len(tables[0])
# rename all columns in all bands except
for f,t in zip(filters,tables):
print "Elapsed time %.3f seconds" % (time.time() - starttime)
for c in t.columns:
if str.lower(c) not in spec_columns:
t.rename_column(c,f+c)
print "Elapsed time %.3f seconds" % (time.time() - starttime)
# adds columns one by one
for t in tables[1:]:
print "Elapsed time %.3f seconds" % (time.time() - starttime)
for c in t.columns:
print c
if str.lower(c) not in spec_columns:
tables[0].add_column(c,t[c])
#if verbose: data1.describe()
print "Elapsed time %.3f seconds" % (time.time() - starttime)
tables[0].write('xx.fits')
# now write the fits output file
print "Elapsed time %.3f seconds" % (time.time() - starttime)