python - 如何使用 pyephem 找到给定 altaz 坐标的北与地平线之间的角度?

标签 python coordinates astronomy pyephem

我有一组用三脚架上的相机拍摄的许多天文照片。使用气泡水平仪确保框架的长边与地平线平行,并且我知道每张照片中心的 alt/az(和赤道)坐标。

现在我正在编写一些 python 代码,在每个图像上叠加一个指示器来标记北方向。我可以使用 pyephem 来获取给定 alt/az 坐标的北天极方向与水平方向之间的角度吗?有什么线索吗?

最佳答案

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

astrometry.net 解算器(如果您安装了适当的依赖项)可以生成图像的 png 版本,并标记了已知的天体。这可能足以满足您的目的,但如果还不够,您可以使用 astropy.wcs 包将图像 WCS 读取到 python 中,并使用它来确定图像的方向,然后根据您的喜好标记图像。

这里有一些快速但肮脏的代码,您可以尝试根据您的目的进行调整:

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

关于python - 如何使用 pyephem 找到给定 altaz 坐标的北与地平线之间的角度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17332853/

相关文章:

python - 使用 Pandas 渲染来自 BigQuery 的 JSON 响应?

python - 极坐标到笛卡尔返回奇怪的结果

Objective-C 天文学库

VB.net -- 在窗体外获取鼠标坐标

python - 使用相同的投影在图像上绘制线条

time - 如何计算日出/日落时间?

python - 检查多个子字符串是否在 Pandas 数据框中

python - Gspread 将电子表格导出到带格式的文件系统

python - 如何使用 Python 将备用空行插入到表格中?

java - 二维数组中两点之间的计算