fit_ramps¶
- sofia_redux.instruments.fifi_ls.fit_ramps.fit_ramps(filename, s2n=10, threshold=5, badpix_file=None, write=False, outdir=None, remove_first=True, subtract_bias=True, indpos_sigma=3.0)[source]¶
Fit straight lines to raw voltage ramps to calculate corresponding flux.
If writing to disk, the output filename is created from the input filename, with the suffix ‘CP0’ or ‘CP1’ replaced with ‘RP0’ or ‘RP1’. The resulting HDU contains n_scan * 2 image extensions, for FLUX and STDDEV data for each grating scan, named with a grating scan index (e.g. FLUX_G0, STDDEV_G0, FLUX_G1, STDDDEV_G1, etc.).
For all data except OTF mode A nods, the output image arrays have dimensions 25 x 16. For OTF A nods, the ramps are not averaged to produce a single 2D array but rather propagated as a 3D cube, along with separate scanning position data. Dimensions for these data are 25 x 16 x n_ramp, and an additional table called SCANPOS_G0 is attached to the output file, containing the scan position data, averaged over each ramp. It is assumed that OTF data files contain only one grating scan.
Input files for this step should have been generated by fifi_ls.split_grating_and_chop.
The procedure is: Loop through the extensions, fitting ramps in each:
Remove the 26th spaxel (chopper values) and the first and last spexel.
Remove the first ramp from each spaxel and the first and last readout in each ramp.
Loop over spaxels and spexels, fitting each ramp with a line. Record the slope and the error on the slope. Combine the slopes from all ramps with a robust weighted mean. Record the error on the mean as the error on the flux.
(optional) Create FITS file and write results to disk.
- Parameters:
- filenamestr
Name of the chop-split, grating-split file (including the path if not in the current working directory)
- s2nfloat, optional
Signal-to-noise below which data will be considered questionable and will be ignored. Set <= 0 to turn off signal-to-noise filtering.
- thresholdfloat, optional
Robust rejection threshold (in sigma) for combining slopes of individual ramps.
- badpix_filestr, optional
badpix file to be used. If not provided, a default file will be retrieved from the data/badpix_files directory, matching the date and channel of the input header. If an override file is provided, it should be a text file containing two columns, spaxel and spexel coordinates. Spaxels are numbered from 1 to 25, spexels from 1 to 16.
- writebool, optional
If True, write the output to disk and return the filename instead of the HDU.
- outdirstr, optional
If writing to disk, use to set the output directory. By default the output directory will be the same as the input filename location.
- remove_firstbool, optional
If True, remove the first two ramps prior to fitting.
- subtract_biasbool, optional
If True, subtract the value of the empty zeroth pixel prior to fitting.
- indpos_sigmafloat, optional
If >0, will be used to discard samples with grating position that deviates from the expected INDPOS value by this many sigma.
- Returns:
- fits.HDUList or str
Either the HDU (if write is False) or the filename of the output file (if write is True)