[英]make subplots from an astronomical fits image
I have a set of RGB
Images and I made a RGB
fits image with aplpy
and I also overlaid some contours on the image but I would like to cut the image and make small fits images where I would see the peaks of contour. 我有一组
RGB
图像,我用aplpy
制作了RGB
拟合图像,并且还在图像上叠加了一些轮廓,但是我想剪切图像并制作小的拟合图像,以便能看到轮廓的峰值。
import aplpy
import atpy
from pyavm import AVM
import asciitable
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm,BoundaryNorm
import montage_wrapper
from astropy.io import fits
import pyfits
from astropy import wcs
fitsfile = 'rgb.fits'
fitsfile_2d = 'rgb_2d.fits'
pngfile = 'rgb_arcsinh_contour.png'
figfile = 'rgb.png'
w = wcs.WCS(naxis=2)
# Set up an "Airy's zenithal" projection
# Vector properties may be set with Python lists, or Numpy arrays
w.wcs.crpix = [5.70000000E+03, 3.05000000E+03]
w.wcs.cdelt = np.array([-6.611111263E-05, 6.611111263E-05])
w.wcs.crval = [23.166667, -7.666667]
w.wcs.ctype = ["RA---TAN", "DEC--TAN"]
w.wcs.cunit =["deg","deg"]
# Print out all of the contents of the WCS object
w.wcs.print_contents()
# Some pixel coordinates of interest.
pixcrd = np.array([[0,0],[24,38],[45,98]], np.float_)
# Convert pixel coordinates to world coordinates
world = w.wcs_pix2world(pixcrd, 1)
print world
# Convert the same coordinates back to pixel coordinates.
pixcrd2 = w.wcs_world2pix(world, 1)
print pixcrd2
# These should be the same as the original pixel coordinates, modulo
# some floating-point error.
assert np.max(np.abs(pixcrd - pixcrd2)) < 1e-6
# Now, write out the WCS object as a FITS header
header = w.to_header()
hdu = pyfits.open(fitsfile)
# header is an astropy.io.fits.Header object. We can use it to create a new
# PrimaryHDU and write it to a file.
hdu = fits.PrimaryHDU(header=header)
# make rgb image
aplpy.make_rgb_image(fitsfile, pngfile,
vmin_r=-0.005, vmax_r=0.2,
vmin_g=-0.02, vmax_g=0.1,
vmin_b=-0.02,vmax_b=0.04,
embed_avm_tags=False)
# make a figure
img = aplpy.FITSFigure(fitsfile_2d)
img.show_rgb(pngfile)
img.set_nan_color('white')
standard_setup(img)
How could I produce subplots from given coordinates of the image with a given size ? 如何从给定尺寸的图像的给定坐标生成子图?
According to the APLpy documentation, you can make subplots : 根据APLpy文档,您可以进行子图绘制:
By default, FITSFigure creates a figure with a single subplot that occupies the entire figure.
默认情况下,FITSFigure创建一个具有单个子图的图形,该子图占据了整个图形。 However, APLpy can be used to place a subplot in an existing matplotlib figure instance.
但是,可以使用APLpy将子图放置在现有的matplotlib图实例中。 To do this, FITSFigure should be called with the figure= argument as follows:
为此,应使用Figure =参数调用FITSFigure,如下所示:
import aplpy import matplotlib.pyplot as mpl fig = mpl.figure() f = aplpy.FITSFigure('some_image.fits', figure=fig)
and recenter your figures: 和recenter您的数字:
The figure can be interactively explored by zooming and panning.
可以通过缩放和平移交互式地浏览该图。 To recenter on a specific region programmatically, use the following method, specifying either a radius:
若要以编程方式更新到特定区域,请使用以下方法,指定一个半径:
fig.recenter(33.23, 55.33, radius=0.3) # degrees
or a separate width and height:
或单独的宽度和高度:
fig.recenter(33.23, 55.33, width=0.3, height=0.2) # degrees
I have tested it because I also use APLpy and it works nice for me. 我已经测试过它,因为我也使用APLpy,它对我来说很好用。
HTH, HTH,
Germán. 德语。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.