2017-10-03 1 views
0

전 전파 된 위성 궤도의 위도, 경도 및 고도 loc = coord.EarthLocation(*itrs.cartesian.xyz)을 얻으려면 AstroPyEarthLocation을 사용했습니다. 이제 np.savetxt()을 사용하여 데이터를 txt 파일에 저장하려고합니다.EarthLocation에서 AstroPy 데이터를 얻는 방법 (Lat, Lon, Alt)

내 데이터가 [< 위도 XX.xxx deg>, < 위도 YY.yyy deg>, ...]보다 엄격하게 숫자로 표시되기를 바랍니다. 누구든지이 작업을 수행하는 방법을 알고 있습니까?

코드 :

now = []  #UTC time at each propagation step 
xyz =[]  #Xyz coordinates from OrbitalPy initial orbit propagation 
cartrep = [] #Cartesian Representation 
gcrs = [] #Geocentric Celestial Reference System/Geocentric Equatorial Inertial, the default coord system of OrbitalPy 
itrs =[]  #International Terrestrial Reference System coordinates 
lat = []  #Longitude of the location, for the default ellipsoid 
lon = []  #Longitude of the location, for the default ellipsoid 
alt = []  #Height of the location, for the default ellipsoid 


for i in range(propNum): 
    xyz = (myOrbitX[i], myOrbitY[i], myOrbitZ[i])     #Xyz coord for each prop. step 
    now = time.Time(myT[i])           #UTC time at each propagation step 
    cartrep = coord.CartesianRepresentation(*xyz, unit=u.m)   #Add units of [m] to xyz 
    gcrs = coord.GCRS(cartrep, obstime=time.Time(myT[i]))   #Let AstroPy know xyz is in GCRS 
    itrs = gcrs.transform_to(coord.ITRS(obstime=time.Time(myT[i]))) #Convert GCRS to ITRS 
    loc = coord.EarthLocation(*itrs.cartesian.xyz)     #Get lat/lon/height from ITRS 
    lat.append(loc.lat)            #Create latitude list 
    lon.append(loc.lon)            #Create longitude list 
    alt.append(loc.height)           #Create altitude list 


print('Lat:') 
print(lat) 
print('Lon:') 
print(lon) 
print('Alt:') 
print(alt) 
print('Time:') 
print(myT) 

출력 :

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'] 

답변

2

입력 Longitude, LatitudeQuantity의 개체가. 그들 모두에는 .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 배열 또는 txt 파일에 쓰기위한 np.savetxt?

도 있습니다. 표 형식의 데이터를 저장하고 CSV 또는 FITS 또는 다른 파일 형식으로 쓰는 것이 좋습니다. Numpy 배열과 Numpy 텍스트 I/O 기능을 사용하는 것보다 훨씬 편리하고 강력합니다. .

+0

또한 특정 단위로 값이 필요하면 'lon.to_value ('radian ')'과 같이 할 수 있습니다. –

관련 문제