def approx_moment_of_depression(self, tee, alpha, early): """Return the moment in local time near tee when depression angle of sun is alpha (negative if above horizon) at location; early is true when MORNING event is sought and false for EVENING. Raise VlueError if depression angle is not reached.""" ttry = self.sine_offset(tee, alpha) date = Clock.ordinal_from_moment(tee) if alpha >= 0: if early: alt = date else: alt = date + 1 else: alt = date + Clock.days_from_hours(12) if abs(ttry) > 1: value = self.sine_offset(alt, alpha) else: value = ttry if abs(value) <= 1: temp = -1 if early else 1 temp *= mod(Clock.days_from_hours(12) + arcsin_degrees(value) / 360, 1) - Clock.days_from_hours(6) temp += date + Clock.days_from_hours(12) return self.local_from_apparent(temp) else: raise ValueError("Depression angle not reached")
def hindu_tithi_occur(l_month, tithi, tee, l_year): """Return the ordinal date of occurrence of Hindu lunar tithi prior to sundial time, tee, in Hindu lunar month, l_month, and year, l_year.""" approx = hindu_date_occur(l_month, int(math.floor(tithi)), l_year) lunar = HinduLunarDate.day_at_or_after(tithi, approx - 2) ttry = Clock.ordinal_from_moment(lunar) tee_h = HinduLunarDate.UJJAIN.standard_from_sundial(ttry + tee) if lunar <= tee_h or HinduLunarDate.lunar_phase( HinduLunarDate.UJJAIN.standard_from_sundial(ttry + 1 + tee)) > 12 * tithi: return ttry else: return ttry + 1
def sundial_time(cls, tee): """Return Hindu local time of temporal moment, tee.""" date = Clock.ordinal_from_moment(tee) time = tee % 1 q = int(math.floor(4 * time)) if q == 0: a = cls.sunset(date - 1) b = cls.sunrise(date) t = Clock.days_from_hours(-6) elif q == 3: a = cls.sunset(date) b = cls.sunrise(date + 1) t = Clock.days_from_hours(18) else: a = cls.sunrise(date) b = cls.sunset(date) t = Clock.days_from_hours(6) return a + (2 * (b - a) * (time - t))
def standard_from_sundial(self, tee): """Return standard time of temporal moment, tee, at location, location.""" date = Clock.ordinal_from_moment(tee) hour = 24 * mod(tee, 1) if 6 <= hour <= 18: h = self.daytime_temporal_hour(date) elif (hour < 6): h = self.nighttime_temporal_hour(date - 1) else: h = self.nighttime_temporal_hour(date) # return if 6 <= hour <= 18: return self.sunrise(date) + ((hour - 6) * h) elif hour < 6: return self.sunset(date - 1) + ((hour + 6) * h) else: return self.sunset(date) + ((hour - 18) * h)