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

nddata.mddocs/

N-Dimensional Data

Framework for handling N-dimensional astronomical data with metadata, masks, and uncertainty propagation.

Core Imports

from astropy.nddata import NDData, CCDData
from astropy.nddata import StdDevUncertainty, VarianceUncertainty, InverseVariance
from astropy.nddata import block_reduce, block_replicate

Capabilities

Core NDData Classes

Base classes for representing N-dimensional data with associated metadata, uncertainty, and masking.

class NDData:
    """
    Base class for N-dimensional data with metadata.
    
    Parameters:
    - data: array-like data
    - uncertainty: uncertainty information
    - mask: boolean mask array
    - meta: metadata dictionary
    - unit: physical unit of the data
    - wcs: world coordinate system information
    """
    def __init__(self, data, uncertainty=None, mask=None, meta=None, unit=None, wcs=None): ...
    
    @property
    def data(self):
        """The stored data array."""
    
    @property
    def uncertainty(self):
        """Uncertainty information."""
    
    @property
    def mask(self):
        """Boolean mask array."""
    
    @property
    def meta(self):
        """Metadata dictionary."""
    
    @property
    def unit(self):
        """Physical unit of the data."""
    
    @property
    def wcs(self):
        """World coordinate system."""

class NDDataArray(NDData):
    """NDData with arithmetic operations support."""
    
    def __add__(self, other): ...
    def __sub__(self, other): ...
    def __mul__(self, other): ...
    def __truediv__(self, other): ...

CCD Data Handling

Specialized class for CCD/detector data with enhanced I/O and FITS integration.

class CCDData(NDData):
    """
    CCD data container with FITS I/O support.
    
    Parameters:
    - data: CCD data array
    - unit: physical unit (required for CCDData)
    - uncertainty: uncertainty information
    - mask: boolean mask
    - meta: metadata dictionary
    - header: FITS header
    - wcs: world coordinate system
    """
    def __init__(self, data, unit=None, uncertainty=None, mask=None, meta=None, header=None, wcs=None): ...
    
    @classmethod
    def read(cls, filename, hdu=0, unit=None, **kwargs):
        """
        Read CCDData from FITS file.
        
        Parameters:
        - filename: file path or file-like object
        - hdu: HDU number or name
        - unit: unit to assign to data
        - **kwargs: additional arguments for fits.open
        
        Returns:
        CCDData: loaded CCD data
        """
    
    def write(self, filename, hdu_mask='MASK', hdu_uncertainty='UNCERT', **kwargs):
        """
        Write CCDData to FITS file.
        
        Parameters:
        - filename: output filename
        - hdu_mask: HDU name for mask
        - hdu_uncertainty: HDU name for uncertainty
        - **kwargs: additional arguments for fits.writeto
        """
    
    @property
    def header(self):
        """FITS header information."""

Uncertainty Classes

Classes for representing and propagating uncertainties in astronomical data.

class NDUncertainty:
    """Base class for uncertainty information."""
    
    def __init__(self, array, unit=None): ...
    
    @property
    def array(self):
        """Uncertainty array."""
    
    @property
    def unit(self):
        """Unit of uncertainty."""

class StdDevUncertainty(NDUncertainty):
    """
    Standard deviation uncertainty.
    
    Parameters:
    - array: standard deviation values
    - unit: unit of uncertainty values
    """
    def __init__(self, array, unit=None): ...
    
    @property
    def uncertainty_type(self):
        """Return 'std' for standard deviation."""

class VarianceUncertainty(NDUncertainty):
    """
    Variance uncertainty.
    
    Parameters:
    - array: variance values  
    - unit: unit of variance values
    """
    def __init__(self, array, unit=None): ...
    
    @property
    def uncertainty_type(self):
        """Return 'var' for variance."""

class InverseVariance(NDUncertainty):
    """
    Inverse variance uncertainty (weights).
    
    Parameters:
    - array: inverse variance values
    - unit: unit of inverse variance
    """
    def __init__(self, array, unit=None): ...
    
    @property 
    def uncertainty_type(self):
        """Return 'ivar' for inverse variance."""

Data Processing Functions

Functions for manipulating and processing N-dimensional data arrays.

def block_reduce(data, block_size, func=np.sum, cval=0.0):
    """
    Downsample data by applying a function to blocks.
    
    Parameters:
    - data: input data array
    - block_size: size of blocks for reduction
    - func: function to apply to each block
    - cval: value for padding if needed
    
    Returns:
    array: reduced data array
    """

def block_replicate(data, block_size, conserve_sum=True):
    """
    Upsample data by replicating blocks.
    
    Parameters:
    - data: input data array
    - block_size: replication factor
    - conserve_sum: whether to conserve total sum
    
    Returns:
    array: upsampled data array
    """

def overlap_slices(large_array_shape, small_array_shape, position, mode='partial'):
    """
    Calculate overlap slices for array positioning.
    
    Parameters:
    - large_array_shape: shape of target array
    - small_array_shape: shape of array to position
    - position: position tuple
    - mode: overlap mode ('partial', 'trim', 'strict')
    
    Returns:
    tuple: (large_slices, small_slices)
    """

def extract_array(array_large, shape, position):
    """
    Extract smaller array from larger array at given position.
    
    Parameters:
    - array_large: source array
    - shape: shape of extracted array
    - position: center position for extraction
    
    Returns:
    array: extracted sub-array
    """

def add_array(array_large, array_small, position):
    """
    Add small array to large array at given position.
    
    Parameters:
    - array_large: target array (modified in-place)
    - array_small: array to add
    - position: position for addition
    """

Bitmask Utilities

Tools for working with bitmask arrays and flag collections.

def interpret_bitmask(bitmask, flip_bits=None):
    """
    Interpret bitmask array or integer.
    
    Parameters:
    - bitmask: bitmask specification
    - flip_bits: bits to flip interpretation
    
    Returns:
    int or array: interpreted bitmask
    """

class FlagCollection:
    """
    Collection of named bit flags.
    
    Parameters:
    - **kwargs: flag_name=bit_value pairs
    """
    def __init__(self, **kwargs): ...
    
    def __getitem__(self, key):
        """Get flag value by name."""
    
    def __setitem__(self, key, value):
        """Set flag value by name."""

Usage Examples

Basic NDData Usage

import numpy as np
from astropy.nddata import NDData, StdDevUncertainty
import astropy.units as u

# Create data with uncertainty
data = np.random.random((100, 100))
uncertainty = StdDevUncertainty(np.sqrt(data))
mask = data < 0.1

# Create NDData object
nd = NDData(data, uncertainty=uncertainty, mask=mask, 
           unit=u.adu, meta={'exposure': 300})

print(f"Data shape: {nd.data.shape}")
print(f"Unit: {nd.unit}")
print(f"Masked pixels: {nd.mask.sum()}")

CCD Data I/O

from astropy.nddata import CCDData
import astropy.units as u

# Create CCD data
data = np.random.random((512, 512))
ccd = CCDData(data, unit=u.adu)

# Add uncertainty and mask
ccd.uncertainty = StdDevUncertainty(np.sqrt(data) * u.adu)
ccd.mask = data < 0.05

# Save to FITS
ccd.write('image.fits', overwrite=True)

# Read back
ccd_loaded = CCDData.read('image.fits', unit=u.adu)

Block Operations

from astropy.nddata import block_reduce, block_replicate

# Reduce resolution by factor of 2
data = np.random.random((100, 100))
reduced = block_reduce(data, 2, func=np.mean)
print(f"Original: {data.shape}, Reduced: {reduced.shape}")

# Replicate to higher resolution
replicated = block_replicate(reduced, 2)
print(f"Replicated: {replicated.shape}")

Types

# Core NDData types
NDData = astropy.nddata.NDData
NDDataArray = astropy.nddata.NDDataArray
CCDData = astropy.nddata.CCDData

# Uncertainty types
NDUncertainty = astropy.nddata.NDUncertainty
StdDevUncertainty = astropy.nddata.StdDevUncertainty
VarianceUncertainty = astropy.nddata.VarianceUncertainty
InverseVariance = astropy.nddata.InverseVariance

# Utility types
FlagCollection = astropy.nddata.FlagCollection

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