-
Notifications
You must be signed in to change notification settings - Fork 1
/
csp.py
70 lines (49 loc) · 1.96 KB
/
csp.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
from importer import *
import os
from astropy.io import fits
def find_sfh_ixs(i, nsfhperfile, nsubpersfh):
# `i` is the pure number SFH;
# find file number `fnum` by dividing by mper
nspecperfile = nsfhperfile * nsubpersfh
# file index in filelist
fnum = i // nspecperfile
# record index within individual spectral-data file
fi = i % nspecperfile
# record number in the corresponding param table
fii = fi // nsubpersfh
# row number
fiii = fi % nsubpersfh
return fnum, fi, fii, fiii
def retrieve_SFHs(filelist, i, massnorm='mformed', nsubpersfh=None, nsfhperfile=None):
'''
fetch a time array & SFH from a series of FITS archives,
each with `nsfhperfile` SFHs & `nsubpersfh` Z/tau/mu realizations for
each SFH
'''
if nsfhperfile is None:
nsfhperfile = fits.getval(filelist[0], ext=0, keyword='NSFHPER')
if nsubpersfh is None:
nsubpersfh = fits.getval(filelist[0], ext=0, keyword='NSUBPER')
fnum, fi, fii, fiii = find_sfh_ixs(i, nsfhperfile, nsubpersfh)
'''
print('trainer {0}: spectral:file-spec {1}-{2}; SFH:file-rec-subsample {1}-{3}-{4}'.format(
i, fnum, fi, fii, fiii))
'''
fname = filelist[fnum]
allts = fits.getdata(fname, extname='allts')
allsfhs = np.repeat(fits.getdata(fname, extname='allsfhs'),
nsubpersfh, axis=0)
# normalize mass either by total mass formed or current stellar mass
mtot = fits.getdata(fname, massnorm)[:, None]
return allts, allsfhs / mtot, fi
def retrieve_meta_table(filelist, i, nsubpersfh=None, nsfhperfile=None):
'''
'''
if nsfhperfile is None:
nsfhperfile = fits.getval(filelist[0], ext=0, keyword='NSFHPER')
if nsubpersfh is None:
nsubpersfh = fits.getval(filelist[0], ext=0, keyword='NSUBPER')
fnum, fi, fii, fiii = find_sfh_ixs(i, nsfhperfile, nsubpersfh)
fname = filelist[fnum]
metadata = t.Table.read(fname)
return metadata, fii