def eop(self):

        IERS_A_in_cache()
        # astroplan.get_IERS_A_or_workaround()
        iers.conf.auto_download = False
        iers.conf.auto_max_age = None
        now = Time.now()

        longitude = '78d57m53s'
        latitude = '32d46m44s'
        elevation = 4500 * u.m
        location = EarthLocation.from_geodetic(longitude, latitude, elevation)
        iaohanle = Observer(location=location,
                            timezone='Asia/Kolkata',
                            name="IAO",
                            description="IAO Hanle telescopes")
        iaohanle
        # Calculating the sunset, midnight and sunrise times for our observatory
        sunset_iao = iaohanle.sun_set_time(now, which='nearest')
        eve_twil_iao = iaohanle.twilight_evening_astronomical(now,
                                                              which='nearest')
        midnight_iao = iaohanle.midnight(now, which='next')
        morn_twil_iao = iaohanle.twilight_morning_astronomical(now,
                                                               which='next')
        sunrise_iao = iaohanle.sun_rise_time(now, which='next')
        moon_rise = iaohanle.moon_rise_time(eve_twil_iao, which='nearest')
        moon_set = iaohanle.moon_set_time(now, which='nearest')
        # moon_alt = iaohanle.moon_altaz(now).alt
        # moon_az = iaohanle.moon_altaz(now).az
        #lst_now = iaohanle.local_sidereal_time(now)
        #lst_mid = iaohanle.local_sidereal_time(midnight_iao)
        #print("LST at IAO now is {0:.2f}".format(lst_now))
        #print("LST at IAO at local midnight will be {0:.2f}".format(lst_mid))

        Automation.moon_strength = moon_illumination(midnight_iao)

        observing_time = (morn_twil_iao - eve_twil_iao).to(u.h)
        #print("Total Night hours at IAO tonight  {0:.1f}  ".format(observing_time))

        img = Image.new('RGB', (850, 320), color=(0, 0, 0))
        fnt = ImageFont.truetype(
            '/var/lib/defoma/gs.d/dirs/fonts/DejaVuSerif.ttf', 15)
        d = ImageDraw.Draw(img)
        d.text((10, 11),
               "IAO Hanle Coordinates:   " + str(iaohanle),
               font=fnt,
               fill=(255, 255, 255))

        d.text((10, 71),
               "Moon Illumination Strength          : " +
               str(moon_illumination(midnight_iao)),
               font=fnt,
               fill=(255, 255, 255))
        d.text((10, 101),
               "Sunset                                       : " +
               Time(sunset_iao, out_subfmt='date_hms').iso + " UTC",
               font=fnt,
               fill=(255, 255, 255))
        d.text((10, 131),
               "Astronomical evening twilight : " +
               Time(eve_twil_iao, out_subfmt='date_hms').iso + " UTC",
               font=fnt,
               fill=(255, 255, 255))
        d.text((10, 161),
               "Astronomical morning twilight : " +
               Time(morn_twil_iao, out_subfmt='date_hms').iso + " UTC",
               font=fnt,
               fill=(255, 255, 255))
        d.text((10, 191),
               "Sunrise                                   : " +
               Time(sunrise_iao, out_subfmt='date_hms').iso + " UTC",
               font=fnt,
               fill=(255, 255, 255))
        d.text((10, 221),
               "Moon Rise                    : " +
               Time(moon_rise, out_subfmt='date_hms').iso + " UTC",
               font=fnt,
               fill=(255, 255, 255))

        d.text((10, 251),
               "Moon Set                    : " +
               Time(moon_set, out_subfmt='date_hms').iso + " UTC",
               font=fnt,
               fill=(255, 255, 255))
        d.text((10, 281),
               "Total Astronomical hours tonight                    : " +
               str(observing_time),
               font=fnt,
               fill=(255, 255, 255))
        img.save('tonight.png')
        img.close()

        t_start = eve_twil_iao
        t_end = morn_twil_iao

        # We can turn solar system objects into 'pseudo-fixed' targets to plan observations
        mercury_midnight = FixedTarget(name='Mercury',
                                       coord=get_body('mercury', midnight_iao))
        mercury_midnight.coord
        venus_midnight = FixedTarget(name='Venus',
                                     coord=get_body('venus', midnight_iao))
        venus_midnight.coord

        uranus_midnight = FixedTarget(name='Uranus',
                                      coord=get_body('uranus', midnight_iao))
        uranus_midnight.coord
        neptune_midnight = FixedTarget(name='Neptune',
                                       coord=get_body('neptune', midnight_iao))
        neptune_midnight.coord

        saturn_midnight = FixedTarget(name='Saturn',
                                      coord=get_body('saturn', midnight_iao))
        saturn_midnight.coord

        jupiter_midnight = FixedTarget(name='Jupiter',
                                       coord=get_body('jupiter', midnight_iao))
        jupiter_midnight.coord

        mars_midnight = FixedTarget(name='Mars',
                                    coord=get_body('mars', midnight_iao))
        mars_midnight.coord

        targets = [
            mercury_midnight, venus_midnight, mars_midnight, jupiter_midnight,
            saturn_midnight, uranus_midnight, neptune_midnight
        ]
        targets

        #for target in targets:
        #print(iaohanle.target_rise_time(now, target, which='next', horizon=10 * u.deg).iso)

        # iaohanle.altaz(now, targets[0])

        # print(iaohanle.target_rise_time(now, target, which='next', horizon=10 * u.deg).iso)

        # iaohanle.altaz(now, targets[0])

        times = (t_start - 0.5 * u.h) + (t_end - t_start +
                                         1 * u.h) * np.linspace(0.0, 1.0, 20)
        for target in targets:
            plot_sky(target, iaohanle, times)
        plt.legend(loc=[1.0, 0])
        plt.xlabel('Planets motion tonight')

        # plt.ylim(4,0.5)
        # plt.legend()
        plt.savefig('planets_motion.png')
        plt.close()

        # plt.legend(loc=[1.1,0])

        coords1 = SkyCoord(
            '15h58m3s', '-18d10m0.0s',
            frame='icrs')  # coordinates of Andromeda Galaxy (M32)
        tt1 = FixedTarget(name='Moon', coord=coords1)

        tt1.coord
        t_observe = t_start + (t_end - t_start) * np.linspace(0.0, 1.0, 20)
        plot_sky(tt1, iaohanle, t_observe)
        plt.xlabel('Moon motion tonight')
        plt.savefig('moon_motion.png')
        plt.close()

        if (eve_twil_iao <= now):
            Automation.eve_twilight_flag = 1
            Automation.mor_twilight_flag = 0
            Automation.moon_setting_flag = 0
        elif (morn_twil_iao <= now):
            Automation.eve_twilight_flag = 0
            Automation.mor_twilight_flag = 1
            Automation.moon_setting_flag = 0
        elif (Automation.moon_strength > 0.30):
            if (moon_rise <= now):
                Automation.eve_twilight_flag = 0
                Automation.mor_twilight_flag = 0
                Automation.moon_setting_flag = 1
            elif (moon_set <= now):
                Automation.eve_twilight_flag = 1
                Automation.mor_twilight_flag = 0
                Automation.moon_setting_flag = 0
Ejemplo n.º 2
0
import numpy as np

from astroplan import Observer
from astropy.coordinates import EarthLocation
import astropy.units as u
from astropy.time import Time

observer = Observer(longitude=-70.7494 * u.deg,
                    latitude=-30.2444 * u.deg,
                    elevation=2650.0 * u.m,
                    name="LSST")

mjd_start = 59853.5

times = Time(np.arange(mjd_start, mjd_start + 356.25 * 3, .3), format='mjd')

tt = observer.twilight_evening_astronomical(times)

ack = observer.moon_rise_time(times)

round_ack = np.round(ack.mjd, decimals=5)
Ejemplo n.º 3
0
    names = [
        'night', 'sunset', 'sun_n12_setting', 'sun_n18_setting',
        'sun_n18_rising', 'sun_n12_rising', 'sunrise', 'moonrise', 'moonset'
    ]
    types = [int]
    types.extend([float] * (len(names) - 1))
    almanac = np.zeros(sunsets.size, dtype=list(zip(names, types)))
    almanac['sunset'] = sunsets

    times = Time(sunsets, format='mjd')
    print('evening twilight 1')
    almanac['sun_n12_setting'] = observer.twilight_evening_nautical(times).mjd
    almanac['sun_n18_setting'] = observer.twilight_evening_astronomical(
        times).mjd
    almanac['sun_n18_rising'] = observer.twilight_morning_astronomical(
        times).mjd
    almanac['sun_n12_rising'] = observer.twilight_morning_nautical(times).mjd
    almanac['sunrise'] = observer.sun_rise_time(times).mjd
    almanac['moonset'] = observer.moon_set_time(times).mjd
    print('moonrise')
    almanac['moonrise'] = observer.moon_rise_time(times).mjd
    results.append(almanac)

almanac = np.concatenate(results)
umjds, indx = np.unique(almanac['sunset'], return_index=True)
almanac = almanac[indx]
almanac['night'] = np.arange(almanac['night'].size)

np.savez('sunsets.npz', almanac=almanac)
Ejemplo n.º 4
0
lokasi = Observer(name='Siak', location=location)  #GMS

time = Time('2019-12-26')  #UTC
midnight = Time(lokasi.midnight(time).iso)
delta_md = np.linspace(-5, 5, 22) * u.hour
win_time = midnight + delta_md
night = win_time
# day = (midnight + 12*u.hour) + delta_md
day = (midnight + 12 * u.hour) + np.linspace(0, 3, 30) * u.hour  # GMS
op = pd.read_csv('op.csv', index_col='nama')
ra = op.ra
dec = op.dec

sunset = lokasi.sun_set_time(time)
sunrise = lokasi.sun_rise_time(time)
moonrise = lokasi.moon_rise_time(time)
moonset = lokasi.moon_set_time(time)
moon_ill = lokasi.moon_illumination(time)
moonaltaz = lokasi.moon_altaz(time)
moonaltaz.name = 'moon'
sunaltaz = lokasi.sun_altaz(time)
sunaltaz.name = 'sun'


def objek(nama, ra, dec):
    op = SkyCoord(ra, dec, frame='icrs', unit='deg')
    op_name = FixedTarget(coord=op, name=nama)
    # betelgeus = SkyCoord.from_name('betelgeuse')
    # altaz_frame = lokasi.altaz(time)  # ubah lokasi pengamat ke altaz frame
    # betelgeus_altaz = betelgeus.transform_to(altaz_frame)  # ubah target ke altaz
    altaz = lokasi.altaz(win_time, op)
Ejemplo n.º 5
0
    'sun_n12_rising', 'sunrise', 'moonrise', 'moonset'
]
types = [int]
types.extend([float] * (len(names) - 1))
base_al = np.zeros(1, dtype=list(zip(names, types)))

while mjd < (mjd_start + duration):
    times = Time(mjd, format='mjd')
    sunsets = observer.sun_set_time(times, which='next')
    times = sunsets

    almanac = base_al.copy()
    almanac['sunset'] = sunsets.mjd

    almanac['moonset'] = observer.moon_set_time(times, which='next').mjd
    almanac['moonrise'] = observer.moon_rise_time(times, which='next').mjd
    almanac['sun_n12_setting'] = observer.twilight_evening_nautical(
        times, which='next').mjd
    times = observer.twilight_evening_astronomical(times, which='next')
    almanac['sun_n18_setting'] = times.mjd
    almanac['sun_n18_rising'] = observer.twilight_morning_astronomical(
        times, which='next').mjd
    almanac['sun_n12_rising'] = observer.twilight_morning_nautical(
        times, which='next').mjd
    almanac['sunrise'] = observer.sun_rise_time(times, which='next').mjd
    results.append(almanac)
    mjd = almanac['sunrise'] + t_step

    progress = (mjd - mjd_start) / duration * 100
    text = "\rprogress = %.2f%%" % progress
    sys.stdout.write(text)