Skip to content

Commit

Permalink
add ability to load from an open FITS object
Browse files Browse the repository at this point in the history
  • Loading branch information
esheldon committed Sep 14, 2016
1 parent 1d27bae commit 70843e6
Showing 1 changed file with 41 additions and 12 deletions.
53 changes: 41 additions & 12 deletions psfex/psfex_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import numpy
from . import _psfex_pywrap

DEFAULT_EXT='psf_data'

DOUBLE_DTYPE = 'f8'
LONG_DTYPE = 'i8'
POLY_DIM = 2
Expand All @@ -19,8 +21,19 @@ def __str__(self):


class PSFEx(dict):
def __init__(self, filename):
self._load(filename)
def __init__(self, *args, **kw):
"""
Load data into a PSFEx object
parameters
----------
filename or FITS object: string, optional
Send filename or open fitsio FITS object
ext: string or int, optional
The extension from which to read
"""

self.load(*args, **kw)

def get_rec(self, row, col):
"""
Expand Down Expand Up @@ -53,19 +66,34 @@ def get_sigma(self):
sigma = fwhm/fac
return sigma

def _load(self, filename):
def load(self, arg, **kw):
"""
Load the PSF information from the fits file
Also load the C PSFEx object
Load data into a PSFEx object
parameters
----------
filename or FITS object: string, optional
Send filename or open fitsio FITS object
ext: string or int, optional
The extension from which to read
"""

self['filename'] = filename
with fitsio.FITS(filename) as fits:
psf_mask=fits['psf_data']['psf_mask'][:]
psf_mask=numpy.array(psf_mask, dtype=DOUBLE_DTYPE)
if isinstance(arg, fitsio.FITS):
self._load_from_fits(arg, **kw)
else:
self['filename'] = arg
with fitsio.FITS(arg) as fits:
self._load_from_fits(fits, **kw)

def _load_from_fits(self, fits, ext=DEFAULT_EXT):

hdu = fits[ext]

psf_mask=hdu['psf_mask'][:]

psf_mask=numpy.array(psf_mask, dtype=DOUBLE_DTYPE)

h=fits['psf_data'].read_header()
h=hdu.read_header()

self._psf_mask=psf_mask

Expand Down Expand Up @@ -100,4 +128,5 @@ def _load(self, filename):
self['contextscale'],
self['psf_samp'],
self._psf_mask)



0 comments on commit 70843e6

Please sign in to comment.