CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-astropy

Astronomy and astrophysics core library providing comprehensive tools for astronomical computations and data handling

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

convolution.mddocs/

Image Convolution

Convolution and filtering operations for astronomical images with kernels optimized for astronomical data analysis.

Core Imports

from astropy.convolution import convolve, convolve_fft
from astropy.convolution import Kernel, Gaussian2DKernel, Box2DKernel

Capabilities

Convolution Functions

Core convolution functions for filtering astronomical images with custom kernels, supporting different boundary conditions and optimized algorithms.

def convolve(array, kernel, boundary='fill', fill_value=0.0, nan_treatment='interpolate', preserve_nan=False, mask=None, normalize_kernel=True):
    """
    Convolve an array with a kernel.
    
    Parameters:
    - array: input array to convolve
    - kernel: convolution kernel (Kernel instance or array)
    - boundary: boundary condition ('fill', 'wrap', 'extend')
    - fill_value: value to use for 'fill' boundary condition
    - nan_treatment: how to handle NaN values ('interpolate', 'fill')
    - preserve_nan: whether to preserve NaN values in output
    - mask: mask array for input data
    - normalize_kernel: whether to normalize kernel
    
    Returns:
    array: convolved array
    """

def convolve_fft(array, kernel, boundary='fill', fill_value=0.0, nan_treatment='interpolate', preserve_nan=False, mask=None, normalize_kernel=True):
    """
    Convolve an array with a kernel using FFT.
    
    Same parameters as convolve() but uses FFT for potentially faster computation
    on large arrays.
    """

def interpolate_replace_nans(array, kernel, boundary='fill', fill_value=0.0):
    """
    Replace NaN values in array using convolution-based interpolation.
    
    Parameters:
    - array: input array containing NaN values
    - kernel: convolution kernel for interpolation
    - boundary: boundary condition
    - fill_value: fill value for boundary
    
    Returns:
    array: array with NaN values replaced
    """

Kernel Base Classes

Base classes for creating convolution kernels with proper normalization and array handling.

class Kernel:
    """
    Base class for convolution kernels.
    
    Parameters:
    - array: kernel array data
    """
    def __init__(self, array): ...
    
    def normalize(self, mode='integral'):
        """Normalize the kernel."""
    
    @property
    def array(self):
        """The kernel array."""
    
    @property
    def separable(self):
        """Whether the kernel is separable."""

class Kernel1D(Kernel):
    """Base class for 1D kernels."""

class Kernel2D(Kernel):
    """Base class for 2D kernels."""

Built-in Kernels

Pre-defined kernels commonly used in astronomical image processing.

class Gaussian1DKernel(Kernel1D):
    """
    1D Gaussian filter kernel.
    
    Parameters:
    - stddev: standard deviation of the Gaussian
    - x_size: size of the kernel (optional)
    - mode: discretization mode ('center', 'linear_interp', 'oversample', 'integrate')
    - factor: oversampling factor for 'oversample' mode
    """
    def __init__(self, stddev, x_size=None, mode='center', factor=10): ...

class Gaussian2DKernel(Kernel2D):
    """
    2D Gaussian filter kernel.
    
    Parameters:
    - stddev: standard deviation (scalar or 2-element array)
    - x_size: x-size of the kernel (optional)
    - y_size: y-size of the kernel (optional) 
    - theta: rotation angle in radians
    - mode: discretization mode
    - factor: oversampling factor
    """
    def __init__(self, stddev, x_size=None, y_size=None, theta=0.0, mode='center', factor=10): ...

class Box1DKernel(Kernel1D):
    """
    1D Box filter kernel.
    
    Parameters:
    - width: width of the box
    """
    def __init__(self, width): ...

class Box2DKernel(Kernel2D):
    """
    2D Box filter kernel.
    
    Parameters:
    - width: width of the box (scalar or 2-element array)
    """
    def __init__(self, width): ...

class Tophat2DKernel(Kernel2D):
    """
    2D circular tophat filter kernel.
    
    Parameters:
    - radius: radius of the tophat
    """
    def __init__(self, radius): ...

class AiryDisk2DKernel(Kernel2D):
    """
    2D Airy disk kernel.
    
    Parameters:
    - radius: radius of the first zero of the Airy function
    """
    def __init__(self, radius): ...

class Moffat2DKernel(Kernel2D):
    """
    2D Moffat kernel.
    
    Parameters:
    - gamma: core width of the Moffat function
    - alpha: power index of the Moffat function
    """
    def __init__(self, gamma, alpha): ...

class TrapezoidDisk2DKernel(Kernel2D):
    """
    2D trapezoidal disk kernel.
    
    Parameters:
    - radius: outer radius of the trapezoid
    - slope: slope of the trapezoid sides
    """
    def __init__(self, radius, slope): ...

class Ring2DKernel(Kernel2D):
    """
    2D ring kernel.
    
    Parameters:
    - radius_in: inner radius of the ring
    - width: width of the ring
    """
    def __init__(self, radius_in, width): ...

Custom Kernels

Tools for creating custom convolution kernels from arrays or astropy models.

class CustomKernel(Kernel):
    """
    Custom kernel from user-provided array.
    
    Parameters:
    - array: kernel array data
    """
    def __init__(self, array): ...

class Model1DKernel(Kernel1D):
    """
    Create 1D kernel from astropy model.
    
    Parameters:
    - model: astropy 1D model instance
    - x_size: size of the kernel
    - mode: discretization mode
    """
    def __init__(self, model, x_size, mode='center'): ...

class Model2DKernel(Kernel2D):
    """
    Create 2D kernel from astropy model.
    
    Parameters:
    - model: astropy 2D model instance
    - x_size: x-size of the kernel
    - y_size: y-size of the kernel
    - mode: discretization mode
    """
    def __init__(self, model, x_size, y_size=None, mode='center'): ...

Usage Examples

Basic Convolution

import numpy as np
from astropy.convolution import convolve, Gaussian2DKernel

# Create sample data
data = np.random.random((100, 100))

# Create Gaussian kernel
kernel = Gaussian2DKernel(stddev=2.0)

# Convolve data
smoothed = convolve(data, kernel)

Custom Kernel Creation

from astropy.convolution import CustomKernel, convolve

# Create custom kernel array
kernel_array = np.array([[0, 1, 0],
                        [1, 4, 1], 
                        [0, 1, 0]]) / 8.0

# Create custom kernel
custom_kernel = CustomKernel(kernel_array)

# Apply convolution
result = convolve(data, custom_kernel)

Handling NaN Values

from astropy.convolution import interpolate_replace_nans, Gaussian2DKernel

# Data with NaN values
data_with_nans = np.random.random((50, 50))
data_with_nans[20:30, 20:30] = np.nan

# Replace NaN values using interpolation
kernel = Gaussian2DKernel(stddev=1.0)
cleaned_data = interpolate_replace_nans(data_with_nans, kernel)

Types

# Kernel types
Kernel = astropy.convolution.Kernel
Kernel1D = astropy.convolution.Kernel1D
Kernel2D = astropy.convolution.Kernel2D

# Built-in kernel types
Gaussian1DKernel = astropy.convolution.Gaussian1DKernel
Gaussian2DKernel = astropy.convolution.Gaussian2DKernel
Box1DKernel = astropy.convolution.Box1DKernel
Box2DKernel = astropy.convolution.Box2DKernel
Tophat2DKernel = astropy.convolution.Tophat2DKernel
AiryDisk2DKernel = astropy.convolution.AiryDisk2DKernel
Moffat2DKernel = astropy.convolution.Moffat2DKernel

Install with Tessl CLI

npx tessl i tessl/pypi-astropy

docs

configuration.md

constants.md

convolution.md

coordinates.md

cosmology.md

fits-io.md

index.md

modeling.md

nddata.md

samp.md

statistics.md

tables.md

time.md

timeseries.md

uncertainty.md

units-quantities.md

utils.md

visualization.md

wcs.md

tile.json