corgidrp.spec#
Functions#
|
2d gaussian function for gaussfit2d |
|
Fits a 2-d Gaussian to the data at point (xguess, yguess), with pixel integration. |
|
Cost function for a least-squares fit to register a PSF with a fitting template. |
|
Finds the center coordinates for a given frame. |
|
Rotate an array of (x,y) coordinates by an angle about a pivot point. |
|
Fit the centroid of a PSF image with a template. |
|
return the default template dataset from the data/spectroscopy/templates files |
|
Compute PSF centroids for a grid of PSFs and return them as a calibration object. |
|
read the csv filter file containing the band names and the central wavelength in nm. |
|
Estimate the clocking angle of the dispersion axis based on the centroids of |
|
Given arrays of wavelengths and positions, fit two polynomials: |
|
Generate a DispersionModel of the spectral dispersion profile of the CGI ZOD prism. |
|
Create a wavelength calibration map and a wavelength-position lookup table, |
|
Find the array shift that maximizes the phase correlation between two |
|
This function addresses: |
|
Fit the line spread function to a wavelength calibrated (averaged) dataset, by reading |
|
This step function addresses: |
|
Find the position of the star using the information from the satellite |
|
generates the SpecFluxCal calibration product for one band, |
|
read the csv filter file containing at least the band names and the pixel x/y offsets |
Module Contents#
- corgidrp.spec.gauss2d(x0, y0, sigma_x, sigma_y, peak)[source]#
2d gaussian function for gaussfit2d
- Parameters:
x0 – center of gaussian
y0 – center of gaussian
peak – peak amplitude of gaussian
sigma_x – stddev in x direction
sigma_y – stddev in y direction
- Returns:
function evaluated at coordinate tuple y,x
- corgidrp.spec.gaussfit2d_pix(frame, xguess, yguess, xfwhm_guess=3, yfwhm_guess=6, halfwidth=3, halfheight=5, guesspeak=1, oversample=5, refinefit=True)[source]#
Fits a 2-d Gaussian to the data at point (xguess, yguess), with pixel integration.
- Parameters:
frame – the data - Array of size (y,x)
xguess – location to fit the 2d gaussian to (should be within +/-1 pixel of true peak)
yguess – location to fit the 2d gaussian to (should be within +/-1 pixel of true peak)
xfwhm_guess – approximate x-axis fwhm to fit to
yfwhm_guess – approximate y-axis fwhm to fit to
halfwidth – 1/2 the width of the box used for the fit
halfheight – 1/2 the height of the box used for the fit
guesspeak – approximate flux in peak pixel
oversample – odd integer >= 3; to represent detector pixels, oversample and then bin the model by this factor
refinefit – whether to refine the fit of the position of the guess
- Returns:
x position (only changed if refinefit is True) yfit: y position (only changed if refinefit is True) xfwhm: x-axis fwhm of the PSF in pixels yfwhm: y-axis fwhm of the PSF in pixels peakflux: the peak value of the gaussian fitbox: 2-d array of the fitted region from the data array model: 2-d array of the best-fit model residual: 2-d array of residuals (data - model)
- Return type:
xfit
- corgidrp.spec.psf_registration_costfunc(p, template, data)[source]#
Cost function for a least-squares fit to register a PSF with a fitting template.
- Parameters:
p (tuple) –
shift and scale parameters: (x-axis shift in pixels, y-axis shift in pixels,
amplitude scale factor)
template (numpy.ndarray) – PSF tempate array, 2d
data (numpy.ndarray) – PSF data array, 2d
- Returns:
The sum of squares of differences between the data array and the shifted and scaled template.
- corgidrp.spec.get_center_of_mass(frame)[source]#
Finds the center coordinates for a given frame.
- Parameters:
frame (np.ndarray) – 2D array to compute centering
- Returns:
xcen (float): X centroid coordinate ycen (float): Y centroid coordinate
- Return type:
tuple
- corgidrp.spec.rotate_points(points, angle_rad, pivot_point)[source]#
Rotate an array of (x,y) coordinates by an angle about a pivot point.
- Parameters:
points (tuple) – Two-element tuple of (x,y) coordinates. The first element is an array of x values; the second element is an array of y values.
angle_rad (float) – Rotation angle in radians
pivot_point (tuple) – Tuple of (x,y) coordinates of the pivot point.
- Returns:
Two-element tuple of rotated (x,y) coordinates.
- corgidrp.spec.fit_psf_centroid(psf_data, psf_template, xcent_template=None, ycent_template=None, xcent_guess=None, ycent_guess=None, halfwidth=10, halfheight=10, fwhm_major_guess=3, fwhm_minor_guess=6, gauss2d_oversample=9)[source]#
Fit the centroid of a PSF image with a template.
- Parameters:
psf_data (np.ndarray) – PSF data, 2D array
psf_template (np.ndarray) – PSF template, 2D array
xcent_template (float) – true x centroid of the template PSF; for accurate results this must be determined in advance.
ycent_template (float) – true y centroid of the template PSF; for accurate results this must be determined in advance.
xcent_guess (int) – Estimate of the x centroid of the data array, pixels
ycent_guess (int) – Estimate of the y centroid of the data array, pixels
halfwidth (int) – Half-width of the fitting region, pixels
halfheight (int) – Half-height of the fitting region, pixels
fwhm_major_guess (float) – guess for FWHM value along major axis of PSF, pixels
fwhm_minor_guess (float) – guess for FWHM value along minor axis of PSF, pixels
gauss2d_oversample (int) – upsample factor for 2-D Gaussian PSF fit; this must be an odd number.
- Returns:
- Data PSF x centroid obtained from the template fit,
array pixels
- yfit (float): Data PSF y centroid obtained from the template fit,
array pixels
- gauss2d_xfit (float): Data PSF x centroid estimated by a 2-D Gaussian fit to
the main lobe of the PSF
- gauss2d_yfit (float): Data PSF y centroid estimated by a 2-D Gaussian fit to
the main lobe of the PSF
peakpix_snr (float): Peak-pixel signal-to-noise ratio x_precis (float): Statistical precision of the x centroid fit, estimated from
peak-pixel S/N ratio
- y_precis (float): Statistical precision of the y centroid fit, estimated from
peak-pixel S/N ratio
- Return type:
xfit (float)
- corgidrp.spec.get_template_dataset(dataset)[source]#
return the default template dataset from the data/spectroscopy/templates files
- corgidrp.spec.compute_psf_centroid(dataset, template_dataset=None, initial_cent=None, filtersweep=False, halfwidth=10, halfheight=10, verbose=False)[source]#
Compute PSF centroids for a grid of PSFs and return them as a calibration object.
- Parameters:
dataset (Dataset) – Dataset containing 2D PSF images. Each image must include pri_hdr and ext_hdr.
template_dataset (Dataset) – dataset of the template PSF, if None, a simulated PSF from the data/spectroscopy/template path is taken
initial_cent (dict) – Dictionary with initial guesses for PSF centroids. Must include keys ‘xcent’ and ‘ycent’, each mapping to an array of shape (N,).
filtersweep (bool) – If True, it uses a filter sweep/scan dataset, this parameter is only relevant if template_dataset is not None.
halfwidth (int) – Half-width of the PSF fitting box.
halfheight (int) – Half-height of the PSF fitting box.
verbose (bool) – If True, prints fitted centroid values for each frame.
- Returns:
Calibration object with fitted (x, y) centroids.
- Return type:
- corgidrp.spec.read_cent_wave(band, filter_file=None)[source]#
read the csv filter file containing the band names and the central wavelength in nm. There are 6 columns: the CFAM filter name, the (Phase C) center wavelength, the TVAC TV-40b measured center wavelength and the FWHM for the 4 broad bands, and xoffset, yoffset between the bands The TVAC wavelengths are not measured for all filters, but are the preferred value if available.
- Parameters:
filter_file (str) – file name of the filter file
band (str) – name of the filter band
- Returns:
[central wavelength of the filter band, fwhm, xoffset, yoffset]
- Return type:
list
- corgidrp.spec.estimate_dispersion_clocking_angle(xpts, ypts, weights)[source]#
Estimate the clocking angle of the dispersion axis based on the centroids of the sub-band filter PSFs.
- Parameters:
xpts (numpy.ndarray) – Array of x coordinates in EXCAM pixels
ypts (numpy.ndarray) – Array of y coordinates in EXCAM pixels
weights (numpy.ndarray) – Array of weights for line fit
- Returns:
clocking_angle, clocking_angle_uncertainty
- corgidrp.spec.fit_dispersion_polynomials(wavlens, xpts, ypts, cent_errs, clock_ang, ref_wavlen, pixel_pitch_um=13.0)[source]#
Given arrays of wavelengths and positions, fit two polynomials: 1. Displacement from a reference wavelength along the dispersion axis,
in millimeters as a function of wavelength
Wavelength as a function of displacement along the dispersion axis
- Parameters:
wavlens (numpy.ndarray) – Array of wavelengths corresponding to the
points (centroid data)
xpts (numpy.ndarray) – Array of x coordinates in EXCAM pixels
ypts (numpy.ndarray) – Array of y coordinates in EXCAM pixels
cent_errs (numpy.ndarray) – Array of centroid uncertainties in EXCAM pixels
clock_ang (float) – Clocking angle of the dispersion axis in degrees
ref_wavlen (float) – Reference wavelength of the bandpass, in nanometers
pixel_pitch_um (float) – EXCAM pixel pitch in microns
- Returns:
polynomial coefficients for the position vs wavelength fit cov_pos_vs_wavlen (numpy.ndarray): covariance matrix of the polynomial coefficients for the position vs wavelength fit pfit_wavlen_vs_pos (numpy.ndarray): polynomial coefficients for the wavelength vs position fit cov_wavlen_vs_pos (numpy.ndarray): covariance matrix of the polynomial coefficients for the wavelength vs position fit
- Return type:
pfit_pos_vs_wavlen (numpy.ndarray)
- corgidrp.spec.calibrate_dispersion_model(centroid_psf, spec_filter_offset, band_center_file=None, pixel_pitch_um=13.0)[source]#
Generate a DispersionModel of the spectral dispersion profile of the CGI ZOD prism.
- Parameters:
centroid_psf (data.SpectroscopyCentroidPsf) – instance of SpectroscopyCentroidPsf calibration class
spec_filter_offset (data.SpecFilterOffset) – instance of SpecFilterOffset calibration class
band_center_file (str) – file name of the band centers, optional, default is in data/spectroscopy
pixel_pitch_um (float) – EXCAM pixel pitch in micron, default 13 micron
- Returns:
DispersionModel calfile object with the fit results including errors of the spectral trace and the dispersion
- Return type:
- corgidrp.spec.create_wave_cal(disp_model, wave_zeropoint, pixel_pitch_um=13.0, ntrials=1000)[source]#
Create a wavelength calibration map and a wavelength-position lookup table, given a dispersion model and a wavelength zero-point
- Parameters:
disp_model (data.DispersionModel) – Dispersion model calibration object
wave_zeropoint (dict) – Wavelength zero-point dictionary
pixel_pitch_um (float) – EXCAM pixel pitch in microns
ntrials (int) – number of trials when applying a Monte Carlo error propagation to estimate the uncertainties of the values in the wavelength calibration map
- Returns:
2-D wavelength calibration map. Each image pixel value is a wavelength in units of nanometers, computed for the dispersion profile, zero-point position, coordinates, and image shape specified in the input wavelength zero-point object. wavlen_uncertainty (numpy.ndarray): 2-D array of wavelength calibration map uncertainty values in units of nanometers. pos_lookup_table (astropy.table.Table): Wavelength-to-position lookup table, computed for the dispersion profile, zero-point position, coordinates, and image shape specified in the input wavelength zero-point object. The table contains 5 columns: wavelength, x, x uncertainty, y, y uncertainty. x_refwav, y_refwave (float): coordinates of the source at the reference wavelength
- Return type:
wavlen_map (numpy.ndarray)
- corgidrp.spec.get_shift_correlation(img_data, img_template)[source]#
- Find the array shift that maximizes the phase correlation between two
images.
- Parameters:
img_data (array) – first two dimensional array.
img_template (array) – second two dimensional array. Its size must be the same or
img1 (less than)
the (because img2 is the noiseless template used to find)
frame. (spectrum on the L2b data and it is a cropped)
- Returns:
Image shift in image pixels that maximizes the phase correlation of the first image with the second one.
- corgidrp.spec.star_spec_registration(dataset_fsm, pathfiles_template, slit_align_err=0, halfheight=40)[source]#
This function addresses:
CGI-REQT-5465 – Given (1) a series of cleaned images of a prism-dispersed unocculted star observed through the FSAM slit mask, observed with the same CFAM filter, and acquired over a grid of FSM offsets and (2) an estimate of the spectroscopic target source position on EXCAM and its alignment error from the FSAM slit, the CTC GSW should identify the dispersed star image whose PSF-to-FSAM slit alignment most closely matches that of the target source.
NOTE: This calibration is repeated for each roll angle in the observation campaign
- Parameters:
dataset_fsm (Dataset) –
Dataset containing a series of L2b cleaned images of a prism-dispersed unocculted star observed through the FSAM slit mask, observed with the same CFAM filter, and acquired over a grid of FSM offsets. By default, the grid of FSM offsets spans a 3×3 FSM offset grid. Each of the L2b images must have the following header keywords:
– FSMX, FSMY (float64) – CFAMNAME (same for all images) – FSAMNAME = OPEN, R1C2, R6C5, R3C1
pathfiles_template (array) – array of path and filenames containing the simulated star spectrum that are used as a template to find the image in dataset_fsm that best matches it.
slit_align_err (float64) – Distance between the source and the center of the slit aperture, measured along the narrow axis of the slit aperture, in units of mas. It is determined after each observation by looking at the data.
halfheight – 1/2 the height of the box used for the fit.
- Returns:
Filenames with the star image whose PSF-to-FSAM slit alignment most closely matches that of the target source.
- corgidrp.spec.fit_line_spread_function(dataset, halfwidth=2, halfheight=9, guess_fwhm=15.0)[source]#
Fit the line spread function to a wavelength calibrated (averaged) dataset, by reading the wavelength map extension and wavelength zeropoint header
- Parameters:
dataset (corgidrp.data.Dataset) – dataset containing a narrowband filter + prism PSF
halfwidth (int) – The width of the fitting region is 2 * halfwidth + 1 pixels.
halfheight (int) – The height of the fitting region is 2 * halfheight + 1 pixels.
guess_fwhm (float) – guess value of the fwhm of the line
- Returns:
LineSpread object containing wavlens (numpy.ndarray) flux_profile (numpy.ndarray) fwhm_fit (float) mean_fit (float) peak_fit (float)
- Return type:
- corgidrp.spec.slit_transmission(dataset_slit, dataset_open, target_pix=None, x_range=[40.0, 42], y_range=[32.0, 34], n_gridx=10, n_gridy=10, kind='linear', average='mean')[source]#
This step function addresses:
CGI-REQT-5475 – Given (1) a series of cleaned images of a prism-dispersed unocculted star observed through the FSAM slit mask, observed with a CFAM filter, and acquired over one or more FSM offsets, (2) a series of cleaned images of the same prism-dispersed unocculted star observed with the FSAM slit mask removed (FSAM in OPEN position), the same CFAM filter, and acquired over one or more FSM offsets, the CTC GSW should compute the slit transmission map.
- Parameters:
dataset_slit (Dataset) – Dataset containing a set of extracted spectra for some set of FSM positions with the FSAM slit in its position. There can be a different number of frames for each FSM position.
dataset_open (Dataset) – Dataset containing a set of extracted spectra for some set of FSM positions with the FSAM slit in OPEN position. There can be a different number of frames for each FSM position.
target_pix (array) (optional) – a user-defined Mx2 array containing the pixel positions for M target pixels where the slit transmission will be derived by interpolation. The target pixels are measured with respect the zero-point in (fractional) EXCAM pixels. Default is None. In this case, a rectangular grid of pixel positions is used.
x_range (array) – Two values [xmin, xmax] specifying the range of pixels to be considered. Units are EXCAM pixels measured with respect the zero-point solution along EXCAM +X direction.
y_range (array) – Two values [ymin, ymax] specifying the range of pixels to be considered. Units are EXCAM pixels measured with respect the zero-point solution along EXCAM +Y direction.
n_gridx (int) (optional) – Number of positions when pos_range is set.
n_gridy (int) (optional) – Number of positions when pos_range is set.
kind (string) – Specifies the kind of interpolation. See scipy documentation. Default is piecewise linear.
average (str) – The type of average (first momentum) applied to each subset of spectra. The slitless spectra are all averaged at once regardless of their FSMX, FSMY values. The spectra with the slit in are averaged over subsets with the same FSMX, FSMY values. Options are ‘mean’ and ‘median’.
- Returns:
1/ Slit transmission map derived at different locations by interpolation. 2/ Corresponding locations along EXCAM +X direction with respect to the
zero-point in (fractional) EXCAM pixels where the slit transmission has been derived.
- 3/ Corresponding locations along EXCAM +Y direction with respect to the
zero-point in (fractional) EXCAM pixels where the slit transmission has been derived.
- Return type:
SlitTransmission calibration product containing
- corgidrp.spec.star_pos_spec(dataset, r_lamD=3, phi_deg=0)[source]#
Find the position of the star using the information from the satellite spot. The position of the satellite spot on EXCAM is given by the zero-point solution. Using the information of the commanded position of the satellite spot with respect the occulted star, one can infer the location of the occulted star. The relative of the satellite spot with respect the occulted star is given in polar coordinates. The radial distance of the satellite spot is measured in units lambda/D, with lambda the band reference wavelength, either 730 nm (band 3) or 660 nm (band 2), and D=2.4 m. The polar angle is measured in degrees, with 0 degrees meaning +X and 90 degrees meaning +Y. The polar coordinates of the satellite spot are translated into (X,Y) EXCAM pixel coordinates, which can then be subtracted from the zero-point solution to infer the location of the occulted star.
- Parameters:
dataset (Dataset) – A Dataset with L3 spectroscopy frames.
r_lamD (float) – Radial distance of the satellite spot on EXCAM with respect
lambda/D. (the occulted star in units of)
phi_deg (float) – Polar angle of the satellite spot on EXCAM with respect
degrees (with 0 degrees meaning +X and 90)
degrees
+Y. (meaning)
- Returns:
Input Dataset with updated keywords recording the satellite position in EXCAM pixels.
- corgidrp.spec.spec_fluxcal(dataset_or_image, calspec_file=None)[source]#
generates the SpecFluxCal calibration product for one band, calculates the spectral flux calibration or spectro-photometric calibration, that describes the sensitivity of the spectrometer, i.e. how an input power is converted into how many photoelectrons per wavelength, with the final unit erg/(s * cm^2 * AA)/(photoelectron/s/bin). The input is expected to be the dataset of an extracted spectrum of a CALSPEC photometric standard star with units photoelectron/s/bin.
The band flux values of the input calspec data files are divided by the spectral extracted photoelectrons/s/bin interpolated on the available wavelengths. Propagates also errors to the spectral flux calibration file.
- Parameters:
dataset_or_image (corgidrp.data.Dataset or corgidrp.data.Image) – Image(s) to compute the calibration factor. Should already be normalized for exposure time. Output of extract_spec.
calspec_file (str, optional) – file path to the calspec fits file of the observed star. If None, it is downloaded from the calspec database
- Returns:
- A calibration object containing the computed
flux calibration factor in units erg/(s * cm^2 * AA)/(photoelectron/s/bin)
- Return type:
- corgidrp.spec.generate_filter_offset(offset_file=None)[source]#
read the csv filter file containing at least the band names and the pixel x/y offsets between the filters and generate a new SpecFilterOffset product.
- Parameters:
offset_file (str) – file name of the filter file, if none it takes data/spectroscopy/CGI_bandpass_centers.csv
- Returns:
SpecFilterOffset product
- Return type: