.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "report/phase_space/plot_class_efficiencies.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_report_phase_space_plot_class_efficiencies.py: Classes on the Maps =================== Where does each transient class sit on the detection maps, and what is the map's detection probability there? The draws that measure a class's region on a map (see the :ref:`maps `) also place each one at a point of the map, so the fitted map can be read off at every draw. This page does that for the **all-sky efficiency** :math:`\eta`, the probability that an event of that peak luminosity and half-decline time, exploding at a random position and time during the survey within its redshift limit, is detected in the band of the map. This is a reading of the map, not the yield of the class. The map holds the rise, the tail and the colour of the event fixed, and a class does not, so the Standard Run, which simulates each class, is the number to quote. The comparison is a check, and shows how much of each class's spread in detectability comes from its luminosity and decline time alone. .. GENERATED FROM PYTHON SOURCE LINES 16-28 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from astropy.table import Table from scipy.interpolate import LinearNDInterpolator from uvex_transients.phase_space.analysis.overlay import split_measurements from uvex_transients.utils import get_phase_space_map from uvex_transients.utils.plotting import get_band_color, set_plot_style set_plot_style() .. GENERATED FROM PYTHON SOURCE LINES 29-31 Load the maps -------------- .. GENERATED FROM PYTHON SOURCE LINES 31-43 .. code-block:: Python MAPS = {"FUV": "fuv_detection", "NUV": "nuv_detection"} try: maps = {} for band, map_id in MAPS.items(): paths = get_phase_space_map(map_id, ["map", "overlay"]) maps[band] = {key: Table.read(path, format="ascii.ecsv") for key, path in paths.items()} except (ConnectionError, LookupError, OSError, ValueError) as err: maps = None print(f"Skipping this page's analysis, the release data is not available: {err}") .. GENERATED FROM PYTHON SOURCE LINES 44-50 Read the map at every draw --------------------------- The fitted map is on a grid, so the efficiency at a draw is interpolated linearly between the grid points around it in the log luminosity and the log half-decline time. A draw outside the map has no value, and is counted as off the map. .. GENERATED FROM PYTHON SOURCE LINES 50-80 .. code-block:: Python def efficiency_at_draws(grid, measurements): """Return the map's efficiency at each draw of a class, NaN where the draw is off the map or not measured.""" names = grid.colnames[:2] interpolate = LinearNDInterpolator( np.column_stack([grid[names[0]], grid[names[1]]]), np.asarray(grid["efficiency"]) ) efficiency = interpolate(np.asarray(measurements["log_luminosity"]), np.asarray(measurements["log_half_time"])) return np.where(np.asarray(measurements["measured"]), efficiency, np.nan) if maps is not None: rows = {} for band, tables in maps.items(): for measurements in split_measurements(tables["overlay"]): eta = efficiency_at_draws(tables["map"], measurements) on_map = np.isfinite(eta) low, median, high = np.percentile(eta[on_map], [16, 50, 84]) if on_map.any() else (np.nan,) * 3 rows.setdefault(measurements.meta["class"], {})[band] = (median, low, high, on_map.mean()) classes = sorted(rows) print(f"{'class':36s}" + "".join(f"{band + ' eta (16-50-84%)':>34s}{'on map':>9s}" for band in maps)) for name in classes: line = f"{name:36s}" for band in maps: median, low, high, on_map = rows[name][band] line += f"{low:11.2g}{median:11.2g}{high:11.2g}{on_map:9.0%}" print(line) .. rst-class:: sphx-glr-script-out .. code-block:: none class FUV eta (16-50-84%) on map NUV eta (16-50-84%) on map Kilonova 0.00015 0.00022 0.00032 100% 0.00044 0.0007 0.0011 100% LowLuminosityGRB 0.0019 0.0025 0.0034 100% 0.0048 0.0061 0.0077 100% LuminousFastBlueOpticalTransient 0.0041 0.0066 0.011 100% 0.007 0.011 0.018 100% MagnetarSLSNe 0.07 0.092 0.11 100% 0.14 0.16 0.19 100% TidalDisruptionEvent 0.055 0.074 0.099 100% 0.095 0.12 0.16 100% TypeIIPSNe 0.0042 0.0064 0.01 100% 0.012 0.018 0.027 100% TypeIIbSNe 0.00048 0.0012 0.0026 100% 0.0022 0.0052 0.011 100% TypeIaSNe 0.0073 0.0084 0.0098 100% 0.02 0.024 0.029 100% TypeIbSNe 0.0061 0.0099 0.034 96% 0.015 0.022 0.062 100% TypeIcBLSNe 0.0058 0.0083 0.024 100% 0.016 0.025 0.054 100% TypeIcSNe 0.0059 0.021 0.034 97% 0.016 0.044 0.07 100% .. GENERATED FROM PYTHON SOURCE LINES 81-86 The efficiency of each class ----------------------------- The bar is the median over the draws of a class that are on the map, and the whiskers the 16th and 84th percentiles. A class whose draws mostly lie off the map is not shown for that band, because the map does not reach it. .. GENERATED FROM PYTHON SOURCE LINES 86-98 .. code-block:: Python if maps is not None: fig, axes = plt.subplots(1, len(maps), figsize=(11, 5), sharey=True, constrained_layout=True) for ax, band in zip(np.atleast_1d(axes), maps): shown = [name for name in classes if rows[name][band][3] >= 0.5] median, low, high, _ = (np.array([rows[name][band][k] for name in shown]) for k in range(4)) ax.barh(shown, median, color=get_band_color(band), alpha=0.8) ax.errorbar(median, shown, xerr=[median - low, high - median], fmt="none", ecolor="black", capsize=3) ax.set_xscale("log") ax.set_xlabel(rf"all-sky efficiency $\eta$ in the {band}") ax.invert_yaxis() plt.show() .. image-sg:: /report/phase_space/images/sphx_glr_plot_class_efficiencies_001.png :alt: plot class efficiencies :srcset: /report/phase_space/images/sphx_glr_plot_class_efficiencies_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 3.500 seconds) .. _sphx_glr_download_report_phase_space_plot_class_efficiencies.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_class_efficiencies.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_class_efficiencies.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_class_efficiencies.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_