Skip to content

Commit

Permalink
Merge pull request #59 from pllim/dq-indexerror
Browse files Browse the repository at this point in the history
Catch out of bound errors and issue warnings instead
  • Loading branch information
pllim committed Dec 1, 2015
2 parents 2f87fac + 28a53c1 commit b9efab1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
17 changes: 11 additions & 6 deletions stginga/plugins/BackgroundSub.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,19 @@ def redo(self):
self.boxwidth, self.boxheight)

# Extract background data
bg_masked = image.cutout_shape(bg_obj)
bg_data = bg_masked[~bg_masked.mask]
self.bgval = calc_stat(bg_data, sigma=self.sigma, niter=self.niter,
algorithm=self.algorithm)
try:
bg_masked = image.cutout_shape(bg_obj)
bg_data = bg_masked[~bg_masked.mask]
except Exception as e:
self.logger.warn('{0}: {1}'.format(e.__class__.__name__, str(e)))
self.bgval = self._dummy_value
else:
self.bgval = calc_stat(bg_data, sigma=self.sigma, niter=self.niter,
algorithm=self.algorithm)

self._debug_str += (', bgval={0}, salgo={1}, sigma={2}, '
'niter={3}'.format(
self.bgval, self.algorithm, self.sigma, self.niter))

self.bgval, self.algorithm, self.sigma, self.niter))
self.logger.debug(self._debug_str)
self.w.background_value.set_text(str(self.bgval))

Expand Down
20 changes: 13 additions & 7 deletions stginga/plugins/DQInspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,19 @@ def redo(self):
dqsrc.metadata[self._cache_key] = pixmask_by_flag

# Parse DQ into individual flag definitions
pixval = data[int(self.ycen), int(self.xcen)]
dqs = dqparser.interpret_dqval(pixval)
self.w.dq.set_text(str(pixval))
for row in dqs:
item = QtGui.QListWidgetItem(
'{0:<5d}\t{1}'.format(row[dqparser._dqcol], row[self.dqstr]))
self.pxdqlist.addItem(item)
ix = int(self.xcen)
iy = int(self.ycen)
if (0 <= iy < data.shape[0]) and (0 <= ix < data.shape[1]):
pixval = data[iy, ix]
dqs = dqparser.interpret_dqval(pixval)
self.w.dq.set_text(str(pixval))
for row in dqs:
item = QtGui.QListWidgetItem('{0:<5d}\t{1}'.format(
row[dqparser._dqcol], row[self.dqstr]))
self.pxdqlist.addItem(item)
else:
self.logger.warn('{0}[{1}, {2}] is out of range; data shape is '
'{3}'.format(dqname, iy, ix, data.shape))

# No need to do the rest if image has not changed
if pixmask_by_flag is self._curpxmask:
Expand Down

0 comments on commit b9efab1

Please sign in to comment.