Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/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_Python 2.7_Latitude Longitude_Astropy - Fatal编程技术网

Python 如何从地球定位获取天文数据,使其仅为数字(纬度、经度、高度)

Python 如何从地球定位获取天文数据,使其仅为数字(纬度、经度、高度),python,python-2.7,latitude-longitude,astropy,Python,Python 2.7,Latitude Longitude,Astropy,我使用EarthLocation获取我传播的卫星轨道的纬度、经度和高度loc=coord.EarthLocation(*itrs.cartesian.xyz)。现在,我正试图使用np.savetxt()将数据放入一个txt文件中 我希望我的数据是严格的数字,而不是它目前给我的[,,…]。有人知道怎么做吗 代码: 输出: Lat: [, , , , , ] 朗: [, , , , , ] 中高音: [, , , , , ] 时间: ['2000-01-01 12:09:16.000', '2000

我使用
EarthLocation
获取我传播的卫星轨道的纬度、经度和高度
loc=coord.EarthLocation(*itrs.cartesian.xyz)
。现在,我正试图使用
np.savetxt()
将数据放入一个txt文件中

我希望我的数据是严格的数字,而不是它目前给我的[<纬度XX.xxx度>,<纬度YY.yyy度>,…]。有人知道怎么做吗

代码:

输出:

Lat:
[, , , , , ]
朗:
[, , , , , ]
中高音:
[, , , , , ]
时间:
['2000-01-01 12:09:16.000', '2000-01-01 12:18:32.000', '2000-01-01 12:27:48.000', '2000-01-01 12:37:04.000', '2000-01-01 12:46:20.000', '2000-01-01 12:55:36.000', '2000-01-01 13:04:52.000', '2000-01-01 13:14:08.000', '2000-01-01 13:23:24.000', '2000-01-01 13:32:40.000']

您有类型为
经度
纬度
数量
的对象。它们都有一个
.value
属性。下面是一个生成此类对象的独立示例,展示了如何访问该值:

from astropy.coordinates import Longitude, Latitude
from astropy.units import Quantity
lon = Longitude('42 deg')
lon.value
lat = Latitude('42 deg')
lat.value
height = Quantity('42 meter')
height.value
因此,也许可以尝试将代码更改为
lat.append(loc.lat.value)
等,看看这是否提供了可以传递到
np.array
以生成Numpy数组或
np.savetxt
以写入txt文件的浮点列表


还可以看看
astropy.table.table
,它非常适合存储表格数据,然后将其写入CSV或FITS或其他文件格式,比仅使用Numpy数组和Numpy文本I/O函数更方便、更强大。

如果您需要特定单位的值,也可以这样做(例如
lon.to_值('radian'))
Lat:

[<Latitude 27.689176073130298 deg>, <Latitude 48.45032120487385 deg>, <Latitude 48.364205712585104 deg>, <Latitude 27.538849564221568 deg>, <Latitude -0.03713701451174661 deg>, <Latitude -27.6161238116795 deg>, <Latitude -48.41635545462272 deg>, <Latitude -48.38265336989975 deg>, <Latitude -27.529850683687265 deg>, <Latitude 0.0929886673818169 deg>]


Lon:

[<Longitude -11.245369984319288 deg>, <Longitude 24.602646508968856 deg>, <Longitude 77.51869866724904 deg>, <Longitude 113.20045826221023 deg>, <Longitude 135.11667887191157 deg>, <Longitude 157.05927178662643 deg>, <Longitude -167.1439210586291 deg>, <Longitude -114.16647366586022 deg>, <Longitude -78.40457926191569 deg>, <Longitude -56.45443351644551 deg>]


Alt:

[<Quantity 409193.55555070826 m>, <Quantity 418422.38904031017 m>, <Quantity 419775.9010528204 m>, <Quantity 412775.65686140396 m>, <Quantity 407430.35452421894 m>, <Quantity 410337.3219834759 m>, <Quantity 415810.49056818814 m>, <Quantity 414410.9036345114 m>, <Quantity 406680.40398573445 m>, <Quantity 402944.3590314008 m>]


Time:

['2000-01-01 12:09:16.000', '2000-01-01 12:18:32.000', '2000-01-01 12:27:48.000', '2000-01-01 12:37:04.000', '2000-01-01 12:46:20.000', '2000-01-01 12:55:36.000', '2000-01-01 13:04:52.000', '2000-01-01 13:14:08.000', '2000-01-01 13:23:24.000', '2000-01-01 13:32:40.000']
from astropy.coordinates import Longitude, Latitude
from astropy.units import Quantity
lon = Longitude('42 deg')
lon.value
lat = Latitude('42 deg')
lat.value
height = Quantity('42 meter')
height.value