Module mrexo



MRExo

DOI

MRExo is a Python script for non-parametric fitting and analysis of the Mass-Radius (M-R) relationship for exoplanets.

We translate Ning et al. (2018)’s R script into a publicly available Python package called MRExo. It offers tools for fitting the M-R relationship to a given data set. Along with the MRExo installation, the fit results from the M dwarf sample dataset from Kanodia et al. (2019) and the Kepler exoplanet sample from Ning et al. (2018) are included. The code also includes predicting functions (M->R, and R->M), and plotting functions to generate the plots used in the below preprint.

For detailed description of the code please see Kanodia et al. (2019)

==================

Installation

Linux/Unix

  1. In the terminal - pip install mrexo

  2. In the terminal - pip install git+<https://github.com/shbhuk/mrexo.git> -U

OR

  1. In the terminal - pip install git+ssh://git@github.com/shbhuk/mrexo.git -U

OR

  1. In the terminal - git clone <https://github.com/shbhuk/mrexo>

  2. In the repository directory python setup.py install

The -U is to upgrade the dependencies.

Windows

  1. Install Git - Git for Windows

  2. Install pip - pip for Windows

  3. In cmd or git cmd - pip install git+<https://github.com/shbhuk/mrexo.git> -U

OR

pip install mrexo

OR

Clone or Download the zip file and then in the repository directory python setup.py install

To sign up for updates, please join the Google Group linked here - https://groups.google.com/forum/#!forum/mrexo

==================

Citation

Guidelines to cite this package can be found here.

The relevant paper can be found on ADS.

================== 

Package dependencies for MRExo

  1. Astropy (v>2.0)
  2. Numpy
  3. SciPy
  4. Matplotlib
  5. Functools32 if running Python 2.7, else Functools

================== 

Sample script to predict Mass/Radius

Sample script to show how to use the predicting function to predict mass from radius

from mrexo import predict_from_measurement, generate_lookup_table
import os
import numpy as np
import matplotlib.pyplot as plt


try :
    pwd = os.path.dirname(__file__)
except NameError:
    pwd = ''
    print('Could not find pwd')

Sample script to show how to use the predicting function to predict mass from radius

I. Predict mass and quantiles from radius for a 1 Earth radii planet with an uncertainty of 0.1 radii using the M dwarf fit from the result_dir

result_dir = os.path.join(pwd,'M_dwarfs_dummy')
predicted_mass, qtls, iron_planet = predict_from_measurement(measurement=1, measurement_sigma=0.1, result_dir=result_dir, is_posterior=False, show_plot=False)
print(predicted_mass)

II. Predict mass from radius for the Kepler dataset for a 1 Earth radii planet

predicted_mass, qtls, iron_planet = predict_from_measurement(measurement=1, measurement_sigma=None, predict = 'mass', dataset='kepler')

III. Predict the mass measurement from a dummy radius posterior and plot it

posterior, iron_planet = predict_from_measurement(measurement=np.random.normal(1,0.1,1000),
            measurement_sigma=None, result_dir=None, dataset='mdwarf', is_posterior=True, show_plot=True, use_lookup = True)

IV. Predict the mass for a radius of 1 Earth radii exoplanet with uncertainty of 0.1 Earth Radii on the included Mdwarf fit. Also output 5,16,84,95% quantile

predicted_mass, qtls, iron_planet = predict_from_measurement(measurement=1, measurement_sigma=0.1, result_dir=None, dataset='mdwarf', is_posterior=False,
                       qtl = [0.05,0.16,0.84,0.95], show_plot=False)

Alternatively, the default dataset is the M dwarf dataset from Kanodia 2019.

predicted_mass, qtls, iron_planet = predict_from_measurement(measurement=1, measurement_sigma=0.1,qtl = [0.05,0.16,0.84,0.95])

==================

Sample script to plot Mass-Radius relationships

Sample script to show how to use the plotting functions available with MRExo

from mrexo import plot_r_given_m_relation, plot_m_given_r_relation, plot_mr_and_rm, plot_joint_mr_distribution
import os
import numpy as np
import matplotlib.pyplot as plt


try :
    pwd = os.path.dirname(__file__)
except NameError:
    pwd = ''
    print('Could not find pwd')

Sample script to show how to use the plotting functions for the M dwarf dataset from Kanodia (2019)

mdwarf_result = r'C:\Users\shbhu\Documents\GitHub\mrexo\mrexo\datasets\M_dwarfs_20181214'
kepler_result = r'C:\Users\shbhu\Documents\Git\mrexo\mrexo\datasets\Kepler_Ning_etal_20170605'

result_dir = mdwarf_result

I. Plot the conditional distribution f(m|r)

ax = plot_m_given_r_relation(result_dir)

II. Plot the conditional distribution f(r|m)

ax = plot_r_given_m_relation(result_dir)

III. Plot both the conditional distributions f(m|r) and f(r|m), similar to Kanodia 2019, Fig 3.

ax = plot_mr_and_rm(result_dir)

IV. Plot the joint distribution f(m,r)

ax = plot_joint_mr_distribution(result_dir)

==================

Sample script to fit mass-radius relationship

The CSV table is generated from the NASA Exoplanet Archive. The existing example is for the 24 M dwarf planets as explained in Kanodia 2019. This can be replaced with a different dataset CSV file.

For this sample, the cross validation has already been performed and the optimum number of degrees has been established to be 17. For a new sample, set select_deg = 'cv' to use cross validation to find the optimum number of degrees.

Can use parallel processing by setting cores > 1. To use all the cores in the CPU, cores=cpu_count() (from multiprocessing import cpu_count)

To bootstrap and estimate the robustness of the median, set num_boot > 1. If cores > 1, then uses parallel processing to run the various boots. For large datasets, first run with num_boot to be a smaller number to estimate the computational time.

For more detailed guidelines read the docuemtnation for the fit_mr_relation() function.

import os
from astropy.table import Table
import numpy as np
from multiprocessing import cpu_count
import numpy as np


from mrexo import fit_mr_relation


try :
    pwd = os.path.dirname(__file__)
except NameError:
    pwd = ''
    print('Could not find pwd')

t = Table.read(os.path.join(pwd,'Cool_stars_MR_20181214_exc_upperlim.csv'))

# Symmetrical errorbars
Mass_sigma = (abs(t['pl_masseerr1']) + abs(t['pl_masseerr2']))/2
Radius_sigma = (abs(t['pl_radeerr1']) + abs(t['pl_radeerr2']))/2

# In Earth units
Mass = np.array(t['pl_masse'])
Radius = np.array(t['pl_rade'])

# Directory to store results in
result_dir = os.path.join(pwd,'M_dwarfs_new_cv')

# Run with 50 bootstraps. Selecting degrees to be 17. Alternatively can set select_deg = 'cv' to
# find the optimum number of degrees.

if __name__ == '__main__':
            initialfit_result, bootstrap_results = fit_mr_relation(Mass = Mass, Mass_sigma = Mass_sigma,
                                                Radius = Radius, Radius_sigma = Radius_sigma,
                                                save_path = result_dir, select_deg = 17,
                                                num_boot = 50, cores = cpu_count())

==================

Source code
"""
.. include:: ../README.md
.. include:: ../docs/dependencies.md
.. include:: ../docs/sample_usage.md

"""

from .plot import plot_m_given_r_relation, plot_r_given_m_relation,plot_mr_and_rm, plot_joint_mr_distribution, plot_mle_weights
from .predict import predict_from_measurement, mass_100_percent_iron_planet,generate_lookup_table, radius_100_percent_iron_planet
from .fit import fit_mr_relation
from .mle_utils import MLE_fit, cond_density_quantile
from .utils import _save_dictionary, _load_lookup_table, _logging
from .cross_validate import run_cross_validation

__version__ = '0.1.4.1'

Sub-modules

mrexo.cross_validate
mrexo.fit
mrexo.mle_utils
mrexo.plot
mrexo.predict
mrexo.utils