Skip to content

Commit

Permalink
Force correct format of excluded frequency intervals
Browse files Browse the repository at this point in the history
  • Loading branch information
matteobachetti committed Nov 30, 2023
1 parent dccf33f commit 228ae50
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 7 additions & 2 deletions stingray/fourier.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,14 @@ def power_color(
power_err = np.asarray(power_err)

if frequencies_to_exclude is not None:
if len(np.shape(frequencies_to_exclude)):
if len(np.shape(frequencies_to_exclude)) == 1:
frequencies_to_exclude = [frequencies_to_exclude]
if np.shape(frequencies_to_exclude)[1] != 2:

if (
not isinstance(frequencies_to_exclude, Iterable)
or len(np.shape(frequencies_to_exclude)) != 2
or np.shape(frequencies_to_exclude)[1] != 2
):
raise ValueError("frequencies_to_exclude must be of format [[f0, f1], [f2, f3], ...]")
for f0, f1 in frequencies_to_exclude:
frequency_mask = (input_frequency_low_edges > f0) & (input_frequency_high_edges < f1)
Expand Down
5 changes: 5 additions & 0 deletions stingray/tests/test_fourier.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,11 @@ def test_bad_edges(self):
with pytest.raises(ValueError, match="The maximum frequency is lower "):
power_color(self.freq[good], self.power[good])

def test_bad_excluded_interval(self):
for fte in ([1, 1.1, 3.0], [4], [[1, 1.1, 3.0]], 0, [[[1, 3]]]):
with pytest.raises(ValueError, match="frequencies_to_exclude must be of "):
power_color(self.freq, self.power, frequencies_to_exclude=fte)

def test_excluded_frequencies(self):
pc0, _, pc1, _ = power_color(self.freq, self.power, frequencies_to_exclude=[1, 1.1])
# The colors calculated with these frequency edges on a 1/f spectrum should be 1
Expand Down

0 comments on commit 228ae50

Please sign in to comment.