Skip to content
dbuscher edited this page Oct 24, 2011 · 11 revisions

Astropy.time discussion

##Storage of time in a common date format:

There are multiple suggestions for this that offer different advantages. Most often however it's a trade-off between precision and range (x many giga years) in contrast to ease-of-use and size. The question remains how much is really needed.

  • Storing time with int64 as days since Julian day and fraction of the day in float64
    • high precision, large range - more memory footprint
    • A variant of this is DJ Bernstein's TAI format (http://cr.yp.to/libtai.html) using two int64s. The fixed-point format makes inadvertently losing precision through "carrying over" the int into the float impossible.
  • Storing time with float64 as seconds since 1998.0
    • easy to use, low memory footprint - not as accurate and lower range
  • Storing time with float128 as seconds?
    • high precision - float128 maybe not available on all platforms?
  • Storing time as a python long in nanoseconds relative to some date (julian day).
    • very high precision - not a numpy object maybe computationally more expensive.

There could be a compromise:

Inside the AstroTime class store time with very high precision and larger memory footprint (int64+float64, python long, float128, ...). But generally advocate the use of storing time as MJD in a float64. The MJD-float64 variant can be easily used in arrays, can be written to databases very easily and should be more than accurate enough for most use cases. For conversion to other systems the AstroTime class can be used.

#First draft example framework class AstroTime(object): """Class to store a time variable. The internal format uses the January 1, 4713 BC Greenwich noon as the zeropoint (Julian Day) and stores the date as days to this zeropoint in ~numpy.int64 and the fraction of a day in ~numpy.float64."""

    @classmethod
    def from_jd(cls, jd_time):
        """Instantiate an AstroTime-object with Julian Date"""
        days = np.int64(jd_time)
        fraction_of_days = np.float64(jd_time - days)
        return cls(days, fraction_of_days)
    
    def __init__(self, days, fraction_of_days):
        """Initialize an AstroTime-object with the days and fraction of days from the January 1, 4713 BC Greenwich noon"""
        self.days = np.int64(days)
        self.fraction = np.float64(fraction_of_days)
    
    
    def to_jd(self):
        """return the date as JD in a float64"""
        return np.float64(self.days+self.fraction)
Clone this wiki locally