Skip to content

Commit

Permalink
Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanconn committed Nov 6, 2024
1 parent c48deac commit 47fd7e4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 35 deletions.
17 changes: 3 additions & 14 deletions chandra_aca/maude_decom.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@

# Maude fetch limits
MAUDE_SINGLE_FETCH_LIMIT = 3.0 * u.hour
MAUDE_FETCH_STEP_MAX = 3.0 * u.hour - 1.0 * u.second
MAUDE_FETCH_LIMIT = 5 * u.day

# The following are the tables in the docstring above. They appear to be transposed,
Expand Down Expand Up @@ -1219,9 +1218,7 @@ def _get_aca_packets(
return table


def get_aca_images(
start: CxoTimeLike, stop: CxoTimeLike, step_max: u.Quantity = None, **kwargs
):
def get_aca_images(start: CxoTimeLike, stop: CxoTimeLike, **kwargs):
"""
Fetch ACA image telemetry
Expand All @@ -1238,28 +1235,22 @@ def get_aca_images(
timestamp, CxoTimeLike
stop
timestamp, CxoTimeLike. stop - start cannot be greater than MAUDE_FETCH_LIMIT
step_max
maximum step size for fetching MAUDE data, u.Quantity, optional.
Overrides module var MAUDE_FETCH_STEP_MAX
kwargs
keyword args passed to get_aca_packets
Returns
-------
astropy.table.Table
"""
fetch_pad = 5 * u.second
start = CxoTime(start)
stop = CxoTime(stop)
if (stop + fetch_pad) - (start - fetch_pad) > MAUDE_FETCH_LIMIT:
if (stop - start) > MAUDE_FETCH_LIMIT:
raise ValueError(
f"stop - start cannot be greater than {MAUDE_FETCH_LIMIT}. "
"Set module variable MAUDE_FETCH_LIMIT if needed."
)
if step_max is None:
step_max = MAUDE_FETCH_STEP_MAX
maude_fetch_times = CxoTime.linspace(
start - fetch_pad, stop + fetch_pad, step_max=step_max
start, stop, step_max=MAUDE_SINGLE_FETCH_LIMIT - 1 * u.s
)
packet_stack = [
get_aca_packets(
Expand All @@ -1273,8 +1264,6 @@ def get_aca_images(
)
]
out = vstack(packet_stack)
# Trim to just have the requested time range
out = out[(out["TIME"] >= start.secs) & (out["TIME"] <= stop.secs)]
out.meta["times"] = maude_fetch_times
return out

Expand Down
24 changes: 3 additions & 21 deletions chandra_aca/tests/test_maude_decom.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,34 +275,16 @@ def test_partial_images():


def test_aca_images_chunks_1():
"""Test that a fetch longer than the single limit does not work
if the step limit is larger than the single limit"""
single_fetch_limit = maude_decom.MAUDE_SINGLE_FETCH_LIMIT
step_max = maude_decom.MAUDE_FETCH_STEP_MAX
maude_decom.MAUDE_FETCH_STEP_MAX = 2 * u.min
maude_decom.MAUDE_SINGLE_FETCH_LIMIT = 1 * u.min
try:
with pytest.raises(ValueError, match="Maximum allowed"):
maude_decom.get_aca_images("2020:001:00:00:00.000", "2020:001:00:02:00.000")
finally:
maude_decom.MAUDE_FETCH_STEP_MAX = step_max
maude_decom.MAUDE_SINGLE_FETCH_LIMIT = single_fetch_limit


def test_aca_images_chunks_2():
"""Test that a fetch longer than the maude step limit works"""
single_fetch_limit = maude_decom.MAUDE_SINGLE_FETCH_LIMIT
step_max = maude_decom.MAUDE_FETCH_STEP_MAX
maude_decom.MAUDE_FETCH_STEP_MAX = 1 * u.min - 1 * u.s
maude_decom.MAUDE_SINGLE_FETCH_LIMIT = 1 * u.min
start = "2023:001:00:00:01.000" # times picked close to 4.1 image boundary
stop = "2023:001:00:30:03.000" # times picked close to 4.1 image boundary
start = "2023:001:00:00:01.000"
stop = "2023:001:00:05:01.000"
tstart = CxoTime(start).secs
tstop = CxoTime(stop).secs
try:
imgs = maude_decom.get_aca_images(start, stop)
finally:
maude_decom.MAUDE_FETCH_STEP_MAX = step_max
maude_decom.MAUDE_SINGLE_FETCH_LIMIT = single_fetch_limit

imgs.sort(["TIME", "IMGNUM"])
Expand Down Expand Up @@ -334,7 +316,7 @@ def test_aca_images_chunks_2():
assert np.all(deltas_lte)


def test_aca_images_chunks_3():
def test_aca_images_chunks_2():
"""Test that a fetch longer than MAUDE_FETCH_LIMIT throws a ValueError"""
start = CxoTime("2023:001:00:00:01.000")
stop = start + (maude_decom.MAUDE_FETCH_LIMIT * 1.1)
Expand Down

0 comments on commit 47fd7e4

Please sign in to comment.