-
Notifications
You must be signed in to change notification settings - Fork 6
/
make.py
executable file
·197 lines (148 loc) · 4.84 KB
/
make.py
1
2
3
4
5
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/usr/bin/env python
"""Command line script to run the analysis.
All results and plot are produced like this:
$ ./make.py all
"""
import os
import logging
from distutils import dir_util
from pathlib import Path
import warnings
import yaml
import click
import matplotlib
# force a non-interactive backend to avoid windows popping up
matplotlib.use("agg")
click.disable_unicode_literals_warning = True
import joint_crab
log = logging.getLogger(__name__)
@click.group()
@click.option(
"--log-level",
default="INFO",
help="Logging verbosity level",
type=click.Choice(["DEBUG", "INFO", "WARNING", "ERROR"]),
)
@click.option("--show-warnings", default=True, help="Show warnings?")
def cli(log_level, show_warnings):
"""Command line tool for this paper.
To run all analyses, type `./make.py all`
"""
logging.basicConfig(level=log_level)
if not show_warnings:
warnings.simplefilter("ignore")
@cli.command(name="all")
@click.pass_context
def cli_all(ctx):
"""Run all steps."""
log.info("Executing task: all")
ctx.invoke(cli_clean)
ctx.invoke(cli_provenance)
ctx.invoke(cli_maps)
ctx.invoke(cli_extract_spectra)
ctx.invoke(cli_fit_spectra)
ctx.invoke(cli_fit_systematics)
ctx.invoke(cli_fit_errorbands)
ctx.invoke(cli_summary_data)
ctx.invoke(cli_summary_results)
ctx.invoke(cli_plot_counts)
ctx.invoke(cli_plot_seds)
ctx.invoke(cli_plot_errorbands)
ctx.invoke(cli_plot_contours)
# copy results from docker container to host
if "DOCKER_INSIDE" in os.environ:
dir_util.copy_tree("results", "host/joint-crab-results")
log.info("Copying results to host.")
@cli.command("clean")
def cli_clean():
"""Clean out results folder."""
log.info("Executing task: clean")
dir_util.remove_tree("results")
Path("results").mkdir()
txt = "# Results\n\nThis folder contains the output of make.py"
Path("results/README.md").write_text(txt)
Path("results/maps").mkdir()
Path("results/spectra").mkdir()
Path("results/fit").mkdir()
Path("results/figures").mkdir()
Path("results/summary").mkdir()
@cli.command("provenance")
def cli_provenance():
"""Write `results/provenance.yaml`."""
log.info("Executing task: provenance")
data = joint_crab.provenance.get_provenance()
filename = "results/provenance.yaml"
log.info(f"Writing {filename}")
with Path(filename).open("w") as fh:
yaml.dump(data, fh, default_flow_style=False)
@cli.command("extract-spectra")
@click.option(
"--dataset",
default="all",
help="Which dataset to process? (default: all)",
type=click.Choice(["fermi", "fact", "magic", "hess", "veritas", "all"]),
)
def cli_extract_spectra(dataset):
"""Extract 1d spectra"""
log.info("Executing task: extract-spectra.")
joint_crab.extract_spectra.main(dataset)
@cli.command("maps")
def cli_maps():
"""Make and plot sky maps."""
log.info("Executing task: maps")
joint_crab.maps.main()
@cli.command("fit-spectra")
@click.option(
"--dataset",
default="all",
help="Which dataset to process? (default: all)",
type=click.Choice(["fermi", "fact", "magic", "hess", "veritas", "joint", "all"]),
)
def cli_fit_spectra(dataset):
"""Execute spectrum fit."""
log.info("Executing task: fit-spectra")
joint_crab.fit_spectra.main(dataset)
@cli.command("fit-systematics")
def cli_fit_systematics():
"""Fit that includes systematics."""
log.info("Executing task: syst-err")
joint_crab.fit_systematics.main()
@cli.command("fit-errorbands")
def cli_fit_errorbands():
"""Compute flux error bands."""
log.info("Executing task: fit-errorbands")
joint_crab.fit_errorbands.main()
@cli.command("summary-data")
def cli_summary_data():
"""Write summary for data."""
log.info("Executing task: summary-data")
joint_crab.summary_data.make_summary_data()
joint_crab.summary_data.make_summary_latex()
@cli.command("summary-results")
def cli_summary_results():
"""Write summary for results."""
log.info("Executing task: summary-results")
joint_crab.summary_results.make_summary_results()
joint_crab.summary_results.make_summary_latex()
@cli.command("plot-counts")
def cli_plot_counts():
"""Plot counts spectra."""
log.info("Executing task: plot-counts")
joint_crab.plot_counts.main()
@cli.command("plot-seds")
def cli_plot_seds():
"""Plot SEDs."""
log.info("Executing task: plot-seds")
joint_crab.plot_seds.main()
@cli.command("plot-errorbands")
def cli_plot_errorbands():
"""Plot SED error bands."""
log.info("Executing task: plot-errorbands")
joint_crab.plot_errorbands.main()
@cli.command("plot-contours")
def cli_plot_contours():
"""Plot contours."""
joint_crab.plot_contours.plot_contours_stat()
joint_crab.plot_contours.plot_contours_systematics()
if __name__ == "__main__":
cli()