def convolve_models(model, kernel, mode='convolve_fft', **kwargs): """ Convolve two models using `~astropy.convolution.convolve_fft`. Parameters ---------- model : `~astropy.modeling.core.Model` Functional model kernel : `~astropy.modeling.core.Model` Convolution kernel mode : str Keyword representing which function to use for convolution. * 'convolve_fft' : use `~astropy.convolution.convolve_fft` function. * 'convolve' : use `~astropy.convolution.convolve`. **kwargs : dict Keyword arguments to me passed either to `~astropy.convolution.convolve` or `~astropy.convolution.convolve_fft` depending on ``mode``. Returns ------- default : `~astropy.modeling.core.CompoundModel` Convolved model """ if mode == 'convolve_fft': operator = SPECIAL_OPERATORS.add('convolve_fft', partial(convolve_fft, **kwargs)) elif mode == 'convolve': operator = SPECIAL_OPERATORS.add('convolve', partial(convolve, **kwargs)) else: raise ValueError(f'Mode {mode} is not supported.') return CompoundModel(operator, model, kernel)
def convolve_models_fft(model, kernel, bounding_box, resolution, cache=True, **kwargs): """ Convolve two models using `~astropy.convolution.convolve_fft`. Parameters ---------- model : `~astropy.modeling.core.Model` Functional model kernel : `~astropy.modeling.core.Model` Convolution kernel bounding_box : tuple The bounding box which encompasses enough of the support of both the ``model`` and ``kernel`` so that an accurate convolution can be computed. resolution : float The resolution that one wishes to approximate the convolution integral at. cache : optional, bool Default value True. Allow for the storage of the convolution computation for later reuse. **kwargs : dict Keyword arguments to be passed either to `~astropy.convolution.convolve` or `~astropy.convolution.convolve_fft` depending on ``mode``. Returns ------- default : `~astropy.modeling.core.CompoundModel` Convolved model """ operator = SPECIAL_OPERATORS.add('convolve_fft', partial(convolve_fft, **kwargs)) return Convolution(operator, model, kernel, bounding_box, resolution, cache)