def time_of_solar_azimuth_today(self, azimuth): sun = ephem.Sun() sun.compute(self.obs) self.obs.date = datetime.utcnow().strftime("%Y/%m/%d %H:%M:%S") def err_az(x): self.obs.date = x sun.compute(self.obs) err_delta = sun.az - (math.pi / 180. * self.home['solar_azimuth']) #print('az: ', sun.az, ', solar_azimuth', self.home['solar_azimuth'], ', delta: ', err_delta) return err_delta x = self.obs.date #print 'Searching for the correct time...' ephem.newton(err_az, x, x + 0.01) dt = datetime.strptime(str(self.obs.date), '%Y/%m/%d %H:%M:%S') return (dt)
def risings(observer, obj, start_date = ephem.now(), end_date = None): alt_func = calc_alt_func(obj, observer) stepper = tracker.sat_stepper(observer, obj, start_date, end_date) # keep going until the sat has set (we ignore risings which already happened before the func got initialized) for date, obj in stepper: if obj.alt < 0: break print date, "wait for the sat to set", obj.alt prev = None risen = False rise_date = set_date = None # step through the different steps and always look at two consecutive ones for date, obj in stepper: if prev != None: if risen: if obj.alt < 0: set_date = ephem.date(ephem.newton(alt_func, prev, date)) risen = False #print date, "set at ", set_date if set_date - rise_date > 60.0 / 86400: yield rise_date, set_date else: # ignore pass else: pass #print date, "still above horizon", obj.alt else: if obj.alt >= 0: rise_date = ephem.date(ephem.newton(alt_func, prev, date)) risen = True #print date, "rise at", rise_date else: pass #print date, "still below", obj.alt prev = date
def time_for_altitude(obj, alt, startvals, date): CTA_N.date = date def rel_pos(when): CTA_N.date = when obj.compute(CTA_N) return obj.alt - alt start = float(ephem.date(startvals)) - 0.08 end = float(ephem.date(startvals)) + 0.08 start, end = min(start, end), max(start, end) return ephem.date(ephem.newton(rel_pos, start, end))
def solar_term(year, degrees, timezone='UTC'): """ Returns the date of the solar term for the given longitude and the given year. Solar terms are used for Chinese and Taiwanese holidays (e.g. Qingming Festival in Taiwan). More information: - https://en.wikipedia.org/wiki/Solar_term - https://en.wikipedia.org/wiki/Qingming This function is adapted from the following topic: https://answers.launchpad.net/pyephem/+question/110832 """ twopi = 2 * pi tz = pytz.timezone(timezone) # Find out the sun's current longitude. sun = ephem.Sun(ephem.Date(str(year))) # > Both hlon and hlat have a special meaning for the Sun and Moon. # > For a Sun body, they give the Earth's heliocentric longitude and # > latitude. current_longitude = sun.hlon - pi # Find approximately the right time of year. target_longitude = degrees * ephem.degree difference = (target_longitude - current_longitude) % twopi t0 = ephem.Date(str(year)) + 365.25 * difference / twopi # Zero in on the exact moment. def f(t): sun.compute(t) longitude = sun.hlon - pi return ephem.degrees(target_longitude - longitude).znorm d = ephem.Date(ephem.newton(f, t0, t0 + ephem.minute)) solar_term = d.datetime() + tz.utcoffset(d.datetime()) return solar_term.date()
def solar_term(self, year, degrees, timezone='UTC'): """ Returns the date of the solar term for the given longitude and the given year. Solar terms are used for Chinese and Taiwanese holidays (e.g. Qingming Festival in Taiwan). More information: - https://en.wikipedia.org/wiki/Solar_term - https://en.wikipedia.org/wiki/Qingming This function is adapted from the following topic: https://answers.launchpad.net/pyephem/+question/110832 """ twopi = 2 * pi tz = pytz.timezone(timezone) # Find out the sun's current longitude. sun = ephem.Sun(ephem.Date(str(year))) current_longitude = sun.hlong - pi # Find approximately the right time of year. target_longitude = degrees * ephem.degree difference = (target_longitude - current_longitude) % twopi t0 = ephem.Date(str(year)) + 365.25 * difference / twopi # Zero in on the exact moment. def f(t): sun.compute(t) longitude = sun.hlong - pi return ephem.degrees(target_longitude - longitude).znorm d = ephem.Date(ephem.newton(f, t0, t0 + ephem.minute)) solar_term = d.datetime() + tz.utcoffset(d.datetime()) return solar_term.date()
def when_is_sun_at_degrees_longitude(date: date, degrees: int) -> ephem.Date: # Thanks to Brandon Rhode @ https://answers.launchpad.net/pyephem/+question/110832 # Find out the sun's current longitude. sun = ephem.Sun(date) current_longitude = sun.hlong - ephem.pi # Find approximately the right time of year. target_longitude = degrees * ephem.degree difference = (target_longitude - current_longitude) % ephem.twopi t0 = date + 365.25 * difference / ephem.twopi # Zero in on the exact moment. def f(t): sun.compute(t) longitude = sun.hlong - ephem.pi return ephem.degrees(target_longitude - longitude).znorm return ephem.Date(ephem.newton(f, t0, t0 + ephem.minute))
def when_is_sun_at_degrees_longitude(degrees): # Find out the sun's current longitude. sun = ephem.Sun(d) current_longitude = sun.hlong - pi #print 365.25*current_longitude/twopi # Find approximately the right time of year. target_longitude = degrees * ephem.degree difference = (target_longitude - current_longitude) % twopi t0 = d + 365.25 * difference / twopi # Zero in on the exact moment. def f(t): sun.compute(t) longitude = sun.hlong - pi return ephem.degrees(target_longitude - longitude).znorm return ephem.Date(ephem.newton(f, t0, t0 + ephem.minute))
# Predictions section #Set start date to now start_date = ephem.now() #Keep track of fp command nr N = 0 #List of commands out = [] while start_date < ephem.now() + nr_days * 24 * ephem.hour: # Find a time where delphini enters the area while adst(start_date) > 0: start_date += 10 * ephem.second #FIND ENTRANCE d1 = ephem.newton(dst, start_date - ephem.minute, start_date) delphini.compute(d1) y1, x1 = (float(repr(delphini.sublat)) * (180 / np.pi), float(repr(delphini.sublong)) * (180 / np.pi)) #Find EXIT start_date += 240 * ephem.second d2 = ephem.newton(dst, start_date + ephem.minute, start_date) delphini.compute(d2) y2, x2 = (float(repr(delphini.sublat)) * (180 / np.pi), float(repr(delphini.sublong)) * (180 / np.pi)) start_date = d2 + 30 * ephem.minute d1 = get_epoch(d1) d2 = get_epoch(d2) duration = d2 - d1 out.append("tx_inhibit{:d},rparam download 5 0,0,0,0,0,{:d},0,0".format(