How to use the ephem.Observer function in ephem

To help you get started, we’ve selected a few ephem 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 ledatelescope / bifrost / python / bifrost / addon / leda / test_model_block.py View on Github external
import unittest
import ephem
import os
import json
import ctypes
import numpy as np
from bifrost.libbifrost import _bf, _check
from bifrost.GPUArray import GPUArray
from model_block import ScalarSkyModelBlock
from blocks import DadaReadBlock
from bifrost.block import Pipeline, WriteAsciiBlock, NearestNeighborGriddingBlock
from bifrost.block import TestingBlock
from bifrost.GPUArray import GPUArray

ovro = ephem.Observer()
ovro.lat = '37.239782'
ovro.lon = '-118.281679'
ovro.elevation = 1184.134
ovro.date = '2016/07/26 16:17:00.00'

def load_telescope(filename):
    with open(filename, 'r') as telescope_file:
        telescope = json.load(telescope_file)
    coords_local = np.array(telescope['coords']['local']['__data__'], dtype=np.float32)
    # Reshape into ant,column
    coords_local = coords_local.reshape(coords_local.size/4,4)
    ant_coords = coords_local[:,1:]
    inputs = np.array(telescope['inputs']['__data__'], dtype=np.float32)
    # Reshape into ant,pol,column
    inputs      = inputs.reshape(inputs.size/7/2,2,7)
    delays      = inputs[:,:,5]*1e-9
github patchvonbraun / simple_ra / simple_ra_utils.py View on Github external
def cur_sidereal(longitude,val):
    global doephem
    if doephem == False:
        return (("12:00:00","9999999999"))
    longstr = "%02d" % int(longitude)
    longstr = longstr + ":"
    longitude = abs(longitude)
    frac = longitude - int(longitude)
    frac *= 60
    mins = int(frac)
    longstr += "%02d" % mins
    longstr += ":00"
    x = ephem.Observer()
    x.date = ephem.now()
    x.long = longstr
    jdate = ephem.julian_date(x)
    tokens=str(x.sidereal_time()).split(":")
    hours=int(tokens[0])
    minutes=int(tokens[1])
    seconds=int(float(tokens[2]))
    sidt = "%02d:%02d:%02d" % (hours, minutes, seconds)
    return ((sidt,jdate))
github lsst / sims_featureScheduler / python / lsst / sims / featureScheduler / observatory / speed_observatory.py View on Github external
self.sky = sb.SkyModelPre(preload=False, speedLoad=quickTest)
        # Should realy set this by inspecting the map.
        self.sky_nside = 32

        # Start out parked
        self.ra = None
        self.dec = None
        self.filtername = None

        # Set up all sky coordinates
        hpids = np.arange(hp.nside2npix(self.sky_nside))
        self.ra_all_sky, self.dec_all_sky = _hpid2RaDec(self.sky_nside, hpids)
        self.status = None

        self.site = Site(name='LSST')
        self.obs = ephem.Observer()
        self.obs.lat = self.site.latitude_rad
        self.obs.lon = self.site.longitude_rad
        self.obs.elevation = self.site.height

        self.obs.horizon = 0.

        self.sun = ephem.Sun()

        # Generate sunset times so we can label nights by integers
        self.generate_sunsets()
        self.night = self.mjd2night(self.mjd)

        # Make a slewtime interpolator
        self.slew_interp = Slewtime_pre()
github zonyl / pytomation / pytomation / devices / location.py View on Github external
def __init__(self, latitude, longitude, tz='US/Eastern', mode=MODE.STANDARD, is_dst=True, *args, **kwargs):
        super(Location, self).__init__(*args, **kwargs)
        self.obs = ephem.Observer()
        self.obs.lat = latitude
        self.obs.long = longitude
        self.tz = pytz.timezone(tz)
        self.is_dst = is_dst

        self.sun = ephem.Sun(self.obs)
        self._horizon = mode
        
        self._sunset_timer = CronTimer()
        self._sunrise_timer = CronTimer()
        self._local_time = None
        self._recalc()
github UASLab / ImageAnalysis / video / hud_glass.py View on Github external
def compute_sun_moon_ned(self, lon_deg, lat_deg, alt_m, timestamp):
        d = datetime.datetime.utcfromtimestamp(timestamp)
        #d = datetime.datetime.utcnow()
        ed = ephem.Date(d)
        #print 'ephem time utc:', ed
        #print 'localtime:', ephem.localtime(ed)

        ownship = ephem.Observer()
        ownship.lon = '%.8f' % lon_deg
        ownship.lat = '%.8f' % lat_deg
        ownship.elevation = alt_m
        ownship.date = ed

        sun = ephem.Sun(ownship)
        moon = ephem.Moon(ownship)

        sun_ned = [ math.cos(sun.az) * math.cos(sun.alt),
                    math.sin(sun.az) * math.cos(sun.alt),
                    -math.sin(sun.alt) ]
        moon_ned = [ math.cos(moon.az) * math.cos(moon.alt),
                     math.sin(moon.az) * math.cos(moon.alt),
                     -math.sin(moon.alt) ]

        return sun_ned, moon_ned
github akkana / scripts / oppretro / oppretro_ephem.py View on Github external
def find_parallax(self, date):
        '''Find the maximum parallax of self.planet on the given date
           from self.observer's location -- in other words, the difference
           in Mars' position between the observer's position and an
           observer at the same latitude but opposite longitude:
           this tells you you how much difference you would see from
           your position if Mars didn't move between your sunrise and sunset.
        '''
        save_date = self.observer.date

        # https://www.quora.com/Is-it-possible-to-measure-the-distance-to-Mars-using-a-telescope-and-the-parallax-method
        # says it should vary between 361.9 arc sec > a > 51.6 arc sec,
        # but I think he's smoking something.
        # So let's calculate it.
        observer = ephem.Observer()
        observer.name = "Observer"
        # To calculate from a point on the equator, set observer.lat to 0.
        observer.lat = self.observer.lat
        observer.lon = self.observer.lon
        observer.elevation = 0

        antipode = ephem.Observer()
        antipode.name = "Anti-point"
        antipode.lat = observer.lat
        antipode.lon = 360 - self.observer.lon
        antipode.elevation = 0

        observer.date = observer.next_rising(self.planet, start=date)
        self.planet.compute(observer)
        our_ra = self.planet.ra
        our_dec = self.planet.dec
github akkana / scripts / conjunctions.py View on Github external
start = ephem.date(sys.argv[1])
    else:
        start = ephem.date('2014/8/15 04:00')
    if len(sys.argv) > 2:
        end = ephem.date(sys.argv[2])
    else:
        end = ephem.date('2017/1/1')

    # Loop from start date to end date,
    # using a time of 10pm MST, which is 4am GMT the following day.
    # end = ephem.date('2016/1/1')
    # For testing, this spans a Mars/Moon/Venus conjunction:
    # d = ephem.date('2015/2/10 04:00')
    # end = ephem.date('2015/3/10')

    observer = ephem.Observer()
    observer.name = "Los Alamos"
    observer.lon = '-106.2978'
    observer.lat = '35.8911'
    observer.elevation = 2286  # meters, though the docs don't actually say

    # How late is too late to observe? E.g. 1 for 1 am, 23 for 11 pm.
    # None means we're interested in all events from sunset to sunrise.
    toolate = None

    try:
        run(start, end, observer, toolate, output_format)
        moon_phases(start, end, output_format)

    except KeyboardInterrupt:
        print("Interrupted")
github nrcharles / solpy / solpy / pv.py View on Github external
def solstice(self, hour):
        """position on winter soltice (Dec 21)"""
        import ephem
        o = ephem.Observer()
        o.date = '2000/12/21 %s:00:00' % (hour - self.tz)
        o.lat = math.radians(self.place[0])
        o.lon = math.radians(self.place[1])
        az = ephem.Sun(o).az
        alt = ephem.Sun(o).alt

        return alt, az
github MITHaystack / digital_rf / python / examples / beacon / beacon_record.py View on Github external
tle2 (string)                    = Second line of TLE
        startDate (string or ephem.date) = The date from which next closest rise and set are to be
                                           found in radians that print as degrees

    RETURNS:
        Param1 (ephem.date)              = Rise time of satellite in 'yyyy/mm/dd hh:mm:ss'
        Param2 (ephem.date)              = Half time between rise and set in 'yyyy/mm/dd hh:mm:ss'
        Param3 (ephem.date)              = Set time of satellite in 'yyyy/mm/dd hh:mm:ss'
    AFFECTS:
        None
    EXCEPTIONS:
        None
    DEPENDENCIES:
        ephem.Observer(...), ephem.readtle(...)
    """
    obsLoc = ephem.Observer()
    obsLoc.lat = obsLat
    obsLoc.long = obsLong
    obsLoc.elev = obsElev
    obsLoc.date = startDate

    if opt.debug:
        print("dbg location: ", obsLoc)

        print("dbg tle1: ", tle1)
        print("dbg tle2: ", tle2)

    satObj = ephem.readtle(objName, tle1, tle2)

    if opt.debug:
        print("dbg object: ", satObj)
github romor / blind-control / blindctrl / sunpower / astrotime.py View on Github external
def process(self):
        try:
            # determine sunset
            # get sun position
            o = ephem.Observer()
            # Vienna: 48 degree north; 16 degree east
            o.lat, o.long, o.date = '48:13', '16:22', datetime.datetime.utcnow()
            o.horizon = self.HORIZON
            sunset = ephem.localtime(o.next_setting(ephem.Sun()))
            logging.getLogger().info("Setting sunset to {}".format(sunset.strftime("%H:%M:%S")))
            
            # store to OPC data point
            self.save_opc(sunset)

        except Exception as e:
            logging.getLogger().error(traceback.format_exc())
            raise