diff --git a/changelog/172.feature.rst b/changelog/172.feature.rst new file mode 100644 index 00000000..6fece416 --- /dev/null +++ b/changelog/172.feature.rst @@ -0,0 +1 @@ +Added frequency_at_index method to GenericSpectrogram class diff --git a/radiospectra/spectrogram/spectrogrambase.py b/radiospectra/spectrogram/spectrogrambase.py index f1cb2b3f..f0119625 100644 --- a/radiospectra/spectrogram/spectrogrambase.py +++ b/radiospectra/spectrogram/spectrogrambase.py @@ -107,3 +107,13 @@ def __repr__(self): f" {self.wavelength.min} - {self.wavelength.max}," f" {self.start_time.isot} to {self.end_time.isot}>" ) + + def frequency_at_index(self, index): + """ + Returns the frequency at a specific index. + """ + freq = self.frequencies + max_freq = len(freq) + if index < 0 or index >= max_freq: + raise IndexError(f"Index {index} out of range for frequency axis with size {max_freq}.") + return freq[index]