해와 달의 위치 파이썬으로 간단히 알아보기

페이지 정보

113 조회
5 댓글
2 추천

본문

ISS 위치에 대해 지난 번에 글을 썼는데, 하나만 하면 뭔가 허전하니(?) 또 가봅니다.

역시 원문은 제 블로그입니다.


해와 달(물론 다른 천제도)의 위치도 ISS 처럼 지구 중심으로부터 기술할 수 있습니다.
그런데, 그렇게 기술하는 건 일반적으로 별 의미가 없어요.

일단 지구 중심으로부터의 거리가 너무 멀어서 지구 중심 좌표계를 사용하면 값도 너무 커지고요...

해나 달과 같은 천체의 위치를 관측자의 위치를 기준으로 방위를 기술하는 게 더 일반적이에요.
(우주에 위성을 포함한 비행체를 올리시는 분들은 완전히 다른 세상이니 패스)


해와 달의 위치를 아주 간단히 알아보기

밖으로 나가 하늘을 보며 됩니다. (당연한 소리잖아...)

하지만, 방위와 고도를 정확한 숫자로 기술하는 것은 쉽지 않아요...


해와 달의 위치를 인터넷으로 간단히 알아보기

Time and Date와 같은 사이트를 이용하면 간단하게 해와 달의 위치를 알 수 있어요.
정확한 숫자로 위치를 알려줍니다.

한국천문연구원에서는 다양한 정보도 제공해줘요.


파이썬 프로그램으로 알아보기

하려고 하는 얘기는 이 쪽입니다.

파이썬으로 정확한 해와 달의 위치를 확인하려면 일단 관측자의 위치를 알아야 합니다.
관측자의 위치에 따라 천체의 방위는 무조건 바뀌에 되어있기 때문이에요.

MAPS.ie와 같은 사이트를 이용하면 간단하게(?) 위도와 경도를 알 수 있어요.

다음으로 필요한 라이브러리는 astral이에요.
다음과 같이 하면 간단하게 설치할 수 있어요.

pip install astral


아래의 코드는 현재 시간을 기준으로 해와 달의 위치를 알려줍니다.

관측자의 위치는 서울이에요.

from astral import LocationInfo
from astral import sun
from astral import moon
from datetime import datetime
from pytz import timezone
from pytz import utc

location=LocationInfo(name="Seoul",region="Korea",timezone="Asia/Seoul",latitude=37.46707105652381,longitude=127.07507550716402)
tm=datetime.now(tz=utc)

print('현재 시간:',tm.astimezone(timezone(location.timezone)))
print()

azimuth_sun=sun.azimuth(location.observer,tm)
zenith_sun=sun.zenith(location.observer,tm)

print('해의 방위각:',azimuth_sun)
print('해의 천정각:',zenith_sun)
print()

azimuth_moon=moon.azimuth(location.observer,tm)
zenith_moon=moon.zenith(location.observer,tm)
moon_phase=moon.phase(tm)

print('달의 방위각:',azimuth_moon)
print('달의 천정각:',zenith_moon)
print('달의 위상:',moon_phase)


실행 결과는 다음과 같아요.


현재 시간: 2024-04-02 23:19:22.573637+09:00
해의 방위각: 333.42946227699565
해의 천정각: 133.76930976393237

달의 방위각: 97.89225017980168
달의 천정각: 127.77412008449195
달의 위상: 21.889000000000003


덧1. 달의 위상은 0에서 27.99 까지의 값을 가집니다.

덧2. 방위각은 정북방향을 0도(또는 360도), 정동방향을 90도로 부르는 각입니다

덧3. 천정각은 연직방향의 직선과의 사잇각이에요. (90도-고도) 입니다.
고도를 사용해서 기술하는 경우도 많으니 참고하세요.

댓글 5

휘소님의 댓글

https://astral.readthedocs.io/en/latest/
복잡한 걸 라이브러리 하나로 끝내는군요 ㄷㄷㄷㄷㄷ

Dawn
    The time in the morning when the sun is a specific number of degrees below the horizon.
Sunrise
    The time in the morning when the top of the sun breaks the horizon (assuming a location with no obscuring features.)
Noon
    The time when the sun is at its highest point directly above the observer.
Midnight
    The time when the sun is at its lowest point.
Sunset
    The time in the evening when the sun is about to disappear below the horizon (asuming a location with no obscuring features.)
Dusk
    The time in the evening when the sun is a specific number of degrees below the horizon.
Daylight
    The time when the sun is up i.e. between sunrise and sunset
Night
    The time between astronomical dusk of one day and astronomical dawn of the next
Twilight
    The time between dawn and sunrise or between sunset and dusk
The Golden Hour
    The time when the sun is between 4 degrees below the horizon and 6 degrees above.
The Blue Hour
    The time when the sun is between 6 and 4 degrees below the horizon.
Time At Elevation
    the time when the sun is at a specific elevation for either a rising or a setting sun.
Solar Azimuth
    The number of degrees clockwise from North at which the sun can be seen
Solar Zenith
    The angle of the sun down from directly above the observer
Solar Elevation
    The number of degrees up from the horizon at which the sun can be seen
Rahukaalam
    “Rahukaalam or the period of Rahu is a certain amount of time every day that is considered inauspicious for any new venture according to Indian Vedic astrology”.
Moonrise and Moonset
    Like the Sun but for the moon
Moon Azimuth and Zenith
    Also like the Sun but for the moon
Moon Phase
    The phase of the moon for a specified date.
전체 207 / 1 페이지
전체 검색