The ccd module contains classes and functions for processing CCD images or similar.
Detailed analysis tools are in phot and spec – this module is mainly for low-level operations like direct viewing of images, calibrations, and similar.
Bases: astropysics.ccd.DataScaling
Bases: astropysics.ccd.CCDImage
arr can be an array or a 2-tuple (nx,ny).
ival sets the initial value - if it is None, the array is not initialized. Otherwise, the array is set to the ival value.
range and scaling set those properties (see CCDImage)
Bases: object
The base class for CCD images. Subclasses should follow the guidelines below to support various formats/file types.
MUST implement:
Note that these two methods in principle operate independent of the CCDImage internal representation, so if desired, _applyArray can just update the same backing store that _extractArray uses
The following image properties are defined, defaulting to None. They may be set or overridden as appropriate
Note that the coordinate system in python is 0-based - the first pixel is (0,0), NOT (1,1)
chooses the range to activate for further operations
can either be None (whole file), a 4-tuple of the form (xl,xu,yl,yu) or a 3-tuple of the form (xcen,ycen,radius)
Note that the 3-tuple form will be range-checked and auto-shrunk if the radius is too big, but the 4-tuple will not
clip points that are non-finite (i.e. NaN or infinite)
action is a replacement action (see clipSigma)
clip points lying outside the range specified in the 2-sequence limits
if percentage is outside True, the limits are percentages, otherwise fractions
action is a replacement action (see clipSigma)
if fullsig is true, the whole image is used for computing the standard deviation instead of just the active region
action can be a value to set the outliers to, ‘mean’,’median’, ‘noclipmean’,’noclipmedian’, ‘fullmean’, or ‘fullmedian’, or ‘mask’
returns number of pixels replaced
clip data points that are above/below a threshold
thresh is the threshold
comp can be ‘<’, ‘>’,’<=’, or ‘>=’ for clipping points that are less that, greater than, less than or equal to, or greater than or equal to the threshold.
action is a replacement action (see clipSigma)
direct access to the array holding the current data. If this data is subsequently edited, applyChanges() should be called to ensure consistancy orientation is such that array should be indexed as data[x,y]
return mean,median,stddev,min, and max for the scaled active region
apply a global offset to all the current data
offset can either by a value or ‘gmin’ to offset the data by the global minimum or ‘gminp1’ to offset the lowest value to 1, or ‘min’ or ‘minp1’ to use the selected area minimum
Pixel scale of the image in
kwargs go into hist reset defaults: ‘log’->True,’bins’->100 or 25,’histtype’->’step’
This plots the associated active range of the image using matplotlib
valrange can be:
scalebar can be False/None to show no scale bar, a 2-tuple (color,unitstring) , or True (red with ” scale)
axes can be ‘image’ or ‘sky’
if clickinspect is True, will return the cid of the matplotlib event
colormap is the name of a colormap (or None to not change the map)
kwargs are passed into matplotlib imshow
returns or sets the range (setting is same as calling activateRange)
Sets the scaling to apply for this image - either a string for the name of a builtin scale function or a DataScaling object, in which case kwargs will be applied to the initializer
if None, LinearScaling will be used
tuple with dimensions of the currently selected image (the internal representation is flipped for FITS - this is the correct orientation)
number of pixels in the currently selected image
The photometric zero-point for this CCDImage, to be used in other processing tasks (see astropysics.phot)
Bases: astropysics.ccd.NoiseModel
Noise model for a CCD with a poissonian term for electrons/photons and a gaussian term for read noise (constant noise), sensitivity noise (e.g. noise proportional to the data), and uniform noise
gain is in e-/ADU
readnoise is in e-
snoise is the ‘sensitivity’ or ‘scale’ noise as a fraction of the adu signal
Bases: object
The base class for objects that scale the data in a CCDImage. Subclasses should override:
an attribute with the name of the transform
accepts a 2D array of the image data and outputs a 2D array of the same shape
accepts a 2D array of altered data and outpts a 2D array of the same shape. Expected to match the property x = invtransform(transform(x)) . If it is set to None, it is assumed that an inverse transform is impossible
the __init__ method can be overridden, but will be called with the CCDImage object as the first argument
Bases: astropysics.ccd.DataScaling
Bases: astropysics.ccd.CCDImage
A CCDImage representation of a FITS file. Note that this class requires pyfits <http://www.stsci.edu/resources/software_hardware/pyfits> to work at all.
Parameters: |
|
---|
Closes the file associated with this FitsImage. Many operations will fail after this occurs.
the hdu of the current fits file
Save this image to a new fits file. kwargs will be passed to pyfits.HDUList.writeto
Be default, this will overwrite a file of the same name - if this is not desired, set the clobber keyword to False.
Bases: astropysics.ccd.NoiseModel
Bases: astropysics.ccd.CCDImage
A CCDImage with an HDF5 file as the backing store.
Warning
This class is a work in progress and may not work right now
Bases: astropysics.pipeline.PipelineElement
Subtracts a dark/bias frame or uses an overscan region to define a bias or bias curve to subtract. The order of operations is:
Any of these operations may be ommitted if the necessary attribute are set to None.
biasframe: an image matching the input’s shape that will be subtracted or None to skip this step.
A 4-tuple defining a region as (xmin,xmax,ymin,ymax) Or None to skip this step.
overscan: an integer defining the edge of the overscan region, or a 2-tuple of the form (edge,bool) where the boolean indicates if the it is a left edge/starting at 0 (True, default) or a right edge (False)
overscanaxis: sets the axis along which the overscan region is defined (typcally the readout axis): ‘x’/0 or ‘y’/1, assumed for the overscan
overscanfit: sets the default fitting method for the overscan region (if used) or None to just use the combined value directly
interactive: if True, interactively fit the overscan curve
The method used to combine the pixels in the bias region or overscan region to produce the overall subtraction value. Can be:
trim: trim off the overscan region if it is specified * save:if True, stores the final image and any fit curve as attributes lastimage or lastcurve on this object.
Bases: astropysics.pipeline.PipelineElement
Combines a sequence of images into a single image.
Attributes that control combining are:
Can be any of:
shifts: a sequence of 2-tuples that are taken as the amount to offset each image before combining (in pixels)
shiftorder: order of the spline interpolation used when images are shifted
trim: if True, the image is trimmed based on the shifts to only include the pixels where the images overlap
sigclip: the number of standard deviations from the mean before a point is rejected from the combination. If None, no sigma clipping is performed
save: if True, the last set of operations will be stored for later use (see below)
these attributes will be set at each operation:
Combines images into a single image.
Parameters: | images – A sequence of 2D numpy arrays with the image data to be combined. |
---|---|
Returns: | A 2D numpy array of images produced by combining the inputs. |
isSequenceType(a) – Return True if a has a sequence type, False otherwise.
Bases: astropysics.pipeline.PipelineElement
This object flattens an image using a flat field image
the following attributes determine the flatfielding behavior: * flatfield: the field to use to generate the flatting response * combine: ‘mean’,’median’,’min’,’max’, or a callable * save: store ‘lastimage’ as the last image that was flatted
Bases: astropysics.ccd.DataScaling
Bases: astropysics.ccd.DataScaling
linearly maps the values to a valid range and applies logarithmic scaling to the result, such that the output ranges from lower to upper.
Alternatively, if the base is specified, the log is taken with respect to that base without ranging.
if upper is None, just offsets to the lower range if lower is None, logarithmic scaling is applied directly
TODO:work out better inverse rescaling - for now setting it to None
Bases: object
Abstract base class for noise models. subclasses should implement the _dataPlusNoise method, and optionally, var (variance)
the floor and ceiling attributes (if not None) set the lowest/highest values - any time noise results in a value smaller/larger than the value, it is set to this value
computes the noise for the given input data.
returns the variance of this noise model for each point in the input data
the nvar attribute is used to determine the number of calculations to use to estimate the variance.
Bases: astropysics.ccd.NoiseModel
Bases: astropysics.ccd.DataScaling
Bases: astropysics.ccd.DataScaling
Bases: astropysics.ccd.NoiseModel
This function performs kcorrections pixel-by-pixel on a matched set of images. Note that one must be carefule to ensure the images are matched (e.g. they must be degraded to the largest PSF image), something that this function does nothing about. See astropysics.phot.kcorrect for more details on the k-correction algorithm
images are a sequence of CCDImage objects, or a list of filenames that will be loaded as images (using the 0th hdu if FITS).
bands should be the photometric bands of each of the images as accepted by kcorrect
z is the redshift to correct this image to
range is the range from each of the images to select
zeropoints and pixelareas (sq asec) will be deduced from the CCDImage properties zeropoint and pixelscale if they are not provided (if they are, they will everwrite the existing properties)
offset is the type of offset to be used (passed into offsetData)
extra kwargs will be passed into astropysics.phot.kcorrect
returns absmag,kcorrection,chi2 as arrays shaped like the input range (for absmag and kcorrection, the first dimension is the bans)
if True, retdict means the absmag and kcorrection will be returned as dictionaries of arrays with the band names as the keys
Factory function for generating CCDImage objects from a file with filename fn - the exact class type will be inferred from the extension. kwargs will be passed into the appropriate constructor.
Currently only supports FITS files.
generate mosaics of objects from different images xcens,ycens,and radii are the x,y of the center and the radius to plot images are the image filenames row determines which row of the mosaic the object is placed in. If None, an optimal square/rectangular mosaic will be used titles is a sequence of strings to title each object if noticks is True, x and y ticks are not drawn clf determines if the figure is cleared before the mosaic is generated imdict is a dictionary with values that are CCDImage objects. Any image filenames will be placed into the provided dictionary keys with values generated by calling load_image_file() on the filenames
alias of ExponentialScaling