小编Ben*_*ose的帖子

使用python查找拟合文件中像素的物理坐标

我想从python脚本中获取给定像素的物理天空坐标.我想使用astropy的WCS,但我会在python中做任何事情.

我试过这两段代码.

from astropy.io import fits
from astropy.wcs import WCS

def astropymethod1(img):
    # from http://astropy.readthedocs.org/en/latest/wcs/
    w = WCS(img)
    lon, lat = w.all_pix2world( 100., 100., 1)
    print lon, lat

def astropymethod2(img):
    # from http://astropy.readthedocs.org/en/latest/wcs/
    hdu = fits.open(img)
    w = WCS(hdu[0].header)
    lon, lat = w.wcs_pix2world(100., 100., 1)
    print lon, lat
Run Code Online (Sandbox Code Playgroud)

问题是我第一次尝试使用WCS时出现错误,结果只是我输入的像素值.

WARNING: FITSFixedWarning: The WCS transformation has more axes (2) than the image it is associated with (0) [astropy.wcs.wcs]
Run Code Online (Sandbox Code Playgroud)

python wcs fits astropy

7
推荐指数
1
解决办法
2628
查看次数

Python:像二维数组一样从字典中提取数据

我有一个 python 字典,其中所有值都是相同长度的数组。我希望能够通过元素编号提取这些值。

我有一本这样的字典:

dictionary = { 'key1': [1,2,3], 'key2': [4,5,6], 'key3': [7,8,9] }
Run Code Online (Sandbox Code Playgroud)

在调用参数 1 时,我想要这个输出:

[2,5,8]
Run Code Online (Sandbox Code Playgroud)

我拥有的最好的是

[dictionary.values()[0][1], dictionary.values()[1][1], dictionary.values()[2][1] ]
Run Code Online (Sandbox Code Playgroud)

因为

dictioinary.values()[:][1]
Run Code Online (Sandbox Code Playgroud)

即使 dictionary.values() 返回一个列表也不起作用。

或者将这些数据存储在二维数组中或使用 numpy 会更容易吗?我想使用字典,以便我可以通过键调用数据。

python dictionary numpy

2
推荐指数
1
解决办法
8702
查看次数

标签 统计

python ×2

astropy ×1

dictionary ×1

fits ×1

numpy ×1

wcs ×1