-
Notifications
You must be signed in to change notification settings - Fork 11
/
render-tiles.py
1381 lines (1178 loc) · 48.9 KB
/
render-tiles.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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from __future__ import print_function
import os
import sys
from glob import glob
import numpy as np
#sys.path.insert(0, 'django-1.9')
import django
os.environ['DJANGO_SETTINGS_MODULE'] = 'viewer.settings'
from viewer import settings
settings.READ_ONLY_BASEDIR = False
#settings.DEBUG_LOGGING = True
from map.views import *
from astrometry.util.multiproc import *
from astrometry.util.fits import *
from astrometry.libkd.spherematch import *
import logging
#lvl = logging.DEBUG
lvl = logging.INFO
logging.basicConfig(level=lvl, format='%(message)s', stream=sys.stdout)
class duck(object):
pass
req = duck()
req.META = dict(HTTP_IF_MODIFIED_SINCE=None)
req.GET = dict()
version = 1
def get_version(kind):
return 1
def _one_tile(X):
(kind, zoom, x, y, ignore, get_images) = X
kwargs = dict(ignoreCached=ignore,
get_images=get_images)
print()
print('one_tile: zoom', zoom, 'x,y', x,y)
v = version
# forcecache=False, return_if_not_found=True)
if kind == 'sdss':
print('Zoom', zoom, 'x,y', x,y)
v = 1
layer = get_layer('sdssco')
return layer.get_tile(req, v, zoom, x, y, savecache=True, forcecache=True,
**kwargs)
elif kind == 'sdss2':
v = 1
layer = get_layer(kind)
return layer.get_tile(req, v, zoom, x, y, savecache=True, forcecache=True,
**kwargs)
elif kind == 'ps1':
print('Zoom', zoom, 'x,y', x,y)
from map import views
get_tile = views.get_tile_view('ps1')
get_tile(req, version, zoom, x, y, savecache=True,
return_if_not_found=True)
elif kind in ['decals-dr5', 'decals-dr5-model', 'decals-dr5-resid',
'mzl1s+bass-dr6', 'mzls+bass-dr6-model', 'mzls+bass-dr6-resid']:
v = 1
layer = get_layer(kind)
return layer.get_tile(req, v, zoom, x, y, savecache=True, forcecache=True,
**kwargs)
elif kind in ['eboss']:
v = 1
layer = get_layer(kind)
return layer.get_tile(req, v, zoom, x, y, savecache=True, forcecache=True,
**kwargs)
elif kind in ['decaps2', 'decaps2-model', 'decaps2-resid']:
v = 2
# layer = get_layer(kind)
# print('kind', kind, 'zoom', zoom, 'x,y', x,y)
# return layer.get_tile(req, v, zoom, x, y, savecache=True, forcecache=True,
# get_images=get_images, ignoreCached=True)
elif kind == 'sfd':
v = 2
layer = sfd_layer
layer.get_tile(req, v, zoom, x, y, savecache=True)
#map_sfd(req, version, zoom, x, y, savecache=True)
elif kind == 'halpha':
map_halpha(req, version, zoom, x, y, savecache=True)
elif kind == 'unwise':
map_unwise_w1w2(req, version, zoom, x, y, savecache=True,
ignoreCached=ignore)
print('unWISE zoom', zoom, 'x,y', x,y)
elif kind in ['unwise-neo2', 'unwise-neo3']:
from map import views
view = views.get_tile_view(kind)
return view(req, version, zoom, x, y, savecache=True, **kwargs)
from map import views
view = views.get_tile_view(kind)
return view(req, v, zoom, x, y, savecache=True, **kwargs)
def _bounce_one_tile(*args):
try:
_one_tile(*args)
except KeyboardInterrupt:
raise
except:
print('Error in _one_tile(', args, '):')
import traceback
traceback.print_exc()
def _bounce_map_unwise_w1w2(args):
return map_unwise_w1w2(*args, ignoreCached=True, get_images=True)
def _bounce_map_unwise_w3w4(args):
return map_unwise_w3w4(*args, ignoreCached=True, get_images=True)
def _bounce_sdssco(X):
(args,kwargs) = X
(req,ver,zoom,x,y) = args
fn = 'top-sdss-%i-%i-%i.fits' % (zoom, x, y)
save = False
if os.path.exists(fn):
img = fitsio.read(fn)
print('Read', img.shape)
H,W,planes = img.shape
ims = [img[:,:,i] for i in range(planes)]
else:
#ims = map_sdss(*args, ignoreCached=True, get_images=True, **kwargs)
ims = map_sdssco(*args, ignoreCached=True, get_images=True,
hack_jpeg=True, **kwargs)
if ims is None:
return ims
save = True
# Save jpeg
#tag = 'sdss'
tag = 'sdssco'
pat = os.path.join(settings.DATA_DIR, 'tiles', tag, '%(ver)s',
'%(zoom)i', '%(x)i', '%(y)i.jpg')
tilefn = pat % dict(ver=1, zoom=zoom, x=x, y=y)
if not os.path.exists(tilefn):
bands = 'gri'
rgb = sdss_rgb(ims, bands)
trymakedirs(tilefn)
save_jpeg(tilefn, rgb)
print('Wrote', tilefn)
# Save FITS
if save:
d = np.dstack(ims)
print('writing', d.shape, 'to', fn)
fitsio.write(fn, d, clobber=True)
return ims
def _bounce_decals_dr3(X):
(args,kwargs) = X
print('Bounce_decals_dr3: kwargs', kwargs)
tag = 'image'
if 'model' in kwargs:
tag = 'model'
if 'resid' in kwargs:
tag = 'resid'
(req,ver,zoom,x,y) = args
print('Tag', tag)
fn = 'top-dr3-%s-%i-%i-%i.fits' % (tag, zoom, x, y)
if os.path.exists(fn):
img = fitsio.read(fn)
print('Read', img.shape)
H,W,planes = img.shape
ims = [img[:,:,i] for i in range(planes)]
return ims
ims = map_decals_dr3(*args, ignoreCached=True, get_images=True, write_jpeg=True,
hack_jpeg=True, forcecache=True, **kwargs)
if ims is None:
return ims
# save FITS
d = np.dstack(ims)
print('writing', d.shape, 'to', fn)
fitsio.write(fn, d, clobber=True)
return ims
def top_levels(mp, opt):
from map.views import save_jpeg, trymakedirs
import pylab as plt
from viewer import settings
import fitsio
from scipy.ndimage.filters import gaussian_filter
from map.views import _unwise_to_rgb
tag = opt.kind
from map.views import get_layer
layer = get_layer(opt.kind)
bands = layer.get_bands()
print('Layer:', layer)
#print('Survey:', layer.survey)
#print(' cache_dir:', layer.survey.cache_dir)
rgbkwargs = {}
if opt.kind in ['unwise-neo2', 'unwise-neo3', 'unwise-neo4', 'unwise-neo6', 'unwise-neo7',
'unwise-cat-model']:
bands = [1, 2]
elif opt.kind == 'unwise-w3w4':
bands = [3, 4]
elif opt.kind == 'sdss2':
bands = 'gri'
elif opt.kind == 'galex':
bands = ['n','f']
elif opt.kind == 'ztf':
bands = 'gri'
elif opt.kind == 'wssa':
bands = ['x']
elif 'vlass' in opt.kind:
bands = [1]
#else:
# bands = 'grz'
if opt.bands is not None:
bands = opt.bands
print('Bands', bands)
ver = tileversions.get(opt.kind, [1])[-1]
print('Version', ver)
basescale = 5
#if opt.kind in ['ls-dr10-early', 'ls-dr10', 'ls-dr10-model', 'ls-dr10-resid',
# 'ls-dr10-grz', 'ls-dr10-model-grz', 'ls-dr10-resid-grz',]:
if 'ls-dr10' in opt.kind:
## UGH, this is because there is some problem with the tiling so that scale 5, y=26 fails
## to find any bricks touching, and rather than figure it out I just backed out the scale.
basescale = 6
pat = os.path.join(settings.DATA_DIR, 'tiles', tag, '%(ver)s',
'%(zoom)i', '%(x)i', '%(y)i.jpg')
patdata = dict(ver=ver)
tilesize = 256
tiles = 2**basescale
side = tiles * tilesize
if opt.kind in ['ls-dr10', 'ls-dr10-model', 'ls-dr10-resid']:
# Split survey with different colormaps for north/south (grz/griz).
decsplit = 32.375
modres = opt.kind.replace('ls-dr10','')
from astrometry.util.starutil_numpy import radectolb
import pylab as plt
from map.views import save_jpeg, trymakedirs
tilesplits = {}
dec = decsplit
fy = 1. - (np.log(np.tan(np.deg2rad(dec + 90)/2.)) - -np.pi) / (2.*np.pi)
for zoom in range(basescale, -1, -1):
n = 2**zoom
y = int(fy * n)
print('Zoom', zoom, '-> y', y)
# ok,rr,dd = wcs.pixelxy2radec([1,1], [1,256])
# #print('Decs', dd)
for x in range(n):
X = get_tile_wcs(zoom, x, y)
wcs = X[0]
H,W = wcs.shape
#px = W//2 + 0.5
#py = np.arange(1, H+1)
px,py = np.meshgrid(np.arange(1, W+1), np.arange(1, H+1))
rr,dd = wcs.pixelxy2radec(px, py)[-2:]
ll,bb = radectolb(rr.ravel(), dd.ravel())
ngc = (bb.reshape(dd.shape) > 0.)
topmask = (dd >= decsplit) * ngc
topfn = 'data/tiles/ls-dr9-north%s/1/%i/%i/%i.jpg' % (modres, zoom,x,y)
botfn = 'data/tiles/ls-dr10-south%s/1/%i/%i/%i.jpg' % (modres, zoom,x,y)
if not os.path.exists(topfn):
toprgb = np.zeros((256,256,3), np.uint8)
else:
toprgb = plt.imread(topfn)
if not os.path.exists(botfn):
botrgb = np.zeros((256,256,3), np.uint8)
else:
botrgb = plt.imread(botfn)
for i in range(3):
#botrgb[topmask,:,:] = toprgb[topmask,:,:]
botrgb[:,:,i][topmask] = toprgb[:,:,i][topmask]
outfn = 'data/tiles/ls-dr10%s/1/%s/%i/%i.jpg' % (modres,zoom,x,y)
trymakedirs(outfn)
save_jpeg(outfn, botrgb)
print('Wrote', outfn)
return
basepat = 'base-%s-%i-%%s.fits' % (opt.kind, basescale)
basefns = [basepat % band for band in bands]
print('Looking for', basefns)
if not all([os.path.exists(fn) for fn in basefns]):
bases = [np.zeros((side, side), np.float32) for band in bands]
args = []
xy = []
if opt.y1 is None:
opt.y1 = tiles
if opt.x0 is None:
opt.x0 = 0
if opt.x1 is None:
opt.x1 = tiles
for y in range(opt.y0, opt.y1):
for x in range(opt.x0, opt.x1):
args.append((opt.kind, basescale, x, y, False, True))
xy.append((x,y))
tiles = mp.map(_one_tile, args)
for ims,(x,y) in zip(tiles, xy):
#for a,(x,y) in zip(args, xy):
#print('_one_tile args:', a)
#ims = _one_tile(a)
#print('-> ', ims)
if ims is None:
continue
for im,base in zip(ims, bases):
if im is None:
continue
base[y*tilesize:(y+1)*tilesize,
x*tilesize:(x+1)*tilesize] = im
for fn,base in zip(basefns, bases):
fitsio.write(fn, base, clobber=True)
else:
print('Reading', basefns)
bases = [fitsio.read(fn) for fn in basefns]
for scale in range(basescale, -1, -1):
print('Scale', scale)
print('Layer:', layer)
print('Bands:', bands)
tiles = 2**scale
for y in range(tiles):
for x in range(tiles):
ims = [base[y*tilesize:(y+1)*tilesize,
x*tilesize:(x+1)*tilesize] for base in bases]
rgb = layer.get_rgb(ims, bands, **rgbkwargs)
pp = patdata.copy()
pp.update(zoom=scale, x=x, y=y)
fn = pat % pp
trymakedirs(fn)
save_jpeg(fn, rgb)
print('Wrote', fn)
for i,base in enumerate(bases):
if 'vlass' in opt.kind:
base = np.maximum(np.maximum(base[::2,::2], base[1::2,::2]),
np.maximum(base[1::2,1::2], base[::2,1::2]))
else:
base = (base[::2,::2] + base[1::2,::2] + base[1::2,1::2] + base[::2,1::2])/4.
bases[i] = base
def _layer_get_filename(args):
layer,brick,band,scale,force,deps = args
if force:
fn = layer.get_scaled_filename(brick, band, scale)
if os.path.exists(fn):
os.remove(fn)
if deps:
fn = layer.get_scaled_filename(brick, band, scale)
if os.path.exists(fn) and layer.needs_recreating(brick, band, scale):
print('Need to re-create', fn, 'due to modified dependencies')
os.remove(fn)
fn = layer.get_filename(brick, band, scale)
print(fn)
def main():
import optparse
parser = optparse.OptionParser()
parser.add_option('--zoom', '-z', type=int, action='append', default=[],
help='Add zoom level; default 13')
parser.add_option('--threads', type=int, default=1, help='Number of threads')
parser.add_option('--y0', type=int, default=0, help='Start row')
parser.add_option('--y1', type=int, default=None, help='End row (non-inclusive)')
parser.add_option('--x0', type=int, default=None)
parser.add_option('--x1', type=int, default=None)
parser.add_option('-x', type=int)
parser.add_option('-y', type=int)
parser.add_option('--mindec', type=float, default=None, help='Minimum Dec to run')
parser.add_option('--maxdec', type=float, default=None, help='Maximum Dec to run')
parser.add_option('--minra', type=float, default=None, help='Minimum RA to run')
parser.add_option('--maxra', type=float, default=None, help='Maximum RA to run')
parser.add_option('--fix', default=False, action='store_true')
parser.add_option('--touching', default=False, action='store_true',
help='Select bricks touching min/max ra/dec box (vs container within)')
parser.add_option('--near', action='store_true', help='Only run tiles near bricks')
parser.add_option('--near-ccds', action='store_true', help='Only run tiles near CCDs')
parser.add_option('--queue', action='store_true', default=False,
help='Print qdo commands')
parser.add_option('--queue-args', help='Add args to --queue commands')
parser.add_option('--all', action='store_true', help='Render all tiles')
parser.add_option('--ignore', action='store_true', help='Ignore cached tile files',
default=False)
parser.add_option('--top', action='store_true', help='Top levels of the pyramid')
parser.add_option('--split', action='store_true', help='For split layers (DR6+DR7), only compute one y strip per zoom level')
parser.add_option('--bricks-exist', action='store_true', help='Create table of bricks that exist')
parser.add_option('--kind', default='image')
parser.add_option('--scale', action='store_true', help='Scale images?')
parser.add_option('--deps', action='store_true', default=False, help='With --scale, check if files need to be remade due to updated dependencies?')
parser.add_option('--bricks', action='store_true', help='Compute scaled brick tables?')
parser.add_option('--coadd', action='store_true', help='Create SDSS coadd images?')
parser.add_option('--grass', action='store_true', help='progress plot')
parser.add_option('--bands', default=None)
parser.add_option('--bandlist', default=None, help='Comma-separated list of bands')
parser.add_option('-v', '--verbose', dest='verbose', action='count',
default=0, help='Make more verbose')
opt,args = parser.parse_args()
if opt.bandlist is not None:
opt.bands = opt.bandlist.split(',')
if opt.verbose == 0:
lvl = logging.INFO
else:
lvl = logging.DEBUG
logging.basicConfig(level=lvl, format='%(message)s', stream=sys.stdout)
mp = multiproc(opt.threads)
if opt.kind in ['cfis-r', 'cfis-u', 'cfis-dr3-r', 'cfis-dr3-u']:
if opt.bands is None:
if opt.kind in ['cfis-r', 'cfis-dr3-r']:
opt.bands = 'R'
if opt.kind in ['cfis-u', 'cfis-dr3-u']:
opt.bands = 'U'
if opt.mindec is None:
if opt.kind in ['cfis-r', 'cfis-dr3-r']:
opt.mindec = 22
if opt.kind in ['cfis-u', 'cfis-dr3-u']:
opt.mindec = -11
if opt.maxdec is None:
opt.maxdec = 90
if opt.kind in ['sdss', 'sdss2']:
if opt.maxdec is None:
opt.maxdec = 90
if opt.mindec is None:
opt.mindec = -25
# All-sky
elif (opt.kind in ['halpha', 'unwise-neo1', 'unwise-neo2', 'unwise-neo3',
'unwise-neo4', 'unwise-neo6', 'unwise-neo7', 'unwise-cat-model',
'unwise-w3w4',
'galex', 'wssa', 'vlass', 'vlass1.2', 'hsc2', 'hsc-dr3', 'ztf',
'cfis-r', 'cfis-u', 'cfis-dr3-r', 'cfis-dr3-u']
or 'dr8i' in opt.kind
or 'dr9-test' in opt.kind
or 'dr9f' in opt.kind
or 'dr9g' in opt.kind
or 'dr9h' in opt.kind
or 'dr9i' in opt.kind
or 'dr9j' in opt.kind
or 'dr9-sga' in opt.kind
or 'dr9-sga2' in opt.kind
or 'dr9-grid' in opt.kind
or 'dr9-segsize2' in opt.kind
or 'dr9k' in opt.kind
or 'dr9m' in opt.kind
or 'ls-dr9.1.1' in opt.kind):
if opt.maxdec is None:
opt.maxdec = 90.
if opt.mindec is None:
opt.mindec = -90.
if opt.maxra is None:
opt.maxra = 360.
if opt.minra is None:
opt.minra = 0.
if opt.kind == 'galex' and opt.bands is None:
opt.bands = 'nf'
if opt.kind == 'unwise-w3w4' and opt.bands is None:
opt.bands = '34'
if 'unwise' in opt.kind and opt.bands is None:
opt.bands = '12'
if 'ztf' in opt.kind and opt.bands is None:
opt.bands = 'gri'
if 'vlass' in opt.kind:
opt.bands = [1]
elif opt.kind == 'm33':
if opt.mindec is None:
opt.mindec = 30.40
if opt.maxdec is None:
opt.maxdec = 30.90
if opt.minra is None:
opt.minra = 23.29
if opt.maxra is None:
opt.maxra = 23.73
elif opt.kind == 'm33':
if opt.mindec is None:
opt.mindec = 30.40
if opt.maxdec is None:
opt.maxdec = 30.90
if opt.minra is None:
opt.minra = 23.29
if opt.maxra is None:
opt.maxra = 23.73
elif opt.kind in ['des-dr1']:
if opt.maxdec is None:
opt.maxdec = 6
if opt.mindec is None:
opt.mindec = -68
if opt.maxra is None:
opt.maxra = 360
if opt.minra is None:
opt.minra = 0
elif opt.kind in ['mzls+bass-dr6', 'mzls+bass-dr6-model', 'mzls+bass-dr6-resid']:
if opt.maxdec is None:
opt.maxdec = 90
if opt.mindec is None:
opt.mindec = -20
if opt.maxra is None:
opt.maxra = 360
if opt.minra is None:
opt.minra = 0
# elif opt.kind in ['dr8', 'dr8-model', 'dr8-resid']:
# if opt.maxdec is None:
# opt.maxdec = 90
# if opt.mindec is None:
# opt.mindec = -5
# if opt.maxra is None:
# opt.maxra = 360
# if opt.minra is None:
# opt.minra = 0
elif opt.kind in ['dr8-north', 'dr8-north-model', 'dr8-north-resid',
'dr9sv-north', 'dr9sv-north-model', 'dr9sv-north-resid',
'ls-dr9-north', 'ls-dr9-north-model',
]:
if opt.maxdec is None:
opt.maxdec = 90
if opt.mindec is None:
opt.mindec = -5
if opt.maxra is None:
opt.maxra = 360
if opt.minra is None:
opt.minra = 0
elif opt.kind in ['dr8-south', 'dr8-south-model', 'dr8-south-resid',
'dr9sv-south', 'dr9sv-south-model', 'dr9sv-south-resid',
'fornax', 'fornax-model', 'fornax-resid']:
if opt.maxdec is None:
opt.maxdec = 40
if opt.mindec is None:
opt.mindec = -70
if opt.maxra is None:
opt.maxra = 360
if opt.minra is None:
opt.minra = 0
elif opt.kind in ['decaps2', 'decaps2-model', 'decaps2-resid']:
# After we have generated the bricks-exist files, don't really need RA,Dec limits...
if opt.maxdec is None:
#opt.maxdec = -15
opt.maxdec = 90
if opt.mindec is None:
#opt.mindec = -75
opt.mindec = -90
if opt.maxra is None:
#opt.maxra = 280
opt.maxra = 360
if opt.minra is None:
#opt.minra = 90
opt.minra = 0
elif opt.kind in ['ls-dr9-south-B', 'ls-dr9-south-B-model']:
if opt.maxdec is None:
opt.maxdec = 40
if opt.mindec is None:
opt.mindec = -70
if opt.maxra is None:
opt.maxra = 360
if opt.minra is None:
opt.minra = 0
elif 'ls-dr10' in opt.kind:
#in ['ls-dr10-early', 'ls-dr10a', 'ls-dr10a-mode`l',
# 'ls-dr10', 'ls-dr10-model', 'ls-dr10-resid']:
if opt.bands is None:
if opt.kind.endswith('-grz'):
opt.bands = 'grz'
else:
opt.bands = 'griz'
if opt.maxdec is None:
opt.maxdec = 40
if opt.mindec is None:
opt.mindec = -90
if opt.maxra is None:
opt.maxra = 360
if opt.minra is None:
opt.minra = 0
elif opt.kind in ['pandas']:
if opt.bands is None:
opt.bands = 'gi'
if opt.maxdec is None:
opt.maxdec = 51
if opt.mindec is None:
opt.mindec = 37
if opt.maxra is None:
opt.maxra = 360
if opt.minra is None:
opt.minra = 0
else:
if opt.maxdec is None:
opt.maxdec = 40
if opt.mindec is None:
opt.mindec = -25
if opt.maxra is None:
opt.maxra = 360
if opt.minra is None:
opt.minra = 0
if opt.bands is None:
opt.bands = 'grz'
if opt.top:
top_levels(mp, opt)
sys.exit(0)
if opt.bricks:
from map.views import get_layer
layer = get_layer(opt.kind)
for scale in range(1,8):
B = layer.get_bricks_for_scale(scale)
sys.exit(0)
if opt.scale:
if opt.kind == 'ps1':
from map.views import get_layer
fns = glob('data/ps1/skycells/*/ps1-*.fits')
fns.sort()
#ps1-1561-021-r.fits
if len(opt.zoom) == 0:
opt.zoom = [1,2,3,4,5,6,7]
print(len(fns), 'PS1 image files')
layer = get_layer(opt.kind)
B = layer.get_bricks()
print(len(B), 'skycells total')
B.cut((B.ra >= opt.minra ) * (B.ra <= opt.maxra ) *
(B.dec >= opt.mindec) * (B.dec <= opt.maxdec))
print(len(B), 'skycells in RA,Dec box')
for i,brick in enumerate(B):
for band in opt.bands:
fn0 = layer.get_filename(brick, band, 0)
print('PS1 image:', fn0)
if not os.path.exists(fn0):
continue
for scale in opt.zoom:
fn = layer.get_filename(brick, band, scale)
layer.create_scaled_image(brick, band, scale, fn)
sys.exit(0)
# Rebricked
if (opt.kind in ['decals-dr5', 'decals-dr5-model', 'decals-dr7', 'decals-dr7-model',
'eboss',
'mzls+bass-dr6', 'mzls+bass-dr6-model',
'unwise-neo3', 'unwise-neo4', 'unwise-neo6', 'unwise-neo7',
'unwise-w3w4',
'unwise-cat-model',
'galex', 'wssa', 'des-dr1', 'hsc2', 'hsc-dr3',
'cfis-dr3-r', 'cfis-dr3-u',
'dr8-north', 'dr8-north-model', 'dr8-north-resid',
'dr8-south', 'dr8-south-model', 'dr8-south-resid',
'dr9c', 'dr9c-model', 'dr9c-resid',
'dr9d-south', 'dr9d-south-model', 'dr9d-south-resid',
'dr9d-north', 'dr9d-north-model', 'dr9d-north-resid',
#
'dr9e-south', 'dr9e-south-model', 'dr9e-south-resid',
'dr9e-north', 'dr9e-north-model', 'dr9e-north-resid',
#
'dr9sv-south', 'dr9sv-south-model', 'dr9sv-south-resid',
'dr9sv-north', 'dr9sv-north-model', 'dr9sv-north-resid',
'dr9sv', 'dr9sv-model', 'dr9sv-resid',
'fornax', 'fornax-model', 'fornax-resid',
'vlass1.2', 'ztf',
'ls-dr9-south', 'ls-dr9-south-model',
'ls-dr9-north', 'ls-dr9-north-model',
'ls-dr9.1.1', 'ls-dr9.1.1-model',
'ls-dr9-south-B', 'ls-dr9-south-B-model',
'asteroids-i',
'ls-dr10-early', 'ls-dr10a', 'ls-dr10a-model',
'ls-dr10', 'ls-dr10-model',
'ls-dr10-grz', 'ls-dr10-model-grz',
'pandas', 'wiro-C', 'wiro-D',
'suprime-L427', 'suprime-L427-model',
'suprime-L464', 'suprime-L464-model',
'suprime-L484', 'suprime-L484-model',
'suprime-L505', 'suprime-L505-model',
'suprime-L527', 'suprime-L527-model',
'suprime-ia-v1', 'suprime-ia-v1-model',
'cfht-cosmos-cahk',
'decaps2', 'decaps2-model',
'dr10-deep', 'dr10-deep-model', 'ibis-color', 'ibis',
'ibis-3',
]
or opt.kind.startswith('dr8-test')
or opt.kind.startswith('dr9-test')
or opt.kind.startswith('dr9f')
or opt.kind.startswith('dr9g')
or opt.kind.startswith('dr9h')
or opt.kind.startswith('dr9i')
or opt.kind.startswith('dr9j')
or opt.kind.startswith('dr9-sga')
or opt.kind.startswith('dr9-sga2')
or opt.kind.startswith('dr9-grid')
or opt.kind.startswith('dr9-segsize2')
or opt.kind.startswith('dr9k')
or opt.kind.startswith('dr9m')
):
from map.views import get_layer
layer = get_layer(opt.kind)
print('Layer:', layer)
if opt.queue:
if len(opt.zoom) == 0:
opt.zoom = [1,2,3,4,5,6,7]
#step = 0.1
step = 1.
ras = np.arange(opt.minra, opt.maxra+step, step)
#ras = np.arange(opt.minra, opt.maxra+step, step)
#decs = np.arange(opt.mindec, opt.maxdec+step, step)
decs = [opt.mindec, opt.maxdec]
for zoom in opt.zoom:
for declo,dechi in zip(decs, np.clip(decs[1:], opt.mindec, opt.maxdec)):
#rstep = step / np.maximum(0.05, np.cos(np.deg2rad((declo+dechi)/2.)))
#ras = np.arange(opt.minra, opt.maxra+rstep, rstep)
for ralo,rahi in zip(ras, np.clip(ras[1:], opt.minra, opt.maxra)):
cmd = ('python3 render-tiles.py --kind %s --bands %s --scale --minra %f --maxra %f --mindec %f --maxdec %f -z %i' %
(opt.kind, opt.bands, ralo, rahi, declo, dechi, zoom))
if opt.queue_args:
cmd = cmd + ' ' + opt.queue_args
print(cmd)
sys.exit(0)
if len(opt.zoom) == 0:
opt.zoom = [1]
for scale in opt.zoom:
B = layer.get_bricks_for_scale(scale)
print(len(B), 'bricks for scale', scale)
if opt.touching:
B.cut((B.dec2 >= opt.mindec) * (B.dec1 <= opt.maxdec))
print(len(B), 'touching Dec range')
B.cut((B.ra2 >= opt.minra) * (B.ra1 <= opt.maxra))
print(len(B), 'touching RA range')
else:
B.cut((B.dec >= opt.mindec) * (B.dec <= opt.maxdec))
print(len(B), 'in Dec range')
B.cut((B.ra >= opt.minra) * (B.ra <= opt.maxra))
print(len(B), 'in RA range')
bands = opt.bands
has = {}
for band in bands:
if 'has_%s' % band in B.get_columns():
has[band] = B.get('has_%s' % band)
else:
# assume yes
has[band] = np.ones(len(B), bool)
# Run one scale at a time
args = []
for ibrick,brick in enumerate(B):
for band in bands:
if has[band][ibrick]:
args.append((layer, brick, band, scale, opt.ignore, opt.deps))
print(len(args), 'bricks for scale', scale)
mp.map(_layer_get_filename, args)
if mp.pool is not None:
mp.pool.close()
mp.pool.join()
#mp.close()
sys.exit(0)
if (opt.kind in ['eboss', 'ps1']
or 'dr8b' in opt.kind
or 'dr8c' in opt.kind
or 'dr8i' in opt.kind):
from map.views import get_survey, get_layer
surveyname = opt.kind
for suffix in ['-model', '-resid']:
if surveyname.endswith(suffix):
surveyname = surveyname[:-len(suffix)]
survey = get_survey(surveyname)
print('Survey:', survey)
print(' cache_dir:', survey.cache_dir)
B = survey.get_bricks()
print(len(B), 'bricks')
B.cut((B.dec >= opt.mindec) * (B.dec < opt.maxdec))
print(len(B), 'in Dec range')
B.cut((B.ra >= opt.minra) * (B.ra < opt.maxra))
print(len(B), 'in RA range')
print('Resulting range: RA', B.ra.min(), 'to', B.ra.max(),
'Dec', B.dec.min(), 'to', B.dec.max())
# find all image files
filetype = 'image'
model = False
if '-model' in opt.kind:
model = True
filetype = 'model'
bands = opt.bands
layer = get_layer(opt.kind)
has = {}
for band in bands:
if 'has_%s' % band in B.get_columns():
has[band] = B.get('has_%s' % band)
else:
# assume yes
has[band] = np.ones(len(B), bool)
for scale in opt.zoom:
args = []
for ibrick,brick in enumerate(B):
for band in bands:
if not has[band][ibrick]:
print('Brick', brick.brickname, 'does not have', band)
continue
args.append((layer, brick, band, scale, opt.ignore, False))
mp.map(_layer_get_filename, args)
sys.exit(0)
elif opt.kind == 'sdss2':
layer = get_layer(opt.kind)
bands = 'gri'
scales = opt.zoom
if len(scales) == 0:
scales = list(range(1,8))
for scale in scales:
#maxscale = 7
bricks = layer.get_bricks_for_scale(scale)
print('Got', len(bricks), 'bricks for scale', scale)
bricks.cut((bricks.dec > opt.mindec) * (bricks.dec <= opt.maxdec) *
(bricks.ra > opt.minra ) * (bricks.ra <= opt.maxra))
print('Cut to', len(bricks), 'bricks within RA,Dec box')
for ibrick,brick in enumerate(bricks):
for band in bands:
print('Scaling brick', ibrick, 'of', len(bricks), 'scale', scale, 'brick', brick.brickname, 'band', band)
fn = layer.get_filename(brick, band, scale)
sys.exit(0)
if opt.kind in ['unwise-w1w2', 'unwise-neo2']:
# scaledir = opt.kind
# basedir = settings.DATA_DIR
# dirnm = os.path.join(basedir, 'scaled', scaledir)
# B = fits_table(os.path.join(basedir, 'unwise-bricks.fits'))
layer = get_layer(opt.kind)
B = layer.get_bricks()
print(len(B), 'unWISE tiles')
for b in B:
for band in ['1','2']:
for scale in [1,2,3,4,5,6,7]:
print('Get brick', b.brickname, 'band', band, 'scale', scale)
layer.get_filename(b, band, scale)
else:
assert(False)
if opt.bricks_exist:
from map.views import get_survey
surveyname = opt.kind
filetype = 'image'
survey = get_survey(surveyname)
print('Survey:', type(survey), survey)
B = survey.get_bricks()
print(len(B), 'bricks')
B.cut((B.dec >= opt.mindec) * (B.dec < opt.maxdec))
print(len(B), 'in Dec range')
B.cut((B.ra >= opt.minra) * (B.ra < opt.maxra))
print(len(B), 'in RA range')
# find all image files
bands = opt.bands
has_band = {}
for b in bands:
B.set('has_%s' % b, np.zeros(len(B), bool))
has_band[b] = B.get('has_%s' % b)
exists = np.zeros(len(B), bool)
for i,brick in enumerate(B.brickname):
found = False
for band in bands:
fn = survey.find_file(filetype, brick=brick, band=band)
ex = os.path.exists(fn)
print('Brick', brick, 'band', band, 'exists?', ex, 'file', fn)
has_band[band][i] = ex
if ex:
found = True
exists[i] = found
B.cut(exists)
B.writeto('bricks-exist-%s.fits' % opt.kind)
sys.exit(0)
from map.views import get_survey
surveyname = opt.kind
if surveyname.endswith('-model'):
surveyname = surveyname.replace('-model','')
if surveyname.endswith('-resid'):
surveyname = surveyname.replace('-resid','')
survey = get_survey(surveyname)
if len(opt.zoom) == 0:
opt.zoom = [13]
if opt.near:
if opt.kind == 'sdss':
B = fits_table(os.path.join(settings.DATA_DIR, 'bricks-sdssco.fits'))
else:
B = survey.get_bricks()
print(len(B), 'bricks')
#if opt.scale:
# opt.near_ccds = True
ccdsize = None
if opt.near_ccds:
if opt.kind == 'sdss':
C = fits_table(os.path.join(settings.DATA_DIR, 'sdss', 'window_flist.fits'),
columns=['rerun','ra','dec', 'run', 'camcol', 'field', 'score'])
C.cut(C.rerun == '301')
C.cut(C.score >= 0.6)
#C.delete_column('rerun')