简体   繁体   中英

How to Use Pixel Coordinates with the imshow() command in order to make images from specific sections of a fits image in python?

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.

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, ie x[i] and y[i], where x and y are the arrays you've defined above, and i is some integer index.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM