Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从天文图像制作子图_Python_Astropy_Aplpy - Fatal编程技术网

Python 从天文图像制作子图

Python 从天文图像制作子图,python,astropy,aplpy,Python,Astropy,Aplpy,我有一组RGB图像,我用aplpy制作了一个RGBfits图像,我也在图像上覆盖了一些轮廓,但我想剪切图像,并在我可以看到轮廓峰值的地方制作小尺寸图像 import aplpy import atpy from pyavm import AVM import asciitable import matplotlib import matplotlib.pyplot as plt from matplotlib.colors import LogNorm,BoundaryNorm import m

我有一组
RGB
图像,我用
aplpy
制作了一个
RGB
fits图像,我也在图像上覆盖了一些轮廓,但我想剪切图像,并在我可以看到轮廓峰值的地方制作小尺寸图像

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)  
导入aplpy
导入atpy
从pyavm导入AVM
进口腹水
导入matplotlib
将matplotlib.pyplot作为plt导入
从matplotlib.colors导入LogNorm、BoundaryNorm
导入蒙太奇包装
从astropy.io导入拟合
导入pyfits
从astropy导入wcs
fitsfile='rgb.fits'
fitsfile_2d='rgb_2d.fits'
pngfile='rgb_arcinh_contour.png'
figfile='rgb.png'
w=wcs.wcs(naxis=2)
#设置一个“艾里天顶”投影
#可以使用Python列表或Numpy数组设置向量属性
w、 wcs.crpix=[5.70000000E+03,3.0500000e+03]
w、 wcs.cdelt=np.array([-6.61111263E-05,6.61111263E-05])
w、 wcs.crval=[23.166667,-7.66666]
w、 wcs.ctype=[“RA--TAN”,“DEC--TAN”]
w、 wcs.cunit=[“度”,“度”]
#打印出WCS对象的所有内容
w、 wcs.print_contents()
#一些感兴趣的像素坐标。
pixcrd=np.array([[0,0],[24,38],[45,98]],np.float_u2;)
#将像素坐标转换为世界坐标
世界=w.wcs\U pix2world(pixcrd,1)
印刷世界
#将相同的坐标转换回像素坐标。
pixcrd2=w.wcs_world2pix(世界,1)
打印pixcrd2
#这些坐标应与原始像素坐标相同,以模为单位
#一些浮点错误。
断言np.max(np.abs(pixcrd-pixcrd2))<1e-6
#现在,写出WCS对象作为FITS头
页眉=w.至_页眉()
hdu=pyfits.open(fitsfile)
#header是astropy.io.fits.header对象。我们可以用它来创建一个新的
#PrimaryHDU并将其写入文件。
hdu=fits.PrimaryHDU(表头=表头)
#制作rgb图像
aplpy.make_rgb_图像(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,
嵌入\u avm\u标记=假)
#算计
img=aplpy.FITSFigure(fitsfile_2d)
图像显示(PNG文件)
图像设置颜色(“白色”)
标准设置(img)

如何从给定大小的图像的给定坐标生成子图?

根据APLpy文档,您可以:

默认情况下,FITSFigure会创建一个包含单个子地块的地物 占据整个图形。但是,APLpy可用于放置 现有matplotlib地物实例中的子地块。为此,, 应使用figure=参数调用FITSFigure,如下所示:

import aplpy
import matplotlib.pyplot as mpl

fig = mpl.figure()
f = aplpy.FITSFigure('some_image.fits', figure=fig)
你的数字是:

图形可以通过缩放和平移进行交互浏览。到 以编程方式在特定区域上重新居中,使用以下命令 方法,指定半径:

fig.recenter(33.23,55.33,半径=0.3)#度

或单独的宽度和高度:

fig.recenter(33.23,55.33,宽=0.3,高=0.2)#度

我已经测试了它,因为我也使用APLpy,它对我来说很好

嗯,


German.

如果只想覆盖部分轴,还可以将
子绘图
参数添加到FITSFigure。@astrofrog如何提高已保存图片的分辨率并调整合适的背景颜色?对于分辨率,请将例如
dpi=300
添加到
保存
命令中。对于背景色,您是指轴还是图形?