How to use the ephem.separation 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 HERA-Team / aipy / scripts / srclist.py View on Github external
aa.set_jultime(opts.juldate)

for c in [cat, xcat, ccat]:
    for s in c.keys():
        try: ephem.FixedBody.compute(c[s], date)
        except(TypeError):
            if opts.juldate is None: del(c[s])
            else: c[s].compute(aa)

srcs = cat.keys()
srcs = [s for s in srcs if s not in xcat]
if opts.sep != None:
    nsrcs = []
    for s1 in srcs:
        for s2 in ccat.keys():
            if ephem.separation(cat[s1], ccat[s2]) <= opts.sep * a.img.deg2rad:
                nsrcs.append(s1)
                break
    srcs = nsrcs
    

if opts.ra_rng != None:
    ra1,ra2 = map(ephem.hours, opts.ra_rng.split('_'))
    if ra1 < ra2:
        srcs = [s for s in srcs if (cat[s].ra > ra1 and cat[s].ra < ra2)]
    else:
        srcs = [s for s in srcs if (cat[s].ra > ra1 or cat[s].ra < ra2)]

if opts.dec_rng != None:
    dec1,dec2 = map(ephem.degrees, opts.dec_rng.split('_'))
    if dec1 < dec2:
        srcs = [s for s in srcs if (cat[s].dec > dec1 and cat[s].dec < dec2)]
github akkana / scripts / conjunctions.py View on Github external
# print()
        # print(datestr(d), "visible planets:",
        #       ' '.join([p.name for p in visible_planets]))
        # print("planets_up:", planets_up)

        # Done with computing visible_planets.
        # Now look for conjunctions, anything closer than 5 degrees.
        # Split the difference, use a time halfway between sunset and latenight.
        saw_conjunction = False
        observer.date = ephem.date((sunset + latenight)/2)
        moon = planets[0]
        if len(visible_planets) > 1:
            for p, planet in enumerate(visible_planets):
                for planet2 in visible_planets[p+1:]:
                    sep = ephem.separation(planet, planet2)
                    # print(observer.date, "moon -", planet2.name, sep)
                    if sep <= max_sep:
                        # print (datestr(observer.date), planet.name,
                        #        planet2.name, sepstr(sep))
                        if verbose:
                            print("adding sep", planet.name, planet2.name,
                                  observer.date, sep)
                        conjunctions.add(planet.name, planet2.name,
                                         observer.date, sep)
                        saw_conjunction = True
                    elif planet == moon and sep <= moon_sep:
                        if verbose:
                            print("adding moon sep", planet.name, planet2.name,
                                  observer.date, sep)
                        conjunctions.add(planet.name, planet2.name,
                                         observer.date, sep)
github heidtn / MeteorTracker / MeteorTracker / ParseStars.py View on Github external
def findQuad(self, starlist):
		for star in starlist:
			#don't add the starA to the list
			if star != self.starA:
				#populate the list first and then sort by closest 3 stars
				if len(self.quad) < 3:
					self.quad.append(star)
					self.sortQuad()
				else:
					#if the current star is closer than a current star in the quad replace that star
					if(ephem.separation(self.quad[2], self.starA) > ephem.separation(star, self.starA)):
						self.quad[2] = star
						self.sortQuad()

			#print "star, ", float(self.starA.alt), float(self.starA.az)
			#for i in self.quad:
				#print float(ephem.separation(i, self.starA))

		#print self.starA, self.quad

		self.pointsInCircle()
github akkana / scripts / conjunctions.py View on Github external
"""Use a more fine-grained time step to check for a lunar occultation.
    """
    # Unfortunately, by the time we get here we only have a name,
    # not an ephem body. Get the body back:
    b1 = planets[planets_by_name.index(b1name)]
    b2 = planets[planets_by_name.index(b2name)]

    timestep = ephem.hour / 20

    # Go from a day earlier to a day later:
    enddate = closest_date + oneday
    observer.date = closest_date - oneday
    while observer.date < enddate:
        b1.compute(observer)
        b2.compute(observer)
        sep = ephem.separation(b1, b2)
        if sep < minsep:
            minsep = sep
            closest_date = observer.date
        observer.date += timestep

    return minsep, closest_date
github weewx / weewx / bin / weewx / almanac.py View on Github external
def separation(self, body1, body2):
        return ephem.separation(body1, body2)
github heidtn / MeteorTracker / MeteorTracker / ParseStars.py View on Github external
def normalizeQuad(self):
		normal = ephem.separation(self.quad[2], self.starA)
github joshwalawender / IQMon / IQMon.py View on Github external
TargetObject = ephem.readdb("Target,f|M|F7,{},2.02,2000".format(RADEC_string))
            TargetObject.compute(self.tel.site)
            self.target_alt = TargetObject.alt * 180./ephem.pi * u.deg
            self.target_az = TargetObject.az * 180./ephem.pi * u.deg
            self.logger.debug("  Target Alt, Az = {0:.1f}, {1:.1f}".format(\
                                             self.target_alt.to(u.deg).value,\
                                             self.target_az.to(u.deg).value))
            self.target_zenith_angle = 90.*u.deg - self.target_alt
            self.airmass = 1.0/math.cos(self.target_zenith_angle.to(u.radian).value)*(1.0 - 0.0012*(1.0/(math.cos(self.target_zenith_angle.to(u.radian).value)**2 - 1.0)))
            self.logger.debug("  Target airmass (calculated) = {0:.2f}".format(\
                                                                 self.airmass))
            ## Calculate Moon Position and Illumination
            TheMoon = ephem.Moon()
            TheMoon.compute(self.tel.site)
            self.moon_phase = TheMoon.phase
            self.moon_sep = ephem.separation(TargetObject, TheMoon)
            self.moon_sep = self.moon_sep * 180./ephem.pi * u.deg
            self.moon_alt = TheMoon.alt * 180./ephem.pi * u.deg
            if self.moon_alt > 0:
                self.logger.debug("  A {0:.0f} percent illuminated Moon is {1:.0f} deg from target.".format(\
                                       self.moon_phase,\
                                       self.moon_sep.to(u.deg).value))
            else:
                self.logger.debug("  A {0:.0f} percent illuminated Moon is down.".format(\
                                       self.moon_phase))
        else:
            self.target_alt = None
            self.target_az = None
            self.moon_phase = None
            self.moon_sep = None
            self.moon_alt = None
            self.target_zenith_angle = None
github HERA-Team / aipy / antennas.py View on Github external
def response(self, azalt, pol=1):
        """Return the total antenna response to a source at azalt=(az, alt),
        including beam response, per-frequency gain, and a phase offset."""
        zang = ephem.separation(self.pointing, azalt)
        beam_resp = self.beam.response(zang, azalt[0], pol=pol)
        offset = numpy.exp(2*math.pi*1j*self.offset)
        return beam_resp * self.gain * offset
github heidtn / MeteorTracker / MeteorTracker / ParseStars.py View on Github external
def drawUnitCircles(self, quadlist):
		for quad in quadlist:
			center_x = quad.midpoint[0]*self.xscale
			center_y = quad.midpoint[1]*self.yscale
			radius = quad.radius*self.xscale
			print radius, quad.radius, float(quad.starA.alt), float(quad.starA.az), float(quad.quad[2].alt), float(quad.quad[2].az), float(ephem.separation(quad.starA, quad.quad[2]))
			color = (random.randint(50,250),random.randint(50,250),random.randint(50,250))
			cv2.circle(self.image, (int(center_x + .5), int(center_y + .5)), int(radius + .5), color)