Python bindings for the CASACORE radio astronomy library providing comprehensive interfaces for table operations, image processing, coordinate systems, and astronomical measurements.
npx @tessl/cli install tessl/pypi-python-casacore@3.7.0Python-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.
pip install python-casacoreMain package import:
import casacoreCommon 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, getvariableBackwards compatibility imports (pyrap):
# Legacy pyrap compatibility
import pyrap.tables as pt
import pyrap.measures as pm
import pyrap.quanta as pqfrom 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()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])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')Python-casacore consists of two main packages with six core functional areas:
The package includes six C++ extension modules that provide high-performance implementations:
_tables, _images, _measures, _quanta, _functionals, _fittingThis hybrid architecture ensures both Python convenience and C++ performance for computationally intensive radio astronomy 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): ...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: ...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): ...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: ...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: ...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): ...# 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'