Epoch Class¶
The Epoch class is the foundational time representation in Brahe, providing comprehensive support for multiple time systems and high-precision time computations with nanosecond accuracy.
Epoch
¶
Represents a specific instant in time.
Epoch is the primary and preferred mechanism for representing time in brahe. It accurately represents, tracks, and compares instants in time with nanosecond precision.
Internally, Epoch stores time in terms of days, seconds, and nanoseconds. This representation was chosen to enable accurate time system conversions using the IAU SOFA library (which operates in days and fractional days) while maintaining high precision for small time differences. The structure uses Kahan summation to accurately handle running sums over long periods without losing accuracy to floating-point rounding errors.
All arithmetic operations (addition, subtraction) use seconds as the default unit and return time differences in seconds.
The Epoch constructor accepts multiple input formats for convenience:
- Date components:
Epoch(year, month, day)- creates epoch at midnight - Full datetime:
Epoch(year, month, day, hour, minute, second, nanosecond)- full precision - Partial datetime:
Epoch(year, month, day, hour)orEpoch(year, month, day, hour, minute)etc. - ISO 8601 string:
Epoch("2024-01-01T12:00:00Z")- parse from string - Python datetime:
Epoch(datetime_obj)- convert from Python datetime - Copy constructor:
Epoch(other_epoch)- create a copy - Time system: All constructors accept optional
time_system=keyword argument (default: UTC)
Example
import brahe as bh
from datetime import datetime
# Multiple ways to create the same epoch
epc1 = bh.Epoch(2024, 1, 1, 12, 0, 0.0, 0.0)
epc2 = bh.Epoch("2024-01-01 12:00:00.000 UTC")
epc3 = bh.Epoch(datetime(2024, 1, 1, 12, 0, 0))
print(epc1)
# Output: 2024-01-01 12:00:00.000 UTC
# Create epoch at midnight
midnight = bh.Epoch(2024, 1, 1)
print(midnight)
# Output: 2024-01-01 00:00:00.000 UTC
# Use different time systems
gps_time = bh.Epoch(2024, 1, 1, 12, 0, 0.0, 0.0, time_system=bh.GPS)
print(gps_time)
# Output: 2024-01-01 12:00:00.000 GPS
# Perform arithmetic operations
epoch2 = epc1 + 3600.0 # Add one hour (in seconds)
diff = epoch2 - epc1 # Difference in seconds
print(f"Time difference: {diff} seconds")
# Output: Time difference: 3600.0 seconds
# Legacy constructors still available
epc4 = bh.Epoch.from_datetime(2024, 1, 1, 12, 0, 0.0, 0.0, bh.UTC)
epc5 = bh.Epoch.from_jd(2460310.0, bh.UTC)
Initialize instance.
__doc__
class-attribute
¶
__doc__ = 'Represents a specific instant in time.\n\nEpoch is the primary and preferred mechanism for representing time in brahe.\nIt accurately represents, tracks, and compares instants in time with nanosecond precision.\n\nInternally, Epoch stores time in terms of days, seconds, and nanoseconds. This representation\nwas chosen to enable accurate time system conversions using the IAU SOFA library (which operates\nin days and fractional days) while maintaining high precision for small time differences.\nThe structure uses Kahan summation to accurately handle running sums over long periods without\nlosing accuracy to floating-point rounding errors.\n\nAll arithmetic operations (addition, subtraction) use seconds as the default unit and return\ntime differences in seconds.\n\nThe Epoch constructor accepts multiple input formats for convenience:\n\n- **Date components**: `Epoch(year, month, day)` - creates epoch at midnight\n- **Full datetime**: `Epoch(year, month, day, hour, minute, second, nanosecond)` - full precision\n- **Partial datetime**: `Epoch(year, month, day, hour)` or `Epoch(year, month, day, hour, minute)` etc.\n- **ISO 8601 string**: `Epoch("2024-01-01T12:00:00Z")` - parse from string\n- **Python datetime**: `Epoch(datetime_obj)` - convert from Python datetime\n- **Copy constructor**: `Epoch(other_epoch)` - create a copy\n- **Time system**: All constructors accept optional `time_system=` keyword argument (default: UTC)\n\nExample:\n ```python\n import brahe as bh\n from datetime import datetime\n\n # Multiple ways to create the same epoch\n epc1 = bh.Epoch(2024, 1, 1, 12, 0, 0.0, 0.0)\n epc2 = bh.Epoch("2024-01-01 12:00:00.000 UTC")\n epc3 = bh.Epoch(datetime(2024, 1, 1, 12, 0, 0))\n print(epc1)\n # Output: 2024-01-01 12:00:00.000 UTC\n\n # Create epoch at midnight\n midnight = bh.Epoch(2024, 1, 1)\n print(midnight)\n # Output: 2024-01-01 00:00:00.000 UTC\n\n # Use different time systems\n gps_time = bh.Epoch(2024, 1, 1, 12, 0, 0.0, 0.0, time_system=bh.GPS)\n print(gps_time)\n # Output: 2024-01-01 12:00:00.000 GPS\n\n # Perform arithmetic operations\n epoch2 = epc1 + 3600.0 # Add one hour (in seconds)\n diff = epoch2 - epc1 # Difference in seconds\n print(f"Time difference: {diff} seconds")\n # Output: Time difference: 3600.0 seconds\n\n # Legacy constructors still available\n epc4 = bh.Epoch.from_datetime(2024, 1, 1, 12, 0, 0.0, 0.0, bh.UTC)\n epc5 = bh.Epoch.from_jd(2460310.0, bh.UTC)\n ```'
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to 'utf-8'. errors defaults to 'strict'.
__module__
class-attribute
¶
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to 'utf-8'. errors defaults to 'strict'.
time_system
property
¶
time_system: TimeSystem
Time system of the epoch.
Returns:
| Name | Type | Description |
|---|---|---|
TimeSystem |
TimeSystem
|
The time system used by this epoch |
__new__
builtin
¶
Create and return a new object. See help(type) for accurate signature.
day
method descriptor
¶
day() -> int
Returns the day component of the epoch in the epoch's time system.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The day of the month as an integer from 1 to 31 |
day_of_year
method descriptor
¶
day_of_year() -> float
Returns the day of year as a floating-point number in the epoch's time system.
The day of year is computed such that January 1st at midnight is 1.0, January 1st at noon is 1.5, January 2nd at midnight is 2.0, etc.
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
The day of year as a floating-point number (1.0 to 366.999...) |
Example
epoch = brahe.Epoch.from_datetime(2023, 4, 10, 12, 0, 0.0, 0.0, "UTC") doy = epoch.day_of_year() print(f"Day of year: {doy}") Day of year: 100.5
day_of_year_as_time_system
method descriptor
¶
day_of_year_as_time_system(time_system: TimeSystem) -> float
Returns the day of year as a floating-point number in the specified time system.
The day of year is computed such that January 1st at midnight is 1.0, January 1st at noon is 1.5, January 2nd at midnight is 2.0, etc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time_system
|
TimeSystem
|
The time system to use for the calculation |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
The day of year as a floating-point number (1.0 to 366.999...) |
Example
epoch = brahe.Epoch.from_datetime(2023, 4, 10, 12, 0, 0.0, 0.0, brahe.TimeSystem.UTC) doy_tai = epoch.day_of_year_as_time_system(brahe.TimeSystem.TAI) print(f"Day of year in TAI: {doy_tai}") Day of year in TAI: 100.50042824074075
from_date
builtin
¶
from_date(year: int, month: int, day: int, time_system: TimeSystem) -> Epoch
Create an Epoch from a calendar date at midnight.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
year
|
int
|
Gregorian calendar year |
required |
month
|
int
|
Month (1-12) |
required |
day
|
int
|
Day of month (1-31) |
required |
time_system
|
TimeSystem
|
Time system |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Epoch |
Epoch
|
The epoch representing midnight on the specified date |
Example
import brahe as bh
# Create an epoch at midnight on January 1, 2024 UTC
epc = bh.Epoch.from_date(2024, 1, 1, bh.TimeSystem.UTC)
print(epc)
# Output: 2024-01-01T00:00:00.000000000 UTC
# Create epoch in different time system
epc_tai = bh.Epoch.from_date(2024, 6, 15, bh.TimeSystem.TAI)
print(epc_tai)
# Output: 2024-06-15T00:00:00.000000000 TAI
from_datetime
builtin
¶
from_datetime(year: int, month: int, day: int, hour: int, minute: int, second: float, nanosecond: float, time_system: TimeSystem) -> Epoch
Create an Epoch from a complete Gregorian calendar date and time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
year
|
int
|
Gregorian calendar year |
required |
month
|
int
|
Month (1-12) |
required |
day
|
int
|
Day of month (1-31) |
required |
hour
|
int
|
Hour (0-23) |
required |
minute
|
int
|
Minute (0-59) |
required |
second
|
float
|
Second with fractional part |
required |
nanosecond
|
float
|
Nanosecond component |
required |
time_system
|
TimeSystem
|
Time system |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Epoch |
Epoch
|
The epoch representing the specified date and time |
Example
import brahe as bh
# Create epoch for January 1, 2024 at 12:30:45.5 UTC
epc = bh.Epoch.from_datetime(2024, 1, 1, 12, 30, 45.5, 0.0, bh.TimeSystem.UTC)
print(epc)
# Output: 2024-01-01T12:30:45.500000000 UTC
# With nanosecond precision
epc_ns = bh.Epoch.from_datetime(2024, 6, 15, 14, 30, 0.0, 123456789.0, bh.TimeSystem.TAI)
print(epc_ns)
# Output: 2024-06-15T14:30:00.123456789 TAI
from_day_of_year
builtin
¶
from_day_of_year(year: int, day_of_year: float, time_system: TimeSystem) -> Epoch
Create an Epoch from a year and floating-point day-of-year.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
year
|
int
|
Gregorian calendar year |
required |
day_of_year
|
float
|
Day of year as a floating-point number (1.0 = January 1st, 1.5 = January 1st noon, etc.) |
required |
time_system
|
TimeSystem
|
Time system |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Epoch |
Epoch
|
The epoch representing the specified day of year |
Example
import brahe as bh
# Create epoch for day 100 of 2024 at midnight
epc = bh.Epoch.from_day_of_year(2024, 100.0, bh.TimeSystem.UTC)
print(epc)
# Output: 2024-04-09T00:00:00.000000000 UTC
# Create epoch for day 100.5 (noon on day 100)
epc_noon = bh.Epoch.from_day_of_year(2024, 100.5, bh.TimeSystem.UTC)
year, month, day, hour, minute, second, ns = epc_noon.to_datetime()
print(f"{year}-{month:02d}-{day:02d} {hour:02d}:{minute:02d}:{second:06.3f}")
# Output: 2024-04-09 12:00:00.000
from_gps_date
builtin
¶
from_gps_nanoseconds
builtin
¶
from_gps_seconds
builtin
¶
from_jd
builtin
¶
from_jd(jd: float, time_system: TimeSystem) -> Epoch
Create an Epoch from a Julian Date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
jd
|
float
|
Julian date |
required |
time_system
|
TimeSystem
|
Time system |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Epoch |
Epoch
|
The epoch representing the Julian date |
from_mjd
builtin
¶
from_mjd(mjd: float, time_system: TimeSystem) -> Epoch
Create an Epoch from a Modified Julian Date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mjd
|
float
|
Modified Julian date |
required |
time_system
|
TimeSystem
|
Time system |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Epoch |
Epoch
|
The epoch representing the Modified Julian date |
from_string
builtin
¶
Create an Epoch from an ISO 8601 formatted string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
datestr
|
str
|
ISO 8601 formatted date string (e.g., "2024-01-01T12:00:00.000000000 UTC") |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Epoch |
Epoch
|
The epoch representing the parsed date and time |
Example
import brahe as bh
# Parse ISO 8601 string with full precision
epc = bh.Epoch.from_string("2024-01-01T12:00:00.000000000 UTC")
print(epc)
# Output: 2024-01-01T12:00:00.000000000 UTC
# Parse different time systems
epc_tai = bh.Epoch.from_string("2024-06-15T14:30:45.123456789 TAI")
print(epc_tai.time_system)
# Output: TimeSystem.TAI
gast
method descriptor
¶
gast(angle_format: AngleFormat) -> float
Get the Greenwich Apparent Sidereal Time (GAST) for this epoch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
angle_format
|
AngleFormat
|
Format for the returned angle (radians or degrees) |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
GAST angle |
gmst
method descriptor
¶
gmst(angle_format: AngleFormat) -> float
Get the Greenwich Mean Sidereal Time (GMST) for this epoch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
angle_format
|
AngleFormat
|
Format for the returned angle (radians or degrees) |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
GMST angle |
gps_date
method descriptor
¶
gps_date() -> Tuple
Get the GPS week number and seconds into the week.
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
Tuple
|
A tuple containing (week, seconds_into_week) |
gps_nanoseconds
method descriptor
¶
gps_nanoseconds() -> float
Get the nanoseconds since GPS epoch (January 6, 1980, 00:00:00 UTC).
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
GPS nanoseconds |
gps_seconds
method descriptor
¶
gps_seconds() -> float
Get the seconds since GPS epoch (January 6, 1980, 00:00:00 UTC).
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
GPS seconds |
hour
method descriptor
¶
hour() -> int
Returns the hour component of the epoch in the epoch's time system.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The hour as an integer from 0 to 23 |
isostring
method descriptor
¶
isostring() -> str
Convert the epoch to an ISO 8601 formatted string.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
ISO 8601 formatted date string with full nanosecond precision |
isostring_with_decimals
method descriptor
¶
jd
method descriptor
¶
jd() -> float
Get the Julian Date in the epoch's time system.
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Julian date |
jd_as_time_system
method descriptor
¶
jd_as_time_system(time_system: TimeSystem) -> float
Get the Julian Date in a specified time system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time_system
|
TimeSystem
|
Target time system for the conversion |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Julian date in the specified time system |
minute
method descriptor
¶
minute() -> int
Returns the minute component of the epoch in the epoch's time system.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The minute as an integer from 0 to 59 |
mjd
method descriptor
¶
mjd() -> float
Get the Modified Julian Date in the epoch's time system.
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Modified Julian date |
mjd_as_time_system
method descriptor
¶
mjd_as_time_system(time_system: TimeSystem) -> float
Get the Modified Julian Date in a specified time system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time_system
|
TimeSystem
|
Target time system for the conversion |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Modified Julian date in the specified time system |
month
method descriptor
¶
month() -> int
Returns the month component of the epoch in the epoch's time system.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The month as an integer from 1 to 12 |
nanosecond
method descriptor
¶
nanosecond() -> float
Returns the nanosecond component of the epoch in the epoch's time system.
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
The nanosecond component as a floating-point number |
now
builtin
¶
now() -> Epoch
Create an Epoch representing the current UTC instant.
This method uses the system clock to get the current time and creates an Epoch in the UTC time system.
Returns:
| Name | Type | Description |
|---|---|---|
Epoch |
Epoch
|
The epoch representing the current instant in time in UTC |
Example
import brahe as bh
# Get current time as an Epoch
now = bh.Epoch.now()
print(f"Current time: {now}")
print(f"Time system: {now.time_system}")
# Output: Time system: TimeSystem.UTC
# Use in orbital calculations
import numpy as np
current_epoch = bh.Epoch.now()
oe = np.array([bh.R_EARTH + 500e3, 0.01, np.radians(97.8), 0.0, 0.0, 0.0])
state = bh.state_osculating_to_cartesian(oe, bh.AngleFormat.RADIANS)
propagator = bh.KeplerianPropagator.from_eci(current_epoch, state, 60.0)
second
method descriptor
¶
second() -> float
Returns the second component of the epoch in the epoch's time system.
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
The second as a floating-point number from 0.0 to 59.999... |
to_datetime
method descriptor
¶
to_datetime() -> Tuple
Convert the epoch to Gregorian calendar date and time in the epoch's time system.
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
Tuple
|
A tuple containing (year, month, day, hour, minute, second, nanosecond) |
to_datetime_as_time_system
method descriptor
¶
to_datetime_as_time_system(time_system: TimeSystem) -> Tuple
Convert the epoch to Gregorian calendar date and time in a specified time system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time_system
|
TimeSystem
|
Target time system for the conversion |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
Tuple
|
A tuple containing (year, month, day, hour, minute, second, nanosecond) |
Example
import brahe as bh
# Create epoch in UTC and convert to TAI
epc = bh.Epoch.from_datetime(2024, 1, 1, 12, 0, 0.0, 0.0, bh.TimeSystem.UTC)
year, month, day, hour, minute, second, ns = epc.to_datetime_as_time_system(bh.TimeSystem.TAI)
print(f"TAI: {year}-{month:02d}-{day:02d} {hour:02d}:{minute:02d}:{second:06.3f}")
# Output: TAI: 2024-01-01 12:00:37.000
to_string_as_time_system
method descriptor
¶
to_string_as_time_system(time_system: TimeSystem) -> str
Convert the epoch to a string representation in a specified time system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time_system
|
TimeSystem
|
Target time system for the conversion |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
String representation of the epoch |