Code Monkey home page Code Monkey logo

stardate's Introduction

stardate

https://travis-ci.org/RuthAngus/stardate.svg?branch=master https://readthedocs.org/projects/stardate/badge/?version=latest

Checkout the documentation.

stardate currently only works with python3.

stardate is a tool for measuring precise stellar ages. it combines isochrone fitting with gyrochronology (rotation-based ages) to increase the precision of stellar ages on the main sequence. the best possible ages provided by stardate will be for stars with rotation periods, although ages can be predicted for stars without rotation periods too. if you don't have rotation periods for any of your stars, you might consider using isochrones as stardate is simply an extension to isochrones that incorporates gyrochronology. stardate reverts back to isochrones when no rotation period is provided.

If you would like to contribute to this project, feel free to raise issues or submit pull requests from the github repo.

Installation

Currently the best way to install stardate is from github.

git clone https://github.com/RuthAngus/stardate.git
cd stardate
python setup.py install

Dependencies

The dependencies of stardate are NumPy, pandas, h5py, numba, emcee3, tqdm and isochrones.

These can be installed using pip:

pip install numpy pandas h5py numba "emcee==3.0rc2" tqdm isochrones

You can check out the isochrones documentation if you run into difficulties installing that.

Example usage

import stardate as sd

# Create a dictionary of observables
iso_params = {"teff": (4386, 50),     # Teff with uncertainty.
              "logg": (4.66, .05),    # logg with uncertainty.
              "feh": (0.0, .02),      # Metallicity with uncertainty.
              "parallax": (1.48, .1),  # Parallax in milliarcseconds.
              "maxAV": .1}            # Maximum extinction

prot, prot_err = 29, 3

# Set up the star object.
star = sd.Star(iso_params, prot=prot, prot_err=prot_err)  # Here's where you add a rotation period

# Run the MCMC
star.fit(max_n=1000)

# max_n is the maximum number of MCMC samples. I recommend setting this
# much higher when running for real, or using the default value of 100000.

# Print the median age with the 16th and 84th percentile uncertainties.
age, errm, errp, samples = star.age_results()
print("stellar age = {0:.2f} + {1:.2f} - {2:.2f}".format(age, errp, errm))

>> stellar age = 2.97 + 0.55 - 0.60

If you want to just use a simple gyrochronology model without running MCMC, you can predict a stellar age from a rotation period like this:

import numpy as np
from stardate.lhf import age_model

bprp = .82  # Gaia BP - RP color.
log10_period = np.log10(26)
log10_age_yrs = age_model(log10_period, bprp)
print((10**log10_age_yrs)*1e-9, "Gyr")
>> 4.565055357152765 Gyr

Or a rotation period from an age like this:

from stardate.lhf import gyro_model_praesepe

bprp = .82  # Gaia BP - RP color.
log10_age_yrs = np.log10(4.56*1e9)
log10_period = gyro_model_praesepe(log10_age_yrs, bprp)
print(10**log10_period, "days")
>> 25.98136488222407 days

BUT be aware that these simple relations are only applicable to FGK and early M dwarfs on the main sequence, older than a few hundred Myrs. If you're not sure if gyrochronology is applicable to your star, want the best age possible, or would like proper uncertainty estimates, I recommend using the full MCMC approach.

stardate's People

Contributors

arfon avatar john-livingston avatar ruthangus avatar timothydmorton avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

stardate's Issues

Issues when testing stardate

I installed stardate on a new python=3.8 conda environment, following the instructions.

The following example MCMC fits from the readthedocs run fine (no error), but I am not getting the right results:

My code:

import stardate as sd

# Create a dictionary of observables
iso_params = {"teff": (4386, 50),     # Teff with uncertainty.
              "logg": (4.66, .05),    # logg with uncertainty.
              "feh": (0.0, .02),      # Metallicity with uncertainty.
              "parallax": (1.48, .1),  # Parallax in milliarcseconds.
              "maxAV": .1}            # Maximum extinction

prot, prot_err = 29, 3

# Set up the star object.
star = sd.Star(iso_params, prot=prot, prot_err=prot_err)  # Here's where you add a rotation period

# Run the MCMC
star.fit(max_n=1000)

# max_n is the maximum number of MCMC samples. I recommend setting this
# much higher when running for real, or using the default value of 100000.

# Print the median age with the 16th and 84th percentile uncertainties.
age, errp, errm, samples = star.age_results()
print("stellar age = {0:.2f} + {1:.2f} + {2:.2f}".format(age, errp, errm))

I get as an output 0.42 + 0.32 + 3.37 rather than 2.97 + 0.60 + 0.55, and the bias towards low stellar ages remains even for larger numbers of steps (10,000).

When directly calling the Praesepe model to get period from age or age from period however, I am getting the expected values.

Another issue is that I am getting 3 failed tests when running pytest (see below).

platform darwin -- Python 3.8.13, pytest-7.1.2, pluggy-1.0.0
rootdir: /Users/caroline/Research/GitHub/stardate
collected 13 items                                                                                    

test/isochrone_test.py F                                                                        [  7%]
test/lhf_test.py ..F..F......                                                                   [100%]

============================================== FAILURES ===============================================
___________________________________________ test_iso_lnlike ___________________________________________

    def test_iso_lnlike():
    
        iso_params = {"teff": (5770, 10),
                    "feh": (0, .01),
                    "logg": (4.44, .1),
                    "parallax": (1, 1)}
    
        mod = SingleStarModel(mist, **iso_params)  # StarModel isochrones obj
        params = [354, np.log10(4.56*1e9), 0., 1000, 0.]
        lnparams = [354, np.log10(4.56*1e9), 0., np.log(1000), 0.]
        lnpr = mod.lnprior(params)
        # lnparams = [350, 9, 0., 6, 0.]
        args1 = [mod, iso_params]
    
        # Calculate the lnprob above
        iso_lp = iso_lnprob(lnparams, *args1)
        start = time.time()
        for i in range(100):
            iso_lp = iso_lnprob(lnparams, *args1)
        end = time.time()
    
        # Calculate the stardate lnprob
        args2 = [mod, None, None, True, False, True, "praesepe"]
    
        start = time.time()
        for i in range(100):
            lp = lnprob(lnparams, *args2)[0]
        end = time.time()
        # print("time = ", end - start)
    
        ll = lnlike(lnparams, *args2)
        lnprior = lp - ll
    
        assert iso_lp == lp
        assert np.isclose(iso_lp - lnpr, ll)
>       assert lnpr == lnprior
E       assert -18.46720822861122 == -18.46720822861107

test/isochrone_test.py:62: AssertionError
____________________________________________ test_calc_bv _____________________________________________

    def test_calc_bv():
        sun = [355, np.log10(4.56*1e9), 0., np.log(1000), 0.]
        bv_sun = calc_bv(sun)
>       assert .6 < bv_sun, "Are you sure you're on the isochrones eep branch?"
E       AssertionError: Are you sure you're on the isochrones eep branch?
E       assert 0.6 < 0.42834431703148956

test/lhf_test.py:92: AssertionError
_______________________________________ test_gyro_model_rossby ________________________________________

    def test_gyro_model_rossby():
        """
        Make sure that the rossby model gives Solar values for the Sun.
        Make sure it gives a maximum rotation period of pmax.
        """
        age = np.log10(4.56*1e9)
        sun = [355, age, 0., np.log(1000), 0.]
    
        # iso_params = {"teff": (5777, 10),
        #               "logg": (4.44, .05),
        #               "feh": (0., .001),
        #               "parallax": (1., .01),  # milliarcseconds
        #               "B": (15.48, 0.02)}
    
        # # Set up the StarModel isochrones object.
        # mod = StarModel(mist, **iso_params)
        # # the lnprob arguments]
        # args = [mod, 26., 1., False, True, "praesepe"]
        # print(lnprob(sun, *args))
        # assert 0
    
        prot_sun = 10**gyro_model_rossby(sun, model="praesepe")[0]
>       assert 21 < prot_sun
E       assert 21 < 6.909888089400217

test/lhf_test.py:142: AssertionError

Fully-convective stars

Hi @RuthAngus!

I'm interested in using stardate for a project I'm working on with fully-convective stars. I see in your paper's Discussion section that these stars perhaps shouldn't trusted with stardate.ย I'm wondering if you could elaborate a bit on what circumstances need to be met to trust stardate ages for fully-convective stars?

Thanks so much ๐Ÿ˜„

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.