-
Notifications
You must be signed in to change notification settings - Fork 11
/
phat-clusters.py
62 lines (52 loc) · 1.53 KB
/
phat-clusters.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
from astrometry.util.fits import *
'''
Parse the PHAT young & old cluster catalogs sent by Nelson, 2017-12-15
'''
def convert(f, name):
hdr = f.readline()
f.readline()
T = fits_table()
T.name = []
T.ra = []
T.dec = []
T.comment = []
T.mag = []
T.velocity = []
T.metallicity = []
for line in f.readlines():
words = line.split()
T.name.append(words[0])
T.ra.append(float(words[1]))
T.dec.append(float(words[2]))
cc = ' '.join(words[3:])
T.comment.append(cc)
# strip off quotation marks
cc = cc.replace('"','')
words = cc.split(',')
#print('words', words)
T.mag.append(float(words[0].strip()))
if len(words) >= 2:
v = float(words[1].replace('km/s', '').strip())
else:
v = 0.
T.velocity.append(v)
if len(words) >= 3:
z = float(words[2].strip())
else:
z = 0
T.metallicity.append(z)
T.to_np_arrays()
T.mag = T.mag.astype(np.float32)
T.metallicity = T.metallicity.astype(np.float32)
T.velocity = T.velocity.astype(np.float32)
T.writeto('%s.fits' % name)
f = open('young_phat_clusters', 'rb')
convert(f, 'phat-clusters-young')
f = open('old_phat_clusters', 'rb')
convert(f, 'phat-clusters-old')
T1 = fits_table('phat-clusters-young.fits')
T1.young = np.ones(len(T1), bool)
T2 = fits_table('phat-clusters-old.fits')
T2.young = np.zeros(len(T2), bool)
T = merge_tables([T1,T2])
T.writeto('phat-clusters.fits')