Utils
Created on Wed Jul 20 08:51 2022
@author: MCR
Miscellaneous pipeline tools.
- exotedrf.utils.do_replacement(frame, badpix_map, dq=None, box_size=5)
Replace flagged pixels with the median of a surrounding box.
- Parameters:
frame (array-like[float]) – Data frame.
badpix_map (array-like[bool]) – Map of pixels to be replaced.
dq (array-like[int]) – Data quality flags.
box_size (int) – Size of box to consider.
- Returns:
frame_out (array-like[float]) – Input frame wth pixels interpolated.
dq_out (array-like[int]) – Input dq map with interpolated pixels set to zero.
- exotedrf.utils.download_stellar_spectra(st_teff, st_logg, st_met, outdir)
Download a grid of PHOENIX model stellar spectra.
- Parameters:
st_teff (float) – Stellar effective temperature.
st_logg (float) – Stellar log surface gravity.
st_met (float) – Stellar metallicity as [Fe/H].
outdir (str) – Output directory.
- Returns:
wfile (str) – Path to wavelength file.
ffiles (list[str]) – Path to model stellar spectrum files.
- exotedrf.utils.fancyprint(message, msg_type='INFO')
Fancy printing statement mimicking logging. Basically a hack to get around complications with the STScI pipeline logging.
- Parameters:
message (str) – Message to print.
msg_type (str) – Type of message. Mirrors the jwst pipeline logging.
- exotedrf.utils.format_out_frames(out_frames)
Create a mask of baseline flux frames for lightcurve normalization.
- Parameters:
out_frames (int, array-like[int]) – Integration numbers of ingress and/or egress.
- Returns:
baseline_ints – Array of baseline frames.
- Return type:
array-like[int]
- exotedrf.utils.get_default_header()
Format the default header for the lightcurve file.
- Returns:
header_dict (dict) – Header keyword dictionary.
header_commets (dict) – Header comment dictionary.
- exotedrf.utils.get_dq_flag_metrics(dq_map, flags)
Take a data quality map and extract a map of pixels which are flagged for a specific reason. A list of data quality flags can be found here: https://jwst-reffiles.stsci.edu/source/data_quality.html.
- Parameters:
dq_map (array-like(float)) – Map of data quality flags.
flags (list[str], str) – Flag types to find.
- Returns:
flagged – Boolean map where True values have the applicable flag.
- Return type:
np.array(bool)
- exotedrf.utils.get_filename_root(datafiles)
Get the file name roots for each segment. Assumes that file names follow the default jwst pipeline structure and are in correct segment order.
- Parameters:
datafiles (array-like[str], array-like[jwst.datamodel]) – Datamodels, or paths to datamodels for each segment.
- Returns:
fileroots – List of file name roots.
- Return type:
array-like[str]
- exotedrf.utils.get_filename_root_noseg(fileroots)
Get the file name root for a SOSS TSO with no segment information.
- Parameters:
fileroots (array-like[str]) – File root names for each segment.
- Returns:
fileroot_noseg – File name root with no segment information.
- Return type:
str
- exotedrf.utils.get_interp_box(data, box_size, i, j, dimx)
Get median and standard deviation of a box centered on a specified pixel.
- Parameters:
data (array-like[float]) – Data frame.
box_size (int) – Size of box to consider.
i (int) – X pixel.
j (int) – Y pixel.
dimx (int) – Size of x dimension.
- Returns:
box_properties – Median and standard deviation of pixels in the box.
- Return type:
array-like
- exotedrf.utils.get_stellar_param_grid(st_teff, st_logg, st_met)
Given a set of stellar parameters, determine the neighbouring grid points based on the PHOENIX grid steps.
- Parameters:
st_teff (float) – Stellar effective temperature.
st_logg (float) – Stellar log surface gravity.
st_met (float) – Stellar metallicity as [Fe/H].
- Returns:
teffs (list[float]) – Effective temperature grid bounds.
loggs (list[float]) – Surface gravity grid bounds.
mets (list[float]) – Metallicity grid bounds.
- exotedrf.utils.get_trace_centroids(deepframe, tracetable, subarray, save_results=True, save_filename='')
Get the trace centroids for all three orders via the edgetrigger method.
- Parameters:
deepframe (array-like[float]) – Median stack.
tracetable (str) – Path to SpecTrace reference file.
subarray (str) – Subarray identifier.
save_results (bool) – If True, save results to file.
save_filename (str) – Filename of save file.
- Returns:
cen_o1 (array-like[float]) – Order 1 X and Y centroids.
cen_o2 (array-like[float]) – Order 2 X and Y centroids.
cen_o3 (array-like[float]) – Order 3 X and Y centroids.
- exotedrf.utils.get_wavebin_limits(wave)
Determine the upper and lower limits of wavelength bins centered on a given wavelength axis.
- Parameters:
wave (array-like[float]) – Wavelengh array.
- Returns:
bin_low (array-like[float]) – Lower edge of wavelength bin.
bin_up (array-like[float]) – Upper edge of wavelength bin.
- exotedrf.utils.interpolate_stellar_model_grid(model_files, st_teff, st_logg, st_met)
Given a grid of stellar spectrum files, interpolate the model spectra to a set of stellar parameters.
- Parameters:
model_files (list[str]) – List of paths to stellar spectra at grid points.
st_teff (float) – Stellar effective temperature.
st_logg (float) – Stellar log surface gravity.
st_met (float) – Stellar metallicity as [Fe/H].
- Returns:
model_interp – Model stellar spectrum interpolated to the input paramaters.
- Return type:
array-like(float)
- exotedrf.utils.line_mle(x, y, e)
Analytical solution for Chi^2 of fitting a straight line to data. All inputs are assumed to be 3D (ints, dimy, dimx).
- Parameters:
x (array-like[float]) – X-data. Median stack for 1/f correction.
y (array-like[float]) – Y-data. Data frames for 1/f correction.
e (array-like[float]) – Errors.
- Returns:
m_e (np.array(float)) – “Slope” values for even numbered columns.
b_e (np.array(float)) – “Intercept” values for even numbered columns.
m_o (np.array(float)) – “Slope” values for odd numbered columns.
b_o (np.array(float)) – “Intercept” values for odd numbered columns.
- exotedrf.utils.make_deepstack(cube)
Make deep stack of a TSO.
- Parameters:
cube (array-like[float]) – Stack of all integrations in a TSO
- Returns:
deepstack – Median of the input cube along the integration axis.
- Return type:
array-like[float]
- exotedrf.utils.open_filetype(datafile)
Open a datamodel whether it is a path, or the datamodel itself.
- Parameters:
datafile (str, jwst.datamodel) – Datamodel or path to datamodel.
- Returns:
data – Opened datamodel.
- Return type:
jwst.datamodel
- Raises:
ValueError – If the filetype passed is not str or jwst.datamodel.
- exotedrf.utils.outlier_resistant_variance(data)
Calculate the varaince of some data along the 0th axis in an outlier resistant manner.
- exotedrf.utils.parse_config(config_file)
Parse a yaml config file.
- Parameters:
config_file (str) – Path to config file.
- Returns:
config – Dictionary of config parameters.
- Return type:
dict
- exotedrf.utils.save_extracted_spectra(filename, wl1, wu1, f1, e1, wl2, wu2, f2, e2, t, header_dict=None, header_comments=None, save_results=True)
Pack stellar spectra into a fits file.
- Parameters:
filename (str) – File to which to save results.
wl1 (array-like[float]) – Order 1 wavelength bin lower limits.
wu1 (array-like[float]) – Order 1 wavelength bin upper limits.
f1 (array-like[float]) – Order 1 flux.
e1 (array-like[float]) – Order 1 flux error.
wl2 (array-like[float]) – Order 2 wavelength bin lower limits.
wu2 (array-like[float]) – Order 2 wavelength bin upper limits.
f2 (array-like[float]) – Order 2 flux.
e2 (array-like[float]) – Order 2 flux error.
t (array-like[float]) – Time axis.
header_dict (dict) – Header keywords and values.
header_comments (dict) – Header comments.
save_results (bool) – If True, save results to file.
- Returns:
param_dict – Lightcurve parameters packed into a dictionary.
- Return type:
dict
- exotedrf.utils.save_ld_priors(wave, c1, c2, order, target, m_h, teff, logg, outdir)
Write model limb darkening parameters to a file to be used as priors for light curve fitting.
- Parameters:
wave (array-like[float]) – Wavelength axis.
c1 (array-like[float]) – c1 parameter for two-parameter limb darkening law.
c2 (array-like[float]) – c2 parameter for two-parameter limb darkening law.
order (int) – SOSS order.
target (str) – Name of the target.
m_h (float) – Host star metallicity.
teff (float) – Host star effective temperature.
logg (float) – Host star gravity.
outdir (str) – Directory to which to save file.
- exotedrf.utils.sigma_clip_lightcurves(flux, thresh=5, window=5)
Sigma clip outliers in time from final lightcurves.
- Parameters:
flux (array-like[float]) – Flux array.
thresh (int) – Sigma level to be clipped.
window (int) – Window function to calculate median. Must be odd.
- Returns:
flux_clipped – Flux array with outliers
- Return type:
array-like[float]
- exotedrf.utils.sort_datamodels(datafiles)
Sort a list of jwst datamodels or filenames in chronological order by segment.
- Parameters:
datafiles (array-like(str), array-like(datamodel)) – List of jwst datamodels or filenames.
- Returns:
files_sorted – Inputs sorted in chronological order.
- Return type:
np.array
- exotedrf.utils.unpack_atoca_spectra(datafile, quantities=('WAVELENGTH', 'FLUX', 'FLUX_ERROR'))
Unpack useful quantities from extract1d outputs.
- Parameters:
datafile (str, MultiSpecModel) – Extract1d output, or path to the file.
quantities (tuple(str)) – Quantities to unpack.
- Returns:
all_spec – Dictionary containing unpacked quantities for each order.
- Return type:
dict
- exotedrf.utils.unpack_input_dir(indir, filetag='', exposure_type='CLEAR')
- Get all segment files of a specified exposure type from an input data
directory.
- Parameters:
indir (str) – Path to input directory.
filetag (str) – File name extension of files to unpack.
exposure_type (str) – Either ‘CLEAR’ or ‘F277W’; unpacks the corresponding exposure type.
- Returns:
segments – File names of the requested exposure and file tag in chronological order.
- Return type:
array-like[str]
- exotedrf.utils.verify_path(path)
Verify that a given directory exists. If not, create it.
- Parameters:
path (str) – Path to directory.