これは日々の作業を通して学んだことや毎日の生活で気づいたことをを記録しておく備忘録である。
HTML ファイル生成日時: 2024/11/21 17:40:55.112 (台灣標準時)
astroplan を使って、日の入りから日の出の時間を調べるには以下のようにす ればよいようでござる。
#!/usr/pkg/bin/python3.9 # # Time-stamp: <2022/07/03 10:54:44 (CST) daisuke> # # importing argparse module import argparse # importing astropy module import astropy.units import astropy.time import astropy.coordinates # importing astroplan module import astroplan # units unit_m = astropy.units.m # constructing parser object desc = "finding length of night" 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) # observer object observer = astroplan.Observer (location=location, name="observer", \ timezone="UTC") # time object datetime = astropy.time.Time (datetime_str, scale='utc') # sunset sunset = observer.sun_set_time (datetime, which="nearest") # sunrise sunrise = observer.sun_rise_time (datetime, which="nearest") # length of night length_night = sunrise.mjd - sunset.mjd # printing results print ("sunset time (UT) nearest to %s (UT)" % datetime) print (" JD = %s" % sunset) print (" = %s" % sunset.isot) print ("sunrise time (UT) nearest to %s (UT)" % datetime) print (" JD = %s" % sunrise) print (" = %s" % sunrise.isot) print ("length of night on %s (UT)" % datetime) print (" length = %6.4f [day]" % length_night) print (" = %5.2f [hour]" % (length_night * 24.0) )
実行してみると、以下のようになるでござる。
% ./astroplan_sample_05.py -h usage: astroplan_sample_05.py [-h] [-l LONGITUDE] [-b LATITUDE] [-a ALTITUDE] [-t DATETIME] finding length of night 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_05.py -t 2022-07-03T16:00:00 # # input parameters # # Location: # longitude = +121d11m12s # latitude = +24d58m12s # altitude = 151.6 m # Date/Time: # date/time (UT) = 2022-07-03T16:00:00 # sunset time (UT) nearest to 2022-07-03T16:00:00.000 (UT) JD = 2459763.947916772 = 2022-07-03T10:45:00.009 sunrise time (UT) nearest to 2022-07-03T16:00:00.000 (UT) JD = 2459764.3848835514 = 2022-07-03T21:14:13.939 length of night on 2022-07-03T16:00:00.000 (UT) length = 0.4370 [day] = 10.49 [hour] % ./astroplan_sample_05.py -t 2023-01-03T16:00:00 # # input parameters # # Location: # longitude = +121d11m12s # latitude = +24d58m12s # altitude = 151.6 m # Date/Time: # date/time (UT) = 2023-01-03T16:00:00 # sunset time (UT) nearest to 2023-01-03T16:00:00.000 (UT) JD = 2459947.884945797 = 2023-01-03T09:14:19.317 sunrise time (UT) nearest to 2023-01-03T16:00:00.000 (UT) JD = 2459948.4478666475 = 2023-01-03T22:44:55.678 length of night on 2023-01-03T16:00:00.000 (UT) length = 0.5629 [day] = 13.51 [hour]