-
Notifications
You must be signed in to change notification settings - Fork 0
/
band_infoing.py
93 lines (77 loc) · 2.74 KB
/
band_infoing.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
import logging
import hashlib
import numpy as np
import yaml
import desmeds
from constants import MEDSCONF, PIFF_RUN
from files import (
get_band_info_file,
make_dirs_for_file)
from des_info import add_extra_des_coadd_tile_info
logger = logging.getLogger(__name__)
def make_band_info(*, tilename, bands, output_meds_dir, config, n_files=None):
"""Make YAML files with the information on each band.
Parameters
----------
tilename : str
The DES coadd tilename (e.g., 'DES2122+0001').
bands : list of str
A list of bands to process (e.g., `['r', 'i', 'z']`).
output_meds_dir : str
The DESDATA/MEDS_DIR path where the info file should be written.
n_files : int, optional
If not `None`, then only keep this many files for the sources. Useful
for testing.
Returns
-------
info : dict
A dictionary mapping the band name to the info file. Note that these
paths are relative to the environment variable '$MEDS_DIR' in the
returned file path. Replace this with `output_meds_dir` to read
the file.
"""
logger.info(' processing coadd tile %s', tilename)
cfg = {
'source_type': 'finalcut',
'piff_run': PIFF_RUN,
'medsconf': MEDSCONF
}
if config['name'] == 'DES':
cfg['campaign'] = 'Y3A1_COADD'
elif config['name'] == 'DECADE':
cfg['campaign'] = 'DR3_1'
fnames = {}
for band in bands:
band_info_file = get_band_info_file(
meds_dir=output_meds_dir,
medsconf=cfg['medsconf'],
tilename=tilename,
band=band)
prep = desmeds.desdm_maker.Preparator(
cfg,
tilename,
band,
)
prep.coadd["piff_campaign"] = None
if prep.coadd.sources is not None:
prep.coadd.sources["piff_campaign"] = None
prep.go()
info = prep.coadd.get_info()
add_extra_des_coadd_tile_info(info=info, piff_run=cfg['piff_run'])
# build hashes and sort
hashes = []
for i in range(len(info['src_info'])):
hash_str = "%s%s" % (
info['src_info'][i]['expnum'],
info['src_info'][i]['ccdnum'])
hashes.append(hashlib.md5(hash_str.encode('utf-8')).hexdigest())
inds = np.argsort(hashes)
new_src_info = [info['src_info'][i] for i in inds]
info['src_info'] = new_src_info
if n_files is not None:
info['src_info'] = info['src_info'][:n_files]
make_dirs_for_file(band_info_file)
with open(band_info_file, 'w') as fp:
yaml.dump(info, fp)
fnames[band] = band_info_file.replace(output_meds_dir, '$MEDS_DIR')
return fnames