How to use astroplan - 10 common examples

To help you get started, we’ve selected a few astroplan examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GalSim-developers / GalSim / tests / test_photon_array.py View on Github external
# is working properly.
    import astropy.time

    # Set up an observation date, time, location, coordinate
    # These are arbitrary, so ripped from astroplan's docs
    # https://media.readthedocs.org/pdf/astroplan/latest/astroplan.pdf
    subaru = astroplan.Observer.at_site('subaru')
    time = astropy.time.Time('2015-06-16 12:00:00')

    # Stars that are visible from the north in summer time.
    names = ['Vega', 'Polaris', 'Altair', 'Regulus', 'Spica', 'Algol', 'Fomalhaut', 'Markab',
             'Deneb', 'Mizar', 'Dubhe', 'Sirius', 'Rigel', 'Etamin', 'Alderamin']

    for name in names:
        try:
            star = astroplan.FixedTarget.from_name(name)
        except Exception as e:
            print('Caught exception trying to make star from name ',name)
            print(e)
            print('Aborting.  (Probably some kind of network problem.)')
            return
        print(star)

        ap_z = subaru.altaz(time, star).zen
        ap_q = subaru.parallactic_angle(time, star)
        print('According to astroplan:')
        print('  z,q = ', ap_z.deg, ap_q.deg)

        # Repeat with GalSim
        coord = galsim.CelestialCoord(star.ra.deg * galsim.degrees, star.dec.deg * galsim.degrees)
        lat = subaru.location.lat.deg * galsim.degrees
        local_sidereal_time = subaru.local_sidereal_time(time)
github GalSim-developers / GalSim / tests / test_photon_array.py View on Github external
def test_dcr_angles():
    """Check the DCR angle calculations by comparing to astroplan's calculations of the same.
    """
    # Note: test_chromatic.py and test_sed.py both also test aspects of the dcr module, so
    # this particular test could belong in either of them too.  But I (MJ) put it here, since
    # I wrote it in conjunction with the tests of PhotonDCR to try to make sure that code
    # is working properly.
    import astropy.time

    # Set up an observation date, time, location, coordinate
    # These are arbitrary, so ripped from astroplan's docs
    # https://media.readthedocs.org/pdf/astroplan/latest/astroplan.pdf
    subaru = astroplan.Observer.at_site('subaru')
    time = astropy.time.Time('2015-06-16 12:00:00')

    # Stars that are visible from the north in summer time.
    names = ['Vega', 'Polaris', 'Altair', 'Regulus', 'Spica', 'Algol', 'Fomalhaut', 'Markab',
             'Deneb', 'Mizar', 'Dubhe', 'Sirius', 'Rigel', 'Etamin', 'Alderamin']

    for name in names:
        try:
            star = astroplan.FixedTarget.from_name(name)
        except Exception as e:
            print('Caught exception trying to make star from name ',name)
            print(e)
            print('Aborting.  (Probably some kind of network problem.)')
            return
        print(star)
github lsst / sims_featureScheduler / python / lsst / sims / featureScheduler / modelObservatory / generate_almanac.py View on Github external
from astroplan import Observer
import astropy.units as u
from astropy.time import Time
from lsst.sims.utils import Site

# Trying out the astroplan sunrise/set code.
# conda install -c astropy astroplan
mjd_start = 59853.5 - 3.*365.25
duration = 25.*365.25
pad_around = 40
t_step = 0.7

mjds = np.arange(mjd_start-pad_around, duration+mjd_start+pad_around+t_step, t_step)

site = Site('LSST')
observer = Observer(longitude=site.longitude*u.deg, latitude=site.latitude*u.deg,
                    elevation=site.height*u.m, name="LSST")


# This blows up if I try to do it all at once? 250 GB of memory?
results = []

mjds_list = np.array_split(mjds, 500)

for i, mjds in enumerate(mjds_list):
    print('chunk %i of %i'%(i, len(mjds_list)))
    times = Time(mjds, format='mjd')
    print('getting sunsets')
    sunsets = observer.sun_set_time(times)

    sunsets = np.unique(np.round(sunsets.mjd, decimals=4))
github TOMToolkit / tom_base / tom_observations / utils.py View on Github external
:returns: ra/dec positions of the sun over the time range,
        time range between start_time and end_time at interval
    :rtype: astropy SkyCoord, astropy Time
    """

    start = Time(start_time)
    end = Time(end_time)

    time_range = time_grid_from_range(time_range=[start, end], time_resolution=interval*units.minute)

    number_of_days = end.mjd - start.mjd
    if number_of_days*4 < float(interval)/2:
        # Hack to speed up calculation by factor of ~3
        sun_coords = get_sun(time_range[int(len(time_range)/2)])
        sun = FixedTarget(name='sun', coord=SkyCoord(sun_coords.ra, sun_coords.dec, unit='deg'))
    else:
        sun = get_sun(time_range)

    return sun, time_range
github TOMToolkit / tom_base / tom_observations / utils.py View on Github external
:rtype: dict
    """

    if target.type != 'SIDEREAL':
        msg = '\033[1m\033[91mAirmass plotting is only supported for sidereal targets\033[0m'
        logger.info(msg)
        empty_visibility = {}
        return empty_visibility

    if end_time < start_time:
        raise Exception('Start must be before end')

    if airmass_limit is None:
        airmass_limit = 10

    body = FixedTarget(name=target.name, coord=SkyCoord(target.ra, target.dec, unit='deg'))

    visibility = {}
    sun, time_range = get_astroplan_sun_and_time(start_time, end_time, interval)
    for observing_facility in facility.get_service_classes():
        observing_facility_class = facility.get_service_class(observing_facility)
        sites = observing_facility_class().get_observing_sites()
        for site, site_details in sites.items():
            observer = Observer(longitude=site_details.get('longitude')*units.deg,
                                latitude=site_details.get('latitude')*units.deg,
                                elevation=site_details.get('elevation')*units.m)

            sun_alt = observer.altaz(time_range, sun).alt
            obj_airmass = observer.altaz(time_range, body).secz

            bad_indices = np.argwhere(
                (obj_airmass >= airmass_limit) |
github panoptes / POCS / src / panoptes / pocs / scheduler / field.py View on Github external
from astroplan import FixedTarget
from astropy.coordinates import SkyCoord

from panoptes.pocs.base import PanBase


class Field(FixedTarget, PanBase):

    def __init__(self, name, position, equinox='J2000', *args, **kwargs):
        """ An object representing an area to be observed

        A `Field` corresponds to an `~astroplan.ObservingBlock` and contains information
        about the center of the field (represented by an `astroplan.FixedTarget`).

        Arguments:
            name {str} -- Name of the field, typically the name of object at
                center `position`.
            position {str} -- Center of field, can be anything accepted by
                `~astropy.coordinates.SkyCoord`.
            **kwargs {dict} -- Additional keywords to be passed to
                `astroplan.ObservingBlock`.

        """
github ojhall94 / stateoftheuniverse / stateoftheuniverse / widgets / constillations / get_constillations.py View on Github external
from astropy import units as u
from astroplan import Observer, FixedTarget
from astropy.coordinates import SkyCoord, AltAz, Angle, get_constellation
from astropy.time import Time
import numpy as np

subaru = Observer.at_site('subaru')

altair = FixedTarget.from_name('Altair')
vega = FixedTarget.from_name('Vega')

time = Time('2019-08-27 12:00:00')

alt = Angle(np.arange(0,90,5), unit=u.deg)
az = Angle(np.arange(0,395,5), unit=u.deg)

#altaz = AltAz(az=az[0], alt=alt[0], location=subaru.location)
altaz = SkyCoord(az=az[1]*u.degree, alt=alt[1]*u.degree, frame='altaz') 
print(subaru.location)
print(type(subaru))
print(altaz)
print(get_constellation(altaz))
github panoptes / POCS / pocs / scheduler / target.py View on Github external
from .observation import Observation

try:
    import seaborn
    seaborn.set()
except:
    matplotlib.use('Agg')
    plt.style.use('ggplot')


# ----------------------------------------------------------------------------
# Target Class
# ----------------------------------------------------------------------------


class Target(FixedTarget):

    """An object describing an astronomical target.

    An object representing a possible target which the scheduler is considering,
    also is the object which the scheduler will return when asked for a target
    to observe.
    """

    def __init__(self, target_config, cameras=None, **kwargs):
        """  A FixedTarget object that we want to gather data about.

        A `Target` represents not only the actual object in the night sky
        (via the `self.coord` astropy.SkyCoord attribute) but also the concept
        of a `visit`, which is a list of `Observation`s.

        """
github astropy / astroplan / dev / planning-example.py View on Github external
# `constraints` will be a boolean where True=observable. For a list of
# targets, observatories, or times, `constraints` may be a booleans array

# We will eventually need a more complicated method that minimizes a cost
# function when optimizing an observing schedule given the results of
# `is_observable`.

# ======================================================
# Other useful calculations wrt an observer and a target
#=======================================================

# calculate the distance in alt and az degrees between two targets at
# the given time (e.g. to calculate slew time)
sf = FixedTarget(SkyCoord('09d40m00.00s', '43d00m00.00s'), name='Sf')
sm = FixedTarget(SkyCoord('10d30m00.00s', '36d00m00.00s'), name='Sm')

# Coordinate arithmetic gives separations in RA, Dec, alt, az
dra, ddec = sf.ra - sm.ra, sf.dec - sm.dec
dalt = obs.altaz(time_obs, sf).alt - obs.altaz(time_obs, sm).alt
dazt = obs.altaz(time_obs, sf).az - obs.altaz(time_obs, sm).az
github ojhall94 / stateoftheuniverse / stateoftheuniverse / widgets / constillations / get_constillations.py View on Github external
from astropy import units as u
from astroplan import Observer, FixedTarget
from astropy.coordinates import SkyCoord, AltAz, Angle, get_constellation
from astropy.time import Time
import numpy as np

subaru = Observer.at_site('subaru')

altair = FixedTarget.from_name('Altair')
vega = FixedTarget.from_name('Vega')

time = Time('2019-08-27 12:00:00')

alt = Angle(np.arange(0,90,5), unit=u.deg)
az = Angle(np.arange(0,395,5), unit=u.deg)

#altaz = AltAz(az=az[0], alt=alt[0], location=subaru.location)
altaz = SkyCoord(az=az[1]*u.degree, alt=alt[1]*u.degree, frame='altaz') 
print(subaru.location)
print(type(subaru))
print(altaz)
print(get_constellation(altaz))