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

utils.mddocs/

Utilities

Common utility functions and classes used throughout the astropy ecosystem including data downloading, metadata handling, and helper functions.

Core Imports

from astropy.utils.data import download_file, get_pkg_data_filename
from astropy.utils.decorators import deprecated, lazyproperty
from astropy.utils.console import ProgressBar
from astropy.utils.misc import isiterable

Capabilities

Data Management

Functions for downloading, caching, and managing data files.

def download_file(remote_url, cache=True, show_progress=True, timeout=None):
    """
    Download a file from a remote URL.
    
    Parameters:
    - remote_url: URL of file to download
    - cache: whether to cache downloaded file
    - show_progress: whether to show progress bar
    - timeout: timeout for download
    
    Returns:
    str: path to downloaded file
    """

def get_pkg_data_filename(data_name, package=None, show_progress=True):
    """
    Get path to package data file.
    
    Parameters:
    - data_name: name of data file
    - package: package containing data
    - show_progress: show progress if downloading
    
    Returns:
    str: path to data file
    """

def data_dir():
    """Return the data directory for astropy."""

def cache_dir():
    """Return the cache directory for astropy."""

def clear_download_cache():
    """Clear the download cache."""

Decorators

Decorator functions for common programming patterns.

def deprecated(since, message='', name='', alternative='', pending=False):
    """
    Decorator to mark functions/classes as deprecated.
    
    Parameters:
    - since: version when deprecated
    - message: deprecation message
    - name: name of deprecated item
    - alternative: suggested alternative
    - pending: whether deprecation is pending
    """

def lazyproperty(func):
    """
    Decorator for lazy property evaluation.
    
    The property is computed only once and cached.
    """

def classproperty(func):
    """Decorator for class properties."""

def format_doc(*args, **kwargs):
    """Decorator to format docstrings."""

Console Utilities

Utilities for console output and progress reporting.

class ProgressBar:
    """
    Progress bar for long-running operations.
    
    Parameters:
    - total: total number of iterations
    - ipython_widget: use IPython widget if available
    """
    def __init__(self, total, ipython_widget=False): ...
    
    def update(self, value=None):
        """Update progress bar."""
    
    def close(self):
        """Close progress bar."""

def human_time(dt):
    """
    Format time duration in human-readable form.
    
    Parameters:
    - dt: time duration in seconds
    
    Returns:
    str: formatted duration
    """

def human_file_size(size, si=False):
    """
    Format file size in human-readable form.
    
    Parameters:
    - size: size in bytes
    - si: use SI units (1000) vs binary (1024)
    
    Returns:
    str: formatted size
    """

Miscellaneous Utilities

Various utility functions for common tasks.

def isiterable(obj):
    """
    Check if object is iterable.
    
    Parameters:
    - obj: object to check
    
    Returns:
    bool: True if iterable
    """

def silence():
    """Context manager to silence warnings."""

def find_api_page(obj):
    """
    Find API documentation page for object.
    
    Parameters:
    - obj: object to find documentation for
    
    Returns:
    str: URL of documentation page
    """

def resolve_name(name):
    """
    Resolve dotted name to object.
    
    Parameters:
    - name: dotted name string
    
    Returns:
    object: resolved object
    """

def indent(s, shift=1, width=4):
    """
    Indent a string.
    
    Parameters:
    - s: string to indent
    - shift: number of indentation levels
    - width: width of each indentation level
    
    Returns:
    str: indented string
    """

Usage Examples

Downloading Data

from astropy.utils.data import download_file

# Download a file with caching
url = 'https://example.com/data.fits'
local_path = download_file(url, cache=True)
print(f'Downloaded to: {local_path}')

Progress Bar

from astropy.utils.console import ProgressBar
import time

# Show progress for long operation
with ProgressBar(100) as bar:
    for i in range(100):
        time.sleep(0.01)  # Simulate work
        bar.update(i + 1)

Deprecation Warning

from astropy.utils.decorators import deprecated

@deprecated('1.0', message='Use new_function instead')
def old_function():
    """This function is deprecated."""
    return "old result"

# Using deprecated function will show warning
result = old_function()

Types

# Utility types
ProgressBar = astropy.utils.console.ProgressBar

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