Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def set_analysis(self, quantity, type='rate', factor=0):
self.plot_fac = factor
type = str(type).strip().lower()
if not (type.startswith('counts') or type.startswith('rate')):
raise DataErr("plottype", type, "'rate' or 'counts'")
self.rate = (type == 'rate')
arf, rmf = self.get_response()
if rmf is not None and rmf.detchans != len(self.channel):
raise DataErr("incompatibleresp", rmf.name, self.name)
if (rmf is None and arf is None) and \
(self.bin_lo is None and self.bin_hi is None) and \
quantity != 'channel':
raise DataErr('noinstr', self.name)
if rmf is None and arf is not None and quantity != 'channel' and \
len(arf.energ_lo) != len(self.channel):
raise DataErr("incompleteresp", self.name)
def _check_shape(self):
if self.shape is None:
raise DataErr('shape', self.name)
def _check_physical_transform(self):
if self.sky is None:
raise DataErr('nocoord', self.name, 'physical')
Array to be filtered
Returns
-------
array_like : filtered array
"""
if array is None:
return
if self.mask is False:
raise DataErr('notmask')
if self.mask is not True: # mask is not False and not True, so it's something else we'll try to use as an array
array = numpy.asarray(array)
if array.shape != self.mask.shape:
raise DataErr('mismatch', 'mask', 'data array')
return array[self.mask]
return array
def _check_shape(self):
if self.shape is None:
raise DataErr('shape', self.name)
def __call__(self, model, session=None):
pha = self.pha
# clear out any previous response filter
pha.notice_response(False)
if isinstance(model, string_types):
if session is None:
model = sherpa.astro.ui._session._eval_model_expression(model)
else:
model = session._eval_model_expression(model)
arf, rmf = pha.get_response()
err_msg = None
if arf is None and rmf is None:
raise DataErr('norsp', pha.name)
if arf is None:
err_msg = 'does not have an associated ARF'
elif pha.exposure is None:
err_msg = 'does not specify an exposure time'
if err_msg:
raise InstrumentErr('baddata', pha.name, err_msg)
# Currently, the response is NOT noticed using pileup
# ARF convolution done inside ISIS pileup module
# on finite grid scale
model = model.apply(self.pileup_model, pha.exposure, arf.energ_lo,
arf.energ_hi, arf.specresp, model)
def get_x(self, filter=False, response_id=None):
# If we are already in channel space, self._from_channel
# is always ungrouped. In any other space, we must
# disable grouping when calling self._from_channel.
if self.units != 'channel':
elo, ehi = self._get_ebins(group=False)
if len(elo) != len(self.channel):
raise DataErr("incompleteresp", self.name)
return self._from_channel(self.channel, group=False,
response_id=response_id)
else:
return self._from_channel(self.channel)
def set_coord(self, coord):
coord = str(coord).strip().lower()
# Destroys original data to conserve memory for big imgs
good = ('logical', 'image', 'physical', 'world', 'wcs')
if coord not in good:
raise DataErr('badchoices', 'coordinates', coord, ", ".join(good))
if coord.startswith('wcs'):
coord = 'world'
elif coord.startswith('image'):
coord = 'logical'
self.x0, self.x1 = getattr(self, 'get_' + coord)()
self._x0 = self.apply_filter(self.x0)
self._x1 = self.apply_filter(self.x1)
self._set_coord(coord)
if nincreasing > 0 and nincreasing != len(increasing):
# raise DataErr('ogip-error', rtype, label,
# 'has a non-monotonic ENERG_LO array')
wmsg = "The {} '{}' ".format(rtype, label) + \
'has a non-monotonic ENERG_LO array'
warnings.warn(wmsg)
if nincreasing == 0:
startidx = -1
else:
startidx = 0
e0 = elo[startidx]
if ethresh is None:
if e0 <= 0.0:
raise DataErr('ogip-error', rtype, label,
'has an ENERG_LO value <= 0')
else:
# TODO: should this equality be replaced by an approximation test?
if e0 == 0.0:
if ehi[startidx] <= ethresh:
raise DataErr('ogip-error', rtype, label,
'has an ENERG_HI value <= the replacement ' +
'value of {}'.format(ethresh))
elo = elo.copy()
elo[startidx] = ethresh
wmsg = "The minimum ENERG_LO in the " + \
"{} '{}' was 0 and has been ".format(rtype, label) + \
"replaced by {}".format(ethresh)
warnings.warn(wmsg)
if hasattr(data, 'get_response'):
arf, rmf = data.get_response()
elo = data.bin_lo
ehi = data.bin_hi
if arf is not None:
elo = arf.energ_lo
ehi = arf.energ_hi
elif rmf is not None:
elo = rmf.energ_lo
ehi = rmf.energ_hi
else:
elo, ehi = data.get_indep()
if elo is None or ehi is None:
raise DataErr('noenergybins', data.name)
emin = elo[0]
emax = ehi[-1]
if restlo < emin or resthi > emax:
raise IOErr('energoverlap', emin, emax, 'rest-frame',
restlo, resthi, '')
if obslo * (1.0 + z.min()) < emin:
raise IOErr('energoverlap', emin, emax, 'observed-frame',
restlo, resthi, "at a redshift of %f" % z.min())
if obshi * (1.0 + z.max()) > emax:
raise IOErr('energoverlap', emin, emax, 'rest-frame',
restlo, resthi, "at a redshift of %f" % z.min())