Skip to content

Commit

Permalink
Add check for bad index
Browse files Browse the repository at this point in the history
  • Loading branch information
darafferty committed Mar 21, 2024
1 parent 76a9de2 commit 7f83963
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions bdsf/collapse.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def __call__(self, img):
chan0 = img.opts.collapse_ch0
c_list = img.opts.collapse_av
c_wts = img.opts.collapse_wt
if c_list == []: c_list = N.arange(img.shape[1])
if not c_list:
c_list = N.arange(img.shape[1])
if len(c_list) == 1 and c_mode=='average':
c_mode = 'single'
chan0 = c_list[0]
Expand All @@ -43,6 +44,12 @@ def __call__(self, img):
else:
ch0images = ['ch0_arr']

# Check whether the collapse channel index is sensible
if chan0 < 0 or chan0 >= len(c_list):
raise RuntimeError('The channel index (set with the "collapse_ch0" option) '
'must be greater than zero and less than the number of '
'channels ({}).'.format(len(c_list)))

# assume all Stokes images have the same blank pixels as I:
blank = N.isnan(img.image_arr[0])
hasblanks = blank.any()
Expand All @@ -64,9 +71,6 @@ def __call__(self, img):
# Construct weights so that desired channel has weight of 1 and all
# others have weight of 0. The init_freq_collapse function will then
# select the intended frequency
c_list = img.opts.collapse_av
if c_list == []:
c_list = N.arange(img.image_arr.shape[1])
wtarr = N.zeros(len(c_list))
wtarr[chan0] = 1.0
init_freq_collapse(img, wtarr)
Expand Down

0 comments on commit 7f83963

Please sign in to comment.