これは日々の作業を通して学んだことや毎日の生活で気づいたことをを記録しておく備忘録である。
HTML ファイル生成日時: 2024/12/05 07:26:42.662 (台灣標準時)
astropy を使って、与えられた場所での与えられた時間での太陽の座標を調べ るには、以下のようにすればよいようでござる。
#!/usr/pkg/bin/python3.9 # # Time-stamp: <2022/07/03 10:40:02 (CST) daisuke> # # importing argparse module import argparse # importing astropy module import astropy.units import astropy.time import astropy.coordinates # importing ssl module import ssl # allow insecure downloading ssl._create_default_https_context = ssl._create_unverified_context # units unit_m = astropy.units.m # constructing parser object desc = "position of the Sun in (RA, Dec) at given location and time" parser = argparse.ArgumentParser (description=desc) # adding arguments parser.add_argument ('-l', '--longitude', default='+121d11m12s', \ help='longitude of observing site in format "+121d11m12s"') parser.add_argument ('-b', '--latitude', default='+24d58m12s', \ help='latitude of observing site in format "+24d58m12s"') parser.add_argument ('-a', '--altitude', type=float, default=151.6, \ help='altitude above sea-level in metre') parser.add_argument ('-t', '--datetime', default='2000-01-01T12:00:00.000', \ help='date/time in UT in "YYYY-MM-DDThh:mm:ss.sss" format') # command-line argument analysis args = parser.parse_args () # input parameters site_lon = args.longitude site_lat = args.latitude site_alt = args.altitude * unit_m datetime_str = args.datetime # printing input parameters print ("#") print ("# input parameters") print ("#") print ("# Location:") print ("# longitude =", site_lon) print ("# latitude =", site_lat) print ("# altitude =", site_alt) print ("# Date/Time:") print ("# date/time (UT) =", datetime_str) print ("#") # location object location = astropy.coordinates.EarthLocation.from_geodetic \ (site_lon, site_lat, site_alt) # time object datetime = astropy.time.Time (datetime_str, scale='utc') # using DE430 astropy.coordinates.solar_system_ephemeris.set ('de430') # position of the Sun sun = astropy.coordinates.get_body ('sun', datetime, location) (sun_ra, sun_dec) = sun.to_string ('hmsdms').split () # conversion from equatorial into ecliptic sun_ecliptic = sun.transform_to \ (astropy.coordinates.GeocentricMeanEcliptic (obstime=datetime) ) sun_lambda = sun_ecliptic.lon sun_beta = sun_ecliptic.lat # conversion from equatorial into horizontal sun_altaz = sun.transform_to \ (astropy.coordinates.AltAz (obstime=datetime, location=location) ) sun_alt = sun_altaz.alt sun_az = sun_altaz.az # printing position of the Sun print ("Sun:") print (" Equatorial: (RA, Dec) = (%s, %s)" % (sun_ra, sun_dec) ) print (" Ecliptic: (lambda, beta) = (%s, %s)" % (sun_lambda, sun_beta) ) print (" AltAz: (Az, Alt) = (%s, %s)" % (sun_az, sun_alt) )
実行してみると、以下のようになるでござる。
% ./astroplan_sample_03.py -h usage: astroplan_sample_03.py [-h] [-l LONGITUDE] [-b LATITUDE] [-a ALTITUDE] [-t DATETIME] position of the Sun in (RA, Dec) at given location and time optional arguments: -h, --help show this help message and exit -l LONGITUDE, --longitude LONGITUDE longitude of observing site in format "+121d11m12s" -b LATITUDE, --latitude LATITUDE latitude of observing site in format "+24d58m12s" -a ALTITUDE, --altitude ALTITUDE altitude above sea-level in metre -t DATETIME, --datetime DATETIME date/time in UT in "YYYY-MM-DDThh:mm:ss.sss" format % ./astroplan_sample_03.py -t 2022-07-03T04:00:00 # # input parameters # # Location: # longitude = +121d11m12s # latitude = +24d58m12s # altitude = 151.6 m # Date/Time: # date/time (UT) = 2022-07-03T04:00:00 # Sun: Equatorial: (RA, Dec) = (06h47m32.47569282s, +22d59m12.51257435s) Ecliptic: (lambda, beta) = (100d55m45.62031139s, -0d00m09.3442212s) AltAz: (Az, Alt) = (183d23m17.48446394s, 87d59m20.74531916s)