Skip to content

Commit

Permalink
Update get_Times utils.py
Browse files Browse the repository at this point in the history
added type annotation and changed t to t0 to better indicate it's an initial time, not a list of times.
  • Loading branch information
SuperdoerTrav authored Dec 6, 2024
1 parent 4451c5a commit 65b80e2
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions ssapy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1978,27 +1978,26 @@ def dd_to_hms(degree_decimal):
return f'{int(_h)}:{int(_m)}:{_s}'


def get_times(duration, freq, t):
def get_times(duration: Tuple[int, str], freq: Tuple[int, str], t0: Union[str, Time] = "2025-01-01") -> np.ndarray:
"""
Calculate a list of times spaced equally apart over a specified duration.
Parameters
----------
duration: int
The length of time to calculate times for.
freq: int, unit: str
frequency of time outputs in units provided
t: ssapy.utils.Time, optional
duration : tuple
A tuple containing the length of time and the unit (e.g., (30, 'day')).
freq : tuple
A tuple containing the frequency value and its unit (e.g., (1, 'hr')).
t0 : str or Time, optional
The starting time. Default is "2025-01-01".
example input:
duration=(30, 'day'), freq=(1, 'hr'), t=Time("2025-01-01", scale='utc')
Returns
-------
times: array-like
np.ndarray
A list of times spaced equally apart over the specified duration.
"""
if isinstance(t, str):
t = Time(t, scale='utc')
if isinstance(t0, str):
t0 = Time(t0, scale='utc')
unit_dict = {'second': 1, 'sec': 1, 's': 1, 'minute': 60, 'min': 60, 'hour': 3600, 'hr': 3600, 'h': 3600, 'day': 86400, 'd': 86400, 'week': 604800, 'month': 2630016, 'mo': 2630016, 'year': 31557600, 'yr': 31557600}
dur_val, dur_unit = duration
freq_val, freq_unit = freq
Expand All @@ -2014,7 +2013,7 @@ def get_times(duration, freq, t):
freq_seconds = freq_val * unit_dict[freq_unit.lower()]
timesteps = int(dur_seconds / freq_seconds) + 1

times = t + np.linspace(0, dur_seconds, timesteps) / unit_dict['day'] * u.day
times = t0 + np.linspace(0, dur_seconds, timesteps) / unit_dict['day'] * u.day
return times


Expand Down Expand Up @@ -2149,4 +2148,4 @@ def points_on_circle(r, v, rad, num_points=4):
# Translate the rotated points to the center point r
points_rotated = rotated_points + r.reshape(1, 3)

return points_rotated
return points_rotated

0 comments on commit 65b80e2

Please sign in to comment.