Skip to content

Sub6Resources/polars-astro

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

polars_astro

A package adding support for common astronomy data files in Polars.

DOI

Installing

pip install polars_astro

Usage

FITS Files

scan_fits adds support for reading in FITS files as a LazyFrame including predicate pushdown and column projection. The python package fitsio (built around CFITSIO) is used internally for efficient row/column access.

import polars as pl
import polars_astro as pla

pla.scan_fits("astro_catalog.fits").filter(
    pl.col("parallax") > 0.1,
    pl.col("parallax_err") < 0.01
).select(
    pl.col("ID"),
    pl.col("pm_ra"),
    pl.col("pm_dec"),
    pl.col("B_mag"),
    pl.col("V_mag")
)

Numpy Arrays

The np namespace makes it easy to retrieve numpy arrays from a DataFrame

import polars as pl
import polars_astro as pla

pmra, pmdec, distance = pla.read_fits("astro_catalog.fits").filter(
    pl.col("parallax") > 0.1,
    pl.col("parallax_err") < 0.01
).np.select(
    "pm_ra",
    "pm_dec",
    1/pl.col("parallax")
)

pmra, pmdec and distance will all be one-dimensional numpy arrays of the appropriate type. Nulls are handled as described in the polars documentation for Series.to_numpy. This may involve casting integers to floats.

About

A collection of code to aid with processing data in astronomy using Polars

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages