How to use ephem - 10 common examples

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 brandon-rhodes / pyephem / tests / test_usno.py View on Github external
def standard_parse(line):
    """Read the date, RA, and dec from a USNO data file line."""

    fields = re.split(r'   +', line)
    dt = datetime(*strptime(fields[0][:-2], "%Y %b %d %H:%M:%S")[0:6])
    date = ephem.Date(dt)
    ra = ephem.hours(fields[1].replace(' ', ':'))
    sign, mag = fields[2].split(None, 1)
    dec = ephem.degrees(sign + mag.replace(' ', ':'))
    return date, ra, dec
github brandon-rhodes / pyephem / tests / test_usno.py View on Github external
def parse(fields, n):
            if len(fields) < n + 2:
                return None, None
            (timestr, anglestr) = fields[n:n+2]
            if timestr == '*****':
                return None, None
            h, m = [ int(s) for s in timestr.split(':') ]
            date = ephem.Date(midnight + h * ephem.hour + m * ephem.minute)
            angle = ephem.degrees(anglestr.strip('NS'))
            return date, angle
github brandon-rhodes / pyephem / tests / test_usno.py View on Github external
def parse(fields, n):
            if len(fields) < n + 2:
                return None, None
            (timestr, anglestr) = fields[n:n+2]
            if timestr == '*****':
                return None, None
            h, m = [ int(s) for s in timestr.split(':') ]
            date = ephem.Date(midnight + h * ephem.hour + m * ephem.minute)
            angle = ephem.degrees(anglestr.strip('NS'))
            return date, angle
github brandon-rhodes / pyephem / tests / test_usno.py View on Github external
def standard_parse(line):
    """Read the date, RA, and dec from a USNO data file line."""

    fields = re.split(r'   +', line)
    dt = datetime(*strptime(fields[0][:-2], "%Y %b %d %H:%M:%S")[0:6])
    date = ephem.Date(dt)
    ra = ephem.hours(fields[1].replace(' ', ':'))
    sign, mag = fields[2].split(None, 1)
    dec = ephem.degrees(sign + mag.replace(' ', ':'))
    return date, ra, dec
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 ledatelescope / bifrost / python / bifrost / addon / leda / test_model_block.py View on Github external
def setUp(self):
        """Generate simple model based on Cygnus A and the sun at 60 MHz"""
        self.blocks = []
        self.sources = {}
        self.sources['cyg'] = {
            'ra':'19:59:28.4', 'dec':'+40:44:02.1', 
            'flux': 10571.0, 'frequency': 58e6, 
            'spectral index': -0.2046}
        self.sources['sun'] = {
            'ephemeris': ephem.Sun(),
            'flux': 250.0, 'frequency':20e6,
            'spectral index':+1.9920}
        frequencies = [60e6]
        self.blocks.append((ScalarSkyModelBlock(ovro, coords, frequencies, self.sources), [], [0]))
        self.blocks.append((WriteAsciiBlock('.log.txt'), [0], []))
    def test_output_size(self):
github brandon-rhodes / pyephem / tests / test_usno.py View on Github external
name = name[4:]
        self.body = self.select_body(name)
        self.year = int(year)

        longstr, latstr = re.search(r'Location: (.\d\d\d \d\d), (.\d\d \d\d)',
                                    self.content).groups()
        longstr = longstr.replace(' ', ':').replace('W', '-').strip('E')
        latstr = latstr.replace(' ', ':').replace('S', '-').strip('N')

        self.observer = o = ephem.Observer()
        o.lat = latstr
        o.long = longstr
        o.elevation = 0
        setup_horizon(o)

        self.error = ephem.minute # error we tolerate in predicted time
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 akkana / scripts / rise_set_az.py View on Github external
observer = None
    else:
        observer = None

    if not observer:
        observer = observer_for_city(args.observer)

    if not observer:
        print("Couldn't parse observer '%s'" % args.observer)
        parser.print_help()
        sys.exit(1)

    print("Observer:", observer)

    if args.sun:
        body = ephem.Sun()
    else:
        body = ephem.Moon()

    rise = not args.set
    if rise:
        print("Finding %srises" % body.name)
    else:
        print("Finding %ssets" % body.name)

    if not args.start:
        args.start = datetime.datetime.now()
    if not args.end:
        args.end = args.start.replace(month=12, day=31, hour=23)

    vals = find_rise_set(observer, body, rise,
                         ephem.Date(args.start), ephem.Date(args.end),
github OSCAAR / OSCAAR / oscaar / extras / eph / calculateEphemerides.py View on Github external
def list2datestrHTML_LT(inList,alt,direction):
        '''Converse function to datestr2list for daylight savings time'''
        #print "original",inList
        tempDate = ephem.Date(inList)
        inList = ephem.Date(ephem.localtime(tempDate)).tuple()
        #print "converted",lt_inList,'\n'
        inList = map(str,inList)
        #return inList[1].zfill(2)+'/'+inList[2].zfill(2)+'<br>'+inList[3].zfill(2)+':'+inList[4].zfill(2)
        return inList[1].zfill(2)+'/<strong>'+inList[2].zfill(2)+'</strong>, '+inList[3].zfill(2)+':'+inList[4].split('.')[0].zfill(2)+'<br> '+alt+'° '+direction