1

I have a fits image with many astronomical objects in it. I am trying to create small 4x4 "stamps" (sections/images around the objects) from the objects that interest me. I have already calculated the pixel coordinates for the objects in the original fits file, and created a document that contains the coordinates. I know that the imshow() command is probably the best option, but I am stumped as to how I can use the pixel coordinates to complete the task.

from pylab import *
import numpy as np
import pyfits
import matplotlib.pyplot as plat
coord = loadtxt('/Users/seadr/data/sky_coordinate_selection.txt')
x = coord[:,0]
y = coord[:,1]

data = pyfits.getdata('/Users/seadr/data/sky_bkgdcor_match.fits')

#vimin will calaculate the median of the data that does not equal 0
vmin = median(data[where(data != 0)])

#vmax will calculate the normalized median
vmax = 1.483 * np.median(abs(np.array(data[where(data!= 0)]) - 

np.median(data[where(data!= 0)])))
print vmax, vmin

plt.imshow(data,vmin = vmin,vmax = vmax)

The first imshow() gives me the original fits document.

If I wanted to look at something like a single star in my image, while knowing its pixel coordinates, how would I go about doing that.

My long term goal is to be able to create many "stamps" because I have many different version of the same astronomical image, such that they were taken in different filters. I want to be able to switch out the original fits file, and create a sets of these "stamps" for the same objects in the different filters.

Iguananaut
  • 15,675
  • 4
  • 43
  • 50
Seadrow
  • 13
  • 3
  • I'm not sure where your confusion is, but nowhere in your example do you slice the image into smaller sections using the coordinates. *Is* `imshow` necessarily the best function for your problem? I don't know. – Iguananaut Jun 23 '15 at 13:13

1 Answers1

1

If you'd like to slice the image you're displaying using imshow, you can simply index data. For example,

plt.imshow(data[0:10, 0:10])

will display the 10x10 corner cutout of data. It looks like you want to display a region centered on each of your x, y coordinates. You want each of these stamps to be 4 pixels by 4 pixels, so you would do

imwidth = 2
plt.imshow(data[xcoord-imwidth:xcoord+imwidth, ycoord-imwidth:ycoord+imwidth])

where xcoord and ycoord are the coordinates of the object you want to be centered on, i.e. x[i] and y[i], where x and y are the arrays you've defined above, and i is some integer index.

S E Clark
  • 395
  • 2
  • 14