From 3bcd3afc612953f4d6c4ac4e1206afecc032f8b5 Mon Sep 17 00:00:00 2001 From: Jean Connelly Date: Thu, 17 Oct 2024 15:20:16 -0400 Subject: [PATCH 1/9] Add time linspace on get_aca_images for > 3hour range --- chandra_aca/maude_decom.py | 26 ++++++++++++++++----- chandra_aca/tests/test_maude_decom.py | 33 +++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/chandra_aca/maude_decom.py b/chandra_aca/maude_decom.py index 16966f8..b0d6a27 100644 --- a/chandra_aca/maude_decom.py +++ b/chandra_aca/maude_decom.py @@ -78,10 +78,12 @@ from struct import Struct from struct import unpack as _unpack +import astropy.units as u import maude import numpy as np from astropy.table import Table, vstack from Chandra.Time import DateTime +from cxotime import CxoTime, CxoTimeLike # The following are the tables in the docstring above. They appear to be transposed, # but the resultt agrees with level0. @@ -1209,24 +1211,36 @@ def _get_aca_packets( return table -def get_aca_images(start, stop, **maude_kwargs): +def get_aca_images(start: CxoTimeLike, stop: CxoTimeLike, **kwargs): """ Fetch ACA image telemetry Parameters ---------- start - timestamp interpreted as a Chandra.Time.DateTime + timestamp, CxoTimeLike stop - timestamp interpreted as a Chandra.Time.DateTime - maude_kwargs - keyword args passed to maude + timestamp, CxoTimeLike. stop - start cannot be greater than 1 day. + kwargs + keyword args passed to get_aca_packets Returns ------- astropy.table.Table """ - return get_aca_packets(start, stop, level0=True, **maude_kwargs) + if CxoTime(stop) - CxoTime(start) > 1 * u.day: + raise ValueError("stop - start cannot be greater than 1 day") + maude_fetch_times = CxoTime.linspace(start, stop, step_max=2.5 * u.hour) + packet_stack = [ + get_aca_packets( + start=maude_fetch_times[i], + stop=maude_fetch_times[i + 1], + level0=True, + **kwargs, + ) + for i in range(len(maude_fetch_times) - 1) + ] + return vstack(packet_stack) ###################### diff --git a/chandra_aca/tests/test_maude_decom.py b/chandra_aca/tests/test_maude_decom.py index 24acc24..b28f49b 100755 --- a/chandra_aca/tests/test_maude_decom.py +++ b/chandra_aca/tests/test_maude_decom.py @@ -7,6 +7,7 @@ import maude import numpy as np import pytest +from cxotime import CxoTime from chandra_aca import maude_decom @@ -272,6 +273,38 @@ def test_partial_images(): assert np.all(table[i]["IMG"].mask == mask[table[i]["IMGTYPE"]]) +def test_aca_images_chunks_1(): + """Test that a fetch longer than the maude 3 hour limit works""" + start = "2023:001:00:00:01.000" # times picked close to 4.1 image boundary + stop = "2023:001:03:30:01.000" # times picked close to 4.1 image boundary + imgs = maude_decom.get_aca_images(start, stop) + imgs.sort(["TIME", "IMGNUM"]) + + for slot in range(8): + # Confirm that the data is basically contiguous + ok_slot = imgs["IMGNUM"] == slot + # Confirm no duplicates by VCDUCTR + assert len(np.unique(imgs[ok_slot]["VCDUCTR"])) == len(imgs[ok_slot]) + # Confirm for these 8x8 data that there's no gap > 5 seconds + assert np.max(np.diff(imgs[ok_slot]["TIME"])) < 5 + + assert abs(imgs[0]["TIME"] - CxoTime(start).secs) < 2 + assert abs(imgs[-1]["TIME"] - CxoTime(stop).secs) < 2 + # Confirm that the beginning and end match the expected values + imgs_start = maude_decom.get_aca_images(start, CxoTime(start).secs + 60) + imgs_stop = maude_decom.get_aca_images(CxoTime(stop).secs - 60, stop) + assert np.all(imgs[0] == imgs_start[0]) + assert np.all(imgs[-1] == imgs_stop[-1]) + + +def test_aca_images_chunks_2(): + """Test that a fetch longer than 1 day throws a ValueError""" + start = "2023:001:00:00:00.000" + stop = "2023:003:00:00:00.000" + with pytest.raises(ValueError, match="stop - start cannot be greater than 1 day"): + maude_decom.get_aca_images(start, stop) + + def test_vcdu_vs_level0(): from astropy.table import Table From 5fa516188d203448a67beb5d596b01aa22eacbd3 Mon Sep 17 00:00:00 2001 From: Jean Connelly Date: Mon, 21 Oct 2024 12:06:49 -0400 Subject: [PATCH 2/9] Put step_max right at the limit --- chandra_aca/maude_decom.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chandra_aca/maude_decom.py b/chandra_aca/maude_decom.py index b0d6a27..6bdbcbb 100644 --- a/chandra_aca/maude_decom.py +++ b/chandra_aca/maude_decom.py @@ -1230,7 +1230,7 @@ def get_aca_images(start: CxoTimeLike, stop: CxoTimeLike, **kwargs): """ if CxoTime(stop) - CxoTime(start) > 1 * u.day: raise ValueError("stop - start cannot be greater than 1 day") - maude_fetch_times = CxoTime.linspace(start, stop, step_max=2.5 * u.hour) + maude_fetch_times = CxoTime.linspace(start, stop, step_max=3.0 * u.hour) packet_stack = [ get_aca_packets( start=maude_fetch_times[i], From 305d4584d3d4fefcd5919454b253aa52151b671b Mon Sep 17 00:00:00 2001 From: Jean Connelly Date: Tue, 5 Nov 2024 15:10:28 -0500 Subject: [PATCH 3/9] Improve testing for get_aca_images --- chandra_aca/maude_decom.py | 46 ++++++++++++++++++----- chandra_aca/tests/test_maude_decom.py | 53 ++++++++++++++++++++++----- 2 files changed, 81 insertions(+), 18 deletions(-) diff --git a/chandra_aca/maude_decom.py b/chandra_aca/maude_decom.py index 6bdbcbb..033f91d 100644 --- a/chandra_aca/maude_decom.py +++ b/chandra_aca/maude_decom.py @@ -85,6 +85,11 @@ from Chandra.Time import DateTime from cxotime import CxoTime, CxoTimeLike +# 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, # but the resultt agrees with level0. PIXEL_MAP = { @@ -1066,10 +1071,10 @@ def get_aca_packets( date_start, date_stop = DateTime(start), DateTime( stop ) # ensure input is proper date - if 24 * (date_stop - date_start) > 3: + if (CxoTime(stop) - CxoTime(start)) > MAUDE_SINGLE_FETCH_LIMIT: raise ValueError( - f"Requested {24 * (date_stop - date_start)} hours of telemetry. " - "Maximum allowed is 3 hours at a time" + f"Requested {CxoTime(stop) - CxoTime(start)} of telemetry. " + f"Maximum allowed is {MAUDE_SINGLE_FETCH_LIMIT} at a time (see MAUDE_SINGLE_FETCH_LIMIT)." ) stop_pad = 0 @@ -1211,16 +1216,26 @@ def _get_aca_packets( return table -def get_aca_images(start: CxoTimeLike, stop: CxoTimeLike, **kwargs): +def get_aca_images( + start: CxoTimeLike, stop: CxoTimeLike, step_max: u.Quantity = None, **kwargs +): """ Fetch ACA image telemetry + Fetch ACA image telemetry from MAUDE and return it as an astropy Table. With the default settings + and no additional kwargs, this calls `get_aca_packets()` in a configuration that uses MAUDE frames, + combines image data, and sets the TIME associated with each image to the midpoint of the integration + time during which that pixel data was collected (matches CXC L0 times). See `get_aca_packets()`. + + Parameters ---------- start timestamp, CxoTimeLike stop - timestamp, CxoTimeLike. stop - start cannot be greater than 1 day. + 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 @@ -1228,9 +1243,18 @@ def get_aca_images(start: CxoTimeLike, stop: CxoTimeLike, **kwargs): ------- astropy.table.Table """ - if CxoTime(stop) - CxoTime(start) > 1 * u.day: - raise ValueError("stop - start cannot be greater than 1 day") - maude_fetch_times = CxoTime.linspace(start, stop, step_max=3.0 * u.hour) + fetch_pad = 5 * u.second + start = CxoTime(start) + stop = CxoTime(stop) + if (stop + fetch_pad) - (start - fetch_pad) > 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 + ) packet_stack = [ get_aca_packets( start=maude_fetch_times[i], @@ -1240,7 +1264,11 @@ def get_aca_images(start: CxoTimeLike, stop: CxoTimeLike, **kwargs): ) for i in range(len(maude_fetch_times) - 1) ] - return vstack(packet_stack) + 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 ###################### diff --git a/chandra_aca/tests/test_maude_decom.py b/chandra_aca/tests/test_maude_decom.py index b28f49b..a141a24 100755 --- a/chandra_aca/tests/test_maude_decom.py +++ b/chandra_aca/tests/test_maude_decom.py @@ -4,6 +4,7 @@ import os import pickle +import astropy.units as u import maude import numpy as np import pytest @@ -274,10 +275,34 @@ def test_partial_images(): def test_aca_images_chunks_1(): - """Test that a fetch longer than the maude 3 hour limit works""" + """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:03:30:01.000" # times picked close to 4.1 image boundary - imgs = maude_decom.get_aca_images(start, stop) + stop = "2023:001:00:30:03.000" # times picked close to 4.1 image boundary + 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"]) for slot in range(8): @@ -288,20 +313,30 @@ def test_aca_images_chunks_1(): # Confirm for these 8x8 data that there's no gap > 5 seconds assert np.max(np.diff(imgs[ok_slot]["TIME"])) < 5 + # Confirm that the returned data times are within the start stop + assert imgs["TIME"][0] >= CxoTime(start).secs + assert imgs["TIME"][-1] <= CxoTime(stop).secs + + # Confirm that the beginning and end match the expected values assert abs(imgs[0]["TIME"] - CxoTime(start).secs) < 2 assert abs(imgs[-1]["TIME"] - CxoTime(stop).secs) < 2 - # Confirm that the beginning and end match the expected values + imgs_start = maude_decom.get_aca_images(start, CxoTime(start).secs + 60) imgs_stop = maude_decom.get_aca_images(CxoTime(stop).secs - 60, stop) assert np.all(imgs[0] == imgs_start[0]) assert np.all(imgs[-1] == imgs_stop[-1]) + # Check the linspace times in the returned data + used_step_max = 1 * u.min - 1 * u.s + deltas_lte = [t <= used_step_max for t in np.diff(imgs.meta["times"])] + assert np.all(deltas_lte) -def test_aca_images_chunks_2(): - """Test that a fetch longer than 1 day throws a ValueError""" - start = "2023:001:00:00:00.000" - stop = "2023:003:00:00:00.000" - with pytest.raises(ValueError, match="stop - start cannot be greater than 1 day"): + +def test_aca_images_chunks_3(): + """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) + with pytest.raises(ValueError, match="stop - start cannot be greater than"): maude_decom.get_aca_images(start, stop) From a2300c1771b19a138cf01ca95942e344a2f5d3bc Mon Sep 17 00:00:00 2001 From: Jean Connelly Date: Tue, 5 Nov 2024 18:36:21 -0500 Subject: [PATCH 4/9] Fix some DRY and use some CxoTime arithmetic --- chandra_aca/tests/test_maude_decom.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/chandra_aca/tests/test_maude_decom.py b/chandra_aca/tests/test_maude_decom.py index a141a24..d685bea 100755 --- a/chandra_aca/tests/test_maude_decom.py +++ b/chandra_aca/tests/test_maude_decom.py @@ -297,6 +297,8 @@ def test_aca_images_chunks_2(): 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 + tstart = CxoTime(start).secs + tstop = CxoTime(stop).secs try: imgs = maude_decom.get_aca_images(start, stop) finally: @@ -314,15 +316,15 @@ def test_aca_images_chunks_2(): assert np.max(np.diff(imgs[ok_slot]["TIME"])) < 5 # Confirm that the returned data times are within the start stop - assert imgs["TIME"][0] >= CxoTime(start).secs - assert imgs["TIME"][-1] <= CxoTime(stop).secs + assert imgs["TIME"][0] >= tstart + assert imgs["TIME"][-1] <= tstop # Confirm that the beginning and end match the expected values - assert abs(imgs[0]["TIME"] - CxoTime(start).secs) < 2 - assert abs(imgs[-1]["TIME"] - CxoTime(stop).secs) < 2 + assert abs(imgs[0]["TIME"] - tstart) < 2 + assert abs(imgs[-1]["TIME"] - tstop) < 2 - imgs_start = maude_decom.get_aca_images(start, CxoTime(start).secs + 60) - imgs_stop = maude_decom.get_aca_images(CxoTime(stop).secs - 60, stop) + imgs_start = maude_decom.get_aca_images(start, CxoTime(start) + 60 * u.s) + imgs_stop = maude_decom.get_aca_images(CxoTime(stop) - 60 * u.s, stop) assert np.all(imgs[0] == imgs_start[0]) assert np.all(imgs[-1] == imgs_stop[-1]) From 9cbc87adfac8b59df1d983be8513242067b51c6e Mon Sep 17 00:00:00 2001 From: Jean Connelly Date: Tue, 5 Nov 2024 18:40:03 -0500 Subject: [PATCH 5/9] Fix wrap and use zip --- chandra_aca/maude_decom.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/chandra_aca/maude_decom.py b/chandra_aca/maude_decom.py index 033f91d..8a1b447 100644 --- a/chandra_aca/maude_decom.py +++ b/chandra_aca/maude_decom.py @@ -1248,7 +1248,8 @@ def get_aca_images( stop = CxoTime(stop) if (stop + fetch_pad) - (start - fetch_pad) > MAUDE_FETCH_LIMIT: raise ValueError( - f"stop - start cannot be greater than {MAUDE_FETCH_LIMIT}. Set module variable MAUDE_FETCH_LIMIT if needed." + 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 @@ -1257,12 +1258,12 @@ def get_aca_images( ) packet_stack = [ get_aca_packets( - start=maude_fetch_times[i], - stop=maude_fetch_times[i + 1], + start=istart, + stop=istop, level0=True, **kwargs, ) - for i in range(len(maude_fetch_times) - 1) + for istart, istop in zip(maude_fetch_times[:-1], maude_fetch_times[1:]) ] out = vstack(packet_stack) # Trim to just have the requested time range From 15c66faca4fb5ef16985abc2b884219b9e6eb638 Mon Sep 17 00:00:00 2001 From: Jean Connelly Date: Tue, 5 Nov 2024 18:42:41 -0500 Subject: [PATCH 6/9] Some ruff formatting --- chandra_aca/maude_decom.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/chandra_aca/maude_decom.py b/chandra_aca/maude_decom.py index 8a1b447..172d392 100644 --- a/chandra_aca/maude_decom.py +++ b/chandra_aca/maude_decom.py @@ -694,8 +694,9 @@ def get_raw_aca_packets(start, stop, maude_result=None, **maude_kwargs): {'flags': int, 'packets': [], 'TIME': np.array([]), 'MNF': np.array([]), 'MJF': np.array([])} """ - date_start, date_stop = DateTime(start), DateTime( - stop + date_start, date_stop = ( + DateTime(start), + DateTime(stop), ) # ensure input is proper date stop_pad = 1.5 / 86400 # padding at the end in case of trailing partial ACA packets @@ -1068,8 +1069,9 @@ def get_aca_packets( combine = True calibrate = True - date_start, date_stop = DateTime(start), DateTime( - stop + date_start, date_stop = ( + DateTime(start), + DateTime(stop), ) # ensure input is proper date if (CxoTime(stop) - CxoTime(start)) > MAUDE_SINGLE_FETCH_LIMIT: raise ValueError( @@ -1222,10 +1224,11 @@ def get_aca_images( """ Fetch ACA image telemetry - Fetch ACA image telemetry from MAUDE and return it as an astropy Table. With the default settings - and no additional kwargs, this calls `get_aca_packets()` in a configuration that uses MAUDE frames, - combines image data, and sets the TIME associated with each image to the midpoint of the integration - time during which that pixel data was collected (matches CXC L0 times). See `get_aca_packets()`. + Fetch ACA image telemetry from MAUDE and return it as an astropy Table. With the default + settings and no additional kwargs, this calls `get_aca_packets()` in a configuration that + uses MAUDE frames, combines image data, and sets the TIME associated with each image to the + midpoint of the integration time during which that pixel data was collected (matches CXC L0 + times). See `get_aca_packets()`. Parameters @@ -1235,7 +1238,8 @@ def get_aca_images( 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 + 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 @@ -1263,7 +1267,9 @@ def get_aca_images( level0=True, **kwargs, ) - for istart, istop in zip(maude_fetch_times[:-1], maude_fetch_times[1:]) + for istart, istop in zip( + maude_fetch_times[:-1], maude_fetch_times[1:], strict=False + ) ] out = vstack(packet_stack) # Trim to just have the requested time range @@ -1306,8 +1312,9 @@ def get_raw_aca_blobs(start, stop, maude_result=None, **maude_kwargs): dict {'blobs': [], 'names': np.array([]), 'types': np.array([])} """ - date_start, date_stop = DateTime(start), DateTime( - stop + date_start, date_stop = ( + DateTime(start), + DateTime(stop), ) # ensure input is proper date stop_pad = 1.5 / 86400 # padding at the end in case of trailing partial ACA packets From c48deacada26b7ad03e480ac0159afc9a22bfb05 Mon Sep 17 00:00:00 2001 From: Jean Connelly Date: Tue, 5 Nov 2024 18:47:08 -0500 Subject: [PATCH 7/9] Fix long line --- chandra_aca/maude_decom.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/chandra_aca/maude_decom.py b/chandra_aca/maude_decom.py index 172d392..dafbb14 100644 --- a/chandra_aca/maude_decom.py +++ b/chandra_aca/maude_decom.py @@ -1076,7 +1076,8 @@ def get_aca_packets( if (CxoTime(stop) - CxoTime(start)) > MAUDE_SINGLE_FETCH_LIMIT: raise ValueError( f"Requested {CxoTime(stop) - CxoTime(start)} of telemetry. " - f"Maximum allowed is {MAUDE_SINGLE_FETCH_LIMIT} at a time (see MAUDE_SINGLE_FETCH_LIMIT)." + f"Maximum allowed is {MAUDE_SINGLE_FETCH_LIMIT} at a time " + "(see MAUDE_SINGLE_FETCH_LIMIT)." ) stop_pad = 0 From 47fd7e40457233f603ba9559a8683b9397fab11d Mon Sep 17 00:00:00 2001 From: Jean Connelly Date: Wed, 6 Nov 2024 15:53:50 -0500 Subject: [PATCH 8/9] Simplify --- chandra_aca/maude_decom.py | 17 +++-------------- chandra_aca/tests/test_maude_decom.py | 24 +++--------------------- 2 files changed, 6 insertions(+), 35 deletions(-) diff --git a/chandra_aca/maude_decom.py b/chandra_aca/maude_decom.py index dafbb14..fba6447 100644 --- a/chandra_aca/maude_decom.py +++ b/chandra_aca/maude_decom.py @@ -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, @@ -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 @@ -1238,9 +1235,6 @@ 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 @@ -1248,18 +1242,15 @@ def get_aca_images( ------- 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( @@ -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 diff --git a/chandra_aca/tests/test_maude_decom.py b/chandra_aca/tests/test_maude_decom.py index d685bea..61c3b53 100755 --- a/chandra_aca/tests/test_maude_decom.py +++ b/chandra_aca/tests/test_maude_decom.py @@ -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"]) @@ -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) From e748730dbccbb96d3d935784d4fc37b9d5b1ef6c Mon Sep 17 00:00:00 2001 From: Tom Aldcroft Date: Thu, 7 Nov 2024 06:39:52 -0500 Subject: [PATCH 9/9] Fix test to sort results --- chandra_aca/tests/test_maude_decom.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/chandra_aca/tests/test_maude_decom.py b/chandra_aca/tests/test_maude_decom.py index 61c3b53..a3f9011 100755 --- a/chandra_aca/tests/test_maude_decom.py +++ b/chandra_aca/tests/test_maude_decom.py @@ -307,6 +307,8 @@ def test_aca_images_chunks_1(): imgs_start = maude_decom.get_aca_images(start, CxoTime(start) + 60 * u.s) imgs_stop = maude_decom.get_aca_images(CxoTime(stop) - 60 * u.s, stop) + imgs_start.sort(["TIME", "IMGNUM"]) + imgs_stop.sort(["TIME", "IMGNUM"]) assert np.all(imgs[0] == imgs_start[0]) assert np.all(imgs[-1] == imgs_stop[-1])