Pywifes

Welcome to the documentation for the Pywifes module, which contains the core functions for data processing.

pywifes.pywifes.blockwise_mean_3D(A, S)

From https://stackoverflow.com/questions/37532184/downsize-3d-matrix-by-averaging-in-numpy-or-alike/73078468

A is the 3D input array S is the blocksize on which averaging is to be performed (list or 1D array)

pywifes.pywifes.calib_to_half_frame(obs_metadata, temp_data_dir, to_taros=False)

Convert calibration files to half-frame format.

This function takes the observation metadata and temporary data directory as input. It converts the calibration files to half-frame format by cutting them in half. The calibration types that can be converted are domeflat, twiflat, wire, and arc. The converted files are saved with a prefix ‘cut_’ added to their names.

Parameters:
  • obs_metadata (dict) – The observation metadata containing calibration file information.

  • temp_data_dir (str) – The temporary data directory where the calibration files are located.

  • to_taros (bool, optional) – Whether the reference image (science, standard, or arc) needs the TAROS-style top half or the Automation-style middle half.

Returns:

The updated observation metadata with the converted calibration file names.

Return type:

dict

pywifes.pywifes.cut_fits_to_half_frame(inimg_path, outimg_prefix='cut_', to_taros=False)

Cuts a FITS file to half-frame size and saves the output with a specified prefix.

Parameters:
  • inimg_path (str) – Path to the input FITS file.

  • outimg_prefix (str, optional) – Prefix for the output FITS file. Default is “cut_”.

  • to_taros (bool, optional) – Whether to extract the TAROS-style top half or the Automation-style middle half.

Return type:

None

Notes

This function performs the following steps:

  1. Opens the input FITS file.

  2. Extracts the primary HDU (Header/Data Unit).

  3. Considers binning specified in the ‘CCDSUM’ header.

  4. Cuts the data to a section defined by the specified coordinates.

  5. Updates the ‘DETSEC’ keyword in the header.

  6. Writes the cut data to a new FITS file with the specified prefix.

pywifes.pywifes.derive_wifes_wire_solution(inimg, out_file, bin_x=None, bin_y=None, fit_zones=[16, 26, 54, 70], flux_threshold=0.001, wire_polydeg=1, xlims='default', interactive_plot=False, plot=True, plot_dir='.', save_prefix='wire_fit_params', debug=False)

Trace the wire image to determine position of centre of each slitlet.

Parameters:
  • inimg (str) – Path to the input wire image.

  • out_file (str) – Path to the output wire solution.

  • bin_x (int, optional) – Binning factor in the x-direction. If not specified, it will be read from the header.

  • bin_y (int, optional) – Binning factor in the y-direction. If not specified, it will be read from the header.

  • fit_zones (list, optional) – List of per-slitlet y-axis region limits to define background against which to locate wire. Unbinned pixels. Default is [16, 26, 54, 70].

  • flux_threshold (float, optional) – Minimum flux difference for wire relative to background. Default value assumes a superwire scaled by “percentileN”. Default is 0.001.

  • wire_polydeg (int, optional) – Degree of polynomial in x-direction to fit. Default is 1.

  • xlims (str or list, optional) – Either “default” or a 2-element list defining the x-axis range for the wire fitting. Default is “default”.

  • interactive_plot (bool, optional) – Whether to interrupt processing to provide interactive plot to user. Default is False.

  • plot (bool, optional) – Whether to output a diagnostic plot. Default is True.

  • plot_dir (str, optional) – Directory for output of plot (if requested). Default is ‘.’.

  • save_prefix (str, optional) – Prefix for plot (if requested). Default is ‘wire_fit_params’.

  • debug (bool, optional) – Whether to report the parameters used in this function call. Default is False.

Return type:

None

pywifes.pywifes.determine_detector_epoch(inimg, data_hdu=0)

Determine the observing epoch of the image, which defines detector properties like overscan regions, gain, and read noise.

Parameters:
  • inimg (str) – The path to the input image.

  • data_hdu (int, optional) – The HDU index for the data extension in the input images. Default is 0.

Returns:

  • epoch (str) – The code for the observing epoch.

  • None

pywifes.pywifes.fit_wifes_interslit_bias(inimg, data_hdu=0, slitlet_def_file=None, method='row_med', x_polydeg=1, y_polydeg=1, interactive_plot=False)

Inter-slitlet bias determination.

Parameters:
  • inimg (str) – The path to the input image.

  • data_hdu (int, optional) – The HDU index for the data extension in the input images. Default is 0.

  • slitlet_def_file (str, optional) – The path to the pickle file defining the slitlet boundaries. Default is None.

  • method (str, optional) – Method to fit interslit bias level. Options are “row_med” (per-column mean of points within 20 counts of the column’s median), “surface” (fit 2D surface to bias level), “median” (median of the interslice regions from the entire frame). Default is “row_med”.

  • x_polydeg (int, optional) – For method=”surface”, polynomial degree of the fit in the x-axis. Default is 1.

  • y_polydeg (int, optional) – For method=”surface”, polynomial degree of the fit in the y-axis. Default is 1.

  • interactive_plot (bool, optional) – Whether to interrupt processing to provide interactive plot to user. Default is False.

Return type:

Numpy ndarray of the bias level.

pywifes.pywifes.generate_wifes_3dcube(inimg, outimg, halfframe=False, taros=False, nan_bad_pixels=False, debug=False)

Convert multi-extension FITS datacube into a single three-dimensional FITS image.

Parameters:
  • inimg (str) – Path to the input image.

  • outimg (str) – Path to the output image.

  • halfframe (bool, optional) – Whether the input image uses stellar (half-frame) readout mode. Default is False.

  • taros (bool, optional) – Whether the input image was acquired with Taros (prior to the Automated 2.3m operations). Default is False.

  • nan_bad_pixels (bool, optional) – Set FLUX extension to NaN where DQ extension > 0. Default is False.

  • debug (bool, optional) – Whether to report the parameters used in this function call. Default is False.

Return type:

None

pywifes.pywifes.generate_wifes_bias_fit(bias_img, outimg, method='row_med', data_hdu=0, plot=True, plot_dir='.', save_prefix='bias', verbose=False)

Fit the bias level.

Parameters:
  • bias_img (str) – The path to the input bias image.

  • outimg (str) – The path to the output bias level image.

  • method (str, optional) – Method to fit bias level. Options are “row_med” (per-column mean of points within 20 counts of the column’s median), “fit” (collapse along y-axis and fit a parametrised shape). Default is “row_med”.

  • data_hdu (int, optional) – The HDU index for the data extension in the input images. Default is 0.

  • plot (bool, optional) – Whether to output a diagnostic plot. Default is False.

  • plot_dir (str, optional) – Directory for output of plot (if requested). Default is ‘.’.

  • save_prefix (str, optional) – Prefix for plot (if requested). Default is ‘bias’.

  • verbose (bool, optional) – If method=”fit”, whether to report progress of MPFit. Default is False.

Return type:

None.

pywifes.pywifes.generate_wifes_cube(inimg, outimg, wire_fn, wsol_fn, wmin_set=None, wmax_set=None, dw_set=None, wavelength_ref='AIR', wave_native=False, bin_x=None, bin_y=None, ny_orig=76, offset_orig=2, verbose=True, adr=False, subsample=1, multithread=False, max_processes=-1, print_progress=False, debug=False)

Prepare data cube for assembly by unifying wavelength solution and slitlet centering (and optionally resampling flux to correct atmospheric differential refraction). The output cube remains as a multi-extension FITS file with one extension per slitlet.

Parameters:
  • inimg (str) – Path to the input image.

  • outimg (str) – Path to the output image.

  • wire_fn (str) – Path to the wire solution.

  • wsol_fn (str) – Path to the wavelength solution.

  • wmin_set (float, optional) – Minimum wavelength of output cube. Reverts to minimum in data if wmin_set is smaller or None. Default is None.

  • wmax_set (float, optional) – Maximum wavelength of output cube. Reverts to maximum in data if wmax_set is larger or None. Default is None.

  • dw_set (float, optional) – Wavelength step in output cube. Reverts to mean of per-slitlet mean wavelength steps if dw_set is None. Default is None.

  • wavelength_ref (str, optional) – Wavelength reference for output cube. Options are “AIR”, “VACUUM”. Default is “AIR”.

  • wave_native (bool, optional) – Override wmin_set, wmax_set, dw_set and use native dispersion of central slitlet. N.B.: Prevents clean splicing of blue/red cubes and spectra. Default is False.

  • bin_x (int, optional) – Binning factor in the x-direction. If not specified, it will be read from the header.

  • bin_y (int, optional) – Binning factor in the y-direction. If not specified, it will be read from the header.

  • ny_orig (int, optional) – Number of unbinned y-axis pixels in each slitlet. Default is 76.

  • offset_orig (int, optional) – Number of (unbinned) y-axis pixels that the wire is offset from the field centre. Default is 2.

  • verbose (bool, optional) – Whether to report additional diagnostic info. Default is True.

  • adr (bool, optional) – Apply atmospheric differential refraction correction. Default is False.

  • subsample (int, optional) – Divide each spatial dimension into “subsample” components. Minimises effects of intergerisation of pixel shifts, but increases processing time by subsample^2. Default is 1.

  • multithread (bool, optional) – Run step using “multiprocessing” module. Default is False.

  • max_processes (int, optional) – Number of simultaneous processes allowed. Non-positive values default to os.cpu_count(). Default is -1.

  • print_progress (bool, optional) – Write interpolation progress to screen/log. Default is False.

  • debug (bool, optional) – Whether to report the parameters used in this function call. Default is False.

Return type:

None

pywifes.pywifes.imarith(inimg1, operator, inimg2, outimg, data_hdu=0)

Performs arithmetic operations between two images.

Parameters:
  • inimg1 (str) – The path to the first input image.

  • operator (str) – The operator to be used for combining the images. Options: ‘+’, ‘-’, ‘*’, ‘/’.

  • inimg2 (str) – The path to the second input image.

  • outimg (str) – The path to the output image.

  • data_hdu (int, optional) – The HDU index for the data extension in the input images. Default is 0.

Return type:

None

pywifes.pywifes.imarith_float(inimg1, operator, scale, outimg, data_hdu=0)

Performs arithmetic operations between two floating point images.

Parameters:
  • inimg1 (str) – The path to the first input image.

  • operator (str) – The operator to be used for combining the images. Options: ‘+’, ‘-’, ‘*’, ‘/’.

  • inimg2 (str) – The path to the second input image.

  • outimg (str) – The path to the output image.

  • data_hdu (int, optional) – The HDU index for the data extension in the input images. Default is 0.

Return type:

None

pywifes.pywifes.imarith_float_mef(inimg1, operator, scale, outimg)

Performs arithmetic operations between two floating point multi-extension images.

Parameters:
  • inimg1 (str) – The path to the first input image.

  • operator (str) – The operator to be used for combining the images. Options: ‘+’, ‘-’, ‘*’, ‘/’.

  • inimg2 (str) – The path to the second input image.

  • outimg (str) – The path to the output image.

Return type:

None

pywifes.pywifes.imarith_mef(inimg1, operator, inimg2, outimg)

Performs arithmetic operations between two multi-extension images.

Parameters:
  • inimg1 (str) – The path to the first input image.

  • operator (str) – The operator to be used for combining the images. Options: ‘+’, ‘-’, ‘*’, ‘/’.

  • inimg2 (str) – The path to the second input image.

  • outimg (str) – The path to the output image.

Return type:

None

pywifes.pywifes.imcombine(inimg_list, outimg, method='median', nonzero_thresh=100.0, scale=None, data_hdu=0, kwstring=None, commstring=None, outvarimg=None, sregion=None, plot=False, plot_dir='.', save_prefix='imcombine_inputs', interactive_plot=False, debug=False)

Combine multiple images into a single image using a specified method.

Parameters:
  • inimg_list (list) – A list of input image paths.

  • outimg (str) – The path to the output image.

  • method (str, optional) – The method ‘median’, ‘sum’, or ‘mean’ to be used for combining the images. Default is ‘median’.

  • scale (str, optional) – The scaling method to be used, ‘median’, ‘median_nonzero’, ‘exptime’ or None. Default is None.

  • data_hdu (int, optional) – The HDU index for the data extension in the input images. Default is 0.

  • kwstring (str, optional) – Header keyword to add to output as “PYW” + kwstring, containing number of inputs. Default: None.

  • commstring (str, optional) – Header keyword comment to add to output. Default: None.

  • outvarimg (str, optional) – Filename of variance image to output (if defined). Default: None.

  • sregion (list, optional) – List defining image x-axis region in which to compute scaling (if a scaling method is defined). Example: [1000, 3000]. Default: None.

  • plot (bool, optional) – Whether to output a diagnostic plot. Default: False.

  • plot_dir (str, optional) – Directory for output of plot (if requested). Default: ‘.’.

  • save_prefix (str, optional) – Prefix for plot (if requested). Default: ‘imcombine_inputs’.

  • interactive_plot (bool, optional) – Whether to interrupt processing to provide interactive plot to user. Default: False.

  • debug (bool, optional) – Whether to report the parameters used in this function call. Default: False.

Return type:

None

pywifes.pywifes.imcombine_mef(inimg_list, outimg, scale=None, method='median', debug=False)

Combine multiple images into a single image using a specified method.

Parameters:
  • inimg_list (list) – A list of input image paths.

  • outimg (str) – The path to the output image.

  • scale (str, optional) – The scaling method to be used. Options are ‘exptime’, ‘per_slice_median’. Default: None.

  • method (str, optional) – The method to be used for combining the images. Options are ‘median’, ‘sum’, ‘nansafesum’. Default: ‘median’.

  • debug (bool, optional) – Whether to report the parameters used in this function call. Default: False.

Return type:

None

pywifes.pywifes.imcopy(inimg, outimg)

Copy one image to a new filename.

Parameters:
  • inimg (str) – The path to the input image.

  • outimg (str) – The path to the output image.

Return type:

None

pywifes.pywifes.interslice_cleanup(input_fn, output_fn, slitlet_def_file=None, bin_x=None, bin_y=None, data_hdu=0, offset=0.4, buffer=0, radius=10, nsig_lim=5.0, verbose=False, plot=True, plot_dir='.', save_prefix='cleanup_', method='2D', debug=False, interactive_plot=False)

Uses the dark interslice regions of the detector to interpolate the scattered light over the entire detector.

Note that setting nsig_lim to 3 (as it historically has been) can cause problems by sigma clipping the scattered light, not just cosmic rays. For a halframe detector with y binning 2, there are 1024 x 4096 pixels. With sigma values as follows, this is how many pixels lie above: - 3.0 sigma (99.73%): ~11,323 px - 4.0 sigma (99.994%): ~265 px - 4.5 sigma (99.9993%): ~28 px - 5.0 sigma (99.99994%): ~2 px

(This however assumes a Gaussian distribution, which isn’t at all the case but still useful as a guide/metric.)

Parameters:
  • input_fn (str) – The path to the input flatfield image.

  • output_fn (str) – The path to the output file with slitlet positions.

  • slitlet_def_file (str, optional) – Path to a file containing slitlet definitions. If not specified, baseline values will be used.

  • bin_x (int, optional) – If specified, override the CCD binning indicated in the header with this value for the x axis. Default is None.

  • bin_y (int, optional) – If specified, override the CCD binning indicated in the header with this value for the y axis. Default is None.

  • data_hdu (int, optional) – The HDU index for the data extension in the input images. Default is 0.

  • offset (float, optional) – Fraction of median whole-frame background level to add back to flat to avoid negative values. Default is 0.4.

  • buffer (int, optional) – Number of y-axis pixels on either side of each slitlet in which to avoid background fitting. Default is 0.

  • radius (float, optional) – Sigma for 2D Gaussian filtering (with “method” = “2D”). Equal in both axes. Default is 10.

  • nsig_lim (float, optional) – Clipping threshold in number of standard deviations above median. Computed independently for each slitlet. Default is 5.0.

  • verbose (bool, optional) – Whether to report progress. Default is False.

  • plot (bool, optional) – Whether to output a diagnostic plot. Default is True.

  • plot_dir (str, optional) – Directory for output of plot (if requested). Default is ‘.’.

  • save_prefix (str, optional) – Prefix for plot (if requested). Default is ‘cleanup_’.

  • method (str, optional) – Method to fit interslice region. Options are “2D” (fit 2D Gaussian-smoothed shape to interslice segments), “1D” (use median value of each cosmic-ray-filtered interslice segment). Default is “2D”.

  • debug (bool, optional) – Whether to report the parameters used in this function call. Default is False.

  • interactive_plot (bool, optional) – Whether to interrupt processing to provide interactive plot to user. Default is False.

Return type:

None

pywifes.pywifes.make_overscan_mask(dflat, omask, data_hdu=0, debug=False)

From a domeflat, get the slice y-axis locations from a median cut through the centre. Then use the mean of the illuminated and non-illuminated pixels to define a threshold. Rows above the threshold will be masked (value = 0) from the overscan calculation due to elevated counts in those rows. Note that the output FITS image has a single axis, so gets treated by many tools as having only an x-axis extent.

Parameters:
  • dflat (str) – The path to the input domeflat image.

  • omask (str) – The path to the output image mask.

  • data_hdu (int, optional) – The HDU index for the data extension in the input images. Default is 0.

Return type:

None

pywifes.pywifes.repair_bad_pix(inimg, outimg, arm, data_hdu=0, flat_littrow=False, interp_buffer=3, interactive_plot=False, verbose=False, debug=False)

Handle bad pixels. Performs immediate linear x-interpolation across bad pixels in calibration frames, but sets bad pixels to NaN for STANDARD, OBJECT, and SKY frames. The NaN pixels are interpolated across in same way after the VAR and DQ extensions are created, so that the affected pixels are flagged appropriately.

Parameters:
  • inimg (str) – The path to the input image.

  • outimg (str) – The path to the output image.

  • arm (str) – Either ‘blue’ or ‘red’.

  • data_hdu (int, optional) – The HDU index for the data extension in the input images. Default is 0.

  • flat_littrow (bool, optional) – Mask the Littrow ghosts in flats and skyflats. Applies linear interpolation, as with bad pixels in calibrations. Default is False.

  • interp_buffer (int, optional) – Number of additional pixels to median combine with the first on each x-axis edge of a masking region. Default is 3.

  • interactive_plot (bool, optional) – Whether to interrupt processing to provide interactive plot to user. Default is False.

  • verbose (bool) – Whether to report method applied (determined by IMAGETYP header keyword). Default is False.

  • debug (bool, optional) – Whether to report the parameters used in this function call. Default is False.

Return type:

None

pywifes.pywifes.save_wifes_interslit_bias(inimg, outimg, data_hdu=0, slitlet_def_file=None, method='surface', x_polydeg=1, y_polydeg=1, interactive_plot=False)

Save the inter-slitlet bias level.

Parameters:
  • inimg (str) – The path to the input image.

  • outimg (str) – The path to the output bias level image.

  • data_hdu (int, optional) – The HDU index for the data extension in the input images. Default is 0.

  • slitlet_def_file (str, optional) – The path to the pickle file defining the slitlet boundaries. Default is None.

  • method (str, optional) – Method to fit interslit bias level. Options are “row_med” (per-column mean of points within 20 counts of the column’s median), “surface” (fit 2D surface to bias level), “median” (median of the interslice regions from the entire frame). Default is “surface”.

  • x_polydeg (int, optional) – For method=”surface”, polynomial degree of the fit in the x-axis. Default is 1.

  • y_polydeg (int, optional) – For method=”surface”, polynomial degree of the fit in the y-axis. Default is 1.

  • interactive_plot (bool, optional) – Whether to interrupt processing to provide interactive plot to user. Default is False.

Return type:

None.

pywifes.pywifes.scaled_imarith_mef(inimg1, operator, inimg2, outimg, scale=None, arg_scaled='second')

Combine two images using a specified operator and a scaling factor.

Parameters:
  • inimg1 (str) – The path to the first input image.

  • operator (str) – The operator to be used for combining the images. Options are ‘+’, ‘-’, ‘*’, ‘/’.

  • inimg2 (str) – The path to the second input image.

  • outimg (str) – The path to the output image.

  • scale (float or str) – The scaling factor to be used. Options: ‘exptime’, a float value. Default: None.

  • arg_scaled (str, optional) – Which argument the scaling should be applied to. Options: “first”, “second”. Default: “second”

Returns:

This function does not return any value. It writes the combined image to the output file.

Return type:

None

pywifes.pywifes.single_centroid_prof_fit(y, x=None, ctr_guess=None, width_guess=None, return_width=False)

Fit a single Gaussian to a 1D profile to determine the centroid.

Parameters:
  • y (numpy.ndarray) – The 1D profile data.

  • x (numpy.ndarray, optional) – The x-axis data. Default is None.

  • ctr_guess (float, optional) – The initial guess for the centroid. Default is None.

  • width_guess (float, optional) – The initial guess for the width. Default is None.

  • return_width (bool, optional) – If True, the function returns the width of the Gaussian. Default is False.

Returns:

The centroid of the Gaussian.

Return type:

float

pywifes.pywifes.subtract_overscan(inimg, outimg, data_hdu=0, detector_regions=None, overscan_regions=None, science_regions=None, gain=None, rdnoise=None, omaskfile=None, omask_threshold=500.0, match_binning=None, interactive_plot=False, verbose=False, debug=False)

Subtract the overscan.

Parameters:
  • inimg (str) – The path to the input image.

  • outimg (str) – The path to the output image.

  • data_hdu (int, optional) – The HDU index for the data extension in the input images. Default is 0.

  • detector_regions (list, optional) – List of full detector [ymin, ymax, xmin, xmax] pixel coordinates in FITS (1-indexed) format. Default is None (to determine from epoch).

  • overscan_regions (list, optional) – List of overscan [ymin, ymax, xmin, xmax] pixel coordinates in FITS (1-indexed) format. Default is None (to determine from epoch).

  • science_regions (list, optional) – List of science [ymin, ymax, xmin, xmax] pixel coordinates in FITS (1-indexed) format. Default is None (to determine from epoch).

  • gain (float, optional) – CCD gain in e-/ADU. Default is None (to determine from epoch).

  • rdnoise (float, optional) – CCD readnoise in e-. Default is None (to determine from epoch).

  • omaskfile (str, optional) – The path to the maskfile defining the slice/interslice regions. Default is None.

  • omask_threshold (float, optional) – Threshold above which to mask pixels from overscan fit. Threshold is per-row mean ADU relative to row with lowest mean. Default is 500.

  • match_binning (str, optional) – If not None, will expand/contract binning to the specified ‘x y’ format.

  • interactive_plot (bool, optional) – Whether to interrupt processing to provide interactive plot to user. Default is False.

  • verbose (bool) – Whether to report when data has been checked for readout shifts. Default is False.

  • debug (bool, optional) – Whether to report the parameters used in this function call. Default is False.

Return type:

None

pywifes.pywifes.wifes_2dim_response(spec_inimg, spatial_inimg, outimg, wsol_fn=None, zero_var=True, plot=True, plot_dir='.', save_prefix='flat_response', polydeg=7, resp_min=0.0001, debug=False)

Generate response array by fitting dome and twilight flatfields with polynomials in log(count)-space. Operates separately on each slitlet.

Parameters:
  • spec_inimg (str) – The file path to the input domeflat image.

  • spatial_inimg (str) – The file path to the input twilight flat image.

  • outimg (str) – The file path to the output image.

  • wsol_fn (str, optional) – The file path to the wavelength solution. Default is None.

  • zero_var (bool, optional) – Whether to set the VAR extensions to zero in the output file. Default is True.

  • plot (bool, optional) – Whether to output a diagnostic plot. Default is True.

  • plot_dir (str, optional) – Directory for output of plot (if requested). Default is ‘.’.

  • save_prefix (str, optional) – Prefix for plot (if requested). Default is ‘flat_response’.

  • polydeg (int, optional) – Degree of polynomial to fit. Default is 7.

  • resp_min (float, optional) – Minimum response value in output file. Default is 1.0e-4.

  • debug (bool, optional) – Whether to report the parameters used in this function call. Default is False.

Return type:

None.

pywifes.pywifes.wifes_SG_response(spec_inimg, outimg, spatial_inimg=None, wsol_fn=None, zero_var=True, plot=True, plot_dir='.', save_prefix='flat_response', resp_min=0.0001, shape_fn=None, debug=False, interactive_plot=False)

Generate response array by fitting dome and twilight flatfields with Savitzky-Golay filter in log(count)-space. Operates separately on each slitlet.

Parameters:
  • spec_inimg (str) – The file path to the input domeflat image.

  • spatial_inimg (str) – The file path to the input twilight flat image.

  • outimg (str) – The file path to the output image.

  • wsol_fn (str, optional) – The file path to the wavelength solution. Default is None.

  • zero_var (bool, optional) – Whether to set the VAR extensions to zero in the output file. Default is True.

  • plot (bool, optional) – Whether to output a diagnostic plot. Default is True.

  • plot_dir (str, optional) – Directory for output of plot (if requested). Default is ‘.’.

  • save_prefix (str, optional) – Prefix for plot (if requested). Default is ‘flat_response’.

  • resp_min (float, optional) – Minimum response value in output file. Default is 1.0e-4.

  • shape_fn (str, optional) – If defined, outputs shape of central slice’s central pixel to aid later flux calibration to the given filename. Default is None.

  • debug (bool, optional) – Whether to report the parameters used in this function call. Default is False.

  • interactive_plot (bool, optional) – Whether to interrupt processing to provide interactive plot to user. Default is False.

Return type:

None.

pywifes.pywifes.wifes_bias_model(p, x, camera)

Generate bias model from parametrised fit. Model includes constant, linear term, and two exponentials (with an additional Gaussian term for the blue arm).

Parameters:
  • p (list or 1D array) – Parameter values of fit.

  • x (Numpy array) – Pixel number.

  • camera (str) – Label of camera/arm (“WiFeSRed” or not).

Return type:

Numpy ndarray of the bias model.

pywifes.pywifes.wifes_response_pixel(inimg, outimg, wsol_fn=None, debug=False)

Generate response array by dividing flatfield by the median along each axis. Operates separately on each slitlet.

Parameters:
  • inimg (str) – The file path to the input image.

  • outimg (str) – The file path to the output image.

  • wsol_fn (str, optional) – The file path to the wavelength solution. Default is None.

  • debug (bool, optional) – Whether to report the parameters used in this function call. Default is False.

Return type:

None.

pywifes.pywifes.wifes_slitlet_mef(inimg, outimg, data_hdu=0, bin_x=None, bin_y=None, slitlet_def_file=None, nan_method='interp', repl_val=0.0, debug=False)

Create multi-extension FITS file from a single input image.

Parameters:
  • inimg (str) – The path to the input image.

  • outimg (str) – The path to the output multi-extension image.

  • data_hdu (int, optional) – The HDU index for the data extension in the input images. Default is 0.

  • bin_x (int, optional) – If specified, override the CCD binning indicated in the header with this value for the x axis. Default is None.

  • bin_y (int, optional) – If specified, override the CCD binning indicated in the header with this value for the y axis. Default is None.

  • slitlet_def_file (str, optional) – Path to a file containing slitlet definitions. If not specified, baseline values will be used.

  • nan_method (str, optional) – Method to treat NaN pixels. Options are “interp” (apply linear interpolation in x-direction), “replace” (replace with constant value). Default is “interp”.

  • repl_val (float, optional) – Constant to replace NaN values with if “method” = “replace”. Default is 0.0.

  • debug (bool, optional) – Whether to report the parameters used in this function call. Default is False.

Return type:

None.

pywifes.pywifes.wifes_slitlet_mef_ns(inimg, outimg_obj, outimg_sky, data_hdu=0, bin_x=None, bin_y=None, nod_dy=80, slitlet_def_file=None, nan_method='interp', repl_val=0.0, debug=False)

Create multi-extension FITS files for object and sky data from a single input image.

Parameters:
  • inimg (str) – Path to the input FITS image.

  • outimg_obj (str) – Path to the output FITS file for object data.

  • outimg_sky (str) – Path to the output FITS file for sky data.

  • data_hdu (int, optional) – Index of the HDU containing the data in the input FITS image. Default is 0.

  • bin_x (int, optional) – Binning factor in the x-direction. If not specified, it will be read from the header.

  • bin_y (int, optional) – Binning factor in the y-direction. If not specified, it will be read from the header.

  • nod_dy (int, optional) – Offset in pixels between the object and sky slitlets in the y-direction. Default is 80.

  • slitlet_def_file (str, optional) – Path to a file containing slitlet definitions. If not specified, baseline values will be used.

  • nan_method (str, optional) – Method for handling bad (NaN) pixels. Options are ‘interp’, ‘replace’. Default: “interp”.

  • repl_val (float, optional) – If ‘nan_method’=’replace’, replace bad (NaN) pixels with the specified value. Default: 0.0.

  • debug (bool, optional) – Whether to report the parameters used in this function call. Default: False.

Return type:

None