Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
itune2 = 5
ntune = 0
IRLS_scale = 25.
bands=['r','g','u','i','z']
bandname = 'r'
flipBands = ['r']
rerun = 0
TI = []
sources = []
for rcf in rcfs:
print rcf
try:
TI.extend([st.get_tractor_image(rcf[0], rcf[1], rcf[2], bandname,useMags=True) for bandname in bands])
sources.append(st.get_tractor_sources(rcf[0], rcf[1], rcf[2],bandname,bands=bands))
except:
print "Sources not in data! %s" % (rcf)
timg,info = TI[0]
photocal = timg.getPhotoCal()
wcs = timg.getWcs()
lvl = logging.DEBUG
logging.basicConfig(level=lvl,format='%(message)s',stream=sys.stdout)
tims = [timg for timg,tinf in TI]
tractor = st.SDSSTractor(tims)
for source in sources:
tractor.addSources(source)
for theta in np.linspace(0,2*np.pi,100):
ux = np.cos(theta)
uy = np.sin(theta)
x.append(ux*radius+x0)
y.append(uy*radius+y0)
plt.plot(x,y)
plt.plot(x0,y0,'o')
# colors = ['r','g','y','b','k','m','c']
# for col,rcf in zip(colors,rcfs):
for rcf in rcfs:
timg,info = st.get_tractor_image(rcf[0],rcf[1],rcf[2],bandname,useMags=True)
wcs = timg.getWcs()
rd = wcs.pixelToPosition(0,0)
rd2 = wcs.pixelToPosition(width,height)
print(rd)
print(rd2)
plt.plot((rd.ra,rd.ra,rd2.ra,rd2.ra,rd.ra),(rd.dec,rd2.dec,rd2.dec,rd.dec,rd.dec))
plt.text((rd.ra+rd2.ra)/2.,(rd.dec+rd2.dec)/2.,"Run: %s, Camcol: %s, Field: %s" % (rcf[0],rcf[1],rcf[2]),fontsize=10.,va='center',ha='center')
# plt.plot(rd.ra,rd.dec,'+',color=col)
# plt.plot(rd2.ra,rd.dec,'+',color=col)
# plt.plot(rd.ra,rd2.dec,'+',color=col)
# plt.plot(rd2.ra,rd2.dec,'+',color=col)
print("Saving figure")
y0 = 400
y1 = 850
starx = 200. #Star location
stary = 300.
starr = 50. #Star radius
roi = [x0,x1,y0,y1]
bands=['r','g','i','u','z']
bandname = 'r'
flipBands = ['r']
rerun = 0
TI = []
TI.extend([st.get_tractor_image(run, camcol, field, bandname,roi=roi,useMags=True) for bandname in bands])
sources = st.get_tractor_sources(run, camcol, field,bandname, bands=bands,roi=roi)
timg,info = TI[0]
photocal = timg.getPhotoCal()
wcs = timg.getWcs()
lvl = logging.DEBUG
logging.basicConfig(level=lvl,format='%(message)s',stream=sys.stdout)
tims = [timg for timg,tinf in TI]
tractor = st.SDSSTractor(tims)
tractor.addSources(sources)
zr = np.array([-5.,+5.]) * info['skysig']
print(bands)
ra = 198.05
dec = 44.0333
itune = 5
ntune = 2
bands=['r','g','u','i','z']
bandname = 'r'
flipBands = ['r']
rerun = 0
TI = []
sources = []
for run,field,camcol,roi in zip(run,field,camcol,roi):
TI.extend([st.get_tractor_image(run, camcol, field, bandname,useMags=True,roi=roi) for bandname in bands])
sources.append(st.get_tractor_sources(run, camcol, field,bandname,bands=bands,roi=roi))
timg,info = TI[0]
photocal = timg.getPhotoCal()
wcs = timg.getWcs()
lvl = logging.DEBUG
logging.basicConfig(level=lvl,format='%(message)s',stream=sys.stdout)
tims = [timg for timg,tinf in TI]
tractor = st.SDSSTractor(tims)
for source in sources:
tractor.addSources(source)
zr = np.array([-5.,+5.]) * info['skysig']
print('Filtering out run 206:', len(rcf))
sdss = DR7()
sdss.setBasedir('faint')
band = 'z'
skies = []
ims = []
tais = []
rcfs = []
#S = 50
S = 40
for i,(r,c,f,ra,dec) in enumerate(rcf):
print()
print('Retrieving', (i+1), 'of', len(rcf), r,c,f,band)
try:
im,info = st.get_tractor_image(r, c, f, band, psf='dg', useMags=True,
sdssobj=sdss,
roiradecsize=(RA, DEC, S/2))
except:
continue
skies.append((info['sky'], info['skysig']))
tais.append(info['tai'])
rcfs.append((r,c,f))
ims.append(im)
###
#if i == 9:
# break
return ims,skies,tais,rcfs
# def getModelPatchNoCache(self, img, src):
# data,invvar = img.data,img.invvar
# img.shape = data.shape
# del img.data
# del img.invvar
# R = super(Tractor2,self).getModelPatchNoCache(img, src)
# img.data, img.invvar = data,invvar
#run,camcol,field = 7164,4,273
#band='g'
run,camcol,field = 2662, 4, 111
band='i'
roi=[0,300,0,300]
im,info = st.get_tractor_image(run, camcol, field, band,
useMags=True, roi=roi)
sources = st.get_tractor_sources(run, camcol, field, band, roi=roi)
tractor = Tractor2([im], sources)
print tractor
print tractor.getLogProb()
tractor.freezeParam('images')
p0 = tractor.getParams()
tractor.setParams(p0)
print
print 'With Debug:'
tractor.setParams(p0)
tractor.mp = dmup
t0 = Time()
tractor.opt2()
sras, sdecs, smags = tychoMatch(ra,dec,(fieldradius*1.5)/60.)
for sra,sdec,smag in zip(sras,sdecs,smags):
print(sra,sdec,smag)
imkw = dict(psf='dg')
if dr9:
getim = st.get_tractor_image_dr9
getsrc = st.get_tractor_sources_dr9
imkw.update(zrange=[-3,100])
elif dr8:
getim = st.get_tractor_image_dr8
getsrc = st.get_tractor_sources_dr8
imkw.update(zrange=[-3,100])
else:
getim = st.get_tractor_image
getsrc = st.get_tractor_sources_dr8
imkw.update(useMags=True)
bands=['u','g','r','i','z']
bandname = 'r'
flipBands = ['r']
print(rcfs)
imsrcs = mp.map(get_ims_and_srcs, [(rcf + (bands, ra, dec, fieldradius*60./0.396, imkw, getim, getsrc))
for rcf in rcfs])
timgs = []
sources = []
allsources = []
for ims,s in imsrcs:
if ims is None:
continue
def makeTractor(bands, ra, dec, S, RCFS):
TI = []
for i,(run,camcol,field) in enumerate(RCFS):
for bandname in bands:
im,inf = st.get_tractor_image(run, camcol, field, bandname,
useMags=True,
roiradecsize=(ra,dec,S))
#im.dxdy = (fxc - xc, fyc - yc)
TI.append((im,inf))
if i == 0 and bandname == 'r':
wcs = im.getWcs()
# im,info = TI[bands.index('r')]
#wcs = im.getWcs()
# this is a shifted WCS; S,S is the center.
# rd = wcs.pixelToPosition(None, (S,S))
# ra,dec = rd.ra,rd.dec
# print 'RA,Dec', ra,dec
cd = wcs.cdAtPixel(xc,yc)
pixscale = np.sqrt(np.abs(np.linalg.det(cd)))
print('pixscale', pixscale * 3600.)
extent = pixscale * S