How to use the celerite.terms.Term function in celerite

To help you get started, we’ve selected a few celerite examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nespinoza / juliet / juliet.py View on Github external
import dynesty
# Import multinest for (importance) nested sampling:
import pymultinest
import sys

from scipy.interpolate import interp1d
import numpy as np
import utils
import os
import time

# Prepare the celerite term:
import celerite
from celerite import terms

class RotationTerm(terms.Term):
    parameter_names = ("log_amp", "log_timescale", "log_period", "log_factor")

    def get_real_coefficients(self, params):
        log_amp, log_timescale, log_period, log_factor = params
        f = np.exp(log_factor)
        return (
            np.exp(log_amp) * (1.0 + f) / (2.0 + f), 
            np.exp(-log_timescale),
        )   

    def get_complex_coefficients(self, params):
        log_amp, log_timescale, log_period, log_factor = params
        f = np.exp(log_factor)
        return (
            np.exp(log_amp) / (2.0 + f), 
            0.0,
github dfm / celerite / paper / figures / rotation.py View on Github external
import kplr
import emcee3
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import minimize

from celerite.plot_setup import setup, get_figsize, COLORS

import celerite
from celerite import terms

np.random.seed(123)
setup(auto=True)

# Define the custom kernel
class RotationTerm(terms.Term):
    parameter_names = ("log_amp", "log_timescale", "log_period", "log_factor")

    def get_real_coefficients(self):
        f = np.exp(self.log_factor)
        return (
            np.exp(self.log_amp) * (1.0 + f) / (2.0 + f),
            np.exp(-self.log_timescale),
        )

    def get_complex_coefficients(self):
        f = np.exp(self.log_factor)
        return (
            np.exp(self.log_amp) / (2.0 + f),
            0.0,
            np.exp(-self.log_timescale),
            2*np.pi*np.exp(-self.log_period),
github 3fon3fonov / exostriker / exostriker / lib / RV_mod / GP_kernels.py View on Github external
#from pylab import *
import numpy as np
#import celerite 
from celerite import terms

'''Here you can define custom rotational kernels for Gaussian Processes. Give each an id, then you will be able to choose it by passing the id to the GP_parameters object
   If you don't provide an id then id=0, i. e. DefaultRotationTerm will be chosen.
   When defining a new custom kernel make sure to define a parameter_labels function (see examples here), otherwise there will be trouble with printing
'''

    
class RotationTerm(terms.Term):
    
    parameter_names = ("log_amp", "log_timescale", "log_period", "log_factor")
   # number_of_parameters=4 
    
   # def parameter_labels(self):
   #     return ['A','t','P','f']

    def get_real_coefficients(self, params):
        log_amp, log_timescale, log_period, log_factor = params
        f = np.exp(log_factor)
        return (np.exp(log_amp) * (1.0 + f) / (2.0 + f), np.exp(-log_timescale))   

    def get_complex_coefficients(self, params):
        log_amp, log_timescale, log_period, log_factor = params
        f = np.exp(log_factor)
        return (np.exp(log_amp) / (2.0 + f), 0.0, np.exp(-log_timescale), 2*np.pi*np.exp(-log_period))
github nespinoza / juliet / juliet / fit.py View on Github external
import batman
# Import radvel, for RV models:
import radvel
# Import george for detrending:
try:
    import george
except:
    print('Warning: no george installation found. No non-celerite GPs will be able to be used')
# Import celerite for detrending:
try:
    import celerite
    from celerite import terms

    # This class was written by Daniel Foreman-Mackey for his paper: 
    # https://github.com/dfm/celerite/blob/master/paper/figures/rotation/rotation.ipynb
    class RotationTerm(terms.Term):
        parameter_names = ("log_amp", "log_timescale", "log_period", "log_factor")
        def get_real_coefficients(self, params):
            log_amp, log_timescale, log_period, log_factor = params
            f = np.exp(log_factor)
            return (
                np.exp(log_amp) * (1.0 + f) / (2.0 + f),
                np.exp(-log_timescale),
            )    

        def get_complex_coefficients(self, params):
            log_amp, log_timescale, log_period, log_factor = params
            f = np.exp(log_factor)
            return (
                np.exp(log_amp) / (2.0 + f),
                0.0, 
                np.exp(-log_timescale),
github dfm / celerite / celerite / terms.py View on Github external
if self.fit_b and self.log_a + self.log_c < self.log_b + self.log_d:
            return -np.inf
        return super(ComplexTerm, self).log_prior()

    # def get_dcoeffs_dparams(self):
    #     if self.fit_b:
    #         return np.diag(self.get_complex_coefficients())
    #     c = self.get_complex_coefficients()
    #     result = np.zeros((3, 4))
    #     result[0, 0] = c[0]
    #     result[1, 2] = c[2]
    #     result[2, 3] = c[3]
    #     return result


class SHOTerm(Term):
    r"""
    A term representing a stochastically-driven, damped harmonic oscillator

    The PSD of this term is

    .. math::

        S(\omega) = \sqrt{\frac{2}{\pi}} \frac{S_0\,\omega_0^4}
        {(\omega^2-{\omega_0}^2)^2 + {\omega_0}^2\,\omega^2/Q^2}

    with the parameters ``log_S0``, ``log_Q``, and ``log_omega0``.

    Args:
        log_S0 (float): The log of the parameter :math:`S_0`.
        log_Q (float): The log of the parameter :math:`Q`.
        log_omega0 (float): The log of the parameter :math:`\omega_0`.
github 3fon3fonov / exostriker / lib / RV_mod / rot_kernels.py View on Github external
return Kernel
	    

class RotationTerm2(terms.Term):

    ''' to make sure a desired kernel has as many parameters as provided, otherwise there will be problems '''

    def verify_number_of_parameters(self,npar):
        if (self.number_of_parameters==npar):
            return True
        else:
            return False

#class DefaultRotationTerm(RotationTerm):
    
class RotationTerm(terms.Term):
    
    parameter_names = ("log_amp", "log_timescale", "log_period", "log_factor")
   # number_of_parameters=4 
    
   # def parameter_labels(self):
   #     return ['A','t','P','f']

    def get_real_coefficients(self, params):
        log_amp, log_timescale, log_period, log_factor = params
        f = np.exp(log_factor)
        return (np.exp(log_amp) * (1.0 + f) / (2.0 + f), np.exp(-log_timescale))   

    def get_complex_coefficients(self, params):
        log_amp, log_timescale, log_period, log_factor = params
        f = np.exp(log_factor)
        return (np.exp(log_amp) / (2.0 + f), 0.0, np.exp(-log_timescale), 2*np.pi*np.exp(-log_period))
github 3fon3fonov / exostriker / lib / RV_mod / rot_kernels.py View on Github external
'''Here you can define custom rotational kernels for Gaussian Processes. Give each an id, then you will be able to choose it by passing the id to the GP_parameters object
   If you don't provide an id then id=0, i. e. DefaultRotationTerm will be chosen.
   When defining a new custom kernel make sure to define a parameter_labels function (see examples here), otherwise there will be trouble with printing
'''

def choose_kernel(i, params):
	if (i==0):
	    Kernel=DefaultRotationTerm(log_amp=np.log(params[0]),log_timescale=np.log(params[1]),log_period=np.log(params[2]),log_factor=np.log(params[3]))
 	    #Kernel=DefaultRotationTerm(log_amp=params[0],log_timescale=params[1],log_period=params[2],log_factor=params[3])
       
	if not (Kernel.verify_number_of_parameters(len(params))):
	    raise Exception('Number of parameters not suitable for this kernel, this would lead to errors later on!!!')
	return Kernel
	    

class RotationTerm2(terms.Term):

    ''' to make sure a desired kernel has as many parameters as provided, otherwise there will be problems '''

    def verify_number_of_parameters(self,npar):
        if (self.number_of_parameters==npar):
            return True
        else:
            return False

#class DefaultRotationTerm(RotationTerm):
    
class RotationTerm(terms.Term):
    
    parameter_names = ("log_amp", "log_timescale", "log_period", "log_factor")
   # number_of_parameters=4 
github dfm / celerite / celerite / terms.py View on Github external
gen = product(zip(*(c1[2:])), zip(*(c2[2:])))
        for i, ((aj, bj, cj, dj), (ak, bk, ck, dk)) in enumerate(gen):
            ac.append(0.5 * (aj * ak + bj * bk))
            bc.append(0.5 * (bj * ak - aj * bk))
            cc.append(cj + ck)
            dc.append(dj - dk)

            ac.append(0.5 * (aj * ak - bj * bk))
            bc.append(0.5 * (bj * ak + aj * bk))
            cc.append(cj + ck)
            dc.append(dj + dk)

        return list(map(np.array, (ar, cr, ac, bc, cc, dc)))


class TermSum(Term, ModelSet):

    def __init__(self, *terms):
        models = []
        for term in terms:
            models += term.terms
        super(TermSum, self).__init__([("terms[{0}]".format(i), t)
                                       for i, t in enumerate(models)])

    def __repr__(self):
        return "(" + " + ".join(map("{0}".format, self.terms)) + ")"

    @property
    def terms(self):
        return list(self.models.values())

    @property
github dfm / celerite / papers / paper1 / figures / transit_model.py View on Github external
# -*- coding: utf-8 -*-

from __future__ import division, print_function

import transit
import numpy as np
from celerite import terms, modeling

__all__ = ["RotationTerm", "TransitModel"]


class RotationTerm(terms.Term):
    parameter_names = ("log_amp", "log_timescale", "log_period", "log_factor")

    def get_real_coefficients(self):
        f = np.exp(self.log_factor)
        return (
            np.exp(self.log_amp) * (1.0 + f) / (2.0 + f),
            np.exp(-self.log_timescale),
        )

    def get_complex_coefficients(self):
        f = np.exp(self.log_factor)
        return (
            np.exp(self.log_amp) / (2.0 + f),
            0.0,
            np.exp(-self.log_timescale),
            2*np.pi*np.exp(-self.log_period),
github 3fon3fonov / exostriker / rot_kernels.py View on Github external
'''Here you can define custom rotational kernels for Gaussian Processes. Give each an id, then you will be able to choose it by passing the id to the GP_parameters object
   If you don't provide an id then id=0, i. e. DefaultRotationTerm will be chosen.
   When defining a new custom kernel make sure to define a parameter_labels function (see examples here), otherwise there will be trouble with printing
'''

def choose_kernel(i, params):
	if (i==0):
	    #Kernel=DefaultRotationTerm(log_amp=np.log(params[0]),log_timescale=np.log(params[1]),log_period=np.log(params[2]),log_factor=np.log(params[3]))
 	    Kernel=DefaultRotationTerm(log_amp=params[0],log_timescale=params[1],log_period=params[2],log_factor=params[3])
       
	if not (Kernel.verify_number_of_parameters(len(params))):
	    raise Exception('Number of parameters not suitable for this kernel, this would lead to errors later on!!!')
	return Kernel
	    

class RotationTerm(terms.Term):

    ''' to make sure a desired kernel has as many parameters as provided, otherwise there will be problems '''

    def verify_number_of_parameters(self,npar):
        if (self.number_of_parameters==npar):
            return True
        else:
            return False

class DefaultRotationTerm(RotationTerm):
    parameter_names = ("log_amp", "log_timescale", "log_period", "log_factor")
    number_of_parameters=4 
    
    def parameter_labels(self):
        return ['A','t','P','f']