|
22 | 22 | from rubin_sim.maf.stackers.date_stackers import DayObsStacker |
23 | 23 | from rubin_sim.maf.utils.opsim_utils import get_sim_data |
24 | 24 |
|
25 | | -# --------------------------------------------------------------------------- |
26 | | -# DayObs helpers |
27 | | -# DayObs is an integer YYYYMMDD in UTC-12, so it doesn't roll over mid-night. |
28 | | -# --------------------------------------------------------------------------- |
29 | | - |
30 | | - |
31 | | -def _dayobs_to_date(dayobs: int) -> datetime.date: |
32 | | - """Convert an integer YYYYMMDD dayobs to a datetime.date.""" |
33 | | - s = f"{int(dayobs):08d}" |
34 | | - return datetime.date(int(s[:4]), int(s[4:6]), int(s[6:])) |
35 | | - |
36 | | - |
37 | | -def _date_to_dayobs(d: datetime.date) -> int: |
38 | | - """Convert a datetime.date to an integer YYYYMMDD dayobs.""" |
39 | | - return int(d.strftime("%Y%m%d")) |
40 | | - |
41 | 25 |
|
42 | 26 | def _dayobs_range(start_dayobs: int, end_dayobs: int, step: int = 1) -> list[int]: |
43 | 27 | """Return a list of integer dayobs values from start to end (inclusive).""" |
| 28 | + |
| 29 | + def _dayobs_to_date(dayobs: int) -> datetime.date: |
| 30 | + s = f"{int(dayobs):08d}" |
| 31 | + return datetime.date(int(s[:4]), int(s[4:6]), int(s[6:])) |
| 32 | + |
44 | 33 | current = _dayobs_to_date(start_dayobs) |
45 | 34 | end_date = _dayobs_to_date(end_dayobs) |
46 | 35 | result = [] |
47 | 36 | while current <= end_date: |
48 | | - result.append(_date_to_dayobs(current)) |
| 37 | + dayobs = int(current.strftime("%Y%m%d")) |
| 38 | + result.append(dayobs) |
49 | 39 | current += datetime.timedelta(days=step) |
50 | 40 | return result |
51 | 41 |
|
|
0 commit comments