macros.jinja2 8.17 KB
 Leo Pound Singer committed Feb 13, 2019 1 2 3 4 ``````Macro to join a list of terms with Oxford commas, as in "one, two, and three." {% macro oxford_commas(seq, conjunction='and') %} {% for item in seq %} `````` Leo Pound Singer committed Feb 27, 2019 5 ``````{% if caller %}{{caller(item)}}{% else %}{{item}}{% endif -%} `````` Leo Pound Singer committed Feb 13, 2019 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 ``````{% if loop.length > 2 and not loop.last %},{% endif %} {% if loop.length > 1 and not loop.last %} {% endif %} {% if loop.length > 1 and loop.revindex == 2 %}{{conjunction}} {% endif %} {% endfor %} {%- endmacro %} Macro to translate a probability between 0 and 100. These thresholds are roughly derived by assuming that we have a binary classification problem, calculating the odds ratio as K=P/(1-P), and using thresholds based on the table of Kass and Raftery (1995, https://doi.org/10.2307%2F2291091). {% macro evidence_for(value) %} {% if 95 <= value %} strong evidence for {%- elif 75 <= value < 95 %} evidence for {%- elif 25 <= value < 75 %} indeterminate evidence for {%- elif 5 <= value < 25 %} evidence against {%- else %} strong evidence against {%- endif %} {%- endmacro %} Macro to render a percentage between 0 and 100, capping at <1% and >99%. {% macro probability(value) %} {% if value > 99 %} >99 {%- elif value < 1 %} <1 {%- else %} {{value|round|int}} {%- endif %} % {%- endmacro %} `````` Brandon Piotrzkowski committed Aug 21, 2019 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 ``````Macro to write Update type in natural-language {% macro naturalupdatetype(update_type) %} {% if 'sky_localization' == update_type|lower %}Sky Localization{% elif 'p_astro' == update_type|lower %}Source Classification {% elif 'em_bright' == update_type|lower %}EM Bright Classification{% endif %} {%- endmacro %} Macro to write Update type subject {% macro naturalupdatesubject(update_types) %} {% if update_types|length == 1 %}{{naturalupdatetype(update_types[0])}} {% elif update_types|length == 2 %}{{naturalupdatetype(update_types[0])}} and {{naturalupdatetype(update_types[1])}} {% elif update_types|length > 2 %} {% for update_type in update_types[:-1] %}{{naturalupdatetype(update_type)}}, {% endfor %}and {{naturalupdatetype(update_types[-1])}}{% endif %} {%- endmacro %} `````` Leo Pound Singer committed Feb 13, 2019 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 ``````Macro to transform a list like ['H1', 'L1', 'V1'] to natural-language list like "H1 (LIGO Hanford Observatory), L1 (LIGO Livingston Observatory), and V1 (Virgo Observatory)". {% macro naturalinstruments(instruments) %} {% set long_instruments = {'H1': 'LIGO Hanford Observatory', 'L1': 'LIGO Livingston Observatory', 'V1': 'Virgo Observatory'} %} {% call(instrument) oxford_commas(instruments) %} {% if instrument in long_instruments %} {{long_instruments[instrument]}} ({{instrument}}) {%- else %} {{instrument}} {%- endif %} {%- endcall %} {%- endmacro %} `````` Min-A Cho committed Apr 08, 2019 82 83 ``````{% set skymapcitationnumber = namespace(count=0) %} `````` Leo Pound Singer committed May 28, 2019 84 ``````Macro to cite sky maps. Since citations are enumerated, the citation number must start with `````` Min-A Cho committed Apr 08, 2019 85 86 87 88 89 90 91 92 93 94 95 96 97 ``````number of all GW analysis pipelines + 1. {% macro citeskymap(skymappipeline, all_pipelines, skymaps) %} {% set skymapcitationnumber.count = 0 %} {% for skymap in skymaps %} {% if skymap.pipeline|lower in skymapcitations %}{% set skymapcitationnumber.count = skymapcitationnumber.count + 1 %}{% endif %} {% if skymap.pipeline == skymappipeline %}{% break %}{% endif %} {% endfor %} {{skymappipeline}}{% if skymappipeline|lower in skymapcitations %} [{{ all_pipelines|length + skymapcitationnumber.count }}] {%- endif -%} {%- endmacro %} `````` Brandon Piotrzkowski committed Aug 21, 2019 98 99 100 101 102 103 104 105 106 107 108 109 110 ``````Macro to simply write the citation number of a skymap in brackets. {% macro citeskymap_number(skymappipeline, all_pipelines, skymaps) %} {% set skymapcitationnumber.count = 0 %} {% for skymap in skymaps %} {% if skymap.pipeline|lower in skymapcitations %}{% set skymapcitationnumber.count = skymapcitationnumber.count + 1 %}{% endif %} {% if skymap.pipeline == skymappipeline %}{% break %}{% endif %} {% endfor %} {% if skymappipeline|lower in skymapcitations %}[{{ all_pipelines|length + skymapcitationnumber.count }}] {%- endif -%} {%- endmacro %} `````` Min-A Cho committed Feb 24, 2019 111 ``````Macro to transform a list of other GW analysis pipelines like ['gstlal', 'mbtaonline', 'pycbc'] `````` Min-A Cho committed Mar 20, 2019 112 113 ``````to a natural-language list like "gstlal [2], mbtaonline [3], and pycbc [4]". `````` Brandon Piotrzkowski committed Apr 09, 2019 114 115 ``````{% macro naturalotherpipelines(preferred_pipeline, other_pipelines, conjunction='and') %} {% for pipeline in [preferred_pipeline] + other_pipelines %} `````` Peter Shawhan committed May 22, 2019 116 ``````{% if 'pycbc' == pipeline|lower %}PyCBC Live{% elif 'gstlal' == pipeline|lower %}GstLAL{% elif 'spiir' == pipeline|lower %}SPIIR{% else %}{{pipeline}}{% endif %} [{{loop.index}}] `````` Min-A Cho committed Mar 20, 2019 117 118 119 120 121 ``````{%- if loop.length > 2 and not loop.last %},{% endif %} {%- if loop.length > 1 and not loop.last %} {% endif %} {%- if loop.length > 1 and loop.revindex == 2 %}{{conjunction}} {% endif %} {% endfor %} {%- endmacro %} `````` Min-A Cho committed Feb 24, 2019 122 `````` `````` Min-A Cho committed Mar 20, 2019 123 124 `````` Macro to enumerate and cite all GW analysis pipelines involved for the superevent; including the `````` Min-A Cho committed Apr 08, 2019 125 ``````skymap pipelines. `````` Min-A Cho committed Mar 20, 2019 126 `````` `````` Min-A Cho committed Apr 08, 2019 127 ``````{%- macro citenumberedpipelines(all_pipelines, skymaps) -%} `````` Min-A Cho committed Mar 20, 2019 128 ``````{% for pipeline in all_pipelines %} `````` Min-A Cho committed Apr 10, 2019 129 130 131 132 133 ``````{% if pipeline == 'Burst'%} [{{loop.index}}] {{citations['xpipeline']}} {% elif pipeline == 'CBC'%} [{{loop.index}}] {{citations['pygrb']}} {% else %} `````` Min-A Cho committed Mar 20, 2019 134 `````` [{{loop.index}}] {{citations[pipeline|lower]}} `````` Min-A Cho committed Apr 10, 2019 135 ``````{% endif %} `````` Min-A Cho committed Mar 20, 2019 136 ``````{% endfor %} `````` Min-A Cho committed Apr 08, 2019 137 138 139 140 141 142 ``````{% set skymapcitationnumber.count = 0 %} {% for skymap in skymaps %} {% if skymap.pipeline|lower in skymapcitations %} {% set skymapcitationnumber.count = skymapcitationnumber.count + 1 %} [{{ all_pipelines|length + skymapcitationnumber.count }}] {{skymapcitations[skymap.pipeline|lower]}} {% endif %} {% endfor %} `````` Min-A Cho committed Feb 24, 2019 143 144 145 ``````{%- endmacro -%} `````` Min-A Cho committed Mar 07, 2019 146 ``````Macro to transform a list of GRB-GW exclusions/detections like ['CBC', 'Burst'] to a natural-language `````` Min-A Cho committed Apr 10, 2019 147 ``````list like "triggered CBC pipeline (PyGRB) [1] and triggered Burst pipeline (X-Pipeline) [2]". `````` Min-A Cho committed Mar 07, 2019 148 149 `````` {%- macro naturalgrbmediumlatencypipelines(somelist) -%} `````` Min-A Cho committed Apr 10, 2019 150 ``````{% for item in somelist %} `````` Min-A Cho committed Apr 10, 2019 151 ``````{% if item == 'Burst' %}X-Pipeline GRB-unmodeled transient analysis{% else %}PyGRB binary merger analysis{% endif %} [{{loop.index}}] `````` Min-A Cho committed Apr 10, 2019 152 153 154 155 ``````{%- if loop.length > 1 and not loop.last %} {% endif %} {%- if loop.length > 1 and loop.revindex == 2 %}and {% endif %} {% endfor %} {%- endmacro %} `````` Min-A Cho committed Mar 07, 2019 156 157 `````` `````` Brandon Piotrzkowski committed Apr 02, 2019 158 159 160 161 162 163 164 ``````Macro to round FAPs to single decimal place {% macro naturalfap(fap) %} {{'%.1e'|format(fap)}} {%- endmacro %} `````` Leo Pound Singer committed Feb 13, 2019 165 166 167 ``````Macro to format FARs using natural-language time, capped at 1/100 years. {% macro naturalfar(far) %} `````` Leo Pound Singer committed Apr 12, 2019 168 169 170 ``````{{'%.2g'|format(far)}} Hz, or about one in {% if far * 365 * 86400 * 100 > 1 %} {{(1 / far)|naturaldelta}} `````` Leo Pound Singer committed Feb 13, 2019 171 ``````{%- else %} `````` Leo Pound Singer committed Apr 12, 2019 172 ``````1e{{(1 / (365 * 86400 * far))|log10|round|int}} years `````` Leo Pound Singer committed Feb 13, 2019 173 174 175 176 ``````{%- endif %} {%- endmacro %} `````` Leo Pound Singer committed Feb 20, 2019 177 178 ``````Macro to format a dictionary of source classifications as a natural-language list, sorted by descending probability. `````` Leo Pound Singer committed Feb 13, 2019 179 180 `````` {% macro naturalclassifications(classifications) %} `````` Leo Pound Singer committed Feb 20, 2019 181 182 183 ``````{% set items = classifications|dictsort(by='value', reverse=True) %} {% call(item) oxford_commas(items, 'or') %} {% if item[0] == 'Terr' %} `````` Leo Pound Singer committed Feb 13, 2019 184 185 ``````terrestrial {%- else %} `````` Leo Pound Singer committed Feb 20, 2019 186 187 ``````{{item[0]}} {%- endif %} ({{probability(item[1])}}) `````` Leo Pound Singer committed Feb 13, 2019 188 189 190 191 ``````{%- endcall %} {%- endmacro %} `````` Min-A Cho committed Feb 24, 2019 192 193 194 195 ``````Macro to replace jargon terms CBC and Burst. {%- macro renamegroup(group) -%} {%- if group|lower == 'cbc' -%} `````` Brandon Piotrzkowski committed Apr 09, 2019 196 ``````compact binary merger `````` Min-A Cho committed Feb 24, 2019 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 ``````{%- elif group|lower == 'burst' -%} unmodeled transient {%- else -%} {{group}} {%- endif -%} {%- endmacro -%} Macro to include which mission reported the GRB. {%- macro grbmission(external_pipeline) -%} {%- if external_pipeline|lower == 'fermi' -%} Fermi GBM {%- elif external_pipeline|lower == 'swift' -%} Swift BAT {%- else -%} {{external_pipeline}} {%- endif -%} {%- endmacro -%} Macro to include the word `trigger' or not when referring to external_trigger. {%- macro propername(external_trigger) -%} {%- if 'grb' in external_trigger|lower -%} {{external_trigger}} {%- else -%} trigger with ID {{external_trigger}} {%- endif -%} {%- endmacro -%} `````` Leo Pound Singer committed Feb 13, 2019 229 230 ``````Dictionary of common citations. `````` Min-A Cho committed Apr 08, 2019 231 ``````{% set citations = {'pycbc': 'Nitz et al. PRD 98, 024050 (2018)', `````` Leo Pound Singer committed Feb 13, 2019 232 233 `````` 'mbtaonline': 'Adams et al. CQG 33, 175012 (2016)', 'gstlal': 'Messick et al. PRD 95, 042001 (2017)', `````` Peter Shawhan committed Apr 26, 2019 234 `````` 'spiir': 'Qi Chu, PhD Thesis, The University of Western Australia (2017)', `````` Leo Pound Singer committed Feb 13, 2019 235 `````` 'cwb': 'Klimenko et al. PRD 93, 042004 (2016)', `````` Min-A Cho committed Apr 10, 2019 236 237 238 `````` 'olib': 'Lynch et al. PRD 95, 104046 (2017)', 'pygrb': 'Williamson et al. PRD 90, 122004 (2014)', 'xpipeline': 'Was et al. PRD 86, 022003 (2012)'} %} `````` Min-A Cho committed Apr 08, 2019 239 240 `````` `````` Leo Pound Singer committed May 28, 2019 241 ``````Dictionary of sky map citations. `````` Min-A Cho committed Apr 08, 2019 242 `````` `````` Min-A Cho committed Apr 08, 2019 243 ``````{% set skymapcitations = {'bayestar': 'Singer & Price PRD 93, 024013 (2016)', `````` Min-A Cho committed Apr 08, 2019 244 `` 'lalinference': 'Veitch et al. PRD 91, 042003 (2015)'} %}``