-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_sims.py
239 lines (213 loc) · 9.3 KB
/
run_sims.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
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
229
230
231
232
233
234
235
236
237
238
239
#!/usr/bin/env python
#copied directly from https://github.com/beckermr/misc/blob/68b42ea226913b97236ce5145378c6cf6fe05b8b/bin/run-simple-des-y3-sim
import logging
import sys
import click
import yaml
from band_infoing import make_band_info
from simulating import End2EndSimulation
from coadding import MakeSwarpCoadds
from srcextracting import MakeSrcExtractorCat
from true_detecting import make_true_detections
from medsing import make_meds_files
from run_metacal import run_metacal
from finalizing import finalize_files
from initializing import initialize_files
for lib in ['matts_misc.simple_des_y3_sims']:
lgr = logging.getLogger(lib)
hdr = logging.StreamHandler(sys.stdout)
hdr.setFormatter(logging.Formatter(logging.BASIC_FORMAT))
lgr.setLevel(logging.DEBUG)
lgr.addHandler(hdr)
@click.group()
def cli():
"""Run simple DES Y3 end-to-emd simulations."""
pass
@cli.command()
@click.option('--tilename', type=str, required=True,
help='the coadd tile to simulate')
@click.option('--bands', type=str, required=True,
help=('a list of bands to simulate as '
'a concatnated string (e.g., "riz")'))
@click.option('--output-desdata', type=str, required=True,
help='the output DESDATA directory')
@click.option('--config-file', type=str, required=True,
help='the YAML config file')
def initialize(tilename, bands, output_desdata, config_file):
with open(config_file, 'r') as fp:
config = yaml.load(fp, Loader=yaml.Loader)
initialize_files(
tilename=tilename,
bands=[b for b in bands],
output_desdata=output_desdata,
config=config)
@cli.command()
@click.option('--tilename', type=str, required=True,
help='the coadd tile to simulate')
@click.option('--bands', type=str, required=True,
help=('a list of bands to prep for as '
'a concatnated string (e.g., "riz")'))
@click.option('--output-desdata', type=str, required=True,
help='the output DESDATA directory')
@click.option('--n-files', type=int, default=None,
help='number of SE images to keep - useful for testing')
@click.option('--config-file', type=str, required=True,
help='the YAML config file')
def prep(tilename, bands, output_desdata, n_files, config_file):
"""Prepare a tile for simulating."""
with open(config_file, 'r') as fp:
config = yaml.load(fp, Loader=yaml.Loader)
make_band_info(
tilename=tilename,
bands=[b for b in bands],
output_meds_dir=output_desdata,
config=config['survey_kws'],
n_files=n_files)
@cli.command()
@click.option('--tilename', type=str, required=True,
help='the coadd tile to simulate')
@click.option('--bands', type=str, required=True,
help=('a list of bands to simulate as '
'a concatnated string (e.g., "riz")'))
@click.option('--output-desdata', type=str, required=True,
help='the output DESDATA directory')
@click.option('--seed', type=int, required=True,
help='the base RNG seed')
@click.option('--config-file', type=str, required=True,
help='the YAML config file')
def galsim(tilename, bands, output_desdata, seed, config_file):
with open(config_file, 'r') as fp:
config = yaml.load(fp, Loader=yaml.Loader)
sim = End2EndSimulation(
seed=seed,
output_meds_dir=output_desdata,
tilename=tilename,
bands=[b for b in bands],
gal_kws=config['gal_kws'],
star_kws=config['star_kws'],
psf_kws=config['psf_kws'])
sim.run()
@cli.command('true-detection')
@click.option('--tilename', type=str, required=True,
help='the coadd tile to simulate')
@click.option('--bands', type=str, required=True,
help=('a list of bands to run detection for as '
'a concatnated string (e.g., "riz")'))
@click.option('--output-desdata', type=str, required=True,
help='the output DESDATA directory')
@click.option('--config-file', type=str, required=True,
help='the YAML config file')
def true_detection(tilename, bands, output_desdata, config_file):
with open(config_file, 'r') as fp:
config = yaml.load(fp, Loader=yaml.Loader)
if config['gal_kws']['truth_type'] in ['grid-truedet', 'random-truedet']:
make_true_detections(
tilename=tilename,
bands=[b for b in bands],
output_meds_dir=output_desdata,
box_size=config['true_detection']['box_size'],
config = config)
@cli.command('swarp')
@click.option('--tilename', type=str, required=True,
help='the coadd tile to simulate')
@click.option('--bands', type=str, required=True,
help=('a list of bands to prep for as '
'a concatnated string (e.g., "riz")'))
@click.option('--output-desdata', type=str, required=True,
help='the output DESDATA directory')
@click.option('--config-file', type=str, required=True,
help='the YAML config file')
def swarp(tilename, bands, output_desdata, config_file):
with open(config_file, 'r') as fp:
config = yaml.load(fp, Loader=yaml.Loader)
if config['gal_kws']['truth_type'] not in ['grid-truedet', 'random-truedet']:
coadd = MakeSwarpCoadds(
output_meds_dir=output_desdata,
tilename=tilename,
bands=[b for b in bands],
config=config)
coadd.run()
@cli.command('source-extractor')
@click.option('--tilename', type=str, required=True,
help='the coadd tile to simulate')
@click.option('--bands', type=str, required=True,
help=('a list of bands to prep for as '
'a concatnated string (e.g., "riz")'))
@click.option('--output-desdata', type=str, required=True,
help='the output DESDATA directory')
@click.option('--config-file', type=str, required=True,
help='the YAML config file')
def source_extractor(tilename, bands, output_desdata, config_file):
with open(config_file, 'r') as fp:
config = yaml.load(fp, Loader=yaml.Loader)
if config['gal_kws']['truth_type'] not in ['grid-truedet', 'random-truedet']:
SrcExtractor = MakeSrcExtractorCat(
output_meds_dir=output_desdata,
tilename=tilename,
bands=[b for b in bands],
config=config)
SrcExtractor.run()
@cli.command()
@click.option('--tilename', type=str, required=True,
help='the coadd tile to simulate')
@click.option('--bands', type=str, required=True,
help=('a list of bands to make MEDS files for as '
'a concatnated string (e.g., "riz")'))
@click.option('--output-desdata', type=str, required=True,
help='the output DESDATA directory')
@click.option('--config-file', type=str, required=True,
help='the YAML config file')
@click.option('--meds-config-file', type=str, required=True,
help='the YAML config file for MEDS making')
def meds(tilename, bands, output_desdata, config_file, meds_config_file):
with open(config_file, 'r') as fp:
config = yaml.load(fp, Loader=yaml.Loader)
with open(meds_config_file, 'r') as fp:
meds_config = yaml.load(fp, Loader=yaml.Loader)
make_meds_files(
tilename=tilename,
bands=[b for b in bands],
output_meds_dir=output_desdata,
psf_kws=config['psf_kws'],
meds_config=meds_config)
@cli.command()
@click.option('--tilename', type=str, required=True,
help='the coadd tile to simulate')
@click.option('--bands', type=str, required=True,
help=('a list of bands to simulate as '
'a concatnated string (e.g., "riz")'))
@click.option('--output-desdata', type=str, required=True,
help='the output DESDATA directory')
@click.option('--seed', type=int, required=True,
help='the base RNG seed')
@click.option('--metacal-config-file', type=str, required=True,
help='the YAML config file for metacal run')
def metacal(tilename, bands, output_desdata, seed, metacal_config_file):
with open(metacal_config_file, 'r') as fp:
mcal_config = yaml.load(fp, Loader=yaml.Loader)
run_metacal(
tilename=tilename,
output_meds_dir=output_desdata,
bands=[b for b in bands],
seed=seed,
mcal_config=mcal_config)
@cli.command()
@click.option('--tilename', type=str, required=True,
help='the coadd tile to simulate')
@click.option('--bands', type=str, required=True,
help=('a list of bands to simulate as '
'a concatnated string (e.g., "riz")'))
@click.option('--output-desdata', type=str, required=True,
help='the output DESDATA directory')
@click.option('--config-file', type=str, required=True,
help='the YAML config file')
def finalize(tilename, bands, output_desdata, config_file):
with open(config_file, 'r') as fp:
config = yaml.load(fp, Loader=yaml.Loader)
finalize_files(
tilename=tilename,
bands=[b for b in bands],
output_desdata=output_desdata,
config=config)
if __name__ == '__main__':
cli()