Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/331.bugfix.rst
Original file line number Diff line number Diff line change
@@ -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.
7 changes: 4 additions & 3 deletions sunraster/spectrogram_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions sunraster/tests/test_spectrogramsequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Loading