Skip to main content
`Ctrl`+`K`

# discretize_model

astropy.convolution.discretize_model(model, x_range, y_range=None, mode='center', factor=10)

  Evaluate an analytical model function on a pixel grid.

  Parameters:
    model `Model` or callable.

      Analytical model function to be discretized. A callable that is not a `Model` instance is converted to a model using `custom_model`.

    x_range 2-tuple

      Lower and upper bounds of x pixel values at which the model is evaluated. The upper bound is non-inclusive. A `x_range` of `(0, 3)` means the model will be evaluated at x pixels 0, 1, and 2. The difference between the upper and lower bound must be a whole number so that the output array size is well-defined.

    y_range 2-tuple or `None`, optional

      Lower and upper bounds of y pixel values at which the model is evaluated. The upper bound is non-inclusive. A `y_range` of `(0, 3)` means the model will be evaluated at y pixels of 0, 1, and 2. The difference between the upper and lower bound must be a whole number so that the output array size is well-defined. `y_range` is necessary only for 2D models.

    mode{‘center’, ‘linear_interp’, ‘oversample’, ‘integrate’}, optional
      One of the following modes:
        - `'center'` (default)

            Discretize model by taking the value at the center of the pixel bins.

        - `'linear_interp'`

            Discretize model by linearly interpolating between the values at the edges (1D) or corners (2D) of the pixel bins. For 2D models, the interpolation is bilinear.

        - `'oversample'`

            Discretize model by taking the average of model values in the pixel bins on an oversampled grid. Use the `factor` keyword to set the integer oversampling factor.

        - `'integrate'`

            Discretize model by integrating the model over the pixel bins using `scipy.integrate.quad`. This mode conserves the model integral on a subpixel scale, but is very slow.

    factor `python:int`, optional

      The integer oversampling factor used when `mode='oversample'`. Ignored otherwise.

  Returns:
    array `numpy.ndarray`

      The discretized model array.

  Examples

  In this example, we define a `Gaussian1D` model that has been normalized so that it sums to 1.0. We then discretize this model using the `'center'`, `'linear_interp'`, and `'oversample'` (with `factor=10`) modes.

  (`Source code`, `png`, `svg`, `pdf`)