pycrires package

Submodules

pycrires.pipeline module

Module with the pipeline functionalities of pycrires.

class pycrires.pipeline.Pipeline(path: str | None = None, wavel_setting: str | None = None)[source]

Bases: object

Class for the data reduction pipeline. Each method creates a configuration file with default values for the EsoRex recipe that it will run. If needed, these parameters can be adjusted before rerunning a method.

cal_dark(verbose: bool = False, create_sof: bool = True) None[source]

Method for running cr2res_cal_dark.

Parameters:
  • verbose (bool) – Print output produced by esorex.

  • create_sof (bool) – Create a new SOF file. Setting the argument to True will overwrite the SOF file if already present. Setting the argument to False will allow for manually adjusting an existing SOF file if the routine had already been previously executed.

Returns:

None

Return type:

NoneType

cal_detlin(verbose: bool = False, create_sof: bool = True) None[source]

Method for running cr2res_cal_detlin.

Parameters:
  • verbose (bool) – Print output produced by esorex.

  • create_sof (bool) – Create a new SOF file. Setting the argument to True will overwrite the SOF file if already present. Setting the argument to False will allow for manually adjusting an existing SOF file if the routine had already been previously executed.

Returns:

None

Return type:

NoneType

cal_flat(verbose: bool = False, create_sof: bool = True) None[source]

Method for running cr2res_cal_flat.

Parameters:
  • verbose (bool) – Print output produced by esorex.

  • create_sof (bool) – Create a new SOF file. Setting the argument to True will overwrite the SOF file if already present. Setting the argument to False will allow for manually adjusting an existing SOF file if the routine had already been previously executed.

Returns:

None

Return type:

NoneType

cal_wave(verbose: bool = False, create_sof: bool = True) None[source]

Method for running cr2res_cal_wave.

Parameters:
  • verbose (bool) – Print output produced by esorex.

  • create_sof (bool) – Create a new SOF file. Setting the argument to True will overwrite the SOF file if already present. Setting the argument to False will allow for manually adjusting an existing SOF file if the routine had already been previously executed.

Returns:

None

Return type:

NoneType

clean_folder(keep_product: bool = True) None[source]

Method for removing all the output that is produced by the Pipeline (so not the raw data).

Parameters:

keep_product (bool) – Keep the product folder (True) or remove that folder as well (False).

Returns:

None

Return type:

NoneType

correct_wavelengths(nod_ab: str = 'A', input_folder='obs_nodding', accuracy: float = 0.002, n_grid: int = 51, window_length: int = 201, minimum_strength: float = 0.005, collapse_exposures: bool = True, create_plots: bool = False) None[source]

Method for correcting the wavelength solution with a quadratic function and maximizing the correlation with the telluric model spectrum from SkyCalc, obtained with run_skycalc(). The accuracy can be iteratively increased by also adjusting the input_folder.

Parameters:
  • nod_ab (str) – Nod position with the spectra of which the wavelength solution will be corrected.

  • input_folder (str) – Input folder from where the spectra will be read.

  • accuracy (float) – Desired accuracy in nm of the wavelength solution. This will be used to generate the grid on which the correlation with a telluric spectrum is calculated (default: 0.01 nm).

  • n_grid (int) – Number of grid points that will be tested for each of the three parameters of the quadratic function (default: 51).

  • window_length (int) – Width of the kernel (in number of pixels) that is used for estimating the continuum by smoothing with the 2nd order Savitzky-Golay filter from scipy.signal.savgol_filter (default: 201).

  • minimum_strength (float) – Minimum standard deviation of the telluric spectrum in the wavelength range of the spectral order that is used as threshold for applying the wavelength correction. If there are not enough features (i.e. the standard deviation is smaller than minimum_strength), the original wavelength solution will be saved (default: 0.005).

  • collapse_exposures (bool) – If True, the wavelength correction will be calculated using the summed spectra over all exposures, improving the S/N of the spectra.

  • create_plots (bool) – Store plots with the 2D cross-correlation maps (default: False). These maps do not show the quadratic term, for which the best-fit value is used for each pair of parameters.

Returns:

None

Return type:

NoneType

correct_wavelengths_2d(nod_ab: str = 'A', input_folder='fit_gaussian', accuracy: float = 0.002, n_grid: int = 51, window_length: int = 201, minimum_strength: float = 0.005, collapse_spatially: bool = True, collapse_exposures: bool = True, create_plots: bool = True) None[source]

Method for correcting the wavelength solution with a quadratic function and maximizing the correlation with the telluric model spectrum from SkyCalc, obtained with run_skycalc(). This function can be applied to 2D extracted spectra if the spatial dimension needs to be maintained. The accuracy can be iteratively increased by also adjusting the input_folder.

Parameters:
  • nod_ab (str) – Nod position with the spectra of which the wavelength solution will be corrected.

  • input_folder (str) – Input folder from where the spectra will be read. Either ‘custom_extract_2d’, ‘util_extract_2d’, ‘fit_gaussian’, or ‘correct_wavelengths_2d’,

  • accuracy (float) – Desired accuracy in nm of the wavelength solution. This will be used to generate the grid on which the correlation with a telluric spectrum is calculated (default: 0.01 nm).

  • n_grid (int) – Number of grid points that will be tested for each of the three parameters of the quadratic function (default: 51).

  • window_length (int) – Width of the kernel (in number of pixels) that is used for estimating the continuum by smoothing with the 2nd order Savitzky-Golay filter from scipy.signal.savgol_filter (default: 201).

  • minimum_strength (float) – Minimum standard deviation of the telluric spectrum in the wavelength range of the spectral order that is used as threshold for applying the wavelength correction. If there are not enough features (i.e. the standard deviation is smaller than minimum_strength), the original wavelength solution will be saved (default: 0.005).

  • collapse_spatially (bool) – If True, the wavelength correction will be calculated using the summed spectra over the spatial direction, improving the S/N of the spectra. However, this may result in slight errors in the wavelength solution off-axis.

  • collapse_exposures (bool) – If True, the wavelength correction will be calculated using the summed spectra over all exposures, improving the S/N of the spectra.

  • create_plots (bool) – Store plots with the 2D cross-correlation maps (default: False). These maps do not show the quadratic term, for which the best-fit value is used for each pair of parameters. One plot file is created when collapse_exposures=True.

Returns:

None

Return type:

NoneType

custom_extract_2d(nod_ab: str = 'A', spatial_sampling: float = 0.056, max_separation: float = 2.0) None[source]

Method for extracting spectra from the products of obs_nodding(), while retaining the spatial information. It is important to run obs_nodding() before custom_extract_2d(). The 2D spectra are extracted using a custom pipeline that uses the trace data from the EsoRex pipeline.

Parameters:
  • nod_ab (str) – Nod position with the spectra of which the wavelength solution will be corrected.

  • spatial_sampling (float) – Spatial interval (arcsec) over which to extract the spectrum. The default value of 0.056 arcsec is the pixel scale of the CRIRES detectors.

  • max_separation (float) – Spatial extent (arcsec) over which to extract the spectrum. The default value of 2 arcsec is the size of the slit fraction typically used for nodding observations with CRIRES.

Returns:

None

Return type:

NoneType

detection_map(model_flux: ndarray, model_wavel: ndarray, rv_grid: ndarray = array([-150., -149., -148., -147., -146., -145., -144., -143., -142., -141., -140., -139., -138., -137., -136., -135., -134., -133., -132., -131., -130., -129., -128., -127., -126., -125., -124., -123., -122., -121., -120., -119., -118., -117., -116., -115., -114., -113., -112., -111., -110., -109., -108., -107., -106., -105., -104., -103., -102., -101., -100., -99., -98., -97., -96., -95., -94., -93., -92., -91., -90., -89., -88., -87., -86., -85., -84., -83., -82., -81., -80., -79., -78., -77., -76., -75., -74., -73., -72., -71., -70., -69., -68., -67., -66., -65., -64., -63., -62., -61., -60., -59., -58., -57., -56., -55., -54., -53., -52., -51., -50., -49., -48., -47., -46., -45., -44., -43., -42., -41., -40., -39., -38., -37., -36., -35., -34., -33., -32., -31., -30., -29., -28., -27., -26., -25., -24., -23., -22., -21., -20., -19., -18., -17., -16., -15., -14., -13., -12., -11., -10., -9., -8., -7., -6., -5., -4., -3., -2., -1., 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23., 24., 25., 26., 27., 28., 29., 30., 31., 32., 33., 34., 35., 36., 37., 38., 39., 40., 41., 42., 43., 44., 45., 46., 47., 48., 49., 50., 51., 52., 53., 54., 55., 56., 57., 58., 59., 60., 61., 62., 63., 64., 65., 66., 67., 68., 69., 70., 71., 72., 73., 74., 75., 76., 77., 78., 79., 80., 81., 82., 83., 84., 85., 86., 87., 88., 89., 90., 91., 92., 93., 94., 95., 96., 97., 98., 99., 100., 101., 102., 103., 104., 105., 106., 107., 108., 109., 110., 111., 112., 113., 114., 115., 116., 117., 118., 119., 120., 121., 122., 123., 124., 125., 126., 127., 128., 129., 130., 131., 132., 133., 134., 135., 136., 137., 138., 139., 140., 141., 142., 143., 144., 145., 146., 147., 148., 149., 150.]), vsini_grid: ndarray | None = None, nod_ab: str = 'A', input_folder: str = 'remove_systematics', hp_window_length: int = 501, error_weighted: bool = False) tuple[ndarray, ndarray, float][source]

Method for cross-correlating each row of the 2D extracted spectra with a model template.

Parameters:
  • model_flux (np.ndarray) – Template used for cross-correlation.

  • model_wavel (np.ndarray) – Wavelengths (nm) corresponding to the template.

  • rv_grid (np.ndarray) – Radial velocities (km/s) to calculate the cross-correlation on.

  • vsini_grid (np.ndarray, None) – Projected spin velocity (km/s) that is used to broaden the template spectrum. No broadening is applied if the argument is set to None, in which case the input spectrum is expected to have been broadened already. The argument is an array with \(v\sin\,i\) values for which the cross-correlation map will be calculated. For each value of \(v\sin\,i\), a subplot will be created that shows the cross-correlation as function of radial velocity and separation from the star. When using this parameter, make sure that the template of model_flux has not been broadened and make sure that the wavelengths of model_wavel are evenly spaced.

  • nod_ab (str) – Nod position which will be cross-correlated.

  • input_folder (str) – Subfolder in the product folder that contains the spectra that should be processed.

  • hp_window_length (int) – Length (in spectral pixels) of the high-pass filter applied to the template before cross-correlating. This should have the same value as ‘lp_window_length’ in the stellar removal.

  • error_weighted (bool) – If True, each spectral bin is weighted by the noise in the cross-correlation.

Returns:

  • list(np.ndarray) – List with the cross-correlation arrays. The number of arrays in the list is equal to the size of the vsini_grid.

  • np.ndarray – Array with the radial velocities (km/s) that are used for the cross-correlation.

  • float – Field of view (arcsec) along the spatial dimension that is tested with the cross-correlation.

export_spectra(nod_ab: str = 'A', corrected: bool = False) None[source]

Method for exporting the 1D extracted spectra to a JSON file. After exporting, the data can be read with Python from the JSON file into a dictionary. For example, reading the spectra of the first exposure:

>>> import json
>>> with open('product/obs_nodding/spectra_nod_A_000.json') as json_file:
...    data = json.load(json_file)
>>> print(data.keys())
Parameters:
  • nod_ab (str) – Nod position of which the extracted spectra will be exported to a JSON file (“A” or “B”).

  • corrected (bool) – Export the wavelength-corrected spectra, so the output from correct_wavelengths(). If set to False, the extracted spectra from obs_nodding() are exported.

Returns:

None

Return type:

NoneType

extract_header() None[source]

Method for extracting relevant header data from the FITS files and storing these in a DataFrame. The data will also be exported to a CSV and Excel file.

Returns:

None

Return type:

NoneType

fit_gaussian(nod_ab: str = 'A', extraction_input: str = 'custom_extract_2d') None[source]

Method for centering the 2D extracted spectra by fitting a Gaussian function to the mean of each spectral order. This method should be used after extracting the 2D spectra with util_extract_2d().

Parameters:
  • nod_ab (str) – Nod position of which the extracted spectra will be exported to a JSON file (“A” or “B”).

  • extraction_input (str) – Subfolder in the product folder that contains the spectra that should be processed. The options for this argument are either 'custom_extract_2d' or 'util_extract_2d'.

Returns:

None

Return type:

NoneType

molecfit_calctrans(nod_ab: str = 'A', verbose: bool = False) None[source]

Method for running molecfit_calctrans.

Parameters:
  • nod_ab (str) – Nod position of which the extracted spectra are plotted (“A” or “B”).

  • verbose (bool) – Print output produced by esorex.

Returns:

None

Return type:

NoneType

molecfit_correct(nod_ab: str = 'A', verbose: bool = False) None[source]

Method for running molecfit_correct.

Parameters:
  • nod_ab (str) – Nod position of which the extracted spectra are plotted (“A” or “B”).

  • verbose (bool) – Print output produced by esorex.

Returns:

None

Return type:

NoneType

molecfit_input(nod_ab: str = 'A') None[source]

Method for converting the extracted spectra into input files for Molecfit. The content of this method has been adapted from the cr2res_drs2molecfit.py code that is included with the EsoRex pipeline for CRIRES+ (see https://www.eso.org/sci/software/pipelines/cr2res/cr2res-pipe-recipes.html).

Parameters:

nod_ab (str) – Nod position of which the extracted spectra are plotted (“A” or “B”).

Returns:

None

Return type:

NoneType

molecfit_model(nod_ab: str = 'A', verbose: bool = False) None[source]

Method for running molecfit_model.

Parameters:
  • nod_ab (str) – Nod position of which the extracted spectra are plotted (“A” or “B”).

  • verbose (bool) – Print output produced by esorex.

Returns:

None

Return type:

NoneType

obs_nodding(correct_bad_pixels: bool = True, extraction_required: bool = True, check_existing: bool = False, verbose: bool = False, create_sof: bool = True) None[source]

Method for running cr2res_obs_nodding.

Parameters:
  • correct_bad_pixels (bool) – Correct the bad pixel with skimage.restoration.inpaint. If set to False, the bad pixels that were identified and marked in the bad pixel map will remain as NaN in the output images.

  • extraction_required (bool) – Set to True if accuracy of the extracted 1D spectra is important. Set to False if the extraction will be done separately, e.g. with custom_extract_2d(). In the latter case, the extracted spectra that are part of the output from obs_nodding() should be ignored. The advantage of setting the argument to False is that it very much decreases the computation time since the extract_height and extract_oversample will be adjusted.

  • check_existing (bool) – Search for existing files in the product folder. Avoids re-reducing existing files.

  • verbose (bool) – Print output produced by esorex.

  • create_sof (bool) – Create a new SOF file. Setting the argument to True will overwrite the SOF file if already present. Setting the argument to False will allow for manually adjusting an existing SOF file if the routine had already been previously executed.

Returns:

None

Return type:

NoneType

obs_nodding_irregular(unique_pairs: bool = False, correct_bad_pixels: bool = True, extraction_required: bool = True, check_existing: bool = False, verbose: bool = False, create_sof: bool = True) None[source]

Method for running cr2res_obs_nodding.

Parameters:
  • unique_pairs (bool) – In case of nods with multiple but equal numbers of exposures (e.g. AABB BBAA AABB…), pair each A uniquely to each B in sequence. So the nth A goes with the nth B and the nth B goes with the nth A. This will only be carried out if the numbers of nodding exposures is equal.

  • correct_bad_pixels (bool) – Correct bad pixels with the bad pixel map and skimage.restoration.inpaint. If set to False, the bad pixels will remain as NaN in the output images.

  • extraction_required (bool) – Set to True if accuracy of the extracted 1D spectra is important. Set to False if the extraction will be done separately, e.g. with custom_extract_2d(). In the latter case, the extracted spectra that are part of the output from obs_nodding() should be ignored. The advantage of setting the argument to False is that it very much decreases the computation time since the extract_height and extract_oversample will be adjusted.

  • check_existing (bool) – Search for existing files in the product folder. Avoids re-reducing existing files.

  • verbose (bool) – Print output produced by esorex.

  • create_sof (bool) – Create a new SOF file. Setting the argument to True will overwrite the SOF file if already present. Setting the argument to False will allow for manually adjusting an existing SOF file if the routine had already been previously executed.

Returns:

None

Return type:

NoneType

obs_staring(verbose: bool = False, check_existing: bool = True, create_sof: bool = True) None[source]

Method for running cr2res_obs_staring.

Parameters:
  • verbose (bool) – Print output produced by esorex.

  • check_existing (bool) – Search for existing extracted spectra in the product folder. Avoids re-reducing existing files.

  • create_sof (bool) – Create a new SOF file. Setting the argument to True will overwrite the SOF file if already present. Setting the argument to False will allow for manually adjusting an existing SOF file if the routine had already been previously executed.

Returns:

None

Return type:

NoneType

plot_spectra(nod_ab: str = 'A', telluric: bool = True, corrected: bool = False, file_id: int = 0) None[source]

Method for plotting the extracted spectra.

Parameters:
  • nod_ab (str) – Nod position of which the extracted spectra are plotted (“A” or “B”).

  • telluric (bool) – Plot a telluric transmission spectrum for comparison. It should have been calculated with run_skycalc().

  • corrected (bool) – Plot the wavelength-corrected spectra. The output from correct_wavelengths().

  • file_id (int) – File ID number from the FITS filename as produced by obs_nodding(). The numbers consist of three values, starting at 000. To select the first file (that contains 000), set file_id=0. For the second file, which has 001 in its filename, set file_id=1, etc.

Returns:

None

Return type:

NoneType

remove_starlight(nod_ab: str = 'A', input_folder: str = 'correct_wavelengths_2d', lp_window_length: int = 501, telluric_mask: tuple[float, float] = (0.4, 2.0), svd_broadening_kernel: bool = False) None[source]

Method for removing the stellar contribution from each row along the slit. This is done by calculating a master stellar spectrum and fitting this to the local continuum of each row. Subsequently, a correction is applied for changes in the line spread function along the slit using a singular value decomposition (SVD).

Parameters:
  • nod_ab (str) – Nod position of which the stellar contribution will be removed.

  • input_folder (str) – Subfolder in the product folder that contains the spectra that should be processed.

  • lp_window_length (int) – Length (in spectral pixels) of the low-pass filter applied to the data to fit the local continuum.

  • telluric_mask (tuple(float, float)) – Relative flux fraction to use as a cutoff for masking the deepest tellurics. E.g. ‘telluric_mask = (0.4, 2.0) will result in all spectral bins with less than 40% or more than 200% flux w.r.t the continuum to be masked.

  • svd_broadening_kernel (bool) – If True, the local line spread function is fitted for each row using an SVD. This results in better stellar subtraction but is much slower and can result in self-subtraction of the planet signal.

Returns:

None

Return type:

NoneType

remove_systematics(nod_ab: str = 'A', n_modes: int = 5, input_folder: str = 'remove_starlight', normalize: bool = True, exclude_rows: list[int] | None = None) None[source]

Method for removing systematics from the data using a principal component analysis (PCA).

Parameters:
  • nod_ab (str) – Nod position of which the PCA components will be removed.

  • n_modes (int) – Number of PCA components to subtract from each spectrum.

  • input_folder (str) – Subfolder in the product folder that contains the spectra that should be processed.

  • normalize (bool) – If true, all rows are normalized before doing the PCA.

  • exclude_rows (list, None) – Rows to exclude when building the PCA model. This is used to avoid self-subtraction of the planet signal. The input data has the following shape: (n_detectors, n_orders, n_rows, n_wavelengths), so the exclude_rows indices should be smaller than the n_rows size. No rows are excluded if the argument is set to None.

Returns:

None

Return type:

NoneType

rename_files() None[source]

Method for renaming the files from ARCFILE to ORIGFILE.

Returns:

None

Return type:

NoneType

run_recipes() None[source]

Method for running the full chain of recipes up and including obs_nodding().

Returns:

None

Return type:

NoneType

run_skycalc(pwv: float = 3.5) None[source]

Method for running the Python wrapper of SkyCalc (see https://skycalc-ipy.readthedocs.io). The wavelengths of the SkyCalc spectrum are set to vacuum wavelengths.

Parameters:

pwv (float) – Precipitable water vapor (default: 3.5) that is used for the telluric spectrum. This value will impact the depth of the telluric lines which can be seen when plotting the spectra with plot_spectra() while setting telluric=True.

Returns:

None

Return type:

NoneType

util_bpm_merge(verbose: bool = False, create_sof: bool = True) None[source]

Method for running cr2res_util_bpm_merge.

Parameters:
  • verbose (bool) – Print output produced by esorex.

  • create_sof (bool) – Create a new SOF file. Setting the argument to True will overwrite the SOF file if already present. Setting the argument to False will allow for manually adjusting an existing SOF file if the routine had already been previously executed.

Returns:

None

Return type:

NoneType

util_calib(calib_type: str, verbose: bool = False, create_sof: bool = True) None[source]

Method for running cr2res_util_calib.

Parameters:
  • calib_type (str) – Calibration type (“flat”, “une”, “fpet”, “nodding”).

  • verbose (bool) – Print output produced by esorex.

  • create_sof (bool) – Create a new SOF file. Setting the argument to True will overwrite the SOF file if already present. Setting the argument to False will allow for manually adjusting an existing SOF file if the routine had already been previously executed.

Returns:

None

Return type:

NoneType

util_extract(calib_type: str, verbose: bool = False, create_sof: bool = True) None[source]

Method for running cr2res_util_extract. If one of the orders lies partially outside the detector, then NaNs will be stored for that spectral order. Depending if the full spatial extent is needed, it is possible to adjust the cr2res.cr2res_util_extract.slit_frac parameter in the configuration files that is created after the first execution of util_extract (see config folder).

Parameters:
  • calib_type (str) – Calibration type (“flat”, “une”, or “fpet”).

  • verbose (bool) – Print output produced by esorex.

  • create_sof (bool) – Create a new SOF file. Setting the argument to True will overwrite the SOF file if already present. Setting the argument to False will allow for manually adjusting an existing SOF file if the routine had already been previously executed.

Returns:

None

Return type:

NoneType

util_extract_2d(nod_ab: str = 'A', verbose: bool = False, extraction_length: float = 0.056, spatial_oversampling: float = 1.0, use_corr_wavel: bool = True) None[source]

Method for extracting spectra from the products of obs_nodding(), while retaining the spatial information. It is important to run obs_nodding() before util_extract_2d(). The 2D spectra are extracted by running the cr2res_util_extract recipe over a range of slit fractions.

Parameters:
  • nod_ab (str) – Nod position with the spectra of which the wavelength solution will be corrected.

  • verbose (bool) – Print output produced by esorex.

  • extraction_length (float) – Spatial extent (arcsec) over which to extract the spectrum. The default value of 0.056 arcsec is the pixel scale of the CRIRES detectors.

  • spatial_oversampling (float) – Oversampling factor for the extraction along the slit length. For example, with spatial_oversampling=2, the end result will have twice as many spatial pixels as the original images.

  • use_corr_wavel (bool) – Use the wavelength solution obtained with correct_wavelengths() when set to True. Otherwise, the original wavelength solution is used that is determined by the EsoRex recipes.

Returns:

None

Return type:

NoneType

util_extract_science(slit_fraction: list, nod_ab: str = 'A', verbose: bool = False) None[source]

Method for extracting spectra from the products of obs_nodding() for specific slit fractions. This can for example be used when there are multiple objects in the field of view. It is important to run obs_nodding() before util_extract_science().

Parameters:
  • slit_fraction (list) – Spatial extent (in slit fraction) over which to extract the spectrum. These values should be between 0 and 1.

  • nod_ab (str) – Nod position with the spectra of which the wavelength solution will be corrected.

  • verbose (bool) – Print output produced by esorex.

Returns:

None

Return type:

NoneType

util_genlines(verbose: bool = False, create_sof: bool = True) None[source]

Method for running cr2res_util_genlines. Generate spectrum calibration FITS tables.

Parameters:
  • verbose (bool) – Print output produced by esorex.

  • create_sof (bool) – Create a new SOF file. Setting the argument to True will overwrite the SOF file if already present. Setting the argument to False will allow for manually adjusting an existing SOF file if the routine had already been previously executed.

Returns:

None

Return type:

NoneType

util_normflat(verbose: bool = False, create_sof: bool = True) None[source]

Method for running cr2res_util_normflat.

Parameters:
  • verbose (bool) – Print output produced by esorex.

  • create_sof (bool) – Create a new SOF file. Setting the argument to True will overwrite the SOF file if already present. Setting the argument to False will allow for manually adjusting an existing SOF file if the routine had already been previously executed.

Returns:

None

Return type:

NoneType

util_slit_curv(plot_trace: bool = False, verbose: bool = False, create_sof: bool = True) None[source]

Method for running cr2res_util_slit_curv.

Parameters:
  • plot_trace (bool) – Plot the traces of the spectral orders on the raw data.

  • verbose (bool) – Print output produced by esorex.

  • create_sof (bool) – Create a new SOF file. Setting the argument to True will overwrite the SOF file if already present. Setting the argument to False will allow for manually adjusting an existing SOF file if the routine had already been previously executed.

Returns:

None

Return type:

NoneType

util_trace(plot_trace: bool = False, verbose: bool = False, create_sof: bool = True) None[source]

Method for running cr2res_util_trace.

Parameters:
  • plot_trace (bool) – Plot the traces of the spectral orders on the raw data.

  • verbose (bool) – Print output produced by esorex.

  • create_sof (bool) – Create a new SOF file. Setting the argument to True will overwrite the SOF file if already present. Setting the argument to False will allow for manually adjusting an existing SOF file if the routine had already been previously executed.

Returns:

None

Return type:

NoneType

util_wave(calib_type: str, poly_deg: int = 0, wl_err: float = 0.1, verbose: bool = False, create_sof: bool = True) None[source]

Method for running cr2res_util_wave.

Parameters:
  • calib_type (str) – Calibration type (“une” or “fpet”).

  • poly_deg (int) – Polynomial degree for fitting the wavelength solution.

  • wl_err (float) – Estimate wavelength error (in nm).

  • verbose (bool) – Print output produced by esorex.

  • create_sof (bool) – Create a new SOF file. Setting the argument to True will overwrite the SOF file if already present. Setting the argument to False will allow for manually adjusting an existing SOF file if the routine had already been previously executed.

Returns:

None

Return type:

NoneType

pycrires.util module

Module with utility functions for pycrires.

pycrires.util.fastRotBroad(wvl, flux, epsilon, vsini, effWvl=None)[source]

Apply rotational broadening using a single broadening kernel. Function copied from PyAstronomy package.

The effect of rotational broadening on the spectrum is wavelength dependent, because the Doppler shift depends on wavelength. This function neglects this dependence, which is weak if the wavelength range is not too large.

Note

numpy.convolve is used to carry out the convolution and “mode = same” is used. Therefore, the output will be of the same size as the input, but it will show edge effects.

Parameters:
  • wvl (array) – The wavelength

  • flux (array) – The flux

  • epsilon (float) – Linear limb-darkening coefficient

  • vsini (float) – Projected rotational velocity in km/s.

  • effWvl (float, optional) – The wavelength at which the broadening kernel is evaluated. If not specified, the mean wavelength of the input will be used.

Returns:

Broadened spectrum – The rotationally broadened output spectrum.

Return type:

array

pycrires.util.fit_svd_kernel(order_flux: ndarray, order_wl: ndarray, star_model: ndarray, max_shift: int = 50, rcond: float = 0.001) ndarray[source]

Function that tries to determine the line spread function of each row using a Singular Value Decomposition.

Parameters:
  • order_flux (np.ndarray) – 2D spectrum (N_rows, N_wavelengths) to apply the masking to.

  • order_wl (np.ndarray) – 2D array (N_rows, N_wavelengths) corresponding to the wavelength at each bin.

  • star_model (np.ndarray) – 2D array (N_rows, N_wavelengths) with the estimated stellar contribution to each row.

  • max_shift (int) – Maximum allowed shift (in pixels) for the line spread function kernel.

  • rcond (float) – Cutoff for small singular values in the inversion.

Returns:

result – 2D array (N_rows, N_wavelengths) with the stellar contribution to each row corrected for the local line spread function.

Return type:

np.ndarray

pycrires.util.flag_outliers(order_flux: ndarray, sigma: float = 4.0, fill_value: float = nan) ndarray[source]

Function that flags outliers in a 2D spectrum.

Parameters:
  • order_flux (np.ndarray) – 2D spectrum (N_rows, N_wavelengths) to flag.

  • sigma (float) – Values with a ‘sigma’ standard deviations from the mean will be flagged.

  • fill_value (float) – Value to replace the outliers with

Returns:

order_flux – 2D spectrum (N_rows, N_wavelengths) with flagged values.

Return type:

np.ndarray

pycrires.util.highpass_filter(order_flux: ndarray, window_length: int) ndarray[source]

Function that high-pass filters a spectrum.

Parameters:
  • flux (np.ndarray) – Spectrum to high-pass filter

  • window_length (int) – Length of the Savitsky-Golay filter to use

Returns:

filtered – The high-pass filtered spectrum

Return type:

np.ndarray

pycrires.util.load_bt_settl_template(t_eff: float, log_g: float, vsini: float | None = None, wl_lims: tuple[float, float] = (0.8, 3.0)) tuple[ndarray, ndarray][source]

Function that loads a BT-SETTL template for the given temperature, surface gravity and vsin(i).

Parameters:
  • t_eff (float) – Effective temperature of the model to load. The grid has a resolution of 100 K, so will be rounded to the nearest value.

  • log_g (float) – Surface gravity of the model to load. The grid has a resolution of 0.5 dex, so will be rounded to the nearest value.

  • vsini (float, None) – Rotational velocity of the model to load used for the broadening kernel. The broadening is not applied if the argument is set to None.

  • wl_lim (tuple(float, float)) – Lower and upper limits (in micron) of the wavelength range to load.

Returns:

  • np.ndarray – Flux of the planetary template (in erg/s).

  • np.ndarray – Wavelengths.

pycrires.util.lowpass_filter(flux: ndarray, window_length: int) ndarray[source]

Function that low-pass filters a spectrum.

Parameters:
  • flux (np.ndarray) – Spectrum to low-pass filter

  • window_length (int) – Length of the Savitsky-Golay filter to use

Returns:

filtered: np.ndarray The low-pass filtered spectrum

Return type:

NoneType

pycrires.util.mask_tellurics(order_flux: ndarray, order_wl: ndarray, lower_lim: float = 0.5, upper_lim: float = 2.0, fill_val: float = nan) ndarray[source]

Function that masks telluric absorption or emission lines.

Parameters:
  • order_flux (np.ndarray) – 2D spectrum (N_rows, N_wavelengths) to apply the masking to.

  • order_wl (np.ndarray) – 2D array (N_rows, N_wavelengths) corresponding to the wavelength at each bin.

  • lower_lim (float) – Lower limit for the masking. A value of 0.5 will mask all tellurics that have less than 50% flux w.r.t to the continuum envelope.

  • upper_lim (float) – Upper limit for the masking. A value of 2. will mask all tellurics that have more than 100% excess flux w.r.t to the continuum envelope.

  • fill_val (float) – Value to fill the masked bins with.

Returns:

masked_order – 2D spectrum (N_rows, N_wavelengths) with applied masking.

Return type:

np.ndarray

Module contents