Skip to content

skyweaver.timegrid

Time grid utilities for satellite simulations.

TimeGrid dataclass

TimeGrid(start, stop, cadence_s)

Regular time sampling grid.

Parameters:

Name Type Description Default
start datetime

Start datetime of the grid. Naive datetimes are interpreted as UTC.

required
stop datetime

Stop datetime of the grid. Naive datetimes are interpreted as UTC.

required
cadence_s float

Sampling cadence in seconds. Must be positive.

required
Notes

The generated grid includes the start time and includes the stop time only if it lies exactly on the cadence.

duration_s property

duration_s

Return the total duration of the grid in seconds.

n_times property

n_times

Return the number of samples in the grid.

offsets_s property

offsets_s

Return sample offsets from start in seconds.

__post_init__

__post_init__()

Validate inputs and normalize datetimes to UTC.

Source code in src/skyweaver/timegrid.py
53
54
55
56
57
58
59
60
61
62
63
64
65
def __post_init__(self) -> None:
    """Validate inputs and normalize datetimes to UTC."""
    start_utc = _ensure_utc(self.start)
    stop_utc = _ensure_utc(self.stop)

    object.__setattr__(self, "start", start_utc)
    object.__setattr__(self, "stop", stop_utc)

    if self.cadence_s <= 0.0:
        raise ValueError("cadence_s must be positive")

    if self.stop < self.start:
        raise ValueError("stop must be greater than or equal to start")

datetimes

datetimes()

Return the grid as a list of UTC datetimes.

Source code in src/skyweaver/timegrid.py
82
83
84
def datetimes(self) -> list[datetime]:
    """Return the grid as a list of UTC datetimes."""
    return [self.start + timedelta(seconds=float(offset_s)) for offset_s in self.offsets_s]

skyfield

skyfield()

Return the grid as a Skyfield Time array.

Source code in src/skyweaver/timegrid.py
86
87
88
89
def skyfield(self) -> Time:
    """Return the grid as a Skyfield ``Time`` array."""
    ts = load.timescale()
    return ts.from_datetimes(self.datetimes())

summary

summary()

Return a compact human-readable summary.

Source code in src/skyweaver/timegrid.py
91
92
93
94
95
96
97
98
def summary(self) -> str:
    """Return a compact human-readable summary."""
    return (
        f"TimeGrid(start={self.start.isoformat()}, "
        f"stop={self.stop.isoformat()}, "
        f"cadence_s={self.cadence_s:.3f}, "
        f"n_times={self.n_times})"
    )