如何用pyephem求给定altaz坐标的北面与地平线的夹角?

2024-06-06 08:13:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我用三脚架上的照相机拍了一组天体照片。用气泡水准仪确保相框的长边与地平线平行,我知道每张照片中心的alt/az(和赤道)坐标。在

现在我正在编写一些python代码,在每个图像上覆盖一个指示器来标记北向。我可以用pyephem来得到给定的alt/az坐标下,北天极方向和水平方向之间的夹角吗?有什么线索吗?在


Tags: 代码图像天体方向alt中心气泡照片
3条回答

我会尝试为你的每个图像创建一个“世界坐标系”(WCS),这本质上是你的像素坐标和天空坐标(即RA和Dec)之间的映射。您可以使用http://astrometry.net上提供的工具,根据图像中可见的星形图案自动解决图像问题。这将为图像生成WCS。在

在天体测量.net解算器(如果安装了适当的依赖项)可以生成带有已知天体标记的png版本的图像。对于您的目的来说,这已经足够了,但是如果没有,您可以使用阿童木.wcs打包并使用它来确定图像的方向,然后根据需要标记图像。在

下面是一些快速而肮脏的代码,您可以尝试调整这些代码以适应您的目的:

import math
import subprocess
import astropy.units as u
import astropy.fits as fits

## Solve the image using the astrometry.net solve-field tool.
## You'll want to look over the options for solve-field and adapt this call
## to your images.
output = subprocess.check_output(['solve-field', filename])

## Read Header of Image (assumes you are working off a fits file with a WCS)
## If not, you can probably read the text header output my astrometry.net in
## a similar fashion.
hdulist = fits.open(solvedFilename)
header = hdulist[0].header
hdulist.close()
CD11 = float(header['CD1_1'])
CD12 = float(header['CD1_2'])
CD21 = float(header['CD2_1'])
CD22 = float(header['CD2_2'])

## This is my code to interpet the CD matrix in the WCS and determine the
## image orientation (position angle) and flip status.  I've used it and it
## seems to work, but there are some edge cases which are untested, so it
## might fail in those cases.
## Note: I'm using astropy units below, you can strip those out if you keep
## track of degrees and radians manually.
if (abs(CD21) > abs(CD22)) and (CD21 >= 0): 
    North = "Right"
    positionAngle = 270.*u.deg + math.degrees(math.atan(CD22/CD21))*u.deg
elif (abs(CD21) > abs(CD22)) and (CD21 < 0):
    North = "Left"
    positionAngle = 90.*u.deg + math.degrees(math.atan(CD22/CD21))*u.deg
elif (abs(CD21) < abs(CD22)) and (CD22 >= 0):
    North = "Up"
    positionAngle = 0.*u.deg + math.degrees(math.atan(CD21/CD22))*u.deg
elif (abs(CD21) < abs(CD22)) and (CD22 < 0):
    North = "Down"
    positionAngle = 180.*u.deg + math.degrees(math.atan(CD21/CD22))*u.deg
if (abs(CD11) > abs(CD12)) and (CD11 > 0): East = "Right"
if (abs(CD11) > abs(CD12)) and (CD11 < 0): East = "Left"
if (abs(CD11) < abs(CD12)) and (CD12 > 0): East = "Up"
if (abs(CD11) < abs(CD12)) and (CD12 < 0): East = "Down"
if North == "Up" and East == "Left": imageFlipped = False
if North == "Up" and East == "Right": imageFlipped = True
if North == "Down" and East == "Left": imageFlipped = True
if North == "Down" and East == "Right": imageFlipped = False
if North == "Right" and East == "Up": imageFlipped = False
if North == "Right" and East == "Down": imageFlipped = True
if North == "Left" and East == "Up": imageFlipped = True
if North == "Left" and East == "Down": imageFlipped = False
print("Position angle of WCS is {0:.1f} degrees.".format(positionAngle.to(u.deg).value))
print("Image orientation is North {0}, East {1}.".format(North, East))
if imageFlipped:
    print("Image is mirrored.")

## Now you have position angle and flip status and can mark up your image

为了获得正确的方向,所有这些都可以简化为:

    positionAngle = np.degrees(np.arctan2(CD12, CD11))

因为有NumPy(np)的帮助来处理所有情况下(象限)的arctan函数。在

米歇尔

编辑:如果您想检测图像是否被镜像:计算矩阵的行列式

^{pr2}$

然后检查它是否为<;0。而不是内部有镜像。在

无论你是想用十字或圆点来标记北天极,还是在地平线上的北极点做个标记,你都在问一个关于你的相机镜头的问题:你的特定镜头在你拍摄照片时所用的精确焦距时,是如何做到的,在你的平面地图上?在

这不仅是天文学面临的一个挑战,而且任何人只要拍了一张照片,然后想把它用于测量或空间计算,都会面临这样的挑战。在

我听说专业天文学家使用一个叫做FITS的库。我的印象是,如果你向图书馆解释你的相机有什么样的镜头,它会产生什么样的失真,它会告诉你每个像素的坐标——这应该能让你找到天北的点:

http://fits.gsfc.nasa.gov/fits_libraries.html

相关问题 更多 >