Skip to main content

Read FITS files in Dask Arrays.

Project description

da-fits

Read/write FITS files to/from Dask Arrays. Currently a very simple implementation.

NOTE: Astropy can't write from a Dask array to FITS in parallel (see #11159). As a workaround, I write to a temporary Zarr file (which supports parallel write), and then copy to a FITS file in serial. Keep this in mind for very large files!

Inspired by:

Installation

Install from PyPi

pip install dafits

Or, from GitHub:

pip install git+https://github.com/AlecThomson/da-fits.git

Example usage

import dafits

# See doctstring
help(dafits.read)
# Help on function read in module dafits.core:

# read(file: str, ext=0, memmap=True, mode='denywrite', chunks='auto', return_header=False) -> Tuple[dask.array.core.Array, Optional[Dict]]
#     Read FITS file to DataArray.

#     Args:
#         file (str): FITS file to read.
#         ext (int, optional): FITS extension to read. Defaults to 0.
#         memmap (bool, optional): Use memmap. Defaults to True.
#         mode (str, optional): Read mode. Defaults to "denywrite".
#         chunks (str, optional): Dask array chunks. Defaults to "auto".
#         return_header (bool, optional): Optionally return the FITS header. Defaults to False.

#     Returns:
#         typing.Tuple[da.Array, typing.Optional[typing.Dict]]: DataArray and (optionally) FITS header.

# Read a file with header
data, header = dafits.read('/path/to/file.fits', return_header=True)

# Get data in memory
data.compute()

# Do some kind of maths
new_data = data.mean(axis=0)

# Write to disk (via Zarr)
# See doctstring
help(dafits.write)
# Help on function write in module dafits.core:

# write(file: str, data: dask.array.core.Array, header=None, verbose=True, **kwargs) -> None
#     Write DataArray to FITS file (via Zarr).

#     Args:
#         file (str): Output filename.
#         data (da.Array): Input data.
#         header (header, optional): FITS header. Defaults to None.
#         verbose (bool, optional): Verbose output. Defaults to True.
#         **kwargs: Additional keyword arguments passed onto fits.writeto.


dafits.write('/path/to/new_file.fits', new_data, header=header, overwrite=True)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dafits-1.1.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

dafits-1.1.0-py2.py3-none-any.whl (5.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file dafits-1.1.0.tar.gz.

File metadata

  • Download URL: dafits-1.1.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/3.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.64.0 CPython/3.9.6

File hashes

Hashes for dafits-1.1.0.tar.gz
Algorithm Hash digest
SHA256 fb10a53c941c74965a590463f3f9fd279031b004ffdb32bbc3bb8aea2050bd6e
MD5 3210587a351401597e9ddebbbe20211d
BLAKE2b-256 d1fe74b72fa797d3b18656c67bf0f3be3b0516b49bc9819cc90224e7e7034278

See more details on using hashes here.

File details

Details for the file dafits-1.1.0-py2.py3-none-any.whl.

File metadata

  • Download URL: dafits-1.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/3.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.64.0 CPython/3.9.6

File hashes

Hashes for dafits-1.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9b0aa54bbafc58b43a71b98d8da538558c073b8cb99ab7c95f69a18b32c46a9f
MD5 fdd29a24f210e6072e9246bcaf77d40c
BLAKE2b-256 50920f515719b9c1c77a4139f9e87a311a7e5522c6037b46a8f4009813c18799

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page