hipercam.ccd

Classes & methods to represent CCDs and multi-CCDs

A CCD is built as a Group of Window objects, while a multi-CCD of MCCD is built as a Group of CCD objects. These classes allow handling of CCD data.

Classes summary

CCD(winds, nxtot, nytot[, nxpad, nypad, copy])

Represents a single CCD as a Group of Window.

MCCD(ccds[, head, copy])

Class representing a multi-CCD as a Group of CCD objects plus a FITS header.

class hipercam.ccd.CCD(winds, nxtot, nytot, nxpad=0, nypad=0, copy=False)

Bases: hipercam.group.Agroup

Represents a single CCD as a Group of Window.

CCD objects support a few operations such as returning the mean value, arithematic operations, and file I/O to/from FITS files. Header information is passed via the Windows. The first of these is assumed to be the location for any data pertaining to the CCD as a whole.

copy(memo=None)

Make a copy of the CCD

copy.copy and copy.deepcopy of a CCD use this method

crop(ccd)

Given a template CCD called ccd, this tries to modify the format of the CCD, returning a new CCD. This is often needed e.g. prior to applying a full frame flat field. In general this operation requires re-labelling of the Window composing the CCD. It raises a HipercamError if it fails.

flatten()
float32()

Applies :class:Window.float32 to all Windows of a CCD

float64()

Applies :class:Window.float64 to all Windows of a CCD

property head

Returns the first Window or an empty fits.Header if there is no first Window. The header of the first Window is where general header items of the CCD are stored.

inside(x, y, dmin)

Tests whether a point x,y lies within any Window of a CCD, at least dmin from its outer edge. It returns with the Window label or None if the point is not inside any Window

is_data()

Returns True / False according to whether the frame is thought to contain data. Uses DSTATUS keyword if present, else returns True

matches(ccd)

Check that the CCD matches another, which in this case means checking that each window of the same label matches the equivalent in the other CCD.

There will be no match if there any windows present in one CCD but not the other and the windows must have identical location, size and binning.

Raises KeyError or ValueError exception depending on the problem.

max()

Returns the maximum value of the CCD.

mean()

Returns the mean value of the CCD.

median()

Returns the median value of the CCD.

min()

Returns the minimum value of the CCD, i.e. the minimum of all the minimum values of all the Window

percentile(q, xlo=None, xhi=None, ylo=None, yhi=None)

Computes percentile(s) of the CCD.

Arguments:

q : float or sequence of floats
  Percentile(s) to use, in range [0,100]

xlo : int | None
  To restrict range of pixels

xhi : int | None
  To restrict range of pixels

ylo : int | None
  To restrict range of pixels

yhi : int | None
  To restrict range of pixels
classmethod read(fname, cnam=None)

Builds a CCD from a FITS file. Expects a primary HDU, containing no data, followed by a series of HDUs each containing data for a series of non-overlapping windows.

This can also be applied to extract a particular CCD, labelled ‘cnam’ from an MCCD hcm file, on the assumption that all HDUs for a given CCD come in a contiguous block with each one labelled with the keyword ‘CCD’.

Data are converted to float32 unless they are read in as float64.

classmethod rhdul(hdul, cnam=None)

Builds a single CCD from an HDUList.

If cnam is None, it is assumed that each HDU represents a Window. Each data HDU will be searched for a header parameter ‘WINDOW’ to label the Window, but the routine will attempt to generate a sequential label if WINDOW is not found. If the auto-generated label conflicts with one already found, then a KeyError will be raised.

If cnam is not None, cnam is taken to be the label of a CCD to be extracted from the HDUList which may contain multiple CCDs. It is assumed in this case that the CCD of interest has a continguous set of HDUs all containing the keyword CCD set equal to cnam. This allows individual CCDs to be read from hcm MCCD files.

Arguments:

hdul  : :class:`HDUList`
     each HDU will be read as sub-window of the :class:`CCD`

cnam  : (None | string)
     if cnam is not None, the routine will try to find and return a
     :class:CCD built from a contiguous subset of HDUs that matches
     cnam (the keyword CCD is used)

Returns a CCD. Data are converted to float32 unless they are read in as float64.

classmethod rmhdul(hdul)

Builds a CCD from an HDUList potentially containing multiple CCDs, i.e. an MCCD object. This function acts as a generator to allow the CCDs to be returned in successive calls. It is assumed that hdul is positioned at the start of the CCDs (i.e. with the initial data-less primary HDU removed).

Arguments:

hdul  : :class:`HDUList`
     each ImageHDU will be read as a sub-window of the :class:`CCD`

Returns:

A series of (label, :class:`CCD`) 2-element tuples to be used as
as follows::

  >> for label, ccd in CCD.rmhdul(hdul, True):
  >>    ... do something

Data are converted to float32 unless they are read in as float64.

set_const(val)

Sets all Windows to a constant value

uint16()

Applies :class:Window.uint16 to all Windows of a CCD

whdul(hdul=None, cnam=None, xoff=0, yoff=0)

Write the CCD as a series of HDUs, one per Window, adding to and returning an HDUList.

Arguments:

hdul : astropy.io.fits.HDUList
   The HDUList to add to.

cnam : string | None
   CCD name.

xoff : int [if cname is not None]
   X-offset for mosaicing in ds9. Ignored if cnam is None.

Returns:: an HDUList.

write(fname, overwrite=False)

Writes out the CCD to a FITS file.

Arguments:

fname : (string)
     Name of file to write to.

overwrite : (bool)
     True to overwrite pre-existing files
class hipercam.ccd.MCCD(ccds, head=None, copy=False)

Bases: hipercam.group.Agroup

Class representing a multi-CCD as a Group of CCD objects plus a FITS header. It supports arithematic operations and file I/O to/from FITS files.

copy(memo=None)

Make a copy of the MCCD

copy.copy and copy.deepcopy of an MCCD use this method

crop(mccd)

Crops the :class:MCCD to the same format as a template, mccd. Returns the new version. Will raise a HipercamError if it fails.

float32()

Applies :class:Window.float32 to all Windows of an MCCD

float64()

Applies :class:Window.float64 to all Windows of an MCCD

matches(mccd)

Check that the MCCD matches another, which in this means checking that each CCD of the same label matches the equivalent in the other MCCD.

There will be no match if there any CCDs present in one MCCD which are not in the other.

Raises KeyError or ValueError exception depending on the problem.

classmethod read(fname)

Builds an MCCD from a FITS file. Expects a primary HDU, containing general headers and the first HDU, followed by a series of HDU blocks for each CCD with the first one of each containing some general per-CCD header items.

Data are converted to float32 unless they are read in as float64.

classmethod rhdul(hdul)

Builds an MCCD from an HDUList.

This will usually be passed the HDUList from a file. The header from the first (primary) HDU will be used to create the header for the MCCD. It is then assumed that the data for each CCD is contained in blocks of HDUs after the first. The data from all HDUs will be read into the Window objects that make up the CCD. Each HDU will be searched for a header parameter WINDOW to label the Window, but the code will attempt to generate a sequential label if WINDOW is not found.

Arguments:

hdul : :class:`HDUList`
     each ImageHDU will be read as sub-window of the :class:`CCD`

Data are converted to float32 unless they are read in as float64.

set_const(val)

Sets all CCDs to a constant value

uint16()

Applies :class:Window.uint16 to all Windows of an MCCD

write(fname, overwrite=False, xgap=200, ygap=200)

Writes out the MCCD to a FITS file.

Arguments:

fname : string or file-like object
    Name of file to write to. Can also be a file, opened in
    writeable binary mode.

overwrite : bool
    True to overwrite pre-existing files

xgap  : int
   X-gap used to space CCDs for ds9 mosaicing (unbinned pixels)

ygap  : int
   Y-gap used to space CCDs for ds9 mosaicing (unbinned pixels)