コード例 #1
0
    def resolve_target(self, itar):

        info = self.info[itar]

        # First simply try to resolve with the name and return
        try:
            target = FixedTarget.from_name(info['pl_name'])
            return target
        except NameResolveError as e:
            print(e)
            pass

        # If failed, try to change the name
        try:
            try_name = ' '.join(info['pl_name'].split(' ')[:-2])
            print("Trying with {}".format(try_name))
            target = FixedTarget.from_name(try_name)
        # Finally, try with ra and dec
        except NameResolveError as e:
            print(e)
            print('Searching with RA and dec')
            ra = info['ra'].quantity
            dec = info['dec'].quantity
            coord = SkyCoord(ra=ra, dec=dec)
            target = FixedTarget(coord=coord, name=info['pl_name'])

        return target
コード例 #2
0
def get_star_info(obj):
    star = FixedTarget.from_name(obj)
    is_up = location.target_is_up(time, star)

    if not is_up:
        return None, None, None, is_up

    rise_time = location.target_rise_time(time, star)
    set_time = location.target_set_time(time, star)
    altitude_at_rise = location.altaz(rise_time, star).alt
    return rise_time, set_time, altitude_at_rise, is_up
コード例 #3
0
    def lecture_cible(self, evt):
        """ Lecture des coordonnées de la cible dans le fichier d'abord, puis via internet

        :param evt: évènement WX
        :return:
        """
        nom_cible = evt.GetString()
        coord = None
        try:
            # on cherche dans le fichier local
            cible = [
                element for element in self.cibles
                if element['Nom'].lower() == nom_cible.lower()
            ][0]
            coord = SkyCoord(cible['Alpha'], cible['Delta'])
        except IndexError:
            # la cible n'a pas été trouvée dans le fichier
            # on essaie via internet
            try:
                cible = FixedTarget.from_name(nom_cible)
                coord = cible.coord
                alpha_delta = coord.to_string('hmsdms').split()
                self.cibles.append(
                    dict([('Nom', nom_cible), ('Alpha', alpha_delta[0]),
                          ('Delta', alpha_delta[1])]))
                self.ecriture_fichier_csv(self.fichier_csv_cibles)
                self.colore_champs_etoile(couleur_normale)
            except astropy.coordinates.name_resolve.NameResolveError:
                # la cible n'a nom plus pas été trouvée sur Simbad
                self.colore_champs_etoile(couleur_erreur)
                self.boite_erreur(
                    'Impossible de trouver {0}'.format(nom_cible))
        finally:
            if coord:
                self.edit_heure_alpha.SetValue(str(int(coord.ra.hms[0])))
                self.edit_minute_alpha.SetValue(
                    str(int(coord.ra.hms[1] + coord.ra.signed_dms[2] / 60.0)))
                self.edit_degre_delta.SetValue(
                    str(int(coord.dec.signed_dms[1])))
                self.edit_minute_delta.SetValue(
                    str(
                        int(coord.dec.signed_dms[2] +
                            coord.dec.signed_dms[2] / 60.0)))
                self.br_signe_delta.SetSelection(
                    int((1 - int(coord.dec.signed_dms[0]) / 2)))
                self.signe_delta = int(
                    coord.dec.signed_dms[0]
                )  # Pas d'évènement généré quand on change la sélection d'une radiobox
                self.edit_cible.SetValue(nom_cible)
                self.nom_cible = nom_cible
                self.bouton_calcul.Enable()
            else:
                self.bouton_calcul.Disable()
コード例 #4
0
def test_event_observable():

    epoch = Time(2452826.628514, format='jd')
    period = 3.52474859 * u.day
    duration = 0.1277 * u.day

    hd209458 = EclipsingSystem(primary_eclipse_time=epoch, orbital_period=period, duration=duration,
                               name='HD 209458 b')
    observing_time = Time('2017-09-15 10:20')

    apo = Observer.at_site('APO')

    target = FixedTarget.from_name("HD 209458")
    n_transits = 100  # This is the roughly number of transits per year
    ing_egr = hd209458.next_primary_ingress_egress_time(observing_time,
                                                        n_eclipses=n_transits)
    constraints = [AltitudeConstraint(min=0*u.deg), AtNightConstraint()]
    observable = is_event_observable(constraints, apo, target,
                                     times_ingress_egress=ing_egr)

    # This answer was validated against the Czech Exoplanet Transit Database
    # transit prediction service, at:
    # http://var2.astro.cz/ETD/predict_detail.php?delka=254.1797222222222&submit=submit&sirka=32.780277777777776&STARNAME=HD209458&PLANET=b
    # There is some disagreement, as the ETD considers some transits which begin
    # before sunset or after sunrise to be observable.
    cetd_answer = [[False, False, False, True, False, True, False, True, False,
                    True, False, True, False, False, False, False, False, False,
                    False, False, False, False, True, False, True, False, False,
                    False, False, False, False, False, False, False, False, False,
                    False, False, False, False, False, False, False, False, False,
                    False, False, False, False, False, False, False, False, False,
                    False, False, False, True, False, False, False, False, False,
                    False, False, False, False, False, False, False, False, False,
                    True, False, True, False, False, False, False, False, False,
                    False, False, False, False, False, False, True, False, True,
                    False, True, False, True, False, True, False, True, False,
                    False]]

    assert np.all(observable == np.array(cetd_answer))
コード例 #5
0
def get_observability_fraction(name="WASP 4", site='keck', ra=None, dec=None,
                               start_time=Time('2019-09-13 20:00:00'),
                               end_time=Time('2020-07-31 20:00:00')):

    if isinstance(name,str) and ra is None and dec is None:
        target = FixedTarget.from_name(name)
    elif isinstance(ra,float) and isinstance(dec,float):
        target_coord = SkyCoord(ra=ra*u.deg, dec=dec*u.deg)
        target = FixedTarget(coord=target_coord, name=name)
    else:
        raise NotImplementedError('failed to make target')

    observer = Observer.at_site(site)

    constraints = [AltitudeConstraint(min=20*u.deg, max=85*u.deg),
                   AirmassConstraint(3),
                   AtNightConstraint.twilight_civil()]

    # over every day between start and end time, check if the observing
    # constraints are meetable.
    days = Time(
        np.arange(start_time.decimalyear, end_time.decimalyear,
                  1/(365.25)),
        format='decimalyear'
    )

    frac, ever_observable = [], []

    for day in days:

        table = observability_table(constraints, observer, [target],
                                    time_range=day)
        frac.append(float(table['fraction of time observable']))
        ever_observable.append(bool(table['ever observable']))

    ever_observable = np.array(ever_observable)
    frac = np.array(frac)

    return frac, ever_observable, days
コード例 #6
0
def read_transits(file, site='Keck', frac=1.0):
	"""
	read transits from exoplanet archive transit planner CSV file

	site options from astroplan: e.g. KPNO, Keck
	"""


	data = Table.read(file,format='ascii')

	startimes = data['targetobsstartcalendar']
	endtimes  = data['targetobsendcalendar']
	midtimes  = data['midpointcalendar']
	duration  = data['transitduration']
	fracs     = data['fractionobservable']

	full_transits =  np.where(fracs>=frac)[0]

	target = FixedTarget.from_name(planet.strip('b'))
	obs    = Observer.at_site(site)

	return startimes[full_transits], endtimes[full_transits], midtimes[full_transits], duration[full_transits], target, obs
コード例 #7
0
def create_real_times(tmin,tmax,ndata=50,air_mass_limit=1.5,tformat='mjd',star='K2-100',observatory='lapalma'):
    times = []
    #Create a observatory instance with astroplan
    observatory = Observer.at_site(observatory)
    #Create star object from astroplan, the name has to be a valid simbad name for the target
    star = FixedTarget.from_name(star)
    while len(times) < ndata:
        #Draw random time between tmin and tmax
        drt = np.random.uniform(tmin,tmax)
        #Get the time object from astropy.time
        time = Time(drt,format=tformat)
        #Compute the air_mass that the target has at time t
        air_mass = observatory.altaz(time,star).secz
        #If the target is observable at time drt and the air_mass < air_mass_limit then
        #We accept the dummy random time
        if observatory.target_is_up(time,star) and air_mass < air_mass_limit:
            times.append(drt)

    #Sort thet times
    times = sorted(times)

    #Return a numpy array with all the times
    return np.array(times)
コード例 #8
0
A target object defines a single observation target, with coordinates
and an optional name.
'''
from astroplan import FixedTarget

# Define a target.

from astropy.coordinates import SkyCoord
t1 = FixedTarget(name='Polaris',
                 coord=SkyCoord('02h31m49.09s', '+89d15m50.8s', frame='icrs'))

# Leaves scope for NonSiderealTarget, etc.

# Convenience methods for looking up/constructing targets by name via
# astroquery:
t1 = FixedTarget.from_name('Polaris')

# ================================
# Condition objects, observability
# ================================

"""
Q: Can I observe this target on the night of May 1, 2015 between 18:30
and 05:30 HST, above airmass 1.2, on a telescope that can observe between
15 degrees and 89 degrees altitude?
"""

# first we define the conditions
from astroplan import TimeRange, AltitudeRange, AirmassRange, is_observable
# `is_observable` is a temporary function which will eventually be a method of
# something to support caching
コード例 #9
0
from astroplan import EclipsingSystem
from astroplan import is_event_observable
from astroplan import PrimaryEclipseConstraint
from astroplan import AtNightConstraint
from astroplan import AltitudeConstraint
from astroplan import TimeConstraint
from pytz import timezone

# Download updated bulletin table
from astroplan import download_IERS_A
# download_IERS_A()

# Our target is an explanet in HAT-P-32, a G or F-type dwarf star
# 860 light years away with an apparent magnitude of 11.197
# at 02h04m10.28s +46d41m16.2s
HATP32 = FixedTarget.from_name('HAT-P-32')

# I used the data from the desert museum, which is close
# close to our observation site. I average temp and humidity
# measures for observation months.
latitude = '+32d14m38.45s'
longitude = '-111d10m5.43s'
elevation = 867.2962 * u.m
location = EarthLocation.from_geodetic(longitude, latitude, elevation)

observer = Observer(
    name='BB/RH Tucson',
    location=location,
    pressure=0.91 * u.bar,
    relative_humidity=0.25,
    temperature=20.0 * u.deg_C,
コード例 #10
0
from astroplan import FixedTarget

# From skyandtelescope.com/
#       observing/colored-double-stars-real-and-imagined/
eta_cassiopeiae = FixedTarget.from_name('eta Cas')
one_arietis = FixedTarget.from_name('1 Ari')
gamma_andromedae = FixedTarget.from_name('gamma_and')
iota_trianguli = FixedTarget.from_name('iot Tri')
eta_persei = FixedTarget.from_name('eta Per')
thirtytwo_eridani = FixedTarget.from_name('32 Eri')
rho_orionis = FixedTarget.from_name('rho Ori')
fourteen_aurigae = FixedTarget.from_name('14 Aur')
iota_orionis = FixedTarget.from_name('iot Ori')
gamma_leporis = FixedTarget.from_name('gam Lep')
winter_albireo = FixedTarget.from_name('145 CMa')
iota_cancri = FixedTarget.from_name('iot Cnc')
twentyfour_comae_berenices = FixedTarget.from_name('24 Com')
xi_bootes = FixedTarget.from_name('xi Boo')
alpha_herculis = FixedTarget.from_name('alp Her')
ninetyfive_herculis = FixedTarget.from_name('95 Her')
zeta_lyrae = FixedTarget.from_name('zet Lyr')
albireo = FixedTarget.from_name('Albireo')
thirtyone_cygni = FixedTarget.from_name('31 Cyg')
beta_capricorni = FixedTarget.from_name('bet Cap')
gamma_delphini = FixedTarget.from_name('gam Del')
delta_cephei = FixedTarget.from_name('del Cep')
コード例 #11
0
if "__main__":

	args = cli()
	fov = args.fov

	try:
		targets = np.genfromtxt(args.file,dtype=None)
	except:
		targets = np.atleast_2d(np.array([args.file, "0:0:0", "0:0:0"]))

	for t in targets:
		objname = t[0].upper()
		
		# From coordinates
		if args.COORD:
			ra,dec = t[1], t[2]
			try:
				radeg 	= ra.astype('float')
				decdeg 	= dec.astype('float')
			except:
				radeg,decdeg = sexa2deg([ra,dec])
			mycoord = SkyCoord(ra=radeg*u.deg,dec=decdeg*u.deg,frame='fk5')
			object = FixedTarget(coord=mycoord, name=t[0].upper())

		# From object name
		else:
			object = FixedTarget.from_name(objname)
		ax, hdu = plot_finder_image(object,reticle=True,fov_radius=fov*u.arcmin)
		plt.savefig(objname+'.jpg')
		plt.close()
コード例 #12
0
# Check sec(z) for each target and return target name with starting altitude and azimuth
def check_secz(target, start_time, end_time, secz_max=2.0):
    start_secz = schoolyard_observatory.altaz(start_time, target).secz
    end_secz = schoolyard_observatory.altaz(end_time, target).secz
    start_altaz = schoolyard_observatory.altaz(start_time, target)
    if start_secz < 2.0 or end_secz < 2.0:
        # print('{}: \tsec(z) < {} between {} and {}'.format(target.name, secz_max, start_time, end_time))
        return target.name, start_altaz.alt, start_altaz.az
    else:
        # print('\tsec(z) > {} between {} and {}'.format(secz_max, start_time, end_time))
        # return 'Too low', start_altaz.alt, start_altaz.az
        return '', '', ''


number_of_messier_objects = 110
messier_list = ('M', ) * number_of_messier_objects
#  convert this tuple of numbers into the target list to check for visibility

target_list = (FixedTarget.from_name('M13'), FixedTarget.from_name('M31'),
               vega, polaris)

for target in target_list:
    name, altitude, azimuth = check_secz(target,
                                         start_time,
                                         end_time,
                                         secz_max=5.0)
    #    if name != 'Too low':
    print('{}: Altitude, Azimuth = ({}, {}) at {}'.format(
        name, altitude, azimuth, start_time))
コード例 #13
0
"""
#from astropy.coordinates import EarthLocation

from astroplan import Observer, FixedTarget
from astropy.time import Time
from astropy import units as u
import numpy as np
from astroplan.plots import plot_airmass
import matplotlib.pyplot as plt

star_name = 'DQ Her'
star_name2 = 'V392 Per'
site = 'Roque de los Muchachos'

obs = Observer.at_site(site)
star = FixedTarget.from_name(star_name)
star2 = FixedTarget.from_name(star_name2)

now = Time.now()

if obs.target_is_up(now, star):
    print(f"{star_name:s} is up at {now}")

# Sunrise and Sunset
horizon = 2.5 * u.degree
sunset_tonight = obs.sun_set_time(now,
                                  which='nearest',
                                  horizon=-2.5 * u.degree)
sunrise_tomorrow = obs.sun_rise_time(now,
                                     which='next',
                                     horizon=-2.5 * u.degree)