ModelDomainRegridder1D
- class sherpa.models.regrid.ModelDomainRegridder1D(evaluation_space=None, name='regrid1d', **kwargs)[source] [edit on github]
Bases:
objectAllow 1D models to be evaluated on a different grid.
This class is not used directly in a model expression; instead it creates an instance that is used to evaluate the model.
- Parameters:
- evaluation_space
objectorNone,optional - name
str,optional The default name is ‘regrid1d’.
- interp
callable(),optional The interpolation function: it should accept three arrays: the output x values and the x, y values to interpolate, and return the interpolated y values. The default is to use
sherpa.utils.akima.akima.
- evaluation_space
- Attributes:
Methods
apply_to(model)Evaluate a model on a different grid.
calc(pars, modelfunc, *args, **kwargs)Evaluate and regrid a model
eval_integrated(pars, modelfunc, data_grid, ...)Rebin the model onto a grid with low and high bins.
eval_non_integrated(pars, modelfunc, ...)Interpolate the model.
Examples
The “internal” model (gaussian plus constant) will be evaluated on the grid 0 to 10 (spacing of 0.5), and then linearly-interpolated onto the desired grid (1 to 8, spacing of 0.7). In this example there is no benefit to this approach - it is easier just to evaluate
internal_mdlon the gridx- but it illustrates the approach.>>> from sherpa.models import Gauss1D, Const1D >>> internal_mdl = Gauss1D() + Const1D() >>> eval_space = EvaluationSpace1D(np.arange(0, 10, 0.5)) >>> rmdl = ModelDomainRegridder1D(eval_space) >>> mdl = rmdl.apply_to(internal_mdl) >>> x = np.arange(1, 8, 0.7) >>> y = mdl(x)
Attributes Summary
The grid of the associated evaluation space.
Interpolate the data from the internal to requested grid.
Methods Summary
apply_to(model)Evaluate a model on a different grid.
calc(pars, modelfunc, *args, **kwargs)Evaluate and regrid a model
eval_integrated(pars, modelfunc, data_grid, ...)Rebin the model onto a grid with low and high bins.
eval_non_integrated(pars, modelfunc, ...)Interpolate the model.
Attributes Documentation
- grid
The grid of the associated evaluation space.
- method
Interpolate the data from the internal to requested grid.
This is only used for point grids, as integrated grids use a simple rebinning scheme. The default is
sherpa.utils.akima.akima. The callable should accept(xout, xin, yin)arguments and interpolate the(xin, yin)data onto thexoutgrid, returning the interpolated data.
Methods Documentation
- apply_to(model)[source] [edit on github]
Evaluate a model on a different grid.
- calc(pars, modelfunc, *args, **kwargs)[source] [edit on github]
Evaluate and regrid a model
Evaluate the model on the internal grid and then convert it onto the desired grid either preserving flux (rebinning) or via interpolation.
- Parameters:
- parssequence
ofnumbers The parameter values of the model.
- modelfunc
The model to evaluate (the calc attribute of the model)
- args
The grid to interpolate the model onto. This must match the format of the grid attribute of the model - i.e. non-integrate (single array) or integrated (a pair of equal-sized arrays).
- kwargs
Keyword arguments for the model.
- parssequence
Notes
If the requested grid (i.e. that defined by args) does not overlap the stored grid (the grid attribute) then all values are set to 0. However, if the grids partially overlap then there will be extrapolation (depending on the method).
It is not clear yet whether the restriction on grid type (i.e. must match between the requested grid and the internal grid whether it is integrated or non-integrated) is too restrictive.
- eval_integrated(pars, modelfunc, data_grid, eval_grid, **kwargs)[source] [edit on github]
Rebin the model onto a grid with low and high bins.
- Parameters:
- pars
listofnumbers The parameters for the model.
- modelfunc
callable() The model to evaluate. It is called as
modelfunc(pars, lo, hi, **kwargs)- data_grid(sequence
ofnumbers, sequenceofnumbers) The grid on which to return the values, as low and high edges.
- eval_grid(sequence
ofnumbers, sequenceofnumbers) The grid on which to evaluate the model, as low and high edges.
- kwargs
Any arguments to be sent to modelfunc.
- pars
- Returns:
- model
ndarray The model values matching the data_grid bins.
- model
- eval_non_integrated(pars, modelfunc, data_grid, eval_grid, **kwargs)[source] [edit on github]
Interpolate the model.
- Parameters:
- pars
listofnumbers The parameters for the model.
- modelfunc
callable() The model to evaluate. It is called as
modelfunc(pars, x, **kwargs)- data_gridsequence
ofnumbers The grid on which to return the values.
- eval_gridsequence
ofnumbers The grid on which to evaluate the model.
- kwargs
Any arguments to be sent to modelfunc.
- pars
- Returns:
- model
ndarray The model values matching the data_grid bins.
- model