def transitDuration_Rs(sma, rprs, inc, period, exact=False): """ Calculate transit duration Invokes :py:func:`transitDuration` after parameter transformation. Parameters ---------- sma : float Semi-major axis [stellar radii] rprs : float Planet-to-star radius ratio (Rp/Rs) inc : float Orbital inclination [deg] period : float Orbital period exact : boolean, optional If True, a slightly more accurate expression is evaluated. The default is False. Returns ------- Transit duration : float The duration of the transit (same units as `period`). """ from PyAstronomy import constants as PC c = PC.PyAConstants() rs = c.RSun return transitDuration(sma*rs/c.AU, rprs*rs/c.RJ, 1., inc, period, exact)
def transitDuration(sma, rp, rs, inc, period, exact=False): """ Calculate the transit duration. The routine calculates the transit duration assuming a spherical star and planet and a circular planetary orbit. It evaluates the expression .. math:: T_D = \\frac{P}{\\pi} \\arcsin\\left(\\frac{\\sqrt{(R_s+R_p)^2 - b^2}}{a} \\right) where P is the orbital period, b the impact parameter (:math:`b=a \\cos(i)`), and a the semi-major axis. If the `exact` flag is set True, the slightly more accurate expression .. math:: T_D = \\frac{P}{\\pi} \\arcsin\\left(\\frac{\\sqrt{(R_s+R_p)^2 - b^2}}{a \\sin(i)} \\right) is evaluated, where the additional sine term accounts for orbit curvature. .. note:: The units of the transit duration are the same as the units of the input orbital period. Parameters ---------- sma : float The semi-major axis in AU. rp : float The planetary radius in Jovian radii. rs : float The stellar radius in solar radii. inc : float The orbital inclination in degrees. period : float The orbital period. exact : boolean, optional If True, a slightly more accurate expression is evaluated. The default is False. Returns ------- Transit duration : float The duration of the transit (same units as `period`). """ from PyAstronomy import constants as PC c = PC.PyAConstants() # Calculate the impact parameter impact = (sma * c.AU) * np.cos(inc / 180. * np.pi) # Correction factor (inclination dependent factor) cfac = 1.0 if not exact else np.sin(inc / 180. * np.pi) # Calculate the geometric transit duration dur = (period / np.pi) * \ np.arcsin(np.sqrt((rs * c.RSun + rp * c.RJ) ** 2 - impact**2) / (sma * c.AU * cfac)) return dur
def ingressDuration_Rs(sma, rprs, inc, period): """ Calculate transit duration Invokes :py:func:`transitDuration` after parameter transformation. Parameters ---------- sma : float Semi-major axis [stellar radii] rprs : float Planet-to-star radius ratio (Rp/Rs) inc : float Orbital inclination [deg] period : float Orbital period Returns ------- Transit duration : float The duration of the transit (same units as `period`). """ from PyAstronomy import constants as PC c = PC.PyAConstants() rs = c.RSun return ingressDuration(sma*rs/c.AU, rprs*rs/c.RJ, 1., inc, period)
def planck(T, lam=None, nu=None): """ Evaluate Planck's radiation law. Depending on whether wavelength or frequency is specified as input, the function evaluates: .. math:: B_{\\nu} = \\frac{2\\pi h \\nu^3}{c^2} \\frac{1}{e^{\\frac{h\\nu}{kT}} - 1} or .. math:: B_{\\lambda} = \\frac{2\\pi h c^2}{\\lambda^5} \\frac{1}{e^{\\frac{h c}{\\lambda kT}} - 1} \\; . If lambda is given (in meters), the output units are W/(m^2 m). To convert into erg/(cm^2 A s), the output has to be multiplied by a factor of 1e-7. Parameters ---------- T : float Temperature in Kelvin. lam : float or array, optional Wavelength in meters. nu : float or array, optional Frequency in Hz. Returns ------- Spectral radiance : float or array Depending on whether `lam` or `nu` were specified, returns the spectral radiance per area and wavelength or frequency. The unit (SI) will be W/(m^2 m) if `lam` was given and W/(m^2 Hz) if `nu` was specified. """ if _ic.check["quantities"]: from PyAstronomy import constants c = constants.PyAConstants(unitSystem="SI") else: raise (PE.PyARequiredImport( "You need to install 'quantities' to use this function.\n 'quantities' can be obtained from 'http://pypi.python.org/pypi/quantities'." )) return None if (lam is not None) and (nu is not None): raise (PE.PyAParameterConflict( "Specify either 'lam' OR 'nu', but not both.")) if (lam is None) and (nu is None): raise (PE.PyAParameterConflict("Specify either 'lam' OR 'nu'.")) # Parameters have been specified properly if lam is not None: result = 2. * np.pi * c.h * (c.c**2) / (lam**5) result /= (np.exp(c.h * c.c / (lam * c.k * T)) - 1.0) return result elif nu is not None: result = 2. * np.pi * c.h * (nu**3) / (c.c**2) result /= (np.exp(c.h * nu / (c.k * T)) - 1.0) return result
def thermalBroadeningWidth(lam0, T, m=None, fwhm=True): """ Calculate the width for thermal broadening. Thermal motion of particles causes a Doppler broadening of the line profile. The resulting line profile is Gaussian with FWHM given by .. math:: fwhm = \\lambda_0\\sqrt{\\frac{8k_B T\\ln(2)}{m c^2}} See, e.g., http://hyperphysics.phy-astr.gsu.edu/hbase/atomic/broaden.html Parameters ---------- lam0 : float Wavelength at which to calculate the width. T : float Temperature [K]. m : float, optional Mass of the particles [kg]. If not specified, the proton mass is assumed. fwhm : boolean, optional If True (default), the FWHM of the Gaussian broadening kernel will be returned. Otherwise, the standard deviation is returned. Returns ------- Width : float The width of the Gaussian broadening kernel. By default, the FWHM is returned. To obtain the standard deviation, set the `fwhm` flag to False. """ from PyAstronomy import constants as PC pc = PC.PyAConstants() pc.setSystem("SI") if m is None: # Use proton mass if not specified otherwise m = pc.mp result = lam0 * np.sqrt(8.0 * pc.k * T * np.log(2.0) / (m * (pc.c)**2)) if not fwhm: return result / (2.0 * np.sqrt(2.0 * np.log(2.0))) else: return result
def ingressDuration(sma, rp, rs, inc, period): """ Calculate the ingress (and egress) duration of the transit. The routine calculates the transit in- and egress duration assuming a spherical star and planet and a circular planetary orbit. It evaluates the expression .. math:: T_I = \\frac{P}{2 \\pi} \\left( \\arcsin\\left(\\frac{\\sqrt{(R_s+R_p)^2 - b^2}}{a \\sin(i)} \\right) - \\arcsin\\left(\\frac{\\sqrt{(R_s-R_p)^2 - b^2}}{a \\sin(i)} \\right) \\right) is evaluated, where b is the impact parameter (:math:`b=a \\cos(i)`). .. note:: The units of the ingress duration are the same as the units of the input orbital period. Parameters ---------- sma : float The semi-major axis in AU. rp : float The planetary radius in Jovian radii. rs : float The stellar radius in solar radii. inc : float The orbital inclination in degrees. period : float The orbital period. Returns ------- Ingress duration : float The duration of in- and egress (same units as `period`). """ from PyAstronomy import constants as PC c = PC.PyAConstants() # Calculate the impact parameter impact = (sma * c.AU) * np.cos(inc / 180. * np.pi) imsin = (sma * c.AU) * np.sin(inc / 180. * np.pi) # Calculate the geometric transit duration idur = (period / (2.*np.pi)) * ( \ np.arcsin(np.sqrt((rs * c.RSun + rp * c.RJ)** 2 - impact**2) / imsin) - \ np.arcsin(np.sqrt((rs * c.RSun - rp * c.RJ)** 2 - impact**2) / imsin) \ ) return idur
def transitDuration(sma, rp, rs, inc, period): """ Calculate the transit duration. The routine calculates the transit duration assuming a circular star and planet and a circular planetary orbit. In particular, it evaluates: .. math:: T_D = \\frac{P}{\\pi} \\arcsin\\left(\\frac{\\sqrt{(R_s+R_p)^2 - b^2}}{a} \\right) where P is the orbital period, b the impact parameter (:math:`b=a/R_s\\cos(i)`), and a the semi-major axis. .. note:: The units of the transit duration are the same as the units of the input orbital period. Parameters ---------- sma : float The semi-major axis in AU. rp : float The planetary radius in Jovian radii. rs : float The stellar radius in solar radii. inc : float The orbital inclination in degrees. period : float The orbital period. Returns ------- Transit duration : float The duration of the transit (same units as `period`). """ from PyAstronomy import constants as PC c = PC.PyAConstants() # Calculate the impact parameter impact = (sma * c.AU) * np.cos(inc / 180. * np.pi) # Calculate the geometric transit duration dur = (period / np.pi) * \ np.arcsin(np.sqrt((rs * c.RSun + rp * c.RJ) ** 2 - impact**2) / (sma * c.AU)) return dur
def tempFromthermalBroadeningWidth(lam0, width, m=None, awidth=0.0): """ Calculate the temperature required to obtain thermal broadening width. Thermal motion of particles causes Doppler broadening of the line profile. The resulting line profile is Gaussian with FWHM given by .. math:: fwhm = \\lambda_0\\sqrt{\\frac{8k_B T\\ln(2)}{m c^2}} See, e.g., http://hyperphysics.phy-astr.gsu.edu/hbase/atomic/broaden.html Here, the relation is reversed, so that the temperature, T, can be obtained from the width. The relation is only strictly valid in the case of Gaussian lines. .. note:: Units of lam0, width, and awidth have to be consistent. Parameters ---------- lam0 : float Wavelength at which to width (FWHM) was measured. width : float Measured width of the feature (FWHM) m : float, optional Mass of the particles [kg]. If not specified, the proton mass is assumed. awidth : float Additional width contributed by other effects such as instrumental resolution. The thermal width, ft, is obtained by quadratic subtraction, i.e., ft**2 = width**2 - awidth**2. Default is zero. Returns ------- Temperature : float The temperature required to achieve the specified broadening width. Thermal width : float The thermal width used in the calculations (may be modified if `awidth` has been specified. """ from PyAstronomy import constants as PC pc = PC.PyAConstants() pc.setSystem("SI") if m is None: # Use proton mass if not specified otherwise m = pc.mp if awidth > width: raise(PE.PyAValError("The additional width (awidth) is larger than the specified width of the feature.", \ where="tempFromthermalBroadeningWidth", \ solution="Check width specification.")) # Take into account additional width width = np.sqrt(width**2 - awidth**2) result = width**2 / lam0**2 * (m * (pc.c)**2) / (8.0 * pc.k * np.log(2.0)) return result
def __init__(self, ccfs="rutten", afc="middelkoop", rphot="noyes"): """ Converting Mount-Wilson S-index into RHK index. The Mount-Wilson S-index is a measure of the emission-line cores of the Ca II H and K lines at about 3933 A and 3968 A in two narrow bands normalized by two adjacent continuum bands. The activity index RHK is closely related to the S-index. In particular, it gives the emission in the narrow bands normalized by the bolometric brightness of the star .. math:: R_{HK} = \\frac{4\\pi R_s^2 (F_H + F_K)}{4\\pi R_s^2\\sigma T_{eff}^4} = \\frac{F_H+F_K}{\\sigma T_{eff}^4} \\; . The stellar surface flux in "arbitrary units" in the narrow H and K bands (fH + fK) is related to the Mount-Wilson S-index through the relation .. math:: f_H + f_K = S C_{cf} T_{eff}^4 10^{-14} \\; , where Ccf is a conversion factor, which can be parameterized in terms of the B-V color and the luminosity class. The conversion between arbitrary units and physical units, needed to derive the true surface flux and the RHK index, has been derived by several authors starting with Middelkoop 1982. Their factor was also used by Noyes et al. 1984---in particular in their appendix a, where is appears implicitly. Later, the value of the conversion factor has been revised by several authors, e.g., Oranje 1983 and Rutten 1984, who estimated a value about 70% larger than previously proposed. Hall et al. 2007 derive a value 40% larger than that of Middelkoop 1982 and provide a thorough discussion on the differences between the individual approaches and results given in the literature. Finally, the RHK index thus derived still covers a photospheric contribution, which is always present and not related to the chromosphere. To obtain the purely chromospheric, primed RHK index, an estimate of the photospheric surface flux in the H and K pass-bands has to be subtracted. For active stars, the photospheric correction is usually quite irrelevant. For inactive, quiet stars, it can, however, be important. The issue of the Mount-Wilson S-index conversion has been revisited by Mittag et al. 2013, who provide an alternative conversion procedure and revised photospheric corrections for various luminosity classes. .. note:: In the default configuration, the conversion of the S-index into RHK is identical to the relation stated by Noyes et al. 1984 in their appendix (a) .. math:: R_{HK} = 1.340 \\times 10^{-4} C_{cf} S where the factor 1.34e-4 is a combination of the conversion from arbitrary to physical units, 1e-14, and the Stefan-Boltzmann constant, in particular 1.34e-4 = 7.6e5*1e-14/5.67e-5. The Ccf factor is, however, calculated according to Rutten 1984. The relations and coefficients used here are taken from the following publications (and references therein): - Middelkoop 1982, A&A 107, 31 - Oranje 1983, A&A 124, 43 - Noyes et al. 1984, A&A 279, 763 - Rutten 1984, A&A 130, 353 - Hall et al. 2007, AJ 133, 862 - Mittag et al. 2013, A&A 549, 117 Parameters ---------- ccfs : string, {rutten, noyes}, optional Source of the conversion factor between S-index and RHK. afc : string, {rutten, oranje, middelkoop, hall}, optional Source of conversion factor between "arbitrary units" and physical units of surface flux. rphot : string, {noyes} The source for the photospheric correction for the RHK index. """ if ccfs == "rutten": self._log10ccf = self.log10ccfRutten elif ccfs == "noyes": self._log10ccf = self.log10ccfNoyes else: raise(PE.PyAValError("No such Ccf source: " + str(ccfs), \ solution="Use 'rutten' or 'noyes'.")) self._ccfs = ccfs if rphot == "noyes": self._logrphot = self.logRphotNoyes else: raise(PE.PyAValError("No such source for the photospheric correction: " + str(rphot), \ solution="Use 'noyes'.")) self._rphots = rphot self._afc = afc # The conversion factor from "arbitrary units" to physical units. self._absCal = { "rutten": 1.29e6, "oranje": 1.21e6, "middelkoop": 7.6e5, "hall": 1.07e6 } if not self._afc in self._absCal: raise(PE.PyAValError("No such source for the conversion from arbitrary to physical units: " + str(self._afc), \ solution="Use either of: " + ', '.join(self._absCal.keys()) )) from PyAstronomy.pyasl import _ic if not _ic.check["quantities"]: raise(PE.PyARequiredImport("The 'quantities' package is not installed, which is required to use 'SMW_RHK'.", \ where="SMW_RHK", \ solution="Install quantities (https://pypi.python.org/pypi/quantities/0.10.1).")) from PyAstronomy import constants as PC self._pc = PC.PyAConstants() self._pc.setSystem("cgs")