Skip to content

Utilities

__all__ = ['logger', 'arange_gpstime', 'validate_gps_week'] module-attribute

Copyright 2020 The Aerospace Corporation

arange_gpstime(start_gpstime, duration_s, step_ms)

Create a list of GPSTimes in sequence.

The purpose of this function is to create a list that represents a sequence of GPSTimes of the specified duration with the specified step size.

This function is an analogue of the numpy.arange() function, but operates on GPSTimes.

Parameters

start_gpstime : GPSTime The GPSTime to start the sequence duration_s : float The duration of the sequence, in seconds step_ms : float The step size, in milliseconds

Returns

List[GPSTime] The sequence of GPSTimes

Notes

Like numpy.arange, this does not include the final element. That is, if the start is at 0 with a duration of 5 and step of 1, the sequence would return [0, 1, 2, 3, 4]

See Also

numpy.arange() arange_datetime()

Todo

.. todo:: Determine if this still works if a np.ndarray is returned instead of a list

Source code in gps_time/utilities.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
def arange_gpstime(
    start_gpstime: GPSTime, duration_s: float, step_ms: float
) -> List[GPSTime]:
    """Create a list of GPSTimes in sequence.

    The purpose of this function is to create a list that represents a
    sequence of GPSTimes of the specified duration with the specified step
    size.

    This function is an analogue of the `numpy.arange()` function, but
    operates on GPSTimes.

    Parameters
    ----------
    start_gpstime : GPSTime
        The GPSTime to start the sequence
    duration_s : float
        The duration of the sequence, in seconds
    step_ms : float
        The step size, in milliseconds

    Returns
    -------
    List[GPSTime]
        The sequence of GPSTimes

    Notes
    -----
    Like `numpy.arange`, this does not include the final element. That is, if
    the start is at 0 with a duration of 5 and step of 1, the sequence would
    return [0, 1, 2, 3, 4]

    See Also
    --------
    `numpy.arange()`
    `arange_datetime()`

    Todo
    ----
    .. todo:: Determine if this still works if a np.ndarray is returned
        instead of a list

    """
    return list(start_gpstime + np.arange(0, duration_s, step_ms / 1000))

validate_gps_week(full_week, gps_week)

Validate that the week numbers are consistent.

This function validates that the full GPS week number (i.e. the number of weeks since 6 Jan 1980) and the mod-1024 week numbers are consistent. If they are not, it raises an error.

Parameters

full_week : int The number of weeks since 6 Jan 1980 gps_week : int The mod-1024 GPS week

Returns

None

Source code in gps_time/utilities.py
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
def validate_gps_week(full_week: int, gps_week: int) -> None:
    """Validate that the week numbers are consistent.

    This function validates that the full GPS week number (i.e. the number of
    weeks since 6 Jan 1980) and the mod-1024 week numbers are consistent. If
    they are not, it raises an error.

    Parameters
    ----------
    full_week : int
        The number of weeks since 6 Jan 1980
    gps_week : int
        The mod-1024 GPS week

    Returns
    -------
    None
    """

    """
    Raises
    ------
    ValueError
        If the `full_week` and `gps_week` disagree

    """
    if full_week % 1024 != gps_week:
        raise ValueError(
            "".join(["Full GPS Week {} must be mod 1024 of ", "GPS Week {}"]).format(
                full_week, gps_week
            )
        )