How to use the ephem.Date 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 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 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
github OSCAAR / OSCAAR / Extras / eph / calculateEphemerides.py View on Github external
line = indentation+''+middle+'\n'
                report.write(line)

        
            if np.shape(events[key])[0] &gt; 1:
                elapsedTime = []
                
                for i in range(1,len(events[key])):
                    nextPlanet = events[key][1]
                    planet = events[key][0]
                    double = False
                    '''If the other planet's ingress is before this one's egress, then'''
                    if ephem.Date(list2datestr(jd2gd(float(nextPlanet[1]-nextPlanet[2])))) -\
                             ephem.Date(list2datestr(jd2gd(float(planet[1]+planet[2])))) &gt; 0.0:
                        double = True
                        elapsedTime.append(ephem.Date(list2datestr(jd2gd(float(nextPlanet[1]-nextPlanet[2])))) - \
                             ephem.Date(list2datestr(jd2gd(float(planet[1]+planet[2])))))
                        
                    if ephem.Date(list2datestr(jd2gd(float(planet[1]-planet[2])))) - \
                             ephem.Date(list2datestr(jd2gd(float(nextPlanet[1]+nextPlanet[2])))) &gt; 0.0:
                        '''If the other planet's egress is before this one's ingress, then'''
                        double = True
                        elapsedTime.append(ephem.Date(list2datestr(jd2gd(float(planet[1]-planet[2])))) - \
                             ephem.Date(list2datestr(jd2gd(float(nextPlanet[1]+nextPlanet[2])))))
                
                #if double:
                #    report.write(list2datestr(jd2gd(float(key)+1)).split(' ')[0]+'\t'+'&gt;1 event'+'\t'+str(np.max(elapsedTime)*24.0)+'\t'+'\n')
                #else:
                #    report.write(list2datestr(jd2gd(float(key)+1)).split(' ')[0]+'\n')
                for planet in events[key]:
                    if calcTransits and planet[3] == 'transit':
                        writeHTMLtransit()
github lofar-astron / RMextract / RMextract / PosTools.py View on Github external
print ('**** specified start and end time ', start_time, end_time)
        reference_time = start_time * 86400.0 - TIME_OFFSET
        st = reference_time - timestep 
        et = end_time * 86400.0 +  timestep + TIME_OFFSET
        #print ("getting string",reference_time)
        str_start_time =  obtain_observation_year_month_day_hms(reference_time)
        timerange= [st, et]
      except:
        print ('no time range given')
        print ('exiting')
        return -1,-1,-1
    elif HAS_EPHEM:
      if time_in_sec:
        dublin_start = start_time / 86400.0 -15019.5
        dublin_end = end_time / 86400.0 -15019.5
        start_time = ephem.julian_date(ephem.Date(dublin_start)) - 2400000.5
        end_time = ephem.julian_date(ephem.Date(dublin_end)) - 2400000.5
      else:
        start_time = ephem.julian_date(ephem.Date(start_time)) - 2400000.5
        end_time = ephem.julian_date(ephem.Date(end_time)) - 2400000.5
      print ('ephem start and end time ', start_time, end_time)
      reference_time = start_time * 86400.0 - TIME_OFFSET
      st = reference_time - timestep 
      et = end_time * 86400.0 + timestep + TIME_OFFSET
      str_start_time =  obtain_observation_year_month_day_hms(reference_time)
      timerange= [st, et]
    else:
      print ('unable to get time range so exiting!')
      return -1,-1,-1
    return timerange,str_start_time,reference_time
github darkstar007 / GroundStation / src / SatPass.py View on Github external
datetime.timedelta(seconds=60))
        while tr &lt; ts:
            obs.date = tr
            self.sat.compute(obs)
            print "%s | %4.1f %5.1f | %4.1f %+6.1f | %5.1f | %+6.1f" % \
                  (tr,
                   math.degrees(self.sat.alt),
                   math.degrees(self.sat.az),
                   math.degrees(self.sat.sublat),
                   math.degrees(self.sat.sublong),
                   self.sat.range/1000.,
                   self.sat.range_velocity * 435e6 / 3.0e8)
            data.append((tr, self.sat.alt*1.0, self.sat.az*1.0))
            tr = ephem.Date(tr + 20.0 * ephem.second)

        tr = ephem.Date(ltime)
        labels = []
        while tr &lt; ts:
            obs.date = tr
            self.sat.compute(obs)
            dt = tr.datetime() + dtime
            labels.append(("%02d:%02d" % (dt.hour, dt.minute), self.sat.alt*1.0, self.sat.az*1.0))
            tr = ephem.Date(tr + 60.0 * ephem.second)
            
        self.plot.addPass(data, labels)
        self.resize(600,600)
        self.show()
github hazrmard / SatTrack / build / lib / sattrack / sattrack.py View on Github external
def _update_coords(self, t, trace):
        """
        This function runs in a thread started in 'begin_computing' and recomputes the satellites position after
        interval 't'.
        :param t: Interval between computations
        """
        while True:
            with self.lock:
                try:
                    if trace > 0:
                        self.observer.date = ephem.Date(self.observer.date + trace * ephem.second)
                    else:
                        self.observer.date = ephem.Date(str(datetime.utcnow()))
                    self.satellite.compute(self.observer)
                    self._isActive = True
                except:
                    self._isActive = False
            time.sleep(t)
github akkana / scripts / oppretro / oppretro_ephem.py View on Github external
pre_closest = True
        self.retrograding = False
        retro_start = None
        retro_end = None

        # A place to store the data points
        self.planettrack = []

        # When a planet is approaching opposition, its elongation is negative.
        # When it flips to positive (-180 to 180), it just passed opposition.
        # Can't check for exactly 180 if we're only checking time coarsely.
        last_elong = -1
        end_date = ephem.Date(self.observer.date + 170)
        while self.observer.date &lt; end_date:
            # Add time, in days or fractions thereof.
            self.observer.date = ephem.Date(self.observer.date + .01)
            # self.observer.date = ephem.Date(self.observer.date + 1)

            # It's important to use compute(date), not compute(observer).
            # The latter will include parallax, and will show shifts
            # from retrograde to direct motion on multiple days
            # because (apparently) the parallax is greater than the
            # motion of the planet on those days, at least for Mars.
            # self.planet.compute(self.observer)
            self.planet.compute(self.observer.date)

            flags = ''

            # Are we starting or stopping retrograde?
            if ( (self.planet.ra == last_RA) or
                 (self.planet.ra &lt; last_RA and not self.retrograding) or
                 (self.planet.ra &gt; last_RA and self.retrograding) ):
github hazrmard / SatTrack / build / lib / sattrack / sattrack.py View on Github external
def _update_coords(self, t, trace):
        """
        This function runs in a thread started in 'begin_computing' and recomputes the satellites position after
        interval 't'.
        :param t: Interval between computations
        """
        while True:
            with self.lock:
                try:
                    if trace > 0:
                        self.observer.date = ephem.Date(self.observer.date + trace * ephem.second)
                    else:
                        self.observer.date = ephem.Date(str(datetime.utcnow()))
                    self.satellite.compute(self.observer)
                    self._isActive = True
                except:
                    self._isActive = False
            time.sleep(t)