forked from legacysurvey/imagine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
load-layer.py
166 lines (128 loc) · 5.3 KB
/
load-layer.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
from __future__ import print_function
import os
from glob import glob
import numpy as np
from astrometry.util.file import read_file, write_file
from legacypipe.survey import LegacySurveyData
def main():
# indir = '/global/cscratch1/sd/dstn/dr8test-1'
# name = 'dr8-test1'
# pretty = 'DR8 test1'
# indir = '/scratch1/scratchdirs/desiproc/dr8test002/'
# name = 'dr8-test2'
# pretty = 'DR8 test2 (outliers)'
# indir = '/scratch1/scratchdirs/desiproc/dr8test003/'
# name = 'dr8-test3'
# pretty = 'DR8 test3 (outliers)'
#
# indir = '/scratch1/scratchdirs/desiproc/dr8test004/'
# name = 'dr8-test4'
# pretty = 'DR8 test4 (large-galaxies)'
# indir = '/global/cscratch1/sd/dstn/dr8test005/'
# name = 'dr8-test5'
# pretty = 'DR8 test5 (trident)'
# indir = '/global/cscratch1/sd/dstn/dr8test006/'
# name = 'dr8-test6'
# pretty = 'DR8 test6 (sky)'
# indir = '/global/cscratch1/sd/dstn/dr8test007/'
# name = 'dr8-test7'
# pretty = 'DR8 test7 (outliers)'
#indir = '/global/cscratch1/sd/dstn/dr8test14/'
#name = 'dr8-test14'
#pretty = 'DR8 test14 (rc)'
#indir = '/global/project/projectdirs/cosmo/work/legacysurvey/dr8a/'
#name = 'dr8a'
#pretty = 'DR8a (rc)'
if False:
indir = '/global/project/projectdirs/cosmo/work/legacysurvey/dr8b/runbrick-decam/'
name = 'dr8b-decam'
pretty = 'DR8b DECam'
survey_dir = '/global/project/projectdirs/cosmo/work/legacysurvey/dr8b/runbrick-decam'
if True:
indir = '/global/project/projectdirs/cosmo/work/legacysurvey/dr8b/runbrick-90prime-mosaic/'
name = 'dr8b-90p-mos'
pretty = 'DR8b BASS+MzLS'
survey_dir = '/global/project/projectdirs/cosmo/work/legacysurvey/dr8b/runbrick-90prime-mosaic'
# ln -s /global/project/projectdirs/cosmo/work/legacysurvey/dr8b/runbrick-decam/coadds-only/coadd/ .
sublayers = ['', '-model', '-resid']
subpretty = {'':' images', '-model':' models', '-resid':' residuals'}
# survey_dir = '/global/cscratch1/sd/desiproc/dr7'
# sublayers = ['']
# subpretty = {'':' images'}
#survey_dir = '/global/cscratch1/sd/dstn/dr8-depthcut'
#survey_dir = '/global/project/projectdirs/cosmo/work/legacysurvey/dr8a/'
rsync = False
datadir = 'data'
survey = LegacySurveyData(survey_dir=survey_dir)
fn = 'map/test_layers.py'
txt = open(fn).read()
for x in sublayers:
txt = txt + '\n' + 'test_layers.append(("%s%s", "%s%s"))\n' % (name, x, pretty, subpretty[x])
open(fn, 'wb').write(txt.encode())
print('Wrote', fn)
basedir = os.path.join(datadir, name)
if rsync:
cmd = 'rsync -LRarv %s/./{coadd/*/*/*-{image-,model-,ccds}*.fits*,tractor} %s/%s' % (indir, datadir, name)
print(cmd)
os.system(cmd)
# ...?
cmd = 'rsync -Rarv %s/./{images,survey-ccds*.fits} %s/%s' % (survey_dir, datadir, name)
print(cmd)
os.system(cmd)
else:
# symlink
if os.path.exists(basedir):
print('Not symlinking', indir, 'to', basedir, ': already exists!')
else:
os.makedirs(basedir)
for subdir in ['coadd', 'tractor']:
os.symlink(os.path.join(indir, subdir), os.path.join(basedir, subdir), target_is_directory=True)
for fn in ['images', 'calib']:
os.symlink(os.path.join(indir, subdir), os.path.join(basedir, subdir), target_is_directory=False)
for pat in ['survey-ccds-*']:
for fn in [os.path.basename(f) for f in glob(os.path.join(indir, pat))]:
os.symlink(os.path.join(indir, subdir), os.path.join(basedir, subdir), target_is_directory=False)
allbricks = survey.get_bricks_readonly()
imagefns = glob(os.path.join(basedir, 'coadd', '*', '*', '*-image-*.fits*'))
extraimagefns = glob(os.path.join(basedir, 'extra-images', 'coadd', '*', '*', '*-image-*.fits*'))
print('Image filenames:', len(imagefns), 'plus', len(extraimagefns), 'extras')
imagefns += extraimagefns
brickset = set()
for fn in imagefns:
dirs = fn.split('/')
brickname = dirs[-2]
brickset.add(brickname)
print(len(brickset), 'bricks found')
I, = np.nonzero([b in brickset for b in allbricks.brickname])
bricks = allbricks[I]
brickfn = os.path.join(basedir, 'survey-bricks.fits.gz')
bricks.writeto(brickfn)
print('Wrote', brickfn)
threads = 8
tharg = '--threads %i ' % threads
#tharg = ''
for x in sublayers:
cmd = 'python -u render-tiles.py --kind %s%s --bricks' % (name, x)
print(cmd)
os.system(cmd)
# images
for scale in range(1,8):
cmd = 'python -u render-tiles.py --kind %s --scale --zoom %i %s' % (name, scale, tharg)
print(cmd)
os.system(cmd)
# models
for scale in range(1,8):
cmd = 'python -u render-tiles.py --kind %s-model --scale --zoom %i %s' % (name, scale, tharg)
print(cmd)
os.system(cmd)
# resids
for scale in range(1,8):
cmd = 'python -u render-tiles.py --kind %s-resid --scale --zoom %i %s' % (name, scale, tharg)
print(cmd)
os.system(cmd)
for x in sublayers:
cmd = 'python -u render-tiles.py --kind %s%s --top' % (name, x)
print(cmd)
os.system(cmd)
if __name__ == '__main__':
main()