From f24e12817b1793c0534b90c19c6e130f79b3b359 Mon Sep 17 00:00:00 2001 From: Nabil Freij Date: Sun, 27 Sep 2026 20:48:23 -0700 Subject: [PATCH 1/2] Report the earliest and latest times in SpectrogramSequence.__str__ The time range used the first time of the first cube and the last time of the last cube, so a sequence whose time runs backwards along an axis (for example an IRIS v34 raster) printed its range with the start after the end. --- sunraster/spectrogram_sequence.py | 7 ++++--- sunraster/tests/test_spectrogramsequence.py | 13 +++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/sunraster/spectrogram_sequence.py b/sunraster/spectrogram_sequence.py index 9a65700..68bdea0 100644 --- a/sunraster/spectrogram_sequence.py +++ b/sunraster/spectrogram_sequence.py @@ -168,9 +168,10 @@ def __str__(self): ) data0 = self.data[0] if data0._time_name: - start_time = data0.time if data0.time.isscalar else data0.time.squeeze()[0] - data_1 = self.data[-1] - stop_time = data_1.time if data_1.time.isscalar else data_1.time.squeeze()[-1] + # Time can run backwards along an axis (for example IRIS v34 rasters), + # so the first and last values are not always the start and end. + start_time = min(cube.time.min() for cube in self.data) + stop_time = max(cube.time.max() for cube in self.data) time_period = start_time if start_time == stop_time else Time([start_time.iso, stop_time.iso]) else: time_period = None diff --git a/sunraster/tests/test_spectrogramsequence.py b/sunraster/tests/test_spectrogramsequence.py index 73d4825..aa395b6 100644 --- a/sunraster/tests/test_spectrogramsequence.py +++ b/sunraster/tests/test_spectrogramsequence.py @@ -322,3 +322,16 @@ def test_sns_instrument_axes_types(input_sequence, expected_sns_axes_types): def test_slice_as_raster(): assert isinstance(sequence_DN[:, 0], SpectrogramSequence) + + +def test_str_time_range_when_time_runs_backwards(): + # IRIS v34 rasters step backwards in time, so the first time is the latest one. + times = Time("2017-01-01") + TimeDelta(np.arange(TIME_DIM_LEN * 2)[::-1], format="sec") + cubes = [] + for i in range(2): + cube = SpectrogramCube(SOURCE_DATA_DN, WCS0, u.ct, SOURCE_UNCERTAINTY_DN, meta=meta_exposure0) + cube.extra_coords.add("time", 0, times[i * TIME_DIM_LEN : (i + 1) * TIME_DIM_LEN]) + cubes.append(cube) + assert "Time Range: ['2017-01-01 00:00:00.000' '2017-01-01 00:00:03.000']" in str( + RasterSequence(cubes, meta=meta_seq, common_axis=0) + ) From 33bb8980a6d628f54da6f2cfeb622e6aa22c87cd Mon Sep 17 00:00:00 2001 From: Nabil Freij Date: Sun, 27 Sep 2026 21:07:46 -0700 Subject: [PATCH 2/2] Add changelog entry for #331 --- changelog/331.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/331.bugfix.rst diff --git a/changelog/331.bugfix.rst b/changelog/331.bugfix.rst new file mode 100644 index 0000000..21025eb --- /dev/null +++ b/changelog/331.bugfix.rst @@ -0,0 +1 @@ +The time range printed for a `~sunraster.SpectrogramSequence` now runs from the earliest to the latest time, even when time runs backwards along an axis (for example IRIS v34 rasters); before, it could print the start after the end.