pypeit.core.spatialprofile module

Module to model the spatial profile of sources, used for optimal extraction.

pypeit.core.spatialprofile.findfwhm(model, sig_x)[source]

Calculate the spatial FWHM of an object profile. This is utility routine is used in fit_profile().

Revision History:

  • 11-Mar-2005 Written by J. Hennawi and S. Burles David Schlegel, Princeton.

  • 28-May-2018 Ported to python by J. Hennawi

Parameters:
  • model (numpy.ndarray) – Model of the object profile. This is 2-d floating-point array with shape \((N_{\rm spec}, N_{\rm spat})\).

  • sig_x (numpy.ndarray) – Floating-point 2-d array containing the spatial location of the object profile. Shape is \((N_{\rm spec}, N_{\rm spat})\).

Returns:

  • peak (float) – Peak value of the object profile model.

  • peak_x (float) – sig_x location where the peak value is obtained.

  • lwhm (float) – Value of sig_x at the left width at half maximum.

  • rwhm (float) – Value of sig_x at the right width at half maximum.

pypeit.core.spatialprofile.fit_profile(image, ivar, waveimg, thismask, spat_img, trace_in, wave, flux, fluxivar, inmask=None, thisfwhm=4.0, max_trace_corr=2.0, sn_gauss=4.0, percentile_sn2=70.0, prof_nsigma=None, no_deriv=False, gauss=False, obj_string='', show_profile=False)[source]

Fit a non-parametric object profile to an object spectrum. If the S/N ratio of the object is less than sn_gauss, a simple Gaussian will be fitted.

This routine was ported from the IDL LOWREDUX routine long_gprofile.pro.

Parameters:
  • image (numpy.ndarray) – Floating-point sky-subtracted science image with shape \((N_{\rm spec}, N_{\rm spat})\). The first dimension (\(N_{\rm spec}\)) is spectral, and second dimension (\(N_{\rm spat}\)) is spatial.

  • ivar (numpy.ndarray) – Floating-point inverse variance image for the sky-subtracted science image. Shape must match image, \((N_{\rm spec}, N_{\rm spat})\).

  • waveimg (numpy.ndarray) – Floating-point wavelength image. Must have the same shape as image, \((N_{\rm spec}, N_{\rm spat})\).

  • thismask (numpy.ndarray) – Boolean image indicating which pixels are on the slit/order in question. Must have the same shape as sciimg, \((N_{\rm spec}, N_{\rm spat})\).

  • spat_img (numpy.ndarray) – Floating-point image containing the spatial location of pixels. Must have the same shape as image, \((N_{\rm spec}, N_{\rm spat})\).

  • trace_in (numpy.ndarray) – Floating-point 1-d array containing the object trace. Shape is \((N_{\rm spec},)\).

  • wave (numpy.ndarray) – Floating-point 1-d array containing the extracted wavelength of spectrum. Shape is \((N_{\rm spec},)\).

  • flux (numpy.ndarray) – Floating-point 1-d array containing the extracted flux of spectrum. Shape is \((N_{\rm spec},)\).

  • fluxivar (numpy.ndarray) – Floating-point 1-d array containing the inverse variance of extracted flux spectrum. Shape is \((N_{\rm spec},)\).

  • thisfwhm (float, optional) – FWHM value in pixels of the traced object. The default is 4.0.

  • max_trace_corr (float, optional) – Maximum correction in pixels to apply to the object trace. The default is 2.0.

  • sn_gauss (float, optional) – S/N ratio below which the routine just fit a simple Gaussian. The default is 4.0.

  • percentile_sn2 (float, optional) – Percentile of the S/N values along the spectral direction used to estimate the object median S/N. For example if percentile_sn2 = 70.0 then the upper 30% of the S/N values are used. This allows to determine the object median S/N even when the object shows signal only for part of fulle wavelength range. The default is 70.0.

  • prof_nsigma (float, optional) – Number of sigma to include in the profile fitting. This value is needed for bright objects that are not point sources, allowing to fit the high S/N wings of the object profile, rather than truncate it exponentially. Setting this value allows to extract all the object flux and provides a better sky-subtraction for bright extended objects. The default is None.

  • no_deriv (bool, optional) – If True, disables the determination of derivatives and exponential apodization. The default is False.

  • gauss (bool, optional) – If True, the profile fitting will not be attempted, and a Gaussian profile will be assumed.

  • obj_string (str) – String identifying the object. Used only to generate the QA plot.

  • show_profile (bool) – If True, the QA plot will be shown to screen.

Returns:

  • profile_model (numpy.ndarray) – Floating-point 2-d array containing the model of the object profile. Shape is \((N_{\rm spec}, N_{\rm spat})\).

  • xnew (numpy.ndarray) – Floating-point 1-d array containing the new trace of the object. Shape is \((N_{\rm spec},)\).

  • fwhmfit (numpy.ndarray) – Floating-point 1-d array containing the estimated FWHM in pixels of the object profile along the spectral direction. Shape is \((N_{\rm spec},)\).

  • med_sn2 (float) – Estimated median S/N^2 of the object profile.

pypeit.core.spatialprofile.qa_fit_profile(x_tot, y_tot, model_tot, l_limit=None, r_limit=None, ind=None, title=' ', xtrunc=1000000.0, xlim=None, ylim=None)[source]

Generate a QA plot for the object fitted profile.

Parameters:
  • x_tot (numpy.ndarray) – Floating-point 2-d array containing the spatial location of the object profile. Shape is \((N_{\rm spec}, N_{\rm spat})\).

  • y_tot (numpy.ndarray) – Floating-point 2-d array containing the flux of the object profile. Shape is \((N_{\rm spec}, N_{\rm spat})\).

  • model_tot (numpy.ndarray) – Floating-point 2-d array containing the model of the object profile. Shape is \((N_{\rm spec}, N_{\rm spat})\).

  • l_limit (float, optional) – If not None, draw a vertical line at this left position.

  • r_limit (float, optional) – If not None, draw a vertical line at this right position.

  • ind (numpy.ndarray, optional) – Integer 1-d array containing the indices of a subset of the object profile to be plot. The default is None.

  • title (str, optional) – Title to show on plot. Defaults to ‘ ‘.

  • xtrunc (float, optional) – Number of sigma to include in the plot of the object profile when generating the QA plot. The default is 1e6.

  • xlim (float, optional) – Minimum and maximum x-axis limits for the plot. Defaults is None.

  • ylim (tuple, optional) – Minimum and maximum y-axis limits for the plot. Defaults is None.

pypeit.core.spatialprofile.return_gaussian(sigma_x, norm_obj, fwhm, med_sn2, obj_string, show_profile, ind=None, l_limit=None, r_limit=None, xlim=None, xtrunc=1000000.0)[source]

Utility function to return a Gaussian object profile.

Parameters:
  • sigma_x (numpy.ndarray) – Floating-point 2-d array containing the location of the Gaussian profile. Shape is \((N_{\rm spec}, N_{\rm spat})\).

  • norm_obj (numpy.ndarray) – Floating-point 2-d array containing the normalized spectrum. Shape is \((N_{\rm spec}, N_{\rm spat})\).

  • fwhm (float) – FWHM value in pixels for the Gaussian profile.

  • med_sn2 (float) – Median (S/N)^2. Used only to generate the QA plot.

  • obj_string (str) – String identifying object. Used only to generate the QA plot.

  • show_profile (bool) – If True, the QA plot will be shown to screen.

  • ind (numpy.ndarray, optional) – Integer 1-d array containing the indices of the good pixels for the object profile. Used only to generate the QA plot. The deafault is None.

  • l_limit (float, optional) – Left and right limits of profile fit where derivative is evaluated for Gaussian apodization. Used only to generate the QA plot. The default is None.

  • r_limit (float, optional) – Left and right limits of profile fit where derivative is evaluated for Gaussian apodization. Used only to generate the QA plot. The default is None.

  • xlim (float, optional) – Minimum and maximum x-axis limits for plotting the object profile when generating the QA plot.

  • xtrunc (float, optional) – Number of sigma to include in the plot of the object profile when generating the QA plot. The default is 1e6.

Returns:

profile_model – Floating-point 2-d array containing the model of the object profile. Shape is \((N_{\rm spec}, N_{\rm spat})\).

Return type:

numpy.ndarray