How to use the astroplan.Observer function in astroplan

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 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 astropy / astroplan / dev / planning-example.py View on Github external
# Latitude/Longitude take input as strings or quantities,
# elevation, pressure, temperature must be quantities.
# Accept `timezone` from pytz
from astroplan import Observer
import astropy.units as u
from astropy.coordinates import EarthLocation
import pytz

# Define the observer with an instance of astropy.coordinates.EarthLocation,
# also use pytz.timezone() argument directly as `timezone` keyword's input
longitude = '-155d28m48.900s'
latitude = '+19d49m42.600s'
elevation = 4163 * u.m
location = EarthLocation.from_geodetic(longitude, latitude, elevation)

obs = Observer(name='Subaru Telescope',
               location=location,
               pressure=0.615 * u.bar,
               relative_humidity=0.11,
               temperature=0 * u.deg_C,
               timezone=pytz.timezone('US/Hawaii'),
               description="Subaru Telescope on Mauna Kea, Hawaii")

# It would also be desirable to be able to have a small database of
# common telescopes.  Maybe this can at first simply take the form of
# a python module:
from astroplan import sites

obs = sites.Keck1

# Environmental conditions should be updatable.
obs.pressure = 0.600 * u.bar
github soar-telescope / goodman_pipeline / src / goodman_ccd / goodman_ccdreduction.py View on Github external
image_collection (object): ImageFileCollection object that contains all header information of all images.
            observatory (str): Observatory name.
            longitude (str): Geographic longitude in string format.
            latitude (str): Geographic latitude in string format.
            elevation (int): Geographic elevation in meters above sea level
            timezone (str): Time zone.
            description (str): Observatory description

        Returns:
            twilight_evening (str): Evening twilight time in the format 'YYYY-MM-DDTHH:MM:SS.SS'
            twilight_morning (str): Morning twilight time in the format 'YYYY-MM-DDTHH:MM:SS.SS'

        """
        soar_loc = EarthLocation.from_geodetic(longitude, latitude, elevation * u.m, ellipsoid='WGS84')

        soar = Observer(name=observatory, location=soar_loc, timezone=timezone, description=description)

        dateobs_list = image_collection.values('date-obs')
        time_first_frame, time_last_frame = Time(min(dateobs_list)), Time(max(dateobs_list))

        twilight_evening = soar.twilight_evening_astronomical(Time(time_first_frame), which='nearest').isot
        twilight_morning = soar.twilight_morning_astronomical(Time(time_last_frame), which='nearest').isot

        return twilight_evening, twilight_morning
github panoptes / POCS / pocs / scheduler / core.py View on Github external
import yaml

from astroplan import Observer
from astroplan import get_moon
from astropy import units as u
from astropy.coordinates import SkyCoord

from . import merits as merit_functions
from ..utils import current_time
from ..utils.config import load_config
from ..utils.logger import get_logger

from .target import Target


class Scheduler(Observer):

    """ Main scheduler for the POCS system. Responsible for returning current targets.

    Args:
        targets_file (str): Filename of target list to load. Defaults to None.
        location (astropy.coordinates.EarthLocation): Earth location for the mount.
        cameras(list[pocs.cameras]): The cameras to schedule

    """

    def __init__(self, targets_file=None, location=None, cameras=None, **kwargs):
        self.logger = get_logger(self)
        self.config = load_config()

        name = self.config['location'].get('name', 'Super Secret Undisclosed Location')
        horizon = self.config['location'].get('horizon', 20) * u.degree
github soar-telescope / goodman_pipeline / goodman_pipeline / core / core.py View on Github external
# elevation (int): Geographic elevation in meters above sea level
    elevation = geodetic_location[2]

    # timezone (str): Time zone.
    timezone = 'UTC'

    # description(str): Observatory description
    description = 'Soar Telescope on Cerro Pachon, Chile'

    soar_loc = EarthLocation.from_geodetic(longitude,
                                           latitude,
                                           elevation * u.m,
                                           ellipsoid='WGS84')

    soar = Observer(name=observatory,
                    location=soar_loc,
                    timezone=timezone,
                    description=description)

    time_first_frame, time_last_frame = Time(min(date_obs)), Time(
        max(date_obs))

    twilight_evening = soar.twilight_evening_astronomical(
        Time(time_first_frame), which='nearest').isot

    twilight_morning = soar.twilight_morning_astronomical(
        Time(time_last_frame), which='nearest').isot

    sun_set_time = soar.sun_set_time(
        Time(time_first_frame), which='nearest').isot
github TOMToolkit / tom_base / tom_observations / utils.py View on Github external
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) |
                (obj_airmass <= 1) |
                (sun_alt > -18*units.deg)  # between astronomical twilights, i.e. sun is up
            )

            obj_airmass = [None if i in bad_indices else float(airmass) for i, airmass in enumerate(obj_airmass)]

            visibility[f'({observing_facility}) {site}'] = (time_range.datetime, obj_airmass)
    return visibility
github panoptes / POCS / scripts / plot_weather.py View on Github external
def get_twilights(self, config=None):
        """ Determine sunrise and sunset times """
        print('  Determining sunrise, sunset, and twilight times')

        if config is None:
            from pocs.utils.config import load_config as pocs_config
            config = pocs_config()['location']

        location = EarthLocation(
            lat=config['latitude'],
            lon=config['longitude'],
            height=config['elevation'],
        )
        obs = Observer(location=location, name='PANOPTES',
                       timezone=config['timezone'])

        sunset = obs.sun_set_time(Time(self.start), which='next').datetime
        sunrise = obs.sun_rise_time(Time(self.start), which='next').datetime

        # Calculate and order twilights and set plotting alpha for each
        twilights = [(self.start, 'start', 0.0),
                     (sunset, 'sunset', 0.0),
                     (obs.twilight_evening_civil(Time(self.start),
                                                 which='next').datetime, 'ec', 0.1),
                     (obs.twilight_evening_nautical(Time(self.start),
                                                    which='next').datetime, 'en', 0.2),
                     (obs.twilight_evening_astronomical(Time(self.start),
                                                        which='next').datetime, 'ea', 0.3),
                     (obs.twilight_morning_astronomical(Time(self.start),
                                                        which='next').datetime, 'ma', 0.5),