tools

tools.nearest_index(array, target_value)[source]

Finds the index of a value in array that is closest to target_value.

Parameters
array (``numpy.array``):

Target array.

target_value (``float``):

Target value.

Returns
index (int):

Index of the value in array that is closest to target_value.

tools.generate_muscles_spectrum(host_star_name, muscles_dir, semi_major_axis, truncate_wavelength_grid=False, cutoff_thresh=13.6)[source]

Construct a dictionary containing an input spectrum from a MUSCLES spectrum. MUSCLES reports spectra as observed at Earth, the code scales this to the spectrum received at your planet provided a value for the scaled semi-major axis a_rs.

Parameters
host_star_name (``str``):

Name of the stellar spectrum you want to use in MUSCLES. Must be one of: [‘gj176’, ‘gj436’, ‘gj551’, ‘gj581’, ‘gj667c’, ‘gj832’, ‘gj876’, ‘gj1214’, ‘hd40307’, ‘hd85512’, ‘hd97658’, ‘v-eps-eri’].

muscles_dir (``str``):

Path to the directory with the MUSCLES data.

semi_major_axis (``float``):

Semi-major axis of the planet in units of stellar radii. The code first converts the MUSCLES spectrum to what it would be at R_star; semi_major_axis is needed to get the spectrum at the planet.

truncate_wavelength_grid (``bool``, optional):

If True, will only return the spectrum with energy > 13.6 eV. This may be useful for computational expediency. If False, returns the whole spectrum. Default is False.

cutoff_thresh (`float`, optional):

If truncate_wavelength_grid is set to True, then the truncation happens for energies whose value in eV is above this threshold, also in eV. Default is 13.6.

Returns
spectrum (dict):

Spectrum dictionary with entries for the wavelength and flux, and their units.

tools.make_spectrum_from_file(filename, units, path='', skiprows=0, scale_flux=1.0)[source]

Construct a dictionary containing an input spectrum from a text file. The input file must have two or more columns, in which the first is the wavelength or frequency bin center and the second is the flux per bin of wavelength or frequency. The code automatically figures out if the input spectra are binned in wavelength or frequency based on the units the user passes.

Parameters
filename (``str``):

Name of the file containing the spectrum data.

units (``dict``):

Units of the spectrum. This dictionary must have the entries 'wavelength' and 'flux', or 'frequency' and 'flux'. The units must be set in astropy.units.

path (``str``, optional):

Path to the spectrum data file.

skiprows (``int``, optional):

Number of rows to skip corresponding to the header of the input text file.

scale_flux (``float``, optional):

Scaling factor for flux. Default value is 1.0 (no scaling).

Returns
spectrum (dict):

Spectrum dictionary with entries for the wavelength and flux, and their units.