-
Notifications
You must be signed in to change notification settings - Fork 11
/
dr8-update-paths.py
60 lines (51 loc) · 1.59 KB
/
dr8-update-paths.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
'''
CP files got moved around after DR8... update the CCDs file.
'''
import os
import sys
import pylab as plt
import numpy as np
from glob import glob
import fitsio
from collections import Counter
from astrometry.util.fits import *
from astrometry.util.util import *
from astrometry.libkd.spherematch import match_radec
from tractor import *
from astrometry.util.starutil_numpy import *
#C = fits_table('/global/cfs/cdirs/cosmo/data/legacysurvey/dr8/survey-ccds-decam-dr8.kd.fits')
C = fits_table('data/ls-dr8-south/survey-ccds-dr8-decam-all.kd.fits')
print(Counter(C.plver))
paths = [fn.strip() for fn in C.image_filename]
fns = [p.split('/')[-1] for p in paths]
newfns = []
for plver in np.unique(C.plver):
plver = plver.strip()
g = glob('/global/cfs/cdirs/cosmo/staging/decam/CP/' + plver + '/*/*_ooi_*')
print(len(g), 'in', plver)
newfns.extend(g)
fnmap = dict()
for i,full in enumerate(newfns):
fn = full.strip().split('/')[-1]
full = '/'.join(full.split('/')[6:])
if not fn in fnmap:
fnmap[fn] = [full]
else:
fnmap[fn].append(full)
#for fn in fns:
# assert(len(fnmap[fn]) == 1)
found = []
newfns = []
for i,fn in enumerate(fns):
mapped = fnmap.get(fn, [])
if len(mapped) != 1:
print('file', fn, 'got', mapped)
if len(mapped) == 0:
continue
found.append(i)
newfns.append(mapped[0])
C.cut(np.array(found))
C.image_filename = np.array(newfns)
#C.new_filename = np.array([fnmap[fn][0] for fn in fns])
#C.rename('new_filename', 'image_filename')
C.writeto('/global/cfs/cdirs/cosmo/webapp/viewer-dev/survey-ccds-dr8-fixed.fits')