or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

coordinate-systems.mdfitting-operations.mdfunctionals.mdimage-processing.mdindex.mdquantities-units.mdtable-operations.md
tile.json

tessl/pypi-python-casacore

Python bindings for the CASACORE radio astronomy library providing comprehensive interfaces for table operations, image processing, coordinate systems, and astronomical measurements.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/python-casacore@3.7.x

To install, run

npx @tessl/cli install tessl/pypi-python-casacore@3.7.0

index.mddocs/

Python-Casacore

Python-casacore provides comprehensive Python bindings for the CASACORE radio astronomy library, enabling radio astronomy applications to access core functionality including table operations, image processing, coordinate systems, and measurement sets through a Python interface. It offers high-performance astronomical data handling capabilities with support for FITS files, coordinate transformations, and specialized radio astronomy data structures.

Package Information

  • Package Name: python-casacore
  • Language: Python (with C++ extensions)
  • Installation: pip install python-casacore
  • Minimum Python Version: 3.8+
  • Dependencies: numpy, boost-python, casacore C++ library

Core Imports

Main package import:

import casacore

Common submodule imports:

# Table system
from casacore.tables import table, taql
from casacore.tables import default_ms, default_ms_subtable

# Table utilities
from casacore.tables import tablefromascii, msconcat, msregularize
from casacore.tables import makescacoldesc, makearrcoldesc, makecoldesc, maketabdesc

# Image processing
from casacore.images import image

# Coordinate systems and measures
from casacore.measures import measures

# Quantities with units
from casacore.quanta import quantity

# Mathematical functionals
from casacore.functionals import gaussian1d, poly, compiled

# Least squares fitting
from casacore.fitting import fitserver

# Utilities  
from casacore.util import substitute, getlocals, getvariable

Backwards compatibility imports (pyrap):

# Legacy pyrap compatibility
import pyrap.tables as pt
import pyrap.measures as pm
import pyrap.quanta as pq

Basic Usage

Working with Tables

from casacore.tables import table, taql

# Open an existing table
t = table('my_table.ms', readonly=True)

# Get basic table information
print(f"Table has {t.nrows()} rows and {t.ncols()} columns")
print("Columns:", t.colnames())

# Access cell data
value = t.getcell('DATA', 0)  # Get first row of DATA column
column_data = t.getcol('TIME')  # Get entire TIME column

# Query with TaQL (Table Query Language)
result = taql("SELECT TIME, DATA FROM my_table.ms WHERE ANTENNA1 < 10")
print(f"Query returned {result.nrows()} rows")

# Close table
t.close()

Working with Images

from casacore.images import image

# Open an image
img = image('my_image.fits')

# Get image information
print("Image shape:", img.shape())
print("Image coordinates:", img.coordinates())

# Get image data
data = img.getdata()

# Get image statistics
stats = img.statistics()
print("Max:", stats['max'], "Min:", stats['min'])

# Create a subimage
subimg = img.subimage(blc=[10, 10], trc=[100, 100])

Working with Quantities and Measures

from casacore.quanta import quantity
from casacore.measures import measures

# Create quantities with units
freq = quantity('1.4GHz')
time = quantity('2023-01-01/12:00:00')
pos = quantity([10.0, 20.0, 30.0], 'm')

# Create measures server
dm = measures()

# Set reference frame
dm.doframe(dm.epoch('utc', 'today'))
dm.doframe(dm.observatory('VLA'))

# Create direction measure
source = dm.direction('j2000', '12h30m00s', '-30d00m00s')

# Convert between coordinate systems
azel = dm.measure(source, 'azel')

Architecture

Python-casacore consists of two main packages with six core functional areas:

Package Structure

  • casacore: Primary package with modern Python interfaces
  • pyrap: Backwards compatibility package that re-exports casacore modules

Core Submodules

  • Tables: Complete table system with SQL-like query language (TaQL)
  • Images: Multi-dimensional image processing with coordinate systems
  • Measures: Astronomical reference frames and coordinate conversions
  • Quanta: Physical quantities with units and constants
  • Functionals: Mathematical functions with parameters for fitting
  • Fitting: Linear and non-linear least squares fitting algorithms

C++ Integration

The package includes six C++ extension modules that provide high-performance implementations:

  • _tables, _images, _measures, _quanta, _functionals, _fitting

This hybrid architecture ensures both Python convenience and C++ performance for computationally intensive radio astronomy operations.

Capabilities

Table System Operations

Complete interface to casacore's table system including table creation, data access, querying with TaQL (Table Query Language), and MeasurementSet operations. Provides both high-level convenience methods and low-level table manipulation.

def table(tablename, readonly=True, ack=True, **kwargs): ...
def taql(command, style='Python', tables=[], globals={}, locals={}): ...
def default_ms(name, tabdesc=None, dminfo=None): ...

Table Operations

Image Processing and Analysis

Multi-dimensional astronomical image processing with support for FITS, HDF5, MIRIAD, and casacore paged image formats. Includes coordinate system handling, image statistics, regridding, and subimage operations.

def image(imagename, **kwargs): ...
class coordinatesystem: ...

Image Processing

Coordinate Systems and Measures

Astronomical reference frames, coordinate conversions, and measurement systems. Handles directions, positions, epochs, frequencies, Doppler shifts, and baseline/UVW coordinates with full support for reference frame transformations.

class measures:
    def direction(self, rf='', v0='0..', v1='90..', off=None): ...
    def position(self, rf='', v0='0..', v1='90..', v2='0m', off=None): ...
    def epoch(self, rf='', v0='0.0d', off=None): ...
    def measure(self, v, rf, off=None): ...

Coordinate Systems

Quantities and Units

Physical quantities with units, unit conversions, and astronomical constants. Supports scalar and vector quantities with comprehensive unit system including SI, astronomical, and specialized radio astronomy units.

def quantity(*args): ...  
def is_quantity(q): ...
class Quantity: ...
class QuantVec: ...

Quantities and Units

Mathematical Functionals

Parameterized mathematical functions including polynomials, Gaussians, and user-defined compiled expressions. These functionals can be used for data modeling and as input to the fitting system.

class functional: ...
class gaussian1d: ...
class poly: ...
class compiled: ...

Mathematical Functionals

Least Squares Fitting

Linear and non-linear least squares fitting with constraint support. Handles both real and complex fitting problems with SVD solutions for rank-deficient systems and comprehensive error analysis.

class fitserver:
    def linear(self, functional, x, y, **kwargs): ...
    def functional(self, functional, x, y, **kwargs): ...
    def solution(self, fid=None): ...
    def addconstraint(self, x=[], y=0.0, **kwargs): ...

Fitting Operations

Types

Common Types

# Table-related types
class table:
    def nrows(self) -> int: ...
    def ncols(self) -> int: ...
    def colnames(self) -> list[str]: ...
    def getcell(self, columnname: str, rownr: int): ...
    def getcol(self, columnname: str, startrow: int = 0, nrow: int = -1): ...

# Quantity types  
class Quantity:
    def get_value(self): ...
    def get_unit(self) -> str: ...
    def convert(self, unit: str): ...

class QuantVec:
    def get_value(self): ...
    def get_unit(self) -> str: ...

# Measure types (all measures are dictionaries with 'type', 'refer', and 'm0'/'m1'/'m2' keys)
MeasureDict = dict[str, Any]  # Has keys: 'type', 'refer', 'm0', optionally 'm1', 'm2', 'offset'