Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
hfmt = '\n %-12s %12s %29s %12s'
lowstr = '%29s '
lownum = '%29g '
highstr = '%13s'
highnum = '%13g'
elif not in_low and in_high and mymethod:
hfmt = '\n %-12s %12s %12s %29s'
highstr = '%29s'
highnum = '%29g'
else:
hfmt = '\n %-12s %12s %12s %12s'
return myformat(hfmt, s, lowstr, lownum, highstr, highnum)
class IterFit(NoNewAttributesAfterInit):
def __init__(self, data, model, stat, method, itermethod_opts=None):
if itermethod_opts is None:
itermethod_opts = {'name': 'none'}
# Even if there is only a single data set, I will
# want to treat the data and models I am given as
# collections of data and models -- so, put data and
# models into the objects needed for simultaneous fitting,
# if they are not already in such objects.
self.data = data
if (type(data) is not DataSimulFit):
self.data = DataSimulFit('simulfit data', (data,))
self.model = model
if (type(model) is not SimulFitModel):
self.model = SimulFitModel('simulfit model', (model,))
self.stat = stat
model = session._eval_model_expression(model)
# Automatically add exposure time to source model
if pha is not None and pha.exposure is not None:
model = pha.exposure * model
elif arf.exposure is not None:
model = arf.exposure * model
# FIXME: display a warning if exposure is None?
if pha is not None:
return ARFModelPHA(arf, pha, model)
return ARFModelNoPHA(arf, model)
class RMF1D(NoNewAttributesAfterInit):
def __init__(self, rmf, pha=None, arf=None):
self._rmf = rmf
self._arf = arf
self._pha = pha
NoNewAttributesAfterInit.__init__(self)
def __getattr__(self, name):
rmf = None
try:
rmf = RMF1D.__getattribute__(self, '_rmf')
except:
pass
if name in ('_rmf', '_pha'):
return self.__dict__[name]
reporting an error.
"""
# be explicit here
opts = {}
for k, v in prefs.items():
opts[k] = v
for k, v in user.items():
opts[k] = v
return opts
class Plot(NoNewAttributesAfterInit):
"Base class for line plots"
plot_prefs = backend.get_plot_defaults()
def __init__(self):
"""
Initialize a Plot object. All 1D line plot
instances utilize Plot, which provides a generic
interface to a backend.
Once an instance of Plot is initialized no new
attributes of the class can be made. (To eliminate
the accidental creation of erroneous attributes)
"""
self.plot_prefs = self.plot_prefs.copy()
NoNewAttributesAfterInit.__init__(self)
"""Return the plot preferences merged with user settings."""
return merge_settings(self.contour_prefs, kwargs)
def contour(self, x0, x1, y, levels=None, title=None, xlabel=None,
ylabel=None, overcontour=False, clearwindow=True,
**kwargs):
opts = self._merge_settings(kwargs)
backend.contour(x0, x1, y, levels, title, xlabel, ylabel, overcontour,
clearwindow, **opts)
def overcontour(self, *args, **kwargs):
kwargs['overcontour'] = True
self.contour(*args, **kwargs)
class Point(NoNewAttributesAfterInit):
"Base class for point plots"
point_prefs = backend.get_point_defaults()
def __init__(self):
"""
Initialize a Point object. All 1D point plot
instances utilize Point, which provides a generic
interface to a backend.
Once an instance of Point is initialized no new
attributes of the class can be made. (To eliminate
the accidental creation of erroneous attributes)
"""
self.point_prefs = self.point_prefs.copy()
NoNewAttributesAfterInit.__init__(self)
def __init__(self, name):
self.name = name
NoNewAttributesAfterInit.__init__(self)
raise EstErr('nocov')
cov = numpy.asarray(cov)
# Investigate spectral decomposition to avoid requirement that the cov be
# semi-positive definite. Nevermind, NumPy already uses SVD to generate
# deviates from a multivariate normal. An alternative is to use Cholesky
# decomposition, but it assumes that the matrix is semi-positive
# definite.
if numpy.min(numpy.linalg.eigvalsh(cov)) <= 0:
raise TypeError("The covariance matrix is not positive definite")
return cov
class ParameterSampleFromScaleVector(NoNewAttributesAfterInit):
def __init__(self):
self.scale = ParameterScaleVector()
NoNewAttributesAfterInit.__init__(self)
def get_sample(self):
raise NotImplementedError
class ParameterSampleFromScaleMatrix(NoNewAttributesAfterInit):
def __init__(self):
self.scale = ParameterScaleMatrix()
NoNewAttributesAfterInit.__init__(self)
def get_sample(self):
def stat_calc_wrapper(valid_args, stat, dep, model, staterror, syserror,
bkg_data):
if is_in('bkg', valid_args):
if isinstance(stat, UserStat):
result = stat.calc_stat(dep, model, staterror, syserror=syserror,
bkg=bkg_data['bkg'])
else:
result = stat.calc_stat(dep, model, staterror, syserror=syserror,
bkg=bkg_data)
else:
result = stat.calc_stat(dep, model, staterror, syserror=syserror)
return result
class StatInfoResults(NoNewAttributesAfterInit):
"""A summary of the current statistic value for
one or more data sets.
Attributes
----------
name : str
The name of the data set, or sets.
ids : sequence of int or str
The data set ids (it may be a tuple or array) included in the
results.
bkg_ids: sequence of int or str, or `None`
The background data set ids (it may be a tuple or array)
included in the results, if any.
statname : str
The name of the statistic function.
# remove first item in queue and remove from cache
key = queue.pop(0)
cache.pop(key, None)
# append newest model values to queue
queue.append(digest)
cache[digest] = vals.copy()
return vals
cache_model.__name__ = func.__name__
cache_model.__doc__ = func.__doc__
return cache_model
class Model(NoNewAttributesAfterInit):
"""The base class for Sherpa models.
A model contains zero or more parameters that control the
predictions of the model when given one or more coordinates.
These parameters may represent some variable that describes
the model, such as the temperature of a black body, or the
computation, such as what form of interpolation to use.
Parameters
----------
name : str
A label for the model instance.
pars : sequence of sherpa.parameter.Parameter objects
The parameters of the model.
Attributes
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
from sherpa.utils import NoNewAttributesAfterInit
__all__ = ('Meta',)
class Meta(NoNewAttributesAfterInit):
"""A key-value store."""
def __init__(self):
self.__header = {}
NoNewAttributesAfterInit.__init__(self)
def __getitem__(self, name):
return self.__header[name]
def __delitem__(self, name):
del self.__header[name]
def __setitem__(self, name, val):
self.__header[name] = val
def get(self, name, default=None):