Skip to main content

Package to efficiently read large fits arrays in object by object

Project description

https://img.shields.io/travis/mindriot101/fitsiochunked.svg

Package to sequentially efficiently read large fits arrays in object by object

  • Free software: MIT license

Features

  • Sequentially read in large fits files, within a given fixed memory limit

Quick usage

The following example shows an example of reading in a large fits hdu within a memory limit of 2048MB, assuming light curves are stored in rows:

import numpy as np
import fitsio
import fitsiochunked as fc

with fitsio.FITS(filename) as infile:
    hdu = infile['flux']
    napertures = hdu.get_info()['ndim'][0]
    mean_flux = np.zeros(napertures)

    for chunk in fc.chunks(hdu, memory_limit_mb=2048):

        # `chunk` is a namedtuple with `.data` and `.slice` properties
        chunk_data = chunk.data
        print('Data shape:', chunk_data.shape)
        print('Data dtype:', chunk_data.dtype)


        chunk_slice = chunk.slice
        print('Chunk starting from aperture:', chunk_slice.start)
        print('Chunk up to:', chunk_slice.stop)

        chunk_mean = np.average(chunk_data, axis=1)
        mean_flux[chunk_slice] = chunk_mean

Installation

Install with pip:

pip install git+https://github.com/mindriot101/fitsiochunked

or download and run the setup file:

git clone https://github.com/mindriot101/fitsiochunked
cd fitsiochunked
python setup.py install

When this code matures, it will be put up on pip.

Details

The high level interface is the chunks function, which builds a ChunkedAdapter object wrapping a fitsio.ImageHDU object.

The ChunkedAdapter wraps a fitsio HDU object. When constructed, it becomes a callable which yields the image data in that hdu in chunks.

The chunksize can be set either with with the parameter chunksize which simply yields chunksize rows each time, or with memory_limit_mb which tries (no promises!) to automatically calculate the number of lightcurves that will fit into memory_limit_mb megabytes of memory.

Project details


Download files

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

Source Distributions

fitsiochunked-0.0.2.tar.gz (5.2 kB view hashes)

Uploaded Source

fitsiochunked-0.0.2.macosx-10.5-x86_64.tar.gz (4.1 kB view hashes)

Uploaded Source

Built Distribution

fitsiochunked-0.0.2-py2.py3-none-any.whl (5.1 kB view hashes)

Uploaded Python 2 Python 3

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