Skip to content

Instantly share code, notes, and snippets.

@torrance
Created December 7, 2017 04:02
Show Gist options
  • Save torrance/626692a2ab93306069bc9bba1f69374b to your computer and use it in GitHub Desktop.
Save torrance/626692a2ab93306069bc9bba1f69374b to your computer and use it in GitHub Desktop.
for source in ghosts:
if source in close_sources:
continue
xmin, xmax, ymin, ymax = source.bounds()
# Enlarge the bounding box just slightly
xwidth = xmax - xmin
if xwidth > 300:
xmin -= (xwidth * 1.2 - xwidth) / 2
xmax += (xwidth * 1.2 - xwidth) / 2
else:
center = xmin + xwidth // 2
xmin = center - 150
xmax = center + 150
yheight = ymax - ymin
if yheight > 300:
ymin -= (yheight * 1.2 - yheight) / 2
ymax += (yheight * 1.2 - yheight) / 2
else:
center = ymin + yheight // 2
ymin = center - 150
ymax = center + 150
maxX, maxY = hdulist[0].data.shape
maxX, maxY = maxX - 1, maxY - 1
xmin, xmax, ymin, ymax = int(max(0, xmin)), int(min(xmax, maxX)), int(max(0, ymin)), int(min(ymax, maxY))
window = hdulist[0].data[ymin:ymax, xmin:xmax]
window = fits.PrimaryHDU(window)
window.header = hdulist[0].header.copy()
window.header['CRPIX1'] = window.header['CRPIX1'] - xmin
window.header['CRPIX2'] = window.header['CRPIX2'] - ymin
fig = aplpy.FITSFigure(window)
fig.show_colorscale(cmap='viridis', interpolation=None)
source.show(fig, color='orange')
fig.save(filename + '-ghost-ID' + str(source.id) + '.pdf')
fig.save(filename + '-ghost-ID' + str(source.id) + '.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment