-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.py
154 lines (121 loc) · 4 KB
/
build.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
147
148
149
150
151
152
153
154
import yaml
import glob
import os
import numpy as np
from astropy.coordinates import SkyCoord
import astropy.table
from grizli import utils
## Read tables
files = glob.glob("tables/*csv")
files.sort()
tabs = []
ids = []
with open("tables/README.md", "w") as fpr:
fpr.write("# References\n\n")
fpr.write("| arXiv | Author | Title |\n")
fpr.write("| ----- | ------ | ----- |\n")
for file in files:
meta = file.replace(".csv", ".meta")
if not os.path.exists(meta):
print(f"meta file {meta} not found for {file}")
continue
print(f"Read table: {file}")
try:
tab = utils.read_catalog(file)
except:
print(f"Failed to read table: {file}")
continue
with open(meta) as fp:
try:
_meta = yaml.load(fp, Loader=yaml.SafeLoader)
except:
print(
f'ERROR: Failed to parse {meta}, check that there are no ":" or incompatible linebreaks in `description`'
)
continue
fpr.write(
f"| [{_meta['arxiv']}](https://arxiv.org/abs/{_meta['arxiv']}) | {_meta['author']} | {_meta['description']} | \n"
)
meta_ok = True
for k in ["arxiv", "author"]:
if k not in _meta:
print(f"ERROR: `{k}` keyword not found in {meta}")
meta_ok = False
if not meta_ok:
continue
for k in ["arxiv", "author"]:
tab[k] = _meta[k]
if "rah" in tab.colnames:
try:
coo = SkyCoord(tab["rah"], tab["decd"], unit=("hour", "deg"))
except:
print(f"Failed to parse rah/decd coordinates in {file}")
continue
tab["ra"] = coo.ra.deg
tab["dec"] = coo.dec.deg
# tab['id'] =
ids.extend([f"{_id}" for _id in tab["id"]])
tab.remove_column("id")
tab["jname"] = [
utils.radec_to_targname(
ra,
dec,
round_arcsec=(0.00001, 0.00001),
precision=2,
targstr="j{rah}{ram}{ras}.{rass}{sign}{ded}{dem}{des}.{dess}",
)
for ra, dec in zip(tab["ra"], tab["dec"])
]
if len(tabs) > 0:
# If matches exist in files already processed, get the
# jname from there
_full = utils.GTable(astropy.table.vstack(tabs))
idx, dr = _full.match_to_catalog_sky(tab)
hasm = dr.value < 0.5
if hasm.sum() > 0:
tab["jname"][hasm] = _full["jname"][idx][hasm]
tabs.append(tab)
# Concatenated table
full = utils.GTable(astropy.table.vstack(tabs))
full["id"] = ids
jn = utils.Unique(full["jname"], verbose=False)
full["count"] = 1
for name, ct in zip(jn.values, jn.counts):
full["count"][jn[name]] = ct
so = np.argsort(full["jname"])
full = full[so]
full["ra"].format = ".6f"
full["ra"].description = "Right Ascension, deg"
full["dec"].format = ".5f"
full["dec"].description = "Declination, deg"
full["zphot"].format = ".2f"
full["zphot"].description = "Photometric redshift"
if "zspec" not in full.colnames:
full["zspec"] = -1.0
full["zspec"].format = ".3f"
full["zspec"].description = "Spectroscopic redshift"
full["count"].description = "Number of references"
thumb = '<img src="http://grizli-cutout.herokuapp.com/thumb?ra={ra}8&dec={dec}&filters={filt}&size=1&scl={scl}&invert=True" height=100px />'
full["F200W"] = [thumb.format(filt="f200w-clear", scl=16, **row) for row in full]
full["F444W"] = [thumb.format(filt="f444w-clear", scl=24, **row) for row in full]
full.write("jwst-sources.csv", overwrite=True)
sub = full[
"jname",
"count",
"F200W",
"F444W",
"ra",
"dec",
"id",
"zphot",
"zspec",
"arxiv",
"author",
]
sub.write_sortable_html(
"jwst-sources.html",
localhost=False,
max_lines=100000,
filter_columns=["count", "ra", "dec", "zphot", "zspec"],
use_json=True,
)