Skip to content

Commit

Permalink
Fix bug in spw_range functions
Browse files Browse the repository at this point in the history
  • Loading branch information
philbull committed Apr 30, 2018
1 parent ff5527e commit e687d15
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 0 additions & 3 deletions hera_pspec/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,6 @@ def test_spw_range_from_redshifts(self):
nt.ok_( isinstance(spw2, list) )
nt.ok_( len(spw2) == len(z_list) )

# Make sure that bounds_error=False works
nt.ok_( spw3 == spw4 )

# Make sure that this also works for UVPSpec objects
spw5 = utils.spw_range_from_redshifts(self.uvp, z_range=(13.1, 13.2))
nt.ok_( isinstance(spw5, tuple) )
Expand Down
7 changes: 6 additions & 1 deletion hera_pspec/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ def spw_range_from_freqs(data, freq_range, bounds_error=True):
# Get frequency array from input object
try:
freqs = data.freq_array
if len(freqs.shape) == 2 and freqs.shape[0] == 1:
freqs = freqs.flatten() # Support UVData 2D freq_array
elif len(freqs.shape) > 2:
raise ValueError("data.freq_array has unsupported shape: %s" \
% str(freqs.shape))
except:
raise AttributeError("Object 'data' does not have a freq_array attribute.")

Expand Down Expand Up @@ -138,7 +143,7 @@ def spw_range_from_freqs(data, freq_range, bounds_error=True):

# Get indices within this range
idxs = np.where(np.logical_and(freqs >= fmin, freqs < fmax))[0]
spw = (idxs[0], idxs[1]) if idxs.size > 0 else (None, None)
spw = (idxs[0], idxs[-1]) if idxs.size > 0 else (None, None)
spw_range.append(spw)

# Unpack from list if only a single tuple was specified originally
Expand Down

0 comments on commit e687d15

Please sign in to comment.