Exemplo n.º 1
0
def calculate_julian(year, month, day, hours=None, minutes=None, seconds=None):
    """
    Calculate the julian date value.
    :param year:    the year
    :param month:   the month
    :param day:     the day
    :param hours:   the hours
    :param minutes: the minutes
    :param seconds: the seconds
    :return:        the julian date
    """
    yr = mathutils.to_int(year)
    mth = mathutils.to_int(month)
    day = mathutils.to_int(day)
    hrs = mathutils.to_int(hours)
    mns = mathutils.to_int(minutes)
    scs = mathutils.to_float(seconds)
    if mth <= 2:
        yr -= 1
        mth += 12
    if yr >= 1582:
        A = yr / 100
        B = 2 - A + (A / 4)
    else:
        B = 0
    if yr < 0:
        C = int((365.25 * yr) - 0.75)
    else:
        C = int(365.25 * yr)
    D = int(30.6001 * (mth + 1))
    return 1720994.5 + B + C + D + day + (((
        (mathutils.fix(scs, TIME_SECONDS_PRECISION) / 60.0) + float(mns)) /
                                           60.0) + float(hrs)) / 24.0
Exemplo n.º 2
0
def dms_from_dd(dd):
    dd = mathutils.to_float(dd, None)
    if dd is not None:
        d = int(dd)
        dm = abs(dd - d) * 60.0
        m = int(dm + 0.0005)
        s = mathutils.fix((dm - m) * 60.0, 2)
        return d, m, s
    return None
Exemplo n.º 3
0
 def get_tuple(self):
     """
     Get the current date/time as a tuple.
     :return:    the date/time (year, month, day[, hours, minutes, seconds[, mode]])
     """
     if self.year is not None:
         if self.hours is not None:
             secs = mathutils.fix(self.seconds, TIME_SECONDS_PRECISION)
             if self.mode is not None:
                 return self.year, self.month, self.day, self.hours, self.minutes, secs, self.mode
             return self.year, self.month, self.day, self.hours, self.minutes, secs
         return self.year, self.month, self.day
     return None
Exemplo n.º 4
0
def hms_from_dh(dh):
    """
    Converts decimal hours to a time tuple.
    :param dh:  decimal hours to convert
    :return:    time tuple (hours, mins, secs)
    """
    dh = mathutils.to_float(dh, None)
    if dh is not None:
        h = int(dh)
        dm = abs(dh - h) * 60.0
        m = int(dm + 0.0005
                )  # add a tiny amount to make sure the minutes round properly
        s = mathutils.fix((dm - m) * 60.0, 2)
        return h, m, s
    return None
Exemplo n.º 5
0
def __convert_date_time(res):
    """
    Convert the response array (usually from keyboard input) into a date time tuple.

    :param res: the response to convert
    :return:    an unvalidated date time tuple
    """
    dat = []
    i = 0
    while (i < len(res)) and (i < 7):
        if i < 5:
            dat.append(mathutils.to_int(res[i]))
        elif i == 5:
            dat.append(mathutils.fix(res[i], astrodate.TIME_SECONDS_PRECISION))
        else:
            dat.append(res[i])
        i += 1
    return dat
Exemplo n.º 6
0
def read_datetime(default_datetime=None,
                  prompt=DATETIME_PROMPT,
                  format=DATETIME_FORMAT):
    """
    Read a date time tuple.

    :param default_datetime:    the default date time tuple to use
    :param prompt:              the prompt to use (optional)
    :param format:              the format to use (optional)
    :return:    the date time tuple (year, month, day[, hours, minutes, seconds, mode])
    """
    while True:
        res = sio.read_delimited_line(DATE_DELIMITER, prompt, None, format,
                                      default_datetime)
        if (type(res) is str) and (len(res) == 0):
            return None
        if (type(res) is str) and (len(res) == 1) and (res[0] == '?'):
            sio.print_newline()
            sio.print_text(DATETIME_HELP)
            sio.print_newline()
        elif (type(res) is str) and (len(res) == 1) and (res[0] == '*'):
            current = time.time()
            dat = time.gmtime(current)
            #   dat = (year, month, day, hour, min, sec, weekday, julian day, daylight savings flag)
            year = dat[0]
            month = dat[1]
            day = dat[2]
            hours = dat[3]
            minutes = dat[4]
            seconds = mathutils.fix(dat[5], astrodate.TIME_SECONDS_PRECISION)
            mode = astrodate.TIME_MODE_UT
            return year, month, day, hours, minutes, seconds, mode
        else:
            dat = __convert_date_time(res)
            if not astrodate.validate_date(dat, True):
                sio.print_newline()
                sio.print_text(DATETIME_INVALID)
                sio.print_newline()
            else:
                return tuple(dat)
Exemplo n.º 7
0
 def calculate_angular_separation(self, coord2):
     if (self.mode == coord2.mode) and (self.is_equatorial() or self.is_ecliptic()):
         c1_1 = self.get_dd1()
         c2_1 = coord2.get_dd1()
         if self.is_hours():
             c1_1 *= 15.0
             c2_1 *= 15.0
         diff_c1_1_c2_1 = c1_1 - c2_1
         diff_c1_1_c2_1_rad = diff_c1_1_c2_1 * math.pi / 180.0
         c1_2 = self.get_dd2()
         c1_2_rad = c1_2 * math.pi / 180.0
         c2_2 = coord2.get_dd2()
         c2_2_rad = c2_2 * math.pi / 180.0
         cos_d = (math.sin(c1_2_rad) * math.sin(c2_2_rad)) + (math.cos(c1_2_rad) * math.cos(c2_2_rad) * math.cos(diff_c1_1_c2_1_rad))
         dd = math.acos(cos_d) * 180.0 / math.pi
         if (dd <= 0.16666667) or (dd >= 179.83333333):
             t1 = math.cos((c1_2 + c2_2) / 2.0)
             t2 = c1_1 - c2_1
             t3 = c1_2 - c2_2
             t = (t1 * t1) * (t2 * t2) + (t3 * t3)
             dd = math.sqrt(t)
         d, m, s = dms_from_dd(dd)
         return d, m, mathutils.fix(s, 2)
     raise ValueError, "Invalid coordinate! (Must be Equatorial or Ecliptic)"