2014-12-02 50 views
0

我有一套RGB圖像和我作了RGB適合圖像與aplpy和我也覆蓋圖像上的一些輪廓,但我想剪切圖像,使小圖像適合圖像我會看到輪廓的峯值。從一個天文合適的圖像做出subplots

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) 

我怎麼能產生從圖像中的給定座標的次要情節與給定的大小?

回答

1

按照APLpy文檔,可以使subplots

默認情況下,FITSFigure創建了一個插曲是 佔據整個圖形的圖形。但是,APLpy可用於將 子圖放置在現有的matplotlib圖形實例中。要做到這一點, FITSFigure應與圖中可以稱爲=參數如下:

import aplpy 
import matplotlib.pyplot as mpl 

fig = mpl.figure() 
f = aplpy.FITSFigure('some_image.fits', figure=fig) 

recenter您的數字:

圖中可以通過縮放和平移交互地探索。到 recenter上的特定區域以編程,使用下列 方法,指定任一個半徑:

fig.recenter(33.23, 55.33, radius=0.3) # degrees

或單獨的寬度和高度:

fig.recenter(33.23, 55.33, width=0.3, height=0.2) # degrees

我已經測試這是因爲我也使用APLpy,它對我很好。

HTH,

Germán。

+0

如果您只想覆蓋部分軸,您也可以將「subplot」參數添加到FITSFigure。 – astrofrog 2014-12-03 12:37:21

+0

@astrofrog如何提高保存的圖片的分辨率並調整合適的背景顏色? – Dalek 2014-12-03 14:50:06

+0

對於分辨率,添加例如''保存''命令的''dpi = 300''。對於背景顏色,你的意思是軸還是數字? – astrofrog 2014-12-04 15:09:56