bioverse.util module

Miscellanous functions used elsewhere in the code.

bioverse.util.bar(arg, do_bar=True)

Given an iterable, returns a progress bar if tqdm is installed. Otherwise, returns the iterable.

Parameters:
  • arg (iterable) – Iterable for which to return a progress bar.

  • do_bar (bool) – If False, return arg and don’t display a progress bar.

Returns:

tqdm – If tqdm is installed, return a progress bar formed from arg. Otherwise, just return arg.

Return type:

iterable

bioverse.util.get_type(x)
bioverse.util.is_bool(a)
bioverse.util.as_tuple(x)

Returns the parameter as a tuple.

bioverse.util.import_function_from_file(function_name, filename)
bioverse.util.get_planet_colors(d)
bioverse.util.cycle_index(vals, val, delta)
bioverse.util.nan_fill(a, dtype=None)
bioverse.util.get_order(N)
bioverse.util.mask_from_model_subset(pl, subset)
bioverse.util.compute_bin_centers(bins)

Given a set of N bin edges, returns N-1 bin centers and half-widths.

bioverse.util.compute_eta_Earth(d, by_type=True)

Computes the value of eta Earth for a simulated sample of planets. Note this could be inaccurate if there are stars without planets which are usually not listed in the simulated sample, although the algorithm does attempt to correct for this.

Parameters:
  • d (Table) – Simulated sample of planets.

  • by_type (bool, optional) – If True, calculate eta Earth separately for each spectral type.

bioverse.util.compute_occurrence_multiplier(optimistic=False, optimistic_factor=3, N_pts=30)

Determines the multiplier for occurrence rates and planet periods as a function of stellar mass.

bioverse.util.update_stellar_catalog(d_max=100, filename='/home/docs/checkouts/readthedocs.org/user_builds/bioverse/envs/stable/lib/python3.7/site-packages/bioverse-1.1.0-py3.7.egg/bioverse/Data/Gaia.csv')

Updates the catalog of nearby sources from Gaia DR2 and saves it to a file. Requires astroquery.

bioverse.util.get_xyz(pl, t=0, M=None, n=3)
bioverse.util.normal(a, b, xmin=None, xmax=None, size=1)
bioverse.util.binned_average(x, y, bins=10, match_counts=True)

Computes the average value of a variable in bins of another variable.

Parameters:
  • x (float array) – Array of independent values along which to perform the binning.

  • y (float array) – Array of dependent values to be averaged.

  • bins (int or float array, optional) – Number of bins or array of bin edges.

  • match_counts (bool, optional) – If True, adjust the bin sizes so that an equal number of data points fall in each bin. Passing an array of bin edges for bins will override this setting.

Returns:

  • bins (float array) – Array of bin edges.

  • values (float array) – Average value of y in each bin.

  • errors (float array) – Uncertainty on values in each bin, i.e. the standard error on the mean.

bioverse.util.compute_t_ref(filenames, t_exp, wl_min, wl_max, threshold=5, usecols=(0, 1, 2))

Computes t_ref for the detection of a spectroscopic feature. User must first use PSG or other tools to simulate spectra of the reference target with and without the feature of interest.

Parameters:
  • filenames ((str, str)) – Points to two PSG output spectra files - one where the atmosphere contains the species of interest, and one where it does not (the order does not matter).

  • t_exp (float) – Exposure time for the PSG simulations - must be identical for both.

  • wl_min (float) – Minimum wavelength of the absorption feature, same units as the PSG output.

  • wl_max (float) – Maximum wavelength of the absorption feature.

  • threshold (float, optional) – SNR threshold for a confident detection.

  • usecols ((int, int, int), optional) – Specifies the column numbers corresponding to (wavelength, radiance, uncertainty) in the input files.

Returns:

t_ref – Exposure time required to reach the targeted detection SNR, same units as t_exp.

Return type:

float

bioverse.util.compute_logbins(binWidth_dex, Range)

Compute the bin edges for a logarithmic grid.

Parameters:
  • binWidth_dex (float) – width of bins in log space (dex)

  • Range (Tuple) – range for parameter

Returns:

bins – bins for one dimension

Return type:

array

Example

>>> binWidth_dex = 1.0
>>> Range = (10., 1000.)
>>> compute_logbins(binWidth_dex, Range)
array([   10.,   100.,  1000.])
bioverse.util.interpolate_df(xvals, df, xcol, ycol)

Interpolate values in a pandas DataFrame.

Parameters:
  • xvals (iterable) – input values for which to search in the x column

  • df (pandas DataFrame) – dataframe in which to interpolate. Expected to be sorted by xcol.

  • xcol (str) – column with values we’re comparing to xval

  • ycol (str) – column with interpolated output values

Returns:

y_interp – interpolated values

Return type:

iterable

bioverse.util.S2a_eff(S)

Convert instellation in W/m2 to solar-equivalent semi-major axis.

bioverse.util.a_eff2S(a_eff)

Convert solar-equivalent semi-major axis to instellation in W/m2.

bioverse.util.compute_moving_average(d, window=25)

Compute rolling mean of radius and density and their uncertainties, ordered by instellation.

Parameters:
  • d (Table) – Table containing the sample of simulated planets.

  • window (int, optional) – window size of the rolling mean

Returns:

d – Table containing new columns for rolling mean of radius, density.

Return type:

Table

bioverse.util.get_ideal_bins(data, method='freedman')

return optimal bins for a given 1D data set

bioverse.util.binned_stats(df, x_param, y_param, bins=None, statistic='mean', scale='log')

Compute a binned statistic of parameter y’s mean with respect to bins in parameter x.

bioverse.util.compute_binned_average(d, x_param='S_abs', y_params=['R', 'rho'])

Compute mean of radius and density and their uncertainties, binned in instellation.

Parameters:
  • d (Table) – Table containing the sample of simulated planets.

  • x_param (str) – Parameter axis along which we want to bin.

  • y_params (str or iterable) – Parameter(s) on which the binned average will be computed.

Returns:

d – Table containing new columns for rolling mean of radius, density.

Return type:

Table

bioverse.util.generate_generator(g_args, stars_only=False, **kwargs)

Helper function to create a planet generator.

bioverse.util.find_distance4samplesize(N_target, g_args, tolerance=2, max_iterations=10, h=5)

Iteratively find the distance d_max needed to achieve a specified planet sample size. Uses the Secant method for root-finding. Sort of.

Parameters:
  • N_target (int) – target sample size

  • g_args (dict) – arguments for generator object

  • tolerance (int) – range around N_target into which we need to land

  • max_iterations (int) – maximum number of iterations

  • h (int) – distance delta (in pc) used for initial guess

Returns:

  • N (int) – closest sample size achieved

  • d0 (float) – distance at closest sample size