Skip to content

Instantly share code, notes, and snippets.

@andymiller
Created March 23, 2016 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andymiller/dd0482f0cde789ff77e6 to your computer and use it in GitHub Desktop.
Save andymiller/dd0482f0cde789ff77e6 to your computer and use it in GitHub Desktop.
from tractor import sdss as st
def tractor_render_patch(run, camcol, field, roi, celeste_src=None, bandname='r'):
""" ROI = (x0, x1, y0, y1), zero indexed pixel coordinates """
# set up tractor
sdss = DR9()
getim = st.get_tractor_image_dr9
getsrc = st.get_tractor_sources_dr9
imkw = dict(zrange=[-3,100], sdss=sdss)
# get images
tim,tinf = getim(run, camcol, field, bandname, curl=True, roi=roi, **imkw)
tim.zr = tinf['zr']
# get corresponding sources
sources = getsrc(run, camcol, field, bandname, bands=[bandname], curl=True, roi=roi)
# set the first source to have the same parameters as dustin's
if celeste_src is not None:
print "setting source parameters"
ts = sources[0]
ts_pos = ts.getPosition()
ts_pos.ra, ts_pos.dec = celeste_src.params.u
from CelestePy.util.data import nanomaggies2mags
band_mag = nanomaggies2mags(celeste_src.params.flux_dict[bandname])
ts_bright = ts.getBrightness()
ts_bright.setMag(bandname, band_mag)
# create a tractor object, get a model image
tractor = Tractor(images = [tim], catalog=[ts])
mod = tractor.getModelImage(tim, srcs=sources)
chi = tractor.getChiImage(imgi=0, srcs=sources)
return mod, tim, chi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment