reconstruct_ifu – Reconstruct the IFU image

Reconstruct the IFU

exception pyhetdex.het.reconstruct_ifu.ReconstructError[source]

Bases: Exception

Generic reconstruction error

exception pyhetdex.het.reconstruct_ifu.ReconstructIOError[source]

Bases: pyhetdex.het.reconstruct_ifu.ReconstructError, OSError

Error when the name and/or number fiber extracted file names is not correct

exception pyhetdex.het.reconstruct_ifu.ReconstructIndexError[source]

Bases: pyhetdex.het.reconstruct_ifu.ReconstructError, IndexError

Error for miss-matching the number of fibers in the ifu center files and the fiber extracted ones

exception pyhetdex.het.reconstruct_ifu.ReconstructValueError[source]

Bases: pyhetdex.het.reconstruct_ifu.ReconstructError, ValueError

Errors for wrong combinations of input parameters in ReconstructedIFU or from_files()

class pyhetdex.het.reconstruct_ifu.QuickReconstructedIFU(ifu_center, dist_l=None, dist_r=None, pixscale=0.25)[source]

Bases: object

Quick reconstructed IFU head image from a set of frames given the ifu_center and some reference distortion files.

Parameters:
ifu_center : instance of IFUCenter

fiber number to fiber position mapping

files : string

Basefilename of the image to be reconstructed, or a tuple of three images to reconstruct a complete dither.

dist_l, dist_r : string

Distortion file for the left and right spectrograph; at least one of them must be provided

pixscale : float, optional

pixel scale

Raises:
ReconstructValueError

if an empty dither is passed and fextract is None

ReconstructIOError

if the number and/or number of fiber extracted frames is not correct; raised by _fedict()

ReconstructIndexError

if the number of fibers from the fiber extracted files and from the ifu center files do not match; raised by _reconstruct()

Attributes:
ifu_center : IFUCenter

parsed ifu_center file

dists : dict

distortion files for 'L' and 'R'

dx, dy : tuples

relative shifts of the dithers

pscale : float

Pixel scale

img : 2d numpy array

reconstructed image

dmap : dict of dicts

for each spectrograph, map a fiber number with its y value

_create_dist_map()[source]

Load the distortion into dmap

_create_dxdy()[source]

Precompute the dx and dy shifts

_create_empty_image()[source]

Find the number of pixels x and y and create empty images

_get_overscan(img, biassec)[source]

Extract the sigma clipped mean of the overscan region

Parameters:
img : instance of numpy.array

Input image data

biassec : list

List or tuple with the ranges of the bias section. Use :func:_section_to_list to convert the header BIASSEC keyword to a python list

_load_dists(dist_l, dist_r)[source]

Load the distortion files into dists

Parameters:
dist_l, dist_r : string

Distortion file for the left and right spectrograph; at least one of them must be provided

_load_ifu_center(ifu_center)[source]

Load the IFUcen file

Parameters:
ifu_center : instance of IFUCenter

fiber number to fiber position mapping

_min_max()[source]

Compute the minimum and max x and y positions from the ifu center file and save them in maxx, minx, maxy, miny.

_section_to_list(sec)[source]

Convert a header section string of the form [x1:x2,y1:y2] to a list of integers

Parameters:
sec : str

The header section string

reconstruct(files, subtract_overscan=True, do_not_scale_image_data=False)[source]

Read the files and create a reconstructed image.

Parameters:
files : list

name of the files to use

subtract_overscan : bool

If the overscan region is still present in the image, subtract the bias level, calculated from the overscan region of the image.

do_not_scale_image_data : bool

If True, image data is not scaled using BSCALE/BZERO values when read.

Returns:
img : nd-array

reconstructed image; it is also stored in the img attribute

write(filename)[source]

Write the reconstructed image to file filename as using the fits format

Parameters:
filename : string

name of the output fits file

pscale

Pixel scale

Warning

changing the pixel scale with invalidate the reconstructed image

class pyhetdex.het.reconstruct_ifu.ReconstructedIFU(ifu_center, dither, fextract=None, fe_prefix='')[source]

Bases: object

Reconstructed IFU head image from the fiber extracted frames given the ifu_center and the dither.

Parameters:
ifu_center : instance of IFUCenter

fiber number to fiber position mapping

dither : instance child of _BaseDither

dither relative position, illumination, image quality

fextract : None or list of fits files, optional
  • if None the list of files is inferred from dither.basename;
  • if not None must have ndither x nchannels elements. The channel name and dither number are extracted from the CCDPOS and the DITHER header keywords
fe_prefix : string, optional

when getting the names from the dither file, prepend fe_prefix to the basename

Raises:
ReconstructValueError

if an empty dither is passed and fextract is None

ReconstructIOError

if the number and/or number of fiber extracted frames is not correct; raised by _fedict()

ReconstructIndexError

if the number of fibers from the fiber extracted files and from the ifu center files do not match; raised by _reconstruct()

Attributes:
ifu_center
dither
x, y : 1-dimensional arrays

x and y position of the fibers

flux : list of 2-dimensional arrays

each element is the content of one fiber extracted file

header : list of dictionaries

each element contains the CRVAL1 and CDELT1 keywords :value pairs from the headers of the fiber extracted files; used to determine the wavelength range in reconstruct()

_fedict(fextract)[source]

Organize the fiber extracted file names into a dictionary

Parameters:
fextract : None or list of string

If None get the file names from the dither, otherwise from the fextract list

Returns:
dfextract : dict

dictionary of fiber extracted frames

_reconstruct(dfextract)[source]

Read the fiber extracted files and creates a set of three lists for x, y and flux.

Parameters:
dfextract : dictionary

name of the fiber extracted file

classmethod from_files(ifu_center_file, dither_file=None, fextract=None, fe_prefix='')[source]

Read and parse the file

Parameters:
ifu_center_file : string

file containing the fiber number to fiber position mapping

dither_file : string, optional

file containing the dither relative position. If not given, a singe dither is assumed

fextract : None or list of fits files, optional

if None the list of files is inferred from the second column of the dither_file; if not None must have ndither x nchannels elements. The channel name and dither number are extracted from the CCDPOS and the DITHER header keywords

fe_prefix : string, optional

when getting the names from the dither file, prepend fe_prefix to the basename

Raises:
ReconstructValueError

if both dither_file and fextract are None

ReconstructValueError, ReconstructIOError

as in ReconstructedIFU

Notes

if dither_file is None, fextract must contain a number of files equal to the number of channels (2)

reconstruct(wmin=None, wmax=None)[source]

Returns the reconstructed IFU with the flux computed between [wmin, wmax]

Parameters:
wmin, wmax : float, optional

min and max wavelength to use. If None: use the min and/or max from the file

Returns:
x, y : 1d arrays

x and y position of the fibers

flux : 1d array

flux of the fibers within wmin and wmax

xpos(channel, dither)[source]

get the position for the x dither in channel

Parameters:
channel : string

name of the channel [L, R]

dither : string

name of the dither [D1, D2, ..]

Returns:
ndarray

x position of the fibers for the given channel and dither

ypos(channel, dither)[source]

get the position for the y dither in channel

Parameters:
channel : string

name of the channel [L, R]

dither : string

name of the dither [D1, D2, ..]

Returns:
ndarray

y position of the fibers for the given channel and dither

pyhetdex.het.reconstruct_ifu.argument_parser(argv=None)[source]

Parse the command line

pyhetdex.het.reconstruct_ifu.create_quick_reconstruction(argv=None)[source]

Entry point for the executable running the quick reconstruction of the IFU reconstruction image

Parameters:
argv : list of strings

if not provided sys.argv is used