Package stistools :: Module wx2d
[hide private]
[frames] | no frames]

Module wx2d

source code


Version: 1.2 (2010 April 27)

Functions [hide private]
 
wx2d(input, output, wavelengths=None, helcorr='', algorithm='wavelet', trace=None, order=7, subdiv=8, psf_width=0.0, rows=None, subsampled=None, convolved=None)
Resample the input, correcting for geometric distortion.
source code
 
wx2d_imset(ft, imset, output, wavelengths, helcorr, algorithm, tracefile, order, subdiv, psf_width, rows, subsampled, convolved)
Resample one image set, and append to output file(s).
source code
tuple
wavelet_resampling(hdu, img, errimg, original_nrows, nrows, ncols, rows, a2center, a2displ, offset, shifta2, imset, order, subdiv, psf_width, subsampled, convolved)
Resample img and errimg using wavelets.
source code
tuple
kd_resampling(img, errimg, original_nrows, nrows, ncols, rows, a2center, a2displ, offset, shifta2)
Apply Kris Davidson's resampling method.
source code
array
kd_apply_trace(image, a2center, a2displ, offset=0.0, shifta2=0.0)
Kris Davidson's resampling algorithm, following the trace.
source code
float
stis_psf(x, a)
Evaluate the cross-dispersion PSF at x.
source code
 
apply_trace(image, a2center, a2displ, subdiv, offset=0.0, shifta2=0.0, extname='SCI')
Add together 'subdiv' rows of 'image', following the trace.
source code
array
extract(image, locn, subdiv)
Add together 'subdiv' rows of 'image', centered on 'locn'.
source code
array

This takes the square root of the average of the squares, intended to be used for interpolating the ERR array. Fractions of pixels at the upper and lower edges are excluded.

extract_err(image, locn, subdiv)
Average 'subdiv' rows of 'image', centered on 'locn'.
source code
array
extract_i16(image, locn, subdiv)
Bitwise OR 'subdiv' rows of 'image', centered on 'locn'.
source code
 
interpolate_trace(a2center, a2displ, y, length)
Interpolate within the array of traces, and return a trace.
source code
string or array
trace_name(trace, phdr)
Return the 1dt table name or array.
source code
tuple of two arrays

If 'tracefile' is already a trace array, it will just be returned, together with an arbitrary Y location of 0 (because that will always be within the image).

opt_elem and cenwave are criteria for selecting the relevant rows from the 1dt table. There will normally be several rows that match, and they should have different values of the Y location; the output list will be sorted on Y location.

get_trace(tracefile, phdr, hdr)
Read 1-D traces from the 1dt table (sptrctab).
source code
array
bin_traces(a2displ, binaxis1, ltv)
bin the traces by the factor binaxis1
source code
 
inv_haar(image) source code
 
inv_avg_interp(order, image) source code
 
polynomial(x, y, z, n)
used for interpolation
source code
Variables [hide private]
  __package__ = 'stistools'

Imports: sys, os, math, N, convolve, pyfits, gettable, wavelen, r_util


Function Details [hide private]

wx2d(input, output, wavelengths=None, helcorr='', algorithm='wavelet', trace=None, order=7, subdiv=8, psf_width=0.0, rows=None, subsampled=None, convolved=None)

source code 

Resample the input, correcting for geometric distortion.

Parameters:
  • input (string) - name of input file containing an image set
  • output (string) - name of the output file
  • wavelengths (string, or None) - name of the output file for wavelengths
  • helcorr (string) - specify "perform" or "omit" to override header keyword
  • algorithm (string) - "wavelet" or "kd"
  • trace (string or array, or None) - trace array, or name of FITS table containing trace(s)
  • order (int) - polynomial order (an odd number, e.g. 5 or 7)
  • subdiv (int) - number of subpixels (a power of 2, e.g. 8 or 16)
  • psf_width (float) - width of PSF for convolution (e.g. 1.3); 0 means no convolution
  • rows (tuple, or None) - a tuple giving the slice of rows to process; output values in all other rows will be set to zero. The default of None means all rows, same as (0, 1024)
  • subsampled (string, or None) - name of the output file with the subsampled image
  • convolved (string, or None) - name of the output file with the convolved image

wx2d_imset(ft, imset, output, wavelengths, helcorr, algorithm, tracefile, order, subdiv, psf_width, rows, subsampled, convolved)

source code 

Resample one image set, and append to output file(s).

Parameters:
  • ft - pyfits HDUList object for the input file
  • imset (int) - one-indexed image set number
  • output (string) - name of the output file
  • wavelengths (string, or None) - name of the output file for wavelengths
  • helcorr" (string) - specify "perform" or "omit" to override header keyword
  • algorithm (string) - "wavelet" or "kd"
  • tracefile (string or array) - trace array, or name of FITS table containing trace(s)
  • order (int) - polynomial order
  • subdiv (int) - number of subpixels
  • psf_width (float) - width of PSF for convolution
  • rows (tuple) - a tuple giving the slice of rows to process
  • subsampled (string, or None) - name of the output file with the subsampled image
  • convolved (string, or None) - name of the output file with the convolved image
  • input (HDUList)

wavelet_resampling(hdu, img, errimg, original_nrows, nrows, ncols, rows, a2center, a2displ, offset, shifta2, imset, order, subdiv, psf_width, subsampled, convolved)

source code 

Resample img and errimg using wavelets.

Parameters:
  • hdu (pyfits header/data unit object) - header/data unit for a SCI extension
  • img (array) - SCI image array (could be a subset of full image)
  • errimg (array) - ERR image array (could be a subset of full image)
  • original_nrows (int) - number of image lines (NAXIS2) in input image
  • nrows (int) - number of image lines in subset
  • ncols (int) - number of image columns (NAXIS1)
  • rows (tuple) - tuple giving the slice of rows to process
  • a2center (array) - 1-D array of Y locations
  • a2displ (array) - array of traces, one for each a2center; the length of each trace must be the same as the number of columns in the input image
  • offset (float) - offset of the first row in 'image' from the beginning of the data block in the original file, needed for trace
  • shifta2 (float) - offset of the row from nominal (from shifta2 keyword)
  • imset (int) - number of the current image set (keyword EXTVER)
  • order (int) - polynomial order
  • subdiv (int) - number of subpixels per input pixel
  • psf_width (float) - width of PSF for convolution (e.g. 1.3);
  • subsampled (string, or None) - name of the output file with the subsampled image
  • convolved (string, or None) - name of the output file with the convolved image
Returns: tuple
the image and error arrays (to replace the input img and errimg)

kd_resampling(img, errimg, original_nrows, nrows, ncols, rows, a2center, a2displ, offset, shifta2)

source code 

Apply Kris Davidson's resampling method.

Parameters:
  • img (array) - SCI image array (could be a subset of full image)
  • errimg (array) - ERR image array (could be a subset of full image)
  • original_nrows (int) - number of image lines (NAXIS2) in input image
  • nrows (int) - number of image lines in subset
  • ncols (int) - number of image columns (NAXIS1)
  • rows (tuple) - tuple giving the slice of rows to process
  • a2center (array) - 1-D array of Y locations
  • a2displ (array) - array of traces, one for each a2center; the length of each trace must be the same as the number of columns in the input image
  • offset (float) - offset of the first row in 'image' from the beginning of the data block in the original file, needed for trace
  • shifta2 (float) - offset of the row from nominal (from shifta2 keyword)
Returns: tuple
the image and error arrays (to replace the input img and errimg)

kd_apply_trace(image, a2center, a2displ, offset=0.0, shifta2=0.0)

source code 

Kris Davidson's resampling algorithm, following the trace.

Parameters:
  • image (array) - input 2-D image array
  • a2center (array) - array of Y locations
  • a2displ (array) - array of traces, one for each a2center; the length of each trace must be the same as the number of columns in 'image'
  • offset (float) - offset of the first row in 'image' from the beginning of the data block in the original file, needed for trace
  • shifta2 (float) - offset of the row from nominal (from shifta2 keyword)
Returns: array
2-D array containing the resampled image

stis_psf(x, a)

source code 

Evaluate the cross-dispersion PSF at x.

Parameters:
  • x (float) - offset in pixels from the center of the profile
  • a (float) - a measure of the width of the PSF
Returns: float
the PSF evaluated at x

apply_trace(image, a2center, a2displ, subdiv, offset=0.0, shifta2=0.0, extname='SCI')

source code 
Add together 'subdiv' rows of 'image', following the trace.

@param image: input 2-D image array, oversampled by 'subdiv' in axis 0
@type image: array

@param a2center: 1-D array of Y locations
@type a2center: array

@param a2displ: array of traces, one for each a2center; the length of each
    trace must be the same as the number of columns in the input image
@type a2displ: array

@param subdiv: number of rows to add together
@type subdiv: int

@param offset: offset of the first row in 'image' from the beginning of
    the data block in the original file, needed for trace
@type offset: float

@param shifta2: offset of the row from nominal (from shifta2 keyword)
@type shifta2: float

@param extname: which type of extension (SCI, ERR, DQ)?
@type extname: string

@return: resampled 2-D image array
@rtype: array

The function value is a 2-D array containing the resampled image.
This is binned by subdiv in Y (axis 0), after shifting by trace
(multiplied by subdiv).

For extname = "ERR" the result differs in these ways:
(1) fractions of pixels at the endpoints of the extraction region
    are not included
(2) the values are combined as the average of the sum of the squares

For extname = "DQ" the result differs in these ways:
(1) the output is type int16
(2) the output values are nominally the same as the input, while
    for SCI the output are subdiv times larger than the input
(3) fractions of pixels at the endpoints of the extraction region
    are not included
(4) the values are combined via bitwise OR rather than an average or sum

extract(image, locn, subdiv)

source code 

Add together 'subdiv' rows of 'image', centered on 'locn'.

Parameters:
  • image (array) - input array, oversampled by 'subdiv' in axis 0
  • locn (array) - a 1-D array giving the location at which to extract; an integer value corresponds to the center of the pixel. The length must be the same as the number of columns in the input image.
  • subdiv (int) - number of rows to add together
Returns: array
a 1-D array containing the extracted row

extract_err(image, locn, subdiv)

source code 

Average 'subdiv' rows of 'image', centered on 'locn'.

Parameters:
  • image (array) - input array, oversampled by 'subdiv' in axis 0
  • locn (array) - a 1-D array giving the location at which to extract; an integer value corresponds to the center of the pixel
  • subdiv (int) - number of rows to add together
Returns: array

This takes the square root of the average of the squares, intended to be used for interpolating the ERR array. Fractions of pixels at the upper and lower edges are excluded.

a 1-D array containing the extracted row

extract_i16(image, locn, subdiv)

source code 

Bitwise OR 'subdiv' rows of 'image', centered on 'locn'.

Parameters:
  • image (array) - input array, oversampled by 'subdiv' in axis 0
  • locn (array) - a 1-D array giving the location at which to extract; an integer value corresponds to the center of the pixel
  • subdiv (int) - number of rows to add together
Returns: array
a 1-D array containing the extracted row

interpolate_trace(a2center, a2displ, y, length)

source code 

Interpolate within the array of traces, and return a trace.

Parameters:
  • a2center (array) - array of Y locations
  • a2displ (array) - array of traces, one trace for each element of a2center
  • y (float) - Y location on the detector
  • length (int) - length of a trace; needed only if traces is empty

trace_name(trace, phdr)

source code 

Return the 1dt table name or array.

Parameters:
  • trace (string or array, or None) - if trace is None the header keyword SPTRCTAB will be gotten from phdr; else if this is a string it should be the name of a trace file (possibly using an environment variable); otherwise, it should be a trace, in which case it will be returned unchanged
  • phdr (pyfits Header object) - primary header, used only if trace is None
Returns: string or array
name of a trace file (with environment variable expanded), or an actual trace array

get_trace(tracefile, phdr, hdr)

source code 

Read 1-D traces from the 1dt table (sptrctab).

Parameters:
  • tracefile (string or array) - either a trace array or the name of a FITS 1dt table
  • phdr (pyfits Header object) - primary header of input file
  • hdr (pyfits Header object) - extension header of input image (for binning info and time of exposure)
Returns: tuple of two arrays

If 'tracefile' is already a trace array, it will just be returned, together with an arbitrary Y location of 0 (because that will always be within the image).

opt_elem and cenwave are criteria for selecting the relevant rows from the 1dt table. There will normally be several rows that match, and they should have different values of the Y location; the output list will be sorted on Y location.

a pair of arrays, one is the Y location at the middle column, and the other is an array of trace arrays

bin_traces(a2displ, binaxis1, ltv)

source code 

bin the traces by the factor binaxis1

Parameters:
  • a2displ (array) - an array of one or more arrays of Y displacements (traces)
  • binaxis1 (int) - binning factor in the dispersion axis
  • ltv (float) - offset in the dispersion axis (one indexing)
Returns: array
an array of traces (a2displ), but with the trace arrays binned and shorter by the factor binaxis1

polynomial(x, y, z, n)

source code 

used for interpolation

Parameters:
  • x (array of float64) - the integer values from 0 through n-1 inclusive (but float64)
  • y (array of float64) - a 2-D array, axis 0 of length n
  • z (float) - n / 2.
  • n (int) - 1 + order of polynomial fit