|
| 1 | +#!/usr/bin/python3 |
| 2 | +""" |
| 3 | +This writes LaTeX for the rows of our table of LineTAP columns. Technically, |
| 4 | +this obtains the info from the standard columns of an operational (and |
| 5 | +hopefully validated) table at dc.g-vo.org. |
| 6 | +
|
| 7 | +Dependency: python3-pyvo (and hence astropy). |
| 8 | +""" |
| 9 | + |
| 10 | +import pyvo |
| 11 | + |
| 12 | +NON_NULL_COLUMNS = {'title', 'vacuum_wavelength'} |
| 13 | +TYPE_MAP = { |
| 14 | + ("char", "*"): "text", |
| 15 | + ("unicodeChar", "*"): "text", |
| 16 | + ("int", ""): "integer", |
| 17 | + ("double", ""): "float",} |
| 18 | + |
| 19 | + |
| 20 | +def e(tx): |
| 21 | + """returns tx with TeX's standard active (and other magic) characters |
| 22 | + escaped. |
| 23 | + """ |
| 24 | + return tx.replace("\\", "$\\backslash$" |
| 25 | + ).replace("&", "\\&" |
| 26 | + ).replace("#", "\\#" |
| 27 | + ).replace("%", "\\%" |
| 28 | + ).replace("_", "\\_" |
| 29 | + ).replace("}", "\\}" |
| 30 | + ).replace("{", "\\{" |
| 31 | + ).replace('"', '{"}') |
| 32 | + |
| 33 | + |
| 34 | +def get_type(datatype, arraysize, nonnull): |
| 35 | + """returns a simple type identifier for a VOTable datatype/arraysize. |
| 36 | +
|
| 37 | + Well, this really only nows what people have manually entered into |
| 38 | + TYPE_MAP above... |
| 39 | + """ |
| 40 | + res = e(TYPE_MAP[datatype, arraysize]) |
| 41 | + if nonnull: |
| 42 | + res = f"\\textbf{{{res}}}" |
| 43 | + return res |
| 44 | + |
| 45 | + |
| 46 | +def main(): |
| 47 | + svc = pyvo.tap.TAPService("http://dc.g-vo.org/tap") |
| 48 | + rows = [] |
| 49 | + |
| 50 | + for row in svc.run_sync(""" |
| 51 | + select column_name, description, unit, ucd, datatype, arraysize |
| 52 | + from tap_schema.columns |
| 53 | + where |
| 54 | + table_name='species.main' |
| 55 | + order by column_index"""): |
| 56 | + parts = [r"\texttt{{{}}}".format(e(row["column_name"]))] |
| 57 | + if row["unit"]: |
| 58 | + parts.append(e("["+row["unit"].replace("Angstrom", "Å")+"]")) |
| 59 | + parts.append(r"\hfil\break\ucd{{{}}}".format(e(row["ucd"]))) |
| 60 | + |
| 61 | + parts.append("&") |
| 62 | + parts.append(get_type( |
| 63 | + row["datatype"], |
| 64 | + row["arraysize"], |
| 65 | + row["column_name"] in NON_NULL_COLUMNS)) |
| 66 | + |
| 67 | + parts.append("&") |
| 68 | + parts.append(r"\raggedright "+e(row["description"])) |
| 69 | + |
| 70 | + rows.append(" ".join(parts)+r"\tabularnewline") |
| 71 | + |
| 72 | + print("\n\\rowsep\n".join(rows)) |
| 73 | + |
| 74 | + |
| 75 | +if __name__=="__main__": |
| 76 | + main() |
0 commit comments