wx2d¶
- stistools.wx2d.apply_trace(image, a2center, a2displ, subdiv, offset=0.0, shifta2=0.0, extname='SCI')¶
Add together 'subdiv' rows of 'image', following the trace.
- Parameters:
- image: ndarray
input 2-D image array, oversampled by 'subdiv' in axis 0
- a2center: ndarray
1-D array of Y locations
- a2displ: ndarray
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
- subdiv: int
number of rows to add together
- 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)
- extname: str
which type of extension (SCI, ERR, DQ)?
- Returns:
- x2d: ndarray
resampled 2-D image array
Notes
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:
fractions of pixels at the endpoints of the extraction region are not included
the values are combined as the average of the sum of the squares
For extname = "DQ" the result differs in these ways:
the output is type int16
the output values are nominally the same as the input, while for SCI the output are subdiv times larger than the input
fractions of pixels at the endpoints of the extraction region are not included
the values are combined via bitwise OR rather than an average or sum
- stistools.wx2d.bin_traces(a2displ, binaxis1, ltv)¶
bin the traces by the factor binaxis1
- Parameters:
- a2displ: ndarray
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:
- a2displ: ndarray
an array of traces (a2displ), but with the trace arrays binned and shorter by the factor binaxis1
- stistools.wx2d.extract(image, locn, subdiv)¶
Add together 'subdiv' rows of 'image', centered on 'locn'.
- Parameters:
- image: ndarray
input array, oversampled by 'subdiv' in axis 0
- locn: ndarray
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:
- spec: ndarray
a 1-D array containing the extracted row
- stistools.wx2d.extract_err(image, locn, subdiv)¶
Average 'subdiv' rows of 'image', centered on 'locn'.
- Parameters:
- image: ndarray
input array, oversampled by 'subdiv' in axis 0
- locn: ndarray
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:
- spec: ndarray
a 1-D array containing the extracted row
Notes
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.
- stistools.wx2d.extract_i16(image, locn, subdiv)¶
Bitwise OR 'subdiv' rows of 'image', centered on 'locn'.
- Parameters:
- image: ndarray
input array, oversampled by 'subdiv' in axis 0
- locn: ndarray
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:
- spec: ndarray
a 1-D array containing the extracted row
- stistools.wx2d.get_trace(tracefile, phdr, hdr)¶
Read 1-D traces from the 1dt table (sptrctab).
- Parameters:
- tracefile: str or array
either a trace array or the name of a FITS 1dt table
- phdr: fits Header object
primary header of input file
- hdr: fits Header object
extension header of input image (for binning info and time of exposure)
- Returns:
- trace_arrays: tuple of 2 arrays
a pair of arrays, one is the Y location at the middle column, and the other is an array of trace arrays
Notes
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.
- stistools.wx2d.interpolate_trace(a2center, a2displ, y, length)¶
Interpolate within the array of traces, and return a trace.
- Parameters:
- a2center: ndarray
array of Y locations
- a2displ: ndarray
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
- stistools.wx2d.inv_avg_interp(order, image)¶
- stistools.wx2d.inv_haar(image)¶
- stistools.wx2d.kd_apply_trace(image, a2center, a2displ, offset=0.0, shifta2=0.0)¶
Kris Davidson's resampling algorithm, following the trace.
- Parameters:
- image: ndarray
input 2-D image array
- a2center: ndarray
array of Y locations
- a2displ: ndarray
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:
- x2d: ndarray
2-D array containing the resampled image
- stistools.wx2d.kd_resampling(img, errimg, original_nrows, nrows, ncols, rows, a2center, a2displ, offset, shifta2)¶
Apply Kris Davidson's resampling method.
- Parameters:
- img: ndarray
SCI image array (could be a subset of full image)
- errimg: ndarray
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: ndarray
1-D array of Y locations
- a2displ: ndarray
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:
- img_arr: tuple
the image and error arrays (to replace the input img and errimg)
- stistools.wx2d.polynomial(x, y, z, n)¶
used for interpolation
- Parameters:
- x: ndarray
the integer values from 0 through n-1 inclusive (but float64)
- y: ndarray
a 2-D array, axis 0 of length n
- z: float
n / 2.
- n: int
1 + order of polynomial fit
- stistools.wx2d.stis_psf(x, a)¶
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:
- val: float
the PSF evaluated at x
- stistools.wx2d.trace_name(trace, phdr)¶
Return the 1dt table name or array.
- Parameters:
- trace: str, array, or None
if trace is None the header keyword SPTRCTAB will be gotten from phdr; else if this is a str 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: fits Header object
primary header, used only if trace is None
- Returns:
- tracefile: str or array
name of a trace file (with environment variable expanded), or an actual trace array
- stistools.wx2d.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.
- Parameters:
- hdu: fits header/data unit object
header/data unit for a SCI extension
- img: ndarray
SCI image array (could be a subset of full image)
- errimg: ndarray
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: ndarray
1-D array of Y locations
- a2displ: ndarray
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: str or None
name of the output file with the subsampled image
- convolved: str or None
name of the output file with the convolved image
- Returns:
- img_arr: tuple of ndarrays
the image and error arrays (to replace the input img and errimg)
- stistools.wx2d.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.
- Parameters:
- input: str
name of input file containing an image set
- output: str
name of the output file
- wavelengths: str, optional
name of the output file for wavelengths
- helcorr: str
specify 'perform' or 'omit' to override header keyword
- algorithm: {'wavelet', 'kd'}
algorithm to use in resampling the input
- trace: str or array, or None
trace array, or name of FITS table containing trace(s)
- order: int [Default: 7]
polynomial order (an odd number, e.g. 5 or 7)
- subdiv: int [Default: 8]
number of subpixels (a power of 2, e.g. 8 or 16)
- psf_width: float [Default: 0.]
width of PSF for convolution (e.g. 1.3); 0 means no convolution
- rows: tuple, optional [Default: 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: str, optional
name of the output file with the subsampled image
- convolved: str, optional
name of the output file with the convolved image
- stistools.wx2d.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).
- Parameters:
- ft: HDUList
Fits HDUList object for the input file.
- imset: int
one-indexed image set number
- output: str
name of the output file
- wavelengths: str or None
name of the output file for wavelengths
- helcorr: {'perform', 'omit'}
specify "perform" or "omit" to override header keyword
- algorithm: {'wavelet', 'kd'}
algorithm to use to process input
- tracefile: str 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: str or None
name of the output file with the subsampled image
- convolved: str or None
name of the output file with the convolved image