Usage#
Installation#
To use xarray-fits, first install it using pip:
(.venv) $ pip install xarray-fits
Creating xarray datasets from FITS files#
To retrieve a list of xarray datasets with
FITS file contents, you can use the
xarrayfits.xds_from_fits()
function:
- xarrayfits.xds_from_fits(fits_filename: str | Iterable[str], hdus: None | int | Iterable[int] | Iterable[str] | Mapping[int, str] = None, chunks: None | Mapping[str, int] | Iterable[Mapping[str, int]] = None) Iterable[Dataset]
Parameters#
- fits_filename:
str
orIterable
ofstr
. FITS filename or a list of FITS filenames. The first case supports a globbed pattern.
- hdus
int
orIterable
ofint
orstr
orIterable
ofstr
orMapping[int, str]
, optional Specifies which HDUs are stored on the returned datasets.
If
None
, all HDUs are selected.If integers, the DataArray’s will be named
hdu{h}
, whereh
is the hdu index.If strings are provided, the DataArray’s will be named by them.
A
Mapping[int, str]
will name DataArry hdus at specific indices.
- chunks
Mapping[str, int]
orIterable
ofMapping[str, int]
, optional Chunking strategy for each dimension of each hdu. Dimensions should be specified via the C order dimensions
{0: 513, 1: 513, 2: 33}
Returns#
- datasets: list of
xarray.Dataset
A list of xarray Datasets corresponding to glob matches in the
fits_filename
parameter. Each Dataset containsxarray.DataArray
‘s corresponding to each HDU on the FITS file.
- fits_filename:
For example:
>>> from xarrayfits import xds_from_fits
>>> xds_from_fits("3C147.fits")