Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
dict = {'badid': "identifier '%s' is a reserved word",
'getitem': '%s %s %s',
'nodatasets': "No data sets found",
'nomodels': "model stack is empty",
'badidmodel': "'%s' is a model type, not allowed as a model name",
'badidnative': "'%s' is reserved for the native Python function",
'nomodelcmpt': "model component '%s' does not exist",
}
def __init__(self, key, *args):
SherpaErr.__init__(self, IdentifierErr.dict, key, *args)
class TypeErr(SherpaErr):
dict = {'nocomplex': "ds9 cannot handle complex data",
}
def __init__(self, key, *args):
SherpaErr.__init__(self, TypeErr.dict, key, *args)
class RuntimeErr(SherpaErr):
dict = {'notonpath': "Could not find %s on your PATH",
'nowin': 'Could not open ds9 window %r; timeout',
'cmdfail': "%r failed: %s",
'only2d3d': "ds9 can only display 2d and 3d arrays",
'badarr': "Array info not allowed; rejected keywords: %s",
'badwin': "DS9Win unusable: %s",
class ConfidenceErr(SherpaErr):
dict = {'badarg': "%s must be %s",
'badlimits': 'Bad parameter limits',
'needlist': 'Please provide a list of %s',
'frozen': 'Frozen parameter %s cannot be used for %s',
'thawed': 'Thawed parameter %s not found in %s',
'badargconf': '%s is inappropriate for confidence limit estimation',
}
def __init__(self, key, *args):
SherpaErr.__init__(self, ConfidenceErr.dict, key, *args)
class SessionErr(SherpaErr):
dict = {'nofit': 'no %s has been performed',
'noaction': "%s has not been performed",
}
def __init__(self, key, *args):
SherpaErr.__init__(self, SessionErr.dict, key, *args)
#
# Make the dictionary of the error a class attribute or self.dict?
#
dict = {'statnotforbackgsub': '%s statistics cannot be used with background subtracted data',
'binhas0': 'zeros found in uncertainties, consider using calculated uncertainties',
'nobins': 'no noticed bins found in data set',
'noclobererr': "'%s' exists, and clobber==False",
'nothawedpar': 'model has no thawed parameters',
'needchi2': '%s method requires a deviates array; use a chi-square statistic', }
def __init__(self, key, *args):
SherpaErr.__init__(self, FitErr.dict, key, *args)
class ParameterErr(SherpaErr):
"Error in creating or using a model"
dict = {'edge': "parameter %s has a %s of %g",
'noncall': 'attempted to create %s from non-callable object of type %s',
'alwaysint': '%s model is defined as integrated',
'filterarray': "filter '%s' is not an array",
'filtermismatch': "filter '%s' does not match the dimensions %s",
'alwaysfrozen': 'parameter %s is always frozen and cannot be thawed',
'frozennolink': 'parameter %s is always frozen and cannot be linked',
'notlink': 'link value must be a parameter or None',
'linkcycle': 'requested parameter link creates a cyclic reference',
'frozen': "parameter '%s' is frozen",
}
def __init__(self, key, *args):
SherpaErr.__init__(self, ParameterErr.dict, key, *args)
'noncall': 'attempted to create %s from non-callable object of type %s',
'alwaysint': '%s model is defined as integrated',
'filterarray': "filter '%s' is not an array",
'filtermismatch': "filter '%s' does not match the dimensions %s",
'alwaysfrozen': 'parameter %s is always frozen and cannot be thawed',
'frozennolink': 'parameter %s is always frozen and cannot be linked',
'notlink': 'link value must be a parameter or None',
'linkcycle': 'requested parameter link creates a cyclic reference',
'frozen': "parameter '%s' is frozen",
}
def __init__(self, key, *args):
SherpaErr.__init__(self, ParameterErr.dict, key, *args)
class DataErr(SherpaErr):
"Error in creating or using a data set"
dict = {'ismask': "'mask' must be True, False, or a mask array",
'notmask': 'mask excludes all data',
'nomask': "data set '%s' has no filter",
'mismatch': 'size mismatch between %s and %s',
'typecheck': 'strings not allowed in %s list',
'wrongdim': "data set '%s' does not contain %d-D data",
'notimage': "data set '%s' does not contain image data",
'nodim': "data set '%s' does not have any defined dimensions",
'zerodatasimulfit':
"cannot create a %s instance containing no data sets",
'staterrsimulfit':
'unable to obtain or estimate statistical errors for all data sets',
'shape': "data set '%s' does not specify a shape",
'nogrouping': "data set '%s' does not specify grouping flags",
class RuntimeErr(SherpaErr):
dict = {'notonpath': "Could not find %s on your PATH",
'nowin': 'Could not open ds9 window %r; timeout',
'cmdfail': "%r failed: %s",
'only2d3d': "ds9 can only display 2d and 3d arrays",
'badarr': "Array info not allowed; rejected keywords: %s",
'badwin': "DS9Win unusable: %s",
}
def __init__(self, key, *args):
SherpaErr.__init__(self, RuntimeErr.dict, key, *args)
class NotImplementedErr(SherpaErr):
dict = {'noinstanceallowed': "cannot create %s instances",
'contourgrids': 'contours on non-uniform grids are not yet supported'
}
def __init__(self, key, *args):
SherpaErr.__init__(self, NotImplementedErr.dict, key, *args)
class ImportErr(SherpaErr):
dict = {'importfailed': "failed to import %s module; %s routines are not available",
'notsupported': '%s support is not enabled in this build of Sherpa'
}
def __init__(self, key, *args):
type(self.stat) is not LeastSq):
pass
else:
raise FitErr('needchi2', 'Sigma-rejection')
# Get maximum number of allowed iterations, high and low
# sigma thresholds for jrection of data points, and
# "grow" factor (i.e., how many surrounding data points
# to include with rejected data point).
maxiters = self.itermethod_opts['maxiters']
if (type(maxiters) != int):
raise SherpaErr(
"'maxiters' value for sigma rejection method must be an integer")
if (maxiters < 1):
raise SherpaErr("'maxiters' must be one or greater")
hrej = self.itermethod_opts['hrej']
if (type(hrej) != int and
type(hrej) != float):
raise SherpaErr(
"'hrej' value for sigma rejection method must be a number")
if (not (hrej > 0)):
raise SherpaErr("'hrej' must be greater than zero")
lrej = self.itermethod_opts['lrej']
# FIXME: [OL] There are more reliable ways of checking if an object
# is (not) a number.
if (type(lrej) != int and type(lrej) != float):
raise SherpaErr(
"'lrej' value for sigma rejection method must be a number")
if lrej <= 0:
def __init__(self, key, *args):
SherpaErr.__init__(self, RuntimeErr.dict, key, *args)
class NotImplementedErr(SherpaErr):
dict = {'noinstanceallowed': "cannot create %s instances",
'contourgrids': 'contours on non-uniform grids are not yet supported'
}
def __init__(self, key, *args):
SherpaErr.__init__(self, NotImplementedErr.dict, key, *args)
class ImportErr(SherpaErr):
dict = {'importfailed': "failed to import %s module; %s routines are not available",
'notsupported': '%s support is not enabled in this build of Sherpa'
}
def __init__(self, key, *args):
SherpaErr.__init__(self, ImportErr.dict, key, *args)
class EstErr(SherpaErr):
dict = {'noerr4least2': 'cannot estimate confidence limits with %s',
'nodegfreedom': 'degrees of freedom are zero or lower',
'rstat>max': 'reduced statistic larger than %s',
'nocov': 'Covariance matrix could not be resolved',
'noparameter': '%s is not in a model associated with selected data sets',
# to include with rejected data point).
maxiters = self.itermethod_opts['maxiters']
if (type(maxiters) != int):
raise SherpaErr(
"'maxiters' value for sigma rejection method must be an integer")
if (maxiters < 1):
raise SherpaErr("'maxiters' must be one or greater")
hrej = self.itermethod_opts['hrej']
if (type(hrej) != int and
type(hrej) != float):
raise SherpaErr(
"'hrej' value for sigma rejection method must be a number")
if (not (hrej > 0)):
raise SherpaErr("'hrej' must be greater than zero")
lrej = self.itermethod_opts['lrej']
# FIXME: [OL] There are more reliable ways of checking if an object
# is (not) a number.
if (type(lrej) != int and type(lrej) != float):
raise SherpaErr(
"'lrej' value for sigma rejection method must be a number")
if lrej <= 0:
raise SherpaErr("'lrej' must be greater than zero")
grow = self.itermethod_opts['grow']
if (type(grow) != int):
raise SherpaErr(
"'grow' value for sigma rejection method must be an integer")
if (grow < 0):
raise SherpaErr("'grow' factor must be zero or greater")
lrej = self.itermethod_opts['lrej']
# FIXME: [OL] There are more reliable ways of checking if an object
# is (not) a number.
if (type(lrej) != int and type(lrej) != float):
raise SherpaErr(
"'lrej' value for sigma rejection method must be a number")
if lrej <= 0:
raise SherpaErr("'lrej' must be greater than zero")
grow = self.itermethod_opts['grow']
if (type(grow) != int):
raise SherpaErr(
"'grow' value for sigma rejection method must be an integer")
if (grow < 0):
raise SherpaErr("'grow' factor must be zero or greater")
# Keep record of current and previous statistics
previous_stat = float32(finfo(float32).max)
current_stat = statfunc(pars)[0]
nfev = 0
iters = 0
# Store original masks (filters) for each data set.
mask_original = []
for d in self.data.datasets:
# If there's no filter, create a filter that is
# all True
if (iterable(d.mask) != True):
mask_original.append(d.mask)
d.mask = ones_like(array(d.get_dep(False), dtype=bool))
# Get maximum number of allowed iterations, high and low
# sigma thresholds for jrection of data points, and
# "grow" factor (i.e., how many surrounding data points
# to include with rejected data point).
maxiters = self.itermethod_opts['maxiters']
if (type(maxiters) != int):
raise SherpaErr(
"'maxiters' value for sigma rejection method must be an integer")
if (maxiters < 1):
raise SherpaErr("'maxiters' must be one or greater")
hrej = self.itermethod_opts['hrej']
if (type(hrej) != int and
type(hrej) != float):
raise SherpaErr(
"'hrej' value for sigma rejection method must be a number")
if (not (hrej > 0)):
raise SherpaErr("'hrej' must be greater than zero")
lrej = self.itermethod_opts['lrej']
# FIXME: [OL] There are more reliable ways of checking if an object
# is (not) a number.
if (type(lrej) != int and type(lrej) != float):
raise SherpaErr(
"'lrej' value for sigma rejection method must be a number")
if lrej <= 0:
raise SherpaErr("'lrej' must be greater than zero")
grow = self.itermethod_opts['grow']
if (type(grow) != int):
raise SherpaErr(