The cascade.utilities module¶
Module defiing utility functions used in cascade.
- write_timeseries_to_fits(data, path, additional_file_string=None, delete_old_files=False)[source]¶
Write spectral timeseries data object to fits files.
- Parameters:
data ('ndarry' or 'SpectralDataTimeSeries') – The data cube which will be save to fits file. For each time step a fits file will be generated.
path ('str') – Path to the directory where the fits files will be saved.
additional_file_string ('str' (optional)) – Additional information to be added to the file name.
- find(pattern, path)[source]¶
Return a list of all data files.
- Parameters:
pattern ('str') – Pattern used to search for files.
path ('str') – Path to directory to be searched.
- Returns:
result (‘list’ of ‘str’) – Sorted list of filenames matching the ‘pattern’ search
- get_data_from_fits(data_files, data_list, auxilary_list)[source]¶
Read observations from fits.
This function reads in a list of fits files containing the spectral time series data and auxilary information like position and time.
- Parameters:
data_files ('list' of 'str') – List containing the names of all fits filaes to be read in.
data_list ('list' of 'str') – List containing all the fits data keywords
auxilary_list ('list' of 'str') – List containing all keywords for the auxilary data
- Returns:
data_dict (‘dict’) – Dictonary containing all spectral time series data
auxilary_dict (dict’) – Dictonary containing all auxilary data
- spectres(new_spec_wavs, old_spec_wavs, spec_fluxes, spec_errs=None)[source]¶
SpectRes: A fast spectral resampling function.
Copyright (C) 2017 A. C. Carnall Function for resampling spectra (and optionally associated uncertainties) onto a new wavelength basis.
- Parameters:
new_spec_wavs (numpy.ndarray) – Array containing the new wavelength sampling desired for the spectrum or spectra.
old_spec_wavs (numpy.ndarray) – 1D array containing the current wavelength sampling of the spectrum or spectra.
spec_fluxes (numpy.ndarray) – Array containing spectral fluxes at the wavelengths specified in old_spec_wavs, last dimension must correspond to the shape of old_spec_wavs. Extra dimensions before this may be used to include multiple spectra.
spec_errs (numpy.ndarray (optional)) – Array of the same shape as spec_fluxes containing uncertainties associated with each spectral flux value.
- Returns:
resampled_fluxes (numpy.ndarray) – Array of resampled flux values, first dimension is the same length as new_spec_wavs, other dimensions are the same as spec_fluxes
resampled_errs (numpy.ndarray) – Array of uncertainties associated with fluxes in resampled_fluxes. Only returned if spec_errs was specified.
- write_spectra_to_fits(spectral_dataset, path, filename, header_meta, column_names=['Wavelength', 'Depth', 'Error Depth'])[source]¶
Write spectra dataset object to fits files.
- Parameters:
data ('ndarray' or 'SpectralDataTimeSeries') – The data cube which will be save to fits file. For each time step a fits file will be generated.
path ('str') – Path to the directory where the fits files will be saved.
filename ('str' (optional)) – file name of save fits file.
header_meta ('dict') – All auxilary data to be written to fits header.
column_names ('list' of 'string', optional) – names of the fits table columns.
- _define_band_limits(wave)[source]¶
Define the limits of the rebin intervals.
- Parameters:
wave ('ndarray' of 'float') – Wavelengths (1D or 2D array)
- Returns:
limits (‘tuple’) – lower and upper band limits
- Raises:
TypeError – When the input wavelength array has more than 2 dimensions
ValueError – When the wavelength is not defined for each data point
- _define_rebin_weights(lr0, ur0, lr, ur)[source]¶
Define the weights used in spectral rebin.
Define the summation weights (i.e. the fractions of the original intervals used in the new interval after rebinning)
- Parameters:
lr0 ('ndarray') – lower limits wavelength band of new wavelength grid
ur0 ('ndarray') – upper limits wavelength band of new wavelength grid
lr ('ndarray') – lower limits
ur ('ndarray') – upper limits
- Returns:
weights (‘ndarray’ of ‘float’) – Summation weights used to rebin to new wavelength grid
- Raises:
TypeError – When the input wavelength array has more than 2 dimensions.
- _rebin_spectra(spectra, errors, weights)[source]¶
Rebin spectra.
- Parameters:
spectra ('ndarray') – Input spectral data values
errors ('ndarray') – Input error on spectral data values
weights ('ndarray') – rebin weights
- Returns:
newSpectra (‘ndarray’) – Output spectra
newErrors (‘ndarray’) – Output error
- write_dataset_to_fits(spectral_dataset, path, filename, header_meta)[source]¶
Write a spectral dataset to a single fits files.
- Parameters:
spectral_dataset ('SpectralDataTimeSeries') – The data cube which will be save to fits file.
path ('str') – Path to the directory where the fits files will be saved.
filename ('str' (optional)) – file name of save fits file.
header_meta ('dict') – All auxilary data to be written to fits header.
- read_dataset_from_fits(path, filename, auxilary_meta)[source]¶
Read in a spectral dataset from a single fits files.
- Parameters:
path ('str') – Path to the directory where the fits file is located.
filename ('str' (optional)) – file name of save fits file.
auxilary_meta ('list') – All auxilary data to read from fits header.
- Returns:
spectral_dataset (‘SpectralDataTimeSeries’) – The data cube read from disk.