resample

sofia_redux.instruments.fifi_ls.resample.resample(filenames, target_x=None, target_y=None, target_wave=None, ctype1='RA---TAN', ctype2='DEC--TAN', ctype3='WAVE', interp=False, oversample=None, spatial_size=None, spectral_size=None, window=None, adaptive_threshold=None, adaptive_algorithm=None, error_weighting=True, smoothing=None, order=2, robust=None, neg_threshold=None, fit_threshold=None, edge_threshold=None, append_weights=False, skip_uncorrected=False, write=False, outdir=None, jobs=None, check_memory=True, scan_reduction=False, scan_kwargs=None, save_scan=False, detector_coordinates=None, naif_id_key='NAIF_ID', insert_source=True)[source]

Resample unevenly spaced FIFI-LS pixels to regular grid.

Spatial and spectral pixels from all dither positions are resampled onto a regular grid.

The procedure is:

  1. Read input files

  2. Define output grid based on input parameter values or values from file data.

  3. Resample data: perform local polynomial fits at each output grid point.

  4. Correct flux for change to pixel size. Factor is new pixel area (dx^2) / input pixel size (12” red, 6” blue).

  5. Update header for new WCS, from OBSRA/OBSDEC and offsets, Update PROCSTAT to LEVEL_4 if input data comes from multiple missions.

  6. Create FITS file and write results to disk.

Parameters:
filenamesarray_like of str

File paths to FITS data to be resampled.

target_xfloat, optional

The target right ascension (hourangle). The default is the mid-point of all RA values in the combined data.

target_yfloat, optional

The target declination (degree). The default is the mid-point of all DEC values in the combined data.

target_wavefloat, optional

The center wavelength (um). The default is the mid-point of all wavelength values in the combined data.

ctype1str, optional

The coordinate frame for the x spatial axis using FITS standards.

ctype2str, optional

The coordinate frame for the y spatial axis using FITS standards.

ctype3str, optional

The coordinate frame for the w spectral axis using FITS standards.

interpbool, optional

If True, alternate algorithm will be used for spatial resampling (interpolation / mean combine, rather than local polynomial fits).

oversamplearray_like of int or float, optional

Number of pixels to sample mean FWHM with, in the (spatial, spectral) dimensions. Default is (5.0, 8.0).

spatial_sizefloat, optional

Output pixel size, in the spatial dimensions. Units are arcsec. If specified, the corresponding oversample parameter will be ignored.

spectral_sizefloat, optional

Output pixel size, in the spectral dimension. Units are um. If specified, the corresponding oversample parameter will be ignored.

windowarray_like of float, optional

Region to consider for local polynomial fits, given as a factor of the mean FWHM, in the (x, y, w) dimensions. Default is (3.0, 3.0, 0.5).

adaptive_thresholdarray_like of float, optional

If > 0, determines how the adaptive smoothing algorithm will attempt to fit data. The optimal value is 1. Will automatically enable both distance and error weighting. For dimensions that have adaptive smoothing enabled, smoothing should be set to the Gaussian width of the data in units of window. For other dimensions not using adaptive smoothing, smoothing has the usual definition. Adaptive smoothing is disabled by default: (0.0, 0.0, 0.0).

adaptive_algorithm{‘scaled’, ‘shaped’}, optional

Determines the type of variation allowed for the adaptive kernel. If ‘scaled’, only the kernel size is allowed to vary. If ‘shaped’, kernel shape may also vary.

error_weightingbool, optional

If True, errors will be used to weight the flux fits.

smoothingarray_like of float, optional

Radius over which to smooth the input data, specified as a factor of the mean FWHM, if distance weights are being used. Default is (2.0, 2.0, 0.25).

orderarray_like or int, optional

(nfeatures,) array of single integer value specifying the polynomial fit order for each dimension (x, y, w).

robustfloat, optional

Rejection threshold for input data to local fits, given as a factor of the standard deviation.

neg_thresholdfloat, optional

First-pass rejection threshold for negative input data, given as a factor of the standard deviation; if None or <= 0, first-pass rejection will not be performed.

fit_thresholdfloat, optional

Rejection threshold for output fit values, given as a factor of the standard deviation in the input data. If exceeded, weighted mean value is used in place of fit.

edge_thresholdfloat or array_like or float

If set to a value > 0 and < 1, edges of the fit will be masked out according to edge_algorithm. Values close to zero will result in a high degree of edge clipping, while values close to 1 ckip edges to a lesser extent. The clipping threshold is a fraction of window. An array may be used to specify values for each dimension.

append_weights: bool, optional

If set, distance weights will be appended as an additional extension.

skip_uncorrected: bool, optional

If set, the uncorrected flux cube will not be computed, even if present in the input data. This option is primarily intended for testing or quicklook, when the full data product is not needed.

writebool, optional

If True, write to disk and return the path to the output file. The output filename is created from the input filename, with the product type suffix replaced with ‘WXY’.

outdirstr, optional

Directory path to write output. If None, output files will be written to the same directory as the input files.

jobsint, optional

Specifies the maximum number of concurrently running jobs. Values of 0 or 1 will result in serial processing. A negative value sets jobs to n_cpus + 1 + jobs such that -1 would use all cpus, and -2 would use all but one cpu.

check_memorybool, optional

If set, expected memory use will be checked and used to limit the number of jobs if necessary.

scan_reductionbool, optional

If True, run a scan reduction first before performing the resampling step. This may be a very time consuming operation, but may also remove many correlated noise signals from the data.

save_scanbool, optional

If True, the output from the scan algorithm, prior to resampling, will be saved to disk.

scan_kwargsdict, optional

Optional keyword arguments to pass into the scan reduction.

detector_coordinatesbool, optional

If True, reduce using detector coordinates instead of RA/DEC. if None, will attempt to auto-detect based on OBSLAM/OBSDEC header values (True if all OBSLAM/DEC = 0, False otherwise).

naif_id_keystr, optional

The name of the NAIF ID keyword. If present in the header, should indicate the associated file contains a nonsidereal observation.

insert_sourcebool, optional

If True, will perform a full scan reduction (if applicable) and reinsert the source after. Otherwise, the reduction is used to calculate gains, offsets, and correlations which will then be applied to the original data. If True, note that timestream filtering will not be applied to the correction and should therefore be excluded from the scan reduction runtime parameters in order to reduce processing pressure.

Returns:
fits.HDUList or str

Either the HDU (if write is False) or the filename of the output file (if write is True). The output contains the following extensions: FLUX, ERROR, WAVELENGTH, X, Y, RA, DEC, TRANSMISSION, RESPONSE, EXPOSURE_MAP. The following extensions will be appended if possible: UNCORRECTED_FLUX, UNCORRECTED_ERROR, UNSMOOTHED_TRANSMISSION.