|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "# Create binned table data" |
| 8 | + ] |
| 9 | + }, |
| 10 | + { |
| 11 | + "cell_type": "code", |
| 12 | + "execution_count": 2, |
| 13 | + "metadata": {}, |
| 14 | + "outputs": [], |
| 15 | + "source": [ |
| 16 | + "import io\n", |
| 17 | + "import numpy as np\n", |
| 18 | + "from astropy.table import Table" |
| 19 | + ] |
| 20 | + }, |
| 21 | + { |
| 22 | + "cell_type": "markdown", |
| 23 | + "metadata": {}, |
| 24 | + "source": [ |
| 25 | + "## Gather data sets" |
| 26 | + ] |
| 27 | + }, |
| 28 | + { |
| 29 | + "cell_type": "code", |
| 30 | + "execution_count": 3, |
| 31 | + "metadata": {}, |
| 32 | + "outputs": [], |
| 33 | + "source": [ |
| 34 | + "fq_mass = np.load(\"data/fq_mass.npy\") # Figure 4: quenched fraciton vs. stellar mass\n", |
| 35 | + "fq_dist = np.load(\"data/fq_dist.npy\") # Figure 5: quenched fraction vs. radius\n", |
| 36 | + "ssfr_dist = np.load(\"data/ssfr_dist.npy\") # Figure 7: sSFR vs. radius" |
| 37 | + ] |
| 38 | + }, |
| 39 | + { |
| 40 | + "cell_type": "code", |
| 41 | + "execution_count": 4, |
| 42 | + "metadata": {}, |
| 43 | + "outputs": [], |
| 44 | + "source": [ |
| 45 | + "# Figure 6: SFR_NUV vs. stellar mass - TODO: update to use np.save\n", |
| 46 | + "sfr_nuv_mass = np.loadtxt(io.StringIO(\"\"\"6.9\t -2.84\t 0.22\t 0.30\n", |
| 47 | + "7.3\t -2.47\t 0.41\t 0.23\n", |
| 48 | + "7.6\t -2.40\t 0.30\t 0.37\n", |
| 49 | + "7.8\t -2.19\t 0.42\t 0.40\n", |
| 50 | + "8.2\t -1.94\t 0.35\t 0.37\n", |
| 51 | + "8.6\t -1.65\t 0.25\t 0.41\n", |
| 52 | + "9.4\t -0.88\t 0.37\t 0.44\"\"\")).T" |
| 53 | + ] |
| 54 | + }, |
| 55 | + { |
| 56 | + "cell_type": "code", |
| 57 | + "execution_count": 5, |
| 58 | + "metadata": {}, |
| 59 | + "outputs": [], |
| 60 | + "source": [ |
| 61 | + "# Figure 6: SFR_Halpha vs. stellar mass - TODO: update to use np.save\n", |
| 62 | + "sfr_ha_mass = np.loadtxt(io.StringIO(\"\"\"6.9\t -3.00\t 0.34\t 0.40\n", |
| 63 | + "7.3\t -2.61\t 0.49\t 0.60\n", |
| 64 | + "7.6\t -2.59\t 0.31\t 0.97\n", |
| 65 | + "7.8\t -2.20\t 0.44\t 0.44\n", |
| 66 | + "8.2\t -2.16\t 0.34\t 0.83\n", |
| 67 | + "8.6\t -1.53\t 0.44\t 0.64\n", |
| 68 | + "9.4\t -0.75\t 0.44\t 0.39\"\"\")).T" |
| 69 | + ] |
| 70 | + }, |
| 71 | + { |
| 72 | + "cell_type": "code", |
| 73 | + "execution_count": 6, |
| 74 | + "metadata": {}, |
| 75 | + "outputs": [], |
| 76 | + "source": [ |
| 77 | + "# Figure 8: sSFR_NUV vs. stellar mass - TODO: update to use np.save\n", |
| 78 | + "ssfr_nuv_mass = np.loadtxt(io.StringIO(\"\"\"\n", |
| 79 | + "6.9\t -9.81\t 0.20\t 0.34\n", |
| 80 | + "7.3\t -9.81\t 0.34\t 0.26\n", |
| 81 | + "7.6\t -9.96\t 0.33\t 0.35\n", |
| 82 | + "7.8\t -9.98\t 0.53\t 0.36\n", |
| 83 | + "8.2\t -10.10\t0.32\t0.34\n", |
| 84 | + "8.6\t -10.15\t0.38\t0.32\n", |
| 85 | + "9.4\t -10.19\t0.59\t0.31\"\"\")).T" |
| 86 | + ] |
| 87 | + }, |
| 88 | + { |
| 89 | + "cell_type": "markdown", |
| 90 | + "metadata": {}, |
| 91 | + "source": [ |
| 92 | + "## Print out latex tables" |
| 93 | + ] |
| 94 | + }, |
| 95 | + { |
| 96 | + "cell_type": "code", |
| 97 | + "execution_count": 7, |
| 98 | + "metadata": {}, |
| 99 | + "outputs": [], |
| 100 | + "source": [ |
| 101 | + "def write_latex_table(t, formats=None, write_to=None, display=True, edit_func=None):\n", |
| 102 | + " if formats is None:\n", |
| 103 | + " formats = {}\n", |
| 104 | + " if not isinstance(formats, dict):\n", |
| 105 | + " formats = {c: f for c, f in zip(t.colnames, formats)}\n", |
| 106 | + "\n", |
| 107 | + " fp = io.StringIO()\n", |
| 108 | + " t.write(fp, format=\"ascii.latex\", formats=formats)\n", |
| 109 | + " lines = fp.getvalue().splitlines()\n", |
| 110 | + " if edit_func is not None:\n", |
| 111 | + " lines = edit_func(lines)\n", |
| 112 | + " lines[-3] = lines[-3].rstrip(\"\\\\\")\n", |
| 113 | + "\n", |
| 114 | + " fp = io.StringIO()\n", |
| 115 | + " fp.write(\"\\n\".join(lines[3:-2]))\n", |
| 116 | + " fp.write(\"\\n\")\n", |
| 117 | + " out = fp.getvalue()\n", |
| 118 | + "\n", |
| 119 | + " if write_to:\n", |
| 120 | + " with open(write_to, \"w\") as fp:\n", |
| 121 | + " fp.write(out)\n", |
| 122 | + "\n", |
| 123 | + " if display:\n", |
| 124 | + " print(out)" |
| 125 | + ] |
| 126 | + }, |
| 127 | + { |
| 128 | + "cell_type": "markdown", |
| 129 | + "metadata": {}, |
| 130 | + "source": [ |
| 131 | + "### Stellar mass table" |
| 132 | + ] |
| 133 | + }, |
| 134 | + { |
| 135 | + "cell_type": "code", |
| 136 | + "execution_count": 8, |
| 137 | + "metadata": {}, |
| 138 | + "outputs": [ |
| 139 | + { |
| 140 | + "name": "stdout", |
| 141 | + "output_type": "stream", |
| 142 | + "text": [ |
| 143 | + "9.38 & 0.135 & 0.049 & $-0.88$ & $-1.25$ & $-0.44$ & $-10.26$ & $-10.78$ & $-9.88$ & $-0.75$ & $-1.19$ & $-0.36$ \\\\\n", |
| 144 | + "8.62 & 0.160 & 0.053 & $-1.65$ & $-1.90$ & $-1.24$ & $-10.27$ & $-10.53$ & $-9.83$ & $-1.53$ & $-1.97$ & $-0.89$ \\\\\n", |
| 145 | + "8.15 & 0.259 & 0.061 & $-1.94$ & $-2.29$ & $-1.57$ & $-10.09$ & $-10.42$ & $-9.76$ & $-2.16$ & $-2.50$ & $-1.33$ \\\\\n", |
| 146 | + "7.83 & 0.335 & 0.063 & $-2.19$ & $-2.61$ & $-1.79$ & $-10.02$ & $-10.51$ & $-9.62$ & $-2.20$ & $-2.64$ & $-1.76$ \\\\\n", |
| 147 | + "7.57 & 0.408 & 0.061 & $-2.40$ & $-2.70$ & $-2.03$ & $-9.97$ & $-10.29$ & $-9.61$ & $-2.59$ & $-2.90$ & $-1.62$ \\\\\n", |
| 148 | + "7.31 & 0.562 & 0.056 & $-2.47$ & $-2.88$ & $-2.24$ & $-9.78$ & $-10.15$ & $-9.55$ & $-2.61$ & $-3.10$ & $-2.01$ \\\\\n", |
| 149 | + "6.95 & 0.792 & 0.026 & $-2.84$ & $-3.06$ & $-2.54$ & $-9.79$ & $-10.01$ & $-9.47$ & $-3.00$ & $-3.34$ & $-2.60$ \n", |
| 150 | + "\n" |
| 151 | + ] |
| 152 | + } |
| 153 | + ], |
| 154 | + "source": [ |
| 155 | + "t_mass = Table(data={\n", |
| 156 | + " \"log_sm\": fq_mass[0],\n", |
| 157 | + " \"fq\": fq_mass[1],\n", |
| 158 | + " \"fq_err\": fq_mass[2],\n", |
| 159 | + " \"sfr_nuv\": sfr_nuv_mass[1],\n", |
| 160 | + " \"sfr_nuv_16\": sfr_nuv_mass[1] - sfr_nuv_mass[2],\n", |
| 161 | + " \"sfr_nuv_84\": sfr_nuv_mass[1] + sfr_nuv_mass[3],\n", |
| 162 | + " \"ssfr_nuv\": sfr_nuv_mass[1] - fq_mass[0],\n", |
| 163 | + " \"ssfr_nuv_16\": ssfr_nuv_mass[1] - ssfr_nuv_mass[2],\n", |
| 164 | + " \"ssfr_nuv_84\": ssfr_nuv_mass[1] + ssfr_nuv_mass[3],\n", |
| 165 | + " \"sfr_ha\": sfr_ha_mass[1],\n", |
| 166 | + " \"sfr_ha_16\": sfr_ha_mass[1] - sfr_ha_mass[2],\n", |
| 167 | + " \"sfr_ha_84\": sfr_ha_mass[1] + sfr_ha_mass[3],\n", |
| 168 | + "})\n", |
| 169 | + "\n", |
| 170 | + "write_latex_table(\n", |
| 171 | + " t_mass[::-1],\n", |
| 172 | + " formats=([\"%.2f\"] + [\"%.3f\"] * 2 + [\"$%.2f$\"] * 9),\n", |
| 173 | + ")" |
| 174 | + ] |
| 175 | + }, |
| 176 | + { |
| 177 | + "cell_type": "code", |
| 178 | + "execution_count": 12, |
| 179 | + "metadata": {}, |
| 180 | + "outputs": [ |
| 181 | + { |
| 182 | + "name": "stdout", |
| 183 | + "output_type": "stream", |
| 184 | + "text": [ |
| 185 | + "\\phn34.2 & 0.518 & 0.071 & $-10.17$ & $-10.48$ & $-\\phn9.45$ & $-\\phn9.85$ & $-10.26$ & $-\\phn9.51$ \\\\\n", |
| 186 | + "\\phn82.5 & 0.252 & 0.067 & $-10.27$ & $-10.59$ & $-\\phn9.60$ & $-10.05$ & $-10.33$ & $-\\phn9.42$ \\\\\n", |
| 187 | + "130.8 & 0.247 & 0.073 & $-10.18$ & $-10.49$ & $-\\phn9.85$ & $-10.06$ & $-10.42$ & $-\\phn9.78$ \\\\\n", |
| 188 | + "179.2 & 0.166 & 0.064 & $-10.05$ & $-10.48$ & $-\\phn9.42$ & $-\\phn9.99$ & $-10.32$ & $-\\phn9.59$ \\\\\n", |
| 189 | + "227.5 & 0.205 & 0.065 & $-\\phn9.96$ & $-10.35$ & $-\\phn9.33$ & $-\\phn9.89$ & $-10.21$ & $-\\phn9.34$ \\\\\n", |
| 190 | + "275.8 & 0.132 & 0.048 & $-\\phn9.92$ & $-10.39$ & $-\\phn9.39$ & $-\\phn9.80$ & $-10.36$ & $-\\phn9.36$ \n", |
| 191 | + "\n" |
| 192 | + ] |
| 193 | + } |
| 194 | + ], |
| 195 | + "source": [ |
| 196 | + "t_dist = Table(data={\n", |
| 197 | + " \"dist\": fq_dist[0],\n", |
| 198 | + " \"fq\": fq_dist[1],\n", |
| 199 | + " \"fq_err\": fq_dist[2],\n", |
| 200 | + " \"sfr_gold\": ssfr_dist[4],\n", |
| 201 | + " \"sfr_gold_16\": ssfr_dist[4] - ssfr_dist[5],\n", |
| 202 | + " \"sfr_gold_84\": ssfr_dist[4] + ssfr_dist[6],\n", |
| 203 | + " \"sfr_silver\": ssfr_dist[1],\n", |
| 204 | + " \"sfr_silver_16\": ssfr_dist[1] - ssfr_dist[2],\n", |
| 205 | + " \"sfr_silver_84\": ssfr_dist[1] + ssfr_dist[3],\n", |
| 206 | + "})\n", |
| 207 | + "\n", |
| 208 | + "def edit_func(lines):\n", |
| 209 | + " for i, line in enumerate(lines):\n", |
| 210 | + " line = line.replace(\"$-9.\", \"$-\\phn9.\")\n", |
| 211 | + " lines[i] = line\n", |
| 212 | + " first = line.partition(\".\")[0]\n", |
| 213 | + " if first.isnumeric() and len(first) == 2:\n", |
| 214 | + " lines[i] = \"\\\\phn\" + line\n", |
| 215 | + "\n", |
| 216 | + "\n", |
| 217 | + " return lines\n", |
| 218 | + "\n", |
| 219 | + "write_latex_table(\n", |
| 220 | + " t_dist,\n", |
| 221 | + " formats=([\"%.1f\"] + [\"%.3f\"] * 2 + [\"$%.2f$\"] * 6),\n", |
| 222 | + " edit_func=edit_func,\n", |
| 223 | + ")" |
| 224 | + ] |
| 225 | + }, |
| 226 | + { |
| 227 | + "cell_type": "code", |
| 228 | + "execution_count": null, |
| 229 | + "metadata": {}, |
| 230 | + "outputs": [], |
| 231 | + "source": [] |
| 232 | + } |
| 233 | + ], |
| 234 | + "metadata": { |
| 235 | + "kernelspec": { |
| 236 | + "display_name": "Python 3 (ipykernel)", |
| 237 | + "language": "python", |
| 238 | + "name": "python3" |
| 239 | + }, |
| 240 | + "language_info": { |
| 241 | + "codemirror_mode": { |
| 242 | + "name": "ipython", |
| 243 | + "version": 3 |
| 244 | + }, |
| 245 | + "file_extension": ".py", |
| 246 | + "mimetype": "text/x-python", |
| 247 | + "name": "python", |
| 248 | + "nbconvert_exporter": "python", |
| 249 | + "pygments_lexer": "ipython3", |
| 250 | + "version": "3.9.13" |
| 251 | + } |
| 252 | + }, |
| 253 | + "nbformat": 4, |
| 254 | + "nbformat_minor": 2 |
| 255 | +} |
0 commit comments