2014-12-28 39 views
0

我有一個尺寸爲nTOAST projection行星地圖的圖像,其中n是2的冪。我想在TOAST地圖上繪製一個像素,並計算球體上相應點的緯度/經度。將TOAST地圖上的點轉換爲球體上的緯度/經度

我有以下功能,但它似乎不起作用。

def _x_y_to_lat_lon((x, y), size): 
    quad = size/2 

    if x >= quad: 
     x -= quad 
     if y >= quad: 
      quadrant = 1 
      y -= quad 
     else: 
      quadrant = 2 
      y = (quad - 1 - y) 
    else: 
     x = (quad - 1 - x) 
     if y >= quad: 
      quadrant = 0 
      y -= quad 
     else: 
      quadrant = 3 
      y = (quad - 1 - y) 

    x += 1 
    y += 1 

    ax = abs(x) 
    ay = abs(y) 
    if ax + ay > size: 
     hemisphere = -1 
    else: 
     hemisphere = 1 

    latitude = (ax + ay)/size * pi * hemisphere 
    longitude = (ax - ay)/(ax + ay) * pi/2 * hemisphere + (pi/4) + (quadrant * pi/2) 
    return latitude, longitude 

回答

2

爲了便於參考,這裏是我已經安排了八分:

enter image description here

from math import atan2, degrees 

def toast_xy_to_latlon(x, y, size, inside=False): 
    """ 
    Given TOAST x,y coordinates into a size*size HTM 
    return lat, lon 
     where -90 <= lat <= 90 (degrees North) 
     and  0 <= lon <= 360 (degrees East) 
    """ 
    half = size/2 

    # Figure out which quadrant (x, y) is in; 
    # save longitude offset and cast to first quadrant 
    # in new pixel-centered (u, v) coordinate system 
    # where 0.5 <= u,v <= half - 0.5 and (0,0) is North 
    if x < half: 
     if y < half: 
      # 6,7 
      lon_offset = 270 
      u,v = half - x - 0.5, half - y - 0.5 
     else: 
      # 0,1 
      lon_offset = 0 
      u,v = y + 0.5 - half, half - x - 0.5 
    else: 
     if y < half: 
      # 4,5 
      lon_offset = 180 
      u,v = half - y - 0.5, x + 0.5 - half 
     else: 
      # 2,3 
      lon_offset = 90 
      u, v = x + 0.5 - half, y + 0.5 - half 

    # Find latitude 
    lat = 90 * (1 - (u + v)/half) 

    # Find longitude 
    if u + v <= half: 
     # Northern hemisphere 
     lon = degrees(atan2(u, v)) 
    else: 
     # Southern hemisphere 
     lon = degrees(atan2(half - v, half - u)) 

    # Correct longitude offset - 
    # outside projection longitudes are measured CCW from left, 
    # inside projections CCW from right (rotated 180 degrees) 
    if inside: 
     lon_offset = (lon_offset + 180) % 360 

    return lat, lon + lon_offset 
+0

非常感謝。你也不會碰巧也有相反的功能,是嗎? – Drakekin

+0

@Drakekin最好問一下,作爲一個新問題,引用這個問題 – theheadofabroom

0

第二種解決方案也是不完全正確。它給出了一個奇怪的非線性經度。 45度,135度,225度和315度的經度過度膨脹,0,90,180和270度的經度過度縮小。原因是TOAST投影中的經度等於atan2(u/v)的角度這是不正確的。經度是緯度不變的線的距離,而不是一個角度。見草圖。

如果TOAST投影的原點(0,0)位於中間且X:= V且Y:= V且均爲正值,則草圖中恆星的RA,DEC將爲:

緯度或天空偏角:=(y + x-1)* pi/2;

經度或天空right_ascension:= 0.5 * pi *(1-x /(y + x));

應用此公式中TOAST投影所有8個三角形每次用正確的校正如下:

(1)首先使X,Y正和在範圍[0..1]從極。

(2)將上述式

(3)應用經度/ DEC和緯度/ RA校正/每次移位用於每個三角形。

注意到Microsoft TOAST程序不會在極點附近形成直線偏移/緯線。我的例程呢。

TOAST projection of the sky in RA, DEC

相關問題