qR3D: R3D it is a package for reducing IFS data, focused in fiber/based instruements like PMAS or INTEGRAL. It is actually written in perl/PDL, although its algorithms are easily transformed to C. It comprises the following scripts: peak_find.pl trace_peaks.pl trace_peaks_recursive.pl straight_light.pl extract_aper.pl extract_gauss_simple.pl extract_gauss_weight.pl extract_gauss.pl extract_gauss_external.pl rss2cube.pl rss2cube_pt.pl fiber_flat.pl fiber_trans_flat.pl Description: * fiber_flat.pl SKYFLAT.fits FIBERFLAT.fits Creates the fiber-to-fiber transmision frame (wavelength dependent) using an extracted skyflat. * fiber_trans_flat.pl SKYFLAT.fits FIBERFLAT.fits [NX_min] [NX_max] Create the wavelength independent fiber-to-fiber transmission frame, using an extracted skyflat, averaging the fiber-to-fiber transmission over a certain wavelength range. * peak_find.pl RAW.fits Spectral_axis[0/1] Coadd_width plot nplot nsearch DMIN IMIN(% of the MAX) OUTFILE Find the peaks of the spectra in the pseudo-list direction of the image. As a result it derives an ASCII file with the position of the peaks in the central spectral pixel. It requires as inputs: RAW.fits => The raw fitsfile with the spectra. Spectral_axis[0/1] => The axis of the spectral dispersion, 0=X, 1=Y. Coadd_width => The number of spectral pixels to coadd to look for the peak. plot [0/1] => Flag that allows to visualize the results. nplot => Number of subframes for plotting. nsearch => Number of pixels to compare with the possible maximun. DMIN => Minumun distance between adjacent peaks. IMIN => Mimumun limit of intensity (in fractions of the maximun), for looking for a peak. OUTFILE => Output file: e.g., peak_find.pl run35_00385b.fits 0 1 1 4 2 3.5 0.07 run35_00385b.peaks *trace_peaks.pl RAW.fits Spectral_axis[0/1] PEAKS_FILE x_width y_width plot nplot nsearch TRACE.fits *trace_peaks_recursive.pl Tracing algorithm. It determines the peak intensity of each spectra in the CCD along the pseudo-slit direction for any spectral pixel, using as input the results from "peak_find.pl". It requires: RAW.fits => The raw fitsfile with the spectra. Spectral_axis[0/1] => The axis of the spectral dispersion, 0=X, 1=Y. PEAKS_FILE => Output file from "peak_find.pl". x_width => The number of spectral pixels to coadd to look for the peak. y_width => Pseudo-slit direction region for looking for each peak. plot [0/1] => Flag that allows to visualize the results. nplot => Number of subframes for plotting. nsearch => Number of pixels to compare with the possible maximun. TRACE.fits => Output file. e.g., trace_peaks.pl run35_00385b.fits 0 run35_00385b.peaks 0 5 1 4 2 run35_00385b.trc.fits * trace_peaks_cross.pl Tracing algorithm. It determines the peak intensity of each spectra in the CCD along the pseudo-slit direction for any spectral pixel, using as input the results from "peak_find.pl". It cross-correlate the previously found peak with the new cut determining a shift that accounts for the fleaxures. It requires: RAW.fits => The raw fitsfile with the spectra. Spectral_axis[0/1] => The axis of the spectral dispersion, 0=X, 1=Y. PEAKS_FILE => Output file from "peak_find.pl". x_width => The number of spectral pixels to coadd to look for the peak. y_width => Pseudo-slit direction region for looking for each peak. plot [0/1] => Flag that allows to visualize the results. nplot => Number of subframes for plotting. nsearch => Number of pixels to compare with the possible maximun. TRACE.fits => Output file. y_shift_limit => Maximum tolerance of distance between the new peaks and the old ones. e.g., trace_peaks_cross.pl brun35_00451b.fits 0 brun35_00395b.peaks 0 5 0 4 2 brun35_00451b.trc.fits 0.1 * peaks_cross.pl Peaks cross-correlation algorithm. It determines the peak intensity of each spectra in the CCD for the central spectral pixels, using as input the results from "peak_find.pl". It cross-correlate the previously found peak with the new cut determining a shift that accounts for the fleaxures. It requires: RAW.fits => The raw fitsfile with the spectra. Spectral_axis[0/1] => The axis of the spectral dispersion, 0=X, 1=Y. PEAKS_FILE => Output file from "peak_find.pl". x_width => The number of spectral pixels to coadd to look for the peak. y_width => Pseudo-slit direction region for looking for each peak. plot [0/1] => Flag that allows to visualize the results. nplot => Number of subframes for plotting. nsearch => Number of pixels to compare with the possible maximun. y_shift_limit => Maximum tolerance of distance between the new peaks and the old ones. e.g., peaks_cross.pl brun35_00451b.fits 0 brun35_00395b.peaks 0 5 0 4 2 0.1 *smooth_trace.pl TRACE.fits y_width Npoly OUT_TRACE.fits plot NX_min NX_max Smooth the 2D tracing, by fitting a N-order polynomial function. It requires: TRACE.fits => Input tracing file. y_width => Pseudo-slit direction region for plotting. Npoly => order of the polynomial function. OUT_TRACE.fits => Output tracing file. plot [0/1] => Flag that allows to visualize the results. NX_min,NX_max => Range of spectral pixels over which the straight-light is estimated. *straight_light.pl RAW.fits Spectral_axis[0/1] TRACE.fits width Npoly staight_light.fits clean.fits NY_min NY_max plot Algorithm for determining and removing straight light contamination in the spectra. It requires enough "holes" between the spectra projected in the 2D image to derive a maenful result. It requires: RAW.fits => The raw fitsfile with the spectra. Spectral_axis[0/1] => The axis of the spectral dispersion, 0=X, 1=Y. TRACE.fits => 2D tracing file, output of "trace_peaks.pl" width => The number of pixels in the pseudo-slit direction to mask around the spectral data. Npoly => Order of the polynomical function to fit over the non-contaminated data. straight_light.fits => 2D image with the estimated straight light. clean.fits => 2D image with the decontaminated data. NX_min,NX_max => Range of spectral pixels over which the straight-light is estimated. plot [0/1] => Flag that allows to visualize the results. e.g., straight_light.pl run35_00385b.fits 0 run35_00385b.strc.fits 6 8 run35_00385b.cl.fits run35_00385b. 0 2020 0 *extract_aper.pl RAW.fits Spectral_axis[0/1] TRACE.fits Aperture OUTPUT.fits [SHIFT] Algorithm for aperture extraction of the spectra. It requires: RAW.fits => The raw fitsfile with the spectra. Spectral_axis[0/1] => The axis of the spectral dispersion, 0=X, 1=Y. TRACE.fits => 2D tracing file, output of "trace_peaks.pl" Aperture => Aperture for extracting around the traced peak (+-Aperture). OUTPUT => Output extracted spectra. [SHIFT] => Global Shift to the tracing Mask. *extract_gauss_simple.pl RAW.fits Spectral_axis[0/1] TRACE.fits WIDTH OUTPUT.fits NX_MIN NX_MAX plot nplot Simple gaussian extraction. For each spectral pixel and each spectral peak the program fits a 1D gaussian extracting the integrated flux. It requires: RAW.fits => The raw fitsfile with the spectra. Spectral_axis[0/1] => The axis of the spectral dispersion, 0=X, 1=Y. TRACE.fits => 2D tracing file, output of "trace_peaks.pl" WIDTH => Number of pixels to be fitted around a certain position. Aperture => Aperture for extracting around the traced peak (+-Aperture). OUTPUT => Output extracted spectra. NX_min,NX_max => Range of spectral pixels over which the fitting algorithm is applied. plot [0/1] => Flag that allows to visualize the results. nplot => Number of subframes for plotting. It also produces three 2D images: back.fits => 2D background image, derived from the fitting. cen.fits => 2D Tracing, equivalent to the result from "trace_peaks.pl", but obtained from the gaussian fitting (centroid). fwhm.fits => 2D image containing the FWHM of the fitted gaussian for each spectral pixel and each spectra. *extract_gauss_weight.pl RAW.fits Spectral_axis[0/1] CEN.fits FWHM.fits ADDING_WIDTH ALLOWED_SHIFT_CEN OUTPUT.fits [SHIFT] Gaussian weighted extraction. For each spectral pixel and each spectral peak the program extract an gaussian weighted flux. It requires: RAW.fits => The raw fitsfile with the spectra. Spectral_axis[0/1] => The axis of the spectral dispersion, 0=X, 1=Y. CEN.fits => 2D tracing file, output of "trace_peaks.pl" and/or "extract_gauss_simple.pl". FWHM.fits => 2D image containing the FWHM of the fitted gaussian for each spectral pixel and each spectra. ADDING_WIDTH => Number of pixels to be co-added around a certain position. ALLOWED_SHIFT_CEN => Maximun tolerance for centroid offseting between sucesive centroids. OUTPUT => Output extracted spectra. [SHIFT] => Global Shift to the tracing Mask. *extract_gauss.pl RAW.fits Spectral_axis[0/1] TRACE.fits WIDTH OUTPUT.fits NX_MIN NX_MAX plot nplot Gaussian fitted extraction. It is an extension of "extract_gauss_simple.pl" where, after deriving the gaussian parameters for each spectral pixel and spectra, a LSQ fitting algorithm is applied over the 1D array at a certain spectral pixel fitting simultaneously all the gaussians (fixing the centroid and the FWHMs). It requires: RAW.fits => The raw fitsfile with the spectra. Spectral_axis[0/1] => The axis of the spectral dispersion, 0=X, 1=Y. TRACE.fits => 2D tracing file, output of "trace_peaks.pl" and/or "extract_gauss_simple.pl". WIDTH => Number of pixels to be fitted around a certain position. OUTPUT => Output extracted spectra. NX_min,NX_max => Range of spectral pixels over which the fitting algorithm is applied. plot [0/1] => Flag that allows to visualize the results. nplot => Number of subframes for plotting. * extract_gauss_external.pl RAW.fits Spectral_axis[0/1] CEN.fits FWHM.fits OUTPUT.fits ALLOWED_SHIFT_CEN plot nplot Gaussian fitted extraction. Similar to "extract_gauss.pl", but using as tracing and FWHM an external file, instead of one determined over the data. It requires: RAW.fits => The raw fitsfile with the spectra. Spectral_axis[0/1] => The axis of the spectral dispersion, 0=X, 1=Y. CEN.fits => 2D tracing file, output of "trace_peaks.pl" and/or "extract_gauss_simple.pl". FWHM.fits => 2D image containing the FWHM of the fitted gaussian for each spectral pixel and each spectra. OUTPUT => Output extracted spectra. ALLOWED_SHIFT_CEN => Maximun tolerance for centroid offseting between sucesive centroids. plot [0/1] => Flag that allows to visualize the results. nplot => Number of subframes for plotting. e.g., extract_gauss_external.pl run35_00385b.cl.fits 0 run35_00385b.strc.fits fwhm.fits run35_00385b.gs.fits 2 0 6 *dist_cor.pl EXTRACTED.fits CORRECTED.fits DISTORSION_CORRECTION.txt SMOOTH[0/1] start_index delta_index plot Distortion correction, without required a dispersion correction of the spectra. It cross-correlate the spectra in the file with the 1st spectrum to determine a shift that it is applied to each single spectrum. It requires: EXTRACTED.fits => Input extracted spectra. CORRECTED.fits => Output distortion corrected spectra. DISTORSION_CORRECTION.txt => Output distortion correction solution. SMOOTH[0/1] => Flag to smooth or not the distortion correction start_index,end_index => It defines the wavelength range to cross-correlate. NOTE: end_index must be a power of 2: 16, 32, 128... plot => Flag for plotting the results. *dist_cor_cross.pl EXTRACTED.fits CORRECTED.fits DISTORSION_CORRECTION.txt SMOOTH[0/1] start_index delta_index plot Distortion correction, without required a dispersion correction of the spectra. It cross-correlate the spectra in the file with the 1st spectrum to determine a shift that it is applied to each single spectrum. It requires: EXTRACTED.fits => Input extracted spectra. CORRECTED.fits => Output distortion corrected spectra. DISTORSION_CORRECTION.txt => Output distortion correction solution. SMOOTH[0/1] => Flag to smooth or not the distortion correction start_index,end_index => It defines the wavelength range to cross-correlate. NOTE: end_index must be a power of 2: 16, 32, 128... plot => Flag for plotting the results. *dist_cor_external.pl EXTRACTED.fits CORRECTED.fits DISTORSION_CORRECTION.txt start_index delta_index plot Distortion correction, without required a dispersion correction of the spectra. It use an ascii file as input to define the shifts. It requires: EXTRACTED.fits => Input extracted spectra. CORRECTED.fits => Output distortion corrected spectra. DISTORSION_CORRECTION.txt => Input distortion correction solution. start_index,end_index => It defines the wavelength range to plot. plot => Flag for plotting the results. *mdist_cor.pl EXTRACTED.fits APERTURE NSIGMA NPOLY OUTPUT.fits DISTORSION.fits NX_min NX_max plot Correct the 2nd order of the distortion, with a polynomical correction for each spectra. It requires: EXTRACTED.fits => An extracted spectra, corrected for the 1st order with "dist_cor.pl". APERTURE => Searching aperture for maximun searchings. NSIGMA => N-Sigma over the background for searching new peaks. NPOLY => Order of the polynomical function. OUTPUT.fits => OUTPUT file. DISTORSION.fits => 2D distortion correction. NX_min => minimum spectral index for peak searching. NX_max => maximum spectral index for peak searching. plot => Interactive plotting. *mdist_cor_external.pl EXTRACTED.fits DISTORTION.txt DISTORSION.fits OUTPUT.fits plot Correct the 2nd order of the distortion, using both the 1st order correction and the 2nd order correction derived from "dist_cor.pl" and "mdist_cor.pl". It requires: EXTRACTED.fits => An extracted spectra. DISTORTION.txt => The 1st order distortion correction derived from "dist_cor.pl". DISTORSION.fits => The 2nd order distortion correction derived from "mdist_cor.pl". OUTPUT.fits => Corrected flag. plot => Flag for interactive plotting. *disp_cor.pl EXTRACTED.fits CRVAL CDELT APERTURE NY_SPECTRA WITDH NPOLY OUTPUT.fits DISPERSION.txt plot Program to perform the dispersion correction. It requires: EXTRACTED.fits => Input extracted and distortion corrected 2D spectra. CRVAL => Starting wavelength. CDELT => Wavelength step. APERTURE => Searching aperture for maximun searchings. NY_SPECTRA => Index of the spectrum to look for signatures. WITDH => Width of the aperture to coadd to generate the searching spectrum (+-width). NPOLY => Order of the polynomical function of the spectral correction. OUTPUT.fits => Dispersion corrected 2D spectral image. DISPERSION.txt => Dispersion solution. plot => Flag for plotting. e.g., disp_cor.pl run35_00385b.dist.fits 4406 0.3 5 128 5 4 run35_00385b.disp.fits run35_00385b.disp.txt 1 *disp_cor_external.pl EXTRACTED.fits CRVAL CDELT OUTPUT.fits DISPERSION.txt plot Program to perform the dispersion correction using an external solution. It requires: EXTRACTED.fits => Input extracted and distortion corrected 2D spectra. CRVAL => Starting wavelength. CDELT => Wavelength step. OUTPUT.fits => Dispersion corrected 2D spectral image. DISPERSION.txt => Dispersion solution. plot => Flag for plotting. e.g., disp_cor_external.pl run35_00387b.dist.fits 4406 0.3 run35_00387b.disp.fits run35_00385b.disp.txt 1 *fiber_flat.pl SKYFLAT.fits FIBERFLAT.fits Program that determines the FIBER-FLAT. * Mosaic_cubes.pl CONFIG.txt OUTPUT *rss2cube.pl input_RSS.fits output_cube.fits nx ny Transform a Row-Stacked-Spectra fits file into a datacube, for regular grid IFS, when the spectra are order from left-top to right-bottom in the RSS file. It requires: input_RSS.fits -> The input RSS file. output_cube.fits -> The ouput cube. nx,ny -> size of the cube. *rss2cube_pt.pl input_RSS.fits pos_table.txt output_cube.fits Transform a Row-Stacked-Spectra fits file into a datacube, for regular grid IFS, when the spectra are not ordered from left-top to right-bottom in the RSS file, but following a certain position table. It requires: input_RSS.fits -> The input RSS file. pos_table.txt -> position table (E3D format). output_cube.fits -> The ouput cube. * check_trace.pl TRACE.fits y_width Visualize every tracing in a trace file, over a width of "y_width" points. It requires: TRACE.fits -> Tracing file (output of trace_peaks.pl or trace_peaks_recursive.pl) y_width -> Plotting width. e.g., check_trace.pl VIMOS_IFU_LAMP018_0022_B.1.trc.fits 4 * comp_spec.pl SPEC1.txt SPEC2.txt ratio.txt Compare two spectra, stored in two differen ascii files, and derive the ratio between them. It requires: SPEC1.txt & SPEC2.txt -> Two three-columns ascii files with two spectra (id,wavelength,flux) ratio.txt -> output ratio.