macros.jinja2 8.17 KB
Newer Older
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 %}
5
{% if caller %}{{caller(item)}}{% else %}{{item}}{% endif -%}
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 %}


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 %}


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's avatar
Min-A Cho committed
82 83
{% set skymapcitationnumber = namespace(count=0) %}

84
Macro to cite sky maps. Since citations are enumerated, the citation number must start with
Min-A Cho's avatar
Min-A Cho committed
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 %}


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 %}


111
Macro to transform a list of other GW analysis pipelines like ['gstlal', 'mbtaonline', 'pycbc']
Min-A Cho's avatar
Min-A Cho committed
112 113
to a natural-language list like "gstlal [2], mbtaonline [3], and pycbc [4]".

114 115
{% macro naturalotherpipelines(preferred_pipeline, other_pipelines, conjunction='and') %}
{% for pipeline in [preferred_pipeline] + other_pipelines %}
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's avatar
Min-A Cho committed
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 %}
122

Min-A Cho's avatar
Min-A Cho committed
123 124

Macro to enumerate and cite all GW analysis pipelines involved for the superevent; including the
Min-A Cho's avatar
Min-A Cho committed
125
skymap pipelines.
Min-A Cho's avatar
Min-A Cho committed
126

Min-A Cho's avatar
Min-A Cho committed
127
{%- macro citenumberedpipelines(all_pipelines, skymaps) -%}
Min-A Cho's avatar
Min-A Cho committed
128
{% for pipeline in all_pipelines %}
129 130 131 132 133
{% if pipeline == 'Burst'%}
 [{{loop.index}}] {{citations['xpipeline']}}
{% elif pipeline == 'CBC'%}
 [{{loop.index}}] {{citations['pygrb']}}
{% else %}
Min-A Cho's avatar
Min-A Cho committed
134
 [{{loop.index}}] {{citations[pipeline|lower]}}
135
{% endif %}
Min-A Cho's avatar
Min-A Cho committed
136
{% endfor %}
Min-A Cho's avatar
Min-A Cho committed
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 %}
143 144 145
{%- endmacro -%}


146
Macro to transform a list of GRB-GW exclusions/detections like ['CBC', 'Burst'] to a natural-language
147
list like "triggered CBC pipeline (PyGRB) [1] and triggered Burst pipeline (X-Pipeline) [2]".
148 149

{%- macro naturalgrbmediumlatencypipelines(somelist) -%}
150
{% for item in somelist %}
Min-A Cho's avatar
Min-A Cho committed
151
{% if item == 'Burst' %}X-Pipeline GRB-unmodeled transient analysis{% else %}PyGRB binary merger analysis{% endif %} [{{loop.index}}]
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 %}
156 157


158 159 160 161 162 163 164
Macro to round FAPs to single decimal place

{% macro naturalfap(fap) %}
{{'%.1e'|format(fap)}}
{%- endmacro %}


165 166 167
Macro to format FARs using natural-language time, capped at 1/100 years.

{% macro naturalfar(far) %}
168 169 170
{{'%.2g'|format(far)}} Hz, or about one in
{% if far * 365 * 86400 * 100 > 1 %}
{{(1 / far)|naturaldelta}}
171
{%- else %}
172
1e{{(1 / (365 * 86400 * far))|log10|round|int}} years
173 174 175 176
{%- endif %}
{%- endmacro %}


177 178
Macro to format a dictionary of source classifications as a natural-language
list, sorted by descending probability.
179 180

{% macro naturalclassifications(classifications) %}
181 182 183
{% set items = classifications|dictsort(by='value', reverse=True) %}
{% call(item) oxford_commas(items, 'or') %}
{% if item[0] == 'Terr' %}
184 185
terrestrial
{%- else %}
186 187
{{item[0]}}
{%- endif %} ({{probability(item[1])}})
188 189 190 191
{%- endcall %}
{%- endmacro %}


192 193 194 195
Macro to replace jargon terms CBC and Burst.

{%- macro renamegroup(group) -%}
{%- if group|lower == 'cbc' -%}
196
compact binary merger
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 -%}


229 230
Dictionary of common citations.

231
{% set citations = {'pycbc': 'Nitz et al. PRD 98, 024050 (2018)',
232 233
                    'mbtaonline': 'Adams et al. CQG 33, 175012 (2016)',
                    'gstlal': 'Messick et al. PRD 95, 042001 (2017)',
234
                    'spiir': 'Qi Chu, PhD Thesis, The University of Western Australia (2017)',
235
                    'cwb': 'Klimenko et al. PRD 93, 042004 (2016)',
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's avatar
Min-A Cho committed
239 240


241
Dictionary of sky map citations.
Min-A Cho's avatar
Min-A Cho committed
242

243
{% set skymapcitations = {'bayestar': 'Singer & Price PRD 93, 024013 (2016)',
Min-A Cho's avatar
Min-A Cho committed
244
                          'lalinference': 'Veitch et al. PRD 91, 042003 (2015)'} %}