Utility Functions¶
-
radvel.utils.
Msini
(K, P, Mstar, e, Msini_units='earth')[source]¶ Calculate Msini
Calculate Msini for a given K, P, stellar mass, and e
Parameters: - (float or array (K) – Doppler semi-amplitude [m/s]
- P (float or array) – Orbital period [days]
- Mstar (float or array) – Mass of star [Msun]
- e (float or array) – eccentricity
- Msini_units (Optional[str]) – Units of Msini {‘earth’,’jupiter’} default: ‘earth’
Returns: Msini [units = Msini_units]
Return type: float or array
-
radvel.utils.
bintels
(t, vel, err, telvec, binsize=0.5)[source]¶ Bin velocities by instrument
Bin RV data with bins of with binsize in the units of t. Will not bin data from different telescopes together since there may be offsets between them.
Parameters: - t (array) – array of timestamps
- vel (array) – array of velocities
- err (array) – array of velocity uncertainties
- telvec (array) – array of strings corresponding to the instrument name for each velocity
- binsize (float) – (optional) width of bin in units of t (default=1/2.)
Returns: (bin centers, binned measurements, binned uncertainties, binned instrument codes)
Return type: tuple
-
radvel.utils.
date2jd
(date)[source]¶ Convert datetime object to JD”
Parameters: date (datetime.datetime) – date to convert Returns: Julian date Return type: float
-
radvel.utils.
density
(mass, radius, MR_units='earth')[source]¶ Compute density from mass and radius
Parameters: - mass (float) – mass [MR_units]
- radius (float) – radius [MR_units]
- MR_units (string) – (optional) units of mass and radius. Must be ‘earth’, or ‘jupiter’ (default ‘earth’).
Returns: density in g/cc
Return type: float
-
radvel.utils.
draw_models_from_chain
(mod, chain, t, nsamples=50)[source]¶ Draw Models from Chain
Given an MCMC chain of parameters, draw representative parameters and synthesize models.
Parameters: - mod (radvel.RVmodel) – RV model
- chain (DataFrame) – pandas DataFrame with different values from MCMC chain
- t (array) – time range over which to synthesize models
- nsamples (int) – number of draws
Returns: 2D array with the different models as different rows
Return type: array
-
radvel.utils.
fastbin
(x, y, nbins=30)[source]¶ Fast binning
Fast binning function for equally spaced data
Parameters: - x (array) – independent variable
- y (array) – dependent variable
- nbins (int) – number of bins
Returns: (bin centers, binned measurements, binned uncertainties)
Return type: tuple
-
radvel.utils.
geterr
(vec, angular=False)[source]¶ Calculate median, 15.9, and 84.1 percentile values for a given vector.
Parameters: - vec (array) – vector, usually an MCMC chain for one parameter
- angular (bool [optioanl]) – Is this an angular parameter? if True vec should be in radians. This will perform some checks to ensure proper boundary wrapping.
Returns: 50, 15.9 and 84.1 percentiles
Return type: tuple
-
radvel.utils.
initialize_posterior
(config_file, decorr=False)[source]¶ Initialize Posterior object
Parse a setup file and initialize the RVModel, Likelihood, Posterior and priors.
Parameters: - config_file (string) – path to config file
- decorr (bool) – (optional) decorrelate RVs against columns defined in the decorr_vars list
Returns: (object representation of config file, radvel.Posterior object)
Return type: tuple
-
radvel.utils.
jd2date
(jd)[source]¶ Convert JD to datetime.datetime object
Parameters: jd (float) – Julian date Returns: calendar date Return type: datetime.datetime
-
radvel.utils.
load_module_from_file
(module_name, module_path)[source]¶ Loads a python module from the path of the corresponding file.
Parameters: - module_name (str) – namespace where the python module will be loaded,
e.g.
foo.bar
- module_path (str) – path of the python file containing the module
Returns: A valid module object
Raises: ImportError
– when the module can’t be loadedFileNotFoundError
– when module_path doesn’t exist
- module_name (str) – namespace where the python module will be loaded,
e.g.
-
radvel.utils.
round_sig
(x, sig=2)[source]¶ Round by significant figures :param x: number to be rounded :type x: float :param sig: (optional) number of significant figures to retain :type sig: int
Returns: x rounded to sig significant figures Return type: float
-
radvel.utils.
semi_amplitude
(Msini, P, Mtotal, e, Msini_units='jupiter')[source]¶ Compute Doppler semi-amplitude
Parameters: - Msini (float) – mass of planet [Mjup]
- P (float) – Orbital period [days]
- Mtotal (float) – Mass of star + mass of planet [Msun]
- e (float) – eccentricity
- Msini_units (Optional[str]) – Units of Msini {‘earth’,’jupiter’} default: ‘jupiter’
Returns: Doppler semi-amplitude [m/s]
-
radvel.utils.
semi_major_axis
(P, Mtotal)[source]¶ Semi-major axis
Kepler’s third law
Parameters: - P (float) – Orbital period [days]
- Mtotal (float) – Mass [Msun]
Returns: semi-major axis in AU
Return type: float or array
-
radvel.utils.
sigfig
(med, errlow, errhigh=None)[source]¶ Format values with errors into an equal number of signficant figures.
Parameters: - med (float) – median value
- errlow (float) – lower errorbar
- errhigh (float) – upper errorbar
Returns: (med,errlow,errhigh) rounded to the lowest number of significant figures
Return type: tuple
-
radvel.utils.
t_to_phase
(params, t, num_planet, cat=False)[source]¶ Time to phase
Convert JD to orbital phase
Parameters: - params (radvel.params.RVParameters) – RV parameters object
- t (array) – JD timestamps
- num_planet (int) – Which planet’s ephemeris to phase fold on
- cat (bool) – Concatenate/double the output phase array to extend from 0 to 2
Returns: orbital phase at each timestamp
Return type: array
-
radvel.utils.
time_print
(tdiff)[source]¶ Print time
Helper function to print time remaining in sensible units.
Parameters: tdiff (float) – time in seconds Returns: (float time, string units) Return type: tuple
-
radvel.utils.
timebin
(time, meas, meas_err, binsize)[source]¶ Bin in equal sized time bins
This routine bins a set of times, measurements, and measurement errors into time bins. All inputs and outputs should be floats or double. binsize should have the same units as the time array. (from Andrew Howard, ported to Python by BJ Fulton)
Parameters: - time (array) – array of times
- meas (array) – array of measurements to be comined
- meas_err (array) – array of measurement uncertainties
- binsize (float) – width of bins in same units as time array
Returns: (bin centers, binned measurements, binned uncertainties)
Return type: tuple